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

Run e2e testnet tests via GHA, not Kubernetes #98

Merged
merged 22 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
176ef31
Run e2e testnet tests on Ropsten via GHA, not Kubernetes
michalinacienciala Jul 5, 2021
5655dac
Change value of the CHAIN_API_URL
michalinacienciala Jul 28, 2021
dafcd52
Install latest version of `tbtc.js` package with `ropsten` tag
michalinacienciala Jul 30, 2021
0d82f27
Pass BTC depositor priv key
lukasz-zimnoch Aug 3, 2021
15b3305
Save testnet BTC
lukasz-zimnoch Aug 4, 2021
38bcc53
Use higher lot size
lukasz-zimnoch Aug 4, 2021
bac8d28
Change names of the secrets used in the workflow
michalinacienciala Aug 5, 2021
0cc2ea5
Modify cron - execute daily
michalinacienciala Aug 5, 2021
0b4359e
Add a comment about using `setup-node`'s cache functionality
michalinacienciala Aug 5, 2021
48f75f5
Handle deposit `autoSubmit` errors
lukasz-zimnoch Aug 5, 2021
27f8ab2
Simplify handling of `autoSubmit` errors
lukasz-zimnoch Aug 5, 2021
4e37329
Merge remote-tracking branch 'origin/rfc-18/move-e2e-kubernetes-job-t…
michalinacienciala Aug 9, 2021
283b348
Merge pull request #104 from keep-network/rename-keep-test-eth-hostna…
nkuba Aug 9, 2021
5e00f7a
Exit the script when `onError` callback is hit
lukasz-zimnoch Aug 11, 2021
724cca1
Cache npm dependencies via setup-node action
michalinacienciala Aug 17, 2021
42906be
Add block number information to e2e test
lukasz-zimnoch Aug 18, 2021
77d4a05
Fix block fetching logic in e2e test
lukasz-zimnoch Aug 18, 2021
101f02c
Display source account balance
lukasz-zimnoch Aug 18, 2021
673315e
Improve log formatting
lukasz-zimnoch Aug 18, 2021
68a9902
Increase fee overhead
lukasz-zimnoch Aug 23, 2021
152e9f0
Run four times a day
lukasz-zimnoch Aug 24, 2021
7e7319d
Remove script options values log
lukasz-zimnoch Aug 24, 2021
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
33 changes: 33 additions & 0 deletions .github/workflows/e2e-testnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: E2E tests / Testnet

on:
schedule:
- cron: '0 */6 * * *'
workflow_dispatch:

jobs:
e2e-testnet-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./e2e
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: "14.x"
cache: "npm"
cache-dependency-path: e2e/package-lock.json

- run: npm install --save-exact @keep-network/tbtc.js@ropsten

- name: Run e2e tests
run: |
./e2e-test.js \
--bitcoin-electrum-host=${{ secrets.KEEP_TEST_ELECTRUMX_HOSTNAME }} \
--bitcoin-electrum-port=${{ secrets.KEEP_TEST_ELECTRUMX_PORT }} \
--bitcoin-network="testnet" \
--bitcoin-depositor-pk=${{ secrets.KEEP_TEST_BTC_DEPOSITOR_PK }} \
--ethereum-node=${{ secrets.KEEP_TEST_ETH_HOSTNAME_WS }} \
--lot-size-satoshis="10000"
11 changes: 0 additions & 11 deletions deployments/e2e-test/e2e-test-configmap.yml

This file was deleted.

69 changes: 0 additions & 69 deletions deployments/e2e-test/e2e-test-cronjob.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions deployments/e2e-test/e2e-test-secret.yml.SAMPLE

This file was deleted.

15 changes: 11 additions & 4 deletions e2e/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ export const sendBitcoinTransaction = async(
) => {
const sourceAddress = keyRing.getAddress("string");

console.log(`Sending transaction from ${sourceAddress} to ${targetAddress}`)
const sourceAddressBalance = await BitcoinHelpers.Transaction.getBalance(
sourceAddress
)

console.log(
`Sending transaction from ${sourceAddress} to ${targetAddress}\n` +
`BTC balance of source address is ${sourceAddressBalance}`
)

const utxos = await BitcoinHelpers.Transaction.findAllUnspent(sourceAddress)

Expand All @@ -60,10 +67,10 @@ export const sendBitcoinTransaction = async(

// Start from the oldest UTXO.
for (const utxo of utxos.reverse()) {
// Make sure the selected coins amount covers the 110% of the amount.
// The additional 10% is taken as a big reserve to make sure that input
// Make sure the selected coins amount covers the 120% of the amount.
// The additional 20% is taken as a big reserve to make sure that input
// coins will cover the transaction fee.
if (coinsAmount >= 1.1 * amount.toNumber()) {
if (coinsAmount >= 1.2 * amount.toNumber()) {
break
}

Expand Down
35 changes: 28 additions & 7 deletions e2e/e2e-test.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node --experimental-modules
#!/usr/bin/env -S node --experimental-json-modules

import Web3 from "web3"
import ProviderEngine from "web3-provider-engine"
Expand Down Expand Up @@ -33,9 +33,6 @@ program
.option('--lot-size-satoshis <lot>', "lot size in satoshis", (lot) => parseInt(lot, 10), 1000000)
.parse(process.argv)

console.log("\nScript options values: ", program.opts(), "\n")

const depositsCount = 2
const signerFeeDivisor = 0.0005 // 0.05%
const satoshiMultiplier = 10000000000 // 10^10
const tbtcDepositAmount = program.lotSizeSatoshis * satoshiMultiplier
Expand Down Expand Up @@ -72,6 +69,18 @@ async function run() {
}
})

const btcBlock = await BitcoinHelpers.withElectrumClient(
async electrumClient => {
return electrumClient.latestBlockHeight()
}
)

const ethBlock = await web3.eth.getBlockNumber()

console.log(
`Starting e2e test at BTC block ${btcBlock} and ETH block ${ethBlock}`
)

const bitcoinWalletDB = new bcoin.WalletDB({db: 'memory'})
await bitcoinWalletDB.open()
const bitcoinWallet = await bitcoinWalletDB.create()
Expand All @@ -93,9 +102,18 @@ async function run() {
web3.eth.defaultAccount
)

// When a deposit is opened, the total tBTC value received by the requester
// is smaller than the deposit amount due to the signer fee. On the other
// hand, the redeemer needs to provide an exact deposit amount to redeem
// a deposit. Because of that, we need to check the account's tBTC balance
// and open two deposits if the amount doesn't allow to make the redemption.
const depositsCount =
initialTbtcAccountBalance.lt(web3.utils.toBN(tbtcDepositAmount)) ? 2 : 1

console.log(
`Initial TBTC balance for account ${web3.eth.defaultAccount} ` +
`is: ${initialTbtcAccountBalance}`
`is: ${initialTbtcAccountBalance} - ${depositsCount} deposit(s) ` +
`will be opened`
)

const deposits = []
Expand Down Expand Up @@ -189,6 +207,11 @@ async function createDeposit(tbtc, satoshiLotSize, keyRing) {
web3.utils.toBN(satoshiLotSize)
)

deposit.onError((err) => {
console.error(err)
process.exit(1)
})

deposit.autoSubmit()

return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -242,8 +265,6 @@ async function redeemDeposit(tbtc, depositAddress, redeemerAddress) {
redemption.autoSubmit()

redemption.onWithdrawn(transactionID => {
console.log()

resolve(
`Redeemed deposit ${deposit.address} with Bitcoin transaction ` +
`${transactionID}.`
Expand Down