Skip to content

Commit

Permalink
test: fix test-vaultfactory.js for new timer behavior
Browse files Browse the repository at this point in the history
The test-vaultFactory.js "price falls precipitously" test exercises
the asset price changing in four steps:

* initial conditions: t=0, price=2200
* tick(): t=1, price=19180
* tick(): t=2, price=1650
* tick(): t=3, price=150

A loan is taken out at t=0. The drop to price=1650 is not quite enough
to trigger liquidation. The drop to price=150 does cause liquidation,
moreover the price is so low that it falls underwater entirely, so all
of the collateral is sold, the client gets nothing back, and the vault
manager must tap the reserves to avoid insolvency.

Previously, this test used *four* calls to `tick()`, asserting that
liquidation did not happen after any of the first three. It appears
that this only passed because the `await tick()` was unable to
completely wait for all triggered activity to complete (it merely
waited on the `wake()` result promise, and did not do a full
`setImmediate` / `eventLoopIteration`). When I inserted `await
eventLoopIteration()` calls after `tick()` in the original version,
the test failed, as liquidation was happening (and completing) after
the *third* `tick()`.

Now that our `manualTimer.tick()` can be configured to completely
flush the promise queue, I'm removing the extra `tick()` call, and the
"liquidation has not happened" assertion that was being made too
early.
  • Loading branch information
warner committed Aug 16, 2022
1 parent 4690ed8 commit d955681
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/inter-protocol/test/vaultFactory/test-vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ test('price falls precipitously', async t => {
undefined,
1500n,
);
// we start with time=0, price=2200

const { vaultFactory, lender } = services.vaultFactory;

const { reserveCreatorFacet } = services.reserveFacets;
Expand Down Expand Up @@ -782,16 +784,14 @@ test('price falls precipitously', async t => {
// @ts-expect-error type confusion
const m = await subscriptionTracker(t, metricsSub);
await m.assertInitial(reserveInitialState(run.makeEmpty()));
await manualTimer.tick();
await assertDebtIs(debtAmount.value);

await manualTimer.tick();
await manualTimer.tick(); // t 0->1, p 2200->19180
await assertDebtIs(debtAmount.value);

await manualTimer.tick();
await manualTimer.tick(); // t 1->2, p 19180->1650
await assertDebtIs(debtAmount.value);

await manualTimer.tick();
await manualTimer.tick(); // t 2->3, p 1650->150, liquidates
await eventLoopIteration();

// shortfall 103n covered by the reserve
t.deepEqual(
Expand Down

0 comments on commit d955681

Please sign in to comment.