Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for source in transaction planner request #1499

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TransactionPlannerRequest } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb.js';
import { Code, ConnectError } from '@connectrpc/connect';

export const assertTransactionSource = (transactionPlannerRequest: TransactionPlannerRequest) => {
// Ensure that a source is provided in the transaction request.
if (!transactionPlannerRequest.source) {
throw new ConnectError(
'Source is required in the TransactionPlannerRequest',
Code.InvalidArgument,
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
AssetId,
Value,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb.js';
import { AddressIndex } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb.js';

const mockPlanTransaction = vi.hoisted(() => vi.fn());
vi.mock('@penumbra-zone/wasm/planner', () => ({
Expand Down Expand Up @@ -60,7 +61,9 @@ describe('TransactionPlanner request handler', () => {
.set(fvkCtx, () => Promise.resolve(testFullViewingKey)),
});

req = new TransactionPlannerRequest({});
req = new TransactionPlannerRequest({
source: new AddressIndex({ account: 0 }),
});
});

test('should throw if request is not valid', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { assertSwapAssetsAreNotTheSame } from './assert-swap-assets-are-not-the-
import { TransactionPlannerRequest } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb.js';
import { fvkCtx } from '../../ctx/full-viewing-key.js';
import { extractAltFee } from '../fees.js';
import { assertTransactionSource } from './assert-transaction-source.js';

export const transactionPlanner: Impl['transactionPlanner'] = async (req, ctx) => {
assertValidRequest(req);
Expand Down Expand Up @@ -66,4 +67,5 @@ export const transactionPlanner: Impl['transactionPlanner'] = async (req, ctx) =
*/
const assertValidRequest = (req: TransactionPlannerRequest): void => {
assertSwapAssetsAreNotTheSame(req);
assertTransactionSource(req);
};
Loading