Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion tests/escrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -1441,4 +1459,4 @@ describe('EscrowModule.getEscrowedValueForDepositor', () => {
const total = await client.escrow.getEscrowedValueForDepositor(DEPOSITOR);
expect(total).toBe(0n);
});
});
});
61 changes: 60 additions & 1 deletion tests/recurring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -729,4 +788,4 @@ function makeRecurringRecord(overrides: Partial<RecurringRecord> = {}): Recurrin
lastChargedLedger: 0,
...overrides,
};
}
}
15 changes: 8 additions & 7 deletions tests/splitter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -234,4 +235,4 @@ describe('SplitterModule.getSplitterStats', () => {
expect(typeof stats.cancelledCount).toBe('number');
expect(typeof stats.totalDistributedValue).toBe('bigint');
});
});
});
Loading