@@ -5,10 +5,9 @@ import { assert, describe, it } from 'vitest'
5
5
6
6
import { createFeeMarket1559Tx } from '../src/index.js'
7
7
8
- import testdata from './json /eip1559.json ' // Source: Besu
8
+ import { eip1559Data } from './testData /eip1559.js ' // Source: Besu
9
9
10
- import type { FeeMarketEIP1559TxData , JSONTx } from '../src/index.js'
11
- import type { PrefixedHexString } from '@ethereumjs/util'
10
+ import type { JSONTx } from '../src/index.js'
12
11
13
12
const common = createCustomCommon ( { chainId : 4 } , Mainnet )
14
13
common . setHardfork ( Hardfork . London )
@@ -106,21 +105,21 @@ describe('[FeeMarket1559Tx]', () => {
106
105
} )
107
106
108
107
it ( 'sign()' , ( ) => {
109
- for ( let index = 0 ; index < testdata . length ; index ++ ) {
110
- const data = testdata [ index ]
111
- const pkey = hexToBytes ( data . privateKey as PrefixedHexString )
112
- const txn = createFeeMarket1559Tx ( data as FeeMarketEIP1559TxData , { common } )
108
+ for ( let index = 0 ; index < eip1559Data . length ; index ++ ) {
109
+ const data = eip1559Data [ index ]
110
+ const pkey = hexToBytes ( data . privateKey )
111
+ const txn = createFeeMarket1559Tx ( data , { common } )
113
112
const signed = txn . sign ( pkey )
114
113
const rlpSerialized = RLP . encode ( Uint8Array . from ( signed . serialize ( ) ) )
115
114
assert . ok (
116
- equalsBytes ( rlpSerialized , hexToBytes ( data . signedTransactionRLP as PrefixedHexString ) ) ,
115
+ equalsBytes ( rlpSerialized , hexToBytes ( data . signedTransactionRLP ) ) ,
117
116
'Should sign txs correctly' ,
118
117
)
119
118
}
120
119
} )
121
120
122
121
it ( 'addSignature() -> correctly adds correct signature values' , ( ) => {
123
- const privKey = hexToBytes ( testdata [ 0 ] . privateKey as PrefixedHexString )
122
+ const privKey = hexToBytes ( eip1559Data [ 0 ] . privateKey )
124
123
const tx = createFeeMarket1559Tx ( { } )
125
124
const signedTx = tx . sign ( privKey )
126
125
const addSignatureTx = tx . addSignature ( signedTx . v ! , signedTx . r ! , signedTx . s ! )
@@ -129,7 +128,7 @@ describe('[FeeMarket1559Tx]', () => {
129
128
} )
130
129
131
130
it ( 'addSignature() -> correctly converts raw ecrecover values' , ( ) => {
132
- const privKey = hexToBytes ( testdata [ 0 ] . privateKey as PrefixedHexString )
131
+ const privKey = hexToBytes ( eip1559Data [ 0 ] . privateKey )
133
132
const tx = createFeeMarket1559Tx ( { } )
134
133
135
134
const msgHash = tx . getHashedMessageToSign ( )
@@ -142,7 +141,7 @@ describe('[FeeMarket1559Tx]', () => {
142
141
} )
143
142
144
143
it ( 'addSignature() -> throws when adding the wrong v value' , ( ) => {
145
- const privKey = hexToBytes ( testdata [ 0 ] . privateKey as PrefixedHexString )
144
+ const privKey = hexToBytes ( eip1559Data [ 0 ] . privateKey )
146
145
const tx = createFeeMarket1559Tx ( { } )
147
146
148
147
const msgHash = tx . getHashedMessageToSign ( )
@@ -155,9 +154,9 @@ describe('[FeeMarket1559Tx]', () => {
155
154
} )
156
155
157
156
it ( 'hash()' , ( ) => {
158
- const data = testdata [ 0 ]
159
- const pkey = hexToBytes ( data . privateKey as PrefixedHexString )
160
- let txn = createFeeMarket1559Tx ( data as FeeMarketEIP1559TxData , { common } )
157
+ const data = eip1559Data [ 0 ]
158
+ const pkey = hexToBytes ( data . privateKey )
159
+ let txn = createFeeMarket1559Tx ( data , { common } )
161
160
let signed = txn . sign ( pkey )
162
161
const expectedHash = hexToBytes (
163
162
'0x2e564c87eb4b40e7f469b2eec5aa5d18b0b46a24e8bf0919439cfb0e8fcae446' ,
@@ -166,7 +165,7 @@ describe('[FeeMarket1559Tx]', () => {
166
165
equalsBytes ( signed . hash ( ) , expectedHash ) ,
167
166
'Should provide the correct hash when frozen' ,
168
167
)
169
- txn = createFeeMarket1559Tx ( data as FeeMarketEIP1559TxData , {
168
+ txn = createFeeMarket1559Tx ( data , {
170
169
common,
171
170
freeze : false ,
172
171
} )
@@ -178,9 +177,9 @@ describe('[FeeMarket1559Tx]', () => {
178
177
} )
179
178
180
179
it ( 'freeze property propagates from unsigned tx to signed tx' , ( ) => {
181
- const data = testdata [ 0 ]
182
- const pkey = hexToBytes ( data . privateKey as PrefixedHexString )
183
- const txn = createFeeMarket1559Tx ( data as FeeMarketEIP1559TxData , {
180
+ const data = eip1559Data [ 0 ]
181
+ const pkey = hexToBytes ( data . privateKey )
182
+ const txn = createFeeMarket1559Tx ( data , {
184
183
common,
185
184
freeze : false ,
186
185
} )
@@ -190,9 +189,9 @@ describe('[FeeMarket1559Tx]', () => {
190
189
} )
191
190
192
191
it ( 'common propagates from the common of tx, not the common in TxOptions' , ( ) => {
193
- const data = testdata [ 0 ]
194
- const pkey = hexToBytes ( data . privateKey as PrefixedHexString )
195
- const txn = createFeeMarket1559Tx ( data as FeeMarketEIP1559TxData , {
192
+ const data = eip1559Data [ 0 ]
193
+ const pkey = hexToBytes ( data . privateKey )
194
+ const txn = createFeeMarket1559Tx ( data , {
196
195
common,
197
196
freeze : false ,
198
197
} )
@@ -239,9 +238,9 @@ describe('[FeeMarket1559Tx]', () => {
239
238
} )
240
239
241
240
it ( 'toJSON()' , ( ) => {
242
- const data = testdata [ 0 ]
243
- const pkey = hexToBytes ( data . privateKey as PrefixedHexString )
244
- const txn = createFeeMarket1559Tx ( data as FeeMarketEIP1559TxData , { common } )
241
+ const data = eip1559Data [ 0 ]
242
+ const pkey = hexToBytes ( data . privateKey )
243
+ const txn = createFeeMarket1559Tx ( data , { common } )
245
244
const signed = txn . sign ( pkey )
246
245
247
246
const json = signed . toJSON ( )
0 commit comments