import { describe, it, expect } from 'vitest';
import { handler_0x56_JUMP } from './0x56_JUMP.js';
describe('JUMP (0x56)', () => {
it('jumps to valid JUMPDEST', () => {
const bytecode = new Uint8Array([
0x60, 0x05, // PUSH1 5
0x56, // JUMP
0x00, 0x00, // STOP (skipped)
0x5b, // JUMPDEST
]);
const frame = createFrame({
bytecode,
stack: [5n],
pc: 2,
});
expect(handler_0x56_JUMP(frame)).toBeNull();
expect(frame.pc).toBe(5);
});
it('rejects jump to non-JUMPDEST', () => {
const bytecode = new Uint8Array([0x60, 0x00]);
const frame = createFrame({
bytecode,
stack: [1n],
pc: 0,
});
expect(handler_0x56_JUMP(frame)).toEqual({ type: 'InvalidJump' });
});
it('rejects out of bounds destination', () => {
const frame = createFrame({
bytecode: new Uint8Array([0x5b]),
stack: [1000n],
});
expect(handler_0x56_JUMP(frame)).toEqual({ type: 'InvalidJump' });
});
it('rejects destination larger than u32', () => {
const frame = createFrame({
stack: [0x100000000n],
});
expect(handler_0x56_JUMP(frame)).toEqual({ type: 'OutOfBounds' });
});
it('handles stack underflow', () => {
const frame = createFrame({ stack: [] });
expect(handler_0x56_JUMP(frame)).toEqual({ type: 'StackUnderflow' });
});
});