Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d189795
Make runStateTests and helpers test-framework agnostic
am1r021 May 20, 2025
037829f
Add simplified test runner
am1r021 May 20, 2025
5c06661
Add types for vm state test data
am1r021 May 20, 2025
2ea4ef2
Move assert import into stateRunner.spec.ts
am1r021 May 20, 2025
d606cad
Use current test loader for vm state tests running vitest
am1r021 May 21, 2025
ac7f454
Fix errors
am1r021 May 21, 2025
70aea76
Revert "Add types for vm state test data"
am1r021 May 21, 2025
c9e0c26
Update test retrieval and execution functions
am1r021 May 21, 2025
9c407de
Use vitest state runner for CI job
am1r021 May 21, 2025
784c14c
Fix parameter passing
am1r021 May 21, 2025
dbf44be
Use deepEqual
am1r021 May 21, 2025
211e1eb
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 May 22, 2025
e39ed30
Exclude state test runner from unit testing
am1r021 May 22, 2025
9c9cf3a
Add all parameters from legacy runner
am1r021 May 22, 2025
1c66033
Fix parameter typing
am1r021 May 22, 2025
2cd0a46
Catch errors and fail tests that throw errors
am1r021 May 22, 2025
93264b0
Add verifyTestAmountAllTests functionality to count and compare expec…
am1r021 May 22, 2025
d61a68c
Activate test count comparisons in CI runs
am1r021 May 22, 2025
9476153
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 May 22, 2025
7f9f199
Fix test count comparison
am1r021 May 22, 2025
db518f8
Use env variables from process
am1r021 May 22, 2025
46a3a11
Fix parameter passing in ci job
am1r021 May 22, 2025
586ef73
Update packages/vm/test/tester/stateRunner.spec.ts
am1r021 May 28, 2025
1f44271
Merge branch 'master' into tape-to-vitest-refactor-vm-testrunners
am1r021 May 28, 2025
07fee1f
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 May 28, 2025
8abe920
Calculate testcount for each testcase
am1r021 May 28, 2025
cea7877
Merge branch 'tape-to-vitest-refactor-vm-testrunners' of github.com:e…
am1r021 May 28, 2025
f645c96
Remove duplicate tape assert
am1r021 May 29, 2025
d5dd1a6
Switch state runner scripts to use new runner instead of legacy
am1r021 May 29, 2025
6a48353
Merge branch 'master' into tape-to-vitest-refactor-vm-testrunners
am1r021 May 29, 2025
6900cc7
Merge branch 'master' into tape-to-vitest-refactor-vm-testrunners
holgerd77 Aug 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions packages/tx/test/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,61 @@ export type OfficialTransactionTestData = {
result: ForksData
txbytes: string
}

export interface EnvData {
currentBaseFee: string
currentCoinbase: string
currentDifficulty: string
currentExcessBlobGas: string
currentGasLimit: string
currentNumber: string
currentRandom: string
currentTimestamp: string
}

export interface AccountState {
balance: string
code: string
nonce: string
storage: Record<string, string>
}

export interface Indexes {
data: number
gas: number
value: number
}

export interface PostReceipt {
hash: string
indexes: Indexes
logs: string
txbytes: string
}

export interface BlobTransaction extends TxData {
accessLists: Array<{ address: string; storageKeys: string[] }>
blobVersionedHashes: string[]
maxFeePerBlobGas: string
maxFeePerGas: string
maxPriorityFeePerGas: string
secretKey: string
sender: string
to: string
}

