Skip to content

Commit

Permalink
add tests for notes-for-voting (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentine1898 authored Feb 22, 2024
1 parent 521ae47 commit ad3eab6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
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=',
},
}),
];
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IndexedDbMock {
getGasPrices?: Mock;
getFmdParams?: Mock;
getLastBlockSynced?: Mock;
getNotesForVoting?: Mock;
getSpendableNoteByCommitment?: Mock;
getSpendableNoteByNullifier?: Mock;
getStateCommitmentTree?: Mock;
Expand Down

0 comments on commit ad3eab6

Please sign in to comment.