Skip to content

Commit

Permalink
chore(acceptance): fix potential flake openMarginalVault
Browse files Browse the repository at this point in the history
Refs: #10774
  • Loading branch information
anilhelvaci committed Dec 30, 2024
1 parent 745f2a8 commit b175b2b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
12 changes: 8 additions & 4 deletions a3p-integration/proposals/n:upgrade-next/priceFeedUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@agoric/synthetic-chain';
import {
getPriceFeedRoundId,
tryISTBalances,
verifyPushedPrice,
} from './test-lib/price-feed.js';

Expand Down Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions a3p-integration/proposals/n:upgrade-next/test-lib/price-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit b175b2b

Please sign in to comment.