Skip to content

Commit d121e8f

Browse files
Add stake verification unit tests
1 parent 8ae6aef commit d121e8f

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { StakeVerificationService } from './stake-verification.service';
2+
import { ConfigService } from '@nestjs/config';
3+
4+
const makeService = () => {
5+
const cfg = { get: (k: string) => 'https://example.org' } as unknown as ConfigService;
6+
const cache = { get: jest.fn(), set: jest.fn(), del: jest.fn() } as any;
7+
const svc = new StakeVerificationService(cfg, cache);
8+
// patch private query method
9+
return { svc, cache };
10+
};
11+
12+
describe('StakeVerificationService', () => {
13+
it('verifies eligible provider', async () => {
14+
const { svc } = makeService();
15+
// @ts-ignore
16+
svc.queryStakeFromSoroban = jest.fn(async () => '2000');
17+
const res = await svc.verifyProviderStake({ publicKey: 'GABC' } as any);
18+
expect(res.verified).toBe(true);
19+
expect(res.stakeAmount).toBe('2000');
20+
});
21+
22+
it('rejects ineligible provider', async () => {
23+
const { svc } = makeService();
24+
// @ts-ignore
25+
svc.queryStakeFromSoroban = jest.fn(async () => '10');
26+
const res = await svc.verifyProviderStake({ publicKey: 'GXYZ' } as any);
27+
expect(res.verified).toBe(false);
28+
});
29+
});

0 commit comments

Comments
 (0)