import { getPlaceClaimStakeInstanceWithHubInstructionDataEncoder, PLACE_CLAIM_STAKE_INSTANCE_WITH_HUB_DISCRIMINATOR, } from '../src/generated/instructions/placeClaimStakeInstanceWithHub'; import { identifySageInstruction } from '../src/generated/programs/sage'; const LEGACY_PLACE_CLAIM_STAKE_INSTANCE_DISCRIMINATOR = [ 192, 71, 140, 126, 67, 121, 161, 64, ]; describe('bundled claim stake hub placement', () => { it('encodes the exact-tier hub id under the new instruction discriminator', () => { const encoded = getPlaceClaimStakeInstanceWithHubInstructionDataEncoder().encode({ keyIndex: 0x1234, claimStakeDefinitionId: 0x2345, hubBuildingId: 0x3456, initialRentAmount: null, }); expect(encoded).toHaveLength(15); expect([...encoded.slice(0, 8)]).toEqual([ ...PLACE_CLAIM_STAKE_INSTANCE_WITH_HUB_DISCRIMINATOR, ]); expect([...encoded.slice(8)]).toEqual([ 0x34, 0x12, // keyIndex 0x45, 0x23, // claimStakeDefinitionId 0x56, 0x34, // hubBuildingId 0x00, // initialRentAmount = None ]); }); it('rejects a legacy Some(65_536) payload at the discriminator boundary', () => { const legacyPayload = new Uint8Array([ ...LEGACY_PLACE_CLAIM_STAKE_INSTANCE_DISCRIMINATOR, 0x34, 0x12, // keyIndex 0x45, 0x23, // claimStakeDefinitionId 0x01, // initialRentAmount = Some 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // 65_536u64, little-endian ]); expect(() => identifySageInstruction(legacyPayload)).toThrow(); }); });