import { describe, it, expect } from 'vitest';
import { handler_0xa1_LOG1 } from './0xa1_LOG1.js';
describe('LOG1 (0xa1)', () => {
it('emits log with 1 topic and empty data', () => {
const topic = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaan;
const frame = createFrame({
stack: [topic, 0n, 0n],
gasRemaining: 1000000n,
});
const err = handler_0xa1_LOG1(frame);
expect(err).toBeNull();
expect(frame.logs).toHaveLength(1);
expect(frame.logs[0].topics).toEqual([topic]);
expect(frame.gasRemaining).toBe(999250n);
});
it('emits log with topic and data', () => {
const frame = createFrame({
memory: new Map([[0, 0xde], [1, 0xad]]),
stack: [0x1111n, 2n, 0n],
gasRemaining: 1000000n,
});
handler_0xa1_LOG1(frame);
const log = frame.logs[0];
expect(log.topics).toEqual([0x1111n]);
expect(log.data).toEqual(new Uint8Array([0xde, 0xad]));
});
it('returns WriteProtection in static context', () => {
const frame = createFrame({ isStatic: true, stack: [0n, 0n, 0n] });
const err = handler_0xa1_LOG1(frame);
expect(err).toEqual({ type: "WriteProtection" });
});
it('returns StackUnderflow with 2 items', () => {
const frame = createFrame({ stack: [0n, 0n] });
const err = handler_0xa1_LOG1(frame);
expect(err).toEqual({ type: "StackUnderflow" });
});
it('handles max uint256 topic', () => {
const maxUint256 = (1n << 256n) - 1n;
const frame = createFrame({
stack: [maxUint256, 0n, 0n],
gasRemaining: 1000000n,
});
handler_0xa1_LOG1(frame);
expect(frame.logs[0].topics[0]).toBe(maxUint256);
});
});