Skip to content

Commit ef0e70c

Browse files
evm: fix test
1 parent 9a1b4bf commit ef0e70c

File tree

10 files changed

+35
-23
lines changed

10 files changed

+35
-23
lines changed

packages/evm/test/eips/eip-3860.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('EIP 3860 tests', () => {
4343
}
4444
const result = await evm.runCall(runCallArgs)
4545
assert.ok(
46-
(result.execResult.exceptionError?.error as string) === 'initcode exceeds max initcode size',
46+
result.execResult.exceptionError?.type.code === 'initcode exceeds max initcode size',
4747
'initcode exceeds max size',
4848
)
4949
})

packages/evm/test/precompiles/01-ecrecover.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ describe('Precompiles: ECRECOVER', () => {
4343
common,
4444
_EVM: evm,
4545
})
46-
assert.equal(result.exceptionError!.error, 'out of gas', 'should error when not enough gas')
46+
assert.equal(result.exceptionError!.type.code, 'out of gas', 'should error when not enough gas')
4747
})
4848
})

packages/evm/test/precompiles/03-ripemd160.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ describe('Precompiles: RIPEMD160', () => {
3838
common,
3939
_EVM: evm,
4040
})
41-
assert.equal(result.exceptionError!.error, 'out of gas', 'should error when not enough gas')
41+
assert.equal(result.exceptionError!.type.code, 'out of gas', 'should error when not enough gas')
4242
})
4343
})

packages/evm/test/precompiles/09-blake2f.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ describe('Precompiles: BLAKE2F', () => {
120120
common,
121121
_EVM: evm,
122122
})
123-
assert.equal(result.exceptionError!.error, t.expectedError, 'should generate expected error')
123+
assert.equal(
124+
result.exceptionError!.type.code,
125+
t.expectedError,
126+
'should generate expected error',
127+
)
124128
})
125129
}
126130

packages/evm/test/precompiles/0a-pointevaluation.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ describe('Precompiles: point evaluation', () => {
7878
common,
7979
}
8080
res = await pointEvaluation(optsWithInvalidCommitment)
81-
assert.ok(res.exceptionError?.error.match('invalid input length'), 'invalid input length')
81+
assert.ok(res.exceptionError?.type.code.match('invalid input length'), 'invalid input length')
8282
})
8383
})

packages/evm/test/precompiles/eip-2537-bls.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ for (const bls of [undefined, mclbls]) {
8383
)
8484
assert.equal(result.executionGasUsed, BigInt(data.Gas))
8585
} catch (e: any) {
86-
assert.fail(e.message)
86+
assert.fail(e.type.code)
8787
}
8888
}
8989
})

packages/evm/test/runCall.spec.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import { assert, describe, it } from 'vitest'
1818

1919
import { eip4844Data } from '../../client/test/testdata/geth-genesis/eip4844.js'
2020
import { defaultBlock } from '../src/evm.js'
21-
import { ERROR } from '../src/exceptions.js'
22-
import { createEVM } from '../src/index.js'
21+
import { EVMErrorCode, createEVM } from '../src/index.js'
2322

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

