-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient-debug.test.ts
More file actions
59 lines (52 loc) · 1.75 KB
/
Copy pathclient-debug.test.ts
File metadata and controls
59 lines (52 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { Keypair, nativeToScVal } from '@stellar/stellar-sdk';
describe('ILNSdk debug logging', () => {
const originalEnv = process.env.ILN_DEBUG;
const originalConsoleLog = console.log;
beforeEach(() => {
vi.resetModules();
process.env.ILN_DEBUG = '1';
// The logger routes DEBUG-level entries through console.log (see logger.ts).
globalThis.console.log = vi.fn();
});
afterEach(() => {
process.env.ILN_DEBUG = originalEnv;
globalThis.console.log = originalConsoleLog;
});
it('emits debug logs when ILN_DEBUG=1', async () => {
const { ILNSdk } = await import('./client');
const server = {
getAccount: vi.fn(),
prepareTransaction: vi.fn(),
sendTransaction: vi.fn(),
pollTransaction: vi.fn(),
simulateTransaction: vi.fn().mockResolvedValue({
result: {
retval: nativeToScVal({
amount: 25000000n,
amount_funded: 25000000n,
amount_paid: 0n,
discount_rate: 300,
due_date: 1700000000,
funder: Keypair.random().publicKey(),
funded_at: 1699999000,
freelancer: Keypair.random().publicKey(),
id: 7n,
payer: Keypair.random().publicKey(),
status: 'Funded',
submitter_reputation: 0,
token: Keypair.random().publicKey(),
}),
},
}),
};
const sdk = new ILNSdk({
contractId: 'CD3TE3IAHM737P236XZL2OYU275ZKD6MN7YH7PYYAXYIGEH55OPEWYJC',
networkPassphrase: 'Test SDF Network ; September 2015',
rpcUrl: 'https://example.test',
server,
});
await sdk.getInvoice(7n);
expect(console.log).toHaveBeenCalled();
});
});