import { describe, it, expect } from 'vitest';
import { handler_0xa0_LOG0 } from './0xa0_LOG0.js';
describe('LOG0 (0xa0)', () => {
it('emits log with empty data', () => {
const frame = createFrame({
stack: [0n, 0n],
gasRemaining: 1000000n,
});
const err = handler_0xa0_LOG0(frame);
expect(err).toBeNull();
expect(frame.logs).toHaveLength(1);
expect(frame.logs[0].topics).toEqual([]);
expect(frame.gasRemaining).toBe(999625n);
});
it('reads data from memory', () => {
const frame = createFrame({
memory: new Map([[0, 0xde], [1, 0xad], [2, 0xbe], [3, 0xef]]),
stack: [0n, 4n],
gasRemaining: 1000000n,
});
handler_0xa0_LOG0(frame);
const log = frame.logs[0];
expect(log.data).toEqual(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
});
it('returns WriteProtection in static context', () => {
const frame = createFrame({ isStatic: true, stack: [0n, 0n] });
const err = handler_0xa0_LOG0(frame);
expect(err).toEqual({ type: "WriteProtection" });
});
it('returns StackUnderflow with insufficient stack', () => {
const frame = createFrame({ stack: [0n] });
const err = handler_0xa0_LOG0(frame);
expect(err).toEqual({ type: "StackUnderflow" });
});
it('returns OutOfGas when insufficient gas', () => {
const frame = createFrame({
stack: [0n, 0n],
gasRemaining: 374n,
});
const err = handler_0xa0_LOG0(frame);
expect(err).toEqual({ type: "OutOfGas" });
});
it('expands memory correctly', () => {
const frame = createFrame({
stack: [0n, 100n],
gasRemaining: 1000000n,
});
handler_0xa0_LOG0(frame);
expect(frame.memorySize).toBe(128); // ceil(100/32)*32
});
});