import { describe, it, expect } from 'vitest';
import { handler_0xa3_LOG3 } from './0xa3_LOG3.js';
describe('LOG3 (0xa3)', () => {
it('emits log with 3 topics and empty data', () => {
const topic0 = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaan;
const topic1 = 0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbn;
const topic2 = 0xccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccn;
const frame = createFrame({
stack: [topic2, topic1, topic0, 0n, 0n],
gasRemaining: 1000000n,
});
const err = handler_0xa3_LOG3(frame);
expect(err).toBeNull();
expect(frame.logs).toHaveLength(1);
expect(frame.logs[0].topics).toEqual([topic0, topic1, topic2]);
expect(frame.gasRemaining).toBe(998500n);
});
it('emits log with 3 topics and data', () => {
const frame = createFrame({
memory: new Map([[0, 0xde], [1, 0xad]]),
stack: [0x3333n, 0x2222n, 0x1111n, 2n, 0n],
gasRemaining: 1000000n,
});
handler_0xa3_LOG3(frame);
const log = frame.logs[0];
expect(log.topics).toEqual([0x1111n, 0x2222n, 0x3333n]);
expect(log.data).toEqual(new Uint8Array([0xde, 0xad]));
});
it('returns WriteProtection in static context', () => {
const frame = createFrame({ isStatic: true, stack: [0n, 0n, 0n, 0n, 0n] });
const err = handler_0xa3_LOG3(frame);
expect(err).toEqual({ type: "WriteProtection" });
});
it('returns StackUnderflow with 4 items', () => {
const frame = createFrame({ stack: [0n, 0n, 0n, 0n] });
const err = handler_0xa3_LOG3(frame);
expect(err).toEqual({ type: "StackUnderflow" });
});
it('handles boundary topic values', () => {
const max = (1n << 256n) - 1n;
const frame = createFrame({
stack: [max, 0n, max, 0n, 0n],
gasRemaining: 1000000n,
});
handler_0xa3_LOG3(frame);
expect(frame.logs[0].topics).toEqual([max, 0n, max]);
});
});