Skip to content

Commit

Permalink
chore(pp-upgrade): test functionality after provisionPool and bank up…
Browse files Browse the repository at this point in the history
…grade

Refs: #10395

fix: format fixes
  • Loading branch information
anilhelvaci committed Nov 27, 2024
1 parent c51ee5c commit b8800c9
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 27 deletions.
1 change: 1 addition & 0 deletions a3p-integration/proposals/p:upgrade-19/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
replaceFeeDistributor/
addUsdLemons/
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/* eslint-disable no-undef */
const PROVISIONING_POOL_ADDR = 'agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346';

const depositUsdLemons = async powers => {
const {
consume: { contractKits: contractKitsP, namesByAddressAdmin: namesByAddressAdminP , agoricNames },
// instance: { consume: { ['psm-IST-USD_LEMONS']: usdLemonsPsmInstanceP }}
consume: {
contractKits: contractKitsP,
namesByAddressAdmin: namesByAddressAdminP,
agoricNames,
},
} = powers;

const namesByAddressAdmin = await namesByAddressAdminP;

const getDepositFacet = async address => {
const admin = await E(namesByAddressAdmin).lookupAdmin(address);
console.log('ADMIN', admin)

const nameHub = await E(admin).readonly();
console.log('NAME_HUB', nameHub);
const hub = E(E(namesByAddressAdmin).lookupAdmin(address)).readonly();
return E(hub).lookup('depositFacet');
};

const [contractKits, usdLemonsIssuer, usdLemonsBrand, ppDepositFacet] = await Promise.all([
contractKitsP,
E(agoricNames).lookup('issuer', 'USD_LEMONS'),
E(agoricNames).lookup('brand', 'USD_LEMONS'),
getDepositFacet(PROVISIONING_POOL_ADDR),
]);
const [contractKits, usdLemonsIssuer, usdLemonsBrand, ppDepositFacet] =
await Promise.all([
contractKitsP,
E(agoricNames).lookup('issuer', 'USD_LEMONS'),
E(agoricNames).lookup('brand', 'USD_LEMONS'),
getDepositFacet(PROVISIONING_POOL_ADDR),
]);

console.log('[CONTRACT_KITS]', contractKits);
console.log('[ISSUER]', usdLemonsIssuer);
Expand All @@ -32,13 +32,15 @@ const depositUsdLemons = async powers => {
for (const { publicFacet, creatorFacet: mint } of contractKits.values()) {
if (publicFacet === usdLemonsIssuer) {
usdLemonsMint = mint;
console.log('BINGO', mint)
console.log('BINGO', mint);
break;
}
}

console.log('Minting USD_LEMONS');
const helloPayment = await E(usdLemonsMint).mintPayment(harden({ brand: usdLemonsBrand, value: 500000n }));
const helloPayment = await E(usdLemonsMint).mintPayment(
harden({ brand: usdLemonsBrand, value: 500000n }),
);

console.log('Funding provision pool...');
await E(ppDepositFacet).receive(helloPayment);
Expand Down
3 changes: 2 additions & 1 deletion a3p-integration/proposals/p:upgrade-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"agoricProposal": {
"type": "/agoric.swingset.CoreEvalProposal",
"sdk-generate": [
"testing/replace-feeDistributor-short.js replaceFeeDistributor"
"testing/replace-feeDistributor-short.js replaceFeeDistributor",
"testing/add-USD-LEMONS.js addUsdLemons"
]
},
"type": "module",
Expand Down
129 changes: 129 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/provisionPool.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/* 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
*
* The test scenario is as follows;
* - Prerequisite: provisionPool and bank are already upgraded. See `upgrade.go`
* 1. Add a new account and successfully provision it
* - Observe new account's address under `published.wallet.${address}`
* 2. Send some USDC_axl to provisionPoolAddress and observe its IST balances increases accordingly
* 3. Introduce a new asset to the chain and start a PSM instance for the new asset
* 3a. Deposit some of that asset to provisionPoolAddress
* 3b. Observe provisionPoolAddress' IST balance increase by the amount deposited in step 3a
*/

import '@endo/init';
import test from 'ava';
import { execFileSync } from 'node:child_process';
import {
addUser,
makeAgd,
evalBundles,
agd as agdAmbient,
agoric,
bankSend,
getISTBalance,
} from '@agoric/synthetic-chain';
import { NonNullish } from './test-lib/errors.js';
import {
retryUntilCondition,
waitUntilAccountFunded,
waitUntilContractDeployed,
} from './test-lib/sync-tools.js';

const PROVISIONING_POOL_ADDR = 'agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346';

const ADD_PSM_DIR = 'addUsdLemons';
const DEPOSIT_USD_LEMONS_DIR = 'depositUSD-LEMONS';

const USDC_DENOM = NonNullish(process.env.USDC_DENOM);

const agd = makeAgd({ execFileSync }).withOpts({ keyringBackend: 'test' });

const ambientAuthority = {
query: agdAmbient.query,
follow: agoric.follow,
setTimeout,
};

const provision = (name, address) =>
agd.tx(['swingset', 'provision-one', name, address, 'SMART_WALLET'], {
chainId: 'agoriclocal',
from: 'validator',
yes: true,
});

const introduceAndProvision = async name => {
const address = await addUser(name);
console.log('ADDR', name, address);

const provisionP = provision(name, address);

return { provisionP, address };
};

const getProvisionedAddresses = async () => {
const { children } = await agd.query([
'vstorage',
'children',
'published.wallet',
]);
return children;
};

const checkUserProvisioned = addr =>
retryUntilCondition(
getProvisionedAddresses,
children => children.includes(addr),
'Account not provisioned',
{ maxRetries: 5, retryIntervalMs: 1000, log: console.log, setTimeout },
);

test(`upgrade provision pool`, async t => {
// Introduce new user then provision
const { address } = await introduceAndProvision('provisionTester');
await checkUserProvisioned(address);

// Send USDC_axl to pp
const istBalanceBefore = await getISTBalance(PROVISIONING_POOL_ADDR);
await bankSend(PROVISIONING_POOL_ADDR, `500000${USDC_DENOM}`);

// Check IST balance
await waitUntilAccountFunded(
PROVISIONING_POOL_ADDR,
ambientAuthority,
{ denom: 'uist', value: istBalanceBefore + 500000 },
{ errorMessage: 'Provision pool not able to swap USDC_axl for IST.' },
);

// Introduce USD_LEMONS
await evalBundles(ADD_PSM_DIR);
await waitUntilContractDeployed('psm-IST-USD_LEMONS', ambientAuthority, {
errorMessage: 'psm-IST-USD_LEMONS instance not observed.',
});

// Provision the provisionPoolAddress. This is a workaround of provisionPoolAddress
// not having a depositFacet published to namesByAddress. Shouldn't be a problem since
// vat-bank keeps track of virtual purses per address basis. We need there to be
// depositFacet for provisionPoolAddress since we'll fund it with USD_LEMONS
await provision('provisionPoolAddress', PROVISIONING_POOL_ADDR);
await checkUserProvisioned(PROVISIONING_POOL_ADDR);

// Send USD_LEMONS to provisionPoolAddress
const istBalanceBeforeLemonsSent = await getISTBalance(
PROVISIONING_POOL_ADDR,
);
await evalBundles(DEPOSIT_USD_LEMONS_DIR);

// Check balance again
await waitUntilAccountFunded(
PROVISIONING_POOL_ADDR,
ambientAuthority,
{ denom: 'uist', value: istBalanceBeforeLemonsSent + 500000 },
{ errorMessage: 'Provision pool not bale swap USDC_axl for IST.' },
);
t.pass();
});
20 changes: 20 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/test-lib/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @file Copied from "@agoric/internal"
*/

import { q } from '@endo/errors';

/**
* @template T
* @param {T | null | undefined} val
* @param {string} [optDetails]
* @returns {T}
*/
export const NonNullish = (val, optDetails = `unexpected ${q(val)}`) => {
if (val != null) {
// This `!= null` idiom checks that `val` is neither `null` nor `undefined`.
return val;
}
assert.fail(optDetails);
};
harden(NonNullish);
Loading

0 comments on commit b8800c9

Please sign in to comment.