Skip to content

Commit

Permalink
feat: SingleAmountRecord -> SingleNatAmountRecord
Browse files Browse the repository at this point in the history
- narrows typeguard as only NatAmounts are supported in send-anywhere
  • Loading branch information
0xpatrickdev committed Sep 19, 2024
1 parent ea73ef7 commit f4b8c91
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/orchestration/src/examples/send-anywhere.contract.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { makeSharedStateRecord } from '@agoric/async-flow';
import { AmountShape } from '@agoric/ertp';
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
import { M } from '@endo/patterns';
import { withOrchestration } from '../utils/start-helper.js';
import * as flows from './send-anywhere.flows.js';
import { prepareChainHubAdmin } from '../exos/chain-hub-admin.js';
import { AnyNatAmountShape } from '../typeGuards.js';

/**
* @import {Zone} from '@agoric/zone';
* @import {OrchestrationPowers, OrchestrationTools} from '../utils/start-helper.js';
*/

export const SingleAmountRecord = M.and(
M.recordOf(M.string(), AmountShape, {
export const SingleNatAmountRecord = M.and(
M.recordOf(M.string(), AnyNatAmountShape, {
numPropertiesLimit: 1,
}),
M.not(harden({})),
);
harden(SingleAmountRecord);
harden(SingleNatAmountRecord);

/**
* Orchestration contract to be wrapped by withOrchestration for Zoe
Expand Down Expand Up @@ -61,7 +61,7 @@ const contract = async (
orchFns.sendIt,
'send',
undefined,
M.splitRecord({ give: SingleAmountRecord }),
M.splitRecord({ give: SingleNatAmountRecord }),
);
},
},
Expand Down
6 changes: 3 additions & 3 deletions packages/orchestration/test/examples/send-anywhere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SIMULATED_ERRORS } from '@agoric/vats/tools/fake-bridge.js';
import { withAmountUtils } from '@agoric/zoe/tools/test-utils.js';
import { CosmosChainInfo, IBCConnectionInfo } from '../../src/cosmos-api.js';
import { commonSetup } from '../supports.js';
import { SingleAmountRecord } from '../../src/examples/send-anywhere.contract.js';
import { SingleNatAmountRecord } from '../../src/examples/send-anywhere.contract.js';
import { registerChain } from '../../src/chain-info.js';

const dirname = path.dirname(new URL(import.meta.url).pathname);
Expand Down Expand Up @@ -48,10 +48,10 @@ test('single amount proposal shape (keyword record)', async t => {
],
});
for (const give of cases.good) {
t.notThrows(() => mustMatch(give, SingleAmountRecord));
t.notThrows(() => mustMatch(give, SingleNatAmountRecord));
}
for (const { give, msg } of cases.bad) {
t.throws(() => mustMatch(give, SingleAmountRecord), {
t.throws(() => mustMatch(give, SingleNatAmountRecord), {
message: msg,
});
}
Expand Down

0 comments on commit f4b8c91

Please sign in to comment.