Skip to content

Commit

Permalink
test: add retry logic to provisionSmartWallet
Browse files Browse the repository at this point in the history
- motivated after observing "cannot read data of published.wallet.agoric1ujmk0492mauq2f2vrcn7ylq3w3x55k0ap9mt2p.current: fetch failed"
  in https://github.com/Agoric/agoric-sdk/actions/runs/12313012295/job/34369641775?pr=10638
- this likely indicates a race between `provision-one`, the vstorage update, or the RPCs view of vstorage
- to address this, retry the vstorage query with `retryUntilCondition`
  • Loading branch information
0xpatrickdev committed Dec 13, 2024
1 parent d35659b commit 6b6a241
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
16 changes: 6 additions & 10 deletions multichain-testing/test/fast-usdc/fast-usdc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ test.before(async t => {
const wallets = await setupTestKeys(accounts, values(oracleMnemonics));

// provision oracle wallets first so invitation deposits don't fail
const oracleWdPs = keys(oracleMnemonics).map(n =>
provisionSmartWallet(wallets[n], {
BLD: 100n,
}),
const oracleWds = await Promise.all(
keys(oracleMnemonics).map(n =>
provisionSmartWallet(wallets[n], {
BLD: 100n,
}),
),
);
// execute sequentially, to avoid "published.wallet.${addr}.current: fetch failed"
const oracleWds: WalletDriver[] = [];
for (const p of oracleWdPs) {
const wd = await p;
oracleWds.push(wd);
}

// calculate denomHash and channelId for privateArgs / builder opts
const { getTransferChannelId, toDenomHash } = makeDenomTools(chainInfo);
Expand Down
18 changes: 16 additions & 2 deletions multichain-testing/tools/e2e-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import { flags, makeAgd, makeCopyFiles } from './agd-lib.js';
import { makeHttpClient, makeAPI } from './makeHttpClient.js';
import { dedup, makeQueryKit, poll } from './queryKit.js';
import { makeVStorage } from './batchQuery.js';
import { makeRetryUntilCondition } from './sleep.js';

/** @import { EnglishMnemonic } from '@cosmjs/crypto'; */
/**
* @import { EnglishMnemonic } from '@cosmjs/crypto';
* @import { RetryUntilCondition } from './sleep.js';
*/

const BLD = '000000ubld';

Expand Down Expand Up @@ -121,6 +125,7 @@ const installBundle = async (fullPath, opts) => {
* blockTool: BlockTool;
* lcd: import('./makeHttpClient.js').LCD;
* delay: (ms: number) => Promise<void>;
* retryUntilCondition: RetryUntilCondition;
* chainId?: string;
* whale?: string;
* progress?: typeof console.log;
Expand All @@ -139,6 +144,7 @@ export const provisionSmartWallet = async (
whale = 'faucet',
progress = console.log,
q = makeQueryKit(makeVStorage(lcd)).query,
retryUntilCondition,
},
) => {
// TODO: skip this query if balances is {}
Expand Down Expand Up @@ -187,7 +193,12 @@ export const provisionSmartWallet = async (
{ chainId, from: address, yes: true },
);

const info = await q.queryData(`published.wallet.${address}.current`);
const info = await retryUntilCondition(
() => q.queryData(`published.wallet.${address}.current`),
result => !!result,
`wallet in vstorage ${address}`,
{ log: () => {} }, // suppress logs as this is already noisy
);
progress({
provisioned: address,
purses: info.purses.length,
Expand Down Expand Up @@ -428,6 +439,7 @@ const runCoreEval = async (
* @param {string} [io.rpcAddress]
* @param {string} [io.apiAddress]
* @param {(...parts: string[]) => string} [io.join]
* * @param {RetryUntilCondition} [io.retryUntilCondition]
*/
export const makeE2ETools = async (
log,
Expand All @@ -438,6 +450,7 @@ export const makeE2ETools = async (
setTimeout,
rpcAddress = 'http://localhost:26657',
apiAddress = 'http://localhost:1317',
retryUntilCondition = makeRetryUntilCondition({ log, setTimeout }),
},
) => {
const agd = makeAgd({ execFileSync }).withOpts({ keyringBackend: 'test' });
Expand Down Expand Up @@ -535,6 +548,7 @@ export const makeE2ETools = async (
lcd,
delay,
q: vstorageClient,
retryUntilCondition,
}),
/**
* @param {string} name
Expand Down
6 changes: 3 additions & 3 deletions multichain-testing/tools/sleep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const retryUntilCondition = async <T>(
{
maxRetries = 6,
retryIntervalMs = 3500,
log = () => {},
log = console.log,
setTimeout = ambientSetTimeout,
}: RetryOptions = {},
): Promise<T> => {
console.log({ maxRetries, retryIntervalMs, message });
log({ maxRetries, retryIntervalMs, message });
let retries = 0;

while (retries < maxRetries) {
Expand All @@ -50,7 +50,7 @@ const retryUntilCondition = async <T>(
}

retries++;
console.log(
log(
`Retry ${retries}/${maxRetries} - Waiting for ${retryIntervalMs}ms for ${message}...`,
);
await sleep(retryIntervalMs, { log, setTimeout });
Expand Down

0 comments on commit 6b6a241

Please sign in to comment.