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

Rebase smartWallet (#8488) to release-mainnet1B branch #8609

Closed
Closed
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
115 changes: 115 additions & 0 deletions packages/boot/test/bootstrapTests/test-walletSurvivesZoeRestart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/** @file Bootstrap test of liquidation across multiple collaterals */
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import process from 'process';
import type { TestFn } from 'ava';

import { BridgeHandler } from '@agoric/vats';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import {
LiquidationTestContext,
makeLiquidationTestContext,
LiquidationSetup,
} from '../../tools/liquidation.ts';

const test = anyTest as TestFn<LiquidationTestContext>;

const setup: LiquidationSetup = {
vaults: [
{
atom: 15,
ist: 100,
debt: 100.5,
},
],
bids: [
{
give: '80IST',
discount: 0.1,
},
],
price: {
starting: 12.34,
trigger: 9.99,
},
auction: {
start: {
collateral: 45,
debt: 309.54,
},
end: {
collateral: 9.659301,
debt: 0,
},
},
};

test.before(async t => {
t.context = await makeLiquidationTestContext(t);
});

test.after.always(t => {
return t.context.shutdown && t.context.shutdown();
});

test.serial('wallet survives zoe null upgrade', async t => {
// fail if there are any unhandled rejections
process.on('unhandledRejection', (error: Error) => {
t.fail(error.message);
});
const collateralBrandKey = 'ATOM';
const managerIndex = 0;

const { walletFactoryDriver, setupVaults, controller, buildProposal } =
t.context;

const { EV } = t.context.runUtils;

const buyer = await walletFactoryDriver.provideSmartWallet('agoric1buyer');

const buildAndExecuteProposal = async (packageSpec: string) => {
const proposal = await buildProposal(packageSpec);

for await (const bundle of proposal.bundles) {
await controller.validateAndInstallBundle(bundle);
}

const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};

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

await setupVaults(collateralBrandKey, managerIndex, setup);

// restart Zoe

// /////// Upgrading ////////////////////////////////
await buildAndExecuteProposal('@agoric/builders/scripts/vats/upgrade-zoe.js');

t.like(await buyer.getLatestUpdateRecord(), {
currentAmount: {
// brand from EV() doesn't compare correctly
// brand: invitationBrand,
value: [],
},
updated: 'balance',
});

await buyer.executeOfferMaker(Offers.vaults.OpenVault, {
offerId: 'open1',
collateralBrandKey: 'ATOM',
wantMinted: 5.0,
giveCollateral: 9.0,
});

t.like(buyer.getLatestUpdateRecord(), {
updated: 'offerStatus',
status: { id: 'open1', numWantsSatisfied: 1 },
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const acceptInvitation = async (wallet, priceAggregator) => {

let pushPriceCounter = 0;
/**
* @param {*} wallet
* @param {import('@agoric/smart-wallet/src/smartWallet.js').SmartWallet} wallet
* @param {string} adminOfferId
* @param {import('@agoric/inter-protocol/src/price/roundsManager.js').PriceRound} priceRound
* @returns {Promise<string>} offer id
Expand Down Expand Up @@ -322,6 +322,7 @@ test.serial('errors', async t => {
'In "pushPrice" method of (OracleKit oracle): arg 0: unitPrice: number 1 - Must be a bigint',
},
);

await eventLoopIteration();

// Success, round starts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ test('want stable (insufficient funds)', async t => {
'Withdrawal of {"brand":"[Alleged: AUSD brand]","value":"[20000n]"} failed because the purse only contained {"brand":"[Alleged: AUSD brand]","value":"[10000n]"}';
const status = computedState.offerStatuses.get('insufficientFunds');
t.is(status?.error, `Error: ${msg}`);
/** @type {[PromiseRejectedResult]} */
// @ts-expect-error cast
const result = status.result;
t.is(result[0].status, 'rejected');
t.is(result[0].reason.message, msg);
});

test('govern offerFilter', async t => {
Expand Down Expand Up @@ -384,6 +379,8 @@ test('deposit multiple payments to unknown brand', async t => {
}
});

// related to recovering dropped Payments

// XXX belongs in smart-wallet package, but needs lots of set-up that's handy here.
test('recover when some withdrawals succeed and others fail', async t => {
const { fromEntries } = Object;
Expand Down
2 changes: 2 additions & 0 deletions packages/smart-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"@agoric/cosmic-proto": "^0.3.0",
"@agoric/vats": "^0.15.2-u13.0",
"@endo/bundle-source": "2.5.2-upstream-rollup",
"@endo/captp": "3.1.1",
"@endo/init": "0.5.56",
Expand All @@ -26,6 +27,7 @@
"dependencies": {
"@agoric/assert": "^0.6.1-u11wf.0",
"@agoric/casting": "^0.4.3-u13.0",
"@agoric/deploy-script-support": "^0.10.4-u13.0",
"@agoric/ertp": "^0.16.3-u13.0",
"@agoric/internal": "^0.4.0-u13.0",
"@agoric/notifier": "^0.6.3-u13.0",
Expand Down
Loading
Loading