export type OfficialStateTestData = {
_info: {
comment: string
generatedTestHash: string
filledwith: string // cspell:disable-line
lllcversion: string // cspell:disable-line
solidity: string
source: string
sourceHash: string
}
env: EnvData
pre: Record<string, AccountState>
post: Partial<Record<ForkName, PostReceipt[]>>
transaction: BlobTransaction
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types are added with the following commit message "Add types for vm state test data", so with "vm" in the text, while the types here are in "tx", so there seems to be something off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point, they would have had to have been moved over to the vm package along with making getTests and other helpers in testLoader.ts available there too for use with the new runners. But we could leave that as a potential followup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note if we/you tackle later: these tx specific things should never make it over, there should definitely no unified runner, only a very very lightweight unified 20 line file loader (as outlined in the chat) helper function, which is completely independent of whatever VM or TX code and can therefore be placed in a generic place (testdata package).

71 changes: 39 additions & 32 deletions packages/vm/test/tester/runners/GeneralStateTestsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import { createVerkleTree } from '@ethereumjs/verkle'
import * as verkle from 'micro-eth-signer/verkle'

import { createVM, runTx } from '../../../src/index.ts'
import { makeBlockFromEnv, makeTx, setupPreConditions } from '../../util.ts'

import type { StateManagerInterface } from '@ethereumjs/common'
import type { VerkleTree } from '@ethereumjs/verkle'
import type * as tape from 'tape'
import { createVM, runTx } from '../../../src/index.ts'
import { makeBlockFromEnv, makeTx, setupPreConditions } from '../../util.ts'
const loadVerkleCrypto = () => Promise.resolve(verkle)

function parseTestCases(
Expand Down Expand Up @@ -76,7 +75,12 @@
return testCases
}

async function runTestCase(options: any, testData: any, t: tape.Test) {
function isTape(t: tape.Test | Chai.AssertStatic): t is tape.Test {
// tape.Test has .comment, chai.AssertStatic does not
return typeof (t as tape.Test).comment === 'function'
}

async function runTestCase(options: any, testData: any, t: tape.Test | Chai.AssertStatic) {
const begin = Date.now()
// Copy the common object to not create long-lasting
// references in memory which might prevent GC
Expand Down Expand Up @@ -147,15 +151,15 @@
opName: e.opcode.name,
}

t.comment(JSON.stringify(opTrace))
isTape(t) && t.comment(JSON.stringify(opTrace))
resolve?.()
}

const afterTxHandler = async (_: any, resolve: any) => {
const stateRoot = {
stateRoot: bytesToHex(await vm.stateManager.getStateRoot()),
}
t.comment(JSON.stringify(stateRoot))
isTape(t) && t.comment(JSON.stringify(stateRoot))
resolve?.()
}

Expand Down Expand Up @@ -189,7 +193,14 @@
const end = Date.now()
const timeSpent = `${(end - begin) / 1000} secs`

t.ok(stateRootsAreEqual, `[ ${timeSpent} ] the state roots should match (${execInfo})`)
isTape(t) &&
t.ok(stateRootsAreEqual, `[ ${timeSpent} ] the state roots should match (${execInfo})`)
const msg = `error running test case for fork: ${options.forkConfigTestSuite}`
if (isTape(t)) {
t.ok(stateRootsAreEqual, `[ ${timeSpent} ] the state roots should match (${execInfo})`)
} else {
t.isTrue(stateRootsAreEqual, msg)

Check failure on line 202 in packages/vm/test/tester/runners/GeneralStateTestsRunner.ts

View workflow job for this annotation

GitHub Actions / vm-pr / vm-api

test/tester/stateRunner.spec.ts > TransactionTests > wrongBlobhashVersion - [Cancun]

AssertionError: error running test case for fork: Cancun: expected false to be true - Expected + Received - true + false ❯ runTestCase test/tester/runners/GeneralStateTestsRunner.ts:202:7 ❯ runStateTest test/tester/runners/GeneralStateTestsRunner.ts:234:7 ❯ test/tester/stateRunner.spec.ts:425:7
}

vm.evm.events!.removeListener('step', stepHandler)
vm.events.removeListener('afterTx', afterTxHandler)
Expand All @@ -199,32 +210,28 @@
return parseFloat(timeSpent)
}

export async function runStateTest(options: any, testData: any, t: tape.Test) {
try {
const testCases = parseTestCases(
options.forkConfigTestSuite,
testData,
options.data,
options.gasLimit,
options.value,
)
if (testCases.length === 0) {
t.comment(`No ${options.forkConfigTestSuite} post state defined, skip test`)
return
}
for (const testCase of testCases) {
if (options.reps !== undefined && options.reps > 0) {
let totalTimeSpent = 0
for (let x = 0; x < options.reps; x++) {
totalTimeSpent += await runTestCase(options, testCase, t)
}
t.comment(`Average test run: ${(totalTimeSpent / options.reps).toLocaleString()} s`)
} else {
await runTestCase(options, testCase, t)
export async function runStateTest(options: any, testData: any, t: tape.Test | Chai.AssertStatic) {
const testCases = parseTestCases(
options.forkConfigTestSuite,
testData,
options.data,
options.gasLimit,
options.value,
)
if (testCases.length === 0) {
isTape(t) && t.comment(`No ${options.forkConfigTestSuite} post state defined, skip test`)
return
}
for (const testCase of testCases) {
if (options.reps !== undefined && options.reps > 0) {
let totalTimeSpent = 0
for (let x = 0; x < options.reps; x++) {
totalTimeSpent += await runTestCase(options, testCase, t)
}
isTape(t) &&
t.comment(`Average test run: ${(totalTimeSpent / options.reps).toLocaleString()} s`)
} else {
await runTestCase(options, testCase, t)
}
} catch (e: any) {
console.log(e)
t.fail(`error running test case for fork: ${options.forkConfigTestSuite}`)
}
}
Loading
Loading