Skip to content

Commit

Permalink
check for source in transaction planner request (#1499)
Browse files Browse the repository at this point in the history
* assert validity of source in transaction request

* pass tests
  • Loading branch information
TalDerei authored Jul 17, 2024
1 parent c3184f9 commit 35ed14c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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);
};

0 comments on commit 35ed14c

Please sign in to comment.