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

test: run e2e btc tests locally #1868

Merged
merged 9 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +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
### Chores

* [1814](https://github.com/zeta-chain/node/pull/1814) - fix code coverage ignore for protobuf generated files
Expand Down
8 changes: 2 additions & 6 deletions cmd/zetae2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ 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:
skosito marked this conversation as resolved.
Show resolved Hide resolved

```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]
```

### Commands
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
}
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
Loading