Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping bitcoin address that takes too long too get and improvements #31

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e-summary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
--bitcoin-electrum-host 34.70.251.19 \
--bitcoin-electrum-port 8080 \
--bitcoin-network testnet \
--ethereum-node wss://ropsten.infura.io/ws/v3/c7d9a83a904d440ba19a7acda98f4c72 \
--ethereum-node wss://ropsten.infura.io/ws/v3/a6e0ba36c6b44333bd56c5c8cc681cc3 \
--ethereum-pk 033cea2b77cbd50c02cbc57573cf4389b8c785642c2107c7e1614df9876b787b \
--blocks-timespan 500

Expand Down
125 changes: 77 additions & 48 deletions e2e/e2e-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function run() {
const fromBlock = currentBlockNumber - program.blocksTimespan

const createdDepositEvents = await tbtc.Deposit.systemContract.getPastEvents("Created", {fromBlock: fromBlock, toBlock: "latest"})
console.log("number of created deposit events: ", createdDepositEvents.length)
console.log("number of 'Created' deposit events: ", createdDepositEvents.length)

const signingGroupFormationTimeout = await tbtc.Deposit.constantsContract.methods.getSigningGroupFormationTimeout().call()
const signingTimeout = await tbtc.Deposit.constantsContract.methods.getSignatureTimeout().call()
Expand All @@ -89,56 +89,64 @@ async function run() {
console.log("event count: ", count)
const depositAddress = createdEvent.returnValues._depositContractAddress
const keepAddress = createdEvent.returnValues._keepAddress

console.log("getting deposit...")
const deposit = await tbtc.Deposit.withAddress(depositAddress)

const depositOwner = await deposit.getOwner()
// const depositOwner = await deposit.getOwner()
// console.log("after getting deposit owner...")

// filter deposits that were created by e2e-test.js
// if (depositOwner === web3.eth.defaultAccount) {
console.log("getting current state...")
const currentState = await deposit.getCurrentState()

if (currentState === depositStates['AWAITING_SIGNER_SETUP']) {
if (toBN(currentTimestamp).gt(toBN(createdEvent.returnValues._timestamp).add(toBN(signingTimeout)))) {
console.log("notifySignerSetupFailed() call...")
try {
await deposit.contract.methods.notifySignerSetupFailed().call()
htmlContent +=
`
<tr bgcolor="red">
<td colspan="3">` + "depositAddress: " + depositAddress + `</td>
<td colspan="3">` + "keepAddress: " + keepAddress + `</td>
<td colspan="3">` + depositStatesInverted[currentState] + `</td>
</tr>
`
count++
continue
} catch (err) {
console.log(err)
}
}
}
// if (currentState === depositStates['AWAITING_SIGNER_SETUP']) {
// if (toBN(currentTimestamp).gt(toBN(createdEvent.returnValues._timestamp).add(toBN(signingTimeout)))) {
// console.log("notifySignerSetupFailed() call...")
// try {
// await deposit.contract.methods.notifySignerSetupFailed().call()
// htmlContent +=
// `
// <tr bgcolor="red">
// <td colspan="3">` + "depositAddress: " + depositAddress + `</td>
// <td>` + depositStatesInverted[currentState] + `</td>
// <td colspan="3">notifySignerSetupFailed() call... </td>
// <td>` + keepAddress + `</td>
// <td></td>
// </tr>
// `
// count++
// continue
// } catch (err) {
// console.log(err)
// }
// }
// }

if (currentState === depositStates['AWAITING_WITHDRAWAL_SIGNATURE']) {
const redemptionRequestedAt = await getTimeOfEvent("RedemptionRequested", depositAddress)
if (toBN(currentTimestamp).gt(toBN(redemptionRequestedAt).add(toBN(signingGroupFormationTimeout)))) {
console.log("notifyRedemptionSignatureTimedOut() call...")
try {
await deposit.contract.methods.notifyRedemptionSignatureTimedOut().call()
htmlContent +=
`
<tr bgcolor="red">
<td colspan="3">` + "depositAddress: " + depositAddress + `</td>
<td colspan="3">` + "keepAddress: " + keepAddress + `</td>
<td colspan="3">` + depositStatesInverted[currentState] + `</td>
</tr>
`
count++
continue
} catch(err) {
console.log(err)
}
}
}
// if (currentState === depositStates['AWAITING_WITHDRAWAL_SIGNATURE']) {
// const redemptionRequestedAt = await getTimeOfEvent("RedemptionRequested", depositAddress)
// if (toBN(currentTimestamp).gt(toBN(redemptionRequestedAt).add(toBN(signingGroupFormationTimeout)))) {
// console.log("notifyRedemptionSignatureTimedOut() call...")
// try {
// await deposit.contract.methods.notifyRedemptionSignatureTimedOut().call()
// htmlContent +=
// `
// <tr bgcolor="red">
// <td colspan="3">` + "depositAddress: " + depositAddress + `</td>
// <td>` + depositStatesInverted[currentState] + `</td>
// <td colspan="3">notifyRedemptionSignatureTimedOut() call... </td>
// <td>` + keepAddress + `</td>
// <td></td>
// </tr>
// `
// count++
// continue
// } catch(err) {
// console.log(err)
// }
// }
// }
count++

let bitcoinAddress = ''
Expand All @@ -149,25 +157,39 @@ async function run() {
let tbtcAccountBalance = ''
let keepBondAmount = ''

const waitingTimeForPublicKey = 30*1000 //30sec

try {
bitcoinAddress = await deposit.getBitcoinAddress()
console.log("getting bitcoin address...")
bitcoinAddress = await getBitcoinAddressTimeout(deposit, waitingTimeForPublicKey)
console.log("getting block number...")
createdDepositBlockNumber = await createdEvent.blockNumber
console.log("getting lot size satoshis...")
satoshiLotSize = (await deposit.getLotSizeSatoshis()).toString()
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...")
keepBondAmount = await deposit.keepContract.methods.checkBondAmount().call()
console.log("retrieved all data...")
} catch(err) {
htmlContent +=
`
<tr bgcolor="#ff8000">
<td colspan="9">` + err + `</td>
<td colspan="3">` + "depositAddress: " + depositAddress + `</td>
<td>` + depositStatesInverted[currentState] + `</td>
<td colspan="3">waiting for bitcoin address takes too long </td>
<td>` + keepAddress + `</td>
<td></td>
</tr>
`
console.log(err)
continue
console.log("getting info err: ", err)
continue;
}

htmlContent +=
`
<tr>
Expand Down Expand Up @@ -198,6 +220,13 @@ async function run() {
fs.writeFileSync('./site/index.html', await buildHtml(htmlContent));
}

function getBitcoinAddressTimeout(deposit, timeout) {
return new Promise(function(resolve, reject) {
deposit.getBitcoinAddress().then(resolve, reject);
setTimeout(reject, timeout);
});
}

async function getTimeOfEvent(eventName, depositAddress) {
const event = (
await tbtc.depositFactory.systemContract.getPastEvents(eventName, {
Expand Down