-
Notifications
You must be signed in to change notification settings - Fork 846
Expand file tree
/
Copy pathstepPushData.spec.ts
More file actions
56 lines (50 loc) · 1.97 KB
/
stepPushData.spec.ts
File metadata and controls
56 lines (50 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { equalsBytes, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'
import { createEVM } from '../src/index.ts'
import type { InterpreterStep } from '../src/index.ts'
describe('step event pushData', () => {
it('sets pushData for PUSH0', async () => {
const evm = await createEVM()
const steps: InterpreterStep[] = []
evm.events.on('step', (e) => {
steps.push(e)
})
await evm.runCode({ code: hexToBytes('0x5f00'), gasLimit: 100000n })
const pushStep = steps.find((s) => s.opcode.code === 0x5f)
assert.isDefined(pushStep?.pushData)
assert.isTrue(equalsBytes(pushStep!.pushData!, new Uint8Array([0])))
})
it('sets pushData for PUSH1 to the immediate byte(s)', async () => {
const evm = await createEVM()
const steps: InterpreterStep[] = []
evm.events.on('step', (e) => {
steps.push(e)
})
await evm.runCode({ code: hexToBytes('0x60ab00'), gasLimit: 100000n })
const pushStep = steps.find((s) => s.opcode.code === 0x60)
assert.isDefined(pushStep?.pushData)
assert.isTrue(equalsBytes(pushStep!.pushData!, new Uint8Array([0xab])))
})
it('sets pushData length 32 for PUSH32', async () => {
const evm = await createEVM()
const steps: InterpreterStep[] = []
evm.events.on('step', (e) => {
steps.push(e)
})
const imm = '01'.repeat(32)
await evm.runCode({ code: hexToBytes(`0x7f${imm}00`), gasLimit: 100000n })
const pushStep = steps.find((s) => s.opcode.code === 0x7f)
assert.isDefined(pushStep?.pushData)
assert.strictEqual(pushStep!.pushData!.length, 32)
})
it('does not set pushData for non-PUSH opcodes', async () => {
const evm = await createEVM()
const steps: InterpreterStep[] = []
evm.events.on('step', (e) => {
steps.push(e)
})
await evm.runCode({ code: hexToBytes('0x600160020100'), gasLimit: 100000n })
const addStep = steps.find((s) => s.opcode.code === 0x01)
assert.isUndefined(addStep?.pushData)
})
})