diff --git a/changelog.md b/changelog.md index 724979f970..1ddeb6c4ee 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/cmd/zetae2e/README.md b/cmd/zetae2e/README.md index ccda53caf6..c57863e7cf 100644 --- a/cmd/zetae2e/README.md +++ b/cmd/zetae2e/README.md @@ -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 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: diff --git a/cmd/zetae2e/root.go b/cmd/zetae2e/root.go index ba82430a45..4568358512 100644 --- a/cmd/zetae2e/root.go +++ b/cmd/zetae2e/root.go @@ -27,6 +27,7 @@ func NewRootCmd() *cobra.Command { local.NewLocalCmd(), NewStressTestCmd(), NewInitCmd(), + NewSetupBitcoinCmd(), ) return cmd diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go new file mode 100644 index 0000000000..4de6b0685d --- /dev/null +++ b/cmd/zetae2e/setup_bitcoin.go @@ -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 +} diff --git a/contrib/localnet/docker-compose.yml b/contrib/localnet/docker-compose.yml index bce13ad09f..52ce7d2124 100644 --- a/contrib/localnet/docker-compose.yml +++ b/contrib/localnet/docker-compose.yml @@ -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 diff --git a/e2e/e2etests/test_bitcoin_withdraw.go b/e2e/e2etests/test_bitcoin_withdraw.go index 7a82f4382d..edd779b595 100644 --- a/e2e/e2etests/test_bitcoin_withdraw.go +++ b/e2e/e2etests/test_bitcoin_withdraw.go @@ -30,6 +30,8 @@ func TestBitcoinWithdraw(r *runner.E2ERunner, args []string) { } amount := big.NewInt(int64(withdrawalAmountSat)) + r.SetBtcAddress(r.Name, false) + WithdrawBitcoin(r, amount) } @@ -49,6 +51,8 @@ func TestBitcoinWithdrawRestricted(r *runner.E2ERunner, args []string) { } amount := big.NewInt(int64(withdrawalAmountSat)) + r.SetBtcAddress(r.Name, false) + WithdrawBitcoinRestricted(r, amount) } diff --git a/e2e/e2etests/test_bitcoin_withdraw_invalid.go b/e2e/e2etests/test_bitcoin_withdraw_invalid.go index 4c529bf8ac..d168826493 100644 --- a/e2e/e2etests/test_bitcoin_withdraw_invalid.go +++ b/e2e/e2etests/test_bitcoin_withdraw_invalid.go @@ -26,6 +26,8 @@ func TestBitcoinWithdrawToInvalidAddress(r *runner.E2ERunner, args []string) { } amount := big.NewInt(int64(withdrawalAmountSat)) + r.SetBtcAddress(r.Name, false) + WithdrawToInvalidAddress(r, amount) } diff --git a/e2e/e2etests/test_stress_btc_withdraw.go b/e2e/e2etests/test_stress_btc_withdraw.go index ea4465b52d..dc7579e877 100644 --- a/e2e/e2etests/test_stress_btc_withdraw.go +++ b/e2e/e2etests/test_stress_btc_withdraw.go @@ -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 diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index 3b7ba5136e..06b123c12f 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -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())