From c051a04f7ee2885d12e418251a14e040a9bf596d Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Wed, 6 Nov 2024 13:29:58 -0600 Subject: [PATCH] add balance check after Bitcoin e2e tests --- cmd/zetae2e/local/bitcoin.go | 32 ++++++++++++++------------------ cmd/zetae2e/local/local.go | 12 +++++++++--- e2e/runner/accounting.go | 23 ++++++++++++++--------- e2e/runner/bitcoin.go | 3 ++- e2e/runner/require.go | 4 ++-- e2e/runner/run.go | 6 ++---- e2e/runner/setup_bitcoin.go | 6 +++--- 7 files changed, 46 insertions(+), 40 deletions(-) diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index 343efcac86..28ae560f97 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -34,7 +34,7 @@ func startBitcoinTestRoutines( // 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 rewards can be sent to any address in here + // Note: the block rewards can be sent to any address in here _, err := runnerDeposit.GenerateToAddressIfLocalBitcoin(101, runnerDeposit.BTCDeployerAddress) require.NoError(runnerDeposit, err) @@ -61,7 +61,7 @@ func initRunnerDeposit( var ( name = "btc_deposit" account = conf.AdditionalAccounts.UserBitcoin1 - createWallet = true // deposit tests need Bitcoin node wallet + createWallet = true // deposit tests need Bitcoin node wallet to handle UTXOs ) return initRunner(name, account, conf, deployerRunner, verbose, initNetwork, createWallet) @@ -76,7 +76,7 @@ func initRunnerWithdraw( var ( name = "btc_withdraw" account = conf.AdditionalAccounts.UserBitcoin2 - createWallet = false // withdraw tests do not use Bitcoin node wallet + createWallet = false // withdraw tests DON'T use Bitcoin node wallet ) return initRunner(name, account, conf, deployerRunner, verbose, initNetwork, createWallet) @@ -90,8 +90,8 @@ func initRunner( deployerRunner *runner.E2ERunner, verbose, initNetwork, createWallet bool, ) *runner.E2ERunner { - // initialize r for bitcoin test - r, err := initTestRunner( + // initialize runner for bitcoin test + runner, err := initTestRunner( name, conf, deployerRunner, @@ -101,27 +101,27 @@ func initRunner( testutil.NoError(err) // setup TSS address and setup deployer wallet - r.SetupBitcoinAccounts(createWallet) + runner.SetupBitcoinAccounts(createWallet) // initialize funds if initNetwork { // send some BTC block rewards to the deployer address - _, err = r.GenerateToAddressIfLocalBitcoin(4, r.BTCDeployerAddress) - require.NoError(r, err) + _, err = runner.GenerateToAddressIfLocalBitcoin(4, runner.BTCDeployerAddress) + require.NoError(runner, err) // send ERC20 token on EVM txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1000) - r.WaitForTxReceiptOnEvm(txERC20Send) + runner.WaitForTxReceiptOnEvm(txERC20Send) // deposit ETH and ERC20 tokens on ZetaChain - txEtherDeposit := r.DepositEther() - txERC20Deposit := r.DepositERC20() + txEtherDeposit := runner.DepositEther() + txERC20Deposit := runner.DepositERC20() - r.WaitForMinedCCTX(txEtherDeposit) - r.WaitForMinedCCTX(txERC20Deposit) + runner.WaitForMinedCCTX(txEtherDeposit) + runner.WaitForMinedCCTX(txERC20Deposit) } - return r + return runner } // createTestRoutine creates a test routine for given test names @@ -145,10 +145,6 @@ func createTestRoutine(r *runner.E2ERunner, testNames []string) func() error { return fmt.Errorf("bitcoin tests failed: %v", err) } - // if err := bitcoinRunner.CheckBtcTSSBalance(); err != nil { - // return err - // } - r.Logger.Print("🍾 bitcoin tests completed in %s", time.Since(startTime).String()) return err diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 57538c4323..af9cedecc5 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -301,6 +301,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { e2etests.TestMessagePassingEVMtoZEVMRevertFailName, } + // btc withdraw tests are those that need a Bitcoin node wallet to send UTXOs bitcoinDepositTests := []string{ e2etests.TestBitcoinDonationName, e2etests.TestBitcoinDepositName, @@ -318,7 +319,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { e2etests.TestBitcoinWithdrawInvalidAddressName, e2etests.TestZetaWithdrawBTCRevertName, } - bitcoinAdvancedTests := []string{ + bitcoinWithdrawTestsAdvanced := []string{ e2etests.TestBitcoinWithdrawTaprootName, e2etests.TestBitcoinWithdrawLegacyName, e2etests.TestBitcoinWithdrawP2SHName, @@ -357,7 +358,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { erc20Tests = append(erc20Tests, erc20AdvancedTests...) zetaTests = append(zetaTests, zetaAdvancedTests...) zevmMPTests = append(zevmMPTests, zevmMPAdvancedTests...) - bitcoinWithdrawTests = append(bitcoinWithdrawTests, bitcoinAdvancedTests...) + bitcoinWithdrawTests = append(bitcoinWithdrawTests, bitcoinWithdrawTestsAdvanced...) ethereumTests = append(ethereumTests, ethereumAdvancedTests...) } @@ -466,7 +467,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) @@ -479,10 +480,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 { diff --git a/e2e/runner/accounting.go b/e2e/runner/accounting.go index c47883c3f0..223ca9c8c4 100644 --- a/e2e/runner/accounting.go +++ b/e2e/runner/accounting.go @@ -33,15 +33,20 @@ type Response struct { Amount Amount `json:"amount"` } -func (r *E2ERunner) CheckZRC20ReserveAndSupply() error { - r.Logger.Info("Checking ZRC20 Reserve and Supply") - if err := r.checkEthTSSBalance(); err != nil { - return err - } - if err := r.checkERC20TSSBalance(); err != nil { - return err - } - return r.checkZetaTSSBalance() +func (r *E2ERunner) CheckZRC20BalanceAndSupply() { + r.Logger.Info("Checking ZRC20 Balance vs. Supply") + + err := r.checkEthTSSBalance() + require.NoError(r, err, "ETH balance check failed") + + err = r.checkERC20TSSBalance() + require.NoError(r, err, "ERC20 balance check failed") + + err = r.checkZetaTSSBalance() + require.NoError(r, err, "ZETA balance check failed") + + err = r.CheckBtcTSSBalance() + require.NoError(r, err, "BTC balance check failed") } func (r *E2ERunner) checkEthTSSBalance() error { diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index a452f7d8f3..bec7a1e907 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -145,7 +145,7 @@ func (r *E2ERunner) DepositBTC(receiver common.Address) { r.Logger.Info("ListUnspent:") r.Logger.Info(" spendableAmount: %f", spendableAmount) r.Logger.Info(" spendableUTXOs: %d", spendableUTXOs) - r.Logger.Info("Now sending BTC to tester ZEVM address...") + r.Logger.Info("Now sending two txs to TSS address and tester ZEVM address...") // send initial BTC to the tester ZEVM address amount := 1.15 + zetabitcoin.DefaultDepositorFee @@ -154,6 +154,7 @@ func (r *E2ERunner) DepositBTC(receiver common.Address) { // send a donation to the TSS address to compensate for the funds minted automatically during pool creation // and prevent accounting errors + // it also serves as gas fee for the TSS to send BTC to other addresses _, err = r.SendToTSSFromDeployerWithMemo(0.11, utxos[2:4], []byte(constant.DonationMessage)) require.NoError(r, err) diff --git a/e2e/runner/require.go b/e2e/runner/require.go index 9e296bf748..98496c5f25 100644 --- a/e2e/runner/require.go +++ b/e2e/runner/require.go @@ -24,8 +24,8 @@ func (r *E2ERunner) EnsureNoTrackers() { require.Empty(r, res.OutboundTracker, "there should be no trackers at the end of the test") } -// EnsureZeroBalanceAddressZEVM ensures that the balance of the address is zero in the ZEVM -func (r *E2ERunner) EnsureZeroBalanceAddressZEVM() { +// EnsureZeroBalanceAddressZEVM ensures that the balance of the restricted address is zero in the ZEVM +func (r *E2ERunner) EnsureZeroBalanceOnRestrictedAddressZEVM() { restrictedAddress := ethcommon.HexToAddress(sample.RestrictedEVMAddressTest) // ensure ZETA balance is zero diff --git a/e2e/runner/run.go b/e2e/runner/run.go index c05129b775..fde3de2277 100644 --- a/e2e/runner/run.go +++ b/e2e/runner/run.go @@ -26,11 +26,9 @@ func (r *E2ERunner) RunE2ETest(e2eTest E2ETest, checkAccounting bool) error { } e2eTest.E2ETest(r, args) - //check supplies + // check zrc20 balance vs. supply if checkAccounting { - if err := r.CheckZRC20ReserveAndSupply(); err != nil { - return err - } + r.CheckZRC20BalanceAndSupply() } r.Logger.Print("✅ completed in %s - %s", time.Since(startTime), e2eTest.Description) diff --git a/e2e/runner/setup_bitcoin.go b/e2e/runner/setup_bitcoin.go index 8c46f98e84..88d516e1b7 100644 --- a/e2e/runner/setup_bitcoin.go +++ b/e2e/runner/setup_bitcoin.go @@ -34,15 +34,15 @@ func (r *E2ERunner) SetupBitcoinAccounts(createWallet bool) { r.Logger.Print("✅ Bitcoin account setup in %s", time.Since(startTime)) }() - // setup deployer account + // setup deployer address r.SetupBtcAddress(r.Name, createWallet) - // import the TSS address to index TSS utxos and txs + // import the TSS address to index TSS utxos and transactions err := r.BtcRPCClient.ImportAddress(r.BTCTSSAddress.EncodeAddress()) require.NoError(r, err) r.Logger.Info("⚙️ imported BTC TSSAddress: %s", r.BTCTSSAddress.EncodeAddress()) - // import deployer address to index deployer utxos and txs + // import deployer address to index deployer utxos and transactions err = r.BtcRPCClient.ImportAddress(r.BTCDeployerAddress.EncodeAddress()) require.NoError(r, err) r.Logger.Info("⚙️ imported BTCDeployerAddress: %s", r.BTCDeployerAddress.EncodeAddress())