Skip to content

Commit

Permalink
test: run e2e btc tests locally (#1868)
Browse files Browse the repository at this point in the history
* Run e2e btc tests locally

* Changelog

* Fix lint

* Improve readme

* Debugging fixes
  • Loading branch information
skosito authored Mar 12, 2024
1 parent 71a889b commit 7ed70a0
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* [1791](https://github.com/zeta-chain/node/pull/1791) - add e2e tests for feature of restricted address
* [1787](https://github.com/zeta-chain/node/pull/1787) - add unit tests for cross-chain evm hooks and e2e test failed withdraw to BTC legacy address
* [1840](https://github.com/zeta-chain/node/pull/1840) - fix code coverage test failures ignored in CI
* [1868](https://github.com/zeta-chain/node/pull/1868) - run e2e btc tests locally
* [1851](https://github.com/zeta-chain/node/pull/1851) - rename usdt to erc20 in e2e tests
* [1872](https://github.com/zeta-chain/node/pull/1872) - remove usage of RPC in unit test
* [1805](https://github.com/zeta-chain/node/pull/1805) - add admin and performance test and fix upgrade test
Expand Down
10 changes: 4 additions & 6 deletions cmd/zetae2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ contracts:
### Bitcoin setup
Interaction with the Bitcoin node will require setting up a specific node tracking the address. It can be set locally following the guide [Using Bitcoin Docker Image for Local Development](https://www.notion.so/Using-Bitcoin-Docker-Image-for-Local-Development-bf7e84c58f22431fb52f17a471997e1f?pvs=21)

If an error occurs mention that wallets are not loaded. The following commands might need to be run in the Docker container:
If an error occurs mention that wallets are not loaded, this command can be run to set it up:

```go
docker exec -it <container> bash

bitcoin-cli -testnet -rpcuser=${bitcoin_username} -rpcpassword=${bitcoin_password} -named createwallet wallet_name=${WALLET_NAME} disable_private_keys=false load_on_startup=true
bitcoin-cli -testnet -rpcuser=${bitcoin_username} -rpcpassword=${bitcoin_password} importaddress "${WALLET_ADDRESS}" "${WALLET_NAME}" true
bitcoin-cli -testnet -rpcuser=${bitcoin_username} -rpcpassword=${bitcoin_password} importprivkey "your_private_key" "${WALLET_NAME}" false
zetae2e setup-bitcoin [config]
```

Note: This command is intended for local testing only and won't work on live networks, where a node with an enabled wallet should already be set up.

### Commands

Show the balances of the accounts used on the different networks:
Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewRootCmd() *cobra.Command {
local.NewLocalCmd(),
NewStressTestCmd(),
NewInitCmd(),
NewSetupBitcoinCmd(),
)

return cmd
Expand Down
77 changes: 77 additions & 0 deletions cmd/zetae2e/setup_bitcoin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"context"
"errors"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/app"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
)

// NewSetupBitcoinCmd sets up bitcoin wallet for e2e tests
// should be run in case bitcoin e2e tests return load wallet errors
func NewSetupBitcoinCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "setup-bitcoin [config-file] ",
Short: "Setup Bitcoin wallet for e2e tests",
RunE: runSetupBitcoin,
Args: cobra.ExactArgs(1),
}
return cmd
}

func runSetupBitcoin(_ *cobra.Command, args []string) error {
// read the config file
conf, err := config.ReadConfig(args[0])
if err != nil {
return err
}

// initialize logger
logger := runner.NewLogger(false, color.FgHiYellow, "")

// set config
app.SetConfig()

// initialize context
ctx, cancel := context.WithCancel(context.Background())

// get EVM address from config
evmAddr := conf.Accounts.EVMAddress
if !ethcommon.IsHexAddress(evmAddr) {
cancel()
return errors.New("invalid EVM address")
}
// initialize deployer runner with config
r, err := zetae2econfig.RunnerFromConfig(
ctx,
"e2e",
cancel,
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
cancel()
return err
}

if err := r.SetTSSAddresses(); err != nil {
return err
}

r.SetupBitcoinAccount(true)

logger.Print("* BTC setup done")

return nil
}
2 changes: 1 addition & 1 deletion contrib/localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ services:
command:
-printtoconsole
-regtest=1
-rpcallowip=172.20.0.0/16
-rpcallowip=0.0.0.0/0
-rpcbind=0.0.0.0
-rpcauth=smoketest:63acf9b8dccecce914d85ff8c044b78b$$5892f9bbc84f4364e79f0970039f88bdd823f168d4acc76099ab97b14a766a99
-txindex=1
Expand Down
4 changes: 4 additions & 0 deletions e2e/e2etests/test_bitcoin_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestBitcoinWithdraw(r *runner.E2ERunner, args []string) {
}
amount := big.NewInt(int64(withdrawalAmountSat))

r.SetBtcAddress(r.Name, false)

WithdrawBitcoin(r, amount)
}

Expand All @@ -49,6 +51,8 @@ func TestBitcoinWithdrawRestricted(r *runner.E2ERunner, args []string) {
}
amount := big.NewInt(int64(withdrawalAmountSat))

r.SetBtcAddress(r.Name, false)

WithdrawBitcoinRestricted(r, amount)
}

Expand Down
2 changes: 2 additions & 0 deletions e2e/e2etests/test_bitcoin_withdraw_invalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func TestBitcoinWithdrawToInvalidAddress(r *runner.E2ERunner, args []string) {
}
amount := big.NewInt(int64(withdrawalAmountSat))

r.SetBtcAddress(r.Name, false)

WithdrawToInvalidAddress(r, amount)
}

Expand Down
2 changes: 2 additions & 0 deletions e2e/e2etests/test_stress_btc_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestStressBTCWithdraw(r *runner.E2ERunner, args []string) {
panic("Invalid number of withdrawals specified for TestStressBTCWithdraw.")
}

r.SetBtcAddress(r.Name, false)

r.Logger.Print("starting stress test of %d withdraws", numWithdraws)

// create a wait group to wait for all the withdraws to complete
Expand Down
2 changes: 1 addition & 1 deletion e2e/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (runner *E2ERunner) PrintContractAddresses() {
runner.Logger.Print(" --- 📜zEVM contracts ---")
runner.Logger.Print("SystemContract: %s", runner.SystemContractAddr.Hex())
runner.Logger.Print("ETHZRC20: %s", runner.ETHZRC20Addr.Hex())
runner.Logger.Print("ERC20ZRC20: %s", runner.ERC20ZRC20Addr.Hex())
runner.Logger.Print("ERC20ZRC20: %s", runner.ERC20ZRC20Addr.Hex())
runner.Logger.Print("BTCZRC20: %s", runner.BTCZRC20Addr.Hex())
runner.Logger.Print("UniswapFactory: %s", runner.UniswapV2FactoryAddr.Hex())
runner.Logger.Print("UniswapRouter: %s", runner.UniswapV2RouterAddr.Hex())
Expand Down

0 comments on commit 7ed70a0

Please sign in to comment.