Skip to content

Commit

Permalink
monorepo: address outstanding type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Apr 22, 2024
1 parent ddd4bd6 commit e025e0d
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/statemanager/test/checkpointing.code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const codeEval = async (
}

describe('StateManager -> Code Checkpointing', () => {
const address = new Address(hexToBytes('0x' + '11'.repeat(20)))
const address = new Address(hexToBytes(`0x${'11'.repeat(20)}`))
const account = new Account()

const value = hexToBytes('0x01')
Expand Down
4 changes: 2 additions & 2 deletions packages/statemanager/test/checkpointing.storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const storageEval = async (
}

describe('StateManager -> Storage Checkpointing', () => {
const address = new Address(hexToBytes('0x' + '11'.repeat(20)))
const address = new Address(hexToBytes(`0x${'11'.repeat(20)}`))
const account = new Account()

const key = hexToBytes('0x' + '01'.repeat(32))
const key = hexToBytes(`0x${'01'.repeat(32)}`)

const value = hexToBytes('0x01')
const root = hexToBytes('0x561a011235f3fe8a4d292eba6d462e09015bbef9f8c3373dd70760bbc86f9a6c')
Expand Down
12 changes: 7 additions & 5 deletions packages/statemanager/test/rpcStateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import * as blockData from './testdata/providerData/blocks/block0x7a120.json'
import { getValues } from './testdata/providerData/mockProvider.js'
import * as txData from './testdata/providerData/transactions/0xed1960aa7d0d7b567c946d94331dddb37a1c67f51f30bf51f256ea40db88cfb0.json'

import type { JsonRpcBlock } from '@ethereumjs/block'

const provider = process.env.PROVIDER ?? 'http://cheese'
// To run the tests with a live provider, set the PROVIDER environmental variable with a valid provider url
// from Infura/Alchemy or your favorite web3 provider when running the test. Below is an example command:
Expand Down Expand Up @@ -261,13 +263,13 @@ describe('runTx test: replay mainnet transactions', () => {

const blockTag = 15496077n
common.setHardforkBy({ blockNumber: blockTag })
const tx = await TransactionFactory.fromRPC(txData, { common })
const tx = await TransactionFactory.fromRPC(txData as any, { common })
const state = new RPCStateManager({
provider,
// Set the state manager to look at the state of the chain before the block has been executed
blockTag: blockTag - 1n,
})
const vm = await VM.create({ common, stateManager: <any>state })
const vm = await VM.create({ common, stateManager: state })
const res = await vm.runTx({ tx })
assert.equal(
res.totalGasSpent,
Expand All @@ -293,7 +295,7 @@ describe('runBlock test', () => {
common.setHardforkBy({ blockNumber: blockTag - 1n })

const vm = await VM.create({ common, stateManager: state })
const block = Block.fromRPC(blockData, [], { common })
const block = Block.fromRPC(blockData as JsonRpcBlock, [], { common })
try {
const res = await vm.runBlock({
block,
Expand Down Expand Up @@ -345,8 +347,8 @@ describe('Should return same value as DefaultStateManager when account does not
const rpcState = new RPCStateManager({ provider, blockTag: 1n })
const defaultState = new DefaultStateManager()

const account0 = await rpcState.getAccount(new Address(hexToBytes('0x' + '01'.repeat(20))))
const account1 = await defaultState.getAccount(new Address(hexToBytes('0x' + '01'.repeat(20))))
const account0 = await rpcState.getAccount(new Address(hexToBytes(`0x${'01'.repeat(20)}`)))
const account1 = await defaultState.getAccount(new Address(hexToBytes(`0x${'01'.repeat(20)}`)))
assert.equal(
account0,
account1,
Expand Down
4 changes: 3 additions & 1 deletion packages/statemanager/test/stateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { assert, describe, it } from 'vitest'

import { CacheType, DefaultStateManager } from '../src/index.js'

import type { PrefixedHexString } from '@ethereumjs/util'

export const isBrowser = new Function('try {return this===window;}catch(e){ return false;}')
function verifyAccount(
account: Account,
Expand Down Expand Up @@ -299,7 +301,7 @@ describe('StateManager -> General', () => {
await sm.putAccount(address2, account2)
await sm.putContractStorage(address, setLengthLeft(intToBytes(0), 32), intToBytes(32))
const storage = await sm.dumpStorage(address)
const keys = Object.keys(storage)
const keys = Object.keys(storage) as PrefixedHexString[]
const proof = await sm.getProof(
address,
keys.map((key) => hexToBytes(key))
Expand Down
6 changes: 3 additions & 3 deletions packages/statemanager/test/stateManager.storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('StateManager -> Storage', () => {
await stateManager.putAccount(address, account)

const key = zeros(32)
const value = hexToBytes('0x' + 'aa'.repeat(33))
const value = hexToBytes(`0x${'aa'.repeat(33)}`)
try {
await stateManager.putContractStorage(address, key, value)
assert.fail('did not throw')
Expand All @@ -93,14 +93,14 @@ describe('StateManager -> Storage', () => {
await stateManager.putAccount(address, account)

const key0 = zeros(32)
const value0 = hexToBytes('0x' + '00' + 'aa'.repeat(30)) // put a value of 31-bytes length with a leading zero byte
const value0 = hexToBytes(`0x00${'aa'.repeat(30)}`) // put a value of 31-bytes length with a leading zero byte
const expect0 = unpadBytes(value0)
await stateManager.putContractStorage(address, key0, value0)
const slot0 = await stateManager.getContractStorage(address, key0)
assert.ok(equalsBytes(slot0, expect0), 'value of 31 bytes padded correctly')

const key1 = concatBytes(zeros(31), hexToBytes('0x01'))
const value1 = hexToBytes('0x' + '0000' + 'aa'.repeat(1)) // put a value of 1-byte length with two leading zero bytes
const value1 = hexToBytes(`0x0000${'aa'.repeat(1)}`) // put a value of 1-byte length with two leading zero bytes
const expect1 = unpadBytes(value1)
await stateManager.putContractStorage(address, key1, value1)
const slot1 = await stateManager.getContractStorage(address, key1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { CacheType, StatelessVerkleStateManager } from '../src/index.js'
import * as testnetVerkleKaustinen from './testdata/testnetVerkleKaustinen.json'
import * as verkleBlockJSON from './testdata/verkleKaustinenBlock.json'

import type { BlockData } from '@ethereumjs/block'
import type { PrefixedHexString } from '@ethereumjs/util'
import type { VerkleCrypto } from '@ethereumjs/verkle'

describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => {
Expand All @@ -30,9 +32,11 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => {
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,
})

it('initPreState()', async () => {
const stateManager = await StatelessVerkleStateManager.create({ verkleCrypto })
Expand Down
2 changes: 1 addition & 1 deletion packages/trie/test/encoding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('encoding hex prefixes', () => {
const trie = new Trie()
const trie2 = new Trie()
const hex = 'FF44A3B3'
await trie.put(hexToBytes('0x' + hex), utf8ToBytes('test'))
await trie.put(hexToBytes(`0x${hex}`), utf8ToBytes('test'))
await trie2.put(toBytes(`0x${hex}`), utf8ToBytes('test'))
assert.equal(bytesToHex(trie.root()), bytesToHex(trie2.root()))
})
Expand Down
6 changes: 3 additions & 3 deletions packages/trie/test/official.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bytesToHex, hexToBytes, utf8ToBytes } from '@ethereumjs/util'
import { bytesToHex, hexToBytes, isHexPrefixed, utf8ToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { Trie } from '../src/index.js'
Expand Down Expand Up @@ -41,13 +41,13 @@ describe('official tests any order', async () => {
for (key of keys) {
let val = test.in[key]

if (typeof key === 'string' && key.slice(0, 2) === '0x') {
if (typeof key === 'string' && isHexPrefixed(key)) {
key = hexToBytes(key)
} else if (typeof key === 'string') {
key = utf8ToBytes(key)
}

if (typeof val === 'string' && val.slice(0, 2) === '0x') {
if (typeof val === 'string' && isHexPrefixed(val)) {
val = hexToBytes(val)
} else if (typeof val === 'string') {
val = utf8ToBytes(val)
Expand Down
18 changes: 9 additions & 9 deletions packages/trie/test/proof/range.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ describe('simple merkle range proofs generation and verification', () => {
}

// Special case, two edge proofs for two edge key.
const startKey = hexToBytes('0x' + '00'.repeat(32))
const endKey = hexToBytes('0x' + 'ff'.repeat(32))
const startKey = hexToBytes(`0x${'00'.repeat(32)}`)
const endKey = hexToBytes(`0x${'ff'.repeat(32)}`)
assert.equal(await verify(trie, entries, 0, entries.length - 1, startKey, endKey), false)
})

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('simple merkle range proofs generation and verification', () => {
const tinyEntries: [Uint8Array, Uint8Array][] = [[randomBytes(32), randomBytes(20)]]
await tinyTrie.put(tinyEntries[0][0], tinyEntries[0][1])

const tinyStartKey = hexToBytes('0x' + '00'.repeat(32))
const tinyStartKey = hexToBytes(`0x${'00'.repeat(32)}`)
assert.equal(await verify(tinyTrie, tinyEntries, 0, 0, tinyStartKey), false)
})

Expand Down Expand Up @@ -232,15 +232,15 @@ describe('simple merkle range proofs generation and verification', () => {
entries,
0,
entries.length - 1,
hexToBytes('0x' + '00'.repeat(32)),
hexToBytes('0x' + 'ff'.repeat(32))
hexToBytes(`0x${'00'.repeat(32)}`),
hexToBytes(`0x${'ff'.repeat(32)}`)
),
false
)
})

it('create a single side range proof and verify it', async () => {
const startKey = hexToBytes('0x' + '00'.repeat(32))
const startKey = hexToBytes(`0x${'00'.repeat(32)}`)
const { trie, entries } = await randomTrie(new MapDB(), false)

const cases = [0, 1, 200, entries.length - 1]
Expand All @@ -250,7 +250,7 @@ describe('simple merkle range proofs generation and verification', () => {
})

it('create a revert single side range proof and verify it', async () => {
const endKey = hexToBytes('0x' + 'ff'.repeat(32))
const endKey = hexToBytes(`0x${'ff'.repeat(32)}`)
const { trie, entries } = await randomTrie(new MapDB(), false)

const cases = [0, 1, 200, entries.length - 1]
Expand Down Expand Up @@ -453,14 +453,14 @@ describe('simple merkle range proofs generation and verification', () => {

if (start === -1) {
start = 0
startKey = hexToBytes('0x' + '00'.repeat(32))
startKey = hexToBytes(`0x${'00'.repeat(32)}`)
} else {
startKey = entries[start][0]
}

if (end === -1) {
end = entries.length - 1
endKey = hexToBytes('0x' + 'ff'.repeat(32))
endKey = hexToBytes(`0x${'ff'.repeat(32)}`)
} else {
endKey = entries[end][0]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/trie/test/trie/prune.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Pruned trie tests', () => {
const values = ['00', '02', '03', '04', '05']

for (let i = 0; i < keys.length; i++) {
await trie.put(hexToBytes('0x' + keys[i]), hexToBytes('0x' + values[i]))
await trie.put(hexToBytes(`0x${keys[i]}`), hexToBytes(`0x${values[i]}`))
}
})

Expand Down
4 changes: 3 additions & 1 deletion packages/trie/test/util/asyncWalk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { _walkTrie } from '../../src/util/asyncWalk.js'
import { bytesToNibbles } from '../../src/util/nibbles.js'
import trieTests from '../fixtures/trietest.json'

import type { PrefixedHexString } from '@ethereumjs/util'

describe('walk the tries from official tests', async () => {
const testNames = Object.keys(trieTests.tests)

Expand All @@ -14,7 +16,7 @@ describe('walk the tries from official tests', async () => {
describe(testName, async () => {
const inputs = (trieTests as any).tests[testName].in
const expect = (trieTests as any).tests[testName].root
const testKeys: Map<string, Uint8Array | null> = new Map()
const testKeys: Map<PrefixedHexString, Uint8Array | null> = new Map()
const testStrings: Map<string, [string, string | null]> = new Map()
for await (const [idx, input] of inputs.entries()) {
const stringPair: [string, string] = [inputs[idx][0], inputs[idx][1] ?? 'null']
Expand Down
4 changes: 2 additions & 2 deletions packages/trie/test/util/encodingUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('encoding', () => {
const result = pathToHexKey(path, extension, 'hex')

// Calculate the expected result manually based on the functions used in the pathToHexKey function
const b = hexToBytes('0x' + path)
const b = hexToBytes(`0x${path}`)
const n = byteTypeToNibbleType(b)
const expected = nibbleTypeToByteType(n.concat(extension))

Expand All @@ -91,7 +91,7 @@ describe('encoding', () => {
const result = pathToHexKey(path, extension, 'keybyte')

// Calculate the expected result manually based on the functions used in the pathToHexKey function
const b = hexToBytes('0x' + path)
const b = hexToBytes(`0x${path}`)
const n = byteTypeToNibbleType(b)
const expected = nibbleTypeToPackedBytes(n.concat(extension))

Expand Down
1 change: 1 addition & 0 deletions packages/util/test/types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('toType', () => {
assert.deepEqual(result, toBytes(num))

assert.throws(() => {
// @ts-expect-error
toType('1', TypeOutput.Number)
}, /^A string must be provided with a 0x-prefix, given: 1$/)
})
Expand Down
10 changes: 7 additions & 3 deletions packages/util/test/withdrawal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assert, describe, it } from 'vitest'

import { Withdrawal, bigIntToHex, bytesToHex, hexToBytes, intToHex } from '../src/index.js'

import type { WithdrawalBytes } from '../src/index.js'
import type { WithdrawalBytes, WithdrawalData } from '../src/index.js'

const withdrawalsVector = [
{
Expand Down Expand Up @@ -69,14 +69,18 @@ describe('Withdrawal', () => {
const gethWithdrawalsBuffer = decode(hexToBytes(gethWithdrawals8BlockRlp))[3]!
const gethWithdrawalsRlp = bytesToHex(encode(gethWithdrawalsBuffer))
it('fromWithdrawalData and toBytesArray', () => {
const withdrawals = withdrawalsGethVector.map(Withdrawal.fromWithdrawalData)
const withdrawals = withdrawalsGethVector.map((withdrawal) =>
Withdrawal.fromWithdrawalData(withdrawal as WithdrawalData)
)
const withdrawalstoBytesArr = withdrawals.map((wt) => wt.raw())
const withdrawalsToRlp = bytesToHex(encode(withdrawalstoBytesArr))
assert.equal(gethWithdrawalsRlp, withdrawalsToRlp, 'The withdrawals to buffer should match')
})

it('toBytesArray from withdrawalData', () => {
const withdrawalsDatatoBytesArr = withdrawalsGethVector.map(Withdrawal.toBytesArray)
const withdrawalsDatatoBytesArr = withdrawalsGethVector.map((withdrawal) =>
Withdrawal.toBytesArray(withdrawal as WithdrawalData)
)
const withdrawalsDataToRlp = bytesToHex(encode(withdrawalsDatatoBytesArr))
assert.equal(gethWithdrawalsRlp, withdrawalsDataToRlp, 'The withdrawals to buffer should match')
})
Expand Down
4 changes: 1 addition & 3 deletions packages/verkle/test/internalNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { NODE_WIDTH, VerkleNodeType } from '../src/node/index.js'
import { InternalNode } from '../src/node/internalNode.js'
import { POINT_IDENTITY } from '../src/util/crypto.js'

import type { Point } from '../src/types.js'

describe('verkle node - internal', () => {
it('constructor should create an internal node', async () => {
const commitment = randomBytes(32)
const depth = 2
const node = new InternalNode({ commitment: commitment as unknown as Point, depth })
const node = new InternalNode({ commitment, depth })

assert.equal(node.type, VerkleNodeType.Internal, 'type should be set')
assert.ok(
Expand Down
2 changes: 1 addition & 1 deletion packages/verkle/test/leafNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('verkle node - leaf', () => {
const node = new LeafNode({
c1: c1 as unknown as Point,
c2: c2 as unknown as Point,
commitment: commitment as unknown as Point,
commitment,
depth,
stem,
values,
Expand Down
8 changes: 5 additions & 3 deletions packages/verkle/test/verkle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { assert, describe, it } from 'vitest'

import { VerkleTree } from '../src/verkleTree.js'

import type { PrefixedHexString } from '@ethereumjs/util'

// Testdata from https://github.com/gballet/go-ethereum/blob/kaustinen-with-shapella/trie/verkle_test.go
const presentKeys = [
'0x318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d01',
Expand All @@ -18,7 +20,7 @@ const presentKeys = [
'0xe6ed6c222e3985050b4fc574b136b0a42c63538e9ab970995cd418ba8e526404',
'0x318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d00',
'0x18fb432d3b859ec3a1803854e8cceea75d092e52d0d4a4398d13022496745a01',
].map(hexToBytes)
].map((key) => hexToBytes(key as PrefixedHexString))

// Corresponding values for the present keys
const values = [
Expand All @@ -35,13 +37,13 @@ const values = [
'0x0000000000000000000000000000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000000000000000000000000000',
'0xe703000000000000000000000000000000000000000000000000000000000000',
].map(hexToBytes)
].map((key) => hexToBytes(key as PrefixedHexString))

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const absentKeys = [
'0x318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d03',
'0x318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d04',
].map(hexToBytes)
].map((key) => hexToBytes(key as PrefixedHexString))

describe('Verkle tree', () => {
it.todo('should insert and retrieve values', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/test/tester/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async function runTests() {
* Run-time configuration
*/
const kzg = await loadKZG()
const bn128 = await initRustBN()
const bn128 = (await initRustBN()) as bn128
const runnerArgs: {
forkConfigVM: string
forkConfigTestSuite: string
Expand Down

0 comments on commit e025e0d

Please sign in to comment.