Skip to content

Commit

Permalink
fix: error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Nov 24, 2022
1 parent 5fedea2 commit cd1cca9
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 69 deletions.
19 changes: 8 additions & 11 deletions packages/ERTP/test/unitTests/test-inputValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('makeIssuerKit bad displayInfo.decimalPlaces', async t => {
),
{
message:
'displayInfo: optional-parts: decimalPlaces: "hello" - Must be >= -100',
'displayInfo: optional: decimalPlaces: "hello" - Must be >= -100',
},
);

Expand Down Expand Up @@ -61,17 +61,15 @@ test('makeIssuerKit bad displayInfo.decimalPlaces', async t => {
() =>
makeIssuerKit('myTokens', AssetKind.NAT, harden({ decimalPlaces: 101 })),
{
message:
'displayInfo: optional-parts: decimalPlaces: 101 - Must be <= 100',
message: 'displayInfo: optional: decimalPlaces: 101 - Must be <= 100',
},
);

t.throws(
() =>
makeIssuerKit('myTokens', AssetKind.NAT, harden({ decimalPlaces: -101 })),
{
message:
'displayInfo: optional-parts: decimalPlaces: -101 - Must be >= -100',
message: 'displayInfo: optional: decimalPlaces: -101 - Must be >= -100',
},
);
});
Expand All @@ -89,7 +87,7 @@ test('makeIssuerKit bad displayInfo.assetKind', async t => {
),
{
message:
'displayInfo: optional-parts: assetKind: "something" - Must match one of ["nat","set","copySet","copyBag"]',
'displayInfo: optional: assetKind: "something" - Must match one of ["nat","set","copySet","copyBag"]',
},
);
});
Expand All @@ -106,8 +104,7 @@ test('makeIssuerKit bad displayInfo.whatever', async t => {
}),
),
{
message:
'displayInfo: rest-parts: {"whatever":"something"} - Must be: {}',
message: 'displayInfo: rest: {"whatever":"something"} - Must be: {}',
},
);
});
Expand Down Expand Up @@ -144,7 +141,7 @@ test('brand.isMyIssuer bad issuer', async t => {
// @ts-expect-error Intentional wrong type for testing
t.throwsAsync(() => brand.isMyIssuer('not an issuer'), {
message:
'In "isMyIssuer" method of (myTokens brand) arg 0: string "not an issuer" - Must be a remotable (Issuer)',
'In "isMyIssuer" method of (myTokens brand): args: [0]: string "not an issuer" - Must be a remotable (Issuer)',
});
const fakeIssuer = /** @type {Issuer} */ (
/** @type {unknown} */ (Far('myTokens issuer', {}))
Expand Down Expand Up @@ -187,7 +184,7 @@ test('issuer.combine bad payments array', async t => {
// @ts-expect-error Intentional wrong type for testing
await t.throwsAsync(() => E(issuer).combine(notAnArray), {
message:
'In "combine" method of (fungible issuer) arg 0: cannot serialize Remotables with non-methods like "length" in {"length":2,"split":"[Function split]"}',
'In "combine" method of (fungible issuer): cannot serialize Remotables with non-methods like "length" in {"length":2,"split":"[Function split]"}',
});

const notAnArray2 = Far('notAnArray2', {
Expand All @@ -197,7 +194,7 @@ test('issuer.combine bad payments array', async t => {
// @ts-expect-error Intentional wrong type for testing
await t.throwsAsync(() => E(issuer).combine(notAnArray2), {
message:
'In "combine" method of (fungible issuer) arg 0: remotable "[Alleged: notAnArray2]" - Must be a copyArray',
'In "combine" method of (fungible issuer): args: [0]: remotable "[Alleged: notAnArray2]" - Must be a copyArray',
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/ERTP/test/unitTests/test-issuerObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('bad display info', t => {
const displayInfo = harden({ somethingUnexpected: 3 });
// @ts-expect-error deliberate invalid arguments for testing
t.throws(() => makeIssuerKit('fungible', AssetKind.NAT, displayInfo), {
message: 'displayInfo: rest-parts: {"somethingUnexpected":3} - Must be: {}',
message: 'displayInfo: rest: {"somethingUnexpected":3} - Must be: {}',
});
});

Expand Down Expand Up @@ -199,7 +199,7 @@ test('purse.deposit promise', async t => {
() => E(purse).deposit(exclusivePaymentP, fungible25),
{
message:
'In "deposit" method of (fungible Purse purse) arg 0: promise "[Promise]" - Must be a remotable (Payment)',
'In "deposit" method of (fungible Purse purse): args: [0]: promise "[Promise]" - Must be a remotable (Payment)',
},
'failed to reject a promise for a payment',
);
Expand Down Expand Up @@ -334,7 +334,7 @@ test('issuer.split bad amount', async t => {
_ => E(issuer).split(payment, AmountMath.make(otherBrand, 10n)),
{
message:
'In "split" method of (fungible issuer) arg 1: brand: "[Alleged: other fungible brand]" - Must be: "[Alleged: fungible brand]"',
'In "split" method of (fungible issuer): args: [1]: brand: "[Alleged: other fungible brand]" - Must be: "[Alleged: fungible brand]"',
},
'throws for bad amount',
);
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/test/unitTests/test-mintObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test('mint.mintPayment set w strings AssetKind', async t => {
const badAmount = AmountMath.make(brand, harden([['badElement']]));
t.throws(() => mint.mintPayment(badAmount), {
message:
'In "mintPayment" method of (items mint) arg 0: value: [0]: copyArray ["badElement"] - Must be a string',
'In "mintPayment" method of (items mint): args: [0]: value: [0]: copyArray ["badElement"] - Must be a string',
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/governance/test/unitTests/test-paramGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ test('multiple params bad change', async t => {
),
{
message:
'In "getAmountOf" method of (Zoe Invitation issuer) arg 0: bigint "[13n]" - Must be a remotable (Payment)',
'In "getAmountOf" method of (Zoe Invitation issuer): args: [0]: bigint "[13n]" - Must be a remotable (Payment)',
},
);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/inter-protocol/test/psm/test-psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ test('wrong give giveMintedInvitation', async t => {
),
{
message:
'"giveMinted" proposal: required-parts: give: In: brand: "[Alleged: aUSD brand]" - Must be: "[Alleged: IST brand]"',
'"giveMinted" proposal: give: In: brand: "[Alleged: aUSD brand]" - Must be: "[Alleged: IST brand]"',
},
);
});
Expand Down Expand Up @@ -652,7 +652,7 @@ test('wrong give wantMintedInvitation', async t => {
),
{
message:
'"wantMinted" proposal: required-parts: give: In: brand: "[Alleged: IST brand]" - Must be: "[Alleged: aUSD brand]"',
'"wantMinted" proposal: give: In: brand: "[Alleged: IST brand]" - Must be: "[Alleged: aUSD brand]"',
},
);
});
Expand All @@ -674,7 +674,7 @@ test('extra give wantMintedInvitation', async t => {
),
{
message:
'"wantMinted" proposal: required-parts: give: {"Extra":{"brand":"[Alleged: aUSD brand]","value":"[200000000n]"},"In":{"brand":"[Seen]","value":"[200000000n]"}} - Must not have unexpected properties: ["Extra"]',
'"wantMinted" proposal: give: {"Extra":{"brand":"[Alleged: aUSD brand]","value":"[200000000n]"},"In":{"brand":"[Seen]","value":"[200000000n]"}} - Must not have unexpected properties: ["Extra"]',
},
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@ test('addVaultType: extra, unexpected params', async t => {
E(vaultFactory).addVaultType(chit.issuer, 'Chit', missingParams),
{
message:
/initialParamValues: required-parts: .* - Must have missing properties \["interestRate"\]/,
/initialParamValues: .* - Must have missing properties \["interestRate"\]/,
},
);

Expand Down
15 changes: 6 additions & 9 deletions packages/store/test/test-heap-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ test('test defineHeapFarClass', t => {
t.is(upCounter.incr(5), 8);
t.is(upCounter.incr(1), 9);
t.throws(() => upCounter.incr(-3), {
message:
'In "incr" method of (UpCounter): optional args: [0]: -3 - Must be >= 0',
message: 'In "incr" method of (UpCounter) arg 0: -3 - Must be >= 0',
});
// @ts-expect-error bad arg
t.throws(() => upCounter.incr('foo'), {
message:
'In "incr" method of (UpCounter): optional args: [0]: string "foo" - Must be a number',
'In "incr" method of (UpCounter) arg 0: string "foo" - Must be a number',
});
});

Expand Down Expand Up @@ -76,13 +75,12 @@ test('test defineHeapFarClassKit', t => {
t.is(downCounter.decr(), 7);
t.is(upCounter.incr(3), 10);
t.throws(() => upCounter.incr(-3), {
message:
'In "incr" method of (Counter up): optional args: [0]: -3 - Must be >= 0',
message: 'In "incr" method of (Counter up) arg 0: -3 - Must be >= 0',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => downCounter.decr('foo'), {
message:
'In "decr" method of (Counter down): optional args: [0]: string "foo" - Must be a number',
'In "decr" method of (Counter down) arg 0: string "foo" - Must be a number',
});
// @ts-expect-error bad arg
t.throws(() => upCounter.decr(3), {
Expand All @@ -101,12 +99,11 @@ test('test makeHeapFarInstance', t => {
t.is(upCounter.incr(5), 8);
t.is(upCounter.incr(1), 9);
t.throws(() => upCounter.incr(-3), {
message:
'In "incr" method of (upCounter): optional args: [0]: -3 - Must be >= 0',
message: 'In "incr" method of (upCounter) arg 0: -3 - Must be >= 0',
});
t.throws(() => upCounter.incr('foo'), {
message:
'In "incr" method of (upCounter): optional args: [0]: string "foo" - Must be a number',
'In "incr" method of (upCounter) arg 0: string "foo" - Must be a number',
});
});

Expand Down
24 changes: 9 additions & 15 deletions packages/store/test/test-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ const runTests = (successCase, failCase) => {
failCase(
specimen,
M.split([3, 4, 5, 6]),
'args: [3,4] - Must be: [3,4,5,6]',
'required-parts: [3,4] - Must be: [3,4,5,6]',
);
failCase(specimen, M.split([5]), 'args: [3] - Must be: [5]');
failCase(specimen, M.split([5]), 'required-parts: [3] - Must be: [5]');
failCase(specimen, M.split({}), 'copyArray [3,4] - Must be a copyRecord');
failCase(specimen, M.split([3], 'x'), 'rest args: [4] - Must be: "x"');
failCase(specimen, M.split([3], 'x'), 'rest-parts: [4] - Must be: "x"');

failCase(specimen, M.partial([5]), 'optional args: [0]: 3 - Must be: 5');
failCase(specimen, M.partial([5]), 'optional-parts: [3] - Must be: [5]');

failCase(
specimen,
Expand Down Expand Up @@ -194,19 +194,13 @@ const runTests = (successCase, failCase) => {
'{"foo":3,"bar":4} - Must be >= {"baz":3}',
);

failCase(
specimen,
M.splitRecord({ foo: M.number() }, { bar: M.string(), baz: M.number() }),
'optional: bar: number 4 - Must be a string',
);

failCase(
specimen,
M.split(
{ foo: M.number() },
M.and(M.partial({ bar: M.string() }), M.partial({ baz: M.number() })),
),
'rest: optional: bar: number 4 - Must be a string',
'rest-parts: optional-parts: bar: number 4 - Must be a string',
);

failCase(
Expand All @@ -217,22 +211,22 @@ const runTests = (successCase, failCase) => {
failCase(
specimen,
M.split({ foo: 3, z: 4 }),
'{"foo":3} - Must be: {"foo":3,"z":4}',
'required-parts: {"foo":3} - Must be: {"foo":3,"z":4}',
);
failCase(
specimen,
M.split({ foo: 3 }, { foo: 3, bar: 4 }),
'rest: {"bar":4} - Must be: {"foo":3,"bar":4}',
'rest-parts: {"bar":4} - Must be: {"foo":3,"bar":4}',
);
failCase(
specimen,
M.split({ foo: 3 }, { foo: M.any(), bar: 4 }),
'rest: {"bar":4} - Must have missing properties ["foo"]',
'rest-parts: {"bar":4} - Must have missing properties ["foo"]',
);
failCase(
specimen,
M.partial({ foo: 7, zip: 5 }, { bar: 4 }),
'optional: foo: 3 - Must be: 7',
'optional-parts: {"foo":3} - Must be: {"foo":7}',
);

failCase(
Expand Down
10 changes: 6 additions & 4 deletions packages/vat-data/test/test-durable-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ test('test defineDurableFarClass', t => {
t.is(upCounter.incr(5), 8);
t.is(upCounter.incr(1), 9);
t.throws(() => upCounter.incr(-3), {
message: 'In "incr" method of (UpCounter) arg 0: -3 - Must be >= 0',
message:
'In "incr" method of (UpCounter): optional args: [0]: -3 - Must be >= 0',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => upCounter.incr('foo'), {
message:
'In "incr" method of (UpCounter) arg 0: string "foo" - Must be a number',
'In "incr" method of (UpCounter): optional args: [0]: string "foo" - Must be a number',
});
});

Expand Down Expand Up @@ -80,12 +81,13 @@ test('test defineDurableFarClassKit', t => {
t.is(downCounter.decr(), 7);
t.is(upCounter.incr(3), 10);
t.throws(() => upCounter.incr(-3), {
message: 'In "incr" method of (Counter up) arg 0: -3 - Must be >= 0',
message:
'In "incr" method of (Counter up): optional args: [0]: -3 - Must be >= 0',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => downCounter.decr('foo'), {
message:
'In "decr" method of (Counter down) arg 0: string "foo" - Must be a number',
'In "decr" method of (Counter down): optional args: [0]: string "foo" - Must be a number',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => upCounter.decr(3), {
Expand Down
10 changes: 6 additions & 4 deletions packages/vat-data/test/test-virtual-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ test('test defineVirtualFarClass', t => {
t.is(upCounter.incr(5), 8);
t.is(upCounter.incr(1), 9);
t.throws(() => upCounter.incr(-3), {
message: 'In "incr" method of (UpCounter) arg 0: -3 - Must be >= 0',
message:
'In "incr" method of (UpCounter): optional args: [0]: -3 - Must be >= 0',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => upCounter.incr('foo'), {
message:
'In "incr" method of (UpCounter) arg 0: string "foo" - Must be a number',
'In "incr" method of (UpCounter): optional args: [0]: string "foo" - Must be a number',
});
});

Expand Down Expand Up @@ -75,12 +76,13 @@ test('test defineVirtualFarClassKit', t => {
t.is(downCounter.decr(), 7);
t.is(upCounter.incr(3), 10);
t.throws(() => upCounter.incr(-3), {
message: 'In "incr" method of (Counter up) arg 0: -3 - Must be >= 0',
message:
'In "incr" method of (Counter up): optional args: [0]: -3 - Must be >= 0',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => downCounter.decr('foo'), {
message:
'In "decr" method of (Counter down) arg 0: string "foo" - Must be a number',
'In "decr" method of (Counter down): optional args: [0]: string "foo" - Must be a number',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => upCounter.decr(3), {
Expand Down
15 changes: 9 additions & 6 deletions packages/vat-data/test/test-vivify.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ test('test vivifyFarClass', t => {
t.is(upCounter.incr(5), 8);
t.is(upCounter.incr(1), 9);
t.throws(() => upCounter.incr(-3), {
message: 'In "incr" method of (UpCounter) arg 0: -3 - Must be >= 0',
message:
'In "incr" method of (UpCounter): optional args: [0]: -3 - Must be >= 0',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => upCounter.incr('foo'), {
message:
'In "incr" method of (UpCounter) arg 0: string "foo" - Must be a number',
'In "incr" method of (UpCounter): optional args: [0]: string "foo" - Must be a number',
});
});

Expand Down Expand Up @@ -82,12 +83,13 @@ test('test vivifyFarClassKit', t => {
t.is(downCounter.decr(), 7);
t.is(upCounter.incr(3), 10);
t.throws(() => upCounter.incr(-3), {
message: 'In "incr" method of (Counter up) arg 0: -3 - Must be >= 0',
message:
'In "incr" method of (Counter up): optional args: [0]: -3 - Must be >= 0',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => downCounter.decr('foo'), {
message:
'In "decr" method of (Counter down) arg 0: string "foo" - Must be a number',
'In "decr" method of (Counter down): optional args: [0]: string "foo" - Must be a number',
});
// @ts-expect-error the type violation is what we're testing
t.throws(() => upCounter.decr(3), {
Expand All @@ -108,11 +110,12 @@ test('test vivifyFarInstance', t => {
t.is(upCounter.incr(5), 8);
t.is(upCounter.incr(1), 9);
t.throws(() => upCounter.incr(-3), {
message: 'In "incr" method of (upCounter) arg 0: -3 - Must be >= 0',
message:
'In "incr" method of (upCounter): optional args: [0]: -3 - Must be >= 0',
});
t.throws(() => upCounter.incr('foo'), {
message:
'In "incr" method of (upCounter) arg 0: string "foo" - Must be a number',
'In "incr" method of (upCounter): optional args: [0]: string "foo" - Must be a number',
});
});

Expand Down
Loading

0 comments on commit cd1cca9

Please sign in to comment.