diff --git a/tests/escrow.test.ts b/tests/escrow.test.ts index 438ad54..6c2f86c 100644 --- a/tests/escrow.test.ts +++ b/tests/escrow.test.ts @@ -115,6 +115,24 @@ describe('EscrowModule (stubs)', () => { }); }); + it("getEscrow returns an object with the correct field types", async () => { + const { client, mockServer } = makeConnectedClient(); + mockServer.simulateTransaction.mockResolvedValue({ + status: 'SUCCESS', + result: { + retval: xdr.ScVal.fromXDR(ESCROW_RECORD_XDR, 'base64'), + }, + }); + + const escrow = await client.escrow.getEscrow(1n); + expect(typeof escrow!.depositor).toBe("string"); + expect(typeof escrow!.beneficiary).toBe("string"); + expect(typeof escrow!.amount).toBe("bigint"); + expect(typeof escrow!.expiryLedger).toBe("number"); + expect(typeof escrow!.released).toBe("boolean"); + expect(typeof escrow!.refunded).toBe("boolean"); + }); + it('returns escrow IDs for a depositor', async () => { const { client, mockServer } = makeConnectedClient(); mockServer.simulateTransaction.mockResolvedValue({ @@ -1441,4 +1459,4 @@ describe('EscrowModule.getEscrowedValueForDepositor', () => { const total = await client.escrow.getEscrowedValueForDepositor(DEPOSITOR); expect(total).toBe(0n); }); -}); +}); \ No newline at end of file diff --git a/tests/recurring.test.ts b/tests/recurring.test.ts index 5ee28eb..aa117ec 100644 --- a/tests/recurring.test.ts +++ b/tests/recurring.test.ts @@ -700,6 +700,65 @@ describe('RecurringModule.executeAllDue', () => { }); }); +// --------------------------------------------------------------------------- +// #470 — paused field correctly parsed from contract records +// --------------------------------------------------------------------------- +describe('RecurringModule.getRecurring paused field parsing', () => { + // First, add the mapEntry helper we need to create valid ScvMap entries + function mapEntry(key: string, val: xdr.ScVal): xdr.ScMapEntry { + return new xdr.ScMapEntry({ + key: xdr.ScVal.scvSymbol(key), + val, + }); + } + + it("getRecurring returns paused:true when the contract record is paused", async () => { + const { client, mockServer } = makeRecurringClient(); + // Create a recurring record with paused: true in the raw ScvMap + mockServer.simulateTransaction.mockResolvedValue({ + status: 'SUCCESS', + result: { + retval: xdr.ScVal.scvMap([ + mapEntry('id', nativeToScVal(1n, { type: 'u64' })), + mapEntry('payer', xdr.ScVal.scvString(FAKE_PAYER)), + mapEntry('payee', xdr.ScVal.scvString('GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN')), + mapEntry('amount', nativeToScVal(1_000_000n, { type: 'i128' })), + mapEntry('interval', nativeToScVal(100, { type: 'u32' })), + mapEntry('active', xdr.ScVal.scvBool(true)), + mapEntry('paused', xdr.ScVal.scvBool(true)), + mapEntry('last_charged_ledger', nativeToScVal(0, { type: 'u32' })), + ]), + }, + }); + + const record = await client.recurring.getRecurring(1n); + expect(record!.paused).toBe(true); + }); + + it("getRecurring returns paused:false for an active recurring record", async () => { + const { client, mockServer } = makeRecurringClient(); + // Create a recurring record with paused: false in the raw ScvMap + mockServer.simulateTransaction.mockResolvedValue({ + status: 'SUCCESS', + result: { + retval: xdr.ScVal.scvMap([ + mapEntry('id', nativeToScVal(2n, { type: 'u64' })), + mapEntry('payer', xdr.ScVal.scvString(FAKE_PAYER)), + mapEntry('payee', xdr.ScVal.scvString('GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN')), + mapEntry('amount', nativeToScVal(1_000_000n, { type: 'i128' })), + mapEntry('interval', nativeToScVal(100, { type: 'u32' })), + mapEntry('active', xdr.ScVal.scvBool(true)), + mapEntry('paused', xdr.ScVal.scvBool(false)), + mapEntry('last_charged_ledger', nativeToScVal(0, { type: 'u32' })), + ]), + }, + }); + + const record = await client.recurring.getRecurring(2n); + expect(record!.paused).toBe(false); + }); +}); + // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- @@ -729,4 +788,4 @@ function makeRecurringRecord(overrides: Partial = {}): Recurrin lastChargedLedger: 0, ...overrides, }; -} +} \ No newline at end of file diff --git a/tests/splitter.test.ts b/tests/splitter.test.ts index 3640cce..9204fee 100644 --- a/tests/splitter.test.ts +++ b/tests/splitter.test.ts @@ -75,15 +75,16 @@ describe('SplitterModule.validateRecipients', () => { expect(result.errors).toEqual([]); }); - it('populates the errors array for each violation', () => { - // Duplicate address + non-positive share + wrong total → multiple errors. + it("errors array contains a message for each violation", () => { const result = client.splitter.validateRecipients([ - { address: ADDR_A, shareBps: 0 }, - { address: ADDR_A, shareBps: 5000 }, - { address: ADDR_B, shareBps: 4000 }, + { address: "GA1...", shareBps: 0 }, // zero BPS + { address: "GA2...", shareBps: 5000 }, // duplicate address + { address: "GA2...", shareBps: 5000 }, // duplicate address ]); expect(result.valid).toBe(false); - expect(result.errors.length).toBeGreaterThanOrEqual(3); + expect(result.errors.length).toBeGreaterThanOrEqual(2); + expect(result.errors.some(e => e.toLowerCase().includes("zero"))).toBe(true); + expect(result.errors.some(e => e.toLowerCase().includes("duplicate"))).toBe(true); }); }); @@ -234,4 +235,4 @@ describe('SplitterModule.getSplitterStats', () => { expect(typeof stats.cancelledCount).toBe('number'); expect(typeof stats.totalDistributedValue).toBe('bigint'); }); -}); +}); \ No newline at end of file