|
1 | 1 | const tape = require('tape')
|
2 | 2 | const utils = require('ethereumjs-util')
|
3 | 3 | const FakeTransaction = require('../fake.js')
|
| 4 | + |
| 5 | +var txData = { |
| 6 | + data: '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', |
| 7 | + gasLimit: '0x15f90', |
| 8 | + gasPrice: '0x1', |
| 9 | + nonce: '0x01', |
| 10 | + to: '0xd9024df085d09398ec76fbed18cac0e1149f50dc', |
| 11 | + value: '0x0', |
| 12 | + from: '0x1111111111111111111111111111111111111111' |
| 13 | +} |
| 14 | + |
4 | 15 | tape('[FakeTransaction]: Basic functions', function (t) {
|
| 16 | + t.test('instantiate with from / create a hash', function (st) { |
| 17 | + st.plan(3) |
| 18 | + var tx = new FakeTransaction(txData) |
| 19 | + var hash = tx.hash() |
| 20 | + var cmpHash = Buffer.from('f0327c058946be12609d2afc0c45e8e1fffe57acbbff0e9c252e8fab61c3b2b9', 'hex') |
| 21 | + st.deepEqual(hash, cmpHash, 'should create hash with includeSignature=true (default)') |
| 22 | + var hash2 = tx.hash(false) |
| 23 | + var cmpHash2 = Buffer.from('0401bf740d698674be321d0064f92cd6ebba5d73d1e5e5189c0bebbda33a85fe', 'hex') |
| 24 | + st.deepEqual(hash2, cmpHash2, 'should create hash with includeSignature=false') |
| 25 | + st.notDeepEqual(hash, hash2, 'previous hashes should be different') |
| 26 | + }) |
| 27 | + |
| 28 | + t.test('instantiate without from / create a hash', function (st) { |
| 29 | + var txDataNoFrom = Object.assign({}, txData) |
| 30 | + delete txDataNoFrom['from'] |
| 31 | + st.plan(3) |
| 32 | + var tx = new FakeTransaction(txDataNoFrom) |
| 33 | + var hash = tx.hash() |
| 34 | + var cmpHash = Buffer.from('7521eb94880840a93e2105f064cec3fe605f0159778a420b9b529c2f3d3b4e37', 'hex') |
| 35 | + st.deepEqual(hash, cmpHash, 'should create hash with includeSignature=true (default)') |
| 36 | + var hash2 = tx.hash(false) |
| 37 | + var cmpHash2 = Buffer.from('0401bf740d698674be321d0064f92cd6ebba5d73d1e5e5189c0bebbda33a85fe', 'hex') |
| 38 | + st.deepEqual(hash2, cmpHash2, 'should create hash with includeSignature=false') |
| 39 | + st.notDeepEqual(hash, hash2, 'previous hashes should be different') |
| 40 | + }) |
| 41 | + |
5 | 42 | t.test('should not produce hash collsions for different senders', function (st) {
|
6 | 43 | st.plan(1)
|
7 |
| - var baseTxData = { |
8 |
| - data: '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', |
9 |
| - gasLimit: '0x15f90', |
10 |
| - gasPrice: '0x1', |
11 |
| - nonce: '0x01', |
12 |
| - to: '0xd9024df085d09398ec76fbed18cac0e1149f50dc', |
13 |
| - value: '0x0', |
14 |
| - from: '0x1111111111111111111111111111111111111111' |
15 |
| - } |
16 |
| - var modifiedFromFieldTxData = Object.assign({}, baseTxData, { from: '0x2222222222222222222222222222222222222222' }) |
17 |
| - var baseTx = new FakeTransaction(baseTxData) |
18 |
| - var modifiedFromFieldTx = new FakeTransaction(modifiedFromFieldTxData) |
19 |
| - var baseTxHash = utils.bufferToHex(baseTx.hash()) |
20 |
| - var modifiedFromFieldTxHash = utils.bufferToHex(modifiedFromFieldTx.hash()) |
21 |
| - st.notEqual(baseTxHash, modifiedFromFieldTxHash, 'FakeTransactions with different `from` addresses but otherwise identical data should have different hashes') |
| 44 | + var txDataModFrom = Object.assign({}, txData, { from: '0x2222222222222222222222222222222222222222' }) |
| 45 | + var tx = new FakeTransaction(txData) |
| 46 | + var txModFrom = new FakeTransaction(txDataModFrom) |
| 47 | + var hash = utils.bufferToHex(tx.hash()) |
| 48 | + var hashModFrom = utils.bufferToHex(txModFrom.hash()) |
| 49 | + st.notEqual(hash, hashModFrom, 'FakeTransactions with different `from` addresses but otherwise identical data should have different hashes') |
22 | 50 | })
|
23 | 51 | })
|
0 commit comments