From 7f8d01087fc7f5ffe0b557464920e259dbbef9da Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 17 Apr 2025 22:36:55 +0800 Subject: [PATCH] add retries and sleep time --- evm-tests/package.json | 2 +- evm-tests/src/subtensor.ts | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/evm-tests/package.json b/evm-tests/package.json index d03300f32f..45f03c0b49 100644 --- a/evm-tests/package.json +++ b/evm-tests/package.json @@ -1,6 +1,6 @@ { "scripts": { - "test": "mocha --timeout 999999 --file src/setup.ts --require ts-node/register test/*test.ts" + "test": "mocha --timeout 999999 --retries 3 --file src/setup.ts --require ts-node/register test/*test.ts" }, "keywords": [], "author": "", diff --git a/evm-tests/src/subtensor.ts b/evm-tests/src/subtensor.ts index 0866c790a9..94b10dee95 100644 --- a/evm-tests/src/subtensor.ts +++ b/evm-tests/src/subtensor.ts @@ -38,9 +38,21 @@ export async function forceSetBalanceToSs58Address(api: TypedApi, const internalCall = api.tx.Balances.force_set_balance({ who: MultiAddress.Id(ss58Address), new_free: balance }) const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall }) - await waitForTransactionCompletion(api, tx, alice) - .then(() => { }) - .catch((error) => { console.log(`transaction error ${error}`) }); + let failed = true; + let retries = 0; + + // set max retries times + while (failed && retries < 5) { + failed = false + await waitForTransactionCompletion(api, tx, alice) + .then(() => { }) + .catch((error) => { + failed = true + console.log(`transaction error ${error}`) + }); + await new Promise((resolve) => setTimeout(resolve, 1000)); + retries += 1 + } const balanceOnChain = (await api.query.System.Account.getValue(ss58Address)).data.free // check the balance except for sudo account becasue of tx fee @@ -155,6 +167,7 @@ export async function disableWhiteListCheck(api: TypedApi, disabl } export async function burnedRegister(api: TypedApi, netuid: number, ss58Address: string, keypair: KeyPair) { + await new Promise((resolve) => setTimeout(resolve, 1000)); const uids = await api.query.SubtensorModule.SubnetworkN.getValue(netuid) const signer = getSignerFromKeypair(keypair) const tx = api.tx.SubtensorModule.burned_register({ hotkey: ss58Address, netuid: netuid }) @@ -347,8 +360,8 @@ export async function rootRegister(api: TypedApi, ss58Address: st export async function setSubtokenEnable(api: TypedApi, netuid: number, subtokenEnable: boolean) { const signer = getAliceSigner() let internalTx = api.tx.AdminUtils.sudo_set_subtoken_enabled({ - netuid: netuid, - subtoken_enabled: subtokenEnable + netuid: netuid, + subtoken_enabled: subtokenEnable }) let tx = api.tx.Sudo.sudo({ call: internalTx.decodedCall }) @@ -371,11 +384,16 @@ export async function startCall(api: TypedApi, netuid: number, ke const signer = getSignerFromKeypair(keypair) let tx = api.tx.SubtensorModule.start_call({ - netuid: netuid, + netuid: netuid, }) await waitForTransactionCompletion(api, tx, signer) .then(() => { }) .catch((error) => { console.log(`transaction error ${error}`) }); + await new Promise((resolve) => setTimeout(resolve, 1000)); + const callStarted = await api.query.SubtensorModule.FirstEmissionBlockNumber + .getValue(netuid); + assert.notEqual(callStarted, undefined); + } \ No newline at end of file