Skip to content

Commit

Permalink
Merge pull request #98 from keep-network/rfc-18/move-e2e-kubernetes-j…
Browse files Browse the repository at this point in the history
…ob-to-gha

Run e2e testnet tests 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.
  • Loading branch information
nkuba committed Aug 24, 2021
2 parents 388f346 + 7e7319d commit 2aad2b3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 100 deletions.
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

0 comments on commit 2aad2b3

Please sign in to comment.