Skip to content

Commit

Permalink
test: add concurrent liquidation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iomekam committed Oct 5, 2023
1 parent da3b8a8 commit 9af1e08
Show file tree
Hide file tree
Showing 5 changed files with 1,087 additions and 31 deletions.
37 changes: 36 additions & 1 deletion packages/boot/test/bootstrapTests/liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ export const makeLiquidationTestContext = async t => {
const setupStartingState = async ({
collateralBrandKey,
managerIndex,
price,
}: {
collateralBrandKey: string;
managerIndex: number;
price: number;
}) => {
const managerPath = `published.vaultFactory.managers.manager${managerIndex}`;
const { advanceTimeBy, readLatest } = swingsetTestKit;
Expand All @@ -111,7 +113,7 @@ export const makeLiquidationTestContext = async t => {
// price feed logic treats zero time as "unset" so advance to nonzero
await advanceTimeBy(1, 'seconds');

await priceFeedDrivers[collateralBrandKey].setPrice(12.34);
await priceFeedDrivers[collateralBrandKey].setPrice(price);

// raise the VaultFactory DebtLimit
await governanceDriver.changeParams(
Expand Down Expand Up @@ -217,6 +219,39 @@ export const makeLiquidationTestContext = async t => {
};
};

export const addSTARsCollateral = async t => {
const { controller, buildProposal } = t.context;

t.log('building proposal');
const proposal = await buildProposal({
package: 'builders',
packageScriptName: 'build:add-STARS-proposal',
});

for await (const bundle of proposal.bundles) {
await controller.validateAndInstallBundle(bundle);
}
t.log('installed', proposal.bundles.length, 'bundles');

t.log('launching proposal');
const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};
t.log({ bridgeMessage });

const { EV } = t.context.runUtils;
/** @type {ERef<import('@agoric/vats/src/types.js').BridgeHandler>} */
const coreEvalBridgeHandler = await EV.vat('bootstrap').consumeItem(
'coreEvalBridgeHandler',
);
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);

t.context.refreshAgoricNamesRemotes();

t.log('add-STARS proposal executed');
};

export type LiquidationTestContext = Awaited<
ReturnType<typeof makeLiquidationTestContext>
>;
32 changes: 3 additions & 29 deletions packages/boot/test/bootstrapTests/test-liquidation-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { ExecutionContext, TestFn } from 'ava';
import type { ScheduleNotification } from '@agoric/inter-protocol/src/auction/scheduler.js';
import { BridgeHandler } from '@agoric/vats';
import {
addSTARsCollateral,
LiquidationTestContext,
likePayouts,
makeLiquidationTestContext,
Expand Down Expand Up @@ -152,6 +153,7 @@ const checkFlow1 = async (
await setupStartingState({
collateralBrandKey,
managerIndex,
price: setup.price.starting,
});

const minter = await walletFactoryDriver.provideSmartWallet('agoric1minter');
Expand Down Expand Up @@ -389,35 +391,7 @@ test.serial(
);

test.serial('add STARS collateral', async t => {
const { controller, buildProposal } = t.context;

t.log('building proposal');
const proposal = await buildProposal({
package: 'builders',
packageScriptName: 'build:add-STARS-proposal',
});

for await (const bundle of proposal.bundles) {
await controller.validateAndInstallBundle(bundle);
}
t.log('installed', proposal.bundles.length, 'bundles');

t.log('launching proposal');
const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};
t.log({ bridgeMessage });

const { EV } = t.context.runUtils;
const coreEvalBridgeHandler: ERef<BridgeHandler> = await EV.vat(
'bootstrap',
).consumeItem('coreEvalBridgeHandler');
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);

t.context.refreshAgoricNamesRemotes();

t.log('add-STARS proposal executed');
await addSTARsCollateral(t);
t.pass(); // reached here without throws
});

Expand Down
6 changes: 5 additions & 1 deletion packages/boot/test/bootstrapTests/test-liquidation-2b.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ test.serial('scenario: Flow 2b', async t => {
walletFactoryDriver,
} = t.context;

await setupStartingState({ collateralBrandKey: 'ATOM', managerIndex: 0 });
await setupStartingState({
collateralBrandKey: 'ATOM',
managerIndex: 0,
price: setup.price.starting,
});

const minter = await walletFactoryDriver.provideSmartWallet('agoric1minter');

Expand Down
Loading

0 comments on commit 9af1e08

Please sign in to comment.