import { AccountRole, address, createNoopSigner, type AccountMeta, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyUint8Array, } from '@solana/kit'; import { describe, expect, it } from 'vitest'; import { getAcknowledgeScanResultInstruction, parseAcknowledgeScanResultInstruction, } from '../src/generated/instructions/acknowledgeScanResult'; import { parseSageInstruction, SageInstruction, } from '../src/generated/programs/sage'; const SIGNER = address('11111111111111111111111111111111'); const PROFILE = address('Vote111111111111111111111111111111111111111'); const GAME = address('Stake11111111111111111111111111111111111111'); const SIGNAL = address('SysvarC1ock11111111111111111111111111111111'); const FLEET = address('Config1111111111111111111111111111111111111'); const HYE_PROGRAM = address('HYEWZXXzMyrnN89ASYPVHHdFdgvrgV8diFLv6P2wEwFN'); const upgradedInstruction = () => getAcknowledgeScanResultInstruction({ profileValidationSigner: createNoopSigner(SIGNER), profileValidationProfile: PROFILE, game: GAME, scanSignal: SIGNAL, fleet: FLEET, keyIndex: 0, expectedSequence: 3n, }); type ParseableInstruction = Instruction & InstructionWithAccounts & InstructionWithData; describe('AcknowledgeScanResult parser compatibility', () => { it('parses the upgraded seven-account instruction and exposes Fleet', () => { const instruction = upgradedInstruction(); expect(instruction.accounts).toHaveLength(7); expect(instruction.accounts[6]).toEqual({ address: FLEET, role: AccountRole.WRITABLE, }); const parsed = parseAcknowledgeScanResultInstruction(instruction); expect(parsed.accounts.fleet?.address).toBe(FLEET); }); it('parses historical six-account instructions through direct and top-level parsers', () => { const upgraded = upgradedInstruction(); const legacy = { ...upgraded, accounts: upgraded.accounts.slice(0, 6), } as ParseableInstruction; const parsed = parseAcknowledgeScanResultInstruction(legacy); expect(parsed.accounts.fleet).toBeUndefined(); const topLevel = parseSageInstruction(legacy); expect(topLevel.instructionType).toBe( SageInstruction.AcknowledgeScanResult, ); if (topLevel.instructionType !== SageInstruction.AcknowledgeScanResult) { throw new Error('expected AcknowledgeScanResult'); } expect(topLevel.accounts.fleet).toBeUndefined(); }); const omittedFleetInstruction = (programAddress?: typeof HYE_PROGRAM) => getAcknowledgeScanResultInstruction( { profileValidationSigner: createNoopSigner(SIGNER), profileValidationProfile: PROFILE, game: GAME, scanSignal: SIGNAL, keyIndex: 0, expectedSequence: 3n, }, programAddress ? { programAddress } : undefined, ); it('parses an omitted Fleet sentinel directly for the default deployment', () => { const instruction = omittedFleetInstruction(); expect(instruction.accounts).toHaveLength(7); expect(instruction.accounts[6]?.address).toBe(instruction.programAddress); expect( parseAcknowledgeScanResultInstruction(instruction).accounts.fleet, ).toBeUndefined(); }); it('parses an omitted Fleet sentinel through the top-level default parser', () => { const parsed = parseSageInstruction(omittedFleetInstruction()); expect(parsed.instructionType).toBe(SageInstruction.AcknowledgeScanResult); if (parsed.instructionType !== SageInstruction.AcknowledgeScanResult) { throw new Error('expected AcknowledgeScanResult'); } expect(parsed.accounts.fleet).toBeUndefined(); }); it('parses an omitted Fleet sentinel directly for a non-default deployment', () => { const instruction = omittedFleetInstruction(HYE_PROGRAM); expect(instruction.accounts).toHaveLength(7); expect(instruction.accounts[6]?.address).toBe(HYE_PROGRAM); expect( parseAcknowledgeScanResultInstruction(instruction).accounts.fleet, ).toBeUndefined(); }); it('parses an omitted Fleet sentinel through the top-level non-default parser', () => { const parsed = parseSageInstruction(omittedFleetInstruction(HYE_PROGRAM)); expect(parsed.instructionType).toBe(SageInstruction.AcknowledgeScanResult); if (parsed.instructionType !== SageInstruction.AcknowledgeScanResult) { throw new Error('expected AcknowledgeScanResult'); } expect(parsed.accounts.fleet).toBeUndefined(); }); it('preserves an explicit Fleet for a non-default deployment', () => { const instruction = getAcknowledgeScanResultInstruction( { profileValidationSigner: createNoopSigner(SIGNER), profileValidationProfile: PROFILE, game: GAME, scanSignal: SIGNAL, fleet: FLEET, keyIndex: 0, expectedSequence: 3n, }, { programAddress: HYE_PROGRAM }, ); expect( parseAcknowledgeScanResultInstruction(instruction).accounts.fleet ?.address, ).toBe(FLEET); }); });