Skip to content

Commit

Permalink
monorepo: more type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Apr 22, 2024
1 parent 0817150 commit ddd4bd6
Show file tree
Hide file tree
Showing 86 changed files with 610 additions and 460 deletions.
2 changes: 1 addition & 1 deletion packages/block/test/eip1559block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 3 additions & 3 deletions packages/block/test/eip4895block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('EIP4895 tests', () => {
const withdrawal = <WithdrawalData>{
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),
}

Expand All @@ -185,7 +185,7 @@ describe('EIP4895 tests', () => {
const withdrawal2 = <WithdrawalData>{
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),
}

Expand Down
17 changes: 12 additions & 5 deletions packages/block/test/from-beacon-payload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 }
Expand All @@ -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`)
Expand All @@ -61,7 +66,7 @@ describe('[fromExecutionPayloadJson]: 4844 devnet 5', () => {
{
...payload87475,
block_hash: '0x573714bdd0ca5e47bc32008751c4fc74237f8cb354fbc1475c1d0ece38236ea4',
},
} as BeaconPayloadJson,
{ common }
)
const parentHeader = BlockHeader.fromHeaderData({ excessBlobGas: BigInt(0) }, { common })
Expand All @@ -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'
)
})
Expand Down
9 changes: 5 additions & 4 deletions packages/blockchain/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -573,15 +574,15 @@ 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,
validateConsensus: false,
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)
})
Expand Down
150 changes: 76 additions & 74 deletions packages/client/test/execution/vmexecution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
})
Expand All @@ -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')
Expand All @@ -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,
})
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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',
},
],
}
2 changes: 1 addition & 1 deletion packages/client/test/net/protocol/ethprotocol.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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], [
Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/rpc/debug/storageRangeAt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,7 +53,7 @@ const updateBytecode: string = '0xa2e62045'
}
```
*/
const noStorageBytecode: string =
const noStorageBytecode =
'0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea26469706673582212202f85c21c604b5e0fde9dca0615b4dd49a586dd18ada5ad8b85aa950462e1e73664736f6c63430008120033'

describe(method, () => {
Expand Down
Loading

0 comments on commit ddd4bd6

Please sign in to comment.