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: split bitcoin e2e into deposit group and withdraw group #3105

Merged
merged 11 commits into from
Nov 8, 2024
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
* [3122](https://github.com/zeta-chain/node/pull/3122) - improve & refactor zetaclientd cli

### Tests

* [3075](https://github.com/zeta-chain/node/pull/3075) - ton: withdraw concurrent, deposit & revert.
* [3105](https://github.com/zeta-chain/node/pull/3105) - split Bitcoin E2E tests into two runners for deposit and withdraw

### Refactor
* [3118](https://github.com/zeta-chain/node/pull/3118) - zetaclient: remove hsm signer
Expand Down
9 changes: 3 additions & 6 deletions cmd/zetae2e/bitcoin_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error {
return err
}

addr, privKey, err := r.GetBtcAddress()
if err != nil {
return err
}
addr, privKey := r.GetBtcAddress()
lumtis marked this conversation as resolved.
Show resolved Hide resolved

logger.Print("* BTC address: %s", addr)
logger.Print("* BTC address: %s", addr.EncodeAddress())
if showPrivKey {
logger.Print("* BTC privkey: %s", privKey)
logger.Print("* BTC privkey: %s", privKey.String())
}

return nil
Expand Down
6 changes: 5 additions & 1 deletion cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ additional_accounts:
bech32_address: "zeta13t3zjxvwec7g38q8mdjga37rpes9zkfvv7tkn2"
evm_address: "0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c"
private_key: "105460aebf71b10bfdb710ef5aa6d2932ee6ff6fc317ac9c24e0979903b10a5d"
user_bitcoin:
user_bitcoin_deposit:
bech32_address: "zeta19q7czqysah6qg0n4y3l2a08gfzqxydla492v80"
evm_address: "0x283d810090EdF4043E75247eAeBcE848806237fD"
private_key: "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a"
user_bitcoin_withdraw:
bech32_address: "zeta17e77anpmzhuuam67hg6x3mtqrulqh80z9chv70"
evm_address: "0xf67deecc3B15F9CEeF5eba3468ed601f3e0B9de2"
private_key: "2b3306a8ac43dbf0e350b87876c131e7e12bd49563a16de9ce8aeb664b94d559"
user_solana:
bech32_address: "zeta1zqlajgj0qr8rqylf2c572t0ux8vqt45d4zngpm"
evm_address: "0x103FD9224F00ce3013e95629e52DFc31D805D68d"
Expand Down
6 changes: 5 additions & 1 deletion cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ additional_accounts:
bech32_address: "zeta13t3zjxvwec7g38q8mdjga37rpes9zkfvv7tkn2"
evm_address: "0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c"
private_key: "105460aebf71b10bfdb710ef5aa6d2932ee6ff6fc317ac9c24e0979903b10a5d"
user_bitcoin:
user_bitcoin_deposit:
bech32_address: "zeta19q7czqysah6qg0n4y3l2a08gfzqxydla492v80"
evm_address: "0x283d810090EdF4043E75247eAeBcE848806237fD"
private_key: "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a"
user_bitcoin_withdraw:
bech32_address: "zeta17e77anpmzhuuam67hg6x3mtqrulqh80z9chv70"
evm_address: "0xf67deecc3B15F9CEeF5eba3468ed601f3e0B9de2"
private_key: "2b3306a8ac43dbf0e350b87876c131e7e12bd49563a16de9ce8aeb664b94d559"
user_solana:
bech32_address: "zeta1zqlajgj0qr8rqylf2c572t0ux8vqt45d4zngpm"
evm_address: "0x103FD9224F00ce3013e95629e52DFc31D805D68d"
Expand Down
135 changes: 96 additions & 39 deletions cmd/zetae2e/local/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,128 @@ import (
"time"

"github.com/fatih/color"
"github.com/stretchr/testify/require"
gartnera marked this conversation as resolved.
Show resolved Hide resolved

"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/e2etests"
"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/testutil"
lumtis marked this conversation as resolved.
Show resolved Hide resolved
)

// bitcoinTestRoutine runs Bitcoin related e2e tests
func bitcoinTestRoutine(
// initBitcoinTestRunners initializes Bitcoin deposit and withdraw test runners
func initBitcoinTestRunners(
conf config.Config,
deployerRunner *runner.E2ERunner,
verbose bool,
initBitcoinNetwork bool,
testNames ...string,
) func() error {
return func() (err error) {
account := conf.AdditionalAccounts.UserBitcoin
// initialize runner for bitcoin test
bitcoinRunner, err := initTestRunner(
"bitcoin",
conf,
deployerRunner,
account,
runner.NewLogger(verbose, color.FgYellow, "bitcoin"),
)
if err != nil {
return err
}
initNetwork bool,
depositTests []string,
withdrawTests []string,
) (func() error, func() error) {
// initialize runner for deposit tests
// deposit tests need Bitcoin node wallet to handle UTXOs
account := conf.AdditionalAccounts.UserBitcoinDeposit
runnerDeposit := initBitcoinRunner(
"btc_deposit",
account,
conf,
deployerRunner,
color.FgYellow,
verbose,
initNetwork,
true,
)

bitcoinRunner.Logger.Print("🏃 starting Bitcoin tests")
startTime := time.Now()
// initialize runner for withdraw tests
// withdraw tests DON'T use Bitcoin node wallet
account = conf.AdditionalAccounts.UserBitcoinWithdraw
runnerWithdraw := initBitcoinRunner(
"btc_withdraw",
account,
conf,
deployerRunner,
color.FgHiYellow,
verbose,
initNetwork,
false,
)

// initialize funds
// send BTC to TSS for gas fees and to tester ZEVM address
if initNetwork {
// mine 101 blocks to ensure the BTC rewards are spendable
// Note: the block rewards can be sent to any address in here
_, err := runnerDeposit.GenerateToAddressIfLocalBitcoin(101, runnerDeposit.BTCDeployerAddress)
require.NoError(runnerDeposit, err)
gartnera marked this conversation as resolved.
Show resolved Hide resolved

// funding the account
// send BTC to ZEVM addresses
runnerDeposit.DepositBTC(runnerDeposit.EVMAddress())
runnerDeposit.DepositBTC(runnerWithdraw.EVMAddress())
gartnera marked this conversation as resolved.
Show resolved Hide resolved
}

// create test routines
routineDeposit := createBitcoinTestRoutine(runnerDeposit, depositTests)
routineWithdraw := createBitcoinTestRoutine(runnerWithdraw, withdrawTests)

return routineDeposit, routineWithdraw
}

// initBitcoinRunner initializes the Bitcoin runner for given test name and account
func initBitcoinRunner(
name string,
account config.Account,
conf config.Config,
deployerRunner *runner.E2ERunner,
printColor color.Attribute,
verbose, initNetwork, createWallet bool,
) *runner.E2ERunner {
// initialize runner for bitcoin test
runner, err := initTestRunner(name, conf, deployerRunner, account, runner.NewLogger(verbose, printColor, name))
testutil.NoError(err)
gartnera marked this conversation as resolved.
Show resolved Hide resolved

// setup TSS address and setup deployer wallet
runner.SetupBitcoinAccounts(createWallet)

// initialize funds
if initNetwork {
// send some BTC block rewards to the deployer address
_, err = runner.GenerateToAddressIfLocalBitcoin(4, runner.BTCDeployerAddress)
require.NoError(runner, err)

// send ERC20 token on EVM
txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1000)
bitcoinRunner.WaitForTxReceiptOnEvm(txERC20Send)
runner.WaitForTxReceiptOnEvm(txERC20Send)

// depositing the necessary tokens on ZetaChain
txEtherDeposit := bitcoinRunner.DepositEther()
txERC20Deposit := bitcoinRunner.DepositERC20()
// deposit ETH and ERC20 tokens on ZetaChain
txEtherDeposit := runner.DepositEther()
txERC20Deposit := runner.DepositERC20()
ws4charlie marked this conversation as resolved.
Show resolved Hide resolved

bitcoinRunner.WaitForMinedCCTX(txEtherDeposit)
bitcoinRunner.WaitForMinedCCTX(txERC20Deposit)
runner.WaitForMinedCCTX(txEtherDeposit)
runner.WaitForMinedCCTX(txERC20Deposit)
}
gartnera marked this conversation as resolved.
Show resolved Hide resolved

bitcoinRunner.SetupBitcoinAccount(initBitcoinNetwork)
bitcoinRunner.DepositBTC()
return runner
}

// run bitcoin test
// Note: due to the extensive block generation in Bitcoin localnet, block header test is run first
// to make it faster to catch up with the latest block header
testsToRun, err := bitcoinRunner.GetE2ETestsToRunByName(
// createBitcoinTestRoutine creates a test routine for given test names
func createBitcoinTestRoutine(r *runner.E2ERunner, testNames []string) func() error {
return func() (err error) {
r.Logger.Print("🏃 starting bitcoin tests")
startTime := time.Now()

// run bitcoin tests
testsToRun, err := r.GetE2ETestsToRunByName(
e2etests.AllE2ETests,
testNames...,
)
if err != nil {
return fmt.Errorf("bitcoin tests failed: %v", err)
}

if err := bitcoinRunner.RunE2ETests(testsToRun); err != nil {
if err := r.RunE2ETests(testsToRun); err != nil {
return fmt.Errorf("bitcoin tests failed: %v", err)
}

if err := bitcoinRunner.CheckBtcTSSBalance(); err != nil {
return err
}

bitcoinRunner.Logger.Print("🍾 Bitcoin tests completed in %s", time.Since(startTime).String())
r.Logger.Print("🍾 bitcoin tests completed in %s", time.Since(startTime).String())

return err
}
Expand Down
31 changes: 24 additions & 7 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestMessagePassingEVMtoZEVMRevertFailName,
}

bitcoinTests := []string{
// btc withdraw tests are those that need a Bitcoin node wallet to send UTXOs
bitcoinDepositTests := []string{
e2etests.TestBitcoinDonationName,
e2etests.TestBitcoinDepositName,
e2etests.TestBitcoinDepositAndCallName,
Expand All @@ -315,17 +316,19 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestBitcoinStdMemoDepositAndCallRevertName,
e2etests.TestBitcoinStdMemoDepositAndCallRevertOtherAddressName,
e2etests.TestBitcoinStdMemoInscribedDepositAndCallName,
e2etests.TestCrosschainSwapName,
}
bitcoinWithdrawTests := []string{
e2etests.TestBitcoinWithdrawSegWitName,
e2etests.TestBitcoinWithdrawInvalidAddressName,
e2etests.TestZetaWithdrawBTCRevertName,
e2etests.TestCrosschainSwapName,
}
bitcoinAdvancedTests := []string{
bitcoinWithdrawTestsAdvanced := []string{
e2etests.TestBitcoinWithdrawTaprootName,
e2etests.TestBitcoinWithdrawLegacyName,
e2etests.TestBitcoinWithdrawMultipleName,
e2etests.TestBitcoinWithdrawP2SHName,
e2etests.TestBitcoinWithdrawP2WSHName,
e2etests.TestBitcoinWithdrawMultipleName,
e2etests.TestBitcoinWithdrawRestrictedName,
}
ethereumTests := []string{
Expand Down Expand Up @@ -359,15 +362,24 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
erc20Tests = append(erc20Tests, erc20AdvancedTests...)
zetaTests = append(zetaTests, zetaAdvancedTests...)
zevmMPTests = append(zevmMPTests, zevmMPAdvancedTests...)
bitcoinTests = append(bitcoinTests, bitcoinAdvancedTests...)
bitcoinWithdrawTests = append(bitcoinWithdrawTests, bitcoinWithdrawTestsAdvanced...)
ethereumTests = append(ethereumTests, ethereumAdvancedTests...)
}

eg.Go(statefulPrecompilesTestRoutine(conf, deployerRunner, verbose, precompiledContractTests...))
eg.Go(erc20TestRoutine(conf, deployerRunner, verbose, erc20Tests...))
eg.Go(zetaTestRoutine(conf, deployerRunner, verbose, zetaTests...))
eg.Go(zevmMPTestRoutine(conf, deployerRunner, verbose, zevmMPTests...))
eg.Go(bitcoinTestRoutine(conf, deployerRunner, verbose, !skipBitcoinSetup, bitcoinTests...))
runnerDeposit, runnerWithdraw := initBitcoinTestRunners(
conf,
deployerRunner,
verbose,
!skipBitcoinSetup,
bitcoinDepositTests,
bitcoinWithdrawTests,
)
eg.Go(runnerDeposit)
eg.Go(runnerWithdraw)
eg.Go(ethereumTestRoutine(conf, deployerRunner, verbose, ethereumTests...))
}

Expand Down Expand Up @@ -460,7 +472,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
}

// if all tests pass, cancel txs priority monitoring and check if tx priority is not correct in some blocks
logger.Print("⏳ e2e tests passed,checking tx priority")
logger.Print("⏳ e2e tests passed, checking tx priority")
monitorPriorityCancel()
if err := <-txPriorityErrCh; err != nil && errors.Is(err, errWrongTxPriority) {
logger.Print("❌ %v", err)
Expand All @@ -473,10 +485,15 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
if testTSSMigration {
TSSMigration(deployerRunner, logger, verbose, conf)
}

// Verify that there are no trackers left over after tests complete
if !skipTrackerCheck {
deployerRunner.EnsureNoTrackers()
}

// Verify that the balance of restricted address is zero
deployerRunner.EnsureZeroBalanceOnRestrictedAddressZEVM()

// print and validate report
networkReport, err := deployerRunner.GenerateNetworkReport()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/setup_bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error {
return err
}

r.SetupBitcoinAccount(true)
r.SetupBitcoinAccounts(true)
lumtis marked this conversation as resolved.
Show resolved Hide resolved

logger.Print("* BTC setup done")

Expand Down
7 changes: 5 additions & 2 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ fund_eth_from_config '.additional_accounts.user_zeta_test.evm_address' 10000 "ze
# unlock zevm message passing tester accounts
fund_eth_from_config '.additional_accounts.user_zevm_mp_test.evm_address' 10000 "zevm mp tester"

# unlock bitcoin tester accounts
fund_eth_from_config '.additional_accounts.user_bitcoin.evm_address' 10000 "bitcoin tester"
# unlock bitcoin deposit tester accounts
fund_eth_from_config '.additional_accounts.user_bitcoin_deposit.evm_address' 10000 "bitcoin deposit tester"

# unlock bitcoin withdraw tester accounts
fund_eth_from_config '.additional_accounts.user_bitcoin_withdraw.evm_address' 10000 "bitcoin withdraw tester"

# unlock solana tester accounts
fund_eth_from_config '.additional_accounts.user_solana.evm_address' 10000 "solana tester"
Expand Down
7 changes: 5 additions & 2 deletions contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ then
# zeta tester
address=$(yq -r '.additional_accounts.user_zeta_test.bech32_address' /root/config.yml)
zetacored add-genesis-account "$address" 100000000000000000000000000azeta
# bitcoin tester
address=$(yq -r '.additional_accounts.user_bitcoin.bech32_address' /root/config.yml)
# bitcoin deposit tester
address=$(yq -r '.additional_accounts.user_bitcoin_deposit.bech32_address' /root/config.yml)
zetacored add-genesis-account "$address" 100000000000000000000000000azeta
# bitcoin withdraw tester
address=$(yq -r '.additional_accounts.user_bitcoin_withdraw.bech32_address' /root/config.yml)
zetacored add-genesis-account "$address" 100000000000000000000000000azeta
# solana tester
address=$(yq -r '.additional_accounts.user_solana.bech32_address' /root/config.yml)
Expand Down
Loading
Loading