Skip to content

Commit

Permalink
Merge branch 'develop' into withdraw-spl
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito authored Nov 8, 2024
2 parents 5eee39a + 7c70809 commit 22e0c43
Show file tree
Hide file tree
Showing 46 changed files with 261 additions and 371 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
* [3134](https://github.com/zeta-chain/node/pull/3134) - integrate withdraw SPL

### 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
3 changes: 0 additions & 3 deletions cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"os"

rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
dbm "github.com/cometbft/cometbft-db"
tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
Expand Down Expand Up @@ -177,8 +176,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig types.EncodingConfig) {
if err := SetEthereumHDPath(rootCmd); err != nil {
fmt.Printf("warning: unable to set default HD path: %v\n", err)
}

rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
}

func addModuleInitFlags(startCmd *cobra.Command) {
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()

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"

"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"
)

// 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)

// funding the account
// send BTC to ZEVM addresses
runnerDeposit.DepositBTC(runnerDeposit.EVMAddress())
runnerDeposit.DepositBTC(runnerWithdraw.EVMAddress())
}

// 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)

// 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()

bitcoinRunner.WaitForMinedCCTX(txEtherDeposit)
bitcoinRunner.WaitForMinedCCTX(txERC20Deposit)
runner.WaitForMinedCCTX(txEtherDeposit)
runner.WaitForMinedCCTX(txERC20Deposit)
}

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 @@ -313,7 +313,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 @@ -323,17 +324,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 @@ -367,15 +370,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 @@ -471,7 +483,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 @@ -484,10 +496,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)

logger.Print("* BTC setup done")

Expand Down
17 changes: 0 additions & 17 deletions contrib/localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# - An Ethereum node (eth)
# - A secondary optional Ethereum node (eth2) enabled when profile is set to eth2
# - A Bitcoin node (bitcoin)
# - A Rosetta API (rosetta)
# - An orchestrator to manage interaction with the localnet (orchestrator)
# - An upgrade host to serve binaries for the upgrade tests (upgrade-host). Only enabled when profile is set to upgrade.
# - An upgrade orchestrator to send the upgrade governance proposal (upgrade-orchestrator). Only enabled when profile is set to upgrade.
Expand All @@ -19,22 +18,6 @@ networks:
- subnet: 172.20.0.0/24

services:
rosetta:
image: zetanode:latest
container_name: rosetta
hostname: rosetta
depends_on:
zetacore0:
condition: service_healthy
ports:
- "8080:8080"
networks:
mynetwork:
ipv4_address: 172.20.0.200
entrypoint: ["zetacored", "rosetta", "--tendermint", "zetacore0:26657", "--grpc", "zetacore0:9090", "--network", "athens_101-1", "--blockchain", "zetacore"]
volumes:
- ssh:/root/.ssh

zetacore0:
image: zetanode:latest
container_name: zetacore0
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
14 changes: 0 additions & 14 deletions contrib/localnet/scripts/start-rosetta.sh

This file was deleted.

Loading

0 comments on commit 22e0c43

Please sign in to comment.