From 081715047e398b9a685218b8ff287220bc411e8b Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Fri, 19 Apr 2024 19:54:59 -0700 Subject: [PATCH] monorepo: more type improvements --- packages/block/test/block.spec.ts | 49 +++++++++++-------- packages/block/test/from-rpc.spec.ts | 44 ++++++++++------- packages/block/test/header.spec.ts | 12 +++-- .../client/test/rpc/engine/preimages.spec.ts | 10 ++-- .../test/rpc/engine/withdrawals.spec.ts | 3 +- packages/client/test/rpc/eth/call.spec.ts | 3 +- packages/client/test/rpc/eth/getProof.spec.ts | 7 +-- .../test/rpc/eth/sendRawTransaction.spec.ts | 2 +- .../client/test/sim/4844-blobpost.spec.ts | 7 ++- packages/client/test/sim/simutils.ts | 9 ++-- packages/client/test/sim/snapsync.spec.ts | 3 +- packages/tx/src/baseTransaction.ts | 2 +- packages/tx/src/types.ts | 2 +- packages/util/src/genesis.ts | 2 +- 14 files changed, 90 insertions(+), 65 deletions(-) diff --git a/packages/block/test/block.spec.ts b/packages/block/test/block.spec.ts index e0a6371c77..58dae5468a 100644 --- a/packages/block/test/block.spec.ts +++ b/packages/block/test/block.spec.ts @@ -20,8 +20,9 @@ import * as testDataPreLondon2 from './testdata/testdata_pre-london-2.json' import * as testDataPreLondon from './testdata/testdata_pre-london.json' import * as testnetMerge from './testdata/testnetMerge.json' -import type { BlockBytes } from '../src/index.js' -import type { NestedUint8Array } from '@ethereumjs/util' +import type { BlockBytes, JsonRpcBlock } from '../src/index.js' +import type { ChainConfig } from '@ethereumjs/common' +import type { NestedUint8Array, PrefixedHexString } from '@ethereumjs/util' describe('[Block]: block functions', () => { it('should test block initialization', () => { @@ -51,7 +52,7 @@ describe('[Block]: block functions', () => { ) const zero = new Uint8Array(0) - const headerArray = [] + const headerArray: Uint8Array[] = [] for (let item = 0; item < 15; item++) { headerArray.push(zero) } @@ -82,7 +83,7 @@ describe('[Block]: block functions', () => { const common = new Common({ chain: 'testnetMerge', hardfork: Hardfork.Istanbul, - customChains, + customChains: customChains as ChainConfig[], }) let block = Block.fromBlockData( @@ -153,7 +154,7 @@ describe('[Block]: block functions', () => { it('should test block validation on pow chain', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const blockRlp = toBytes(testDataPreLondon.blocks[0].rlp) + const blockRlp = toBytes(testDataPreLondon.blocks[0].rlp as PrefixedHexString) try { Block.fromRLPSerializedBlock(blockRlp, { common }) assert.ok(true, 'should pass') @@ -166,7 +167,7 @@ describe('[Block]: block functions', () => { const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart }) try { - blockFromRpc(testDataFromRpcGoerli, [], { common }) + blockFromRpc(testDataFromRpcGoerli as JsonRpcBlock, [], { common }) assert.ok(true, 'does not throw') } catch (error: any) { assert.fail('error thrown') @@ -179,7 +180,7 @@ describe('[Block]: block functions', () => { } it('should test transaction validation - invalid tx trie', async () => { - const blockRlp = toBytes(testDataPreLondon.blocks[0].rlp) + const blockRlp = toBytes(testDataPreLondon.blocks[0].rlp as PrefixedHexString) const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) const block = Block.fromRLPSerializedBlock(blockRlp, { common, freeze: false }) await testTransactionValidation(block) @@ -220,7 +221,7 @@ describe('[Block]: block functions', () => { it('should test transaction validation with legacy tx in london', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const blockRlp = toBytes(testDataPreLondon.blocks[0].rlp) + const blockRlp = toBytes(testDataPreLondon.blocks[0].rlp as PrefixedHexString) const block = Block.fromRLPSerializedBlock(blockRlp, { common, freeze: false }) await testTransactionValidation(block) ;(block.transactions[0] as any).gasPrice = BigInt(0) @@ -233,7 +234,7 @@ describe('[Block]: block functions', () => { it('should test uncles hash validation', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const blockRlp = toBytes(testDataPreLondon2.blocks[2].rlp) + const blockRlp = toBytes(testDataPreLondon2.blocks[2].rlp as PrefixedHexString) const block = Block.fromRLPSerializedBlock(blockRlp, { common, freeze: false }) assert.equal(block.uncleHashIsValid(), true) ;(block.header as any).uncleHash = new Uint8Array(32) @@ -322,16 +323,16 @@ describe('[Block]: block functions', () => { it('should test genesis hashes (mainnet default)', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const rlp = hexToBytes('0x' + testDataGenesis.test.genesis_rlp_hex) - const hash = hexToBytes('0x' + testDataGenesis.test.genesis_hash) + const rlp = hexToBytes(`0x${testDataGenesis.test.genesis_rlp_hex}`) + const hash = hexToBytes(`0x${testDataGenesis.test.genesis_hash}`) const block = Block.fromRLPSerializedBlock(rlp, { common }) assert.ok(equalsBytes(block.hash(), hash), 'genesis hash match') }) it('should test hash() method (mainnet default)', () => { let common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const rlp = hexToBytes('0x' + testDataGenesis.test.genesis_rlp_hex) - const hash = hexToBytes('0x' + testDataGenesis.test.genesis_hash) + const rlp = hexToBytes(`0x${testDataGenesis.test.genesis_rlp_hex}`) + const hash = hexToBytes(`0x${testDataGenesis.test.genesis_hash}`) let block = Block.fromRLPSerializedBlock(rlp, { common }) assert.ok(equalsBytes(block.hash(), hash), 'genesis hash match') @@ -369,23 +370,31 @@ describe('[Block]: block functions', () => { it('should return the same block data from raw()', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const block = Block.fromRLPSerializedBlock(toBytes(testDataPreLondon2.blocks[2].rlp), { - common, - }) + const block = Block.fromRLPSerializedBlock( + toBytes(testDataPreLondon2.blocks[2].rlp as PrefixedHexString), + { + common, + } + ) const blockFromRaw = Block.fromValuesArray(block.raw(), { common }) assert.ok(equalsBytes(block.hash(), blockFromRaw.hash())) }) it('should test toJSON', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const block = Block.fromRLPSerializedBlock(toBytes(testDataPreLondon2.blocks[2].rlp), { - common, - }) + const block = Block.fromRLPSerializedBlock( + toBytes(testDataPreLondon2.blocks[2].rlp as PrefixedHexString), + { + common, + } + ) assert.equal(typeof block.toJSON(), 'object') }) it('DAO hardfork', () => { - const blockData = RLP.decode(testDataPreLondon2.blocks[0].rlp) as NestedUint8Array + const blockData = RLP.decode( + testDataPreLondon2.blocks[0].rlp as PrefixedHexString + ) as NestedUint8Array // Set block number from test block to mainnet DAO fork block 1920000 blockData[0][8] = hexToBytes('0x1D4C00') diff --git a/packages/block/test/from-rpc.spec.ts b/packages/block/test/from-rpc.spec.ts index 7b09d8230f..630f500518 100644 --- a/packages/block/test/from-rpc.spec.ts +++ b/packages/block/test/from-rpc.spec.ts @@ -19,20 +19,22 @@ import * as uncleBlockData from './testdata/testdata-from-rpc-with-uncles_uncle- import * as blockDataWithWithdrawals from './testdata/testdata-from-rpc-with-withdrawals.json' import * as blockData from './testdata/testdata-from-rpc.json' +import type { JsonRpcBlock } from '../src/index.js' import type { LegacyTransaction } from '@ethereumjs/tx' +import type { PrefixedHexString } from '@ethereumjs/util' describe('[fromRPC]: block #2924874', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) it('should create a block with transactions with valid signatures', () => { - const block = blockFromRpc(blockData, [], { common }) + const block = blockFromRpc(blockData as JsonRpcBlock, [], { common }) const allValid = block.transactions.every((tx) => tx.verifySignature()) assert.equal(allValid, true, 'all transaction signatures are valid') }) it('should create a block header with the correct hash', () => { - const block = blockHeaderFromRpc(blockData, { common }) - const hash = hexToBytes(blockData.hash) + const block = blockHeaderFromRpc(blockData as JsonRpcBlock, { common }) + const hash = hexToBytes(blockData.hash as PrefixedHexString) assert.ok(equalsBytes(block.hash(), hash)) }) }) @@ -44,7 +46,7 @@ describe('[fromRPC]:', () => { const blockDataTransactionValueAsInteger = blockData blockDataTransactionValueAsInteger.transactions[0].value = valueAsIntegerString const blockFromTransactionValueAsInteger = blockFromRpc( - blockDataTransactionValueAsInteger, + blockDataTransactionValueAsInteger as JsonRpcBlock, undefined, { common } ) @@ -60,7 +62,7 @@ describe('[fromRPC]:', () => { const blockDataTransactionGasPriceAsInteger = blockData blockDataTransactionGasPriceAsInteger.transactions[0].gasPrice = gasPriceAsIntegerString const blockFromTransactionGasPriceAsInteger = blockFromRpc( - blockDataTransactionGasPriceAsInteger, + blockDataTransactionGasPriceAsInteger as JsonRpcBlock, undefined, { common } ) @@ -74,9 +76,13 @@ describe('[fromRPC]:', () => { it('should create a block given json data that includes a difficulty parameter of type integer string', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const blockDifficultyAsInteger = blockFromRpc(blockDataDifficultyAsInteger, undefined, { - common, - }) + const blockDifficultyAsInteger = blockFromRpc( + blockDataDifficultyAsInteger as JsonRpcBlock, + undefined, + { + common, + } + ) assert.equal( blockDifficultyAsInteger.header.difficulty.toString(), blockDataDifficultyAsInteger.difficulty @@ -85,7 +91,7 @@ describe('[fromRPC]:', () => { it('should create a block from london hardfork', () => { const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.London }) - const block = blockFromRpc(testDataFromRpcGoerliLondon, [], { common }) + const block = blockFromRpc(testDataFromRpcGoerliLondon as JsonRpcBlock, [], { common }) assert.equal( `0x${block.header.baseFeePerGas?.toString(16)}`, testDataFromRpcGoerliLondon.baseFeePerGas @@ -95,19 +101,19 @@ describe('[fromRPC]:', () => { it('should create a block with uncles', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const block = blockFromRpc(blockDataWithUncles, [uncleBlockData], { common }) + const block = blockFromRpc(blockDataWithUncles as JsonRpcBlock, [uncleBlockData], { common }) assert.ok(block.uncleHashIsValid()) }) it('should create a block with EIP-4896 withdrawals', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai }) - const block = blockFromRpc(blockDataWithWithdrawals, [], { common }) + const block = blockFromRpc(blockDataWithWithdrawals as JsonRpcBlock, [], { common }) assert.ok(block.withdrawalsTrieIsValid()) }) it('should create a block header with the correct hash when EIP-4896 withdrawals are present', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai }) - const block = blockHeaderFromRpc(blockDataWithWithdrawals, { common }) + const block = blockHeaderFromRpc(blockDataWithWithdrawals as JsonRpcBlock, { common }) const hash = blockDataWithWithdrawals.hash assert.equal(bytesToHex(block.hash()), hash) }) @@ -116,25 +122,25 @@ describe('[fromRPC]:', () => { describe('[fromRPC] - Alchemy/Infura API block responses', () => { it('should create pre merge block from Alchemy API response to eth_getBlockByHash', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const block = blockFromRpc(alchemy14151203, [], { common }) + const block = blockFromRpc(alchemy14151203 as JsonRpcBlock, [], { common }) assert.equal(bytesToHex(block.hash()), alchemy14151203.hash) }) it('should create pre and post merge blocks from Infura API responses to eth_getBlockByHash and eth_getBlockByNumber', () => { const common = new Common({ chain: Chain.Mainnet }) - let block = blockFromRpc(infura2000004woTxs, [], { common, setHardfork: true }) + let block = blockFromRpc(infura2000004woTxs as JsonRpcBlock, [], { common, setHardfork: true }) assert.equal( bytesToHex(block.hash()), infura2000004woTxs.hash, 'created premerge block w/o txns' ) - block = blockFromRpc(infura2000004wTxs, [], { common, setHardfork: true }) + block = blockFromRpc(infura2000004wTxs as JsonRpcBlock, [], { common, setHardfork: true }) assert.equal( bytesToHex(block.hash()), infura2000004wTxs.hash, 'created premerge block with txns' ) - block = blockFromRpc(infura15571241woTxs, [], { + block = blockFromRpc(infura15571241woTxs as JsonRpcBlock, [], { common, setHardfork: 58750000000000000000000n, }) @@ -144,7 +150,7 @@ describe('[fromRPC] - Alchemy/Infura API block responses', () => { 'created post merge block without txns' ) - block = blockFromRpc(infura15571241wTxs, [], { + block = blockFromRpc(infura15571241wTxs as JsonRpcBlock, [], { common, setHardfork: 58750000000000000000000n, }) @@ -157,8 +163,8 @@ describe('[fromRPC] - Alchemy/Infura API block responses', () => { it('should correctly parse a cancun block over rpc', () => { const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Cancun }) - const block = blockHeaderFromRpc(infuraGoerliBlock10536893, { common }) - const hash = hexToBytes(infuraGoerliBlock10536893.hash) + const block = blockHeaderFromRpc(infuraGoerliBlock10536893 as JsonRpcBlock, { common }) + const hash = hexToBytes(infuraGoerliBlock10536893.hash as PrefixedHexString) assert.ok(equalsBytes(block.hash(), hash)) }) }) diff --git a/packages/block/test/header.spec.ts b/packages/block/test/header.spec.ts index c3bcf5c86e..26869a8494 100644 --- a/packages/block/test/header.spec.ts +++ b/packages/block/test/header.spec.ts @@ -8,7 +8,6 @@ import { concatBytes, equalsBytes, hexToBytes, - toBytes, zeros, } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -21,6 +20,7 @@ import * as blocksGoerli from './testdata/blocks_goerli.json' import * as blocksMainnet from './testdata/blocks_mainnet.json' import type { CliqueConfig } from '@ethereumjs/common' +import type { PrefixedHexString } from '@ethereumjs/util' describe('[Block]: Header functions', () => { it('should create with default constructor', () => { @@ -457,12 +457,14 @@ describe('[Block]: Header functions', () => { const bcBlockGasLimitTestData = testData.tests.BlockGasLimit2p63m1 for (const key of Object.keys(bcBlockGasLimitTestData)) { - const genesisRlp = toBytes( - bcBlockGasLimitTestData[key as keyof typeof bcBlockGasLimitTestData].genesisRLP + const genesisRlp = hexToBytes( + bcBlockGasLimitTestData[key as keyof typeof bcBlockGasLimitTestData] + .genesisRLP as PrefixedHexString ) const parentBlock = Block.fromRLPSerializedBlock(genesisRlp, { common }) - const blockRlp = toBytes( - bcBlockGasLimitTestData[key as keyof typeof bcBlockGasLimitTestData].blocks[0].rlp + const blockRlp = hexToBytes( + bcBlockGasLimitTestData[key as keyof typeof bcBlockGasLimitTestData].blocks[0] + .rlp as PrefixedHexString ) const block = Block.fromRLPSerializedBlock(blockRlp, { common }) assert.doesNotThrow(() => block.validateGasLimit(parentBlock)) diff --git a/packages/client/test/rpc/engine/preimages.spec.ts b/packages/client/test/rpc/engine/preimages.spec.ts index e5c8350a96..c52a908593 100644 --- a/packages/client/test/rpc/engine/preimages.spec.ts +++ b/packages/client/test/rpc/engine/preimages.spec.ts @@ -137,7 +137,7 @@ describe(`valid verkle network setup`, async () => { { name: 'block 1 no txs', blockData: { - transactions: [] as string[], + transactions: [] as PrefixedHexString[], blockNumber: '0x01', stateRoot: '0x78026f1e4f2ff57c340634f844f47cb241beef4c965be86a483c855793e4b07d', receiptTrie: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', @@ -154,7 +154,7 @@ describe(`valid verkle network setup`, async () => { { name: 'block 2 having kaustinen2 block 12 txs', blockData: { - transactions: blocks.block12.execute.transactions, + transactions: blocks.block12.execute.transactions as PrefixedHexString[], blockNumber: '0x02', stateRoot: '0xa86d54279c8faebed72e112310b29115d3600e8cc6ff2a2e4466a788b8776ad9', receiptTrie: '0xd95b673818fa493deec414e01e610d97ee287c9421c8eff4102b1647c1a184e4', @@ -183,7 +183,7 @@ describe(`valid verkle network setup`, async () => { { name: 'block 3 no txs with just withdrawals but zero coinbase', blockData: { - transactions: [] as string[], + transactions: [] as PrefixedHexString[], blockNumber: '0x03', stateRoot: '0xe4538f9d7531eb76e82edf7480e4578bc2be5f454ab02db4d9db6187dfa1f9ca', receiptTrie: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', @@ -208,7 +208,7 @@ describe(`valid verkle network setup`, async () => { { name: 'block 4 with kaustinen block13 txs and withdrawals', blockData: { - transactions: blocks.block13.execute.transactions, + transactions: blocks.block13.execute.transactions as PrefixedHexString[], blockNumber: '0x04', stateRoot: '0x57e675e1d6b2ab5d65601e81658de1468afad77752a271a48364dcefda856614', receiptTrie: '0x6a0be0e8208f625225e43681258eb9901ed753e2656f0cd6c0a3971fada5f190', @@ -238,7 +238,7 @@ describe(`valid verkle network setup`, async () => { }, ] as const - let parentHash = genesisBlockHash + let parentHash: PrefixedHexString = genesisBlockHash for (const testCase of testCases) { const { name, blockData, preimages } = testCase it(`run ${name}`, async () => { diff --git a/packages/client/test/rpc/engine/withdrawals.spec.ts b/packages/client/test/rpc/engine/withdrawals.spec.ts index 9161fb359e..4809d53ee1 100644 --- a/packages/client/test/rpc/engine/withdrawals.spec.ts +++ b/packages/client/test/rpc/engine/withdrawals.spec.ts @@ -8,6 +8,7 @@ import genesisJSON from '../../testdata/geth-genesis/withdrawals.json' import { getRpcClient, setupChain } from '../helpers.js' import type { ExecutionPayload } from '@ethereumjs/block' +import type { PrefixedHexString } from '@ethereumjs/util' // Testvectors picked from static testcase generated by the geth team for api unit tests // see: https://hackmd.io/PqZgMpnkSWCWv5joJoFymQ @@ -73,7 +74,7 @@ const gethWithdrawals8BlockRlp = const withdrawalsGethVector = withdrawalsVector.map((testVec) => ({ index: intToHex(testVec.Index), validatorIndex: intToHex(testVec.Validator), - address: testVec.Recipient, + address: testVec.Recipient as PrefixedHexString, amount: bigIntToHex(BigInt(testVec.Amount)), })) diff --git a/packages/client/test/rpc/eth/call.spec.ts b/packages/client/test/rpc/eth/call.spec.ts index 0d4e50b656..42ca5b4663 100644 --- a/packages/client/test/rpc/eth/call.spec.ts +++ b/packages/client/test/rpc/eth/call.spec.ts @@ -9,6 +9,7 @@ import { INVALID_PARAMS } from '../../../src/rpc/error-code' import { createClient, createManager, getRpcClient, startRPC } from '../helpers.js' import type { FullEthereumService } from '../../../src/service' +import type { PrefixedHexString } from '@ethereumjs/util' const method = 'eth_call' @@ -77,7 +78,7 @@ describe(method, () => { 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/rpc/eth/getProof.spec.ts b/packages/client/test/rpc/eth/getProof.spec.ts index a254fa6859..677fb7a54a 100644 --- a/packages/client/test/rpc/eth/getProof.spec.ts +++ b/packages/client/test/rpc/eth/getProof.spec.ts @@ -8,6 +8,7 @@ import { assert, describe, it } from 'vitest' 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_getProof' @@ -49,8 +50,8 @@ const testnetData = { genesis: { gasLimit: 1000000, difficulty: 1, - nonce: '0x0000000000000000', - extraData: '0x', + nonce: '0x0000000000000000' as PrefixedHexString, + extraData: '0x' as PrefixedHexString, }, hardforks: [ { @@ -154,7 +155,7 @@ describe(method, async () => { const storeTxData = { to: createdAddress!.toString(), from: address.toString(), - data: `0x${funcHash}`, + data: `0x${funcHash}` as PrefixedHexString, gasLimit: bigIntToHex(BigInt(530000)), nonce: 1, } diff --git a/packages/client/test/rpc/eth/sendRawTransaction.spec.ts b/packages/client/test/rpc/eth/sendRawTransaction.spec.ts index cf3f4cd437..1ebf864793 100644 --- a/packages/client/test/rpc/eth/sendRawTransaction.spec.ts +++ b/packages/client/test/rpc/eth/sendRawTransaction.spec.ts @@ -79,7 +79,7 @@ describe(method, () => { gasLimit: 21000, gasPrice: 0, nonce: 0, - }).sign(hexToBytes('0x' + '42'.repeat(32))) + }).sign(hexToBytes(`0x${'42'.repeat(32)}`)) const txData = bytesToHex(transaction.serialize()) diff --git a/packages/client/test/sim/4844-blobpost.spec.ts b/packages/client/test/sim/4844-blobpost.spec.ts index 0a45bbe165..df856097b1 100644 --- a/packages/client/test/sim/4844-blobpost.spec.ts +++ b/packages/client/test/sim/4844-blobpost.spec.ts @@ -13,8 +13,11 @@ import { waitForELStart, } from './simutils' +import type { PrefixedHexString } from '@ethereumjs/util' + const pkey = hexToBytes( - process.env.PRIVATE_KEY ?? '0xae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e' + (process.env.PRIVATE_KEY as PrefixedHexString) ?? + '0xae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e' ) const sender = bytesToHex(privateToAddress(pkey)) const rpcUrl = @@ -38,7 +41,7 @@ const commonJson = { ...shardingJson } commonJson.config = { ...commonJson.config, chainId } const common = Common.fromGethGenesis(commonJson, { 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/simutils.ts b/packages/client/test/sim/simutils.ts index 47443c0619..86f58cf3fd 100644 --- a/packages/client/test/sim/simutils.ts +++ b/packages/client/test/sim/simutils.ts @@ -27,6 +27,7 @@ import { Event } from '../../src/types' import type { Common } from '@ethereumjs/common' import type { TransactionType, TxData, TxOptions } from '@ethereumjs/tx' +import type { PrefixedHexString } from '@ethereumjs/util' import type { ChildProcessWithoutNullStreams } from 'child_process' import type { Client } from 'jayson/promise' @@ -268,8 +269,8 @@ export async function startNetwork( export async function runTxHelper( opts: { client: Client; common: Common; sender: string; pkey: Uint8Array }, - data: string, - to?: string, + data: PrefixedHexString | '', + to?: PrefixedHexString, value?: bigint ) { const { client, common, sender, pkey } = opts @@ -313,7 +314,7 @@ export const runBlobTx = async ( client: Client, blobSize: number, pkey: Uint8Array, - to?: string, + to?: PrefixedHexString, value?: bigint, opts?: TxOptions ) => { @@ -373,7 +374,7 @@ export const createBlobTxs = async ( pkey: Uint8Array, startNonce: number = 0, txMeta: { - to?: string + to?: PrefixedHexString value?: bigint chainId?: number maxFeePerBlobGas: bigint diff --git a/packages/client/test/sim/snapsync.spec.ts b/packages/client/test/sim/snapsync.spec.ts index 16db5149d9..a94ffe508c 100644 --- a/packages/client/test/sim/snapsync.spec.ts +++ b/packages/client/test/sim/snapsync.spec.ts @@ -26,6 +26,7 @@ import { import type { EthereumClient } from '../../src/client' import type { DefaultStateManager } from '@ethereumjs/statemanager' +import type { PrefixedHexString } from '@ethereumjs/util' const client = Client.http({ port: 8545 }) @@ -48,7 +49,7 @@ let stateManager: DefaultStateManager | undefined = undefined 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/tx/src/baseTransaction.ts b/packages/tx/src/baseTransaction.ts index 7540c7795c..f63432f908 100644 --- a/packages/tx/src/baseTransaction.ts +++ b/packages/tx/src/baseTransaction.ts @@ -91,7 +91,7 @@ export abstract class BaseTransaction this.gasLimit = bytesToBigInt(toBytes(gasLimit)) this.to = toB.length > 0 ? new Address(toB) : undefined this.value = bytesToBigInt(toBytes(value)) - this.data = toBytes(data) + this.data = toBytes(data === '' ? '0x' : data) this.v = vB.length > 0 ? bytesToBigInt(vB) : undefined this.r = rB.length > 0 ? bytesToBigInt(rB) : undefined diff --git a/packages/tx/src/types.ts b/packages/tx/src/types.ts index 85cd191d25..8c3989968b 100644 --- a/packages/tx/src/types.ts +++ b/packages/tx/src/types.ts @@ -270,7 +270,7 @@ export type LegacyTxData = { /** * This will contain the data of the message or the init of a contract. */ - data?: BytesLike + data?: BytesLike | '' /** * EC recovery ID. diff --git a/packages/util/src/genesis.ts b/packages/util/src/genesis.ts index 3cf5cacbad..269ab84032 100644 --- a/packages/util/src/genesis.ts +++ b/packages/util/src/genesis.ts @@ -37,7 +37,7 @@ export type AccountState = [ * ``` */ export interface GenesisState { - [key: PrefixedHexString]: PrefixedHexString | AccountState + [key: string]: PrefixedHexString | AccountState } /**