Skip to content

Commit a91d27c

Browse files
committed
fixup! clean proposal
1 parent f91292f commit a91d27c

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

packages/zoe/src/cleanProposal.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { assert, q, Fail } from '@endo/errors';
2+
import { assertRecord } from '@endo/marshal';
3+
import { assertKey, M, mustMatch, isKey } from '@endo/patterns';
24
import { AmountMath, getAssetKind } from '@agoric/ertp';
35
import { objectMap } from '@agoric/internal';
4-
import { assertRecord } from '@endo/marshal';
5-
import { assertKey, assertPattern, mustMatch, isKey } from '@agoric/store';
66
import { FullProposalShape } from './typeGuards.js';
77

88
const { ownKeys } = Reflect;
@@ -56,25 +56,26 @@ export const cleanKeywords = uncleanKeywordRecord => {
5656
return /** @type {string[]} */ (keywords);
5757
};
5858

59-
export const coerceAmountPatternKeywordRecord = (
60-
allegedAmountKeywordRecord,
59+
export const coerceAmountBoundKeywordRecord = (
60+
allegedAmountBoundKeywordRecord,
6161
getAssetKindByBrand,
6262
) => {
63-
cleanKeywords(allegedAmountKeywordRecord);
63+
cleanKeywords(allegedAmountBoundKeywordRecord);
6464
// FIXME objectMap should constrain the mapping function by the record's type
65-
return objectMap(allegedAmountKeywordRecord, amount => {
65+
return objectMap(allegedAmountBoundKeywordRecord, amount => {
66+
const { brand, value } = amount;
6667
// Check that each value can be coerced using the AmountMath
6768
// indicated by brand. `AmountMath.coerce` throws if coercion fails.
6869
if (isKey(amount)) {
69-
const brandAssetKind = getAssetKindByBrand(amount.brand);
70+
const brandAssetKind = getAssetKindByBrand(brand);
7071
const assetKind = getAssetKind(amount);
7172
// TODO: replace this assertion with a check of the assetKind
7273
// property on the brand, when that exists.
7374
assetKind === brandAssetKind ||
7475
Fail`The amount ${amount} did not have the assetKind of the brand ${brandAssetKind}`;
75-
return AmountMath.coerce(amount.brand, amount);
76+
return AmountMath.coerce(brand, amount);
7677
} else {
77-
assertPattern(amount);
78+
mustMatch(value, M.kind('match:containerHas'));
7879
return amount;
7980
}
8081
});
@@ -90,7 +91,7 @@ export const coerceAmountKeywordRecord = (
9091
allegedAmountKeywordRecord,
9192
getAssetKindByBrand,
9293
) => {
93-
const result = coerceAmountPatternKeywordRecord(
94+
const result = coerceAmountBoundKeywordRecord(
9495
allegedAmountKeywordRecord,
9596
getAssetKindByBrand,
9697
);
@@ -153,10 +154,7 @@ export const cleanProposal = (proposal, getAssetKindByBrand) => {
153154
ownKeys(rest).length === 0 ||
154155
Fail`${proposal} - Must only have want:, give:, exit: properties: ${rest}`;
155156

156-
const cleanedWant = coerceAmountPatternKeywordRecord(
157-
want,
158-
getAssetKindByBrand,
159-
);
157+
const cleanedWant = coerceAmountBoundKeywordRecord(want, getAssetKindByBrand);
160158
const cleanedGive = coerceAmountKeywordRecord(give, getAssetKindByBrand);
161159

162160
const cleanedProposal = harden({

packages/zoe/test/unitTests/cleanProposal.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ test('cleanProposal - want patterns', t => {
134134
t,
135135
{
136136
want: { Asset2: simoleans(1n) },
137-
give: { Price2: M.containerHas(M.any()) },
137+
give: { Price2: moola(M.containerHas(M.any())) },
138138
exit: { afterDeadline: { timer, deadline: 100n } },
139139
},
140140
'nat',
@@ -145,7 +145,7 @@ test('cleanProposal - want patterns', t => {
145145
t,
146146
{
147147
want: { Asset2: simoleans(1n) },
148-
give: { Price2: M.containerHas(M.any()) },
148+
give: { Price2: moola(M.containerHas(M.any())) },
149149
exit: { afterDeadline: { timer, deadline: M.any() } },
150150
},
151151
'nat',

0 commit comments

Comments
 (0)