import { describe, it, expect } from 'vitest';
import { handle as SLT } from './0x12_SLT.js';
describe('SLT (0x12)', () => {
it('returns 1 when a < b (both positive)', () => {
const frame = createFrame([10n, 20n]);
expect(SLT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]);
expect(frame.gasRemaining).toBe(997n);
});
it('returns 1 when negative < positive', () => {
const NEG_1 = (1n << 256n) - 1n;
const frame = createFrame([NEG_1, 10n]);
expect(SLT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]); // -1 < 10
});
it('returns 0 when positive > negative', () => {
const NEG_1 = (1n << 256n) - 1n;
const frame = createFrame([10n, NEG_1]);
expect(SLT(frame)).toBeNull();
expect(frame.stack).toEqual([0n]); // 10 > -1
});
it('compares negative numbers correctly', () => {
const NEG_10 = (1n << 256n) - 10n;
const NEG_5 = (1n << 256n) - 5n;
const frame = createFrame([NEG_10, NEG_5]);
expect(SLT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]); // -10 < -5
});
it('handles -1 < 0', () => {
const NEG_1 = (1n << 256n) - 1n;
const frame = createFrame([NEG_1, 0n]);
expect(SLT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]);
});
it('handles MIN_INT256 < MAX_INT256', () => {
const MIN = 1n << 255n;
const MAX = (1n << 255n) - 1n;
const frame = createFrame([MIN, MAX]);
expect(SLT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]);
});
it('returns 0 when a >= b (equal)', () => {
const frame = createFrame([20n, 20n]);
expect(SLT(frame)).toBeNull();
expect(frame.stack).toEqual([0n]);
});
it('returns StackUnderflow with insufficient stack', () => {
const frame = createFrame([10n]);
expect(SLT(frame)).toEqual({ type: 'StackUnderflow' });
});
it('preserves stack below compared values', () => {
const frame = createFrame([100n, 200n, 10n, 20n]);
expect(SLT(frame)).toBeNull();
expect(frame.stack).toEqual([100n, 200n, 1n]);
});
});