Skip to content

Commit

Permalink
Add retries in deploy contract script to avoid false positive alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmanzanera committed Dec 15, 2023
1 parent 3bac720 commit 5b104bb
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions deploy_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,11 @@ async function run() {

logger.debug(`Contract's call transaction created - ${Utils.uint8ArrayToHex(callTx.address)}`)

await new Promise(r => setTimeout(r, 2000));

const { lastTransaction: { data: { content: lastContent } } } = await archethic.network.rawGraphQLQuery(`
query
{
lastTransaction(address: "${Utils.uint8ArrayToHex(contractTx.address)}") {
data {
content
}
}
}`)

if (lastContent != "Contract executed") {
reject(`Contract self trigger transaction not executed`)
return
}

resolve("Contract's call transaction executed with success")
return
awaitTriggeredTransaction(archethic, contractTx.address)
.then(() => {
resolve("Contract's call transaction executed with success")
})
.catch(reject)
})
.send()
})
Expand All @@ -147,6 +133,28 @@ async function run() {
})
}

async function awaitTriggeredTransaction(archethic, contractAddress, retries = 0) {
await new Promise(r => setTimeout(r, 3000));
const { lastTransaction: { data: { content: lastContent } } } = await archethic.network.rawGraphQLQuery(`query
{
lastTransaction(address: "${Utils.uint8ArrayToHex(contractAddress)}") {
data {
content
}
}
}`)

if (lastContent != "Contract executed") {
if (retries == 3) {
throw "Contract self trigger transaction not executed"
}
else {
logger.info(`Retry attempt #${retries + 1}`)
await awaitTriggeredTransaction(archethic, contractAddress, retries + 1)
}
}
}

run()
.then((msg) => {
logger.info(msg)
Expand Down

0 comments on commit 5b104bb

Please sign in to comment.