@@ -2,22 +2,26 @@ const tape = require('tape')
2
2
const utils = require ( 'ethereumjs-util' )
3
3
const FakeTransaction = require ( '../fake.js' )
4
4
5
+ // Use private key 0x0000000000000000000000000000000000000000000000000000000000000001 as 'from' Account
5
6
var txData = {
6
7
data : '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005' ,
7
8
gasLimit : '0x15f90' ,
8
9
gasPrice : '0x1' ,
9
10
nonce : '0x01' ,
10
11
to : '0xd9024df085d09398ec76fbed18cac0e1149f50dc' ,
11
12
value : '0x0' ,
12
- from : '0x1111111111111111111111111111111111111111'
13
+ from : '0x7e5f4552091a69125d5dfcb7b8c2659029395bdf' ,
14
+ v : '0x1c' ,
15
+ r : '0x25641558260ac737ea6d800906c6d085a801e5e0f0952bf93978d6fa468fbdfe' ,
16
+ s : '0x5d0904b8f9cfc092805df0cde2574d25e2c5fc28907a9a4741b3e857b68b0778'
13
17
}
14
18
15
19
tape ( '[FakeTransaction]: Basic functions' , function ( t ) {
16
20
t . test ( 'instantiate with from / create a hash' , function ( st ) {
17
21
st . plan ( 3 )
18
22
var tx = new FakeTransaction ( txData )
19
23
var hash = tx . hash ( )
20
- var cmpHash = Buffer . from ( 'f0327c058946be12609d2afc0c45e8e1fffe57acbbff0e9c252e8fab61c3b2b9 ' , 'hex' )
24
+ var cmpHash = Buffer . from ( 'f74b039f6361c4351a99a7c6a10867369fe6701731d85dc07c15671ac1c1b648 ' , 'hex' )
21
25
st . deepEqual ( hash , cmpHash , 'should create hash with includeSignature=true (default)' )
22
26
var hash2 = tx . hash ( false )
23
27
var cmpHash2 = Buffer . from ( '0401bf740d698674be321d0064f92cd6ebba5d73d1e5e5189c0bebbda33a85fe' , 'hex' )
@@ -31,7 +35,7 @@ tape('[FakeTransaction]: Basic functions', function (t) {
31
35
st . plan ( 3 )
32
36
var tx = new FakeTransaction ( txDataNoFrom )
33
37
var hash = tx . hash ( )
34
- var cmpHash = Buffer . from ( '7521eb94880840a93e2105f064cec3fe605f0159778a420b9b529c2f3d3b4e37 ' , 'hex' )
38
+ var cmpHash = Buffer . from ( '80a2ca70509414908881f718502e6bbb3bc67f416abdf972ea7c0888579be7b9 ' , 'hex' )
35
39
st . deepEqual ( hash , cmpHash , 'should create hash with includeSignature=true (default)' )
36
40
var hash2 = tx . hash ( false )
37
41
var cmpHash2 = Buffer . from ( '0401bf740d698674be321d0064f92cd6ebba5d73d1e5e5189c0bebbda33a85fe' , 'hex' )
@@ -48,4 +52,13 @@ tape('[FakeTransaction]: Basic functions', function (t) {
48
52
var hashModFrom = utils . bufferToHex ( txModFrom . hash ( ) )
49
53
st . notEqual ( hash , hashModFrom , 'FakeTransactions with different `from` addresses but otherwise identical data should have different hashes' )
50
54
} )
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
+ } )
51
64
} )
0 commit comments