Skip to content

Commit

Permalink
fix(purse): amountShape param
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed May 23, 2024
1 parent da1314a commit 0ce647f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/ERTP/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export const AmountShape = harden({
value: AmountValueShape,
});

/** For parameters that are themselves an AmountShape pattern. */
export const AmountShapeShape = harden({
brand: M.pattern(),
value: M.pattern(),
});

export const RatioShape = harden({
numerator: AmountShape,
denominator: AmountShape,
Expand Down
18 changes: 18 additions & 0 deletions packages/ERTP/test/unitTests/typeGuards.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from 'ava';

import { M, matches } from '@endo/patterns';
import { Far } from '@endo/far';
import { AmountShape, AmountShapeShape } from '../../src/typeGuards.js';

test('AmountShape', t => {
t.truthy(matches(harden({ brand: Far('brand'), value: 123n }), AmountShape));
});

test('AmountShapeShape', t => {
t.truthy(
matches(
harden({ brand: M.remotable('brand'), value: M.nat() }),
AmountShapeShape,
),
);
});
7 changes: 5 additions & 2 deletions packages/vats/src/virtual-purse.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isPromise } from '@endo/promise-kit';

import {
AmountShape,
AmountShapeShape,
BrandShape,
DepositFacetShape,
NotifierShape,
Expand Down Expand Up @@ -37,7 +38,7 @@ export const makeVirtualPurseKitIKit = (
// to this raw method to validate that this remotable is actually
// a live payment of the correct brand with sufficient funds.
deposit: M.callWhen(PaymentShape)
.optional(M.pattern())
.optional(AmountShapeShape)
.returns(amountShape),
getDepositFacet: M.callWhen().returns(DepositFacetShape),
withdraw: M.callWhen(amountShape).returns(PaymentShape),
Expand All @@ -50,7 +51,9 @@ export const makeVirtualPurseKitIKit = (
});

const RetainRedeemI = M.interface('RetainRedeem', {
retain: M.callWhen(PaymentShape).optional(amountShape).returns(amountShape),
retain: M.callWhen(PaymentShape)
.optional(AmountShapeShape)
.returns(amountShape),
redeem: M.callWhen(amountShape).returns(PaymentShape),
});

Expand Down

0 comments on commit 0ce647f

Please sign in to comment.