Skip to content

Commit

Permalink
test(psm): finalize a3p tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iomekam committed Dec 20, 2024
1 parent eee85f7 commit 94a534b
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 63 deletions.
118 changes: 55 additions & 63 deletions a3p-integration/proposals/p:upgrade-19/psm.test.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,21 @@
/* eslint-env node */
/**
* @file The goal of this file is to make sure v28-provisionPool and v14-bank can be successfully
* upgraded. These vats are related because of the issues below;
* - https://github.com/Agoric/agoric-sdk/issues/8722
* - https://github.com/Agoric/agoric-sdk/issues/8724
* @file The goal of this file is to make sure v36-reserve upgraded.
*
* The test scenario is as follows;
* 1. Upgrade provisionPool. This upgrade overrides provisionWalletBridgerManager with a durable one
* 2. Add a new account and successfully provision it
* - Observe new account's address under `published.wallet.${address}`
* 3. Send some USDC_axl to provisionPoolAddress and observe its IST balances increases accordingly
* 4. Introduce a new asset to the chain and start a PSM instance for the new asset
* 4a. Deposit some of that asset to provisionPoolAddress
* 4b. Observe provisionPoolAddress' IST balance increase by the amount deposited in step 4a
* 5. Perform a null upgrade for provisionPool. This upgrade does NOT override provisionWalletBridgerManager
* - The goal here is to allow testing the bridgeHandler from the first upgrade is in fact durable
* 6. Auto provision
* 6a. Introduce a new account
* 6b. Fund it with IST and ATOM to be able to open a vault
* 6c. Try to open a vault WITHOUT provisioning the newly introduced account
* 6d. Observe the new account's address under `published.wallet`
* 7. Same as step 2. Checks manual provision works after null upgrade
* 1. Simulate trade of IST and USDC
* 2. Upgrade all PSMs
* 3. Verify metrics are the same after the upgrade
* 4. Verity trading is still possible after the upgrade
*/

import '@endo/init';
import test from 'ava';
import {
addUser,
evalBundles,
agd as agdAmbient,
agoric,
getISTBalance,
getDetailsMatchingVats,
GOV1ADDR,
openVault,
ATOM_DENOM,
} from '@agoric/synthetic-chain';
import {
makeVstorageKit,
waitUntilAccountFunded,
waitUntilContractDeployed,
} from '@agoric/client-utils';
import { NonNullish } from '@agoric/internal';
import {
bankSend,
checkUserProvisioned,
introduceAndProvision,
provision,
} from './test-lib/provision-helpers.js';

const ADD_PSM_DIR = 'addUsdLemons';
const DEPOSIT_USD_LEMONS_DIR = 'depositUSD-LEMONS';
const UPGRADE_PSM_DIR = 'upgradePSM';
const NULL_UPGRADE_PP_DIR = 'nullUpgradePP';

const USDC_DENOM = NonNullish(process.env.USDC_DENOM);
import { evalBundles } from '@agoric/synthetic-chain';
import { makeVstorageKit } from '@agoric/client-utils';

const ambientAuthority = {
query: agdAmbient.query,
follow: agoric.follow,
setTimeout,
log: console.log,
};
const UPGRADE_PSM_DIR = 'upgradePSM';
const SWAP_ANCHOR = 'swapAnchorForMintedSeat';

test.before(async t => {
const vstorageKit = await makeVstorageKit(
Expand All @@ -74,15 +28,53 @@ test.before(async t => {
};
});

test.serial('upgrade provisionPool', async t => {
test.serial('similate trade of IST and USDC', async t => {
// @ts-expect-error casting
const { vstorageKit } = t.context;

await evalBundles(SWAP_ANCHOR);

const metrics = await vstorageKit.readLatestHead(
'published.psm.IST.USDC.metrics',
);

t.is(metrics.anchorPoolBalance.value, 500000n);
t.is(metrics.feePoolBalance.value, 0n);
t.is(metrics.mintedPoolBalance.value, 500000n);
t.is(metrics.totalAnchorProvided.value, 0n);
t.is(metrics.totalMintedProvided.value, 500000n);
});

test.serial('upgrade PSMs', async t => {
// @ts-expect-error casting
const { vstorageKit } = t.context;

await evalBundles(UPGRADE_PSM_DIR);

// const vatDetailsAfter = await getDetailsMatchingVats('provisionPool');
// const { incarnation } = vatDetailsAfter.find(vat =>
// vat.vatName.endsWith('provisionPool'),
// );
const metrics = await vstorageKit.readLatestHead(
'published.psm.IST.USDC.metrics',
);

t.is(metrics.anchorPoolBalance.value, 500000n);
t.is(metrics.feePoolBalance.value, 0n);
t.is(metrics.mintedPoolBalance.value, 500000n);
t.is(metrics.totalAnchorProvided.value, 0n);
t.is(metrics.totalMintedProvided.value, 500000n);
});

test.serial('verify trading after upgrade', async t => {
// @ts-expect-error casting
const { vstorageKit } = t.context;

await evalBundles(SWAP_ANCHOR);

const metrics = await vstorageKit.readLatestHead(
'published.psm.IST.USDC.metrics',
);

// t.log(vatDetailsAfter);
// t.is(incarnation, 1, 'incorrect incarnation');
t.pass();
t.is(metrics.anchorPoolBalance.value, 1000000n);
t.is(metrics.feePoolBalance.value, 0n);
t.is(metrics.mintedPoolBalance.value, 1000000n);
t.is(metrics.totalAnchorProvided.value, 0n);
t.is(metrics.totalMintedProvided.value, 1000000n);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"consume": {
"contractKits": true,
"zoe": true,
"agoricNames": true,
"psmKit": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// @ts-nocheck
/* eslint-disable no-undef */

const swapAnchorForMintedSeat = async powers => {
const {
consume: { zoe, contractKits: contractKitsP, psmKit: psmKitP, agoricNames },
} = powers;

const [contractKits, psmKit, usdcIssuer, usdcBrand] = await Promise.all([
contractKitsP,
psmKitP,
E(agoricNames).lookup('issuer', 'USDC'),
E(agoricNames).lookup('brand', 'USDC'),
]);

console.log('[CONTRACT_KITS]', contractKits);
console.log('[ISSUER]', usdcIssuer);

let govCreatorFacet;
for (const { psmGovernorCreatorFacet, label } of psmKit.values()) {
if (label === 'psm-IST-USDC') {
govCreatorFacet = psmGovernorCreatorFacet;
console.log('psm-IST-USDC found', label);
}
}

const psmPublicFacet = await E(govCreatorFacet).getPublicFacet();

let usdcMint;
for (const { publicFacet, creatorFacet: mint } of contractKits.values()) {
if (publicFacet === usdcIssuer) {
usdcMint = mint;
console.log('USDC found', mint);
break;
}
}

console.log('Minting USDC');
const amt = harden({ brand: usdcBrand, value: 500000n });
const payment = await E(usdcMint).mintPayment(amt);

const seat = E(zoe).offer(
E(psmPublicFacet).makeWantMintedInvitation(),
harden({
give: { In: amt },
}),
harden({ In: payment }),
);

console.log(await E(seat).getPayouts());
console.log('Done.');
};

swapAnchorForMintedSeat;

0 comments on commit 94a534b

Please sign in to comment.