From 176ef313dea1a54dbc9b8337a1b70fb4cfdfbbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michalina=20Ciencia=C5=82a?= Date: Mon, 5 Jul 2021 08:22:48 +0200 Subject: [PATCH 01/20] Run e2e testnet tests on Ropsten via GHA, not Kubernetes We were running E2E tests on testnet (Ropsten) using Kubernetes. But as the GitHub Actions provide better visibility for the tests results, we decided to move the testing job there. The `e2e-testnet.yml` has been created and the old Kubernetes config has been removed. The currently proposed solution is not ideal. It requires manual updating of the `tbtc.js` version in the workflow config every time new contracts get released. In the future we plan to do that automatically. --- .github/workflows/e2e-testnet.yml | 45 ++++++++++++ deployments/e2e-test/e2e-test-configmap.yml | 11 --- deployments/e2e-test/e2e-test-cronjob.yaml | 69 ------------------- .../e2e-test/e2e-test-secret.yml.SAMPLE | 9 --- e2e/e2e-test.js | 2 +- 5 files changed, 46 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/e2e-testnet.yml delete mode 100644 deployments/e2e-test/e2e-test-configmap.yml delete mode 100644 deployments/e2e-test/e2e-test-cronjob.yaml delete mode 100644 deployments/e2e-test/e2e-test-secret.yml.SAMPLE mode change 100644 => 100755 e2e/e2e-test.js diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml new file mode 100644 index 00000000..f23160c6 --- /dev/null +++ b/.github/workflows/e2e-testnet.yml @@ -0,0 +1,45 @@ +name: E2E tests / Testnet + +on: + schedule: + - cron: '*/20 * * * *' + workflow_dispatch: + pull_request: # TODO: remove this trigger before merging to main + +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" + + # TODO: Temprorarily we use fixed version of tbtc.js. Ultimately, we would + # need to point to the latest deployed version. + - run: npm install --save-exact @keep-network/tbtc.js@0.19.4-ropsten.4 + + - name: Cache Global NPM Cache + uses: actions/cache@v2 + env: + cache-name: cache-global-npm-cache + with: + path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - 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" \ + --ethereum-node=${{ secrets.KEEP_TEST_ETH_HOSTNAME }} \ + --lot-size-satoshis="1000000" diff --git a/deployments/e2e-test/e2e-test-configmap.yml b/deployments/e2e-test/e2e-test-configmap.yml deleted file mode 100644 index 8cf95a59..00000000 --- a/deployments/e2e-test/e2e-test-configmap.yml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: e2e-test-config - namespace: default -data: - bitcoin-electrum-host: "34.70.251.19" - bitcoin-electrum-port: "8080" - bitcoin-network: "testnet" - ethereum-node: "wss://ropsten.infura.io/ws/v3/dfb807704e67496995fa8e824edcc1b5" - lot-size-satoshis: "1000000" diff --git a/deployments/e2e-test/e2e-test-cronjob.yaml b/deployments/e2e-test/e2e-test-cronjob.yaml deleted file mode 100644 index d9cca66f..00000000 --- a/deployments/e2e-test/e2e-test-cronjob.yaml +++ /dev/null @@ -1,69 +0,0 @@ -apiVersion: batch/v1beta1 -kind: CronJob -metadata: - name: e2e-test - namespace: default - labels: - app: tbtc - type: e2e-test -spec: - schedule: '0 */4 * * *' - concurrencyPolicy: Replace - jobTemplate: - metadata: - labels: - app: tbtc - type: e2e-test - spec: - backoffLimit: 0 - template: - spec: - containers: - - name: e2e-test - image: gcr.io/keep-test-f3e0/e2e-test - args: [ - "--bitcoin-electrum-host", "$(BITCOIN_ELECTRUM_HOST)", - "--bitcoin-electrum-port", "$(BITCOIN_ELECTRUM_PORT)", - "--bitcoin-network", "$(BITCOIN_NETWORK)", - "--bitcoin-depositor-pk", "$(BITCOIN_DEPOSITOR_PK)", - "--ethereum-node", "$(ETHEREUM_NODE)", - "--ethereum-pk", "$(ETHEREUM_PK)", - "--lot-size-satoshis", "$(LOT_SIZE_SATOSHIS)" - ] - env: - - name: BITCOIN_ELECTRUM_HOST - valueFrom: - configMapKeyRef: - name: e2e-test-config - key: bitcoin-electrum-host - - name: BITCOIN_ELECTRUM_PORT - valueFrom: - configMapKeyRef: - name: e2e-test-config - key: bitcoin-electrum-port - - name: BITCOIN_NETWORK - valueFrom: - configMapKeyRef: - name: e2e-test-config - key: bitcoin-network - - name: BITCOIN_DEPOSITOR_PK - valueFrom: - secretKeyRef: - name: e2e-test-secret - key: bitcoin-depositor-pk - - name: ETHEREUM_NODE - valueFrom: - configMapKeyRef: - name: e2e-test-config - key: ethereum-node - - name: ETHEREUM_PK - valueFrom: - secretKeyRef: - name: e2e-test-secret - key: ethereum-pk - - name: LOT_SIZE_SATOSHIS - valueFrom: - configMapKeyRef: - name: e2e-test-config - key: lot-size-satoshis - restartPolicy: Never diff --git a/deployments/e2e-test/e2e-test-secret.yml.SAMPLE b/deployments/e2e-test/e2e-test-secret.yml.SAMPLE deleted file mode 100644 index e6eefe5b..00000000 --- a/deployments/e2e-test/e2e-test-secret.yml.SAMPLE +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: e2e-test-secret - namespace: default -type: Opaque -data: - bitcoin-depositor-pk: "base64 encoded Bitcoin depositor private key WIF" - ethereum-pk: "base64 encoded Ethereum account private key" diff --git a/e2e/e2e-test.js b/e2e/e2e-test.js old mode 100644 new mode 100755 index 7ec49caa..d0ce52d4 --- a/e2e/e2e-test.js +++ b/e2e/e2e-test.js @@ -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" From 5655dac07a1e17a0337581197702a7488e0201c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michalina=20Ciencia=C5=82a?= Date: Wed, 28 Jul 2021 11:13:08 +0200 Subject: [PATCH 02/20] Change value of the CHAIN_API_URL We've changed the names of the secrets and need to update the workflow configs accordingly. The change of secret name was introduced to differentiate between WS and HTTP urls. --- .github/workflows/e2e-testnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index f23160c6..cd1e9ef6 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -38,7 +38,7 @@ jobs: - name: Run e2e tests run: | ./e2e-test.js \ - --bitcoin-electrum-host=${{ secrets.KEEP_TEST_ELECTRUMX_HOSTNAME }} \ + --bitcoin-electrum-host=${{ secrets.KEEP_TEST_ELECTRUMX_HOSTNAME_WS }} \ --bitcoin-electrum-port=${{ secrets.KEEP_TEST_ELECTRUMX_PORT }} \ --bitcoin-network="testnet" \ --ethereum-node=${{ secrets.KEEP_TEST_ETH_HOSTNAME }} \ From dafcd52ece296831d24081f1c0b15816a4068ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michalina=20Ciencia=C5=82a?= Date: Fri, 30 Jul 2021 15:36:23 +0200 Subject: [PATCH 03/20] Install latest version of `tbtc.js` package with `ropsten` tag We've started to tag the `tbtc.js` packages with the environment name. We no longer need to manually update the version of this package in the workflow file, instead we'll be allways using the latest version of the package and contracts migrated on `ropsten`. --- .github/workflows/e2e-testnet.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index f23160c6..b9fc772c 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -19,9 +19,7 @@ jobs: with: node-version: "14.x" - # TODO: Temprorarily we use fixed version of tbtc.js. Ultimately, we would - # need to point to the latest deployed version. - - run: npm install --save-exact @keep-network/tbtc.js@0.19.4-ropsten.4 + - run: npm install --save-exact @keep-network/tbtc.js@ropsten - name: Cache Global NPM Cache uses: actions/cache@v2 From 0d82f27a4534ca7d4de54efb346546095bb291db Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Tue, 3 Aug 2021 13:57:52 +0200 Subject: [PATCH 04/20] Pass BTC depositor priv key We need to use a BTC account which has a non-zero BTC balance on testnet. --- .github/workflows/e2e-testnet.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index b9fc772c..84dc7a6b 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -39,5 +39,6 @@ jobs: --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 }} \ --lot-size-satoshis="1000000" From 15b3305ccdcf1771a7055bebae1fe89e128d958b Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Wed, 4 Aug 2021 14:21:37 +0200 Subject: [PATCH 05/20] Save testnet BTC In order to save testnet BTC, we perform some optimizations in the e2e test. First, we open two deposits only when necessary to avoid locking to much of BTC. Secondly, we use the smallest possible lot size. --- .github/workflows/e2e-testnet.yml | 2 +- e2e/e2e-test.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index 84dc7a6b..98d194bd 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -41,4 +41,4 @@ jobs: --bitcoin-network="testnet" \ --bitcoin-depositor-pk=${{ secrets.KEEP_TEST_BTC_DEPOSITOR_PK }} \ --ethereum-node=${{ secrets.KEEP_TEST_ETH_HOSTNAME }} \ - --lot-size-satoshis="1000000" + --lot-size-satoshis="1000" diff --git a/e2e/e2e-test.js b/e2e/e2e-test.js index d0ce52d4..96376d10 100755 --- a/e2e/e2e-test.js +++ b/e2e/e2e-test.js @@ -35,7 +35,6 @@ program 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 @@ -93,9 +92,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 = [] From 38bcc53a35387bb73cfc9898aaa6922630b2eb98 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Wed, 4 Aug 2021 15:43:04 +0200 Subject: [PATCH 06/20] Use higher lot size The bonds amount must cover the setup fee. --- .github/workflows/e2e-testnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index 98d194bd..8e2c6e06 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -41,4 +41,4 @@ jobs: --bitcoin-network="testnet" \ --bitcoin-depositor-pk=${{ secrets.KEEP_TEST_BTC_DEPOSITOR_PK }} \ --ethereum-node=${{ secrets.KEEP_TEST_ETH_HOSTNAME }} \ - --lot-size-satoshis="1000" + --lot-size-satoshis="10000" From bac8d289b6a6ef96b1a57f75aadb6d3a7a0181a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michalina=20Ciencia=C5=82a?= Date: Thu, 5 Aug 2021 08:34:59 +0200 Subject: [PATCH 07/20] Change names of the secrets used in the workflow In the GitHub's settings, we've changed the name of the `KEEP_TEST_ETH_HOSTNAME` to `KEEP_TEST_ETH_HOSTNAME_WS` to differenciate between WS and HTTP urls. We need to update workflow config accordingly. This commit fixes the configuration incorrectly updated in the last commit. --- .github/workflows/e2e-testnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index cd1e9ef6..1a331fda 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -38,8 +38,8 @@ jobs: - name: Run e2e tests run: | ./e2e-test.js \ - --bitcoin-electrum-host=${{ secrets.KEEP_TEST_ELECTRUMX_HOSTNAME_WS }} \ + --bitcoin-electrum-host=${{ secrets.KEEP_TEST_ELECTRUMX_HOSTNAME }} \ --bitcoin-electrum-port=${{ secrets.KEEP_TEST_ELECTRUMX_PORT }} \ --bitcoin-network="testnet" \ - --ethereum-node=${{ secrets.KEEP_TEST_ETH_HOSTNAME }} \ + --ethereum-node=${{ secrets.KEEP_TEST_ETH_HOSTNAME_WS }} \ --lot-size-satoshis="1000000" From 0cc2ea537dc30348773f3cad4a59e29cf7406e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michalina=20Ciencia=C5=82a?= Date: Thu, 5 Aug 2021 11:09:12 +0200 Subject: [PATCH 08/20] Modify cron - execute daily In order to limit the amount of spent testnet BTC, we are changing the frequency of running the workflow. We will observe how does the daily execution affect the wallet's ballance and will further adjust the frequency of tests execution in the future. --- .github/workflows/e2e-testnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index 8e2c6e06..96a45b26 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -2,7 +2,7 @@ name: E2E tests / Testnet on: schedule: - - cron: '*/20 * * * *' + - cron: '2 0 * * *' workflow_dispatch: pull_request: # TODO: remove this trigger before merging to main From 0b4359e61f81dc27977978b98d4f45a74494ccef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michalina=20Ciencia=C5=82a?= Date: Thu, 5 Aug 2021 11:16:04 +0200 Subject: [PATCH 09/20] Add a comment about using `setup-node`'s cache functionality --- .github/workflows/e2e-testnet.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index 96a45b26..3aa0cb8f 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -21,6 +21,11 @@ jobs: - run: npm install --save-exact @keep-network/tbtc.js@ropsten + # In the future we could switch to using cache functionality built-in to + # the `setup-node` action. Right now the functionality does not support + # cases when package.json resides outside of the root directory, but there's + # an open issue (https://github.com/actions/setup-node/issues/275) in the + # works for that. - name: Cache Global NPM Cache uses: actions/cache@v2 env: From 48f75f5272a0d8e63abc614cd4e71f974f3eb0d2 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Thu, 5 Aug 2021 16:42:34 +0200 Subject: [PATCH 10/20] Handle deposit `autoSubmit` errors Currently those errors are unhandled. Recent changes made in `tbtc.js` require to register an explicit error handler. --- e2e/e2e-test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/e2e/e2e-test.js b/e2e/e2e-test.js index 96376d10..67a26cf9 100755 --- a/e2e/e2e-test.js +++ b/e2e/e2e-test.js @@ -197,6 +197,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) => { @@ -250,8 +255,6 @@ async function redeemDeposit(tbtc, depositAddress, redeemerAddress) { redemption.autoSubmit() redemption.onWithdrawn(transactionID => { - console.log() - resolve( `Redeemed deposit ${deposit.address} with Bitcoin transaction ` + `${transactionID}.` From 27f8ab24c18a84fa962ea490948ed511c5b666b1 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Thu, 5 Aug 2021 17:55:42 +0200 Subject: [PATCH 11/20] Simplify handling of `autoSubmit` errors --- e2e/e2e-test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/e2e/e2e-test.js b/e2e/e2e-test.js index 67a26cf9..24805047 100755 --- a/e2e/e2e-test.js +++ b/e2e/e2e-test.js @@ -197,10 +197,7 @@ async function createDeposit(tbtc, satoshiLotSize, keyRing) { web3.utils.toBN(satoshiLotSize) ) - deposit.onError((err) => { - console.error(err) - process.exit(1) - }) + deposit.onError(console.error) deposit.autoSubmit() From 5e00f7ae3820b736fe4a1d0684c38a43d2f89429 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Wed, 11 Aug 2021 12:52:12 +0200 Subject: [PATCH 12/20] Exit the script when `onError` callback is hit --- e2e/e2e-test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/e2e/e2e-test.js b/e2e/e2e-test.js index 24805047..67a26cf9 100755 --- a/e2e/e2e-test.js +++ b/e2e/e2e-test.js @@ -197,7 +197,10 @@ async function createDeposit(tbtc, satoshiLotSize, keyRing) { web3.utils.toBN(satoshiLotSize) ) - deposit.onError(console.error) + deposit.onError((err) => { + console.error(err) + process.exit(1) + }) deposit.autoSubmit() From 724cca168ea801db494325fc5457f6ccea1e68d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michalina=20Ciencia=C5=82a?= Date: Tue, 17 Aug 2021 08:58:10 +0200 Subject: [PATCH 13/20] Cache npm dependencies via setup-node action Action now supports cases where `*.lock` file is located in the root's subdirectory. --- .github/workflows/e2e-testnet.yml | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index f3b1f85e..ea9fa033 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -18,26 +18,11 @@ jobs: - 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 - # In the future we could switch to using cache functionality built-in to - # the `setup-node` action. Right now the functionality does not support - # cases when package.json resides outside of the root directory, but there's - # an open issue (https://github.com/actions/setup-node/issues/275) in the - # works for that. - - name: Cache Global NPM Cache - uses: actions/cache@v2 - env: - cache-name: cache-global-npm-cache - with: - path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - name: Run e2e tests run: | ./e2e-test.js \ From 42906be900b9ca3918b688622cb92410289eb428 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Wed, 18 Aug 2021 17:17:21 +0200 Subject: [PATCH 14/20] Add block number information to e2e test This should help debugging problems with BTC and ETH client synchronization. --- e2e/e2e-test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/e2e/e2e-test.js b/e2e/e2e-test.js index 67a26cf9..7fe74ac4 100755 --- a/e2e/e2e-test.js +++ b/e2e/e2e-test.js @@ -58,6 +58,18 @@ const web3 = new Web3(engine) engine.start() 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}` + ) + // Set first account as the default account. web3.eth.defaultAccount = (await web3.eth.getAccounts())[0] From 77d4a058df5f6bb5a0280d6a6075c98a7f9347ec Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Wed, 18 Aug 2021 17:23:56 +0200 Subject: [PATCH 15/20] Fix block fetching logic in e2e test --- e2e/e2e-test.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/e2e/e2e-test.js b/e2e/e2e-test.js index 7fe74ac4..da262e2c 100755 --- a/e2e/e2e-test.js +++ b/e2e/e2e-test.js @@ -58,18 +58,6 @@ const web3 = new Web3(engine) engine.start() 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}` - ) - // Set first account as the default account. web3.eth.defaultAccount = (await web3.eth.getAccounts())[0] @@ -83,6 +71,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() From 101f02ce4e31706f6f2fb64a451ab2d3121149e7 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Wed, 18 Aug 2021 17:39:44 +0200 Subject: [PATCH 16/20] Display source account balance --- e2e/common.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/e2e/common.js b/e2e/common.js index b8c9e879..17688bd6 100644 --- a/e2e/common.js +++ b/e2e/common.js @@ -51,7 +51,18 @@ export const sendBitcoinTransaction = async( ) => { const sourceAddress = keyRing.getAddress("string"); - console.log(`Sending transaction from ${sourceAddress} to ${targetAddress}`) + const sourceAddressBalance = await BitcoinHelpers.withElectrumClient( + async electrumClient => { + return electrumClient.getBalanceOfScript( + bcoin.Script.fromAddress(sourceAddress) + ) + } + ) + + console.log( + `Sending transaction from ${sourceAddress} to ${targetAddress}; ` + + `BTC balance of source address is ${sourceAddressBalance.confirmed}` + ) const utxos = await BitcoinHelpers.Transaction.findAllUnspent(sourceAddress) From 673315e08f844031a2ff38509e943d7176a81988 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Wed, 18 Aug 2021 17:48:21 +0200 Subject: [PATCH 17/20] Improve log formatting --- e2e/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/common.js b/e2e/common.js index 17688bd6..9f8b723c 100644 --- a/e2e/common.js +++ b/e2e/common.js @@ -60,7 +60,7 @@ export const sendBitcoinTransaction = async( ) console.log( - `Sending transaction from ${sourceAddress} to ${targetAddress}; ` + + `Sending transaction from ${sourceAddress} to ${targetAddress}\n` + `BTC balance of source address is ${sourceAddressBalance.confirmed}` ) From 68a9902c1b05eae3d33f0584afb031d19af6b560 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Mon, 23 Aug 2021 13:38:43 +0200 Subject: [PATCH 18/20] Increase fee overhead In case of small amounts, the current 10% overhead is not enough. 20% should work in those cases. --- e2e/common.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/e2e/common.js b/e2e/common.js index 9f8b723c..3f0e08e5 100644 --- a/e2e/common.js +++ b/e2e/common.js @@ -51,17 +51,13 @@ export const sendBitcoinTransaction = async( ) => { const sourceAddress = keyRing.getAddress("string"); - const sourceAddressBalance = await BitcoinHelpers.withElectrumClient( - async electrumClient => { - return electrumClient.getBalanceOfScript( - bcoin.Script.fromAddress(sourceAddress) - ) - } + const sourceAddressBalance = await BitcoinHelpers.Transaction.getBalance( + sourceAddress ) console.log( `Sending transaction from ${sourceAddress} to ${targetAddress}\n` + - `BTC balance of source address is ${sourceAddressBalance.confirmed}` + `BTC balance of source address is ${sourceAddressBalance}` ) const utxos = await BitcoinHelpers.Transaction.findAllUnspent(sourceAddress) @@ -71,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 } From 152e9f00514a7066d646d0c4bf72f36c61df2e77 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Tue, 24 Aug 2021 11:20:54 +0200 Subject: [PATCH 19/20] Run four times a day --- .github/workflows/e2e-testnet.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/e2e-testnet.yml b/.github/workflows/e2e-testnet.yml index ea9fa033..6d171285 100644 --- a/.github/workflows/e2e-testnet.yml +++ b/.github/workflows/e2e-testnet.yml @@ -2,9 +2,8 @@ name: E2E tests / Testnet on: schedule: - - cron: '2 0 * * *' + - cron: '0 */6 * * *' workflow_dispatch: - pull_request: # TODO: remove this trigger before merging to main jobs: e2e-testnet-tests: From 7e7319d1a54283620e9d7f7a6818c86a14e6c84b Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Tue, 24 Aug 2021 11:47:42 +0200 Subject: [PATCH 20/20] Remove script options values log --- e2e/e2e-test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/e2e/e2e-test.js b/e2e/e2e-test.js index da262e2c..8ad37acc 100755 --- a/e2e/e2e-test.js +++ b/e2e/e2e-test.js @@ -33,8 +33,6 @@ program .option('--lot-size-satoshis ', "lot size in satoshis", (lot) => parseInt(lot, 10), 1000000) .parse(process.argv) -console.log("\nScript options values: ", program.opts(), "\n") - const signerFeeDivisor = 0.0005 // 0.05% const satoshiMultiplier = 10000000000 // 10^10 const tbtcDepositAmount = program.lotSizeSatoshis * satoshiMultiplier