@@ -138,7 +137,7 @@ describe('RunCall tests', () => {
138137

139138
assert.ok(
140139
byzantiumResult.execResult.exceptionError &&
141-
byzantiumResult.execResult.exceptionError.error === 'invalid opcode',
140+
byzantiumResult.execResult.exceptionError.type.code === 'invalid opcode',
142141
'byzantium cannot accept constantinople opcodes (SHL)',
143142
)
144143
assert.ok(
@@ -272,7 +271,10 @@ describe('RunCall tests', () => {
272271

273272
assert.equal(runCallArgs.gasLimit, result.execResult.executionGasUsed, 'gas used correct')
274273
assert.equal(result.execResult.gasRefund, BigInt(0), 'gas refund correct')
275-
assert.ok(result.execResult.exceptionError!.error === ERROR.OUT_OF_GAS, 'call went out of gas')
274+
assert.ok(
275+
result.execResult.exceptionError!.type.code === EVMErrorCode.OUT_OF_GAS,
276+
'call went out of gas',
277+
)
276278
})
277279

278280
it('ensure selfdestruct pays for creating new accounts', async () => {
@@ -512,7 +514,7 @@ describe('RunCall tests', () => {
512514

513515
const res2 = await evm.runCall({ ...runCallArgs, skipBalance: false })
514516
assert.ok(
515-
res2.execResult.exceptionError?.error.match('insufficient balance'),
517+
res2.execResult.exceptionError?.type.code.match('insufficient balance'),
516518
'runCall reverts when insufficient sender balance and skipBalance is false',
517519
)
518520
})
@@ -536,8 +538,8 @@ describe('RunCall tests', () => {
536538

537539
const result = await evm.runCall(runCallArgs)
538540
assert.equal(
539-
result.execResult.exceptionError?.error,
540-
ERROR.CODESIZE_EXCEEDS_MAXIMUM,
541+
result.execResult.exceptionError?.type.code,
542+
EVMErrorCode.CODESIZE_EXCEEDS_MAXIMUM,
541543
'reported error is correct',
542544
)
543545
})
@@ -648,7 +650,7 @@ describe('RunCall tests', () => {
648650
}
649651

650652
const res = await evm.runCall(runCallArgs)
651-
assert.ok(res.execResult.exceptionError?.error === ERROR.CODESIZE_EXCEEDS_MAXIMUM)
653+
assert.ok(res.execResult.exceptionError?.type.code === EVMErrorCode.CODESIZE_EXCEEDS_MAXIMUM)
652654

653655
// Create a contract which goes OOG when creating
654656
const runCallArgs2 = {
@@ -657,7 +659,7 @@ describe('RunCall tests', () => {
657659
}
658660

659661
const res2 = await evm.runCall(runCallArgs2)
660-
assert.ok(res2.execResult.exceptionError?.error === ERROR.OUT_OF_GAS)
662+
assert.ok(res2.execResult.exceptionError?.type.code === EVMErrorCode.OUT_OF_GAS)
661663
})
662664

663665
it('ensure code deposit errors are logged correctly (Frontier)', async () => {
@@ -671,7 +673,8 @@ describe('RunCall tests', () => {
671673
}
672674

673675
const res = await evm.runCall(runCallArgs)
674-
assert.ok(res.execResult.exceptionError?.error === ERROR.CODESTORE_OUT_OF_GAS)
676+
// TODO: This now fails?
677+
assert.ok(res.execResult.exceptionError?.type.code === EVMErrorCode.CODESTORE_OUT_OF_GAS)
675678

676679
// Create a contract which goes OOG when creating
677680
const runCallArgs2 = {
@@ -680,7 +683,7 @@ describe('RunCall tests', () => {
680683
}
681684

682685
const res2 = await evm.runCall(runCallArgs2)
683-
assert.ok(res2.execResult.exceptionError?.error === ERROR.OUT_OF_GAS)
686+
assert.ok(res2.execResult.exceptionError?.type.code === EVMErrorCode.OUT_OF_GAS)
684687
})
685688

686689
it('ensure call and callcode handle gas stipend correctly', async () => {

packages/evm/test/runCode.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Account, createAddressFromString, hexToBytes } from '@ethereumjs/util'
22
import { assert, describe, it } from 'vitest'
33

4-
import { createEVM } from '../src/index.js'
4+
import { EVMError, createEVM } from '../src/index.js'
55

66
const PUSH1 = '60'
77
const STOP = '00'
@@ -45,6 +45,11 @@ describe('VM.runCode: initial program counter', () => {
4545
}
4646

4747
if (testData.error !== undefined) {
48+
// TODO: for all tests in EVM: this is a perfect place
49+
// to also roll-out the instanceof check for errors
50+
// This currently throws not EVMError but instead the generic EthereumJSError
51+
// with the error code: `ETHEREUMJS_UNSET_ERROR_CODE`
52+
// Here we can thus verify that the error type is generic.
4853
err = err?.message ?? 'no error thrown'
4954
assert.equal(err, testData.error, 'error message should match')
5055
err = false
@@ -71,8 +76,8 @@ describe('VM.runCode: interpreter', () => {
7176
} catch (e: any) {
7277
assert.fail('should not throw error')
7378
}
74-
assert.equal(result!.exceptionError!.errorType, 'EvmError')
75-
assert.ok(result!.exceptionError!.error.includes('invalid opcode'))
79+
assert.ok(result!.exceptionError! instanceof EVMError)
80+
assert.ok(result!.exceptionError!.type.code.includes('invalid opcode'))
7681
})
7782

7883
it('should throw on non-EvmError', async () => {

packages/evm/test/stack.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('Stack', () => {
143143
const executionReturnValue = res.execResult.returnValue
144144
assert.deepEqual(executionReturnValue, expectedReturnValue)
145145
} catch (e: any) {
146-
assert.fail(e.message)
146+
assert.fail(e.type.code)
147147
}
148148
})
149149

packages/evm/test/verkle.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('verkle tests', () => {
7676
([_, chunk]) => chunk.write !== undefined,
7777
)
7878
assert.ok(writtenChunks.length === 0)
79-
assert.equal(res.execResult.exceptionError?.error, 'out of gas')
79+
assert.equal(res.execResult.exceptionError?.type.code, 'out of gas')
8080
})
8181

8282
it('access witness should contain a write access', async () => {
@@ -109,7 +109,7 @@ describe('verkle tests', () => {
109109
([_, chunk]) => chunk.write !== undefined,
110110
)
111111
assert.ok(writtenChunks.length === 1)
112-
assert.equal(res.execResult.exceptionError?.error, undefined)
112+
assert.equal(res.execResult.exceptionError?.type.code, undefined)
113113
})
114114
})
115115
describe('generate an execution witness', () => {

0 commit comments

Comments
 (0)