@@ -6,16 +6,19 @@ import { BaseTransaction } from '../src/baseTransaction'
6
6
import { privateToPublic } from 'ethereumjs-util'
7
7
8
8
tape ( '[BaseTransaction]' , function ( t ) {
9
+ // EIP-2930 is not enabled in Common by default (2021-03-06)
10
+ const common = new Common ( { chain : 'mainnet' , hardfork : 'berlin' } )
11
+
9
12
const legacyFixtures : TxsJsonEntry [ ] = require ( './json/txs.json' )
10
13
const legacyTxs : BaseTransaction < Transaction > [ ] = [ ]
11
14
legacyFixtures . slice ( 0 , 4 ) . forEach ( function ( tx : any ) {
12
- legacyTxs . push ( Transaction . fromTxData ( tx . data ) )
15
+ legacyTxs . push ( Transaction . fromTxData ( tx . data , { common } ) )
13
16
} )
14
17
15
18
const eip2930Fixtures = require ( './json/eip2930txs.json' )
16
19
const eip2930Txs : BaseTransaction < AccessListEIP2930Transaction > [ ] = [ ]
17
20
eip2930Fixtures . forEach ( function ( tx : any ) {
18
- eip2930Txs . push ( AccessListEIP2930Transaction . fromTxData ( tx . data ) )
21
+ eip2930Txs . push ( AccessListEIP2930Transaction . fromTxData ( tx . data , { common } ) )
19
22
} )
20
23
21
24
const zero = Buffer . alloc ( 0 )
@@ -38,58 +41,58 @@ tape('[BaseTransaction]', function (t) {
38
41
39
42
t . test ( 'Initialization' , function ( st ) {
40
43
for ( const txType of txTypes ) {
41
- let tx = txType . class . fromTxData ( { } )
44
+ let tx = txType . class . fromTxData ( { } , { common } )
42
45
st . equal (
43
46
tx . common . hardfork ( ) ,
44
47
'berlin' ,
45
48
`${ txType . name } : should initialize with correct default HF`
46
49
)
47
50
st . ok ( Object . isFrozen ( tx ) , `${ txType . name } : tx should be frozen by default` )
48
51
49
- const common = new Common ( {
52
+ const initCommon = new Common ( {
50
53
chain : 'mainnet' ,
51
54
hardfork : 'istanbul' ,
52
55
eips : [ 2718 , 2929 , 2930 ] ,
53
56
} )
54
- tx = txType . class . fromTxData ( { } , { common } )
57
+ tx = txType . class . fromTxData ( { } , { common : initCommon } )
55
58
st . equal (
56
59
tx . common . hardfork ( ) ,
57
60
'istanbul' ,
58
61
`${ txType . name } : should initialize with correct HF provided`
59
62
)
60
63
61
- common . setHardfork ( 'byzantium' )
64
+ initCommon . setHardfork ( 'byzantium' )
62
65
st . equal (
63
66
tx . common . hardfork ( ) ,
64
67
'istanbul' ,
65
68
`${ txType . name } : should stay on correct HF if outer common HF changes`
66
69
)
67
70
68
- tx = txType . class . fromTxData ( { } , { freeze : false } )
69
- tx = txType . class . fromTxData ( { } , { freeze : false } )
71
+ tx = txType . class . fromTxData ( { } , { common , freeze : false } )
72
+ tx = txType . class . fromTxData ( { } , { common , freeze : false } )
70
73
st . ok (
71
74
! Object . isFrozen ( tx ) ,
72
75
`${ txType . name } : tx should not be frozen when freeze deactivated in options`
73
76
)
74
77
75
78
// Perform the same test as above, but now using a different construction method. This also implies that passing on the
76
79
// options object works as expected.
77
- tx = txType . class . fromTxData ( { } , { freeze : false } )
80
+ tx = txType . class . fromTxData ( { } , { common , freeze : false } )
78
81
const rlpData = tx . serialize ( )
79
82
80
- tx = txType . class . fromRlpSerializedTx ( rlpData )
83
+ tx = txType . class . fromRlpSerializedTx ( rlpData , { common } )
81
84
st . ok ( Object . isFrozen ( tx ) , `${ txType . name } : tx should be frozen by default` )
82
85
83
- tx = txType . class . fromRlpSerializedTx ( rlpData , { freeze : false } )
86
+ tx = txType . class . fromRlpSerializedTx ( rlpData , { common , freeze : false } )
84
87
st . ok (
85
88
! Object . isFrozen ( tx ) ,
86
89
`${ txType . name } : tx should not be frozen when freeze deactivated in options`
87
90
)
88
91
89
- tx = txType . class . fromValuesArray ( txType . values )
92
+ tx = txType . class . fromValuesArray ( txType . values , { common } )
90
93
st . ok ( Object . isFrozen ( tx ) , `${ txType . name } : tx should be frozen by default` )
91
94
92
- tx = txType . class . fromValuesArray ( txType . values , { freeze : false } )
95
+ tx = txType . class . fromValuesArray ( txType . values , { common , freeze : false } )
93
96
st . ok (
94
97
! Object . isFrozen ( tx ) ,
95
98
`${ txType . name } : tx should not be frozen when freeze deactivated in options`
@@ -102,11 +105,11 @@ tape('[BaseTransaction]', function (t) {
102
105
for ( const txType of txTypes ) {
103
106
txType . txs . forEach ( function ( tx : any ) {
104
107
st . ok (
105
- txType . class . fromRlpSerializedTx ( tx . serialize ( ) ) ,
108
+ txType . class . fromRlpSerializedTx ( tx . serialize ( ) , { common } ) ,
106
109
`${ txType . name } : should do roundtrip serialize() -> fromRlpSerializedTx()`
107
110
)
108
111
st . ok (
109
- txType . class . fromSerializedTx ( tx . serialize ( ) ) ,
112
+ txType . class . fromSerializedTx ( tx . serialize ( ) , { common } ) ,
110
113
`${ txType . name } : should do roundtrip serialize() -> fromRlpSerializedTx()`
111
114
)
112
115
} )
@@ -118,7 +121,7 @@ tape('[BaseTransaction]', function (t) {
118
121
for ( const txType of txTypes ) {
119
122
txType . txs . forEach ( function ( tx : any ) {
120
123
st . ok (
121
- txType . class . fromValuesArray ( tx . raw ( true ) ) ,
124
+ txType . class . fromValuesArray ( tx . raw ( true ) , { common } ) ,
122
125
`${ txType . name } : should do roundtrip raw() -> fromValuesArray()`
123
126
)
124
127
} )
@@ -140,7 +143,7 @@ tape('[BaseTransaction]', function (t) {
140
143
txType . fixtures . slice ( 0 , 4 ) . forEach ( function ( txFixture : any ) {
141
144
// set `s` to zero
142
145
txFixture . data . s = `0x` + '0' . repeat ( 16 )
143
- const tx = txType . class . fromTxData ( txFixture . data )
146
+ const tx = txType . class . fromTxData ( txFixture . data , { common } )
144
147
st . equals ( tx . verifySignature ( ) , false , `${ txType . name } : signature should not be valid` )
145
148
st . ok (
146
149
( < string [ ] > tx . validate ( true ) ) . includes ( 'Invalid Signature' ) ,
0 commit comments