-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove incorrect assertion in multipoolAutoSwap priceAuthority (#…
…2839) fixes #2831 priceAggregator shows that when priceQuery() returns a falsy value, createQuote() is expected to return undefined. This happens when the comparefunction returns false, so the promise isn't resolved. I added a test of the priceAuthority in multipoolAutoSwap. The test fails before the change (The first trigger gets false on the comparison) and passes afterward.
- Loading branch information
1 parent
477feeb
commit cb022d6
Showing
2 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/zoe/test/unitTests/contracts/test-multipoolPriceAuthority.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// @ts-check | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { test } from '@agoric/zoe/tools/prepare-test-env-ava'; | ||
import { makeNotifierKit } from '@agoric/notifier'; | ||
import { makeIssuerKit, amountMath, MathKind } from '@agoric/ertp'; | ||
import { makePriceAuthority } from '../../../src/contracts/multipoolAutoswap/priceAuthority'; | ||
import { setup } from '../setupBasicMints'; | ||
import buildManualTimer from '../../../tools/manualTimer'; | ||
|
||
test('multipoolAutoSwap PriceAuthority exception path', async t => { | ||
const { moolaR, simoleanR } = setup(); | ||
const timer = buildManualTimer(console.log, 0n); | ||
const { notifier, updater } = makeNotifierKit(); | ||
|
||
const quoteKit = makeIssuerKit('quoteIssuer', MathKind.SET); | ||
|
||
function ersatzQuote(moolaIn, simoleansOut) { | ||
return { | ||
amountIn: amountMath.make(moolaR.brand, moolaIn), | ||
amountOut: amountMath.make(simoleanR.brand, simoleansOut), | ||
}; | ||
} | ||
|
||
const priceAuthority = makePriceAuthority( | ||
() => ersatzQuote(3, 25), | ||
() => ersatzQuote(18, 5), | ||
moolaR.brand, | ||
simoleanR.brand, | ||
timer, | ||
null, | ||
notifier, | ||
quoteKit, | ||
); | ||
|
||
const triggerDoesNot = priceAuthority.quoteWhenLT( | ||
amountMath.make(moolaR.brand, 10), | ||
amountMath.make(simoleanR.brand, 20), | ||
); | ||
|
||
triggerDoesNot.then( | ||
quote => t.fail(` wasn't expecting a call with a quote ${quote}`), | ||
e => t.fail(` wasn't expecting ${e}`), | ||
); | ||
|
||
const trigger = priceAuthority.quoteWhenLT( | ||
amountMath.make(moolaR.brand, 10), | ||
amountMath.make(simoleanR.brand, 30), | ||
); | ||
|
||
trigger.then( | ||
quote => { | ||
t.deepEqual(quote.quoteAmount.brand, quoteKit.brand); | ||
t.truthy(quote.quoteAmount.value); | ||
t.truthy(quote.quotePayment); | ||
}, | ||
e => t.fail(` wasn't expecting ${e}`), | ||
); | ||
|
||
await updater.updateState(true); | ||
await timer.tick(); | ||
}); |