Skip to content

Commit faed256

Browse files
committed
chore: clean up
1 parent b8c7735 commit faed256

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1151
-1128
lines changed

packages/ERTP/src/amountMath.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ const assertAssetKind = assetKind =>
146146
/** @type {AmountMath} */
147147
const AmountMath = {
148148
make: (brand, allegedValue) => {
149-
assertRemotable(brand);
149+
assertRemotable(brand, 'brand');
150150
const h = assertValueGetHelpers(allegedValue);
151+
// @ts-ignore Needs better typing to express Value to Helpers relationship
151152
const value = h.doCoerce(allegedValue);
152153
return harden({ brand, value });
153154
},
@@ -165,7 +166,7 @@ const AmountMath = {
165166
getValue: (brand, amount) => AmountMath.coerce(brand, amount).value,
166167
makeEmpty: (brand, assetKind = AssetKind.NAT) => {
167168
assertAssetKind(assetKind);
168-
assertRemotable(brand);
169+
assertRemotable(brand, 'brand');
169170
const value = helpers[assetKind].doMakeEmpty();
170171
return harden({ brand, value });
171172
},
@@ -204,5 +205,5 @@ const AmountMath = {
204205
};
205206
harden(AmountMath);
206207

207-
const getAssetKind = assertValueGetAssetKind;
208+
const getAssetKind = amount => assertValueGetAssetKind(amount.value);
208209
export { AmountMath, AssetKind, getAssetKind };

packages/ERTP/src/types.js

+3-38
Original file line numberDiff line numberDiff line change
@@ -51,51 +51,22 @@
5151
* @param {Value} allegedValue
5252
* @returns {Amount}
5353
*
54-
* TODO find out how to get this "deprecated" marking recognized,
55-
* or remove it.
56-
* @deprecated Use brand-first overload instead
57-
* @callback AmountMakeValueBrand
58-
* Please use the brand-first overload. The value-first overload
59-
* is deprecated and will go way.
60-
* @param {Value} brand
61-
* @param {Brand} allegedValue
62-
* @returns {Amount}
63-
*
64-
* @typedef {AmountMakeBrandValue & AmountMakeValueBrand} AmountMake
54+
* @typedef {AmountMakeBrandValue} AmountMake
6555
*
6656
* @callback AmountCoerceBrandAmount
6757
* @param {Brand} brand
6858
* @param {Amount} allegedAmount
6959
* @returns {Amount}
7060
*
71-
* TODO find out how to get this "deprecated" marking recognized,
72-
* or remove it.
73-
* @deprecated Use brand-first overload instead
74-
* @callback AmountCoerceAmountBrand
75-
* Please use the brand-first overload. The amount-first overload
76-
* is deprecated and will go way.
77-
* @param {Amount} brand
78-
* @param {Brand} allegedAmount
79-
* @returns {Amount}
80-
*
81-
* @typedef {AmountCoerceBrandAmount & AmountCoerceAmountBrand} AmountCoerce
61+
* @typedef {AmountCoerceBrandAmount} AmountCoerce
8262
*
8363
* @callback AmountGetValueBrandAmount
8464
* @param {Brand} brand
8565
* @param {Amount} allegedAmount
8666
* @returns {Value}
8767
*
88-
* TODO find out how to get this "deprecated" marking recognized,
89-
* or remove it.
90-
* @deprecated Use brand-first overload instead
91-
* @callback AmountGetValueAmountBrand
92-
* Please use the brand-first overload. The amount-first overload
93-
* is deprecated and will go way.
94-
* @param {Amount} brand
95-
* @param {Brand} allegedAmount
96-
* @returns {Value}
9768
*
98-
* @typedef {AmountGetValueBrandAmount & AmountGetValueAmountBrand} AmountGetValue
69+
* @typedef {AmountGetValueBrandAmount} AmountGetValue
9970
*/
10071

10172
/**
@@ -110,19 +81,13 @@
11081
*
11182
* @property {AmountMake} make
11283
* Make an amount from a value by adding the brand.
113-
* Please use the brand-first overload. The value-first overload
114-
* is deprecated and will go way.
11584
*
11685
* @property {AmountCoerce} coerce
11786
* Make sure this amount is valid enough, and return a corresponding
11887
* valid amount if so.
119-
* Please use the brand-first overload. The amount-first overload
120-
* is deprecated and will go way.
12188
*
12289
* @property {AmountGetValue} getValue
12390
* Extract and return the value.
124-
* Please use the brand-first overload. The amount-first overload
125-
* is deprecated and will go way.
12691
*
12792
* @property {MakeEmpty} makeEmpty
12893
* Return the amount representing an empty amount. This is the

packages/ERTP/test/unitTests/mathHelpers/test-natMathHelpers.js

+40-24
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ import { mockBrand } from './mockBrand.js';
1313
test('natMathHelpers make', t => {
1414
t.deepEqual(m.make(mockBrand, 4n), { brand: mockBrand, value: 4n });
1515
// @ts-ignore deliberate invalid arguments for testing
16-
t.deepEqual(m.make(mockBrand, 4), { brand: mockBrand, value: 4n });
16+
t.throws(() => m.make(mockBrand, 4), {
17+
message: 'value 4 must be a bigint or an array, not "number"',
18+
});
1719
t.throws(
1820
// @ts-ignore deliberate invalid arguments for testing
1921
() => m.make(mockBrand, 'abc'),
2022
{
21-
message: /value .* must be a Nat or an array/,
23+
message: 'value "abc" must be a bigint or an array, not "string"',
2224
},
2325
`'abc' is not a nat`,
2426
);
2527
t.throws(
2628
// @ts-ignore deliberate invalid arguments for testing
2729
() => m.make(mockBrand, -1),
28-
{ message: /value .* must be a Nat or an array/ },
30+
{ message: 'value -1 must be a bigint or an array, not "number"' },
2931
`- 1 is not a valid Nat`,
3032
);
3133
});
@@ -35,15 +37,15 @@ test('natMathHelpers make no brand', t => {
3537
// @ts-ignore deliberate invalid arguments for testing
3638
() => m.make(4n),
3739
{
38-
message: /The brand "\[4n\]" doesn't look like a brand./,
40+
message: '"brand" "[4n]" must be a remotable, not "bigint"',
3941
},
4042
`brand is required in make`,
4143
);
4244
});
4345

4446
test('natMathHelpers coerce', t => {
4547
t.deepEqual(
46-
m.coerce(mockBrand, { brand: mockBrand, value: 4n }),
48+
m.coerce(mockBrand, harden({ brand: mockBrand, value: 4n })),
4749
{
4850
brand: mockBrand,
4951
value: 4n,
@@ -52,14 +54,17 @@ test('natMathHelpers coerce', t => {
5254
);
5355
t.throws(
5456
() =>
55-
m.coerce(mockBrand, {
56-
brand: Far('otherBrand', {
57-
getAllegedName: () => 'somename',
58-
isMyIssuer: async () => false,
59-
getDisplayInfo: () => ({ assetKind: AssetKind.NAT }),
57+
m.coerce(
58+
mockBrand,
59+
harden({
60+
brand: Far('otherBrand', {
61+
getAllegedName: () => 'somename',
62+
isMyIssuer: async () => false,
63+
getDisplayInfo: () => ({ assetKind: AssetKind.NAT }),
64+
}),
65+
value: 4n,
6066
}),
61-
value: 4n,
62-
}),
67+
),
6368
{
6469
message: /The brand in the allegedAmount .* in 'coerce' didn't match the specified brand/,
6570
},
@@ -69,7 +74,7 @@ test('natMathHelpers coerce', t => {
6974
// @ts-ignore deliberate invalid arguments for testing
7075
() => m.coerce(3n, mockBrand),
7176
{
72-
message: /The amount .* doesn't look like an amount. Did you pass a value instead?/,
77+
message: '"brand" "[3n]" must be a remotable, not "bigint"',
7378
},
7479
`coerce needs a brand`,
7580
);
@@ -80,7 +85,7 @@ test('natMathHelpers coerce no brand', t => {
8085
// @ts-ignore deliberate invalid arguments for testing
8186
() => m.coerce(m.make(4n, mockBrand)),
8287
{
83-
message: /The brand {"brand":"\[Alleged: brand\]","value":"\[4n\]"} doesn't look like a brand./,
88+
message: '"brand" "[4n]" must be a remotable, not "bigint"',
8489
},
8590
`brand is required in coerce`,
8691
);
@@ -89,15 +94,17 @@ test('natMathHelpers coerce no brand', t => {
8994
test('natMathHelpers getValue', t => {
9095
t.is(m.getValue(mockBrand, m.make(mockBrand, 4n)), 4n);
9196
// @ts-ignore deliberate invalid arguments for testing
92-
t.is(m.getValue(mockBrand, m.make(mockBrand, 4)), 4n);
97+
t.throws(() => m.getValue(mockBrand, m.make(mockBrand, 4)), {
98+
message: 'value 4 must be a bigint or an array, not "number"',
99+
});
93100
});
94101

95102
test('natMathHelpers getValue no brand', t => {
96103
t.throws(
97104
// @ts-ignore deliberate invalid arguments for testing
98105
() => m.getValue(m.make(4n, mockBrand)),
99106
{
100-
message: /The brand {"brand":"\[Alleged: brand\]","value":"\[4n\]"} doesn't look like a brand./,
107+
message: '"brand" "[4n]" must be a remotable, not "bigint"',
101108
},
102109
`brand is required in getValue`,
103110
);
@@ -114,38 +121,44 @@ test('natMathHelpers makeEmpty no brand', t => {
114121
// @ts-ignore deliberate invalid arguments for testing
115122
() => m.makeEmpty(AssetKind.NAT),
116123
{
117-
message: /The brand .* doesn't look like a brand./,
124+
message: '"brand" "nat" must be a remotable, not "string"',
118125
},
119126
`make empty no brand`,
120127
);
121128
});
122129

123130
test('natMathHelpers isEmpty', t => {
124-
t.assert(m.isEmpty({ brand: mockBrand, value: 0n }), `isEmpty(0) is true`);
125-
t.falsy(m.isEmpty({ brand: mockBrand, value: 6n }), `isEmpty(6) is false`);
131+
t.assert(
132+
m.isEmpty(harden({ brand: mockBrand, value: 0n })),
133+
`isEmpty(0) is true`,
134+
);
135+
t.falsy(
136+
m.isEmpty(harden({ brand: mockBrand, value: 6n })),
137+
`isEmpty(6) is false`,
138+
);
126139
t.assert(m.isEmpty(m.make(mockBrand, 0n)), `isEmpty(0) is true`);
127140
t.falsy(m.isEmpty(m.make(mockBrand, 6n)), `isEmpty(6) is false`);
128141
t.throws(
129142
// @ts-ignore deliberate invalid arguments for testing
130143
() => m.isEmpty('abc'),
131144
{
132-
message: /The amount .* doesn't look like an amount. Did you pass a value instead?/,
145+
message: '"amount" "abc" must be a pass-by-copy record, not "string"',
133146
},
134147
`isEmpty('abc') throws because it cannot be coerced`,
135148
);
136149
t.throws(
137150
// @ts-ignore deliberate invalid arguments for testing
138-
() => m.isEmpty({ brand: mockBrand, value: 'abc' }),
151+
() => m.isEmpty(harden({ brand: mockBrand, value: 'abc' })),
139152
{
140-
message: /value .* must be a Nat or an array/,
153+
message: 'value "abc" must be a bigint or an array, not "string"',
141154
},
142155
`isEmpty('abc') throws because it cannot be coerced`,
143156
);
144157
t.throws(
145158
// @ts-ignore deliberate invalid arguments for testing
146159
() => m.isEmpty(0n),
147160
{
148-
message: /The amount .* doesn't look like an amount. Did you pass a value instead?/,
161+
message: '"amount" "[0n]" must be a pass-by-copy record, not "bigint"',
149162
},
150163
`isEmpty(0) throws because it cannot be coerced`,
151164
);
@@ -155,7 +168,10 @@ test('natMathHelpers isGTE', t => {
155168
t.assert(m.isGTE(m.make(mockBrand, 5n), m.make(mockBrand, 3n)), `5 >= 3`);
156169
t.assert(m.isGTE(m.make(mockBrand, 3n), m.make(mockBrand, 3n)), `3 >= 3`);
157170
t.falsy(
158-
m.isGTE({ brand: mockBrand, value: 3n }, { brand: mockBrand, value: 4n }),
171+
m.isGTE(
172+
harden({ brand: mockBrand, value: 3n }),
173+
harden({ brand: mockBrand, value: 4n }),
174+
),
159175
`3 < 4`,
160176
);
161177
});

0 commit comments

Comments
 (0)