@@ -15,24 +15,15 @@ import {
1515} from '@ethereumjs/common'
1616import { Ethash } from '@ethereumjs/ethash'
1717import { createFeeMarket1559Tx , createLegacyTx } from '@ethereumjs/tx'
18- import {
19- Address ,
20- concatBytes ,
21- createAccount ,
22- createAddressFromPrivateKey ,
23- createZeroAddress ,
24- hexToBytes ,
25- } from '@ethereumjs/util'
18+ import { concatBytes , createAccount , createZeroAddress } from '@ethereumjs/util'
2619import { assert , describe , expect , it } from 'vitest'
2720
2821import { buildBlock , createVM , runBlock } from '../../src/index.ts'
2922
3023import { setBalance } from './utils.ts'
3124
3225import type { Blockchain , ConsensusDict } from '@ethereumjs/blockchain'
33-
34- const privateKey = hexToBytes ( '0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' )
35- const pKeyAddress = createAddressFromPrivateKey ( privateKey )
26+ import { SIGNER_A } from '@ethereumjs/testdata'
3627
3728describe ( 'BlockBuilder' , ( ) => {
3829 it ( 'should build a valid block' , async ( ) => {
@@ -41,7 +32,7 @@ describe('BlockBuilder', () => {
4132 const blockchain = await createBlockchain ( { genesisBlock, common, validateConsensus : false } )
4233 const vm = await createVM ( { common, blockchain } )
4334
44- await setBalance ( vm , pKeyAddress )
35+ await setBalance ( vm , SIGNER_A . address )
4536
4637 const vmCopy = await vm . shallowCopy ( )
4738
@@ -55,7 +46,7 @@ describe('BlockBuilder', () => {
5546 const tx = createLegacyTx (
5647 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , gasPrice : 1 } ,
5748 { common, freeze : false } ,
58- ) . sign ( privateKey )
49+ ) . sign ( SIGNER_A . privateKey )
5950
6051 await blockBuilder . addTransaction ( tx )
6152 const { block } = await blockBuilder . build ( )
@@ -114,7 +105,7 @@ describe('BlockBuilder', () => {
114105 } )
115106 const vm = await createVM ( { common, blockchain } )
116107
117- await setBalance ( vm , pKeyAddress )
108+ await setBalance ( vm , SIGNER_A . address )
118109
119110 const blockBuilder = await buildBlock ( vm , {
120111 parentBlock : genesisBlock ,
@@ -125,7 +116,7 @@ describe('BlockBuilder', () => {
125116 const tx = createLegacyTx (
126117 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , gasPrice : 1 } ,
127118 { common, freeze : false } ,
128- ) . sign ( privateKey )
119+ ) . sign ( SIGNER_A . privateKey )
129120
130121 await blockBuilder . addTransaction ( tx )
131122
@@ -143,14 +134,6 @@ describe('BlockBuilder', () => {
143134 } )
144135
145136 it ( 'should correctly seal a PoA block' , async ( ) => {
146- const signer = {
147- address : new Address ( hexToBytes ( '0x0b90087d864e82a284dca15923f3776de6bb016f' ) ) ,
148- privateKey : hexToBytes ( '0x64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' ) ,
149- publicKey : hexToBytes (
150- '0x40b2ebdf4b53206d2d3d3d59e7e2f13b1ea68305aec71d5d24cefe7f24ecae886d241f9267f04702d7f693655eb7b4aa23f30dcd0c3c5f2b970aad7c8a828195' ,
151- ) ,
152- }
153-
154137 // const common = new Common({ chain: Chain.Rinkeby, hardfork: Hardfork.Istanbul })
155138 const consensusConfig = {
156139 clique : {
@@ -187,11 +170,7 @@ describe('BlockBuilder', () => {
187170 alloc : { } ,
188171 }
189172
190- const A = {
191- address : new Address ( hexToBytes ( '0x0b90087d864e82a284dca15923f3776de6bb016f' ) ) ,
192- privateKey : hexToBytes ( '0x64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' ) ,
193- }
194- const addr = A . address . toString ( ) . slice ( 2 )
173+ const addr = SIGNER_A . address . toString ( ) . slice ( 2 )
195174
196175 const extraData2 = `0x${ '0' . repeat ( 64 ) } ${ addr } ${ '0' . repeat ( 130 ) } `
197176 const chainData = {
@@ -205,8 +184,12 @@ describe('BlockBuilder', () => {
205184 } )
206185
207186 // extraData: [vanity, activeSigner, seal]
208- const extraData = concatBytes ( new Uint8Array ( 32 ) , signer . address . toBytes ( ) , new Uint8Array ( 65 ) )
209- const cliqueSignerKey = signer . privateKey
187+ const extraData = concatBytes (
188+ new Uint8Array ( 32 ) ,
189+ SIGNER_A . address . toBytes ( ) ,
190+ new Uint8Array ( 65 ) ,
191+ )
192+ const cliqueSignerKey = SIGNER_A . privateKey
210193 const genesisBlock = createSealedCliqueBlock (
211194 { header : { gasLimit : 50000 , extraData } } ,
212195 cliqueSignerKey ,
@@ -216,7 +199,7 @@ describe('BlockBuilder', () => {
216199 const vm = await createVM ( { common, blockchain } )
217200
218201 // add balance for tx
219- await vm . stateManager . putAccount ( signer . address , createAccount ( { balance : 100000 } ) )
202+ await vm . stateManager . putAccount ( SIGNER_A . address , createAccount ( { balance : 100000 } ) )
220203
221204 const blockBuilder = await buildBlock ( vm , {
222205 parentBlock : genesisBlock ,
@@ -228,16 +211,19 @@ describe('BlockBuilder', () => {
228211 const tx = createLegacyTx (
229212 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , gasPrice : 1 } ,
230213 { common, freeze : false } ,
231- ) . sign ( signer . privateKey )
214+ ) . sign ( SIGNER_A . privateKey )
232215
233216 await blockBuilder . addTransaction ( tx )
234217
235218 const { block } = await blockBuilder . build ( )
236219
237- assert . isTrue ( cliqueVerifySignature ( block . header , [ signer . address ] ) , 'should verify signature' )
220+ assert . isTrue (
221+ cliqueVerifySignature ( block . header , [ SIGNER_A . address ] ) ,
222+ 'should verify signature' ,
223+ )
238224 assert . deepEqual (
239225 cliqueSigner ( block . header ) ,
240- signer . address ,
226+ SIGNER_A . address ,
241227 'should recover the correct signer address' ,
242228 )
243229 } )
@@ -248,7 +234,7 @@ describe('BlockBuilder', () => {
248234 const blockchain = await createBlockchain ( { genesisBlock, common, validateConsensus : false } )
249235 const vm = await createVM ( { common, blockchain } )
250236
251- await setBalance ( vm , pKeyAddress )
237+ await setBalance ( vm , SIGNER_A . address )
252238
253239 let blockBuilder = await buildBlock ( vm , {
254240 parentBlock : genesisBlock ,
@@ -258,7 +244,7 @@ describe('BlockBuilder', () => {
258244 const tx = createLegacyTx (
259245 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , gasPrice : 1 } ,
260246 { common, freeze : false } ,
261- ) . sign ( privateKey )
247+ ) . sign ( SIGNER_A . privateKey )
262248
263249 await blockBuilder . addTransaction ( tx )
264250 await blockBuilder . build ( )
@@ -279,7 +265,7 @@ describe('BlockBuilder', () => {
279265 const tx2 = createLegacyTx (
280266 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , gasPrice : 1 , nonce : 1 } ,
281267 { common, freeze : false } ,
282- ) . sign ( privateKey )
268+ ) . sign ( SIGNER_A . privateKey )
283269
284270 await blockBuilder . addTransaction ( tx2 )
285271 await blockBuilder . revert ( )
@@ -327,7 +313,7 @@ describe('BlockBuilder', () => {
327313 const blockchain = await createBlockchain ( { genesisBlock, common, validateConsensus : false } )
328314 const vm = await createVM ( { common, blockchain } )
329315
330- await setBalance ( vm , pKeyAddress )
316+ await setBalance ( vm , SIGNER_A . address )
331317
332318 const vmCopy = await vm . shallowCopy ( )
333319
@@ -341,12 +327,12 @@ describe('BlockBuilder', () => {
341327 const tx1 = createLegacyTx (
342328 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , gasPrice : 1 } ,
343329 { common, freeze : false } ,
344- ) . sign ( privateKey )
330+ ) . sign ( SIGNER_A . privateKey )
345331
346332 const tx2 = createFeeMarket1559Tx (
347333 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , maxFeePerGas : 10 } ,
348334 { common, freeze : false } ,
349- ) . sign ( privateKey )
335+ ) . sign ( SIGNER_A . privateKey )
350336
351337 for ( const tx of [ tx1 , tx2 ] ) {
352338 await expect ( async ( ) => {
@@ -359,12 +345,12 @@ describe('BlockBuilder', () => {
359345 const tx3 = createLegacyTx (
360346 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , gasPrice : 101 } ,
361347 { common, freeze : false } ,
362- ) . sign ( privateKey )
348+ ) . sign ( SIGNER_A . privateKey )
363349
364350 const tx4 = createFeeMarket1559Tx (
365351 { to : createZeroAddress ( ) , value : 1000 , gasLimit : 21000 , maxFeePerGas : 101 , nonce : 1 } ,
366352 { common, freeze : false } ,
367- ) . sign ( privateKey )
353+ ) . sign ( SIGNER_A . privateKey )
368354
369355 for ( const tx of [ tx3 , tx4 ] ) {
370356 await blockBuilder . addTransaction ( tx )
0 commit comments