Skip to content

Commit

Permalink
Merge pull request #38 from keep-network/e2e-gh-action-config
Browse files Browse the repository at this point in the history
Adding retries to get redemption cost
  • Loading branch information
lukasz-zimnoch authored Aug 19, 2020
2 parents b42b904 + 3e9a4d3 commit 9dd6d3a
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions e2e/e2e-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function run() {

let htmlContent = ''
let allCreatedEventCount = 1;
// let e2eTestCreatedEventCount = 1
let e2eTestCreatedEventCount = 1

for (const createdEvent of createdDepositEvents) {
console.log("created event count: ", allCreatedEventCount)
Expand All @@ -92,13 +92,13 @@ async function run() {
const depositOwner = await deposit.getOwner()

// filter deposits that were created by e2e-test.js
// if (depositOwner === web3.eth.defaultAccount) {
// console.log("e2e-test created event count: ", e2eTestCreatedEventCount)
if (depositOwner === web3.eth.defaultAccount) {
console.log("e2e-test created event count: ", e2eTestCreatedEventCount)

console.log("getting current state...")
const currentState = await deposit.getCurrentState()

// e2eTestCreatedEventCount++
e2eTestCreatedEventCount++
allCreatedEventCount++

let bitcoinAddress = ''
Expand Down Expand Up @@ -135,8 +135,6 @@ async function run() {
createdDepositBlockNumber = await createdEvent.blockNumber
console.log("getting signer fee TBTC...")
signerFee = await deposit.getSignerFeeTBTC()
console.log("getting redemption cost...")
redemptionCost = await deposit.getRedemptionCost()
console.log("getting balance of deposit...")
tbtcAccountBalance = await tbtc.Deposit.tokenContract.methods.balanceOf(depositAddress).call()
console.log("getting bond amount...")
Expand All @@ -159,6 +157,32 @@ async function run() {
continue;
}

const totalAttempts = 5
for (let attempt = 1; attempt <= totalAttempts; attempt++) {
try {
console.log("getting redemption cost...")
redemptionCost = await deposit.getRedemptionCost()
break;
} catch (err) {
if (attempt === totalAttempts) {
console.debug(`last attempt ${attempt} failed while getting redemption cost`)
redemptionCost = `<div style="background-color:red">` + err + `</div>`
continue;
}

const backoffMillis = Math.pow(2, attempt) * 1000
const jitterMillis = Math.floor(Math.random() * 100)
const waitMillis = backoffMillis + jitterMillis

console.log(
`attempt ${attempt} failed while getting redemption cost; ` +
`retrying after ${waitMillis} milliseconds`
)

await new Promise(resolve => setTimeout(resolve, waitMillis))
}
}

htmlContent +=
`
<tr>
Expand All @@ -181,9 +205,9 @@ async function run() {
console.log("tbtcAccountBalance: ", tbtcAccountBalance.toString())
console.log("keepAddress: ", keepAddress)
console.log("keepBondAmount: ", keepBondAmount.toString())
// } else {
// allCreatedEventCount++
// }
} else {
allCreatedEventCount++
}
}

fs.writeFileSync('./site/index.html', await buildHtml(htmlContent));
Expand Down

0 comments on commit 9dd6d3a

Please sign in to comment.