-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: a virtual object test for AMM pools. (#5224)
* feat: first pass at VO and DVO test harnesses Closes #4997 * docs: add documentation * test: a virtual object test for AMM pools. see: #5207 Pretty rudimentary. It just sees that the objects come back. The test fails when I manually remove (tested) stuff from state. There's one test that changed state is persisted: I update the notifier, and verify that on revival, the count has increased. A plausible next test would be to add liquidity, but that's a bunch more work. * chore: review-inspired cleanups. Co-authored-by: Chip Morningstar <chip@fudco.com>
- Loading branch information
1 parent
ac1c0a6
commit c8c346e
Showing
1 changed file
with
89 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// @ts-check | ||
|
||
import { runVOTest, test } from '@agoric/swingset-vat/tools/vo-test-harness.js'; | ||
import { setupZCFTest } from '@agoric/zoe/test/unitTests/zcf/setupZcfTest.js'; | ||
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js'; | ||
import { makeIssuerKit } from '@agoric/ertp'; | ||
|
||
import { definePoolKind } from '../src/vpool-xyk-amm/pool.js'; | ||
import { makeAmmParamManager } from '../src/vpool-xyk-amm/params.js'; | ||
|
||
const voPoolTest = async (t, mutation, postTest) => { | ||
let makePool; | ||
const { zoe, zcf } = await setupZCFTest(); | ||
const invitation = await zcf.makeInvitation(() => {}, 'fake invitation'); | ||
const paramManager = await makeAmmParamManager(zoe, 25n, 5n, invitation); | ||
const { brand: centralBrand } = makeIssuerKit('central'); | ||
const { brand: secondaryBrand } = makeIssuerKit('secondary'); | ||
const quoteIssuerKit = makeIssuerKit('Quotes'); | ||
const liquidityZcfMint = await zcf.makeZCFMint('Liquidity'); | ||
const { userSeat: poolSeatP } = zcf.makeEmptySeatKit(); | ||
const { zcfSeat: protocolSeatP } = zcf.makeEmptySeatKit(); | ||
const [poolSeat, protocolSeat] = await Promise.all([ | ||
poolSeatP, | ||
protocolSeatP, | ||
]); | ||
|
||
const defineVirtualPoolKind = () => { | ||
const timer = buildManualTimer(t.log); | ||
|
||
const paramAccessor = paramManager.readonly(); | ||
|
||
return definePoolKind( | ||
zcf, | ||
centralBrand, | ||
timer, | ||
quoteIssuerKit, | ||
paramAccessor, | ||
protocolSeat, | ||
); | ||
}; | ||
|
||
const state = {}; | ||
const testVPool = async (context, phase) => { | ||
const { pool, singlePool } = context; | ||
if (phase === 'before') { | ||
state.notifier = pool.getNotifier(); | ||
state.toCentralPA = pool.getToCentralPriceAuthority(); | ||
state.singlePool = pool.getVPool(); | ||
state.liquidityIssuer = pool.getLiquidityIssuer(); | ||
mutation(context); | ||
} else if (phase === 'after') { | ||
const newNotifier = pool.getNotifier(); | ||
t.is(state.notifier, newNotifier); | ||
t.is(state.toCentralPA, pool.getToCentralPriceAuthority()); | ||
t.is(state.singlePool, singlePool); | ||
t.is(state.liquidityIssuer, pool.getLiquidityIssuer()); | ||
t.truthy(postTest(context)); | ||
} | ||
}; | ||
|
||
const prepare = () => { | ||
makePool = defineVirtualPoolKind(); | ||
}; | ||
|
||
const makeTestObject = () => { | ||
return makePool(liquidityZcfMint, poolSeat, secondaryBrand); | ||
}; | ||
|
||
await runVOTest(t, prepare, makeTestObject, testVPool); | ||
}; | ||
|
||
const noOp = () => {}; | ||
|
||
test.serial('unchanged', async t => { | ||
await voPoolTest(t, noOp, () => true); | ||
}); | ||
|
||
test.serial('one update', async t => { | ||
await voPoolTest( | ||
t, | ||
context => { | ||
return context.pool.updateState(); | ||
}, | ||
async context => { | ||
const notification = await context.pool.getNotifier().getUpdateSince(); | ||
t.is(notification.updateCount, 2); | ||
}, | ||
); | ||
}); |