Skip to content

Commit

Permalink
ESM/Vitest Transition: add Trie and EVM (#2783)
Browse files Browse the repository at this point in the history
* Trie: tape -> vitest test transition

* Trie: .js file path additions

* EVM: tape -> vitest transition

* EVM: .js path reference additions

* Fix ethers state manager tests

---------

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>
  • Loading branch information
holgerd77 and acolytec3 authored Jun 14, 2023
1 parent b04b115 commit c618c64
Show file tree
Hide file tree
Showing 98 changed files with 1,967 additions and 2,171 deletions.
4 changes: 2 additions & 2 deletions packages/evm/examples/decode-opcodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// 1. Takes binary EVM code and decodes it into opcodes

import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils'
import { getOpcodesForHF } from '../src/opcodes'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils.js'
import { getOpcodesForHF } from '../src/opcodes/index.js'

const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
const opcodes = getOpcodesForHF(common).opcodes
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/examples/runCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Blockchain } from '@ethereumjs/blockchain'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { EVM } from '@ethereumjs/evm'
import { DefaultStateManager } from '@ethereumjs/statemanager'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils.js'

const main = async () => {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
Expand Down
10 changes: 5 additions & 5 deletions packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"contributors": [
"Alex Beregszaszi <alex@rtfs.hu>"
],
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
Expand All @@ -36,8 +37,8 @@
"scripts": {
"build": "../../config/cli/ts-build.sh",
"clean": "../../config/cli/clean-package.sh",
"coverage": "c8 --all --reporter=lcov --reporter=text npm run coverage:test",
"coverage:test": "npm run test && cd ../vm && npm run tester -- --state",
"coverage": "npx vitest run --coverage.enabled --coverage.reporter=lcov",
"coverage:test": "npm run test:node && cd ../vm && npm run tester -- --state",
"docs:build": "typedoc --options typedoc.js",
"examples": "ts-node ../../scripts/examples-runner.ts -- evm",
"formatTest": "node ./scripts/formatTest",
Expand All @@ -46,9 +47,8 @@
"lint:fix": "../../config/cli/lint-fix.sh",
"prepublishOnly": "../../config/cli/prepublish.sh",
"profiling": "0x ./benchmarks/run.js profiling",
"tape": "tape -r ts-node/register --stack-size=1500",
"test": "npm run tape -- './test/**/*.spec.ts'",
"test:browser": "karma start karma.conf.js",
"test:browser": "npx vitest run --browser.name=chrome --browser.headless",
"test:node": "npx vitest run",
"tsc": "../../config/cli/ts-compile.sh"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/eof.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { handlers } from './opcodes'
import { handlers } from './opcodes/index.js'

export const FORMAT = 0xef
export const MAGIC = 0x00
Expand Down
32 changes: 16 additions & 16 deletions packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ import {
import { debug as createDebugLogger } from 'debug'
import { promisify } from 'util'

import { EOF, getEOFCode } from './eof'
import { ERROR, EvmError } from './exceptions'
import { Interpreter } from './interpreter'
import { Journal } from './journal'
import { Message } from './message'
import { getOpcodesForHF } from './opcodes'
import { getActivePrecompiles } from './precompiles'
import { TransientStorage } from './transientStorage'
import { DefaultBlockchain } from './types'

import type { InterpreterOpts, RunState } from './interpreter'
import type { MessageWithTo } from './message'
import type { OpHandler, OpcodeList } from './opcodes'
import type { AsyncDynamicGasHandler, SyncDynamicGasHandler } from './opcodes/gas'
import type { CustomPrecompile, PrecompileFunc } from './precompiles'
import { EOF, getEOFCode } from './eof.js'
import { ERROR, EvmError } from './exceptions.js'
import { Interpreter } from './interpreter.js'
import { Journal } from './journal.js'
import { Message } from './message.js'
import { getOpcodesForHF } from './opcodes/index.js'
import { getActivePrecompiles } from './precompiles/index.js'
import { TransientStorage } from './transientStorage.js'
import { DefaultBlockchain } from './types.js'

import type { InterpreterOpts, RunState } from './interpreter.js'
import type { MessageWithTo } from './message.js'
import type { AsyncDynamicGasHandler, SyncDynamicGasHandler } from './opcodes/gas.js'
import type { OpHandler, OpcodeList } from './opcodes/index.js'
import type { CustomPrecompile, PrecompileFunc } from './precompiles/index.js'
import type {
Block,
Blockchain,
Expand All @@ -41,7 +41,7 @@ import type {
EVMRunCallOpts,
EVMRunCodeOpts,
Log,
} from './types'
} from './types.js'
import type { EVMStateManagerInterface } from '@ethereumjs/common'

const debug = createDebugLogger('evm:evm')
Expand Down
14 changes: 7 additions & 7 deletions packages/evm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EOF } from './eof'
import { EVM, EVMResult, ExecResult } from './evm'
import { ERROR as EVMErrorMessage, EvmError } from './exceptions'
import { InterpreterStep } from './interpreter'
import { Message } from './message'
import { PrecompileInput, getActivePrecompiles } from './precompiles'
import { EVMInterface, Log } from './types'
import { EOF } from './eof.js'
import { EVM, EVMResult, ExecResult } from './evm.js'
import { ERROR as EVMErrorMessage, EvmError } from './exceptions.js'
import { InterpreterStep } from './interpreter.js'
import { Message } from './message.js'
import { PrecompileInput, getActivePrecompiles } from './precompiles/index.js'
import { EVMInterface, Log } from './types.js'
export {
EOF,
EVM,
Expand Down
22 changes: 11 additions & 11 deletions packages/evm/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { ConsensusAlgorithm } from '@ethereumjs/common'
import { Account, MAX_UINT64, bigIntToHex, bytesToBigInt, bytesToHex } from '@ethereumjs/util'
import { debug as createDebugLogger } from 'debug'

import { EOF } from './eof'
import { ERROR, EvmError } from './exceptions'
import { Memory } from './memory'
import { Message } from './message'
import { trap } from './opcodes'
import { Stack } from './stack'

import type { EVM, EVMResult } from './evm'
import type { Journal } from './journal'
import type { AsyncOpHandler, OpHandler, Opcode } from './opcodes'
import type { Block, Blockchain, Log } from './types'
import { EOF } from './eof.js'
import { ERROR, EvmError } from './exceptions.js'
import { Memory } from './memory.js'
import { Message } from './message.js'
import { trap } from './opcodes/index.js'
import { Stack } from './stack.js'

import type { EVM, EVMResult } from './evm.js'
import type { Journal } from './journal.js'
import type { AsyncOpHandler, OpHandler, Opcode } from './opcodes/index.js'
import type { Block, Blockchain, Log } from './types.js'
import type { Common, EVMStateManagerInterface } from '@ethereumjs/common'
import type { Address } from '@ethereumjs/util'

Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address } from '@ethereumjs/util'

import type { PrecompileFunc } from './precompiles'
import type { PrecompileFunc } from './precompiles/index.js'

const defaults = {
value: BigInt(0),
Expand Down
4 changes: 2 additions & 2 deletions packages/evm/src/opcodes/EIP1283.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { equalsBytes } from 'ethereum-cryptography/utils'
import { equalsBytes } from 'ethereum-cryptography/utils.js'

import type { RunState } from '../interpreter'
import type { RunState } from '../interpreter.js'
import type { Common } from '@ethereumjs/common'

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/evm/src/opcodes/EIP2200.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { equalsBytes } from 'ethereum-cryptography/utils'
import { equalsBytes } from 'ethereum-cryptography/utils.js'

import { ERROR } from '../exceptions'
import { ERROR } from '../exceptions.js'

import { adjustSstoreGasEIP2929 } from './EIP2929'
import { trap } from './util'
import { adjustSstoreGasEIP2929 } from './EIP2929.js'
import { trap } from './util.js'

import type { RunState } from '../interpreter'
import type { RunState } from '../interpreter.js'
import type { Common } from '@ethereumjs/common'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/opcodes/EIP2929.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RunState } from '../interpreter'
import type { RunState } from '../interpreter.js'
import type { Common } from '@ethereumjs/common'
import type { Address } from '@ethereumjs/util'

Expand Down
12 changes: 6 additions & 6 deletions packages/evm/src/opcodes/codes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Hardfork } from '@ethereumjs/common'

import { handlers } from './functions'
import { dynamicGasHandlers } from './gas'
import { getFullname } from './util'
import { handlers } from './functions.js'
import { dynamicGasHandlers } from './gas.js'
import { getFullname } from './util.js'

import type { CustomOpcode } from '../types'
import type { OpHandler } from './functions'
import type { AsyncDynamicGasHandler, SyncDynamicGasHandler } from './gas'
import type { CustomOpcode } from '../types.js'
import type { OpHandler } from './functions.js'
import type { AsyncDynamicGasHandler, SyncDynamicGasHandler } from './gas.js'
import type { Common } from '@ethereumjs/common'

export class Opcode {
Expand Down
10 changes: 5 additions & 5 deletions packages/evm/src/opcodes/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
setLengthLeft,
setLengthRight,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils.js'

import { ERROR } from '../exceptions'
import { ERROR } from '../exceptions.js'

import {
addresstoBytes,
Expand All @@ -28,9 +28,9 @@ import {
toTwos,
trap,
writeCallOutput,
} from './util'
} from './util.js'

import type { RunState } from '../interpreter'
import type { RunState } from '../interpreter.js'
import type { Common } from '@ethereumjs/common'

const EIP3074MAGIC = hexToBytes('03')
Expand Down
12 changes: 6 additions & 6 deletions packages/evm/src/opcodes/gas.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Hardfork } from '@ethereumjs/common'
import { Address, bigIntToBytes, setLengthLeft } from '@ethereumjs/util'

import { ERROR } from '../exceptions'
import { ERROR } from '../exceptions.js'

import { updateSstoreGasEIP1283 } from './EIP1283'
import { updateSstoreGasEIP2200 } from './EIP2200'
import { accessAddressEIP2929, accessStorageEIP2929 } from './EIP2929'
import { updateSstoreGasEIP1283 } from './EIP1283.js'
import { updateSstoreGasEIP2200 } from './EIP2200.js'
import { accessAddressEIP2929, accessStorageEIP2929 } from './EIP2929.js'
import {
addresstoBytes,
divCeil,
Expand All @@ -14,9 +14,9 @@ import {
subMemUsage,
trap,
updateSstoreGas,
} from './util'
} from './util.js'

import type { RunState } from '../interpreter'
import type { RunState } from '../interpreter.js'
import type { Common } from '@ethereumjs/common'

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/evm/src/opcodes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './codes'
export * from './functions'
export * from './util'
export * from './codes.js'
export * from './functions.js'
export * from './util.js'
10 changes: 5 additions & 5 deletions packages/evm/src/opcodes/util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Hardfork } from '@ethereumjs/common'
import { bigIntToBytes, setLengthLeft, setLengthRight } from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { bytesToHex, equalsBytes } from 'ethereum-cryptography/utils'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { bytesToHex, equalsBytes } from 'ethereum-cryptography/utils.js'

