Skip to content

Commit 0f10e95

Browse files
committed
Achieve 100% test coverage across all modules
1 parent 7e0a6c9 commit 0f10e95

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

tests/lib/mock.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ describe('mock', () => {
6767
});
6868

6969
it('should return smart money labels for SM addresses', () => {
70-
const result = getMockData('profiler labels', ['--address', MOCK_WALLETS.smartMoney1]) as any[];
71-
expect(result).toBeInstanceOf(Array);
72-
expect(result[0].label).toBe('Smart Money');
73-
expect(result[0].category).toBe('Smart Money');
70+
const result1 = getMockData('profiler labels', ['--address', MOCK_WALLETS.smartMoney1]) as any[];
71+
expect(result1).toBeInstanceOf(Array);
72+
expect(result1[0].label).toBe('Smart Money');
73+
74+
const result2 = getMockData('profiler labels', ['--address', MOCK_WALLETS.smartMoney2]) as any[];
75+
expect(result2).toBeInstanceOf(Array);
76+
expect(result2[0].label).toBe('Smart Money');
7477
});
7578

7679
it('should return exchange labels for labeled addresses', () => {
@@ -180,6 +183,12 @@ describe('mock', () => {
180183
expect(result).toBeNull();
181184
});
182185

186+
it('should handle missing arg values gracefully for profiler labels', () => {
187+
const result = getMockData('profiler labels', []) as any[];
188+
expect(result).toBeInstanceOf(Array);
189+
expect(result.length).toBe(0);
190+
});
191+
183192
it('should handle missing arg values gracefully', () => {
184193
const result = getMockData('profiler trace', []) as any;
185194
expect(result).toBeDefined();

tests/lib/nansen.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ describe('nansen', () => {
7878
const r = await execNansen('cmd', []); expect(r.error).toBe('rate limit'); expect(r.code).toBe('RL');
7979
});
8080

81+
it('handles JSON error in stderr with no error field', async () => {
82+
mockMode = false;
83+
mockExecFile.mockImplementation((_c: any, _a: any, _o: any, cb: any) => cb(new Error('fallback msg'), '', '{"code":"NO_ERR_FIELD"}'));
84+
const r = await execNansen('cmd', []);
85+
expect(r.error).toBe('fallback msg');
86+
expect(r.code).toBe('NO_ERR_FIELD');
87+
});
88+
8189
it('handles plain error text', async () => {
8290
mockMode = false;
8391
mockExecFile.mockImplementation((_c: any, _a: any, _o: any, cb: any) => cb(new Error('e'), '', 'plain error'));

tests/lib/telemetry.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,21 @@ describe('telemetry', () => {
167167
recordCall(makeEntry({ endpoint: 'profiler trace', status: '200', cache: 'MISS', latency_ms: 200 }));
168168
recordCall(makeEntry({ endpoint: 'profiler labels', status: 'SUCCESS', cache: 'HIT', latency_ms: 5 }));
169169
recordCall(makeEntry({ endpoint: 'long-endpoint-name-that-exceeds-forty-characters-limit', status: 'ERROR', latency_ms: 600 }));
170+
recordCall(makeEntry({ endpoint: 'unknown-status', status: 'UNKNOWN_STATUS', cache: 'N/A', latency_ms: 10 }));
170171

171172
const spy = vi.spyOn(console, 'log').mockImplementation(() => {});
172173
printTelemetryReceipt();
173174
expect(spy).toHaveBeenCalled();
174175
spy.mockRestore();
175176
});
177+
178+
it('should print receipt with zero error count', () => {
179+
recordCall(makeEntry({ endpoint: 'profiler trace', status: '200', cache: 'MISS', latency_ms: 200 }));
180+
const spy = vi.spyOn(console, 'log').mockImplementation(() => {});
181+
printTelemetryReceipt();
182+
expect(spy).toHaveBeenCalled();
183+
spy.mockRestore();
184+
});
176185
});
177186

178187
describe('aliases', () => {

tests/lib/terminal-report.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ function createMockGraph(): GraphData {
1515
return {
1616
nodes: [
1717
{ id: '0xseed', label: '0xseed...dead', type: 'seed', balance_usd: 1000000, pnl_30d: 50000, labels: [], sm_labels: [], depth: 0, defi_protocols: 2 },
18-
{ id: '0xfund', label: 'Fund Alpha', type: 'smart-money', balance_usd: 5000000, pnl_30d: 200000, labels: ['Fund'], sm_labels: ['Smart Money'], depth: 1, defi_protocols: 5 },
18+
{ id: '0xfund', label: 'Fund Alpha', type: 'smart-money', balance_usd: 5000000, pnl_30d: 200000, labels: ['Fund'], sm_labels: [], depth: 1, defi_protocols: 5 },
1919
{ id: '0xlabel', label: 'Binance', type: 'labeled', balance_usd: 250000, pnl_30d: -10000, labels: ['Binance'], sm_labels: [], depth: 1, defi_protocols: 0 },
2020
// Use empty label to trigger `truncate` coverage
2121
{ id: '0xunknown_long_address', label: '', type: 'unknown', balance_usd: 500, pnl_30d: 0, labels: [], sm_labels: [], depth: 2, defi_protocols: 0 },
2222
{ id: '0xshort', label: '', type: 'unknown', balance_usd: 100, pnl_30d: 0, labels: [], sm_labels: [], depth: 2, defi_protocols: 0 },
23-
{ id: '0xcontract', label: 'Uniswap Router', type: 'contract', balance_usd: 0, pnl_30d: 0, labels: ['Contract'], sm_labels: [], depth: 1, defi_protocols: 0 },
23+
{ id: '0xcontract', label: 'Uniswap Router', type: 'contract', balance_usd: 100000, pnl_30d: 0, labels: ['Contract'], sm_labels: [], depth: 1, defi_protocols: 0 },
2424
],
2525
links: [
2626
{ source: '0xseed', target: '0xfund', volume_usd: 500000, tx_count: 20, direction: 'outflow' },

0 commit comments

Comments
 (0)