Skip to content

Commit

Permalink
add tests for wallet-id (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentine1898 authored Feb 22, 2024
1 parent ad3eab6 commit 3ac4b84
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/router/src/grpc/view-protocol-server/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ export interface MockServices {
shieldedPool?: ShieldedPoolMock;
};
}

export interface MockExtLocalCtx {
get: Mock;
}
48 changes: 48 additions & 0 deletions packages/router/src/grpc/view-protocol-server/wallet-id.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { beforeEach, describe, expect, test, vi } from 'vitest';
import {
WalletIdRequest,
WalletIdResponse,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { createContextValues, createHandlerContext, HandlerContext } from '@connectrpc/connect';
import { ViewService } from '@buf/penumbra-zone_penumbra.connectrpc_es/penumbra/view/v1/view_connect';
import { extLocalCtx } from '../../ctx';
import { walletId } from './wallet-id';
import { MockExtLocalCtx } from './test-utils';

describe('WalletId request handler', () => {
let mockExtLocalCtx: MockExtLocalCtx;
let mockCtx: HandlerContext;

beforeEach(() => {
vi.resetAllMocks();

mockExtLocalCtx = {
get: vi.fn().mockImplementation((key: string) => {
if (key === 'wallets') {
return Promise.resolve([{ id: 'mockWalletId' }]);
} else {
return Promise.resolve([]);
}
}),
};
mockCtx = createHandlerContext({
service: ViewService,
method: ViewService.methods.walletId,
protocolName: 'mock',
requestMethod: 'MOCK',
contextValues: createContextValues().set(extLocalCtx, mockExtLocalCtx as unknown),
});
});

test('should successfully get wallet-id if wallet exists', async () => {
const walletIdResponse = new WalletIdResponse(await walletId(new WalletIdRequest(), mockCtx));
expect(walletIdResponse).toBeDefined();
});

test('should fail to get wallet-id if wallet does not exist', async () => {
mockExtLocalCtx.get.mockImplementation(() => {
return Promise.resolve([]);
});
await expect(walletId(new WalletIdRequest(), mockCtx)).rejects.toThrow('No wallet');
});
});

0 comments on commit 3ac4b84

Please sign in to comment.