import { EvmError } from '../exceptions'
import { EvmError } from '../exceptions.js'

import type { ERROR } from '../exceptions'
import type { RunState } from '../interpreter'
import type { ERROR } from '../exceptions.js'
import type { RunState } from '../interpreter.js'
import type { Common } from '@ethereumjs/common'

const MASK_160 = (BigInt(1) << BigInt(160)) - BigInt(1)
Expand Down
6 changes: 3 additions & 3 deletions packages/evm/src/precompiles/01-ecrecover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
short,
} from '@ethereumjs/util'

import { OOGResult } from '../evm'
import { OOGResult } from '../evm.js'

import type { ExecResult } from '../evm'
import type { PrecompileInput } from './types'
import type { ExecResult } from '../evm.js'
import type { PrecompileInput } from './types.js'

export function precompile01(opts: PrecompileInput): ExecResult {
const gasUsed = opts._common.param('gasPrices', 'ecRecover')
Expand Down
8 changes: 4 additions & 4 deletions packages/evm/src/precompiles/02-sha256.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { bytesToHex, short } from '@ethereumjs/util'
import { sha256 } from 'ethereum-cryptography/sha256'
import { sha256 } from 'ethereum-cryptography/sha256.js'

import { OOGResult } from '../evm'
import { OOGResult } from '../evm.js'

import type { ExecResult } from '../evm'
import type { PrecompileInput } from './types'
import type { ExecResult } from '../evm.js'
import type { PrecompileInput } from './types.js'

export function precompile02(opts: PrecompileInput): ExecResult {
const data = opts.data
Expand Down
8 changes: 4 additions & 4 deletions packages/evm/src/precompiles/03-ripemd160.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { bytesToHex, setLengthLeft, short } from '@ethereumjs/util'
import { ripemd160 } from 'ethereum-cryptography/ripemd160'
import { ripemd160 } from 'ethereum-cryptography/ripemd160.js'

import { OOGResult } from '../evm'
import { OOGResult } from '../evm.js'

import type { ExecResult } from '../evm'
import type { PrecompileInput } from './types'
import type { ExecResult } from '../evm.js'
import type { PrecompileInput } from './types.js'

export function precompile03(opts: PrecompileInput): ExecResult {
const data = opts.data
Expand Down
6 changes: 3 additions & 3 deletions packages/evm/src/precompiles/04-identity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { short } from '@ethereumjs/util'

import { OOGResult } from '../evm'
import { OOGResult } from '../evm.js'

import type { ExecResult } from '../evm'
import type { PrecompileInput } from './types'
import type { ExecResult } from '../evm.js'
import type { PrecompileInput } from './types.js'

export function precompile04(opts: PrecompileInput): ExecResult {
const data = opts.data
Expand Down
6 changes: 3 additions & 3 deletions packages/evm/src/precompiles/05-modexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
short,
} from '@ethereumjs/util'

import { OOGResult } from '../evm'
import { OOGResult } from '../evm.js'

import type { ExecResult } from '../evm'
import type { PrecompileInput } from './types'
import type { ExecResult } from '../evm.js'
import type { PrecompileInput } from './types.js'

function multComplexity(x: bigint): bigint {
let fac1
Expand Down
8 changes: 4 additions & 4 deletions packages/evm/src/precompiles/06-ecadd.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { short } from '@ethereumjs/util'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils.js'

import { OOGResult } from '../evm'
import { OOGResult } from '../evm.js'

import type { ExecResult } from '../evm'
import type { PrecompileInput } from './types'
import type { ExecResult } from '../evm.js'
import type { PrecompileInput } from './types.js'

const bn128 = require('rustbn.js')

Expand Down
8 changes: 4 additions & 4 deletions packages/evm/src/precompiles/07-ecmul.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { short } from '@ethereumjs/util'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils'
import { bytesToHex, hexToBytes } from 'ethereum-cryptography/utils.js'

import { OOGResult } from '../evm'
import { OOGResult } from '../evm.js'

import type { ExecResult } from '../evm'
import type { PrecompileInput } from './types'
import type { ExecResult } from '../evm.js'
import type { PrecompileInput } from './types.js'

const bn128 = require('rustbn.js')

Expand Down
Loading

0 comments on commit c618c64

Please sign in to comment.