diff --git a/a3p-integration/proposals/n:upgrade-next/priceFeedUpdate.test.js b/a3p-integration/proposals/n:upgrade-next/priceFeedUpdate.test.js index 557a837be9e..edde68b74b2 100644 --- a/a3p-integration/proposals/n:upgrade-next/priceFeedUpdate.test.js +++ b/a3p-integration/proposals/n:upgrade-next/priceFeedUpdate.test.js @@ -19,6 +19,7 @@ import { } from '@agoric/synthetic-chain'; import { getPriceFeedRoundId, + tryISTBalances, verifyPushedPrice, } from './test-lib/price-feed.js'; @@ -79,16 +80,19 @@ const createNewBid = async t => { }; const openMarginalVault = async t => { - let user1IST = await getISTBalance(USER1ADDR); + const istBalanceBeforeVaultOpen = await getISTBalance(USER1ADDR, 'uist', 1); await bankSend(USER1ADDR, `20000000${ATOM_DENOM}`); const currentVaults = await agops.vaults('list', '--from', USER1ADDR); t.log('opening a vault'); // @ts-expect-error bad typedef await openVault(USER1ADDR, 5, 10); - user1IST += 5; - const istBalanceAfterVaultOpen = await getISTBalance(USER1ADDR); - t.is(istBalanceAfterVaultOpen, user1IST); + const istBalanceAfterVaultOpen = await getISTBalance(USER1ADDR, 'uist', 1); + await tryISTBalances( + t, + istBalanceAfterVaultOpen, + istBalanceBeforeVaultOpen + 5_000_000, // in uist + ); const activeVaultsAfter = await agops.vaults('list', '--from', USER1ADDR); t.log(currentVaults, activeVaultsAfter); diff --git a/a3p-integration/proposals/n:upgrade-next/test-lib/price-feed.js b/a3p-integration/proposals/n:upgrade-next/test-lib/price-feed.js index 0fefd5ca52e..69cd3150f3f 100644 --- a/a3p-integration/proposals/n:upgrade-next/test-lib/price-feed.js +++ b/a3p-integration/proposals/n:upgrade-next/test-lib/price-feed.js @@ -60,3 +60,32 @@ export const getPriceFeedRoundId = async brand => { console.log(latestRoundPath, latestRound); return Number(latestRound.roundId); }; + +/** + * Copy from https://github.com/Agoric/agoric-sdk/blob/745f2a82cc94e246f98dd1bd69cb679b608a7170/a3p-integration/proposals/p%3Aupgrade-19/test-lib/psm-lib.js#L277 + * + * Checking IST balances can be tricky because of the execution fee mentioned in + * https://github.com/Agoric/agoric-sdk/issues/6525. So we first check for + * equality, but if that fails we recheck against an assumption that a fee of + * the default "minFeeDebit" has been charged. + * + * @param {import('ava').ExecutionContext} t + * @param {number} actualBalance + * @param {number} expectedBalance + */ +export const tryISTBalances = async (t, actualBalance, expectedBalance) => { + const firstTry = await t.try(tt => { + tt.is(actualBalance, expectedBalance); + }); + if (firstTry.passed) { + firstTry.commit(); + return; + } + + firstTry.discard(); + t.log('tryISTBalances assuming no batched IST fee', ...firstTry.errors); + // See golang/cosmos/x/swingset/types/default-params.go + // and `ChargeBeans` in golang/cosmos/x/swingset/keeper/keeper.go. + const minFeeDebit = 200_000; + t.is(actualBalance + minFeeDebit, expectedBalance); +};