-
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 notes-for-voting (#589)
- Loading branch information
1 parent
521ae47
commit ad3eab6
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
packages/router/src/grpc/view-protocol-server/notes-for-voting.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,71 @@ | ||
import { beforeEach, describe, expect, test, vi } from 'vitest'; | ||
import { | ||
NotesForVotingRequest, | ||
NotesForVotingResponse, | ||
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb'; | ||
import { ServicesInterface } from '@penumbra-zone/types'; | ||
import { createContextValues, createHandlerContext, HandlerContext } from '@connectrpc/connect'; | ||
import { ViewService } from '@buf/penumbra-zone_penumbra.connectrpc_es/penumbra/view/v1/view_connect'; | ||
import { servicesCtx } from '../../ctx'; | ||
import { IndexedDbMock, MockServices } from './test-utils'; | ||
import { notesForVoting } from './notes-for-voting'; | ||
|
||
describe('NotesForVoting request handler', () => { | ||
let mockServices: MockServices; | ||
let mockIndexedDb: IndexedDbMock; | ||
let mockCtx: HandlerContext; | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
|
||
mockIndexedDb = { | ||
getNotesForVoting: vi.fn(), | ||
}; | ||
mockServices = { | ||
getWalletServices: vi.fn(() => Promise.resolve({ indexedDb: mockIndexedDb })), | ||
}; | ||
mockCtx = createHandlerContext({ | ||
service: ViewService, | ||
method: ViewService.methods.notesForVoting, | ||
protocolName: 'mock', | ||
requestMethod: 'MOCK', | ||
contextValues: createContextValues().set( | ||
servicesCtx, | ||
mockServices as unknown as ServicesInterface, | ||
), | ||
}); | ||
}); | ||
|
||
test('should successfully get notes for voting', async () => { | ||
mockIndexedDb.getNotesForVoting?.mockResolvedValueOnce(testData); | ||
const responses: NotesForVotingResponse[] = []; | ||
const req = new NotesForVotingRequest({}); | ||
for await (const res of notesForVoting(req, mockCtx)) { | ||
responses.push(new NotesForVotingResponse(res)); | ||
} | ||
expect(responses.length).toBe(2); | ||
}); | ||
}); | ||
|
||
const testData: NotesForVotingResponse[] = [ | ||
NotesForVotingResponse.fromJson({ | ||
noteRecord: { | ||
noteCommitment: { | ||
inner: 'pXS1k2kvlph+vuk9uhqeoP1mZRc+f526a06/bg3EBwQ=', | ||
}, | ||
}, | ||
identityKey: { | ||
ik: 'VAv+z5ieJk7AcAIJoVIqB6boOj0AhZB2FKWsEidfvAE=', | ||
}, | ||
}), | ||
NotesForVotingResponse.fromJson({ | ||
noteRecord: { | ||
noteCommitment: { | ||
inner: '2XS1k2kvlph+vuk9uhqeoP1mZRc+f526a06/bg3EBwQ=', | ||
}, | ||
}, | ||
identityKey: { | ||
ik: 'pkxdxOn9EMqdjoCJdEGBKA8XY9P9RK9XmurIly/9yBA=', | ||
}, | ||
}), | ||
]; |
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