Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
evm: fix for browser mode tests
Browse files Browse the repository at this point in the history
ScottyPoi committed Jan 12, 2024
1 parent d805cd7 commit 5c09caf
Showing 20 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@
"prepublishOnly": "../../config/cli/prepublish.sh",
"profiling": "0x ./benchmarks/run.js profiling",
"test": "npm run test:node && npm run test:browser",
"test:browser": "npx vitest run -c=vitest.config.browser.ts --browser.provider=playwright --browser.name=webkit --browser.headless",
"test:browser": "npx vitest run -c=./vitest.config.browser.ts",
"test:node": "npx vitest run",
"tsc": "../../config/cli/ts-compile.sh"
},
2 changes: 1 addition & 1 deletion packages/evm/test/asyncEvents.spec.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { Address, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM } from '../src/index.js'
import { EVM } from '../src/evm.js'
describe('async events', () => {
it('should work', async () => {
const caller = new Address(hexToBytes('0x00000000000000000000000000000000000000ee'))
2 changes: 1 addition & 1 deletion packages/evm/test/blobVersionedHashes.spec.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { Common, Hardfork } from '@ethereumjs/common'
import { Account, Address, bytesToHex, hexToBytes, unpadBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM } from '../src/index.js'
import { EVM } from '../src/evm.js'

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

2 changes: 1 addition & 1 deletion packages/evm/test/customOpcodes.spec.ts
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ describe('VM: custom opcodes', () => {
evm.events.on('step', (e: InterpreterStep) => {
if (e.pc === 0) {
correctOpcodeName = e.opcode.name === testOpcode.opcodeName
assert.ok(correctOpcodeName, 'successfully set opcode name')
}
})
const res = await evm.runCode({
@@ -41,7 +42,6 @@ describe('VM: custom opcodes', () => {
})
assert.ok(res.executionGasUsed === totalFee, 'successfully charged correct gas')
assert.ok(res.runState!.stack.peek()[0] === stackPush, 'successfully ran opcode logic')
assert.ok(correctOpcodeName, 'successfully set opcode name')
})

it('should delete opcodes from the EVM', async () => {
2 changes: 1 addition & 1 deletion packages/evm/test/eips/eip-3860.spec.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { DefaultStateManager } from '@ethereumjs/statemanager'
import { Address, concatBytes, equalsBytes, hexToBytes, privateToAddress } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM } from '../../src/index.js'
import { EVM } from '../../src/evm.js'

const pkey = hexToBytes('0x' + '20'.repeat(32))
const sender = new Address(privateToAddress(pkey))
7 changes: 3 additions & 4 deletions packages/evm/test/eips/eip-5656.spec.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { bytesToHex, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM } from '../../src/index.js'
import { EVM } from '../../src/evm.js'

type Situation = {
pre: string
@@ -56,7 +56,7 @@ const MSTORE8 = '53'
const MCOPY = '5E'
const STOP = '00'

describe('should test mcopy', () => {
describe('should test mcopy', async () => {
for (const situation of situations) {
it('should produce correct output', async () => {
// create bytecode
@@ -92,15 +92,14 @@ describe('should test mcopy', () => {
evm.events.on('step', (e) => {
if (e.opcode.name === 'STOP') {
currentMem = bytesToHex(e.memory)
assert.equal(currentMem, '0x' + situation.post, 'post-memory correct')
}
})

await evm.runCall({
data: hexToBytes(bytecode),
gasLimit: BigInt(0xffffff),
})

assert.equal(currentMem, '0x' + situation.post, 'post-memory correct')
})
}
})
2 changes: 1 addition & 1 deletion packages/evm/test/opcodes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { assert, describe, it } from 'vitest'

import { EVM } from '../src/index.js'
import { EVM } from '../src/evm.js'

describe('EVM -> getActiveOpcodes()', () => {
const DIFFICULTY_PREVRANDAO = 0x44
3 changes: 2 additions & 1 deletion packages/evm/test/precompiles/01-ecrecover.spec.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@ import { bytesToHex, bytesToUnprefixedHex, hexToBytes, utf8ToBytes } from '@ethe
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'
import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'

const prefix = bytesToUnprefixedHex(utf8ToBytes('\x19Ethereum Signed Message:\n32'))
const _hash = '852daa74cc3c31fe64542bb9b8764cfb91cc30f9acf9389071ffb44a9eefde46'
4 changes: 2 additions & 2 deletions packages/evm/test/precompiles/03-ripemd160.spec.ts
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { bytesToHex, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'

import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'
const input =
'38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02'
const expected = '0000000000000000000000009215b8d9882ff46f0dfde6684d78e831467f65e6'
3 changes: 2 additions & 1 deletion packages/evm/test/precompiles/05-modexp.spec.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@ import { Chain, Common } from '@ethereumjs/common'
import { bytesToHex, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'
import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'

import fuzzer from './modexp-testdata.json'

4 changes: 2 additions & 2 deletions packages/evm/test/precompiles/06-ecadd.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'

import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'
describe('Precompiles: ECADD', () => {
it('ECADD', async () => {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Petersburg })
4 changes: 2 additions & 2 deletions packages/evm/test/precompiles/07-ecmul.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'

import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'
describe('Precompiles: ECMUL', () => {
it('ECMUL', async () => {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Petersburg })
4 changes: 2 additions & 2 deletions packages/evm/test/precompiles/08-ecpairing.spec.ts
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'

import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'
describe('Precompiles: ECPAIRING', () => {
it('ECPAIRING', async () => {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Petersburg })
3 changes: 2 additions & 1 deletion packages/evm/test/precompiles/09-blake2f.spec.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { Address, bytesToHex, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'
import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'

const validCases = [
{
5 changes: 3 additions & 2 deletions packages/evm/test/precompiles/0a-pointevaluation.spec.ts
Original file line number Diff line number Diff line change
@@ -10,9 +10,10 @@ import {
import * as kzg from 'c-kzg'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'
import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'

import type { PrecompileInput } from '../../src/index.js'
import type { PrecompileInput } from '../../src/precompiles/index.js'

const BLS_MODULUS = BigInt(
'52435875175126190479447740508185965837690552500527637822603658699938581184513'
4 changes: 2 additions & 2 deletions packages/evm/test/precompiles/hardfork.spec.ts
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { Address, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM, getActivePrecompiles } from '../../src/index.js'

import { EVM } from '../../src/evm.js'
import { getActivePrecompiles } from '../../src/precompiles/index.js'
describe('Precompiles: hardfork availability', () => {
it('Test ECPAIRING availability', async () => {
const ECPAIR_AddressStr = '0000000000000000000000000000000000000008'
7 changes: 3 additions & 4 deletions packages/evm/test/runCall.spec.ts
Original file line number Diff line number Diff line change
@@ -14,10 +14,9 @@ import {
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { assert, describe, it } from 'vitest'

import * as genesisJSON from '../../client/test/testdata/geth-genesis/eip4844.json'
import { defaultBlock } from '../src/evm.js'
import genesisJSON from '../../client/test/testdata/geth-genesis/eip4844.json'
import { EVM, defaultBlock } from '../src/evm.js'
import { ERROR } from '../src/exceptions.js'
import { EVM } from '../src/index.js'

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

@@ -662,10 +661,10 @@ describe('RunCall tests', () => {
assert.ok(e.memory.length <= 96)
if (e.memory.length > 0) {
verifyMemoryExpanded = true
assert.ok(verifyMemoryExpanded, 'memory did expand')
}
})
await evm.runCall(runCallArgs)
assert.ok(verifyMemoryExpanded, 'memory did expand')
})

it('ensure code deposit errors are logged correctly (>= Homestead)', async () => {
2 changes: 1 addition & 1 deletion packages/evm/test/runCode.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Account, Address, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM } from '../src/index.js'
import { EVM } from '../src/evm.js'

const PUSH1 = '60'
const STOP = '00'
2 changes: 1 addition & 1 deletion packages/evm/test/stack.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Account, Address, bigIntToBytes, hexToBytes, setLengthLeft } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { EVM } from '../src/index.js'
import { EVM } from '../src/evm.js'
import { Stack } from '../src/stack.js'

import { createAccount } from './utils.js'
18 changes: 11 additions & 7 deletions packages/evm/vitest.config.browser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import wasm from 'vite-plugin-wasm'
import topLevelAwait from 'vite-plugin-top-level-await'
import { defineConfig } from 'vitest/config'
import { defineConfig, mergeConfig } from 'vitest/config'
import baseConfig from '../../config/vitest.config.browser'

export default defineConfig({
plugins: [wasm(), topLevelAwait()],
test: {
exclude: ['test/blobVersionedHashes.spec.ts', 'test/precompiles/0a-pointevaluation.spec.ts'], // KZG based tests fail since c-kzg doesn't work in browser
},
})
export default mergeConfig(
baseConfig,
defineConfig({
plugins: [topLevelAwait()],
test: {
exclude: ['test/blobVersionedHashes.spec.ts', 'test/precompiles/0a-pointevaluation.spec.ts'], // KZG based tests fail since c-kzg doesn't work in browser
},
})
)

0 comments on commit 5c09caf

Please sign in to comment.