Skip to content

Commit

Permalink
fix: waitForBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Feb 3, 2025
1 parent 8a7ed84 commit 7aff123
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions multichain-testing/tools/e2e-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,25 @@ const makeBlockTool = ({ rpc, delay }) => {
}
};

let last;
const waitForBlock = async (times = 1, info = {}) => {
/**
* @param {number} [advance] number of blocks to wait for
* @param {object} [info] add to logging
* @returns {Promise<void>}
*/
const waitForBlock = async (advance = 1, info = {}) => {
await null;
for (let time = 0; time < times; time += 1) {
for (;;) {
const cur = await waitForBootstrap(2000, { ...info, last });

if (cur !== last) {
last = cur;
break;
}

await delay(1000, info);
}
time += 1;
const startHeight = await waitForBootstrap();
for (
let latestHeight = startHeight;
latestHeight < startHeight + advance;

) {
// Give some time for a new block
await delay(1000, { ...info, latestHeight });
latestHeight = await waitForBootstrap(2000, {
...info,
startHeight,
});
}
};

Expand Down Expand Up @@ -171,11 +175,13 @@ export const provisionSmartWallet = async (
progress({ send: balances, to: address });

/**
* Submit the `bank send` and wait for the next block.
* (Clients have an obligation not to submit >1 tx/block.)
*
* @param {string} denom
* @param {bigint} value
*/
const sendFromWhale = async (denom, value) => {
trace('sendFromWhale', address, denom, value);
const amount = `${value}${denom}`;
progress({ amount, to: address });
// TODO: refactor agd.tx to support a per-sender object
Expand All @@ -186,7 +192,7 @@ export const provisionSmartWallet = async (
from: whale,
yes: true,
});
await blockTool.waitForBlock(1, { step: 'bank send' });
await blockTool.waitForBlock(1, { address, step: 'bank send' });
};

for await (const [name, qty] of Object.entries(balances)) {
Expand Down

0 comments on commit 7aff123

Please sign in to comment.