Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade testing supports #9770

Merged
merged 18 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions packages/boot/test/bootstrapTests/addAssets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test('addAsset to quiescent auction', async t => {
const { liveAuctionSchedule, nextAuctionSchedule } = schedules;
const nextEndTime = liveAuctionSchedule
? liveAuctionSchedule.endTime
: nextAuctionSchedule.endTime;
: nextAuctionSchedule!.endTime;
const fiveMinutes = harden({
relValue: 5n * 60n,
timerBrand: nextEndTime.timerBrand,
Expand All @@ -83,7 +83,7 @@ test('addAsset to active auction', async t => {
const auctioneerKit = await EV.vat('bootstrap').consumeItem('auctioneerKit');
const schedules = await EV(auctioneerKit.creatorFacet).getSchedule();
const { nextAuctionSchedule } = schedules;
t.truthy(nextAuctionSchedule);
assert(nextAuctionSchedule);
const nextStartTime = nextAuctionSchedule.startTime;
const fiveMinutes = harden({
relValue: 5n * 60n,
Expand All @@ -105,18 +105,19 @@ test('addAsset to active auction', async t => {
const coreEvalBridgeHandler = await EV.vat('bootstrap').consumeItem(
'coreEvalBridgeHandler',
);
EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);
// XXX races with the following lines
void EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);

const nextEndTime = nextAuctionSchedule.endTime;
const nextEndTime = nextAuctionSchedule!.endTime;
const afterEndTime = TimeMath.addAbsRel(nextEndTime, fiveMinutes);
await advanceTimeTo(afterEndTime);
t.log('proposal executed');

const schedulesAfter = await EV(auctioneerKit.creatorFacet).getSchedule();
// TimeMath.compareAbs() can't handle brands processed by kmarshall
t.truthy(
schedules.nextAuctionSchedule.endTime.absValue <
schedulesAfter.nextAuctionSchedule.endTime.absValue,
schedules.nextAuctionSchedule!.endTime.absValue <
schedulesAfter.nextAuctionSchedule!.endTime.absValue,
);

t.like(readLatest(`${auctioneerPath}.book1`), { currentPriceLevel: null });
Expand All @@ -129,7 +130,7 @@ test('addAsset to auction starting soon', async t => {
const auctioneerKit = await EV.vat('bootstrap').consumeItem('auctioneerKit');
const schedules = await EV(auctioneerKit.creatorFacet).getSchedule();
const { nextAuctionSchedule } = schedules;
t.truthy(nextAuctionSchedule);
assert(nextAuctionSchedule);
const nextStartTime = nextAuctionSchedule.startTime;
const fiveMinutes = harden({
relValue: 5n * 60n,
Expand All @@ -150,7 +151,8 @@ test('addAsset to auction starting soon', async t => {
const coreEvalBridgeHandler = await EV.vat('bootstrap').consumeItem(
'coreEvalBridgeHandler',
);
EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);
// XXX races with the following lines
void EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);

const nextEndTime = nextAuctionSchedule.endTime;
const afterEndTime = TimeMath.addAbsRel(nextEndTime, fiveMinutes);
Expand All @@ -160,8 +162,8 @@ test('addAsset to auction starting soon', async t => {

const schedulesAfter = await EV(auctioneerKit.creatorFacet).getSchedule();
t.truthy(
schedules.nextAuctionSchedule.endTime.absValue <
schedulesAfter.nextAuctionSchedule.endTime.absValue,
schedules.nextAuctionSchedule!.endTime.absValue <
schedulesAfter.nextAuctionSchedule!.endTime.absValue,
);
t.like(readLatest(`${auctioneerPath}.book1`), { currentPriceLevel: null });
});
130 changes: 76 additions & 54 deletions packages/boot/test/bootstrapTests/orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ test.skip('stakeOsmo - queries', async t => {
});

test.serial('stakeAtom - smart wallet', async t => {
const { buildProposal, evalProposal, agoricNamesRemotes, readLatest } =
t.context;
const {
buildProposal,
evalProposal,
agoricNamesRemotes,
flushInboundQueue,
readLatest,
} = t.context;

await evalProposal(
buildProposal('@agoric/builders/scripts/orchestration/init-stakeAtom.js'),
Expand All @@ -143,7 +148,7 @@ test.serial('stakeAtom - smart wallet', async t => {
'agoric1testStakAtom',
);

await wd.executeOffer({
await wd.sendOffer({
id: 'request-account',
invitationSpec: {
source: 'agoricContract',
Expand All @@ -152,6 +157,7 @@ test.serial('stakeAtom - smart wallet', async t => {
},
proposal: {},
});
await flushInboundQueue();
t.like(wd.getCurrentWalletRecord(), {
offerToPublicSubscriberPaths: [
[
Expand All @@ -170,18 +176,18 @@ test.serial('stakeAtom - smart wallet', async t => {
const { ATOM } = agoricNamesRemotes.brand;
ATOM || Fail`ATOM missing from agoricNames`;

await t.notThrowsAsync(
wd.executeOffer({
id: 'request-delegate-success',
invitationSpec: {
source: 'continuing',
previousOffer: 'request-account',
invitationMakerName: 'Delegate',
invitationArgs: [validatorAddress, { brand: ATOM, value: 10n }],
},
proposal: {},
}),
);
// Cannot await executeOffer because the offer won't resolve until after the bridge's inbound queue is flushed.
// But this test doesn't require that.
0xpatrickdev marked this conversation as resolved.
Show resolved Hide resolved
await wd.sendOffer({
id: 'request-delegate-success',
invitationSpec: {
source: 'continuing',
previousOffer: 'request-account',
invitationMakerName: 'Delegate',
invitationArgs: [validatorAddress, { brand: ATOM, value: 10n }],
},
proposal: {},
});
t.like(wd.getLatestUpdateRecord(), {
status: { id: 'request-delegate-success', numWantsSatisfied: 1 },
});
Expand All @@ -192,6 +198,7 @@ test.serial('stakeAtom - smart wallet', async t => {
encoding: 'bech32',
};

// This will trigger the immediate ack of the mock bridge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "This" related to executeOffer? It seems to be due to ackImmediately. Please consider making this comment more explicit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to word it in a way that wouldn't be false if that code was refactored

await t.throwsAsync(
wd.executeOffer({
id: 'request-delegate-fail',
Expand Down Expand Up @@ -248,8 +255,13 @@ test.serial('revise chain info', async t => {
});

test('basic-flows', async t => {
const { buildProposal, evalProposal, agoricNamesRemotes, readLatest } =
t.context;
const {
buildProposal,
evalProposal,
agoricNamesRemotes,
readLatest,
flushInboundQueue,
} = t.context;

await evalProposal(
buildProposal('@agoric/builders/scripts/orchestration/init-basic-flows.js'),
Expand All @@ -259,7 +271,7 @@ test('basic-flows', async t => {
await t.context.walletFactoryDriver.provideSmartWallet('agoric1test');

// create a cosmos orchestration account
await wd.executeOffer({
await wd.sendOffer({
id: 'request-coa',
invitationSpec: {
source: 'agoricContract',
Expand All @@ -271,6 +283,7 @@ test('basic-flows', async t => {
},
proposal: {},
});
await flushInboundQueue();
t.like(wd.getCurrentWalletRecord(), {
offerToPublicSubscriberPaths: [
[
Expand Down Expand Up @@ -323,8 +336,13 @@ test.serial('auto-stake-it - proposal', async t => {
});

test.serial('basic-flows - portfolio holder', async t => {
const { buildProposal, evalProposal, readLatest, agoricNamesRemotes } =
t.context;
const {
buildProposal,
evalProposal,
readLatest,
agoricNamesRemotes,
flushInboundQueue,
} = t.context;

await evalProposal(
buildProposal('@agoric/builders/scripts/orchestration/init-basic-flows.js'),
Expand All @@ -334,7 +352,7 @@ test.serial('basic-flows - portfolio holder', async t => {
await t.context.walletFactoryDriver.provideSmartWallet('agoric1test2');

// create a cosmos orchestration account
await wd.executeOffer({
await wd.sendOffer({
id: 'request-portfolio-acct',
invitationSpec: {
source: 'agoricContract',
Expand All @@ -346,6 +364,14 @@ test.serial('basic-flows - portfolio holder', async t => {
},
proposal: {},
});
t.like(
wd.getLatestUpdateRecord(),
{
status: { id: 'request-portfolio-acct', numWantsSatisfied: 1 },
},
'trivially satisfied',
);
await flushInboundQueue();
t.like(wd.getCurrentWalletRecord(), {
offerToPublicSubscriberPaths: [
[
Expand All @@ -371,43 +397,39 @@ test.serial('basic-flows - portfolio holder', async t => {
ATOM || Fail`ATOM missing from agoricNames`;
BLD || Fail`BLD missing from agoricNames`;

await t.notThrowsAsync(
wd.executeOffer({
id: 'delegate-cosmoshub',
invitationSpec: {
source: 'continuing',
previousOffer: 'request-portfolio-acct',
invitationMakerName: 'MakeInvitation',
invitationArgs: [
'cosmoshub',
'Delegate',
[validatorAddress, { brand: ATOM, value: 10n }],
],
},
proposal: {},
}),
);
await wd.sendOffer({
id: 'delegate-cosmoshub',
invitationSpec: {
source: 'continuing',
previousOffer: 'request-portfolio-acct',
invitationMakerName: 'MakeInvitation',
invitationArgs: [
'cosmoshub',
'Delegate',
[validatorAddress, { brand: ATOM, value: 10n }],
],
},
proposal: {},
});
t.like(wd.getLatestUpdateRecord(), {
status: { id: 'delegate-cosmoshub', numWantsSatisfied: 1 },
});

await t.notThrowsAsync(
wd.executeOffer({
id: 'delegate-agoric',
invitationSpec: {
source: 'continuing',
previousOffer: 'request-portfolio-acct',
invitationMakerName: 'MakeInvitation',
invitationArgs: [
'agoric',
'Delegate',
// XXX use ChainAddress for LocalOrchAccount
['agoric1validator1', { brand: BLD, value: 10n }],
],
},
proposal: {},
}),
);
await wd.sendOffer({
id: 'delegate-agoric',
invitationSpec: {
source: 'continuing',
previousOffer: 'request-portfolio-acct',
invitationMakerName: 'MakeInvitation',
invitationArgs: [
'agoric',
'Delegate',
// XXX use ChainAddress for LocalOrchAccount
['agoric1validator1', { brand: BLD, value: 10n }],
],
},
proposal: {},
});
t.like(wd.getLatestUpdateRecord(), {
status: { id: 'delegate-agoric', numWantsSatisfied: 1 },
});
Expand Down
14 changes: 3 additions & 11 deletions packages/boot/test/bootstrapTests/vats-restart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { TestFn } from 'ava';

import processAmbient from 'child_process';
import { promises as fsAmbientPromises } from 'fs';

import { Fail } from '@endo/errors';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js';
import { BridgeHandler, ScopedBridgeManager } from '@agoric/vats';
import type { EconomyBootstrapSpace } from '@agoric/inter-protocol/src/proposals/econ-behaviors.js';
import {
makeProposalExtractor,
makeSwingsetTestKit,
} from '../../tools/supports.ts';
import { makeSwingsetTestKit } from '../../tools/supports.ts';
import { makeWalletFactoryDriver } from '../../tools/drivers.ts';

// main/production config doesn't have initialPrice, upon which 'open vaults' depends
Expand Down Expand Up @@ -132,9 +125,8 @@ test.serial('use IBC callbacks after upgrade', async t => {
test.serial('read metrics', async t => {
const { EV } = t.context.runUtils;

const vaultFactoryKit: Awaited<
EconomyBootstrapSpace['consume']['vaultFactoryKit']
> = await EV.vat('bootstrap').consumeItem('vaultFactoryKit');
const vaultFactoryKit =
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');

const vfTopics = await EV(vaultFactoryKit.publicFacet).getPublicTopics();

Expand Down
26 changes: 11 additions & 15 deletions packages/boot/test/bootstrapTests/vaults-upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { SECONDS_PER_YEAR } from '@agoric/inter-protocol/src/interest.js';
import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js';
import { ExecutionContext, TestFn } from 'ava';
import { FakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { EconomyBootstrapSpace } from '@agoric/inter-protocol/src/proposals/econ-behaviors.js';
import { makeSwingsetTestKit } from '../../tools/supports.ts';
import { makeWalletFactoryDriver } from '../../tools/drivers.ts';

Expand Down Expand Up @@ -284,17 +283,14 @@ test.serial('open vault', async t => {
test.serial('restart vaultFactory', async t => {
const { runUtils, readCollateralMetrics } = t.context.shared;
const { EV } = runUtils;
const vaultFactoryKit = await (EV.vat('bootstrap').consumeItem(
'vaultFactoryKit',
) as EconomyBootstrapSpace['consume']['vaultFactoryKit']);
const vaultFactoryKit =
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');

const reserveKit = await (EV.vat('bootstrap').consumeItem(
'reserveKit',
) as EconomyBootstrapSpace['consume']['reserveKit']);
const reserveKit = await EV.vat('bootstrap').consumeItem('reserveKit');
const bootstrapVat = EV.vat('bootstrap');
const electorateCreatorFacet = await (bootstrapVat.consumeItem(
const electorateCreatorFacet = await bootstrapVat.consumeItem(
'economicCommitteeCreatorFacet',
) as EconomyBootstrapSpace['consume']['economicCommitteeCreatorFacet']);
);

const poserInvitation = await EV(electorateCreatorFacet).getPoserInvitation();
const creatorFacet1 = await EV.get(reserveKit).creatorFacet;
Expand Down Expand Up @@ -327,9 +323,8 @@ test.serial('restart vaultFactory', async t => {

test.serial('restart contractGovernor', async t => {
const { EV } = t.context.shared.runUtils;
const vaultFactoryKit = await (EV.vat('bootstrap').consumeItem(
'vaultFactoryKit',
) as EconomyBootstrapSpace['consume']['vaultFactoryKit']);
const vaultFactoryKit =
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');

const { governorAdminFacet } = vaultFactoryKit;
// has no privateArgs of its own. the privateArgs.governed is only for the
Expand Down Expand Up @@ -498,9 +493,10 @@ test.serial(
await EV.vat('bootstrap').consumeItem('powerStore');

const getStoreSnapshot = async (name: string) =>
EV.vat('bootstrap').snapshotStore(
await EV(powerStore).get(name),
) as Promise<[any, any][]>;
EV.vat('bootstrap').snapshotStore(await EV(powerStore).get(name)) as [
any,
any,
][];

const contractKits = await getStoreSnapshot('contractKits');
// TODO refactor the entries to go into governedContractKits too (so the latter is sufficient to test)
Expand Down
Loading
Loading