diff --git a/packages/block/test/eip1559block.spec.ts b/packages/block/test/eip1559block.spec.ts index d2abc8c6dd..69407c7bf1 100644 --- a/packages/block/test/eip1559block.spec.ts +++ b/packages/block/test/eip1559block.spec.ts @@ -414,7 +414,7 @@ describe('EIP1559 tests', () => { maxPriorityFeePerGas: BigInt(0), }, { common } - ).sign(hexToBytes('0x' + '46'.repeat(32))) + ).sign(hexToBytes(`0x${'46'.repeat(32)}`)) const block = Block.fromBlockData( { header: { diff --git a/packages/block/test/eip4895block.spec.ts b/packages/block/test/eip4895block.spec.ts index 6c2bae3174..a0747dab48 100644 --- a/packages/block/test/eip4895block.spec.ts +++ b/packages/block/test/eip4895block.spec.ts @@ -38,7 +38,7 @@ common.hardforkBlock = function (hardfork: string | undefined) { describe('EIP4895 tests', () => { it('should correctly generate withdrawalsRoot', async () => { // get withdwalsArray - const gethBlockBytesArray = RLP.decode(hexToBytes('0x' + gethWithdrawals8BlockRlp)) + const gethBlockBytesArray = RLP.decode(hexToBytes(`0x${gethWithdrawals8BlockRlp}`)) const withdrawals = (gethBlockBytesArray[3] as WithdrawalBytes[]).map((wa) => Withdrawal.fromValuesArray(wa) ) @@ -160,7 +160,7 @@ describe('EIP4895 tests', () => { const withdrawal = { index: BigInt(0), validatorIndex: BigInt(0), - address: new Address(hexToBytes('0x' + '20'.repeat(20))), + address: new Address(hexToBytes(`0x${'20'.repeat(20)}`)), amount: BigInt(1000), } @@ -185,7 +185,7 @@ describe('EIP4895 tests', () => { const withdrawal2 = { index: BigInt(1), validatorIndex: BigInt(11), - address: new Address(hexToBytes('0x' + '30'.repeat(20))), + address: new Address(hexToBytes(`0x${'30'.repeat(20)}`)), amount: BigInt(2000), } diff --git a/packages/block/test/from-beacon-payload.spec.ts b/packages/block/test/from-beacon-payload.spec.ts index 06f275657b..d8e0a5fc05 100644 --- a/packages/block/test/from-beacon-payload.spec.ts +++ b/packages/block/test/from-beacon-payload.spec.ts @@ -10,6 +10,8 @@ import * as payload87335 from './testdata/payload-slot-87335.json' import * as payload87475 from './testdata/payload-slot-87475.json' import * as testnetVerkleKaustinen from './testdata/testnetVerkleKaustinen.json' +import type { BeaconPayloadJson, VerkleExecutionWitness } from '../src/index.js' + describe('[fromExecutionPayloadJson]: 4844 devnet 5', () => { let common: Common beforeAll(async () => { @@ -27,7 +29,7 @@ describe('[fromExecutionPayloadJson]: 4844 devnet 5', () => { it('reconstruct cancun block with blob txs', async () => { for (const payload of [payload87335, payload87475]) { try { - const block = await Block.fromBeaconPayloadJson(payload, { common }) + const block = await Block.fromBeaconPayloadJson(payload as BeaconPayloadJson, { common }) const parentHeader = BlockHeader.fromHeaderData( { excessBlobGas: BigInt(0), blobGasUsed: block.header.excessBlobGas! + BigInt(393216) }, { common } @@ -44,7 +46,10 @@ describe('[fromExecutionPayloadJson]: 4844 devnet 5', () => { try { // construct a payload with differing block hash await Block.fromBeaconPayloadJson( - { ...payload87335, block_hash: payload87475.block_hash }, + { + ...payload87335, + block_hash: payload87475.block_hash, + } as BeaconPayloadJson, { common } ) assert.fail(`should have failed constructing the block`) @@ -61,7 +66,7 @@ describe('[fromExecutionPayloadJson]: 4844 devnet 5', () => { { ...payload87475, block_hash: '0x573714bdd0ca5e47bc32008751c4fc74237f8cb354fbc1475c1d0ece38236ea4', - }, + } as BeaconPayloadJson, { common } ) const parentHeader = BlockHeader.fromHeaderData({ excessBlobGas: BigInt(0) }, { common }) @@ -84,12 +89,14 @@ describe('[fromExecutionPayloadJson]: kaustinen', () => { }) it('reconstruct kaustinen block', async () => { assert.ok(common.isActivatedEIP(6800), 'verkle eip should be activated') - const block = await Block.fromBeaconPayloadJson(payloadKaustinen, { common }) + const block = await Block.fromBeaconPayloadJson(payloadKaustinen as BeaconPayloadJson, { + common, + }) // the witness object in payload has camel casing for now // the current block hash doesn't include witness data so deep match is required assert.deepEqual( block.executionWitness, - payloadKaustinen.execution_witness, + payloadKaustinen.execution_witness as VerkleExecutionWitness, 'execution witness should match' ) }) diff --git a/packages/blockchain/test/index.spec.ts b/packages/blockchain/test/index.spec.ts index 0badf1f26c..4229df50bb 100644 --- a/packages/blockchain/test/index.spec.ts +++ b/packages/blockchain/test/index.spec.ts @@ -9,7 +9,8 @@ import blocksData from './testdata/blocks_mainnet.json' import * as testDataPreLondon from './testdata/testdata_pre-london.json' import { createTestDB, generateBlockchain, generateBlocks, isConsecutive } from './util.js' -import type { BlockOptions } from '@ethereumjs/block' +import type { BlockData, BlockOptions } from '@ethereumjs/block' +import type { PrefixedHexString } from '@ethereumjs/util' describe('blockchain test', () => { it('should not crash on getting head of a blockchain without a genesis', async () => { @@ -54,7 +55,7 @@ describe('blockchain test', () => { it('should initialize correctly with Blockchain.fromBlocksData()', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const blockchain = await Blockchain.fromBlocksData(blocksData, { + const blockchain = await Blockchain.fromBlocksData(blocksData as BlockData[], { validateBlocks: true, validateConsensus: false, common, @@ -573,7 +574,7 @@ describe('blockchain test', () => { it('should add block with body', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesisRlp = hexToBytes(testDataPreLondon.genesisRLP) + const genesisRlp = hexToBytes(testDataPreLondon.genesisRLP as PrefixedHexString) const genesisBlock = Block.fromRLPSerializedBlock(genesisRlp, { common }) const blockchain = await Blockchain.create({ validateBlocks: true, @@ -581,7 +582,7 @@ describe('blockchain test', () => { genesisBlock, }) - const blockRlp = hexToBytes(testDataPreLondon.blocks[0].rlp) + const blockRlp = hexToBytes(testDataPreLondon.blocks[0].rlp as PrefixedHexString) const block = Block.fromRLPSerializedBlock(blockRlp, { common }) await blockchain.putBlock(block) }) diff --git a/packages/client/test/execution/vmexecution.spec.ts b/packages/client/test/execution/vmexecution.spec.ts index c3b774db88..c60ab27639 100644 --- a/packages/client/test/execution/vmexecution.spec.ts +++ b/packages/client/test/execution/vmexecution.spec.ts @@ -14,6 +14,77 @@ import blocksDataMainnet from '../testdata/blocks/mainnet.json' import testnet from '../testdata/common/testnet.json' import shanghaiJSON from '../testdata/geth-genesis/withdrawals.json' +import type { BlockData, ExecutionPayload } from '@ethereumjs/block' +import type { ChainConfig } from '@ethereumjs/common' + +const shanghaiPayload = { + blockNumber: '0x1', + parentHash: '0xfe950635b1bd2a416ff6283b0bbd30176e1b1125ad06fa729da9f3f4c1c61710', + feeRecipient: '0xaa00000000000000000000000000000000000000', + stateRoot: '0x23eadd91fca55c0e14034e4d63b2b3ed43f2e807b6bf4d276b784ac245e7fa3f', + receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', + logsBloom: + '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + gasLimit: '0x1c9c380', + gasUsed: '0x0', + timestamp: '0x2f', + extraData: '0x', + baseFeePerGas: '0x7', + blockHash: '0xd30a8c821078a9153a5cbc5ac9a2c5baca7f7885496f1f461dbfcb8dbe1fa0c0', + prevRandao: '0xff00000000000000000000000000000000000000000000000000000000000000', + transactions: [], + withdrawals: [ + { + index: '0x0', + validatorIndex: '0xffff', + address: '0x0000000000000000000000000000000000000000', + amount: '0x0', + }, + { + index: '0x1', + validatorIndex: '0x10000', + address: '0x0100000000000000000000000000000000000000', + amount: '0x100000000000000000000000000000000000000000000000000000000000000', + }, + { + index: '0x2', + validatorIndex: '0x10001', + address: '0x0200000000000000000000000000000000000000', + amount: '0x200000000000000000000000000000000000000000000000000000000000000', + }, + { + index: '0x3', + validatorIndex: '0x10002', + address: '0x0300000000000000000000000000000000000000', + amount: '0x300000000000000000000000000000000000000000000000000000000000000', + }, + { + index: '0x4', + validatorIndex: '0x10003', + address: '0x0400000000000000000000000000000000000000', + amount: '0x400000000000000000000000000000000000000000000000000000000000000', + }, + { + index: '0x5', + validatorIndex: '0x10004', + address: '0x0500000000000000000000000000000000000000', + amount: '0x500000000000000000000000000000000000000000000000000000000000000', + }, + { + index: '0x6', + validatorIndex: '0x10005', + address: '0x0600000000000000000000000000000000000000', + amount: '0x600000000000000000000000000000000000000000000000000000000000000', + }, + { + index: '0x7', + validatorIndex: '0x10006', + address: '0x0700000000000000000000000000000000000000', + amount: '0x700000000000000000000000000000000000000000000000000000000000000', + }, + ], +} + describe('[VMExecution]', async () => { it('Initialization', async () => { const vm = await VM.create() @@ -43,7 +114,7 @@ describe('[VMExecution]', async () => { let newHead = await exec.vm.blockchain.getIteratorHead!() assert.deepEqual(newHead.hash(), oldHead.hash(), 'should not modify blockchain on empty run') - blockchain = await Blockchain.fromBlocksData(blocksDataMainnet, { + blockchain = await Blockchain.fromBlocksData(blocksDataMainnet as BlockData[], { validateBlocks: true, validateConsensus: false, }) @@ -52,7 +123,7 @@ describe('[VMExecution]', async () => { newHead = await exec.vm.blockchain.getIteratorHead!() assert.equal(newHead.header.number, BigInt(5), 'should run all blocks') - const common = new Common({ chain: 'testnet', customChains: [testnet] }) + const common = new Common({ chain: 'testnet', customChains: [testnet] as ChainConfig[] }) exec = await testSetup(blockchain, common) await exec.run() assert.equal(exec.hardfork, 'byzantium', 'should update HF on block run') @@ -65,7 +136,7 @@ describe('[VMExecution]', async () => { }) let exec = await testSetup(blockchain) - blockchain = await Blockchain.fromBlocksData(blocksDataMainnet, { + blockchain = await Blockchain.fromBlocksData(blocksDataMainnet as BlockData[], { validateBlocks: true, validateConsensus: false, }) @@ -112,7 +183,7 @@ describe('[VMExecution]', async () => { let newHead = await exec.vm.blockchain.getIteratorHead!() assert.deepEqual(newHead.hash(), oldHead.hash(), 'should not modify blockchain on empty run') - blockchain = await Blockchain.fromBlocksData(blocksDataGoerli, { + blockchain = await Blockchain.fromBlocksData(blocksDataGoerli as BlockData[], { validateBlocks: true, validateConsensus: false, common, @@ -128,8 +199,7 @@ describe('[VMExecution]', async () => { engine: true, }) - // eslint-disable-next-line @typescript-eslint/no-use-before-define - const block = await Block.fromExecutionPayload(shanghaiPayload) + const block = await Block.fromExecutionPayload(shanghaiPayload as ExecutionPayload) const oldHead = await blockchain.getIteratorHead() const parentStateRoot = oldHead.header.stateRoot @@ -165,71 +235,3 @@ describe('[VMExecution]', async () => { closeRPC(server) }) }) - -const shanghaiPayload = { - blockNumber: '0x1', - parentHash: '0xfe950635b1bd2a416ff6283b0bbd30176e1b1125ad06fa729da9f3f4c1c61710', - feeRecipient: '0xaa00000000000000000000000000000000000000', - stateRoot: '0x23eadd91fca55c0e14034e4d63b2b3ed43f2e807b6bf4d276b784ac245e7fa3f', - receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', - logsBloom: - '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', - gasLimit: '0x1c9c380', - gasUsed: '0x0', - timestamp: '0x2f', - extraData: '0x', - baseFeePerGas: '0x7', - blockHash: '0xd30a8c821078a9153a5cbc5ac9a2c5baca7f7885496f1f461dbfcb8dbe1fa0c0', - prevRandao: '0xff00000000000000000000000000000000000000000000000000000000000000', - transactions: [], - withdrawals: [ - { - index: '0x0', - validatorIndex: '0xffff', - address: '0x0000000000000000000000000000000000000000', - amount: '0x0', - }, - { - index: '0x1', - validatorIndex: '0x10000', - address: '0x0100000000000000000000000000000000000000', - amount: '0x100000000000000000000000000000000000000000000000000000000000000', - }, - { - index: '0x2', - validatorIndex: '0x10001', - address: '0x0200000000000000000000000000000000000000', - amount: '0x200000000000000000000000000000000000000000000000000000000000000', - }, - { - index: '0x3', - validatorIndex: '0x10002', - address: '0x0300000000000000000000000000000000000000', - amount: '0x300000000000000000000000000000000000000000000000000000000000000', - }, - { - index: '0x4', - validatorIndex: '0x10003', - address: '0x0400000000000000000000000000000000000000', - amount: '0x400000000000000000000000000000000000000000000000000000000000000', - }, - { - index: '0x5', - validatorIndex: '0x10004', - address: '0x0500000000000000000000000000000000000000', - amount: '0x500000000000000000000000000000000000000000000000000000000000000', - }, - { - index: '0x6', - validatorIndex: '0x10005', - address: '0x0600000000000000000000000000000000000000', - amount: '0x600000000000000000000000000000000000000000000000000000000000000', - }, - { - index: '0x7', - validatorIndex: '0x10006', - address: '0x0700000000000000000000000000000000000000', - amount: '0x700000000000000000000000000000000000000000000000000000000000000', - }, - ], -} diff --git a/packages/client/test/net/protocol/ethprotocol.spec.ts b/packages/client/test/net/protocol/ethprotocol.spec.ts index 801c08b717..6296cb8aeb 100644 --- a/packages/client/test/net/protocol/ethprotocol.spec.ts +++ b/packages/client/test/net/protocol/ethprotocol.spec.ts @@ -224,7 +224,7 @@ describe('[EthProtocol]', () => { const eip2929Tx = TransactionFactory.fromTxData({ type: 1 }, { common: config.chainCommon }) const eip1559Tx = TransactionFactory.fromTxData({ type: 2 }, { common: config.chainCommon }) const blobTx = TransactionFactory.fromTxData( - { type: 3, to: Address.zero(), blobVersionedHashes: [hexToBytes('0x01' + '00'.repeat(31))] }, + { type: 3, to: Address.zero(), blobVersionedHashes: [hexToBytes(`0x01${'00'.repeat(31)}`)] }, { common: config.chainCommon } ) const res = p.encode(p.messages.filter((message) => message.name === 'Transactions')[0], [ diff --git a/packages/client/test/rpc/debug/storageRangeAt.spec.ts b/packages/client/test/rpc/debug/storageRangeAt.spec.ts index ef924de66d..3a33ff7773 100644 --- a/packages/client/test/rpc/debug/storageRangeAt.spec.ts +++ b/packages/client/test/rpc/debug/storageRangeAt.spec.ts @@ -36,12 +36,12 @@ const method = 'debug_storageRangeAt' } ``` */ -const storageBytecode: string = +const storageBytecode = '0x608060405234801561001057600080fd5b5060426000819055506001808190555060028081905550610123806100366000396000f3fe6080604052348015600f57600080fd5b506004361060465760003560e01c80630c55699c14604b578063a2e62045146065578063a56dfe4a14606d578063c5d7802e146087575b600080fd5b605160a1565b604051605c919060d4565b60405180910390f35b606b60a7565b005b607360b1565b604051607e919060d4565b60405180910390f35b608d60b7565b6040516098919060d4565b60405180910390f35b60005481565b6043600081905550565b60015481565b60025481565b6000819050919050565b60ce8160bd565b82525050565b600060208201905060e7600083018460c7565b9291505056fea2646970667358221220702e3426f9487bc4c75cca28733223e1292e723c32bbea553973c1ebeaeeb87d64736f6c63430008120033' /* Function selector of the contract's update() function. */ -const updateBytecode: string = '0xa2e62045' +const updateBytecode = '0xa2e62045' /* Contract used to test storageRangeAt(), compiled with solc 0.8.18+commit.87f61d96 ```sol @@ -53,7 +53,7 @@ const updateBytecode: string = '0xa2e62045' } ``` */ -const noStorageBytecode: string = +const noStorageBytecode = '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea26469706673582212202f85c21c604b5e0fde9dca0615b4dd49a586dd18ada5ad8b85aa950462e1e73664736f6c63430008120033' describe(method, () => { diff --git a/packages/client/test/rpc/engine/CLConnectionManager.spec.ts b/packages/client/test/rpc/engine/CLConnectionManager.spec.ts index 013682cc4c..c377092f7d 100644 --- a/packages/client/test/rpc/engine/CLConnectionManager.spec.ts +++ b/packages/client/test/rpc/engine/CLConnectionManager.spec.ts @@ -7,30 +7,40 @@ import { CLConnectionManager, ConnectionStatus } from '../../../src/rpc/modules/ import { Event } from '../../../src/types' import genesisJSON from '../../testdata/geth-genesis/post-merge.json' +import type { PrefixedHexString } from '@ethereumjs/util' + const payload = { payload: { - parentHash: '0xff10941138a407482a2651e3eaf0132f66c82ea1386a1f43287aa0fd6298698a', - feeRecipient: '0xf97e180c050e5ab072211ad2c213eb5aee4df134', - stateRoot: '0x9933050575efffde6b1cdbfb9bca2f1a82df1c3e691f5878afe85eaf21df7d4f', - receiptsRoot: '0x7d1842a048756ca0aa200ff3eb1b66a52434bc7c1ece5e179eb303a0efa1c944', + parentHash: + '0xff10941138a407482a2651e3eaf0132f66c82ea1386a1f43287aa0fd6298698a' as PrefixedHexString, + feeRecipient: '0xf97e180c050e5ab072211ad2c213eb5aee4df134' as PrefixedHexString, + stateRoot: + '0x9933050575efffde6b1cdbfb9bca2f1a82df1c3e691f5878afe85eaf21df7d4f' as PrefixedHexString, + receiptsRoot: + '0x7d1842a048756ca0aa200ff3eb1b66a52434bc7c1ece5e179eb303a0efa1c944' as PrefixedHexString, logsBloom: - '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040', - prevRandao: '0xae8dc2c1223d402fb8e1a48ff6f0f15a543357aca40f34099ef5f5502f97d17d', - blockNumber: '0xd8d0', - gasLimit: '0x7a1200', - gasUsed: '0xc2f8e', - timestamp: '0x6230c760', - extraData: '0x', - baseFeePerGas: '0x3af046a', - blockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882', + '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040' as PrefixedHexString, + prevRandao: + '0xae8dc2c1223d402fb8e1a48ff6f0f15a543357aca40f34099ef5f5502f97d17d' as PrefixedHexString, + blockNumber: '0xd8d0' as PrefixedHexString, + gasLimit: '0x7a1200' as PrefixedHexString, + gasUsed: '0xc2f8e' as PrefixedHexString, + timestamp: '0x6230c760' as PrefixedHexString, + extraData: '0x' as PrefixedHexString, + baseFeePerGas: '0x3af046a' as PrefixedHexString, + blockHash: + '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString, transactions: [], }, } const update = { state: { - headBlockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882', - safeBlockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882', - finalizedBlockHash: '0x90ce8a06162cf161cc7323aa30f1de70b30542cd5da65e521884f517a4548017', + headBlockHash: + '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString, + safeBlockHash: + '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString, + finalizedBlockHash: + '0x90ce8a06162cf161cc7323aa30f1de70b30542cd5da65e521884f517a4548017' as PrefixedHexString, }, } describe('starts and stops connection manager', () => { @@ -113,7 +123,10 @@ describe('updates stats when a new block is processed', () => { manager.lastForkchoiceUpdate(update) manager.lastNewPayload(payload) const block = Block.fromBlockData({ - header: { parentHash: payload.payload.blockHash, number: payload.payload.blockNumber }, + header: { + parentHash: payload.payload.blockHash, + number: payload.payload.blockNumber, + }, }) config.logger.on('data', (chunk) => { if ((chunk.message as string).includes('Payload stats blocks count=1')) { diff --git a/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts b/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts index 2cda972f43..18c74484e2 100644 --- a/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts +++ b/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts @@ -9,6 +9,8 @@ import blocks from '../../testdata/blocks/beacon.json' import genesisJSON from '../../testdata/geth-genesis/post-merge.json' import { baseSetup, batchBlocks, getRpcClient, setupChain } from '../helpers.js' +import type { BlockData } from '@ethereumjs/block' + const crypto = require('crypto') const method = 'engine_forkchoiceUpdatedV1' @@ -174,7 +176,7 @@ describe(method, () => { difficulty: 1, extraData: new Uint8Array(97), }, - }, + } as BlockData, { common, skipConsensusFormatValidation: true } ) diff --git a/packages/client/test/rpc/engine/kaustinen6.spec.ts b/packages/client/test/rpc/engine/kaustinen6.spec.ts index 52b5619fd9..06bc98e6ed 100644 --- a/packages/client/test/rpc/engine/kaustinen6.spec.ts +++ b/packages/client/test/rpc/engine/kaustinen6.spec.ts @@ -9,7 +9,7 @@ import genesisJSON from '../../testdata/geth-genesis/kaustinen6.json' import { getRpcClient, setupChain } from '../helpers.js' import type { Chain } from '../../../src/blockchain' -import type { BeaconPayloadJson } from '@ethereumjs/block' +import type { BeaconPayloadJson, VerkleExecutionWitness } from '@ethereumjs/block' import type { Common } from '@ethereumjs/common' import type { HttpClient } from 'jayson/promise' const genesisVerkleStateRoot = '0x1fbf85345a3cbba9a6d44f991b721e55620a22397c2a93ee8d5011136ac300ee' @@ -99,8 +99,7 @@ describe(`valid verkle network setup`, async () => { testData = JSON.parse(readFileSync(fileName, 'utf8'))[testCase] isBeaconData = false } else { - // @ts-expect-error -- Typescript complains that `testCase` can't index the `blocks` object - testData = blocks[testCase] + testData = blocks[testCase as keyof typeof blocks] isBeaconData = true } if (testData === undefined) { @@ -163,7 +162,7 @@ async function loadGethVectors(vectorsDirPath: string, opts: { common: Common }) // set chain id to 1 for geth vectors opts.common['_chainParams'].chainId = BigInt(1) const stateDiffVec = JSON.parse(readFileSync(`${vectorsDirPath}/statediffs.json`, 'utf8')) - const executionWitness0 = { + const executionWitness0: VerkleExecutionWitness = { stateDiff: [], verkleProof: { commitmentsByPath: [], @@ -178,7 +177,7 @@ async function loadGethVectors(vectorsDirPath: string, opts: { common: Common }) }, } - const executionWitness1 = { + const executionWitness1: VerkleExecutionWitness = { stateDiff: stateDiffVec[0], verkleProof: { commitmentsByPath: [], @@ -193,7 +192,7 @@ async function loadGethVectors(vectorsDirPath: string, opts: { common: Common }) }, } - const executionWitness2 = { + const executionWitness2: VerkleExecutionWitness = { stateDiff: stateDiffVec[1], verkleProof: { commitmentsByPath: [], diff --git a/packages/client/test/rpc/eth/estimateGas.spec.ts b/packages/client/test/rpc/eth/estimateGas.spec.ts index 89f67eac5a..1cf3d0ea4b 100644 --- a/packages/client/test/rpc/eth/estimateGas.spec.ts +++ b/packages/client/test/rpc/eth/estimateGas.spec.ts @@ -10,6 +10,7 @@ import { INVALID_PARAMS } from '../../../src/rpc/error-code' import { createClient, createManager, getRpcClient, startRPC } from '../helpers.js' import type { FullEthereumService } from '../../../src/service/index.js' +import type { PrefixedHexString } from '@ethereumjs/util' const method = 'eth_estimateGas' @@ -83,7 +84,7 @@ describe( const estimateTxData = { to: createdAddress!.toString(), from: address.toString(), - data: `0x${funcHash}`, + data: `0x${funcHash}` as PrefixedHexString, gasLimit: bigIntToHex(BigInt(53000)), } const estimateTx = LegacyTransaction.fromTxData(estimateTxData, { freeze: false }) diff --git a/packages/client/test/sim/4844-devnet.spec.ts b/packages/client/test/sim/4844-devnet.spec.ts index 7e7a3f59c3..198f0c2bb4 100644 --- a/packages/client/test/sim/4844-devnet.spec.ts +++ b/packages/client/test/sim/4844-devnet.spec.ts @@ -16,6 +16,8 @@ import { waitForELStart, } from './simutils' +import type { PrefixedHexString } from '@ethereumjs/util' + const pkey = hexToBytes('0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8') const sender = bytesToHex(privateToAddress(pkey)) const client = Client.http({ port: 8545 }) @@ -24,7 +26,7 @@ const network = '4844-devnet' const shardingJson = require(`./configs/${network}.json`) const common = Common.fromGethGenesis(shardingJson, { chain: network }) -export async function runTx(data: string, to?: string, value?: bigint) { +export async function runTx(data: PrefixedHexString, to?: PrefixedHexString, value?: bigint) { return runTxHelper({ client, common, sender, pkey }, data, to, value) } diff --git a/packages/client/test/sim/beaconsync.spec.ts b/packages/client/test/sim/beaconsync.spec.ts index 58563ccbc1..49e7445aec 100644 --- a/packages/client/test/sim/beaconsync.spec.ts +++ b/packages/client/test/sim/beaconsync.spec.ts @@ -20,6 +20,7 @@ import { import type { EthereumClient } from '../../src/client' import type { RlpxServer } from '../../src/net/server' +import type { PrefixedHexString } from '@ethereumjs/util' const client = Client.http({ port: 8545 }) @@ -39,7 +40,7 @@ let beaconSyncRelayer: any = null const EOATransferToAccount = '0x3dA33B9A0894b908DdBb00d96399e506515A1009' let EOATransferToBalance = BigInt(0) -export async function runTx(data: string, to?: string, value?: bigint) { +export async function runTx(data: PrefixedHexString | '', to?: PrefixedHexString, value?: bigint) { return runTxHelper({ client, common, sender, pkey }, data, to, value) } diff --git a/packages/client/test/sim/eof.spec.ts b/packages/client/test/sim/eof.spec.ts index 5d2b5f1086..e3bae72ff5 100644 --- a/packages/client/test/sim/eof.spec.ts +++ b/packages/client/test/sim/eof.spec.ts @@ -11,6 +11,8 @@ import { waitForELStart, } from './simutils' +import type { PrefixedHexString } from '@ethereumjs/util' + const pkey = hexToBytes('0xae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e') const sender = bytesToHex(privateToAddress(pkey)) const client = Client.http({ port: 8545 }) @@ -19,7 +21,7 @@ const network = 'eof' const eofJson = require(`./configs/${network}.json`) const common = Common.fromGethGenesis(eofJson, { chain: network }) -export async function runTx(data: string, to?: string, value?: bigint) { +export async function runTx(data: PrefixedHexString | '', to?: PrefixedHexString, value?: bigint) { return runTxHelper({ client, common, sender, pkey }, data, to, value) } @@ -71,7 +73,12 @@ describe('EOF ephemeral hardfork tests', async () => { }) // ------------EIP 3540 tests------------------------------- it('EIP 3540 tests', async () => { - const data = '0x6B' + 'EF0001' + '01000102000100' + '00' + 'AA' + '600052600C6014F3' + const data = ('0x6B' + + 'EF0001' + + '01000102000100' + + '00' + + 'AA' + + '600052600C6014F3') as PrefixedHexString const res = await runTx(data) diff --git a/packages/client/test/sim/mainnet.spec.ts b/packages/client/test/sim/mainnet.spec.ts index 953fe85b29..f177af9178 100644 --- a/packages/client/test/sim/mainnet.spec.ts +++ b/packages/client/test/sim/mainnet.spec.ts @@ -12,6 +12,8 @@ import { waitForELStart, } from './simutils' +import type { PrefixedHexString } from '@ethereumjs/util' + const pkey = hexToBytes('0xae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e') const sender = bytesToHex(privateToAddress(pkey)) const client = Client.http({ port: 8545 }) @@ -20,7 +22,7 @@ const network = 'mainnet' const eofJson = require(`./configs/${network}.json`) const common = Common.fromGethGenesis(eofJson, { chain: network }) -export async function runTx(data: string, to?: string, value?: bigint) { +export async function runTx(data: PrefixedHexString | '', to?: PrefixedHexString, value?: bigint) { return runTxHelper({ client, common, sender, pkey }, data, to, value) } diff --git a/packages/client/test/sync/fetcher/accountfetcher.spec.ts b/packages/client/test/sync/fetcher/accountfetcher.spec.ts index 507094524e..5e30d384fa 100644 --- a/packages/client/test/sync/fetcher/accountfetcher.spec.ts +++ b/packages/client/test/sync/fetcher/accountfetcher.spec.ts @@ -13,6 +13,8 @@ import { TrieNodeFetcher } from '../../../src/sync/fetcher/trienodefetcher' import { Event } from '../../../src/types' import { wait } from '../../integration/util' +import type { PrefixedHexString } from '@ethereumjs/util' + export const _accountRangeRLP = '0xf90b7c01f88aeda0000001907a67cf7ece54c42262997b2f19041a4d99466b94b8c12f225827e239cb80872386f26fc100008080eda00000107c642e29a6b613205c923ac3a4cf0cf1704ae9a8bef2784caba060f4b7cb07870e22e1219054118080eda000001d26422787b6d40c0c0c2df85757c5ad4a3e367831e932fa24f34da43d57cb80872386f26fc100008080f90aecb90214f90211a0b3f22b069c398ded55d4ce421b06f6b4d5e13cb53ad1c6220276b2b3a078937ba08a54e492e7b9ef911b4a299487a12390ccd81a087398af7106e00b81a791868da0a323a93f5791d4c39e1496e4856f9233e5e86070c722efde613219aca834bde3a0d8c11a8fc2eba0b47de9d5b207b702a8bd62609e9c2504aaa444fd2e98e31deaa0dbfc625e370fa89cb7b123550ef6fd637687b9e9a7c8556bd41bcd4226226095a094fe5f6ac37c805917beefa220d7c6b3bd50848322f6342e940cc047c9b6a8ffa074af7e57b9c59e06a2e478610d56ab39004cda3109cfd953dc8b1d168c453cbca0d58f31d0ecce773d610aa5d12f7cc2f4ca992db4ce2e154c13a12cb4bb567816a0b26a7d9776165bb52e793df6a77d4032164d788bf9954c9cac289ea0786da2fda043804bd146f583b183dc267b36bbe55f63daa36fd6cbdafce48ce451a444b4eca0fc724e8bb65724450eb3966d8672330c8e49a94c6ceaed06174a2322aafee105a02ccb0445b0a4028f167e425b57cb9462cc6caceda0c3cfb5363f08614314a77ca0c64db3edb50609b6de331f00ba1f455113d1388e9eb5f50f5420983012d62b7da0168c680c03ef3fbcc36a6c1ddd9bf7d46b5fd5ee34dd7048320223c8bbe412f9a05747d2eb930bffce317c253e3889a7db57c87dcc55f1f1f77b3d02fc82bc6bcfa0997073e1664f9cbbcfd968277856596c325a6b83887f4ad007c3b93e1133c65280b90214f90211a0b3e6ec5fa09062b280599994d38261cae87ab198ed1b3a7d7003a277ffc735dfa01bac91007228f4fa15ac9c2a4822b7d4103eafae61dd3db30eb830e31de9cddfa0809973bebc62f48fb834336800b1ce8e1b2128ee5824645464b6c09ddd381578a0f8d54e19e888fc01cd5069bfcddb7ee78a4afdec24aa03822d9fd5356a3c109fa08a61ea95c616906799398778b28f0e8a19f6569f885e4b4f1192f3e9f690cefea09aa53cd259b1df9650222dc285236399da685b7350312a3ac0a07a86bef64d5ea01596637937233489a70e114c23818e3512b3c2abf621d142c14a9b9a3afb09d1a0e8a8bcda78ae77bee956389dff38a10c8c1565bc1a85064da6cd8ba606b9aa35a04ae4b4bfbfb97f5b4e178f8c30a6d93ffd6614c8b4d0b44df31b653a3a1e4f0fa0a4e3413e6ee6c5886ed346827ee0cce05a8e4f799b005aacf002a17e6d93e5aaa09a3e6d344bbd2496bf8fa84abc96a3d5f363ba03103edff2164244bb020c52a2a0998f39835105197f860930b46adad4527f5a9ef31c4744476718b910ffc5e586a01cec4592958b5aefe25bea6a49a11089e798d96aebc2be7fce0f1772146d18aea0d7c178ed5bcf822d22f9ed3ca8c95e5144ee0a9fbae901b21da002e2c3c0415ea0a9d5c5c67326f4154449575827ab68ea47c7c8931490160a7a299f829a670476a074814ffe69da7e253de29fc7d5eb57291a67bd6f16cb52175106b7cbd3b19c8f80b90214f90211a0947eec1b645849d129fb8c65cd06bd52526fb2399d1660ee5108fc4698e809aaa02735f6cbb0e10514b1515826ae1c539850543dbe162badaf2efa51b1a353ca1ca0fde2642bcc8db8d6d6e42731eeae2045fc30b84c6efdc420ce8cee5d537b648fa071e7887ca31ae375838ceeed57165f5592a9e6cae9beb070e92a4f5d5aec5014a0f81f4b4d5e2c52373b8884b398838941df0b16177aa4ea8494b183176cf7d526a0dc6ecec073532c8f9581ece75cb4eea83a40ba0210cc10ef0fd8b27a102a028fa0426f18f1de1bc9b665e9efb45d6547e88e35a267d7ec9197ae97052d1be59ab9a0d6aad68bece934d578e18eb3acd147490bc6cc01e646f1d8618a747526eae4f5a04ffee6f8660794981b15fda1ceafef98db853bfc31c029db7cb515bb34bb5572a0da2497fed45626b94c1eb910c9eedc9c26a4ff5b56b709b96d5a567991ebe2aca021b3bfcd8aa97eb8d9a3ce258389603564f01d6f485899a9f6e0a00d85dc00dfa0339e45f0407ad527a899a2e06e17330c2cfe25b81689dcffd20c166ef256fbc6a0dafd25416aaf44a8bfa1a6bf2b0cc563f9be84b9b3b8bf307983252d7cd63c51a0191504034adb55fe0926c7c4066654739af3e1c9c4173f4d90fa2e1df62a99cca0504e2144c1a889e48cd5a6baa17e39b6a176dbf41147dd171f2673c5c9d849dba04850f33ad929cb1a07136f162e33a5df0f65c48f359637774e7c8ebabe90eb7080b90214f90211a05d16e93a6e58a13a7c7dde40d0c543b9d63d029ec0da5efb4be34cd4ce672181a089cbb0e940fb7bb395091e3b665755be6b51292fba7a7bc39904568c63a907e1a050314b93f73fed553cd9dee63dc1fe9b789f9b9e111a659ff4e4c91c8167a63ca04444bd2a1bb78a83b66a36a09076b2b49eade4e2e8c8ef91538117525893841aa0abde6220817f3608bdfec46ebed292c464ee1d2c58d0b43286b8617bb4cb49d9a07257eff6aebb380db4c75752a84c6b2d0bb86bb190cef2a58829497997262b6aa0a0d4ab9d93be97287f29637a9b16fb8a6c8cd3bc29786b64343113b95a4153ffa0f0d479377ce4c0f31185c45319f915532cea13e97d5abfc939b75b642b5b47bba0eb96a911347f5321e03f1602a041ce82ec29bb4b322faa9f999cf02bb0c7a932a047b6c76ffeb29b4e3c3c09749289213395c8b0126dbd8acee45c6d32d2a0ab5fa0ca462e8ff237f9e56698ca416fac835ed37bc90683d363effe7ec9dacb4963fba0d385f828becce3665e070b645df25dec507a7c6c3813591e3436147be0becc75a0537a7451522228feca0ceb55374615e8396229e1c7a6b0ae16fb49cd8e6ed7a9a0b96561ab484f67b604d2dc46ac170750b321334aabcfb6b212a906e1cb5b3532a09f64f7c76e201d48b4bc1fb02f7e052a5a1bf05b2c59f3c969c8d2d6b373b3dca0398a988af30676952fcf1a968ac530b30dbe32922efe8c27acb9025adcaf1a5180b90134f90131a0b2151043be015f98b1b249180bfac505781022ede708f533f373b2d612837df7a0031e6ffe32d313f0cd57b4bebbf6fcacf83c366157846040108d198129d99a5aa0bfca4f79ac9eb24bcbdbd94fc49c0ca30a6399a2071e4ab3024e1aae0159a31180808080a0f1a2c911436f5bf1aa936e140b17399f7c092ad64a8ab839057a67fc6923a318a0e648ced926c977b0dcc17452361ac43e53f839b8e485a288e93fb667573ae088a0808107d197eb28741f8cec92b6fa76957fa6928b00f4b7301d464809519258098080a02c7ac441b072bbe33030110dccfdda0de6705c4bdb2c94594e10c2fb8687c41080a0162e8104a86bd043ca2fac0c5d56181127c7b24f6c10fefb90c27064b4edeff8a0376bcbdd3b7503a144b9016159b7e2cd074c9566b843cb834123057c61adbd2e80b870f86e9e31907a67cf7ece54c42262997b2f19041a4d99466b94b8c12f225827e239b84df84b80872386f26fc10000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470b873f871a0a75a6fa397f39292a3bb4fdb84463908c473bad9a0206bd00964adabd7a4b589808080808080808080808080a0ea5b9774dfc3fd50b359b86fa49a57fce0186593cf89d865e279413b63947bed80a0a0747bb1023533b4f9cdaa7c845609975d413348fc5f185a120037dccdf3584c80b870f86e9e2026422787b6d40c0c0c2df85757c5ad4a3e367831e932fa24f34da43d57b84df84b80872386f26fc10000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' @@ -26,7 +28,7 @@ export const _zeroElementProof = [ '0xf90211a07d363fdc4ad4413321005a1981d415a872aed14651c159bea575d713fb1d1fd8a0d51e3a39747ab080d602e8dff07ed7fdf18fd5dd480b85ec8d5ebd86475481fba0382fbb965c19798b116e1b32ad64d99bdf09f8f4ed4c83e1b388ffad0ee8bc62a02ff7448b0092b7926a01bbb4f72e6f38366fdf109f3e9f8ac0794af3dc0e3de4a05db544523b1c10f8aead4252bff05665b8c7d21f02a102b51ac79acb6b3d2854a0cb0c46c37d6b44be6ff2204c4f4cea393099fefeae88cf5aa88195da74cca13fa0b459b6b3672dab2bb058e561761a0838e349d1dd1292dda31245e8404ec844eaa082cbce67bd082cb430296662fb1f32aabe866dee947970877abaf4233eb0fb48a0828820316cc02bfefd899aba41340659fd06df1e0a0796287ec2a4110239f6d2a0be88e4724326382a8b56e2328eeef0ad51f18d5bae0e84296afe14c4028c4af9a0c14e9060c6b3784e35b9e6ae2ad2984142a75910ccc89eb89dc1e2f44b6c58c2a091467954490d127631d2a2f39a6edabd702153de817fe8da2ab9a30513e5c6dda01c00f6abbb9bcb3ae9b12c887bc3ea3b13dba33a5dbad455c24778fa7d3ab01ea0899f71abb18c6c956118bf567fac629b75f7e9526873e429d3d8abb6dbb58021a00fd717235298742623c0b3cafb3e4bd86c0b5ab1f71097b4dd19f3d6925d758da011e10e11fa54a847669b26adaf1b5cbe7736eafde6c552b9b6158fe12307e60680', '0xf90131a0e90a923d3266758f74651084eef91d4d62a6eece11d6bc9724f2b6eef20aaac180808080a07ee878af944ffe26ce5c64042dcc79df748286de580e561107594449d8ed516fa0eb748aae6c0c30fc952f9caa1cd5753bc220e571fdd3eb87f90016b4ee1b0d388080a05f4ca08c32e4a3997d0e94d8946e3d361ec5d0225d9cd85c6de8d572bb0a99c980a0faecf459527318d12fee2db8d85c54fc244d0207ba336a01e397593b801ae61fa0d9b3608f7e3498ffe810563f0c0925bea0287cdea57ea1f3ae29af45a192667fa0ca2e251e82502284289d0066710469330d9ec45890680a0909cf47f06c15855ea06585b163fb3bcf2bb1643d73e26170b6849097a9544b6ed6c6aba86397200297a00844a6824efe874b61c480f88d1b0639780aa16aefbad5647403fc7ea6c274b280', '0xf869a020fa0eae268038cfa984647a1d0635beb86eda9fb7b500688f3189520cfa9ee5b846f8448001a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', -].map((e) => hexToBytes(e)) +].map((e) => hexToBytes(e as PrefixedHexString)) describe('[AccountFetcher]', async () => { class PeerPool { @@ -285,7 +287,7 @@ describe('[AccountFetcher]', async () => { // calculate new root with a key all the way to the right of the trie const trie = await Trie.createFromProof(_zeroElementProof) - await trie.put(hexToBytes('0x' + 'F'.repeat(32)), hexToBytes('0x' + '123'), true) + await trie.put(hexToBytes(`0x${'F'.repeat(32)}`), hexToBytes('0x123'), true) const newRoot = trie.root() const fetcher = new AccountFetcher({ diff --git a/packages/client/test/sync/fetcher/storagefetcher.spec.ts b/packages/client/test/sync/fetcher/storagefetcher.spec.ts index 30d368e3d4..f722a04f8a 100644 --- a/packages/client/test/sync/fetcher/storagefetcher.spec.ts +++ b/packages/client/test/sync/fetcher/storagefetcher.spec.ts @@ -363,7 +363,7 @@ describe('[StorageFetcher]', async () => { // calculate new root with a key all the way to the right of the trie const trie = await Trie.createFromProof(_zeroElementProof) - await trie.put(hexToBytes('0x' + 'F'.repeat(32)), hexToBytes('0x' + '123'), true) + await trie.put(hexToBytes(`0x${'F'.repeat(32)}`), hexToBytes('0x123'), true) const newRoot = trie.root() const fetcher = new StorageFetcher({ diff --git a/packages/client/test/sync/txpool.spec.ts b/packages/client/test/sync/txpool.spec.ts index 7cbe880a96..b7e2da1102 100644 --- a/packages/client/test/sync/txpool.spec.ts +++ b/packages/client/test/sync/txpool.spec.ts @@ -340,7 +340,7 @@ describe('[TxPool]', async () => { const hashes = [] for (let i = 1; i <= TX_RETRIEVAL_LIMIT + 1; i++) { // One more than TX_RETRIEVAL_LIMIT - hashes.push(hexToBytes('0x' + i.toString().padStart(64, '0'))) // '0000000000000000000000000000000000000000000000000000000000000001',... + hashes.push(hexToBytes(`0x${i.toString().padStart(64, '0')}`)) // '0x0000000000000000000000000000000000000000000000000000000000000001',... } await pool.handleAnnouncedTxHashes(hashes, peer as any, peerPool) @@ -491,8 +491,8 @@ describe('[TxPool]', async () => { const txs = [] for (let account = 0; account < 51; account++) { const pkey = concatBytes( - hexToBytes('0x' + 'aa'.repeat(31)), - hexToBytes('0x' + account.toString(16).padStart(2, '0')) + hexToBytes(`0x${'aa'.repeat(31)}`), + hexToBytes(`0x${account.toString(16).padStart(2, '0')}`) ) const from = { address: privateToAddress(pkey), @@ -572,7 +572,7 @@ describe('[TxPool]', async () => { maxFeePerGas: 1000000000, maxPriorityFeePerGas: 1000000000, nonce: 0, - data: '0x' + '00'.repeat(128 * 1024 + 1), + data: `0x${'00'.repeat(128 * 1024 + 1)}`, }, { common } ).sign(A.privateKey) diff --git a/packages/common/test/customChains.spec.ts b/packages/common/test/customChains.spec.ts index 845905743b..678ab3120d 100644 --- a/packages/common/test/customChains.spec.ts +++ b/packages/common/test/customChains.spec.ts @@ -7,6 +7,8 @@ import * as testnet from './data/testnet.json' import * as testnet2 from './data/testnet2.json' import * as testnet3 from './data/testnet3.json' +import type { ChainConfig } from '../src/index.js' + describe('[Common]: Custom chains', () => { it('chain -> object: should provide correct access to private network chain parameters', () => { const c = new Common({ chain: testnet, hardfork: Hardfork.Byzantium }) @@ -98,7 +100,7 @@ describe('[Common]: Custom chains', () => { it('customChains parameter: initialization exception', () => { try { - new Common({ chain: testnet, customChains: [testnet] }) + new Common({ chain: testnet, customChains: [testnet] as ChainConfig[] }) assert.fail('should throw') } catch (e: any) { assert.ok( @@ -114,7 +116,7 @@ describe('[Common]: Custom chains', () => { let c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Byzantium, - customChains: [testnet], + customChains: [testnet] as ChainConfig[], }) assert.equal(c.chainName(), 'mainnet', 'customChains, chain set to supported chain') assert.equal(c.hardforkBlock()!, BigInt(4370000), 'customChains, chain set to supported chain') @@ -126,12 +128,12 @@ describe('[Common]: Custom chains', () => { c = new Common({ chain: 'testnet', hardfork: Hardfork.Byzantium, - customChains: [testnet], + customChains: [testnet] as ChainConfig[], }) assert.equal(c.chainName(), 'testnet', 'customChains, chain initialized with custom chain') assert.equal(c.hardforkBlock()!, BigInt(4), 'customChains, chain initialized with custom chain') - const customChains = [testnet, testnet2, testnet3] + const customChains = [testnet, testnet2, testnet3] as ChainConfig[] c = new Common({ chain: 'testnet2', hardfork: Hardfork.Istanbul, diff --git a/packages/common/test/mergePOS.spec.ts b/packages/common/test/mergePOS.spec.ts index 7a7e73ad70..cb0adcd696 100644 --- a/packages/common/test/mergePOS.spec.ts +++ b/packages/common/test/mergePOS.spec.ts @@ -6,9 +6,11 @@ import * as postMergeJSON from './data/geth-genesis/post-merge.json' import * as testnetMerge from './data/merge/testnetMerge.json' import * as testnetPOS from './data/merge/testnetPOS.json' +import type { ChainConfig } from '../src/index.js' + describe('[Common]: Merge/POS specific logic', () => { it('hardforkTTD()', () => { - const customChains = [testnetMerge] + const customChains = [testnetMerge] as ChainConfig[] const c = new Common({ chain: 'testnetMerge', hardfork: Hardfork.Istanbul, customChains }) assert.equal(c.hardforkTTD(Hardfork.Paris), BigInt(5000), 'should get the HF total difficulty') assert.equal( @@ -19,7 +21,7 @@ describe('[Common]: Merge/POS specific logic', () => { }) it('getHardforkBy(), merge block null, with total difficulty', () => { - const customChains = [testnetMerge] + const customChains = [testnetMerge] as ChainConfig[] const c = new Common({ chain: 'testnetMerge', hardfork: Hardfork.Istanbul, customChains }) let msg = 'block number < last HF block number set, without TD set' @@ -76,7 +78,7 @@ describe('[Common]: Merge/POS specific logic', () => { testnetMergeWithBlockNumber['hardforks'][8]['block'] = 16 // Set Shanghai block to 18 testnetMergeWithBlockNumber['hardforks'][9]['block'] = 18 - const customChains = [testnetMergeWithBlockNumber] + const customChains = [testnetMergeWithBlockNumber] as ChainConfig[] const c = new Common({ chain: 'testnetMerge', hardfork: Hardfork.Istanbul, customChains }) const msg = 'block number > last HF block number set, TD set and higher' @@ -84,7 +86,7 @@ describe('[Common]: Merge/POS specific logic', () => { }) it('setHardforkBy(), merge block null, with total difficulty', () => { - const customChains = [testnetMerge] + const customChains = [testnetMerge] as ChainConfig[] const c = new Common({ chain: 'testnetMerge', hardfork: Hardfork.Istanbul, customChains }) let msg = 'block number < last HF block number set, without TD set' @@ -151,7 +153,7 @@ describe('[Common]: Merge/POS specific logic', () => { }) it('Pure POS testnet', () => { - const customChains = [testnetPOS] + const customChains = [testnetPOS] as ChainConfig[] const c = new Common({ chain: 'testnetPOS', hardfork: Hardfork.Chainstart, customChains }) assert.equal( @@ -165,7 +167,7 @@ describe('[Common]: Merge/POS specific logic', () => { }) it('Should fail setting invalid hardfork', () => { - const customChains = [testnetPOS] + const customChains = [testnetPOS] as ChainConfig[] const f = () => { new Common({ chain: 'testnetPOS', hardfork: Hardfork.Istanbul, customChains }) } diff --git a/packages/ethash/test/block.spec.ts b/packages/ethash/test/block.spec.ts index 07724343ca..a8bafc4ca7 100644 --- a/packages/ethash/test/block.spec.ts +++ b/packages/ethash/test/block.spec.ts @@ -22,12 +22,12 @@ describe('Verify POW for valid and invalid blocks', () => { const genesisResult = await e.verifyPOW(genesis) assert.ok(genesisResult, 'genesis block should be valid') - const validRlp = hexToBytes('0x' + validBlockRlp) + const validRlp = hexToBytes(`0x${validBlockRlp}`) const validBlock = Block.fromRLPSerializedBlock(validRlp, { common }) const validBlockResult = await e.verifyPOW(validBlock) assert.ok(validBlockResult, 'should be valid') - const invalidRlp = hexToBytes('0x' + invalidBlockRlp) + const invalidRlp = hexToBytes(`0x${invalidBlockRlp}`) // Put correct amount of extraData in block extraData field so block can be deserialized const values = RLP.decode(Uint8Array.from(invalidRlp)) as BlockBytes values[0][12] = new Uint8Array(32) diff --git a/packages/ethash/test/ethash.spec.ts b/packages/ethash/test/ethash.spec.ts index 8be8b6765c..ecbee8e2ca 100644 --- a/packages/ethash/test/ethash.spec.ts +++ b/packages/ethash/test/ethash.spec.ts @@ -16,7 +16,7 @@ describe('POW tests', () => { it('should work', async () => { for (const key of tests) { const test = powTests[key] - const header = BlockHeader.fromRLPSerializedHeader(hexToBytes('0x' + test.header), { common }) + const header = BlockHeader.fromRLPSerializedHeader(hexToBytes(`0x${test.header}`), { common }) const headerHash = ethash.headerHash(header.raw()) assert.equal(bytesToHex(headerHash), '0x' + test.header_hash, 'generate header hash') @@ -25,10 +25,10 @@ describe('POW tests', () => { assert.equal(await getCacheSize(epoc), test.cache_size, 'generate cache size') assert.equal(await getFullSize(epoc), test.full_size, 'generate full cache size') - ethash.mkcache(test.cache_size, hexToBytes('0x' + test.seed)) + ethash.mkcache(test.cache_size, hexToBytes(`0x${test.seed}`)) assert.equal(bytesToHex(ethash.cacheHash()), '0x' + test.cache_hash, 'generate cache') - const r = ethash.run(headerHash, hexToBytes('0x' + test.nonce), test.full_size) + const r = ethash.run(headerHash, hexToBytes(`0x${test.nonce}`), test.full_size) assert.equal(bytesToHex(r.hash), '0x' + test.result, 'generate result') assert.equal(bytesToHex(r.mix), '0x' + test.mixHash, 'generate mix hash') } diff --git a/packages/evm/test/blobVersionedHashes.spec.ts b/packages/evm/test/blobVersionedHashes.spec.ts index 9ce0731e39..f4e7af49f6 100644 --- a/packages/evm/test/blobVersionedHashes.spec.ts +++ b/packages/evm/test/blobVersionedHashes.spec.ts @@ -5,6 +5,7 @@ import { assert, describe, it } from 'vitest' import { EVM } from '../src/index.js' import type { EVMRunCallOpts } from '../src/types.js' +import type { PrefixedHexString } from '@ethereumjs/util' describe('BLOBHASH / access blobVersionedHashes in calldata', () => { it('should work', async () => { @@ -57,8 +58,7 @@ describe(`BLOBHASH: access blobVersionedHashes within contract calls`, () => { for (const callCode of ['F1', 'F4', 'F2', 'FA']) { // Call the contract via static call and return the returned BLOBHASH - const staticCallCode = - '0x' + + const staticCallCode = ('0x' + // return, args and value '5F5F5F5F5F' + // push 20 bytes address of contract to call @@ -67,7 +67,7 @@ describe(`BLOBHASH: access blobVersionedHashes within contract calls`, () => { '5A' + callCode + // copy returndata to memory offset and then return the same - '60205F5F3E60206000F3' + '60205F5F3E60206000F3') as PrefixedHexString // setup the call arguments const runCallArgs: EVMRunCallOpts = { @@ -107,8 +107,7 @@ describe(`BLOBHASH: access blobVersionedHashes in a CREATE/CREATE2 frame`, () => for (const createOP of ['F0', 'F5']) { // Call the contract via static call and return the returned BLOBHASH - const staticCallCode = - '0x' + + const staticCallCode = ('0x' + // push initcode '7F' + getBlobHashIndex0Code + @@ -121,7 +120,7 @@ describe(`BLOBHASH: access blobVersionedHashes in a CREATE/CREATE2 frame`, () => // run CREATE(2) createOP + // copy the return stack item to memory (this is the created address) - '5F5260206000F3' + '5F5260206000F3') as PrefixedHexString // setup the call arguments const runCallArgs: EVMRunCallOpts = { diff --git a/packages/evm/test/customPrecompiles.spec.ts b/packages/evm/test/customPrecompiles.spec.ts index ac1af774b0..244e0d6442 100644 --- a/packages/evm/test/customPrecompiles.spec.ts +++ b/packages/evm/test/customPrecompiles.spec.ts @@ -6,8 +6,8 @@ import { EVM } from '../src/evm.js' import type { PrecompileInput } from '../src/index.js' import type { ExecResult } from '../src/types.js' -const sender = new Address(hexToBytes('0x' + '44'.repeat(20))) -const newPrecompile = new Address(hexToBytes('0x' + 'ff'.repeat(20))) +const sender = new Address(hexToBytes(`0x${'44'.repeat(20)}`)) +const newPrecompile = new Address(hexToBytes(`0x${'ff'.repeat(20)}`)) const shaAddress = new Address(hexToBytes('0x0000000000000000000000000000000000000002')) const expectedReturn = utf8ToBytes('1337') const expectedGas = BigInt(10) diff --git a/packages/evm/test/eips/eip-3860.spec.ts b/packages/evm/test/eips/eip-3860.spec.ts index c888a883e2..84560c38fc 100644 --- a/packages/evm/test/eips/eip-3860.spec.ts +++ b/packages/evm/test/eips/eip-3860.spec.ts @@ -5,7 +5,7 @@ import { assert, describe, it } from 'vitest' import { EVM } from '../../src/index.js' -const pkey = hexToBytes('0x' + '20'.repeat(32)) +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) const sender = new Address(privateToAddress(pkey)) describe('EIP 3860 tests', () => { @@ -158,7 +158,7 @@ describe('EIP 3860 tests', () => { // It tries to deploy a contract too large, where the code is all zeros // (since memory which is not allocated/resized to yet is always defaulted to 0) data: concatBytes( - hexToBytes('0x' + '00'.repeat(Number(common.param('vm', 'maxInitCodeSize')) + 1)), + hexToBytes(`0x${'00'.repeat(Number(common.param('vm', 'maxInitCodeSize')) + 1)}`), bytes ), } @@ -199,7 +199,7 @@ describe('EIP 3860 tests', () => { // (the initcode of this contract is just zeros, so STOP opcode // It stores the topmost stack item of this CREATE(2) at slot 0 // This is either the contract address if it was succesful, or 0 in case of error - const factoryCode = hexToBytes('0x600060003560006000' + code + '600055') + const factoryCode = hexToBytes(`0x600060003560006000${code}600055`) await evm.stateManager.putContractCode(contractFactory, factoryCode) await evmDisabled.stateManager.putContractCode(contractFactory, factoryCode) @@ -208,13 +208,13 @@ describe('EIP 3860 tests', () => { from: caller, to: contractFactory, gasLimit: BigInt(0xfffffffff), - data: hexToBytes('0x' + '00'.repeat(30) + 'C001'), + data: hexToBytes(`0x${'00'.repeat(30)}C001`), } const res = await evm.runCall(runCallArgs) await evmDisabled.runCall(runCallArgs) - const key0 = hexToBytes('0x' + '00'.repeat(32)) + const key0 = hexToBytes(`0x${'00'.repeat(32)}`) const storageActive = await evm.stateManager.getContractStorage(contractFactory, key0) const storageInactive = await evmDisabled.stateManager.getContractStorage( contractFactory, @@ -236,7 +236,7 @@ describe('EIP 3860 tests', () => { from: caller, to: contractFactory, gasLimit: BigInt(0xfffffffff), - data: hexToBytes('0x' + '00'.repeat(30) + 'C000'), + data: hexToBytes(`0x${'00'.repeat(30)}C000`), } // Test: diff --git a/packages/evm/test/eips/eip-5656.spec.ts b/packages/evm/test/eips/eip-5656.spec.ts index 1a2b78f34a..cccb2639d1 100644 --- a/packages/evm/test/eips/eip-5656.spec.ts +++ b/packages/evm/test/eips/eip-5656.spec.ts @@ -4,6 +4,8 @@ import { assert, describe, it } from 'vitest' import { EVM } from '../../src/index.js' +import type { PrefixedHexString } from '@ethereumjs/util' + type Situation = { pre: string post: string @@ -60,7 +62,7 @@ describe('should test mcopy', () => { for (const situation of situations) { it('should produce correct output', async () => { // create bytecode - let bytecode = '0x' + let bytecode: PrefixedHexString = '0x' // prepare the memory for (let i = 0; i < situation.pre.length / 2; i++) { const start = i * 2 @@ -97,7 +99,7 @@ describe('should test mcopy', () => { }) await evm.runCall({ - data: hexToBytes(bytecode), + data: hexToBytes(bytecode as PrefixedHexString), gasLimit: BigInt(0xffffff), }) }) diff --git a/packages/evm/test/eof.spec.ts b/packages/evm/test/eof.spec.ts index 984cb2343c..4d1bc33d62 100644 --- a/packages/evm/test/eof.spec.ts +++ b/packages/evm/test/eof.spec.ts @@ -3,14 +3,16 @@ import { assert, describe, it } from 'vitest' import { getEOFCode } from '../src/eof.js' -function generateEOFCode(code: string) { +import type { PrefixedHexString } from '@ethereumjs/util' + +function generateEOFCode(code: string): PrefixedHexString { const len = (code.length / 2).toString(16).padStart(4, '0') - return '0xEF000101' + len + '00' + code + return `0xEF000101${len}00${code}` } -function generateInvalidEOFCode(code: string) { +function generateInvalidEOFCode(code: string): PrefixedHexString { const len = (code.length / 2 + 1).toString(16).padStart(4, '0') // len will be 1 too long - return '0xEF000101' + len + '00' + code + return `0xEF000101${len}00${code}` } describe('getEOFCode()', () => { diff --git a/packages/evm/test/precompiles/05-modexp.spec.ts b/packages/evm/test/precompiles/05-modexp.spec.ts index 72f2f28ac5..2e975064d7 100644 --- a/packages/evm/test/precompiles/05-modexp.spec.ts +++ b/packages/evm/test/precompiles/05-modexp.spec.ts @@ -7,8 +7,9 @@ import { EVM, getActivePrecompiles } from '../../src/index.js' import fuzzer from './modexp-testdata.json' import type { PrecompileFunc } from '../../src/precompiles/types.js' +import type { PrefixedHexString } from '@ethereumjs/util' -const fuzzerTests = fuzzer.data +const fuzzerTests = fuzzer.data as PrefixedHexString[][] describe('Precompiles: MODEXP', () => { let common: Common let evm: EVM diff --git a/packages/evm/test/precompiles/09-blake2f.spec.ts b/packages/evm/test/precompiles/09-blake2f.spec.ts index 8a020973f0..e9a39c2edf 100644 --- a/packages/evm/test/precompiles/09-blake2f.spec.ts +++ b/packages/evm/test/precompiles/09-blake2f.spec.ts @@ -134,7 +134,7 @@ describe('Precompiles: BLAKE2F', () => { // -> Copies the CALLDATA into memory, but at offset 0x20 (32) // -> Calls Blake2F with this data (so, with the calldata) // -> Returns the data from Blake2F - const code = '0x366000602037' + '600080366020600060095AF1593D6000593E3D90F3' + const code = `0x366000602037600080366020600060095AF1593D6000593E3D90F3` await evm.stateManager.putContractCode(addr, hexToBytes(code)) const res = await evm.runCall({ diff --git a/packages/evm/test/precompiles/0b-bls12-g1add.spec.ts b/packages/evm/test/precompiles/0b-bls12-g1add.spec.ts index 36cea2da44..a030c783eb 100644 --- a/packages/evm/test/precompiles/0b-bls12-g1add.spec.ts +++ b/packages/evm/test/precompiles/0b-bls12-g1add.spec.ts @@ -89,7 +89,7 @@ describe('Precompiles: BLS12-G1-ADD', () => { for (const testVector of testData) { const result = await BLS12G1ADD({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(5000000), common, _EVM: evm, diff --git a/packages/evm/test/precompiles/0c-bls12-g1mul.spec.ts b/packages/evm/test/precompiles/0c-bls12-g1mul.spec.ts index 9f1d33673f..b2e623051e 100644 --- a/packages/evm/test/precompiles/0c-bls12-g1mul.spec.ts +++ b/packages/evm/test/precompiles/0c-bls12-g1mul.spec.ts @@ -80,7 +80,7 @@ describe('Precompiles: BLS12-G1-MUL', () => { for (const testVector of testData) { const result = await BLS12G1MUL({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(5000000), common, _EVM: evm, diff --git a/packages/evm/test/precompiles/0d-bls12-g1msm.spec.ts b/packages/evm/test/precompiles/0d-bls12-g1msm.spec.ts index a5f085a850..eaa34c0e32 100644 --- a/packages/evm/test/precompiles/0d-bls12-g1msm.spec.ts +++ b/packages/evm/test/precompiles/0d-bls12-g1msm.spec.ts @@ -116,7 +116,7 @@ describe('Precompiles: BLS12-G1-MSM', () => { for (const testVector of testData) { const result = await BLS12G1MSM({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(5000000), common, _EVM: evm, diff --git a/packages/evm/test/precompiles/0e-bls12-g2add.spec.ts b/packages/evm/test/precompiles/0e-bls12-g2add.spec.ts index d03a879d68..e299a59158 100644 --- a/packages/evm/test/precompiles/0e-bls12-g2add.spec.ts +++ b/packages/evm/test/precompiles/0e-bls12-g2add.spec.ts @@ -89,7 +89,7 @@ describe('Precompiles: BLS12-G2-ADD', () => { for (const testVector of testData) { const result = await BLS12G2ADD({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(5000000), common, _EVM: evm, diff --git a/packages/evm/test/precompiles/0f-bls12-g2mul.spec.ts b/packages/evm/test/precompiles/0f-bls12-g2mul.spec.ts index 4a24d746f8..2496b58e27 100644 --- a/packages/evm/test/precompiles/0f-bls12-g2mul.spec.ts +++ b/packages/evm/test/precompiles/0f-bls12-g2mul.spec.ts @@ -80,7 +80,7 @@ describe('Precompiles: BLS12-G2-MUL', () => { for (const testVector of testData) { const result = await BLS12G2MUL({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(5000000), common, _EVM: evm, diff --git a/packages/evm/test/precompiles/10-bls12-g2msm.spec.ts b/packages/evm/test/precompiles/10-bls12-g2msm.spec.ts index 6ef36b0620..3eb070dfc1 100644 --- a/packages/evm/test/precompiles/10-bls12-g2msm.spec.ts +++ b/packages/evm/test/precompiles/10-bls12-g2msm.spec.ts @@ -107,7 +107,7 @@ describe('Precompiles: BLS12-G2-MSM', () => { for (const testVector of testData) { const result = await BLS12G2MSM({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(5000000), common, _EVM: evm, diff --git a/packages/evm/test/precompiles/11-bls12-pairing.spec.ts b/packages/evm/test/precompiles/11-bls12-pairing.spec.ts index 1a54d0f80b..bbb5422a12 100644 --- a/packages/evm/test/precompiles/11-bls12-pairing.spec.ts +++ b/packages/evm/test/precompiles/11-bls12-pairing.spec.ts @@ -820,7 +820,7 @@ describe('Precompiles: BLS12-PAIRING', () => { for (const testVector of testdata) { const result = await BLS12PAIRING({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(500000000), common, _EVM: evm, @@ -828,7 +828,7 @@ describe('Precompiles: BLS12-PAIRING', () => { assert.deepEqual( result.returnValue, - hexToBytes('0x' + testVector.Expected), + hexToBytes(`0x${testVector.Expected}`), 'return value should match testVectorResult' ) assert.equal(result.executionGasUsed, BigInt(testVector.Gas)) diff --git a/packages/evm/test/precompiles/12-bls12-g1map.spec.ts b/packages/evm/test/precompiles/12-bls12-g1map.spec.ts index 79947eb7d2..cfd9e8b74f 100644 --- a/packages/evm/test/precompiles/12-bls12-g1map.spec.ts +++ b/packages/evm/test/precompiles/12-bls12-g1map.spec.ts @@ -64,7 +64,7 @@ describe('Precompiles: BLS12-FP-TO-G1', () => { for (const testVector of testData) { const result = await BLS12FPTOG1({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(5000000), common, _EVM: evm, diff --git a/packages/evm/test/precompiles/13-bls12-g2map.spec.ts b/packages/evm/test/precompiles/13-bls12-g2map.spec.ts index 703f538c69..1090e7d491 100644 --- a/packages/evm/test/precompiles/13-bls12-g2map.spec.ts +++ b/packages/evm/test/precompiles/13-bls12-g2map.spec.ts @@ -64,7 +64,7 @@ describe('Precompiles: BLS12-FP2-TO-G2', () => { for (const testVector of testData) { const result = await BLS12FP2TOG2({ - data: hexToBytes('0x' + testVector.Input), + data: hexToBytes(`0x${testVector.Input}`), gasLimit: BigInt(5000000), common, _EVM: evm, diff --git a/packages/evm/test/precompiles/eip-2537-BLS.spec.ts b/packages/evm/test/precompiles/eip-2537-BLS.spec.ts index 010d70909e..a3be842027 100644 --- a/packages/evm/test/precompiles/eip-2537-BLS.spec.ts +++ b/packages/evm/test/precompiles/eip-2537-BLS.spec.ts @@ -5,13 +5,15 @@ import { assert, describe, it } from 'vitest' import { EVM } from '../../src/evm.js' import { getActivePrecompiles } from '../../src/index.js' +import type { PrefixedHexString } from '@ethereumjs/util' + const precompileAddressStart = 0x0b const precompileAddressEnd = 0x13 -const precompiles: string[] = [] +const precompiles: PrefixedHexString[] = [] for (let address = precompileAddressStart; address <= precompileAddressEnd; address++) { - precompiles.push('0x' + address.toString(16).padStart(40, '0')) + precompiles.push(`0x${address.toString(16).padStart(40, '0')}`) } describe('EIP-2537 BLS tests', () => { @@ -75,7 +77,7 @@ describe('EIP-2537 BLS tests', () => { assert.ok(true, 'BLS precompiles throw correctly on empty inputs') }) - /* + /* The following tests validate that the various precompiles associated with EIP2537 produce expected results against test vectors pulled from this collection of test data provided by Matter Labs here - https://github.com/matter-labs/eip1962/tree/master/src/test/test_vectors/eip2537 diff --git a/packages/evm/test/precompiles/hardfork.spec.ts b/packages/evm/test/precompiles/hardfork.spec.ts index 1027fed872..c617bf988c 100644 --- a/packages/evm/test/precompiles/hardfork.spec.ts +++ b/packages/evm/test/precompiles/hardfork.spec.ts @@ -7,7 +7,7 @@ import { EVM, getActivePrecompiles } from '../../src/index.js' describe('Precompiles: hardfork availability', () => { it('Test ECPAIRING availability', async () => { const ECPAIR_AddressStr = '0000000000000000000000000000000000000008' - const ECPAIR_Address = new Address(hexToBytes('0x' + ECPAIR_AddressStr)) + const ECPAIR_Address = new Address(hexToBytes(`0x${ECPAIR_AddressStr}`)) // ECPAIR was introduced in Byzantium; check if available from Byzantium. const commonByzantium = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Byzantium }) diff --git a/packages/evm/test/runCall.spec.ts b/packages/evm/test/runCall.spec.ts index 8a4f659289..01ea90578e 100644 --- a/packages/evm/test/runCall.spec.ts +++ b/packages/evm/test/runCall.spec.ts @@ -82,8 +82,7 @@ describe('RunCall tests', () => { value: BigInt(value), // call with this value (the value is used in the contract as an argument, see above's code) } - const hexString = '0x' + padToEven(value.toString(16)) - let valueBytes = hexToBytes(hexString) + let valueBytes = hexToBytes(`0x${padToEven(value.toString(16))}`) // pad bytes if (valueBytes.length < 32) { const diff = 32 - valueBytes.length @@ -179,7 +178,7 @@ describe('RunCall tests', () => { await evm.stateManager.putContractStorage( address, new Uint8Array(32), - hexToBytes('0x' + '00'.repeat(31) + '01') + hexToBytes(`0x${'00'.repeat(31)}01`) ) // setup the call arguments @@ -371,7 +370,7 @@ describe('RunCall tests', () => { // setup the accounts for this test const caller = new Address(hexToBytes('0x00000000000000000000000000000000000000ee')) // caller address const address = new Address(hexToBytes('0x00000000000000000000000000000000000000ff')) - const slot = hexToBytes('0x' + '00'.repeat(32)) + const slot = hexToBytes(`0x${'00'.repeat(32)}`) const emptyBytes = hexToBytes('0x') // setup the vm const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) diff --git a/packages/evm/test/runCode.spec.ts b/packages/evm/test/runCode.spec.ts index fdc0f2c790..791654dc1c 100644 --- a/packages/evm/test/runCode.spec.ts +++ b/packages/evm/test/runCode.spec.ts @@ -25,7 +25,7 @@ describe('VM.runCode: initial program counter', () => { for (const [i, testData] of testCases.entries()) { const runCodeArgs = { - code: hexToBytes('0x' + testData.code.join('')), + code: hexToBytes(`0x${testData.code.join('')}`), pc: testData.pc, gasLimit: BigInt(0xffff), } @@ -61,7 +61,7 @@ describe('VM.runCode: interpreter', () => { const INVALID_opcode = 'fe' const runCodeArgs = { - code: hexToBytes('0x' + INVALID_opcode), + code: hexToBytes(`0x${INVALID_opcode}`), gasLimit: BigInt(0xffff), } @@ -90,7 +90,7 @@ describe('VM.runCode: interpreter', () => { const SSTORE = '55' const runCodeArgs = { - code: hexToBytes('0x' + [PUSH1, '01', PUSH1, '05', SSTORE].join('')), + code: hexToBytes(`0x${[PUSH1, '01', PUSH1, '05', SSTORE].join('')}`), gasLimit: BigInt(0xffff), } diff --git a/packages/statemanager/test/cache/account.spec.ts b/packages/statemanager/test/cache/account.spec.ts index 194cdb7de6..a4cdffe844 100644 --- a/packages/statemanager/test/cache/account.spec.ts +++ b/packages/statemanager/test/cache/account.spec.ts @@ -18,7 +18,7 @@ describe('Account Cache: put and get account', () => { for (const type of [CacheType.LRU, CacheType.ORDERED_MAP]) { const cache = new AccountCache({ size: 100, type }) - const addr = new Address(hexToBytes('0x' + '10'.repeat(20))) + const addr = new Address(hexToBytes(`0x${'10'.repeat(20)}`)) const acc: Account = createAccount(BigInt(1), BigInt(0xff11)) const accRLP = acc.serialize() @@ -51,7 +51,7 @@ describe('Account Cache: checkpointing', () => { for (const type of [CacheType.LRU, CacheType.ORDERED_MAP]) { const cache = new AccountCache({ size: 100, type }) - const addr = new Address(hexToBytes('0x' + '10'.repeat(20))) + const addr = new Address(hexToBytes(`0x${'10'.repeat(20)}`)) const acc = createAccount(BigInt(1), BigInt(0xff11)) const accRLP = acc.serialize() diff --git a/packages/statemanager/test/cache/code.spec.ts b/packages/statemanager/test/cache/code.spec.ts index 232a9d0b48..2bbe3eaea7 100644 --- a/packages/statemanager/test/cache/code.spec.ts +++ b/packages/statemanager/test/cache/code.spec.ts @@ -17,7 +17,7 @@ describe('Code Cache: put and get code', () => { for (const type of [CacheType.LRU, CacheType.ORDERED_MAP]) { const cache = new CodeCache({ size: 100, type }) - const addr = new Address(hexToBytes('0x' + '10'.repeat(20))) + const addr = new Address(hexToBytes(`0x${'10'.repeat(20)}`)) const code = hexToBytes('0xdeadbeef') // Example code it('should return undefined for code if not present in the cache', async () => { @@ -49,7 +49,7 @@ describe('Code Cache: checkpointing', () => { for (const type of [CacheType.LRU, CacheType.ORDERED_MAP]) { const cache = new CodeCache({ size: 100, type }) - const addr = new Address(hexToBytes('0x' + '10'.repeat(20))) + const addr = new Address(hexToBytes(`0x${'10'.repeat(20)}`)) const code1 = hexToBytes('0xdeadbeef') // Example code const code2 = hexToBytes('0x00ff00ff') // Example code diff --git a/packages/statemanager/test/cache/storage.spec.ts b/packages/statemanager/test/cache/storage.spec.ts index 90138718fa..3fcb30d5f6 100644 --- a/packages/statemanager/test/cache/storage.spec.ts +++ b/packages/statemanager/test/cache/storage.spec.ts @@ -17,7 +17,7 @@ describe('Storage Cache: put and get account', () => { for (const type of [CacheType.LRU, CacheType.ORDERED_MAP]) { const cache = new StorageCache({ size: 100, type }) - const addr = new Address(hexToBytes('0x' + '10'.repeat(20))) + const addr = new Address(hexToBytes(`0x${'10'.repeat(20)}`)) const key = hexToBytes('0x01') const value = hexToBytes('0x01') @@ -48,7 +48,7 @@ describe('Storage Cache: put and get account', () => { describe('Storage Cache: checkpointing', () => { for (const type of [CacheType.LRU, CacheType.ORDERED_MAP]) { - const addr = new Address(hexToBytes('0x' + '10'.repeat(20))) + const addr = new Address(hexToBytes(`0x${'10'.repeat(20)}`)) const key = hexToBytes('0x01') const value = hexToBytes('0x01') diff --git a/packages/statemanager/test/checkpointing.account.spec.ts b/packages/statemanager/test/checkpointing.account.spec.ts index 29e3a48204..808466a3a2 100644 --- a/packages/statemanager/test/checkpointing.account.spec.ts +++ b/packages/statemanager/test/checkpointing.account.spec.ts @@ -26,7 +26,7 @@ const accountEval = async ( type CompareList = [Account | undefined, bigint | undefined] describe('StateManager -> Account Checkpointing', () => { - const address = new Address(hexToBytes('0x' + '11'.repeat(20))) + const address = new Address(hexToBytes(`0x${'11'.repeat(20)}`)) const accountN1: CompareList = [ Account.fromAccountData({ diff --git a/packages/statemanager/test/proofStateManager.spec.ts b/packages/statemanager/test/proofStateManager.spec.ts index c64bca76d0..ab83ce1fca 100644 --- a/packages/statemanager/test/proofStateManager.spec.ts +++ b/packages/statemanager/test/proofStateManager.spec.ts @@ -18,6 +18,9 @@ import * as ropsten_contractWithStorage from './testdata/ropsten_contractWithSto import * as ropsten_nonexistentAccount from './testdata/ropsten_nonexistentAccount.json' import * as ropsten_validAccount from './testdata/ropsten_validAccount.json' +import type { Proof } from '@ethereumjs/common' +import type { PrefixedHexString } from '@ethereumjs/util' + describe('ProofStateManager', () => { it(`should return quantity-encoded RPC representation`, async () => { const address = Address.zero() @@ -85,7 +88,7 @@ describe('ProofStateManager', () => { account!.balance = BigInt(1) account!.nonce = BigInt(2) await stateManager.putAccount(address, account!) - const address2 = new Address(hexToBytes('0x' + '20'.repeat(20))) + const address2 = new Address(hexToBytes(`0x${'20'.repeat(20)}`)) const account2 = await stateManager.getAccount(address2) account!.nonce = BigInt(2) await stateManager.putAccount(address2, account2!) @@ -113,13 +116,12 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_validAccount.accountProof) { - const bufferData = hexToBytes(proofData) + const bufferData = hexToBytes(proofData as PrefixedHexString) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key } - // @ts-expect-error - await trie._db.put(key, bufferData) + await trie['_db'].put(key, bufferData) } trie.root(stateRoot!) const proof = await stateManager.getProof(address) @@ -138,18 +140,17 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_nonexistentAccount.accountProof) { - const bufferData = hexToBytes(proofData) + const bufferData = hexToBytes(proofData as PrefixedHexString) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key } - // @ts-expect-error - await trie._db.put(key, bufferData) + await trie['_db'].put(key, bufferData) } trie.root(stateRoot!) const proof = await stateManager.getProof(address) assert.deepEqual((ropsten_nonexistentAccount as any).default, proof) - assert.ok(await stateManager.verifyProof(ropsten_nonexistentAccount)) + assert.ok(await stateManager.verifyProof(ropsten_nonexistentAccount as Proof)) }) it('should report data equal to geth output for EIP 1178 proofs - account with storage', async () => { @@ -163,23 +164,21 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_contractWithStorage.accountProof) { - const bufferData = hexToBytes(proofData) + const bufferData = hexToBytes(proofData as PrefixedHexString) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key } - // @ts-expect-error - await trie._db.put(key, bufferData) + await trie['_db'].put(key, bufferData) } - const storageRoot = ropsten_contractWithStorage.storageHash + const storageRoot = ropsten_contractWithStorage.storageHash as PrefixedHexString const storageTrie = new Trie({ useKeyHashing: true }) const storageKeys: Uint8Array[] = [] for (const storageProofsData of ropsten_contractWithStorage.storageProof) { - storageKeys.push(hexToBytes(storageProofsData.key)) + storageKeys.push(hexToBytes(storageProofsData.key as PrefixedHexString)) for (const storageProofData of storageProofsData.proof) { - const key = keccak256(hexToBytes(storageProofData)) - // @ts-expect-error - await storageTrie._db.put(key, hexToBytes(storageProofData)) + const key = keccak256(hexToBytes(storageProofData as PrefixedHexString)) + await storageTrie['_db'].put(key, hexToBytes(storageProofData as PrefixedHexString)) } } storageTrie.root(hexToBytes(storageRoot)) @@ -189,7 +188,7 @@ describe('ProofStateManager', () => { const proof = await stateManager.getProof(address, storageKeys) assert.deepEqual((ropsten_contractWithStorage as any).default, proof) - await stateManager.verifyProof(ropsten_contractWithStorage) + await stateManager.verifyProof(ropsten_contractWithStorage as Proof) }) it(`should throw on invalid proofs - existing accounts/slots`, async () => { @@ -203,23 +202,21 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_contractWithStorage.accountProof) { - const bufferData = hexToBytes(proofData) + const bufferData = hexToBytes(proofData as PrefixedHexString) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key } - // @ts-expect-error - await trie._db.put(key, bufferData) + await trie['_db'].put(key, bufferData) } - const storageRoot = ropsten_contractWithStorage.storageHash + const storageRoot = ropsten_contractWithStorage.storageHash as PrefixedHexString const storageTrie = new Trie({ useKeyHashing: true }) const storageKeys: Uint8Array[] = [] for (const storageProofsData of ropsten_contractWithStorage.storageProof) { - storageKeys.push(hexToBytes(storageProofsData.key)) + storageKeys.push(hexToBytes(storageProofsData.key as PrefixedHexString)) for (const storageProofData of storageProofsData.proof) { - const key = keccak256(hexToBytes(storageProofData)) - // @ts-expect-error - await storageTrie._db.put(key, hexToBytes(storageProofData)) + const key = keccak256(hexToBytes(storageProofData as PrefixedHexString)) + await storageTrie['_db'].put(key, hexToBytes(storageProofData as PrefixedHexString)) } } storageTrie.root(hexToBytes(storageRoot)) @@ -271,15 +268,14 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_nonexistentAccount.accountProof) { - const bufferData = hexToBytes(proofData) + const bufferData = hexToBytes(proofData as PrefixedHexString) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key } - // @ts-expect-error - await trie._db.put(key, bufferData) + await trie['_db'].put(key, bufferData) } - const storageRoot = ropsten_nonexistentAccount.storageHash + const storageRoot = ropsten_nonexistentAccount.storageHash as PrefixedHexString const storageTrie = new Trie({ useKeyHashing: true }) storageTrie.root(hexToBytes(storageRoot)) const addressHex = bytesToHex(address.bytes) diff --git a/packages/statemanager/test/stateManager.code.spec.ts b/packages/statemanager/test/stateManager.code.spec.ts index 3ee027013c..8ec2649297 100644 --- a/packages/statemanager/test/stateManager.code.spec.ts +++ b/packages/statemanager/test/stateManager.code.spec.ts @@ -5,6 +5,8 @@ import { DefaultStateManager } from '../src/index.js' import { createAccount } from './util.js' +import type { AccountData } from '@ethereumjs/util' + describe('StateManager -> Code', () => { for (const accountCacheOpts of [ { deactivate: false }, @@ -16,7 +18,7 @@ describe('StateManager -> Code', () => { This test is mostly an example of why a code prefix is necessary I an address, we put two storage values. The preimage of the (storage trie) root hash is known This preimage is used as codeHash - + NOTE: Currently, the only problem which this code prefix fixes, is putting 0x80 as contract code -> This hashes to the empty trie node hash (0x80 = RLP([])), so keccak256(0x80) = empty trie node hash -> Therefore, each empty state trie now points to 0x80, which is not a valid trie node, which crashes @ethereumjs/trie @@ -27,15 +29,14 @@ describe('StateManager -> Code', () => { const codeStateManager = new DefaultStateManager({ accountCacheOpts }) const address1 = new Address(hexToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b')) const account = createAccount() - const key1 = hexToBytes('0x' + '00'.repeat(32)) - const key2 = hexToBytes('0x' + '00'.repeat(31) + '01') + const key1 = hexToBytes(`0x${'00'.repeat(32)}`) + const key2 = hexToBytes(`0x${'00'.repeat(31)}01`) await stateManager.putAccount(address1, account) await stateManager.putContractStorage(address1, key1, key2) await stateManager.putContractStorage(address1, key2, key2) const root = await stateManager.getStateRoot() - // @ts-expect-error - const rawNode = await stateManager._trie._db.get(root) + const rawNode = await stateManager['_trie']['_db'].get(root) await codeStateManager.putContractCode(address1, rawNode!) @@ -85,10 +86,9 @@ describe('StateManager -> Code', () => { const code = hexToBytes( '0x73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873157' ) - const raw = { + const raw: AccountData = { nonce: '0x0', balance: '0x03e7', - stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4', } const account = Account.fromAccountData(raw) @@ -101,7 +101,7 @@ describe('StateManager -> Code', () => { it(`should not get code if is not contract`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) const address = new Address(hexToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b')) - const raw = { + const raw: AccountData = { nonce: '0x0', balance: '0x03e7', } @@ -114,7 +114,7 @@ describe('StateManager -> Code', () => { it(`should set empty code`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) const address = new Address(hexToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b')) - const raw = { + const raw: AccountData = { nonce: '0x0', balance: '0x03e7', } diff --git a/packages/trie/test/index.spec.ts b/packages/trie/test/index.spec.ts index 5866692fc7..1d901575e9 100644 --- a/packages/trie/test/index.spec.ts +++ b/packages/trie/test/index.spec.ts @@ -252,8 +252,7 @@ for (const keyPrefix of [undefined, hexToBytes('0x1234')]) { assert.ok(path.node !== null, 'findPath should find a node') const { stack } = await trie.findPath(utf8ToBytes('aaa')) - // @ts-expect-error - await trie._db.del(keccak256(stack[1].serialize())) // delete the BranchNode -> value1 from the DB + await trie['_db'].del(keccak256(stack[1].serialize())) // delete the BranchNode -> value1 from the DB path = await trie.findPath(utf8ToBytes('aaa')) diff --git a/packages/trie/test/trie/checkpoint.spec.ts b/packages/trie/test/trie/checkpoint.spec.ts index a85a1c93eb..3e0d320b7e 100644 --- a/packages/trie/test/trie/checkpoint.spec.ts +++ b/packages/trie/test/trie/checkpoint.spec.ts @@ -64,8 +64,7 @@ describe('testing checkpoints', () => { it('should copy trie and get upstream and cache values after checkpoint', async () => { trieCopy = trie.shallowCopy() assert.equal(bytesToHex(trieCopy.root()), postRoot) - // @ts-expect-error - assert.equal(trieCopy._db.checkpoints.length, 1) + assert.equal(trieCopy['_db'].checkpoints.length, 1) assert.ok(trieCopy.hasCheckpoints()) const res = await trieCopy.get(utf8ToBytes('do')) assert.ok(equalsBytes(utf8ToBytes('verb'), res!)) @@ -234,8 +233,7 @@ describe('testing checkpoints', () => { // The CommittedState should not change (not the key/value pairs, not the root, and not the root in DB) assert.equal(bytesToUtf8((await CommittedState.get(KEY))!), '1') assert.equal( - // @ts-expect-error - bytesToHex(await CommittedState._db.get(KEY_ROOT)), + bytesToHex((await CommittedState['_db'].get(KEY_ROOT))!), '0x77ddd505d2a5b76a2a6ee34b827a0d35ca19f8d358bee3d74a84eab59794487c' ) assert.equal( @@ -244,9 +242,9 @@ describe('testing checkpoints', () => { ) // From MemoryState, now take the final checkpoint - const finalCheckpoint = (MemoryState)._db.checkpoints[0] + const finalCheckpoint = MemoryState['_db'].checkpoints[0] // Insert this into CommittedState - ;(CommittedState)._db.checkpoints.push(finalCheckpoint) + CommittedState['_db'].checkpoints.push(finalCheckpoint) // Now all operations done on MemoryState (including pruning) can be // committed into CommittedState diff --git a/packages/tx/test/base.spec.ts b/packages/tx/test/base.spec.ts index 742d1ff570..a3bceeb764 100644 --- a/packages/tx/test/base.spec.ts +++ b/packages/tx/test/base.spec.ts @@ -279,7 +279,7 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey } = txType.fixtures[i] if (privateKey !== undefined) { - assert.ok(tx.sign(hexToBytes('0x' + privateKey)), `${txType.name}: should sign tx`) + assert.ok(tx.sign(hexToBytes(`0x${privateKey}`)), `${txType.name}: should sign tx`) } assert.throws( @@ -321,7 +321,7 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey, sendersAddress } = txType.fixtures[i] if (privateKey !== undefined) { - const signedTx = tx.sign(hexToBytes('0x' + privateKey)) + const signedTx = tx.sign(hexToBytes(`0x${privateKey}`)) assert.equal( signedTx.getSenderAddress().toString(), `0x${sendersAddress}`, @@ -337,9 +337,9 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey } = txType.fixtures[i] if (privateKey !== undefined) { - const signedTx = tx.sign(hexToBytes('0x' + privateKey)) + const signedTx = tx.sign(hexToBytes(`0x${privateKey}`)) const txPubKey = signedTx.getSenderPublicKey() - const pubKeyFromPriv = privateToPublic(hexToBytes('0x' + privateKey)) + const pubKeyFromPriv = privateToPublic(hexToBytes(`0x${privateKey}`)) assert.ok( equalsBytes(txPubKey, pubKeyFromPriv), `${txType.name}: should get sender's public key after signing it` @@ -356,7 +356,7 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey } = txType.fixtures[i] if (privateKey !== undefined) { - let signedTx = tx.sign(hexToBytes('0x' + privateKey)) + let signedTx = tx.sign(hexToBytes(`0x${privateKey}`)) signedTx = JSON.parse(JSON.stringify(signedTx)) // deep clone ;(signedTx as any).s = SECP256K1_ORDER + BigInt(1) assert.throws( @@ -377,7 +377,7 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey } = txType.fixtures[i] if (privateKey !== undefined) { - const signedTx = tx.sign(hexToBytes('0x' + privateKey)) + const signedTx = tx.sign(hexToBytes(`0x${privateKey}`)) assert.ok(signedTx.verifySignature(), `${txType.name}: should verify signing it`) } } diff --git a/packages/tx/test/eip1559.spec.ts b/packages/tx/test/eip1559.spec.ts index 05e3b11168..20b0dd4083 100644 --- a/packages/tx/test/eip1559.spec.ts +++ b/packages/tx/test/eip1559.spec.ts @@ -7,11 +7,14 @@ import { FeeMarketEIP1559Transaction } from '../src/index.js' import testdata from './json/eip1559.json' // Source: Besu +import type { FeeMarketEIP1559TxData, JsonTx } from '../src/index.js' +import type { PrefixedHexString } from '@ethereumjs/util' + const common = Common.custom({ chainId: 4 }) common.setHardfork(Hardfork.London) -const validAddress = hexToBytes('0x' + '01'.repeat(20)) -const validSlot = hexToBytes('0x' + '01'.repeat(32)) +const validAddress = hexToBytes(`0x${'01'.repeat(20)}`) +const validSlot = hexToBytes(`0x${'01'.repeat(32)}`) const chainId = BigInt(4) describe('[FeeMarketEIP1559Transaction]', () => { @@ -105,19 +108,19 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('sign()', () => { for (let index = 0; index < testdata.length; index++) { const data = testdata[index] - const pkey = hexToBytes(data.privateKey) - const txn = FeeMarketEIP1559Transaction.fromTxData(data, { common }) + const pkey = hexToBytes(data.privateKey as PrefixedHexString) + const txn = FeeMarketEIP1559Transaction.fromTxData(data as FeeMarketEIP1559TxData, { common }) const signed = txn.sign(pkey) const rlpSerialized = RLP.encode(Uint8Array.from(signed.serialize())) assert.ok( - equalsBytes(rlpSerialized, hexToBytes(data.signedTransactionRLP)), + equalsBytes(rlpSerialized, hexToBytes(data.signedTransactionRLP as PrefixedHexString)), 'Should sign txs correctly' ) } }) it('addSignature() -> correctly adds correct signature values', () => { - const privKey = hexToBytes(testdata[0].privateKey) + const privKey = hexToBytes(testdata[0].privateKey as PrefixedHexString) const tx = FeeMarketEIP1559Transaction.fromTxData({}) const signedTx = tx.sign(privKey) const addSignatureTx = tx.addSignature(signedTx.v!, signedTx.r!, signedTx.s!) @@ -126,7 +129,7 @@ describe('[FeeMarketEIP1559Transaction]', () => { }) it('addSignature() -> correctly converts raw ecrecover values', () => { - const privKey = hexToBytes(testdata[0].privateKey) + const privKey = hexToBytes(testdata[0].privateKey as PrefixedHexString) const tx = FeeMarketEIP1559Transaction.fromTxData({}) const msgHash = tx.getHashedMessageToSign() @@ -139,7 +142,7 @@ describe('[FeeMarketEIP1559Transaction]', () => { }) it('addSignature() -> throws when adding the wrong v value', () => { - const privKey = hexToBytes(testdata[0].privateKey) + const privKey = hexToBytes(testdata[0].privateKey as PrefixedHexString) const tx = FeeMarketEIP1559Transaction.fromTxData({}) const msgHash = tx.getHashedMessageToSign() @@ -153,8 +156,8 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('hash()', () => { const data = testdata[0] - const pkey = hexToBytes(data.privateKey) - let txn = FeeMarketEIP1559Transaction.fromTxData(data, { common }) + const pkey = hexToBytes(data.privateKey as PrefixedHexString) + let txn = FeeMarketEIP1559Transaction.fromTxData(data as FeeMarketEIP1559TxData, { common }) let signed = txn.sign(pkey) const expectedHash = hexToBytes( '0x2e564c87eb4b40e7f469b2eec5aa5d18b0b46a24e8bf0919439cfb0e8fcae446' @@ -163,7 +166,10 @@ describe('[FeeMarketEIP1559Transaction]', () => { equalsBytes(signed.hash(), expectedHash), 'Should provide the correct hash when frozen' ) - txn = FeeMarketEIP1559Transaction.fromTxData(data, { common, freeze: false }) + txn = FeeMarketEIP1559Transaction.fromTxData(data as FeeMarketEIP1559TxData, { + common, + freeze: false, + }) signed = txn.sign(pkey) assert.ok( equalsBytes(signed.hash(), expectedHash), @@ -173,8 +179,11 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('freeze property propagates from unsigned tx to signed tx', () => { const data = testdata[0] - const pkey = hexToBytes(data.privateKey) - const txn = FeeMarketEIP1559Transaction.fromTxData(data, { common, freeze: false }) + const pkey = hexToBytes(data.privateKey as PrefixedHexString) + const txn = FeeMarketEIP1559Transaction.fromTxData(data as FeeMarketEIP1559TxData, { + common, + freeze: false, + }) assert.notOk(Object.isFrozen(txn), 'tx object is not frozen') const signedTxn = txn.sign(pkey) assert.notOk(Object.isFrozen(signedTxn), 'tx object is not frozen') @@ -182,8 +191,11 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('common propagates from the common of tx, not the common in TxOptions', () => { const data = testdata[0] - const pkey = hexToBytes(data.privateKey) - const txn = FeeMarketEIP1559Transaction.fromTxData(data, { common, freeze: false }) + const pkey = hexToBytes(data.privateKey as PrefixedHexString) + const txn = FeeMarketEIP1559Transaction.fromTxData(data as FeeMarketEIP1559TxData, { + common, + freeze: false, + }) const newCommon = Common.custom({ chainId: 4 }) newCommon.setHardfork(Hardfork.Paris) @@ -228,12 +240,12 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('toJSON()', () => { const data = testdata[0] - const pkey = hexToBytes(data.privateKey) - const txn = FeeMarketEIP1559Transaction.fromTxData(data, { common }) + const pkey = hexToBytes(data.privateKey as PrefixedHexString) + const txn = FeeMarketEIP1559Transaction.fromTxData(data as FeeMarketEIP1559TxData, { common }) const signed = txn.sign(pkey) const json = signed.toJSON() - const expectedJSON = { + const expectedJSON: JsonTx = { type: '0x2', chainId: '0x4', nonce: '0x333', diff --git a/packages/tx/test/eip4844.spec.ts b/packages/tx/test/eip4844.spec.ts index 0f5dc907a7..6c552eec36 100644 --- a/packages/tx/test/eip4844.spec.ts +++ b/packages/tx/test/eip4844.spec.ts @@ -20,7 +20,8 @@ import { BlobEIP4844Transaction, TransactionFactory } from '../src/index.js' import blobTx from './json/serialized4844tx.json' -import type { Kzg } from '@ethereumjs/util' +import type { BlobEIP4844TxData } from '../src/index.js' +import type { Kzg, PrefixedHexString } from '@ethereumjs/util' const pk = randomBytes(32) describe('EIP4844 addSignature tests', () => { @@ -165,7 +166,7 @@ describe('fromTxData using from a json', () => { chainId: Number(txData.chainId), }) try { - const tx = BlobEIP4844Transaction.fromTxData(txData, { common: c }) + const tx = BlobEIP4844Transaction.fromTxData(txData as BlobEIP4844TxData, { common: c }) assert.ok(true, 'Should be able to parse a json data and hash it') assert.equal(typeof tx.maxFeePerBlobGas, 'bigint', 'should be able to parse correctly') @@ -182,7 +183,7 @@ describe('fromTxData using from a json', () => { ) const fromSerializedTx = BlobEIP4844Transaction.fromSerializedTx( - hexToBytes(txMeta.serialized), + hexToBytes(txMeta.serialized as PrefixedHexString), { common: c } ) assert.equal( @@ -327,7 +328,7 @@ describe('Network wrapper tests', () => { BlobEIP4844Transaction.fromTxData( { blobsData: ['hello world'], - blobs: ['hello world'], + blobs: ['hello world' as any], maxFeePerBlobGas: 100000000n, gasLimit: 0xffffffn, to: randomBytes(20), @@ -617,8 +618,7 @@ describe('Network wrapper deserialization test', () => { const commitments = blobsToCommitments(kzg, blobs) const proofs = blobsToProofs(kzg, blobs, commitments) - /* eslint-disable @typescript-eslint/no-use-before-define */ - const wrapper = hexToBytes(blobTx.tx) + const wrapper = hexToBytes(blobTx.tx as PrefixedHexString) const deserializedTx = BlobEIP4844Transaction.fromSerializedBlobTxNetworkWrapper(wrapper, { common, }) diff --git a/packages/tx/test/fromRpc.spec.ts b/packages/tx/test/fromRpc.spec.ts index 9dcadb2b21..a0940408b8 100644 --- a/packages/tx/test/fromRpc.spec.ts +++ b/packages/tx/test/fromRpc.spec.ts @@ -9,6 +9,8 @@ import optimismTx from './json/optimismTx.json' import rpcTx from './json/rpcTx.json' import v0Tx from './json/v0tx.json' +import type { TypedTxData } from '../src/index.js' + const txTypes = [ TransactionType.Legacy, TransactionType.AccessListEIP2930, @@ -77,7 +79,7 @@ describe('fromRPC: interpret v/r/s vals of 0x0 as undefined for Optimism system it('should work', async () => { for (const txType of txTypes) { ;(optimismTx as any).type = txType - const tx = await TransactionFactory.fromRPC(optimismTx) + const tx = await TransactionFactory.fromRPC(optimismTx as TypedTxData) assert.ok(tx.v === undefined) assert.ok(tx.s === undefined) assert.ok(tx.r === undefined) @@ -96,7 +98,7 @@ describe('fromRPC: ensure `v="0x0"` is correctly decoded for signed txs', () => continue } ;(v0Tx as any).type = txType - const tx = await TransactionFactory.fromRPC(v0Tx) + const tx = await TransactionFactory.fromRPC(v0Tx as TypedTxData) assert.ok(tx.isSigned()) } }) diff --git a/packages/tx/test/inputValue.spec.ts b/packages/tx/test/inputValue.spec.ts index 9ad8e62360..b5f3aaf53f 100644 --- a/packages/tx/test/inputValue.spec.ts +++ b/packages/tx/test/inputValue.spec.ts @@ -11,10 +11,10 @@ import { } from '../src/index.js' import type { TxValuesArray } from '../src/index.js' -import type { AddressLike, BigIntLike, BytesLike } from '@ethereumjs/util' +import type { AddressLike, BigIntLike, BytesLike, PrefixedHexString } from '@ethereumjs/util' // @returns: Array with subtypes of the AddressLike type for a given address -function generateAddressLikeValues(address: string): AddressLike[] { +function generateAddressLikeValues(address: PrefixedHexString): AddressLike[] { return [address, toBytes(address), new Address(toBytes(address))] } @@ -24,7 +24,7 @@ function generateBigIntLikeValues(value: number): BigIntLike[] { } // @returns: Array with subtypes of the BytesLike type for a given string -function generateBytesLikeValues(value: string): BytesLike[] { +function generateBytesLikeValues(value: PrefixedHexString): BytesLike[] { return [value, toBytes(value)] } @@ -153,7 +153,7 @@ describe('[Invalid Array Input values]', () => { for (const txType of txTypes) { let tx = TransactionFactory.fromTxData({ type: txType }) if (signed) { - tx = tx.sign(hexToBytes('0x' + '42'.repeat(32))) + tx = tx.sign(hexToBytes(`0x${'42'.repeat(32)}`)) } const rawValues = tx.raw() for (let x = 0; x < rawValues.length; x++) { @@ -222,14 +222,14 @@ describe('[Invalid Access Lists]', () => { accessList: invalidAccessListItem, }) if (signed) { - tx = tx.sign(hexToBytes('0x' + '42'.repeat(32))) + tx = tx.sign(hexToBytes(`0x${'42'.repeat(32)}`)) } assert.fail('did not fail on `fromTxData`') } catch (e: any) { assert.ok(true, 'failed ok on decoding in `fromTxData`') tx = TransactionFactory.fromTxData({ type: txType }) if (signed) { - tx = tx.sign(hexToBytes('0x' + '42'.repeat(32))) + tx = tx.sign(hexToBytes(`0x${'42'.repeat(32)}`)) } } const rawValues = tx!.raw() diff --git a/packages/tx/test/legacy.spec.ts b/packages/tx/test/legacy.spec.ts index 8390f8b3b7..2194a5dcdc 100644 --- a/packages/tx/test/legacy.spec.ts +++ b/packages/tx/test/legacy.spec.ts @@ -17,6 +17,7 @@ import txFixturesEip155 from './json/ttTransactionTestEip155VitaliksTests.json' import txFixtures from './json/txs.json' import type { TransactionType, TxData, TypedTransaction } from '../src/index.js' +import type { PrefixedHexString } from '@ethereumjs/util' describe('[Transaction]', () => { const transactions: TypedTransaction[] = [] @@ -60,7 +61,7 @@ describe('[Transaction]', () => { 'should initialize on a pre-Berlin Harfork (EIP-2930 not activated)' ) - const txData = txFixtures[3].raw.map(hexToBytes) + const txData = txFixtures[3].raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)) txData[6] = intToBytes(45) // v with 0-parity and chain ID 5 let tx = LegacyTransaction.fromValuesArray(txData) assert.ok( @@ -94,7 +95,7 @@ describe('[Transaction]', () => { it('Initialization -> decode with fromValuesArray()', () => { for (const tx of txFixtures.slice(0, 4)) { - const txData = tx.raw.map(hexToBytes) + const txData = tx.raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)) const pt = LegacyTransaction.fromValuesArray(txData) assert.equal(bytesToHex(unpadBytes(toBytes(pt.nonce))), tx.raw[0]) @@ -120,7 +121,7 @@ describe('[Transaction]', () => { let common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Petersburg }) let tx = LegacyTransaction.fromTxData({}, { common }) assert.equal(tx.common.chainId(), BigInt(5)) - const privKey = hexToBytes('0x' + txFixtures[0].privateKey) + const privKey = hexToBytes(`0x${txFixtures[0].privateKey}`) tx = tx.sign(privKey) const serialized = tx.serialize() common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Petersburg }) @@ -135,7 +136,7 @@ describe('[Transaction]', () => { }) it('addSignature() -> correctly adds correct signature values', () => { - const privKey = hexToBytes('0x' + txFixtures[0].privateKey) + const privKey = hexToBytes(`0x${txFixtures[0].privateKey}`) const tx = LegacyTransaction.fromTxData({}) const signedTx = tx.sign(privKey) const addSignatureTx = tx.addSignature(signedTx.v!, signedTx.r!, signedTx.s!) @@ -144,7 +145,7 @@ describe('[Transaction]', () => { }) it('addSignature() -> correctly adds correct signature values from ecrecover with ChainID protection enabled', () => { - const privKey = hexToBytes('0x' + txFixtures[0].privateKey) + const privKey = hexToBytes(`0x${txFixtures[0].privateKey}`) const tx = LegacyTransaction.fromTxData({}, { common: new Common({ chain: Chain.Sepolia }) }) const signedTx = tx.sign(privKey) // `convertV` set to false, since we use the raw value from the signed tx @@ -155,7 +156,7 @@ describe('[Transaction]', () => { }) it('addSignature() -> throws when adding the wrong v value', () => { - const privKey = hexToBytes('0x' + txFixtures[0].privateKey) + const privKey = hexToBytes(`0x${txFixtures[0].privateKey}`) const tx = LegacyTransaction.fromTxData({}, { common: new Common({ chain: Chain.Sepolia }) }) const signedTx = tx.sign(privKey) // `convertV` set to true: this will apply EIP-155 replay transaction twice, so it should throw! @@ -185,10 +186,15 @@ describe('[Transaction]', () => { let tx = LegacyTransaction.fromTxData({}) assert.equal(tx.getDataFee(), BigInt(0)) - tx = LegacyTransaction.fromValuesArray(txFixtures[3].raw.map(hexToBytes)) + tx = LegacyTransaction.fromValuesArray( + txFixtures[3].raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)) + ) assert.equal(tx.getDataFee(), BigInt(1716)) - tx = LegacyTransaction.fromValuesArray(txFixtures[3].raw.map(hexToBytes), { freeze: false }) + tx = LegacyTransaction.fromValuesArray( + txFixtures[3].raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)), + { freeze: false } + ) assert.equal(tx.getDataFee(), BigInt(1716)) }) @@ -197,17 +203,23 @@ describe('[Transaction]', () => { let tx = LegacyTransaction.fromTxData({}, { common }) assert.equal(tx.getDataFee(), BigInt(0)) - tx = LegacyTransaction.fromValuesArray(txFixtures[3].raw.map(hexToBytes), { - common, - }) + tx = LegacyTransaction.fromValuesArray( + txFixtures[3].raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)), + { + common, + } + ) assert.equal(tx.getDataFee(), BigInt(1716)) }) it('getDataFee() -> should invalidate cached value on hardfork change', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Byzantium }) - const tx = LegacyTransaction.fromValuesArray(txFixtures[0].raw.map(hexToBytes), { - common, - }) + const tx = LegacyTransaction.fromValuesArray( + txFixtures[0].raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)), + { + common, + } + ) assert.equal(tx.getDataFee(), BigInt(656)) tx.common.setHardfork(Hardfork.Istanbul) assert.equal(tx.getDataFee(), BigInt(240)) @@ -257,9 +269,12 @@ describe('[Transaction]', () => { hardfork: Hardfork.TangerineWhistle, }) - let tx = LegacyTransaction.fromValuesArray(txFixtures[3].raw.slice(0, 6).map(hexToBytes), { - common, - }) + let tx = LegacyTransaction.fromValuesArray( + txFixtures[3].raw.slice(0, 6).map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)), + { + common, + } + ) assert.throws( () => { tx.hash() @@ -268,9 +283,12 @@ describe('[Transaction]', () => { undefined, 'should throw calling hash with unsigned tx' ) - tx = LegacyTransaction.fromValuesArray(txFixtures[3].raw.map(hexToBytes), { - common, - }) + tx = LegacyTransaction.fromValuesArray( + txFixtures[3].raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)), + { + common, + } + ) assert.deepEqual( tx.hash(), hexToBytes('0x375a8983c9fc56d7cfd118254a80a8d7403d590a6c9e105532b67aca1efb97aa') @@ -287,7 +305,9 @@ describe('[Transaction]', () => { }) it('hash() -> with defined chainId', () => { - const tx = LegacyTransaction.fromValuesArray(txFixtures[4].raw.map(hexToBytes)) + const tx = LegacyTransaction.fromValuesArray( + txFixtures[4].raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)) + ) assert.equal( bytesToHex(tx.hash()), '0x0f09dc98ea85b7872f4409131a790b91e7540953992886fc268b7ba5c96820e4' @@ -304,10 +324,10 @@ describe('[Transaction]', () => { it("getHashedMessageToSign(), getSenderPublicKey() (implicit call) -> verify EIP155 signature based on Vitalik's tests", () => { for (const tx of txFixturesEip155) { - const pt = LegacyTransaction.fromSerializedTx(hexToBytes(tx.rlp)) - assert.equal(bytesToHex(pt.getHashedMessageToSign()), '0x' + tx.hash) + const pt = LegacyTransaction.fromSerializedTx(hexToBytes(tx.rlp as PrefixedHexString)) + assert.equal(bytesToHex(pt.getHashedMessageToSign()), `0x${tx.hash}`) assert.equal(bytesToHex(pt.serialize()), tx.rlp) - assert.equal(pt.getSenderAddress().toString(), '0x' + tx.sender) + assert.equal(pt.getSenderAddress().toString(), `0x${tx.sender}`) } }) @@ -324,7 +344,9 @@ describe('[Transaction]', () => { const privateKey = hexToBytes( '0x4646464646464646464646464646464646464646464646464646464646464646' ) - const pt = LegacyTransaction.fromValuesArray(txRaw.map(hexToBytes)) + const pt = LegacyTransaction.fromValuesArray( + txRaw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)) + ) // Note that Vitalik's example has a very similar value denoted "signing data". // It's not the output of `serialize()`, but the pre-image of the hash returned by `tx.hash(false)`. @@ -347,11 +369,14 @@ describe('[Transaction]', () => { it('sign(), getSenderPublicKey() (implicit call) -> EIP155 hashing when singing', () => { const common = new Common({ chain: 1, hardfork: Hardfork.Petersburg }) for (const txData of txFixtures.slice(0, 3)) { - const tx = LegacyTransaction.fromValuesArray(txData.raw.slice(0, 6).map(hexToBytes), { - common, - }) + const tx = LegacyTransaction.fromValuesArray( + txData.raw.slice(0, 6).map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)), + { + common, + } + ) - const privKey = hexToBytes('0x' + txData.privateKey) + const privKey = hexToBytes(`0x${txData.privateKey}`) const txSigned = tx.sign(privKey) assert.equal( @@ -375,7 +400,10 @@ describe('[Transaction]', () => { '0xDE3128752F183E8930D7F00A2AAA302DCB5E700B2CBA2D8CA5795660F07DEFD5' ) const common = Common.custom({ chainId: 3 }) - const tx = LegacyTransaction.fromValuesArray(txRaw.map(hexToBytes), { common }) + const tx = LegacyTransaction.fromValuesArray( + txRaw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)), + { common } + ) const signedTx = tx.sign(privateKey) assert.equal( bytesToHex(signedTx.serialize()), @@ -463,7 +491,7 @@ describe('[Transaction]', () => { let tx = LegacyTransaction.fromTxData({}, { common }) assert.equal(tx.common.chainId(), BigInt(5)) - const privKey = hexToBytes('0x' + txFixtures[0].privateKey) + const privKey = hexToBytes(`0x${txFixtures[0].privateKey}`) tx = tx.sign(privKey) const serialized = tx.serialize() @@ -476,14 +504,14 @@ describe('[Transaction]', () => { it('freeze property propagates from unsigned tx to signed tx', () => { const tx = LegacyTransaction.fromTxData({}, { freeze: false }) assert.notOk(Object.isFrozen(tx), 'tx object is not frozen') - const privKey = hexToBytes('0x' + txFixtures[0].privateKey) + const privKey = hexToBytes(`0x${txFixtures[0].privateKey}`) const signedTxn = tx.sign(privKey) assert.notOk(Object.isFrozen(signedTxn), 'tx object is not frozen') }) it('common propagates from the common of tx, not the common in TxOptions', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const pkey = hexToBytes('0x' + txFixtures[0].privateKey) + const pkey = hexToBytes(`0x${txFixtures[0].privateKey}`) const txn = LegacyTransaction.fromTxData({}, { common, freeze: false }) const newCommon = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Paris }) assert.notDeepEqual(newCommon, common, 'new common is different than original common') diff --git a/packages/tx/test/transactionRunner.spec.ts b/packages/tx/test/transactionRunner.spec.ts index f09206be10..24bdc3dfcd 100644 --- a/packages/tx/test/transactionRunner.spec.ts +++ b/packages/tx/test/transactionRunner.spec.ts @@ -1,5 +1,5 @@ import { Common } from '@ethereumjs/common' -import { bytesToHex, toBytes } from '@ethereumjs/util' +import { bytesToHex, hexToBytes } from '@ethereumjs/util' import minimist from 'minimist' import { assert, describe, it } from 'vitest' @@ -8,6 +8,7 @@ import { TransactionFactory } from '../src/index.js' import { getTests } from './testLoader.js' import type { ForkName, ForkNamesMap, OfficialTransactionTestData } from './types.js' +import type { PrefixedHexString } from '@ethereumjs/util' const argv = minimist(process.argv.slice(2)) const file: string | undefined = argv.file @@ -62,7 +63,7 @@ describe('TransactionTests', async () => { const shouldBeInvalid = forkTestData.exception !== undefined try { - const rawTx = toBytes(testData.txbytes) + const rawTx = hexToBytes(testData.txbytes as PrefixedHexString) const hardfork = forkNameMap[forkName] const common = new Common({ chain: 1, hardfork }) const activateEIPs = EIPs[forkName] diff --git a/packages/tx/test/typedTxsAndEIP2930.spec.ts b/packages/tx/test/typedTxsAndEIP2930.spec.ts index 4747abe21f..32cde1fd69 100644 --- a/packages/tx/test/typedTxsAndEIP2930.spec.ts +++ b/packages/tx/test/typedTxsAndEIP2930.spec.ts @@ -20,7 +20,7 @@ import { TransactionType, } from '../src/index.js' -import type { AccessList, AccessListBytesItem } from '../src/index.js' +import type { AccessList, AccessListBytesItem, JsonTx } from '../src/index.js' const pKey = hexToBytes('0x4646464646464646464646464646464646464646464646464646464646464646') const address = privateToAddress(pKey) @@ -43,8 +43,8 @@ const txTypes = [ }, ] -const validAddress = hexToBytes('0x' + '01'.repeat(20)) -const validSlot = hexToBytes('0x' + '01'.repeat(32)) +const validAddress = hexToBytes(`0x${'01'.repeat(20)}`) +const validSlot = hexToBytes(`0x${'01'.repeat(32)}`) const chainId = BigInt(Chain.Mainnet) describe('[AccessListEIP2930Transaction / FeeMarketEIP1559Transaction] -> EIP-2930 Compatibility', () => { @@ -229,7 +229,7 @@ describe('[AccessListEIP2930Transaction / FeeMarketEIP1559Transaction] -> EIP-29 for (const txType of txTypes) { let accessList: any[] = [ [ - hexToBytes('0x' + '01'.repeat(21)), // Address of 21 bytes instead of 20 + hexToBytes(`0x${'01'.repeat(21)}`), // Address of 21 bytes instead of 20 [], ], ] @@ -247,7 +247,7 @@ describe('[AccessListEIP2930Transaction / FeeMarketEIP1559Transaction] -> EIP-29 [ validAddress, [ - hexToBytes('0x' + '01'.repeat(31)), // Slot of 31 bytes instead of 32 + hexToBytes(`0x${'01'.repeat(31)}`), // Slot of 31 bytes instead of 32 ], ], ] @@ -424,8 +424,8 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { 'should initialize correctly from its own data' ) - const validAddress = hexToBytes('0x' + '01'.repeat(20)) - const validSlot = hexToBytes('0x' + '01'.repeat(32)) + const validAddress = hexToBytes(`0x${'01'.repeat(20)}`) + const validSlot = hexToBytes(`0x${'01'.repeat(32)}`) const chainId = BigInt(1) try { AccessListEIP2930Transaction.fromTxData( @@ -646,7 +646,7 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { assert.ok(equalsBytes(expectedSigned, signed.serialize()), 'serialized signed message correct') assert.ok(equalsBytes(expectedHash, signed.hash()), 'hash correct') - const expectedJSON = { + const expectedJSON: JsonTx = { type: '0x1', chainId: '0x796f6c6f763378', nonce: '0x0', diff --git a/packages/util/test/account.spec.ts b/packages/util/test/account.spec.ts index 89ce72f45b..4d2bca3d4b 100644 --- a/packages/util/test/account.spec.ts +++ b/packages/util/test/account.spec.ts @@ -32,7 +32,8 @@ import { import eip1014Testdata from './testdata/eip1014Examples.json' -import type { AccountBodyBytes } from '../src/index.js' +import type { AccountBodyBytes, AccountData, PrefixedHexString } from '../src/index.js' +import type { Input } from '@ethereumjs/rlp' const _0n = BigInt(0) @@ -54,7 +55,7 @@ describe('Account', () => { }) it('from Array data', () => { - const raw = [ + const raw: PrefixedHexString[] = [ '0x02', // nonce '0x0384', // balance '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', // storageRoot @@ -77,7 +78,7 @@ describe('Account', () => { }) it('from Object data', () => { - const raw = { + const raw: AccountData = { nonce: '0x02', balance: '0x0384', storageRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', @@ -118,14 +119,14 @@ describe('Account', () => { }) it('serialize', () => { - const raw = { + const raw: AccountData = { nonce: '0x01', balance: '0x42', storageRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', codeHash: '0xc5d2461236f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', } const account = Account.fromAccountData(raw) - const accountRlp = RLP.encode([raw.nonce, raw.balance, raw.storageRoot, raw.codeHash]) + const accountRlp = RLP.encode([raw.nonce, raw.balance, raw.storageRoot, raw.codeHash] as Input) assert.ok(equalsBytes(account.serialize(), accountRlp), 'should serialize correctly') }) @@ -137,7 +138,7 @@ describe('Account', () => { let account = Account.fromRlpSerializedAccount(accountRlp) assert.notOk(account.isContract(), 'should return false for a non-contract account') - const raw = { + const raw: AccountData = { nonce: '0x01', balance: '0x0042', storageRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', @@ -151,7 +152,7 @@ describe('Account', () => { let account = new Account() assert.ok(account.isEmpty(), 'should return true for an empty account') - const raw = { + const raw: AccountData = { nonce: '0x01', balance: '0x0042', storageRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', @@ -214,29 +215,43 @@ describe('Utility Functions', () => { it('isValidPrivate', () => { const SECP256K1_N = BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141') - let tmp = '0x0011223344' - assert.notOk(isValidPrivate(hexToBytes(tmp)), 'should fail on short input') + assert.notOk(isValidPrivate(hexToBytes('0x0011223344')), 'should fail on short input') - tmp = - '0x3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' - assert.notOk(isValidPrivate(hexToBytes(tmp)), 'should fail on too big input') + assert.notOk( + isValidPrivate( + hexToBytes( + '0x3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' + ) + ), + 'should fail on too big input' + ) assert.notOk( isValidPrivate(('WRONG_INPUT_TYPE') as Uint8Array), 'should fail on wrong input type' ) - tmp = '0x0000000000000000000000000000000000000000000000000000000000000000' - assert.notOk(isValidPrivate(hexToBytes(tmp)), 'should fail on invalid curve (zero)') + assert.notOk( + isValidPrivate( + hexToBytes('0x0000000000000000000000000000000000000000000000000000000000000000') + ), + 'should fail on invalid curve (zero)' + ) - tmp = '0x' + SECP256K1_N.toString(16) - assert.notOk(isValidPrivate(hexToBytes(tmp)), 'should fail on invalid curve (== N)') + assert.notOk( + isValidPrivate(hexToBytes(`0x${SECP256K1_N.toString(16)}`)), + 'should fail on invalid curve (== N)' + ) - tmp = '0x' + (SECP256K1_N + BigInt(1)).toString(16) - assert.notOk(isValidPrivate(hexToBytes(tmp)), 'should fail on invalid curve (>= N)') + assert.notOk( + isValidPrivate(hexToBytes(`0x${(SECP256K1_N + BigInt(1)).toString(16)}`)), + 'should fail on invalid curve (>= N)' + ) - tmp = '0x' + (SECP256K1_N - BigInt(1)).toString(16) - assert.ok(isValidPrivate(hexToBytes(tmp)), 'should work otherwise (< N)') + assert.ok( + isValidPrivate(hexToBytes(`0x${(SECP256K1_N - BigInt(1)).toString(16)}`)), + 'should work otherwise (< N)' + ) }) it('isValidPublic', () => { @@ -313,25 +328,36 @@ describe('Utility Functions', () => { const pubKey = '0x3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' - let tmp = - '0x3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' assert.equal( - bytesToHex(importPublic(hexToBytes(tmp))), + bytesToHex( + importPublic( + hexToBytes( + '0x3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' + ) + ) + ), pubKey, 'should work wt.testh an Ethereum public key' ) - tmp = - '0x043a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' assert.equal( - bytesToHex(importPublic(hexToBytes(tmp))), + bytesToHex( + importPublic( + hexToBytes( + '0x043a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d' + ) + ) + ), pubKey, 'should work wt.testh uncompressed SEC1 keys' ) - tmp = '0x033a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a' assert.equal( - bytesToHex(importPublic(hexToBytes(tmp))), + bytesToHex( + importPublic( + hexToBytes('0x033a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a') + ) + ), pubKey, 'should work wt.testh compressed SEC1 keys' ) @@ -507,7 +533,11 @@ describe('Utility Functions', () => { it('generateAddress2: EIP-1014 testdata examples', () => { for (const testdata of eip1014Testdata) { const { address, comment, result, salt, initCode } = testdata - const addr = generateAddress2(toBytes(address), toBytes(salt), toBytes(initCode)) + const addr = generateAddress2( + hexToBytes(address as PrefixedHexString), + hexToBytes(salt as PrefixedHexString), + hexToBytes(initCode as PrefixedHexString) + ) assert.equal(bytesToHex(addr), result, `${comment}: should generate the addresses provided`) } }) @@ -517,7 +547,11 @@ describe('Utility Functions', () => { assert.throws( function () { - generateAddress2((address) as Uint8Array, toBytes(salt), toBytes(initCode)) + generateAddress2( + (address) as Uint8Array, + hexToBytes(salt as PrefixedHexString), + hexToBytes(initCode as PrefixedHexString) + ) }, undefined, undefined, @@ -526,7 +560,11 @@ describe('Utility Functions', () => { assert.throws( function () { - generateAddress2(toBytes(address), (salt) as Uint8Array, toBytes(initCode)) + generateAddress2( + hexToBytes(address as PrefixedHexString), + (salt) as Uint8Array, + hexToBytes(initCode as PrefixedHexString) + ) }, undefined, undefined, @@ -535,7 +573,11 @@ describe('Utility Functions', () => { assert.throws( function () { - generateAddress2(toBytes(address), toBytes(salt), (initCode) as Uint8Array) + generateAddress2( + hexToBytes(address as PrefixedHexString), + hexToBytes(salt as PrefixedHexString), + (initCode) as Uint8Array + ) }, undefined, undefined, @@ -612,7 +654,7 @@ describe('Utility Functions', () => { assert.equal( toChecksumAddress( addr.toLowerCase(), - hexToBytes('0x' + padToEven(chainId)) + hexToBytes(`0x${padToEven(chainId)}`) ).toLowerCase(), addr.toLowerCase() ) @@ -621,7 +663,7 @@ describe('Utility Functions', () => { addr.toLowerCase() ) assert.equal( - toChecksumAddress(addr.toLowerCase(), '0x' + padToEven(chainId)).toLowerCase(), + toChecksumAddress(addr.toLowerCase(), `0x${padToEven(chainId)}`).toLowerCase(), addr.toLowerCase() ) } @@ -648,7 +690,7 @@ describe('Utility Functions', () => { assert.throws( function () { - toChecksumAddress('0xde709f2102306220921060314715629080e2fb77', '1234') + toChecksumAddress('0xde709f2102306220921060314715629080e2fb77', '1234' as any) }, undefined, undefined, @@ -673,7 +715,7 @@ describe('Utility Functions', () => { assert.ok(isValidChecksumAddress(addr, intToBytes(parseInt(chainId)))) assert.ok(isValidChecksumAddress(addr, BigInt(chainId))) assert.ok( - isValidChecksumAddress(addr, '0x' + padToEven(intToHex(parseInt(chainId)).slice(2))) + isValidChecksumAddress(addr, `0x${padToEven(intToHex(parseInt(chainId)).slice(2))}`) ) } } diff --git a/packages/util/test/address.spec.ts b/packages/util/test/address.spec.ts index 9a2312ef07..c0fc0b0e76 100644 --- a/packages/util/test/address.spec.ts +++ b/packages/util/test/address.spec.ts @@ -4,6 +4,8 @@ import { Address, equalsBytes, hexToBytes, toBytes } from '../src/index.js' import eip1014Testdata from './testdata/eip1014Examples.json' +import type { PrefixedHexString } from '../src/index.js' + describe('Address', () => { const ZERO_ADDR_S = '0x0000000000000000000000000000000000000000' @@ -81,7 +83,11 @@ describe('Address', () => { for (const testdata of eip1014Testdata) { const { address, salt, initCode, result } = testdata const from = Address.fromString(address) - const addr = Address.generate2(from, toBytes(salt), toBytes(initCode)) + const addr = Address.generate2( + from, + hexToBytes(salt as PrefixedHexString), + hexToBytes(initCode as PrefixedHexString) + ) assert.equal(addr.toString(), result) } }) diff --git a/packages/vm/test/api/EIPs/eip-1153.spec.ts b/packages/vm/test/api/EIPs/eip-1153.spec.ts index 3ca6374fd1..d59e588852 100644 --- a/packages/vm/test/api/EIPs/eip-1153.spec.ts +++ b/packages/vm/test/api/EIPs/eip-1153.spec.ts @@ -6,6 +6,7 @@ import { assert, describe, it } from 'vitest' import { VM } from '../../../src/vm' import type { TypedTransaction } from '@ethereumjs/tx' +import type { PrefixedHexString } from '@ethereumjs/util' interface Test { steps: { expectedOpcode: string; expectedGasUsed: number; expectedStack: bigint[] }[] @@ -53,7 +54,7 @@ describe('EIP 1153: transient storage', () => { }) for (const { code, address } of test.contracts) { - await vm.stateManager.putContractCode(address, hexToBytes(code)) + await vm.stateManager.putContractCode(address, hexToBytes(code as PrefixedHexString)) } const fromAddress = new Address(privateToAddress(senderKey)) diff --git a/packages/vm/test/api/EIPs/eip-1283-net-gas-metering.spec.ts b/packages/vm/test/api/EIPs/eip-1283-net-gas-metering.spec.ts index cd4289cf65..f00dee5af1 100644 --- a/packages/vm/test/api/EIPs/eip-1283-net-gas-metering.spec.ts +++ b/packages/vm/test/api/EIPs/eip-1283-net-gas-metering.spec.ts @@ -5,6 +5,8 @@ import { assert, describe, it } from 'vitest' import { VM } from '../../../src/vm' import { createAccount } from '../utils' +import type { PrefixedHexString } from '@ethereumjs/util' + /** * Tests taken from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1283.md */ @@ -40,7 +42,7 @@ describe('Constantinople: EIP-1283', () => { const account = createAccount(BigInt(0), BigInt(0)) await vm.stateManager.putAccount(addr, account) - await vm.stateManager.putContractCode(addr, hexToBytes(testCase.code)) + await vm.stateManager.putContractCode(addr, hexToBytes(testCase.code as PrefixedHexString)) if (testCase.original !== BigInt(0)) { await vm.stateManager.putContractStorage(addr, key, bigIntToBytes(testCase.original)) } diff --git a/packages/vm/test/api/EIPs/eip-1559-FeeMarket.spec.ts b/packages/vm/test/api/EIPs/eip-1559-FeeMarket.spec.ts index 5ac537eb86..834bcde51a 100644 --- a/packages/vm/test/api/EIPs/eip-1559-FeeMarket.spec.ts +++ b/packages/vm/test/api/EIPs/eip-1559-FeeMarket.spec.ts @@ -39,8 +39,8 @@ common.hardforkBlock = function (hardfork: string | undefined) { return BigInt(0) } -const coinbase = new Address(hexToBytes('0x' + '11'.repeat(20))) -const pkey = hexToBytes('0x' + '20'.repeat(32)) +const coinbase = new Address(hexToBytes(`0x${'11'.repeat(20)}`)) +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) const sender = new Address(privateToAddress(pkey)) /** @@ -168,7 +168,7 @@ describe('EIP1559 tests', () => { }) it('gasPrice uses the effective gas price', async () => { - const contractAddress = new Address(hexToBytes('0x' + '20'.repeat(20))) + const contractAddress = new Address(hexToBytes(`0x${'20'.repeat(20)}`)) const tx = new FeeMarketEIP1559Transaction( { maxFeePerGas: GWEI * BigInt(5), diff --git a/packages/vm/test/api/EIPs/eip-2565-modexp-gas-cost.spec.ts b/packages/vm/test/api/EIPs/eip-2565-modexp-gas-cost.spec.ts index 4303c596b0..602e76f7ec 100644 --- a/packages/vm/test/api/EIPs/eip-2565-modexp-gas-cost.spec.ts +++ b/packages/vm/test/api/EIPs/eip-2565-modexp-gas-cost.spec.ts @@ -21,7 +21,7 @@ describe('EIP-2565 ModExp gas cost tests', () => { gasLimit: BigInt(0xffffffffff), to, value: BigInt(0), - data: hexToBytes('0x' + test.Input), + data: hexToBytes(`0x${test.Input}`), }) if (result.execResult.executionGasUsed !== BigInt(test.Gas)) { @@ -36,7 +36,7 @@ describe('EIP-2565 ModExp gas cost tests', () => { continue } - if (!equalsBytes(result.execResult.returnValue, hexToBytes('0x' + test.Expected))) { + if (!equalsBytes(result.execResult.returnValue, hexToBytes(`0x${test.Expected}`))) { assert.fail( `[${testName}]: Return value not the expected value (expected: ${ test.Expected diff --git a/packages/vm/test/api/EIPs/eip-2929.spec.ts b/packages/vm/test/api/EIPs/eip-2929.spec.ts index b2dcbcb87c..e1da4ae26a 100644 --- a/packages/vm/test/api/EIPs/eip-2929.spec.ts +++ b/packages/vm/test/api/EIPs/eip-2929.spec.ts @@ -5,6 +5,8 @@ import { assert, describe, it } from 'vitest' import { VM } from '../../../src/vm' +import type { PrefixedHexString } from '@ethereumjs/util' + // Test cases source: https://gist.github.com/holiman/174548cad102096858583c6fbbb0649a describe('EIP 2929: gas cost tests', () => { const initialGas = BigInt(0xffffffffff) @@ -61,7 +63,7 @@ describe('EIP 2929: gas cost tests', () => { return result } - const runCodeTest = async function (code: string, expectedGasUsed: bigint) { + const runCodeTest = async function (code: PrefixedHexString, expectedGasUsed: bigint) { // setup the accounts for this test const privateKey = hexToBytes( '0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' @@ -269,10 +271,10 @@ describe('EIP 2929: gas cost tests', () => { // call to address 0xFFFF..FF const callFF = '6000808080806000195AF1' // call address 0xFF..FF, now call same contract again, call 0xFF..FF again (it is now warm) - await runCodeTest('0x' + callFF + '60003415601B57600080808080305AF15B00', BigInt(23909)) + await runCodeTest(`0x${callFF}60003415601B57600080808080305AF15B00`, BigInt(23909)) // call to contract, call 0xFF..FF, revert, call 0xFF..FF (should be cold) await runCodeTest( - '0x341515601557' + callFF + '600080FD5B600080808080305AF1' + callFF + '00', + `0x341515601557${callFF}600080FD5B600080808080305AF1${callFF}00`, BigInt(26414) ) }) diff --git a/packages/vm/test/api/EIPs/eip-2930-accesslists.spec.ts b/packages/vm/test/api/EIPs/eip-2930-accesslists.spec.ts index 0a69ea72bf..13bbfb92b8 100644 --- a/packages/vm/test/api/EIPs/eip-2930-accesslists.spec.ts +++ b/packages/vm/test/api/EIPs/eip-2930-accesslists.spec.ts @@ -12,7 +12,7 @@ const common = new Common({ }) const validAddress = hexToBytes('0x00000000000000000000000000000000000000ff') -const validSlot = hexToBytes('0x' + '00'.repeat(32)) +const validSlot = hexToBytes(`0x${'00'.repeat(32)}`) // setup the accounts for this test const privateKey = hexToBytes('0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109') diff --git a/packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts b/packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts index 3f9cff6102..aa5a29a0d4 100644 --- a/packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts @@ -44,13 +44,13 @@ const block = Block.fromBlockData( { common } ) -const callerPrivateKey = hexToBytes('0x' + '44'.repeat(32)) +const callerPrivateKey = hexToBytes(`0x${'44'.repeat(32)}`) const callerAddress = new Address(privateToAddress(callerPrivateKey)) const PREBALANCE = BigInt(10000000) const address = new Address(privateToAddress(privateKey)) -const contractAddress = new Address(hexToBytes('0x' + 'ff'.repeat(20))) -const contractStorageAddress = new Address(hexToBytes('0x' + 'ee'.repeat(20))) +const contractAddress = new Address(hexToBytes(`0x${'ff'.repeat(20)}`)) +const contractStorageAddress = new Address(hexToBytes(`0x${'ee'.repeat(20)}`)) // Bytecode to exit call frame and return the topmost stack item const RETURNTOP = hexToBytes('0x60005260206000F3') @@ -529,7 +529,7 @@ describe('EIP-3074 AUTHCALL', () => { const gasUsed = await vm.stateManager.getContractStorage( contractStorageAddress, - hexToBytes('0x' + '00'.repeat(31) + '01') + hexToBytes(`0x${'00'.repeat(31)}01`) ) const gasBigInt = bytesToBigInt(gasUsed) const preGas = @@ -572,7 +572,7 @@ describe('EIP-3074 AUTHCALL', () => { const gasUsed = await vm.stateManager.getContractStorage( contractStorageAddress, - hexToBytes('0x' + '00'.repeat(31) + '01') + hexToBytes(`0x${'00'.repeat(31)}01`) ) const gasBigInt = bytesToBigInt(gasUsed) const preGas = gas! - common.param('gasPrices', 'warmstorageread')! @@ -586,7 +586,7 @@ describe('EIP-3074 AUTHCALL', () => { const code = concatBytes( getAuthCode(message, signature, authAddress), getAuthCallCode({ - address: new Address(hexToBytes('0x' + 'cc'.repeat(20))), + address: new Address(hexToBytes(`0x${'cc'.repeat(20)}`)), value: 1n, }), RETURNTOP @@ -661,7 +661,7 @@ describe('EIP-3074 AUTHCALL', () => { const gasUsed = await vm.stateManager.getContractStorage( contractStorageAddress, - hexToBytes('0x' + '00'.repeat(31) + '01') + hexToBytes(`0x${'00'.repeat(31)}01`) ) const gasBigInt = bytesToBigInt(gasUsed) const preGas = @@ -822,7 +822,7 @@ describe('EIP-3074 AUTHCALL', () => { await vm.runTx({ tx, block, skipHardForkValidation: true }) const gas = await vm.stateManager.getContractStorage( contractStorageAddress, - hexToBytes('0x' + '00'.repeat(31) + '01') + hexToBytes(`0x${'00'.repeat(31)}01`) ) const gasBigInt = bytesToBigInt(gas) assert.equal(gasBigInt, BigInt(700000 - 2), 'forwarded the right amount of gas') // The 2 is subtracted due to the GAS opcode base fee @@ -831,7 +831,7 @@ describe('EIP-3074 AUTHCALL', () => { it('Should set input and output correctly', async () => { const message = hexToBytes('0x01') const signature = signMessage(message, contractAddress, privateKey) - const input = hexToBytes('0x' + 'aa'.repeat(32)) + const input = hexToBytes(`0x${'aa'.repeat(32)}`) const code = concatBytes( getAuthCode(message, signature, authAddress), MSTORE(hexToBytes('0x20'), input), @@ -855,7 +855,7 @@ describe('EIP-3074 AUTHCALL', () => { const result = await vm.runTx({ tx, block, skipHardForkValidation: true }) const callInput = await vm.stateManager.getContractStorage( contractStorageAddress, - hexToBytes('0x' + '00'.repeat(31) + '02') + hexToBytes(`0x${'00'.repeat(31)} 02`) ) assert.deepEqual(callInput, input, 'authcall input ok') assert.deepEqual(result.execResult.returnValue, input, 'authcall output ok') diff --git a/packages/vm/test/api/EIPs/eip-3541.spec.ts b/packages/vm/test/api/EIPs/eip-3541.spec.ts index faf5b4c88f..afe9a8efe7 100644 --- a/packages/vm/test/api/EIPs/eip-3541.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3541.spec.ts @@ -8,7 +8,7 @@ import { VM } from '../../../src/vm' import type { InterpreterStep } from '@ethereumjs/evm' import type { Address } from '@ethereumjs/util' -const pkey = hexToBytes('0x' + '20'.repeat(32)) +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) describe('EIP 3541 tests', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Berlin, eips: [3541] }) diff --git a/packages/vm/test/api/EIPs/eip-3651-warm-coinbase.spec.ts b/packages/vm/test/api/EIPs/eip-3651-warm-coinbase.spec.ts index f67ae8822f..5aa4fd483f 100644 --- a/packages/vm/test/api/EIPs/eip-3651-warm-coinbase.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3651-warm-coinbase.spec.ts @@ -5,11 +5,11 @@ import { Account, Address, hexToBytes, privateToAddress } from '@ethereumjs/util import { assert, describe, it } from 'vitest' import { VM } from '../../../src/vm' -const pkey = hexToBytes('0x' + '20'.repeat(32)) +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) const GWEI = BigInt(1000000000) const sender = new Address(privateToAddress(pkey)) -const coinbase = new Address(hexToBytes('0x' + 'ff'.repeat(20))) +const coinbase = new Address(hexToBytes(`0x${'ff'.repeat(20)}`)) const common = new Common({ chain: Chain.Mainnet, @@ -28,7 +28,7 @@ const block = Block.fromBlockData( ) const code = hexToBytes('0x60008080806001415AF100') -const contractAddress = new Address(hexToBytes('0x' + 'ee'.repeat(20))) +const contractAddress = new Address(hexToBytes(`0x${'ee'.repeat(20)}`)) async function getVM(common: Common) { const vm = await VM.create({ common }) diff --git a/packages/vm/test/api/EIPs/eip-3670-eof-code-validation.spec.ts b/packages/vm/test/api/EIPs/eip-3670-eof-code-validation.spec.ts index 22e3027b50..a77a6daa02 100644 --- a/packages/vm/test/api/EIPs/eip-3670-eof-code-validation.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3670-eof-code-validation.spec.ts @@ -5,11 +5,13 @@ import { Account, Address, hexToBytes, privateToAddress, utf8ToBytes } from '@et import { assert, describe, it } from 'vitest' import { VM } from '../../../src/vm' -const pkey = hexToBytes('0x' + '20'.repeat(32)) + +import type { PrefixedHexString } from '@ethereumjs/util' +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) const GWEI = BigInt('1000000000') const sender = new Address(privateToAddress(pkey)) -async function runTx(vm: VM, data: string, nonce: number) { +async function runTx(vm: VM, data: PrefixedHexString, nonce: number) { const tx = FeeMarketEIP1559Transaction.fromTxData({ data, gasLimit: 1000000, @@ -64,12 +66,10 @@ describe('EIP 3670 tests', () => { account!.balance = balance await vm.stateManager.putAccount(sender, account!) - let data = '0x67EF0001010001000060005260086018F3' - let res = await runTx(vm, data, 0) + let res = await runTx(vm, '0x67EF0001010001000060005260086018F3', 0) assert.ok(res.code.length > 0, 'code section with no data section') - data = '0x6BEF00010100010200010000AA600052600C6014F3' - res = await runTx(vm, data, 1) + res = await runTx(vm, '0x6BEF00010100010200010000AA600052600C6014F3', 1) assert.ok(res.code.length > 0, 'code section with data section') }) @@ -120,8 +120,8 @@ describe('EIP 3670 tests', () => { for (let i = 0; i < codes.length; i++) { const calldata = hexToBytes('0xf8a8fd6d') - const addr = new Address(hexToBytes('0x' + '20'.repeat(20))) - const pkey = hexToBytes('0x' + '42'.repeat(32)) + const addr = new Address(hexToBytes(`0x${'20'.repeat(20)}`)) + const pkey = hexToBytes(`0x${'42'.repeat(32)}`) const code = codes[i] diff --git a/packages/vm/test/api/EIPs/eip-3855.spec.ts b/packages/vm/test/api/EIPs/eip-3855.spec.ts index 1e7af9b31b..4a5e9ebdea 100644 --- a/packages/vm/test/api/EIPs/eip-3855.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3855.spec.ts @@ -42,7 +42,7 @@ describe('EIP 3855 tests', () => { const depth = Number(common.param('vm', 'stackLimit')) const result = await vm.evm.runCode!({ - code: hexToBytes('0x' + '5F'.repeat(depth) + '00'), + code: hexToBytes(`0x${'5F'.repeat(depth)}00`), gasLimit: BigInt(10000), }) @@ -61,7 +61,7 @@ describe('EIP 3855 tests', () => { const depth = Number(common.param('vm', 'stackLimit')!) + 1 const result = await vm.evm.runCode!({ - code: hexToBytes('0x' + '5F'.repeat(depth)), + code: hexToBytes(`0x${'5F'.repeat(depth)}`), gasLimit: BigInt(10000), }) @@ -72,7 +72,7 @@ describe('EIP 3855 tests', () => { const vm = await VM.create({ common: commonNoEIP3855 }) const result = await vm.evm.runCode!({ - code: hexToBytes('0x' + '5F'), + code: hexToBytes('0x5F'), gasLimit: BigInt(10000), }) diff --git a/packages/vm/test/api/EIPs/eip-3860.spec.ts b/packages/vm/test/api/EIPs/eip-3860.spec.ts index 69edae2f4a..27569f7bbf 100644 --- a/packages/vm/test/api/EIPs/eip-3860.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3860.spec.ts @@ -4,7 +4,7 @@ import { Account, Address, bytesToHex, hexToBytes, privateToAddress } from '@eth import { assert, describe, it } from 'vitest' import { VM } from '../../../src/vm' -const pkey = hexToBytes('0x' + '20'.repeat(32)) +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) const GWEI = BigInt('1000000000') const sender = new Address(privateToAddress(pkey)) @@ -29,9 +29,9 @@ describe('EIP 3860 tests', () => { const txCommon = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) const tx = FeeMarketEIP1559Transaction.fromTxData( { - data: - '0x7F6000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060005260206000F3' + - bytesToHex(bytes).slice(2), + data: `0x7F6000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060005260206000F3${bytesToHex( + bytes + ).slice(2)}`, gasLimit: 100000000000, maxFeePerGas: 7, nonce: 0, diff --git a/packages/vm/test/api/EIPs/eip-4788-beaconroot.spec.ts b/packages/vm/test/api/EIPs/eip-4788-beaconroot.spec.ts index 710b761062..f288df2c01 100644 --- a/packages/vm/test/api/EIPs/eip-4788-beaconroot.spec.ts +++ b/packages/vm/test/api/EIPs/eip-4788-beaconroot.spec.ts @@ -26,7 +26,7 @@ import { assert, describe, it } from 'vitest' import { VM } from '../../../src' import type { TransactionType, TxData } from '@ethereumjs/tx' -import type { BigIntLike } from '@ethereumjs/util' +import type { BigIntLike, PrefixedHexString } from '@ethereumjs/util' const common = new Common({ chain: Chain.Mainnet, @@ -34,7 +34,7 @@ const common = new Common({ eips: [4788], }) -const pkey = hexToBytes('0x' + '20'.repeat(32)) +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) const contractAddress = Address.fromString('0x' + 'c0de'.repeat(10)) function beaconrootBlock( @@ -85,13 +85,12 @@ function beaconrootBlock( */ const BROOT_AddressString = '000F3df6D732807Ef1319fB7B8bB8522d0Beac02' -const CODE = - '0x365F5F375F5F365F5F' + +const CODE = ('0x365F5F375F5F365F5F' + // push broot contract address on stack '73' + BROOT_AddressString + // remaining contract - '5AF15F553D5F5F3E3D5FF3' + '5AF15F553D5F5F3E3D5FF3') as PrefixedHexString const BROOT_CODE = '0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500' const BROOT_Address = Address.fromString(`0x${BROOT_AddressString}`) diff --git a/packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts b/packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts index 930fb191f5..54c7654558 100644 --- a/packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts +++ b/packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts @@ -20,7 +20,7 @@ import * as genesisJSON from '../../../../client/test/testdata/geth-genesis/eip4 import { VM } from '../../../src/vm' import { setBalance } from '../utils' -const pk = hexToBytes('0x' + '20'.repeat(32)) +const pk = hexToBytes(`0x${'20'.repeat(32)}`) const sender = bytesToHex(privateToAddress(pk)) describe('EIP4844 tests', () => { diff --git a/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts b/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts index 98819d254b..37cccc795f 100644 --- a/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts +++ b/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts @@ -27,7 +27,7 @@ const common = new Common({ eips: [4895], }) -const pkey = hexToBytes('0x' + '20'.repeat(32)) +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) const gethWithdrawals8BlockRlp = '0xf903e1f90213a0fe950635b1bd2a416ff6283b0bbd30176e1b1125ad06fa729da9f3f4c1c61710a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794aa00000000000000000000000000000000000000a07f7510a0cb6203f456e34ec3e2ce30d6c5590ded42c10a9cf3f24784119c5afba056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018401c9c380802f80a0ff0000000000000000000000000000000000000000000000000000000000000088000000000000000007a0b695b29ec7ee934ef6a68838b13729f2d49fffe26718de16a1a9ed94a4d7d06dc0c0f901c6da8082ffff94000000000000000000000000000000000000000080f83b0183010000940100000000000000000000000000000000000000a00100000000000000000000000000000000000000000000000000000000000000f83b0283010001940200000000000000000000000000000000000000a00200000000000000000000000000000000000000000000000000000000000000f83b0383010002940300000000000000000000000000000000000000a00300000000000000000000000000000000000000000000000000000000000000f83b0483010003940400000000000000000000000000000000000000a00400000000000000000000000000000000000000000000000000000000000000f83b0583010004940500000000000000000000000000000000000000a00500000000000000000000000000000000000000000000000000000000000000f83b0683010005940600000000000000000000000000000000000000a00600000000000000000000000000000000000000000000000000000000000000f83b0783010006940700000000000000000000000000000000000000a00700000000000000000000000000000000000000000000000000000000000000' @@ -45,12 +45,12 @@ describe('EIP4895 tests', () => { SSTORE If code is ran, this stores "2" at slot "0". Check if withdrawal operations do not invoke this code */ - const withdrawalCheckAddress = new Address(hexToBytes('0x' + 'fe'.repeat(20))) + const withdrawalCheckAddress = new Address(hexToBytes(`0x${'fe'.repeat(20)}`)) const withdrawalCode = hexToBytes('0x6002600055') await vm.stateManager.putContractCode(withdrawalCheckAddress, withdrawalCode) - const contractAddress = new Address(hexToBytes('0x' + 'ff'.repeat(20))) + const contractAddress = new Address(hexToBytes(`0x${'ff'.repeat(20)}`)) /* PUSH @@ -61,8 +61,10 @@ describe('EIP4895 tests', () => { PUSH 0 RETURN // Return the balance */ - const contract = '0x73' + addresses[0] + '3160005260206000F3' - await vm.stateManager.putContractCode(contractAddress, hexToBytes(contract)) + await vm.stateManager.putContractCode( + contractAddress, + hexToBytes(`0x73${addresses[0]}3160005260206000F3`) + ) const transaction = FeeMarketEIP1559Transaction.fromTxData({ to: contractAddress, @@ -82,7 +84,7 @@ describe('EIP4895 tests', () => { withdrawals.push({ index, validatorIndex: index, - address: new Address(hexToBytes('0x' + addresses[i])), + address: new Address(hexToBytes(`0x${addresses[i]}`)), amount: amounts[i], }) index++ @@ -112,7 +114,7 @@ describe('EIP4895 tests', () => { await vm.runBlock({ block, generate: true }) for (let i = 0; i < addresses.length; i++) { - const address = new Address(hexToBytes('0x' + addresses[i])) + const address = new Address(hexToBytes(`0x${addresses[i]}`)) const amount = amounts[i] const balance = (await vm.stateManager.getAccount(address))!.balance assert.equal(BigInt(amount) * GWEI_TO_WEI, balance, 'balance ok') diff --git a/packages/vm/test/api/EIPs/eip-6780-selfdestruct-same-tx.spec.ts b/packages/vm/test/api/EIPs/eip-6780-selfdestruct-same-tx.spec.ts index 2c6132089b..aec0d55338 100644 --- a/packages/vm/test/api/EIPs/eip-6780-selfdestruct-same-tx.spec.ts +++ b/packages/vm/test/api/EIPs/eip-6780-selfdestruct-same-tx.spec.ts @@ -5,7 +5,7 @@ import { assert, describe, it } from 'vitest' import { VM } from '../../../src/vm' -const pkey = hexToBytes('0x' + '20'.repeat(32)) +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) const GWEI = BigInt(1000000000) const sender = new Address(privateToAddress(pkey)) @@ -20,7 +20,7 @@ const common = new Common({ PUSH 1 PUSH 1 SSTORE - PUSH 1 + PUSH 1 SELFDESTRUCT This payload stores 1 in slot 1 of the contract, and then selfdestructs to address 0x00..01 */ @@ -91,7 +91,7 @@ describe('EIP 6780 tests', () => { assert.equal(contract.balance, BigInt(0), 'value sent') assert.equal(contract.nonce, BigInt(1), 'nonce 1') - const key = hexToBytes('0x' + '00'.repeat(31) + '01') + const key = hexToBytes(`0x${'00'.repeat(31)}01`) const storage = await vm.stateManager.getContractStorage(target, key) assert.ok(equalsBytes(storage, hexToBytes('0x01')), 'storage not cleared') diff --git a/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts b/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts index de9722e3fb..575ee5b09b 100644 --- a/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts +++ b/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts @@ -9,12 +9,17 @@ import { describe, it } from 'vitest' import * as verkleBlockJSON from '../../../../statemanager/test/testdata/verkleKaustinenBlock.json' import { VM } from '../../../src' +import type { BlockData } from '@ethereumjs/block' +import type { PrefixedHexString } from '@ethereumjs/util' + const customChainParams = { name: 'custom', chainId: 69420, networkId: 678 } const common = Common.custom(customChainParams, { hardfork: Hardfork.Cancun, eips: [4895, 6800] }) const decodedTxs = verkleBlockJSON.transactions.map((tx) => - TransactionFactory.fromSerializedData(hexToBytes(tx)) + TransactionFactory.fromSerializedData(hexToBytes(tx as PrefixedHexString)) ) -const block = Block.fromBlockData({ ...verkleBlockJSON, transactions: decodedTxs }, { common }) +const block = Block.fromBlockData({ ...verkleBlockJSON, transactions: decodedTxs } as BlockData, { + common, +}) describe('EIP 6800 tests', () => { it('successfully run transactions statelessly using the block witness', async () => { diff --git a/packages/vm/test/api/customChain.spec.ts b/packages/vm/test/api/customChain.spec.ts index a5622cc95e..3620a03fe2 100644 --- a/packages/vm/test/api/customChain.spec.ts +++ b/packages/vm/test/api/customChain.spec.ts @@ -11,9 +11,10 @@ import { VM } from '../../src/vm' import * as testChain from './testdata/testnet.json' import * as testnetMerge from './testdata/testnetMerge.json' -import type { AccountState } from '@ethereumjs/util' +import type { ChainConfig } from '@ethereumjs/common' +import type { AccountState, GenesisState, PrefixedHexString } from '@ethereumjs/util' -const storage: Array<[string, string]> = [ +const storage: Array<[PrefixedHexString, PrefixedHexString]> = [ [ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000004', @@ -37,7 +38,7 @@ const accountState: AccountState = [ */ const contractAddress = '0x3651539F2E119a27c606cF0cB615410eCDaAE62a' -const genesisState = { +const genesisState: GenesisState = { '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b': '0x6d6172697573766477000000', '0xbe862ad9abfe6f22bcb087716c7d89a26051f74c': '0x6d6172697573766477000000', [contractAddress]: accountState, @@ -46,7 +47,7 @@ const genesisState = { const common = new Common({ chain: 'testnet', hardfork: Hardfork.Chainstart, - customChains: [testChain], + customChains: [testChain] as ChainConfig[], }) const block = Block.fromBlockData( { @@ -92,7 +93,9 @@ describe('VM initialized with custom state', () => { const blockchain = await Blockchain.create({ common, genesisState }) common.setHardfork(Hardfork.London) const vm = await VM.create({ blockchain, common, genesisState }) - const sigHash = new Interface(['function retrieve()']).getSighash('retrieve') + const sigHash = new Interface(['function retrieve()']).getSighash( + 'retrieve' + ) as PrefixedHexString const callResult = await vm.evm.runCall({ to: Address.fromString(contractAddress), @@ -107,7 +110,7 @@ describe('VM initialized with custom state', () => { }) it('setHardfork', async () => { - const customChains = [testnetMerge] + const customChains = [testnetMerge] as ChainConfig[] const common = new Common({ chain: 'testnetMerge', hardfork: Hardfork.Istanbul, customChains }) let vm = await VM.create({ common, setHardfork: true, genesisState: {} }) diff --git a/packages/vm/test/api/index.spec.ts b/packages/vm/test/api/index.spec.ts index 9d47ea7643..484eeb4852 100644 --- a/packages/vm/test/api/index.spec.ts +++ b/packages/vm/test/api/index.spec.ts @@ -12,6 +12,7 @@ import * as testnetMerge from './testdata/testnetMerge.json' import { setupVM } from './utils' import type { VMOpts } from '../../src' +import type { ChainConfig } from '@ethereumjs/common' import type { DefaultStateManager } from '@ethereumjs/statemanager' /** @@ -140,7 +141,7 @@ describe('VM -> common (chain, HFs, EIPs)', () => { }) it('should accept a custom chain config (Common customChains constructor option)', async () => { - const customChains = [testnet, testnet2] + const customChains = [testnet, testnet2] as ChainConfig[] const common = new Common({ chain: 'testnet', hardfork: Hardfork.Berlin, customChains }) const vm = await VM.create({ common }) @@ -150,7 +151,7 @@ describe('VM -> common (chain, HFs, EIPs)', () => { describe('VM -> setHardfork, state (deprecated), blockchain', () => { it('setHardfork', async () => { - const customChains = [testnetMerge] + const customChains = [testnetMerge] as ChainConfig[] const common = new Common({ chain: 'testnetMerge', hardfork: Hardfork.Istanbul, customChains }) let vm = await VM.create({ common, setHardfork: true }) diff --git a/packages/vm/test/api/istanbul/eip-1344.spec.ts b/packages/vm/test/api/istanbul/eip-1344.spec.ts index 474e461b3a..0f6be13ce4 100644 --- a/packages/vm/test/api/istanbul/eip-1344.spec.ts +++ b/packages/vm/test/api/istanbul/eip-1344.spec.ts @@ -16,7 +16,7 @@ const code = ['46', '60', '00', '53', '60', '01', '60', '00', 'f3'] describe('Istanbul: EIP-1344', () => { it('CHAINID', async () => { const runCodeArgs = { - code: hexToBytes('0x' + code.join('')), + code: hexToBytes(`0x${code.join('')}`), gasLimit: BigInt(0xffff), } diff --git a/packages/vm/test/api/istanbul/eip-1884.spec.ts b/packages/vm/test/api/istanbul/eip-1884.spec.ts index 91938edffe..36a8db84de 100644 --- a/packages/vm/test/api/istanbul/eip-1884.spec.ts +++ b/packages/vm/test/api/istanbul/eip-1884.spec.ts @@ -17,7 +17,7 @@ describe('Istanbul: EIP-1884', () => { it('SELFBALANCE', async () => { const addr = new Address(hexToBytes('0x00000000000000000000000000000000000000ff')) const runCodeArgs = { - code: hexToBytes('0x' + code.join('')), + code: hexToBytes(`0x${code.join('')}`), gasLimit: BigInt(0xffff), to: addr, } diff --git a/packages/vm/test/api/istanbul/eip-2200.spec.ts b/packages/vm/test/api/istanbul/eip-2200.spec.ts index 2e11c7b511..5041fb5f49 100644 --- a/packages/vm/test/api/istanbul/eip-2200.spec.ts +++ b/packages/vm/test/api/istanbul/eip-2200.spec.ts @@ -1,5 +1,5 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' -import { Address, hexToBytes, setLengthLeft, toBytes } from '@ethereumjs/util' +import { Address, hexToBytes, setLengthLeft } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { VM } from '../../../src/vm' @@ -46,7 +46,7 @@ describe('Istanbul: EIP-2200', () => { it('net-metering SSTORE', async () => { const caller = new Address(hexToBytes('0x0000000000000000000000000000000000000000')) const addr = new Address(hexToBytes('0x00000000000000000000000000000000000000ff')) - const key = setLengthLeft(toBytes('0x' + BigInt(0).toString(16)), 32) + const key = setLengthLeft(hexToBytes(`0x${BigInt(0).toString(16)}`), 32) for (const testCase of testCases) { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) @@ -54,12 +54,12 @@ describe('Istanbul: EIP-2200', () => { const account = createAccount(BigInt(0), BigInt(0)) await vm.stateManager.putAccount(addr, account) - await vm.stateManager.putContractCode(addr, hexToBytes('0x' + testCase.code)) + await vm.stateManager.putContractCode(addr, hexToBytes(`0x${testCase.code}`)) if (testCase.original !== BigInt(0)) { await vm.stateManager.putContractStorage( addr, key, - toBytes('0x' + testCase.original.toString(16)) + hexToBytes(`0x${testCase.original.toString(16)}`) ) } diff --git a/packages/vm/test/api/runBlock.spec.ts b/packages/vm/test/api/runBlock.spec.ts index 0a6a602b65..2b5383fb6d 100644 --- a/packages/vm/test/api/runBlock.spec.ts +++ b/packages/vm/test/api/runBlock.spec.ts @@ -23,16 +23,19 @@ import type { PreByzantiumTxReceipt, RunBlockOpts, } from '../../src/types' +import type { BlockBytes } from '@ethereumjs/block' +import type { ChainConfig } from '@ethereumjs/common' import type { TypedTransaction } from '@ethereumjs/tx' +import type { NestedUint8Array, PrefixedHexString } from '@ethereumjs/util' const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Berlin }) describe('runBlock() -> successful API parameter usage', async () => { async function simpleRun(vm: VM) { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const genesisRlp = toBytes(testData.genesisRLP) + const genesisRlp = hexToBytes(testData.genesisRLP as PrefixedHexString) const genesis = Block.fromRLPSerializedBlock(genesisRlp, { common }) - const blockRlp = toBytes(testData.blocks[0].rlp) + const blockRlp = hexToBytes(testData.blocks[0].rlp as PrefixedHexString) const block = Block.fromRLPSerializedBlock(blockRlp, { common }) //@ts-ignore @@ -66,7 +69,7 @@ describe('runBlock() -> successful API parameter usage', async () => { await setupPreConditions(vm.stateManager, testData) const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const block1Rlp = toBytes(testData.blocks[0].rlp) + const block1Rlp = hexToBytes(testData.blocks[0].rlp as PrefixedHexString) const block1 = Block.fromRLPSerializedBlock(block1Rlp, { common }) await vm.runBlock({ block: block1, @@ -76,7 +79,7 @@ describe('runBlock() -> successful API parameter usage', async () => { skipHardForkValidation: true, }) - const block2Rlp = toBytes(testData.blocks[1].rlp) + const block2Rlp = hexToBytes(testData.blocks[1].rlp as PrefixedHexString) const block2 = Block.fromRLPSerializedBlock(block2Rlp, { common }) await vm.runBlock({ block: block2, @@ -86,7 +89,7 @@ describe('runBlock() -> successful API parameter usage', async () => { skipHardForkValidation: true, }) - const block3Rlp = toBytes(testData.blocks[2].rlp) + const block3Rlp = toBytes(testData.blocks[2].rlp as PrefixedHexString) const block3 = Block.fromRLPSerializedBlock(block3Rlp, { common }) await vm.runBlock({ block: block3, @@ -125,7 +128,7 @@ describe('runBlock() -> successful API parameter usage', async () => { }) it('PoW block, Common custom chain (Common customChains constructor option)', async () => { - const customChains = [testnet] + const customChains = [testnet] as ChainConfig[] const common = new Common({ chain: 'testnet', hardfork: Hardfork.Berlin, customChains }) const vm = await setupVM({ common }) await simpleRun(vm) @@ -198,7 +201,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => { it('should fail when runTx fails', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const blockRlp = toBytes(testData.blocks[0].rlp) + const blockRlp = hexToBytes(testData.blocks[0].rlp as PrefixedHexString) const block = Block.fromRLPSerializedBlock(blockRlp, { common }) // The mocked VM uses a mocked runTx @@ -214,7 +217,6 @@ describe('runBlock() -> API parameter usage/data errors', async () => { const block = Block.fromBlockData({ header: { - ...testData.blocks[0].header, gasLimit: hexToBytes('0x8000000000000000'), }, }) @@ -227,7 +229,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => { it('should fail when block validation fails', async () => { const vm = await VM.create({ common }) - const blockRlp = toBytes(testData.blocks[0].rlp) + const blockRlp = hexToBytes(testData.blocks[0].rlp as PrefixedHexString) const block = Object.create(Block.fromRLPSerializedBlock(blockRlp, { common })) await vm @@ -243,7 +245,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => { it('should fail when no `validateHeader` method exists on blockchain class', async () => { const vm = await VM.create({ common }) - const blockRlp = toBytes(testData.blocks[0].rlp) + const blockRlp = hexToBytes(testData.blocks[0].rlp as PrefixedHexString) const block = Object.create(Block.fromRLPSerializedBlock(blockRlp, { common })) ;(vm.blockchain as any).validateHeader = undefined try { @@ -260,7 +262,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => { it('should fail when tx gas limit higher than block gas limit', async () => { const vm = await VM.create({ common }) - const blockRlp = toBytes(testData.blocks[0].rlp) + const blockRlp = hexToBytes(testData.blocks[0].rlp as PrefixedHexString) const block = Object.create(Block.fromRLPSerializedBlock(blockRlp, { common })) // modify first tx's gasLimit const { nonce, gasPrice, to, value, data, v, r, s } = block.transactions[0] @@ -286,10 +288,10 @@ describe('runBlock() -> runtime behavior', async () => { const vm = await setupVM({ common }) - const block1: any = RLP.decode(testData.blocks[0].rlp) + const block1 = RLP.decode(testData.blocks[0].rlp as PrefixedHexString) as NestedUint8Array // edit extra data of this block to "dao-hard-fork" block1[0][12] = utf8ToBytes('dao-hard-fork') - const block = Block.fromValuesArray(block1, { common }) + const block = Block.fromValuesArray(block1 as BlockBytes, { common }) // @ts-ignore await setupPreConditions(vm.stateManager, testData) @@ -424,7 +426,7 @@ async function runWithHf(hardfork: string) { const common = new Common({ chain: Chain.Mainnet, hardfork }) const vm = await setupVM({ common }) - const blockRlp = toBytes(testData.blocks[0].rlp) + const blockRlp = hexToBytes(testData.blocks[0].rlp as PrefixedHexString) const block = Block.fromRLPSerializedBlock(blockRlp, { common }) // @ts-ignore @@ -461,7 +463,7 @@ describe('runBlock() -> tx types', async () => { async function simpleRun(vm: VM, transactions: TypedTransaction[]) { const common = vm.common - const blockRlp = toBytes(testData.blocks[0].rlp) + const blockRlp = hexToBytes(testData.blocks[0].rlp as PrefixedHexString) const block = Block.fromRLPSerializedBlock(blockRlp, { common, freeze: false }) //@ts-ignore overwrite transactions diff --git a/packages/vm/test/api/runTx.spec.ts b/packages/vm/test/api/runTx.spec.ts index 0aba1b32a2..e33415454d 100644 --- a/packages/vm/test/api/runTx.spec.ts +++ b/packages/vm/test/api/runTx.spec.ts @@ -25,7 +25,7 @@ import { VM } from '../../src/vm' import { createAccount, getTransaction, setBalance } from './utils' -import type { FeeMarketEIP1559TxData } from '@ethereumjs/tx' +import type { FeeMarketEIP1559TxData, TypedTxData } from '@ethereumjs/tx' const TRANSACTION_TYPES = [ { @@ -221,7 +221,7 @@ describe('runTx() -> successful API parameter usage', async () => { type: txType.type, maxPriorityFeePerGas: 50, maxFeePerGas: 50, - }, + } as TypedTxData, { common } ) const tx = unsignedTx.sign(privateKey) @@ -466,8 +466,8 @@ describe('runTx() -> runtime behavior', () => { await vm.stateManager.putContractCode(address, code) await vm.stateManager.putContractStorage( address, - hexToBytes('0x' + '00'.repeat(32)), - hexToBytes('0x' + '00'.repeat(31) + '01') + hexToBytes(`0x${'00'.repeat(32)}`), + hexToBytes(`0x${'00'.repeat(31)}01`) ) const txParams: any = { nonce: '0x00', @@ -621,7 +621,7 @@ describe('runTx() -> API return values', () => { assert.deepEqual( res.bloom.bitvector, - hexToBytes('0x' + '00'.repeat(256)), + hexToBytes(`0x${'00'.repeat(256)}`), `runTx result -> bloom.bitvector -> should be empty (${txType.name})` ) assert.equal( @@ -661,7 +661,7 @@ describe('runTx() -> consensus bugs', () => { s: '0x4a16b7d119cdc34e454fa2cc0a152904f7deb23e2a5f2966f70981361c853874', v: '0x26', value: '0x0', - } + } as TypedTxData const beforeBalance = BigInt(149123788000000000) const afterBalance = BigInt(129033829000000000) diff --git a/packages/vm/test/tester/runners/BlockchainTestsRunner.ts b/packages/vm/test/tester/runners/BlockchainTestsRunner.ts index e468a728af..65c9ca35f2 100644 --- a/packages/vm/test/tester/runners/BlockchainTestsRunner.ts +++ b/packages/vm/test/tester/runners/BlockchainTestsRunner.ts @@ -20,6 +20,7 @@ import { setupPreConditions, verifyPostConditions } from '../../util' import type { EthashConsensus } from '@ethereumjs/blockchain' import type { Common } from '@ethereumjs/common' +import type { PrefixedHexString } from '@ethereumjs/util' import type * as tape from 'tape' function formatBlockHeader(data: any) { @@ -121,12 +122,12 @@ export async function runBlockchainTest(options: any, testData: any, t: tape.Tes const expectException = (raw[paramFork] ?? raw[paramAll1] ?? raw[paramAll2] ?? - raw.blockHeader === undefined) as string | boolean + raw.blockHeader === undefined) as PrefixedHexString | boolean // Here we decode the rlp to extract the block number // The block library cannot be used, as this throws on certain EIP1559 blocks when trying to convert try { - const blockRlp = hexToBytes(raw.rlp as string) + const blockRlp = hexToBytes(raw.rlp as PrefixedHexString) const decodedRLP: any = RLP.decode(Uint8Array.from(blockRlp)) currentBlock = bytesToBigInt(decodedRLP[0][8]) } catch (e: any) { @@ -135,7 +136,7 @@ export async function runBlockchainTest(options: any, testData: any, t: tape.Tes } try { - const blockRlp = hexToBytes(raw.rlp as string) + const blockRlp = hexToBytes(raw.rlp as PrefixedHexString) // Update common HF let TD: bigint | undefined = undefined let timestamp: bigint | undefined = undefined @@ -164,7 +165,7 @@ export async function runBlockchainTest(options: any, testData: any, t: tape.Tes >[]) { const shouldFail = txData.valid === 'false' try { - const txRLP = hexToBytes(txData.rawBytes) + const txRLP = hexToBytes(txData.rawBytes as PrefixedHexString) const tx = TransactionFactory.fromSerializedData(txRLP, { common }) await blockBuilder.addTransaction(tx) if (shouldFail) { diff --git a/packages/vm/test/util.ts b/packages/vm/test/util.ts index 3bebca978e..e601fca134 100644 --- a/packages/vm/test/util.ts +++ b/packages/vm/test/util.ts @@ -17,7 +17,6 @@ import { hexToBytes, isHexPrefixed, setLengthLeft, - stripHexPrefix, toBytes, } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak' @@ -88,7 +87,7 @@ export function format(a: any, toZero: boolean = false, isHex: boolean = false): if (typeof a === 'string' && isHexPrefixed(a)) { a = a.slice(2) if (a.length % 2) a = '0' + a - a = hexToBytes('0x' + a) + a = hexToBytes(`0x${a}`) } else if (!isHex) { try { a = bigIntToBytes(BigInt(a)) @@ -97,7 +96,7 @@ export function format(a: any, toZero: boolean = false, isHex: boolean = false): } } else { if (a.length % 2) a = '0' + a - a = hexToBytes('0x' + a) + a = hexToBytes(`0x${a}`) } if (toZero && bytesToHex(a) === '0x') { @@ -146,7 +145,7 @@ export async function verifyPostConditions(state: any, testData: any, t: tape.Te const keyMap: any = {} for (const key in testData) { - const hash = bytesToHex(keccak256(hexToBytes(stripHexPrefix(key)))) + const hash = bytesToHex(keccak256(hexToBytes(isHexPrefixed(key) ? key : `0x${key}`))) hashedAccounts[hash] = testData[key] keyMap[hash] = key } @@ -215,8 +214,9 @@ export function verifyAccountPostConditions( const hashedStorage: any = {} for (const key in acctData.storage) { - hashedStorage[bytesToHex(keccak256(setLengthLeft(hexToBytes(key.slice(2)), 32)))] = - acctData.storage[key] + hashedStorage[ + bytesToHex(keccak256(setLengthLeft(hexToBytes(isHexPrefixed(key) ? key : `0x${key}`), 32))) + ] = acctData.storage[key] } state.root(account.storageRoot)