Skip to content

Commit

Permalink
Run e2e btc tests locally
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Mar 8, 2024
1 parent f8e8565 commit e6927a0
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
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:

```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(cmd *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

0 comments on commit e6927a0

Please sign in to comment.