-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for unclaimed-swaps (#585)
- Loading branch information
1 parent
3960479
commit 521ae47
Showing
2 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/router/src/grpc/view-protocol-server/unclaimed-swaps.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { ViewService } from '@buf/penumbra-zone_penumbra.connectrpc_es/penumbra/view/v1/view_connect'; | ||
import { servicesCtx } from '../../ctx'; | ||
|
||
import { createContextValues, createHandlerContext, HandlerContext } from '@connectrpc/connect'; | ||
|
||
import { beforeEach, describe, expect, test, vi } from 'vitest'; | ||
|
||
import { | ||
SwapRecord, | ||
UnclaimedSwapsRequest, | ||
UnclaimedSwapsResponse, | ||
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb'; | ||
import { IndexedDbMock, MockServices } from './test-utils'; | ||
import { Services } from '@penumbra-zone/services'; | ||
import { unclaimedSwaps } from './unclaimed-swaps'; | ||
|
||
describe('UnclaimedSwaps request handler', () => { | ||
let mockServices: MockServices; | ||
let mockCtx: HandlerContext; | ||
let mockIndexedDb: IndexedDbMock; | ||
let req: UnclaimedSwapsRequest; | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
|
||
const mockIterateSwaps = { | ||
next: vi.fn(), | ||
[Symbol.asyncIterator]: () => mockIterateSwaps, | ||
}; | ||
|
||
mockIndexedDb = { | ||
iterateSwaps: () => mockIterateSwaps, | ||
}; | ||
|
||
mockServices = { | ||
getWalletServices: vi.fn(() => Promise.resolve({ indexedDb: mockIndexedDb })), | ||
}; | ||
|
||
mockCtx = createHandlerContext({ | ||
service: ViewService, | ||
method: ViewService.methods.unclaimedSwaps, | ||
protocolName: 'mock', | ||
requestMethod: 'MOCK', | ||
contextValues: createContextValues().set(servicesCtx, mockServices as unknown as Services), | ||
}); | ||
|
||
for (const record of testData) { | ||
mockIterateSwaps.next.mockResolvedValueOnce({ | ||
value: record, | ||
}); | ||
} | ||
mockIterateSwaps.next.mockResolvedValueOnce({ | ||
done: true, | ||
}); | ||
req = new UnclaimedSwapsRequest(); | ||
}); | ||
|
||
test('should get all swaps with undefined heightClaimed', async () => { | ||
const responses: UnclaimedSwapsResponse[] = []; | ||
for await (const res of unclaimedSwaps(req, mockCtx)) { | ||
responses.push(new UnclaimedSwapsResponse(res)); | ||
} | ||
expect(responses.length).toBe(2); | ||
}); | ||
}); | ||
|
||
const testData: SwapRecord[] = [ | ||
SwapRecord.fromJson({ | ||
swapCommitment: { inner: '16VBVkrk+s18q+Sjhl8uEGfS3i0dwF1FrkNm8Db6VAA=' }, | ||
heightClaimed: 122, | ||
nullifier: { inner: '1E7LbhBDgDXHiRvreFyCllcKOOQeuIVsbn2aw8uKhww=' }, | ||
}), | ||
SwapRecord.fromJson({ | ||
swapCommitment: { inner: '26VBVkrk+s18q+Sjhl8uEGfS3i0dwF1FrkNm8Db6VAA=' }, | ||
nullifier: { inner: '2E7LbhBDgDXHiRvreFyCllcKOOQeuIVsbn2aw8uKhww=' }, | ||
}), | ||
SwapRecord.fromJson({ | ||
swapCommitment: { inner: '36VBVkrk+s18q+Sjhl8uEGfS3i0dwF1FrkNm8Db6VAA=' }, | ||
nullifier: { inner: '3E7LbhBDgDXHiRvreFyCllcKOOQeuIVsbn2aw8uKhww=' }, | ||
}), | ||
]; |