Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

Commit b569738

Browse files
authored
Merge pull request #118 from ShipChain/master
Fix #113 (signed FakeTransaction)
2 parents 32989a3 + 1fb1b74 commit b569738

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

fake.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ module.exports = class FakeTransaction extends Transaction {
4545
configurable: true,
4646
get: this.getSenderAddress.bind(self),
4747
set: function (val) {
48-
self._from = ethUtil.toBuffer(val)
48+
if (val) {
49+
self._from = ethUtil.toBuffer(val)
50+
}
4951
}
5052
})
5153

test/fake.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ const tape = require('tape')
22
const utils = require('ethereumjs-util')
33
const FakeTransaction = require('../fake.js')
44

5+
// Use private key 0x0000000000000000000000000000000000000000000000000000000000000001 as 'from' Account
56
var txData = {
67
data: '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005',
78
gasLimit: '0x15f90',
89
gasPrice: '0x1',
910
nonce: '0x01',
1011
to: '0xd9024df085d09398ec76fbed18cac0e1149f50dc',
1112
value: '0x0',
12-
from: '0x1111111111111111111111111111111111111111'
13+
from: '0x7e5f4552091a69125d5dfcb7b8c2659029395bdf',
14+
v: '0x1c',
15+
r: '0x25641558260ac737ea6d800906c6d085a801e5e0f0952bf93978d6fa468fbdfe',
16+
s: '0x5d0904b8f9cfc092805df0cde2574d25e2c5fc28907a9a4741b3e857b68b0778'
1317
}
1418

1519
tape('[FakeTransaction]: Basic functions', function (t) {
1620
t.test('instantiate with from / create a hash', function (st) {
1721
st.plan(3)
1822
var tx = new FakeTransaction(txData)
1923
var hash = tx.hash()
20-
var cmpHash = Buffer.from('f0327c058946be12609d2afc0c45e8e1fffe57acbbff0e9c252e8fab61c3b2b9', 'hex')
24+
var cmpHash = Buffer.from('f74b039f6361c4351a99a7c6a10867369fe6701731d85dc07c15671ac1c1b648', 'hex')
2125
st.deepEqual(hash, cmpHash, 'should create hash with includeSignature=true (default)')
2226
var hash2 = tx.hash(false)
2327
var cmpHash2 = Buffer.from('0401bf740d698674be321d0064f92cd6ebba5d73d1e5e5189c0bebbda33a85fe', 'hex')
@@ -31,7 +35,7 @@ tape('[FakeTransaction]: Basic functions', function (t) {
3135
st.plan(3)
3236
var tx = new FakeTransaction(txDataNoFrom)
3337
var hash = tx.hash()
34-
var cmpHash = Buffer.from('7521eb94880840a93e2105f064cec3fe605f0159778a420b9b529c2f3d3b4e37', 'hex')
38+
var cmpHash = Buffer.from('80a2ca70509414908881f718502e6bbb3bc67f416abdf972ea7c0888579be7b9', 'hex')
3539
st.deepEqual(hash, cmpHash, 'should create hash with includeSignature=true (default)')
3640
var hash2 = tx.hash(false)
3741
var cmpHash2 = Buffer.from('0401bf740d698674be321d0064f92cd6ebba5d73d1e5e5189c0bebbda33a85fe', 'hex')
@@ -48,4 +52,13 @@ tape('[FakeTransaction]: Basic functions', function (t) {
4852
var hashModFrom = utils.bufferToHex(txModFrom.hash())
4953
st.notEqual(hash, hashModFrom, 'FakeTransactions with different `from` addresses but otherwise identical data should have different hashes')
5054
})
55+
56+
t.test('should retrieve "from" from signature if transaction is signed', function (st) {
57+
var txDataNoFrom = Object.assign({}, txData)
58+
delete txDataNoFrom['from']
59+
st.plan(1)
60+
61+
var tx = new FakeTransaction(txDataNoFrom)
62+
st.equal(utils.bufferToHex(tx.from), txData.from)
63+
})
5164
})

0 commit comments

Comments
 (0)