@@ -8,7 +8,7 @@ tape('[Transaction]: Basic functions', function (t) {
8
8
var transactions = [ ]
9
9
10
10
t . test ( 'should decode transactions' , function ( st ) {
11
- txFixtures . slice ( 0 , 3 ) . forEach ( function ( tx ) {
11
+ txFixtures . slice ( 0 , 4 ) . forEach ( function ( tx ) {
12
12
var pt = new Transaction ( tx . raw )
13
13
st . equal ( '0x' + pt . nonce . toString ( 'hex' ) , tx . raw [ 0 ] )
14
14
st . equal ( '0x' + pt . gasPrice . toString ( 'hex' ) , tx . raw [ 1 ] )
@@ -32,15 +32,15 @@ tape('[Transaction]: Basic functions', function (t) {
32
32
} )
33
33
34
34
t . test ( 'should hash' , function ( st ) {
35
- var tx = new Transaction ( txFixtures [ 2 ] . raw )
35
+ var tx = new Transaction ( txFixtures [ 3 ] . raw )
36
36
st . deepEqual ( tx . hash ( ) , new Buffer ( '375a8983c9fc56d7cfd118254a80a8d7403d590a6c9e105532b67aca1efb97aa' , 'hex' ) )
37
37
st . deepEqual ( tx . hash ( false ) , new Buffer ( '61e1ec33764304dddb55348e7883d4437426f44ab3ef65e6da1e025734c03ff0' , 'hex' ) )
38
38
st . deepEqual ( tx . hash ( true ) , new Buffer ( '375a8983c9fc56d7cfd118254a80a8d7403d590a6c9e105532b67aca1efb97aa' , 'hex' ) )
39
39
st . end ( )
40
40
} )
41
41
42
42
t . test ( 'should hash with defined chainId' , function ( st ) {
43
- var tx = new Transaction ( txFixtures [ 3 ] . raw )
43
+ var tx = new Transaction ( txFixtures [ 4 ] . raw )
44
44
st . equal ( tx . hash ( ) . toString ( 'hex' ) , '0f09dc98ea85b7872f4409131a790b91e7540953992886fc268b7ba5c96820e4' )
45
45
st . equal ( tx . hash ( true ) . toString ( 'hex' ) , '0f09dc98ea85b7872f4409131a790b91e7540953992886fc268b7ba5c96820e4' )
46
46
st . equal ( tx . hash ( false ) . toString ( 'hex' ) , 'f97c73fdca079da7652dbc61a46cd5aeef804008e057be3e712c43eac389aaf0' )
@@ -153,7 +153,7 @@ tape('[Transaction]: Basic functions', function (t) {
153
153
var tx = new Transaction ( )
154
154
st . equals ( tx . getDataFee ( ) . toNumber ( ) , 0 )
155
155
156
- tx = new Transaction ( txFixtures [ 2 ] . raw )
156
+ tx = new Transaction ( txFixtures [ 3 ] . raw )
157
157
st . equals ( tx . getDataFee ( ) . toNumber ( ) , 2496 )
158
158
159
159
st . end ( )
@@ -185,6 +185,42 @@ tape('[Transaction]: Basic functions', function (t) {
185
185
st . end ( )
186
186
} )
187
187
188
+ t . test ( 'Verify EIP155 Signature before and after signing with private key' , function ( st ) {
189
+ // Inputs and expected results for this test are taken directly from the example in https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
190
+ var txRaw = [
191
+ '0x09' ,
192
+ '0x4a817c800' ,
193
+ '0x5208' ,
194
+ '0x3535353535353535353535353535353535353535' ,
195
+ '0x0de0b6b3a7640000' ,
196
+ '0x'
197
+ ]
198
+ var privateKey = Buffer . from ( '4646464646464646464646464646464646464646464646464646464646464646' , 'hex' )
199
+ var pt = new Transaction ( txRaw , { chain : 1 } )
200
+ st . equal ( pt . serialize ( ) . toString ( 'hex' ) , 'ec098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080018080' )
201
+ pt . sign ( privateKey )
202
+ st . equal ( pt . hash ( false ) . toString ( 'hex' ) , 'daf5a779ae972f972197303d7b574746c7ef83eadac0f2791ad23db92e4c8e53' )
203
+ st . equal ( pt . serialize ( ) . toString ( 'hex' ) , 'f86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83' )
204
+ st . end ( )
205
+ } )
206
+
207
+ t . test ( 'Serialize correctly after being signed with EIP155 Signature for tx created on ropsten' , function ( st ) {
208
+ var txRaw = [
209
+ '0x1' ,
210
+ '0x02540be400' ,
211
+ '0x5208' ,
212
+ '0xd7250824390ec5c8b71d856b5de895e271170d9d' ,
213
+ '0x0de0b6b3a7640000' ,
214
+ '0x'
215
+ ]
216
+
217
+ var privateKey = Buffer . from ( 'DE3128752F183E8930D7F00A2AAA302DCB5E700B2CBA2D8CA5795660F07DEFD5' , 'hex' )
218
+ var pt = new Transaction ( txRaw , { chain : 3 } )
219
+ pt . sign ( privateKey )
220
+ st . equal ( pt . serialize ( ) . toString ( 'hex' ) , 'f86c018502540be40082520894d7250824390ec5c8b71d856b5de895e271170d9d880de0b6b3a76400008029a0d3512c68099d184ccf54f44d9d6905bff303128574b663dcf10b4c726ddd8133a0628acc8f481dea593f13309dfc5f0340f83fdd40cf9fbe47f782668f6f3aec74' )
221
+ st . end ( )
222
+ } )
223
+
188
224
t . test ( 'sign tx with chainId specified in params' , function ( st ) {
189
225
var tx = new Transaction ( { chainId : 42 } )
190
226
st . equal ( tx . getChainId ( ) , 42 )
@@ -202,4 +238,21 @@ tape('[Transaction]: Basic functions', function (t) {
202
238
st . equal ( tx . getChainId ( ) , 0x16b2 )
203
239
st . end ( )
204
240
} )
241
+
242
+ t . test ( 'EIP155 hashing when singing' , function ( st ) {
243
+ txFixtures . slice ( 0 , 3 ) . forEach ( function ( txData ) {
244
+ const tx = new Transaction ( txData . raw . slice ( 0 , 6 ) , { chain : 1 } )
245
+
246
+ var privKey = new Buffer ( txData . privateKey , 'hex' )
247
+ tx . sign ( privKey )
248
+
249
+ st . equal (
250
+ tx . getSenderAddress ( ) . toString ( 'hex' ) ,
251
+ txData . sendersAddress ,
252
+ 'computed sender address should equal the fixture\'s one'
253
+ )
254
+ } )
255
+
256
+ st . end ( )
257
+ } )
205
258
} )
0 commit comments