Skip to content

Commit

Permalink
chore: cleanup test etc. based on commnts
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jun 12, 2024
1 parent 7b3eea8 commit 997d72c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 72 deletions.
33 changes: 0 additions & 33 deletions a3p-integration/proposals/a:upgrade-next/localchain.test.js

This file was deleted.

37 changes: 19 additions & 18 deletions a3p-integration/proposals/a:upgrade-next/provisionPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const PROVISIONING_POOL_ADDR = 'agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346';

/**
* @file
* The problems to be addressed are that provisionPool won't correctly handle
* (#8722) deposit of assets after it (provisionPool) is upgraded, or (#8724)
* The problem to be addressed is that provisionPool won't correctly handle
* (#8722) deposit of assets after it (provisionPool) is upgraded or (#8724)
* new asset kinds after vat-bank is upgraded.
*
* To test this, we will
Expand All @@ -31,14 +31,17 @@ const PROVISIONING_POOL_ADDR = 'agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346';
*
* 2. Null upgrade vat-bank, and see that we can add a new collateal.
*
* 2a. if we had been able to null-upgrade provisionPool at this point, we
* wouldn't have been able to productively add USDC, but the null upgrade fails.
* 2a. Not null upgrade provisionPool, since it would fail. If it had succeeded,
* we would have been able to observe the effect of #8724, which would have
* caused addition of new currencies to be ignored.
*
* 3. Do a full upgrade of provisionPool; then deposit USDC, and see IST
* incremented in totalMintedConverted.
*
* 4. Null upgrade vat-bank again, and then see (in logs) that adding a new
* asset type gives the ability to make deposits.
* asset type gives the ability to make deposits. We don't actually add it
* because it would be too much work to add a faucet or other ability to mint
* the new collateral.
*/

const contributeToPool = async (t, asset, expectedToGrow) => {
Expand Down Expand Up @@ -69,33 +72,31 @@ const contributeToPool = async (t, asset, expectedToGrow) => {
}
};

test.serial('add assets before', async t => {
test('upgrading provisionPool and vat-bank', async t => {
t.log('add assets before');
await contributeToPool(t, `10000${USDC_DENOM}`, true);
});

test.serial(`upgrade Bank`, async t => {
t.log(`upgrade Bank`);
await evalBundles(NULL_UPGRADE_BANK_DIR);

const incarnation = await getIncarnation('bank');
t.is(incarnation, 1);
const firstIncarnation = await getIncarnation('bank');
t.is(firstIncarnation, 1);

await evalBundles(ADD_STARS_DIR);
});
await evalBundles(ADD_LEMONS_DIR);

test.serial('full upgrade ProvisionPool', async t => {
t.log('full upgrade ProvisionPool');
await evalBundles(UPGRADE_PP_DIR);
const ppIncarnation = await getIncarnation('db93f-provisionPool');
t.is(ppIncarnation, 1);

await contributeToPool(t, `30000${USDC_DENOM}`, true);
});

test.serial(`Add assets after bank upgrade`, async t => {
t.log(`Add assets after bank upgrade`);
await evalBundles(NULL_UPGRADE_BANK_DIR);
await waitForBlock(2);

const incarnation = await getIncarnation('bank');
t.is(incarnation, 2);
const secondIncarnation = await getIncarnation('bank');
t.is(secondIncarnation, 2);

await evalBundles(ADD_STARS2_DIR);
await evalBundles(ADD_OLIVES_DIR);
});
51 changes: 31 additions & 20 deletions packages/inter-protocol/src/provisionPoolKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const { details: X, quote: q, Fail } = assert;

const trace = makeTracer('ProvPool');

const FIRST_CAP_ASCII = /^[A-Z][a-zA-Z0-9_$]*$/;
const FIRST_LOWER_ASCII = /^[a-z][a-zA-Z0-9_$]*$/;
const FIRST_UPPER_KEYWORD = /^[A-Z][a-zA-Z0-9_$]*$/;
// see https://github.com/Agoric/agoric-sdk/issues/8238
const FIRST_LOWER_NEAR_KEYWORD = /^[a-z][a-zA-Z0-9_$]*$/;

/**
* @import {ERef} from '@endo/far'
Expand Down Expand Up @@ -102,14 +103,6 @@ export const makeBridgeProvisionTool = (sendInitialPayment, onProvisioned) => {
return makeBridgeHandler;
};

const saveIssuerWithLegalKeyword = (desc, zcf) => {
const bad = desc.issuerName;
const good = bad.replace(bad[0], bad[0].toUpperCase());
trace(`Saved Issuer ${desc.issuerName} with repaired keyword ${good}`);

return zcf.saveIssuer(desc.issuer, good);
};

/**
* @param {import('@agoric/vat-data').Baggage} baggage
* @param {{
Expand Down Expand Up @@ -383,28 +376,46 @@ export const prepareProvisionPoolKit = (
const { facets } = this;
const { helper } = facets;

/** @param {import('@agoric/vats/src/vat-bank.js').AssetDescriptor} desc */
const repairDesc = desc => {
if (desc.issuerName.match(FIRST_UPPER_KEYWORD)) {
trace(`Saving Issuer ${desc.issuerName}`);
return desc;
} else if (desc.issuerName.match(FIRST_LOWER_NEAR_KEYWORD)) {
const bad = desc.issuerName;
const goodName = bad.replace(bad[0], bad[0].toUpperCase());

trace(
`Saving Issuer ${desc.issuerName} with repaired keyword ${goodName}`,
);
return { ...desc, issuerName: goodName };
} else {
console.error(
`unable to save issuer with illegal keyword: ${desc.issuerName}`,
);
return undefined;
}
};

return observeIteration(
subscribeEach(E(poolBank).getAssetSubscription()),
{
updateState: async desc => {
await null;
const issuer = zcf.getTerms().issuers[desc.issuerName];
if (issuer !== desc.issuer) {
if (desc.issuerName.match(FIRST_CAP_ASCII)) {
trace(`Saved Issuer ${desc.issuerName}`);
await zcf.saveIssuer(desc.issuer, desc.issuerName);

// see https://github.com/Agoric/agoric-sdk/issues/8238
} else if (desc.issuerName.match(FIRST_LOWER_ASCII)) {
await saveIssuerWithLegalKeyword(desc, zcf);
if (issuer === desc.issuer) {
trace('provisionPool re-notified of known asset', desc.brand);
} else {
const goodDesc = repairDesc(desc);
if (goodDesc) {
await zcf.saveIssuer(goodDesc.issuer, goodDesc.issuerName);
} else {
console.error(
`unable to save issuer with illegal keyword: ${desc.issuerName}`,
);
}
} else {
trace('provisionPool re-notified of known asset', desc.brand);
}

/** @type {ERef<Purse>} */
const exchangePurse = E(poolBank).getPurse(desc.brand);
helper.watchCurrentAmount(exchangePurse, desc.brand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const upgradeProvisionPool = async (
instancePrivateArgsP,
]);
const { adminFacet, instance } = provisionPoolStartResult;
// const privateArgs = await deeplyFulfilled(instancePrivateArgs.get(instance));

const [originalPrivateArgs, poserInvitation] = await Promise.all([
deeplyFulfilled(instancePrivateArgs.get(instance)),
Expand Down

0 comments on commit 997d72c

Please sign in to comment.