1
1
import tape from 'tape'
2
2
import { Buffer } from 'buffer'
3
- import {
4
- BN ,
5
- rlp ,
6
- zeros ,
7
- privateToPublic ,
8
- toBuffer ,
9
- bufferToHex ,
10
- unpadBuffer ,
11
- } from 'ethereumjs-util'
3
+ import { BN , rlp , privateToPublic , toBuffer , bufferToHex , unpadBuffer } from 'ethereumjs-util'
12
4
import Common from '@ethereumjs/common'
13
5
import { LegacyTransaction , TxData } from '../src'
14
6
import { TxsJsonEntry , VitaliksTestsDataEntry } from './types'
15
7
16
8
const txFixtures : TxsJsonEntry [ ] = require ( './json/txs.json' )
17
9
const txFixturesEip155 : VitaliksTestsDataEntry [ ] = require ( './json/ttTransactionTestEip155VitaliksTests.json' )
18
10
19
- tape ( '[Transaction]: Basic functions ' , function ( t ) {
11
+ tape ( '[Transaction]' , function ( t ) {
20
12
const transactions : LegacyTransaction [ ] = [ ]
21
13
22
- t . test ( 'should initialize correctly' , function ( st ) {
23
- let tx = LegacyTransaction . fromTxData ( { } )
24
- st . equal ( tx . common . hardfork ( ) , 'berlin' , 'should initialize with correct default HF' )
25
- st . ok ( Object . isFrozen ( tx ) , 'tx should be frozen by default' )
26
-
27
- const common = new Common ( { chain : 'mainnet' , hardfork : 'spuriousDragon' } )
28
- tx = LegacyTransaction . fromTxData ( { } , { common } )
29
- st . equal ( tx . common . hardfork ( ) , 'spuriousDragon' , 'should initialize with correct HF provided' )
30
-
31
- common . setHardfork ( 'byzantium' )
32
- st . equal (
33
- tx . common . hardfork ( ) ,
34
- 'spuriousDragon' ,
35
- 'should stay on correct HF if outer common HF changes'
36
- )
37
-
38
- tx = LegacyTransaction . fromTxData ( { } , { freeze : false } )
39
- st . ok ( ! Object . isFrozen ( tx ) , 'tx should not be frozen when freeze deactivated in options' )
40
-
41
- // Perform the same test as above, but now using a different construction method. This also implies that passing on the
42
- // options object works as expected.
43
- const rlpData = tx . serialize ( )
44
-
45
- const zero = Buffer . alloc ( 0 )
46
- const valuesArray = [ zero , zero , zero , zero , zero , zero ]
47
-
48
- tx = LegacyTransaction . fromRlpSerializedTx ( rlpData )
49
- st . ok ( Object . isFrozen ( tx ) , 'tx should be frozen by default' )
50
-
51
- tx = LegacyTransaction . fromRlpSerializedTx ( rlpData , { freeze : false } )
52
- st . ok ( ! Object . isFrozen ( tx ) , 'tx should not be frozen when freeze deactivated in options' )
53
-
54
- tx = LegacyTransaction . fromValuesArray ( valuesArray )
55
- st . ok ( Object . isFrozen ( tx ) , 'tx should be frozen by default' )
56
-
57
- tx = LegacyTransaction . fromValuesArray ( valuesArray , { freeze : false } )
58
- st . ok ( ! Object . isFrozen ( tx ) , 'tx should not be frozen when freeze deactivated in options' )
59
-
60
- st . end ( )
61
- } )
62
-
63
- t . test ( 'should decode transactions' , function ( st ) {
14
+ t . test ( 'Initialization -> decode with fromValuesArray()' , function ( st ) {
64
15
txFixtures . slice ( 0 , 4 ) . forEach ( function ( tx : any ) {
65
16
const txData = tx . raw . map ( toBuffer )
66
17
const pt = LegacyTransaction . fromValuesArray ( txData )
@@ -80,7 +31,7 @@ tape('[Transaction]: Basic functions', function (t) {
80
31
st . end ( )
81
32
} )
82
33
83
- t . test ( 'should serialize' , function ( st ) {
34
+ t . test ( 'serialize() ' , function ( st ) {
84
35
transactions . forEach ( function ( tx , i ) {
85
36
const s1 = tx . serialize ( )
86
37
const s2 = rlp . encode ( txFixtures [ i ] . raw )
@@ -89,7 +40,7 @@ tape('[Transaction]: Basic functions', function (t) {
89
40
st . end ( )
90
41
} )
91
42
92
- t . test ( 'should hash' , function ( st ) {
43
+ t . test ( 'hash() ' , function ( st ) {
93
44
const common = new Common ( {
94
45
chain : 'mainnet' ,
95
46
hardfork : 'tangerineWhistle' ,
@@ -112,7 +63,7 @@ tape('[Transaction]: Basic functions', function (t) {
112
63
st . end ( )
113
64
} )
114
65
115
- t . test ( 'should hash with defined chainId' , function ( st ) {
66
+ t . test ( 'hash() -> with defined chainId' , function ( st ) {
116
67
const tx = LegacyTransaction . fromValuesArray ( txFixtures [ 4 ] . raw . map ( toBuffer ) )
117
68
st . equal (
118
69
tx . hash ( ) . toString ( 'hex' ) ,
@@ -129,43 +80,11 @@ tape('[Transaction]: Basic functions', function (t) {
129
80
st . end ( )
130
81
} )
131
82
132
- t . test ( 'should verify Signatures' , function ( st ) {
133
- transactions . forEach ( function ( tx ) {
134
- st . equals ( ( < LegacyTransaction > tx ) . verifySignature ( ) , true )
135
- } )
136
- st . end ( )
137
- } )
138
-
139
- t . test ( 'should not verify invalid signatures' , function ( st ) {
140
- const txs : LegacyTransaction [ ] = [ ]
141
-
142
- txFixtures . slice ( 0 , 4 ) . forEach ( function ( txFixture : any ) {
143
- const txData = txFixture . raw . map ( toBuffer )
144
- // set `s` to zero
145
- txData [ 8 ] = zeros ( 32 )
146
- const tx = LegacyTransaction . fromValuesArray ( txData )
147
- txs . push ( tx )
148
- } )
149
-
150
- txs . forEach ( function ( tx ) {
151
- st . equals ( tx . verifySignature ( ) , false )
152
-
153
- st . ok (
154
- tx . validate ( true ) . includes ( 'Invalid Signature' ) ,
155
- 'should give a string about not verifying signatures'
156
- )
157
-
158
- st . notOk ( tx . validate ( ) , 'should validate correctly' )
159
- } )
160
-
161
- st . end ( )
162
- } )
163
-
164
- t . test ( 'should sign tx' , function ( st ) {
83
+ t . test ( 'sign()' , function ( st ) {
165
84
transactions . forEach ( function ( tx , i ) {
166
85
const { privateKey } = txFixtures [ i ]
167
86
if ( privateKey ) {
168
- st . ok ( tx . sign ( Buffer . from ( privateKey , 'hex' ) ) )
87
+ st . ok ( tx . sign ( Buffer . from ( privateKey , 'hex' ) ) , 'should sign tx' )
169
88
}
170
89
} )
171
90
st . end ( )
0 commit comments