Skip to content

Commit

Permalink
fix some lint issues and rename all runners to r
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Jul 7, 2024
1 parent 1469b73 commit 353f962
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 77 deletions.
4 changes: 4 additions & 0 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ func start(_ *cobra.Command, _ []string) error {
hotkeyPass,
server,
)
if err != nil {
startLogger.Error().Err(err).Msg("NewTSS error")
return err
}
if cfg.TestTssKeysign {
err = TestTSS(tss.CurrentPubkey, *tss.Server, masterLogger)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ additional_accounts:
bech32_address: "zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3"
evm_address: "0x8305C114Ea73cAc4A88f39A173803F94741b9055"
private_key: "d88d09a7d6849c15a36eb6931f9dd616091a63e9849a2cc86f309ba11fb8fec5"
user_migration_admin:
bech32_address: "zeta1pvtxa708yvdmszn687nne6nl8qn704daf420xz"
evm_address: "0x0B166ef9e7231Bb80A7A3FA73CEA7F3827E7D5BD"
private_key: "0BCC2FA28B526F90E1D54648D612DB901E860BF68248555593F91EA801C6B482"
rpcs:
zevm: "http://zetacore0:8545"
evm: "http://eth:8545"
Expand Down
29 changes: 14 additions & 15 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/e2etests"
Expand Down Expand Up @@ -67,7 +68,7 @@ func NewLocalCmd() *cobra.Command {
cmd.Flags().Bool(flagSkipSetup, false, "set to true to skip setup")
cmd.Flags().Bool(flagSkipBitcoinSetup, false, "set to true to skip bitcoin wallet setup")
cmd.Flags().Bool(flagSkipHeaderProof, false, "set to true to skip header proof tests")
cmd.Flags().Bool(flagTestMigration, false, "set to true to skip migration tests")
cmd.Flags().Bool(flagTestMigration, false, "set to true to include a migration test at the end")

return cmd
}
Expand Down Expand Up @@ -326,30 +327,30 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
if testMigration {
migrationCtx, cancel := context.WithCancel(context.Background())
deployerRunner.CtxCancel = cancel
migrationStartTime := time.Now()

migrationStartTime := time.Now()
logger.Print("🏁 starting tss migration")

response, err := deployerRunner.CctxClient.LastZetaHeight(migrationCtx, &crosschaintypes.QueryLastZetaHeightRequest{})
if err != nil {
logger.Error("cctxClient.LastZetaHeight error: %s", err)
panic(err)
}
require.NoError(deployerRunner, err)
err = zetaTxServer.UpdateKeygen(response.Height)
if err != nil {
panic(err)
}
require.NoError(deployerRunner, err)

// Generate new TSS
waitKeygenHeight(migrationCtx, deployerRunner.CctxClient, deployerRunner.ObserverClient, logger, 0)

// migration test is a blocking thread, we cannot run other tests in parallel
eg.Go(migrationTestRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTssEthName))
// The migration test migrates funds to a new TSS and then updates the TSS address on zetacore.
// The necessary restarts are done by the zetaclient supervisor
fn := migrationTestRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTssEthName)

if err := eg.Wait(); err != nil {
deployerRunner.CtxCancel()
if err := fn(); err != nil {
logger.Print("❌ %v", err)
logger.Print("❌ tss migration failed")
os.Exit(1)
}

logger.Print("✅ migration tests completed in %s sleeping for 30 secs ", time.Since(migrationStartTime).String())
logger.Print("✅ migration completed in %s ", time.Since(migrationStartTime).String())
logger.Print("🏁 starting post migration tests")

tests := []string{
Expand All @@ -364,8 +365,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
logger.Print("❌ post migration tests failed")
os.Exit(1)
}

logger.Print("✅ migration tests completed in %s", time.Since(migrationStartTime).String())
}

// print and validate report
Expand Down
10 changes: 4 additions & 6 deletions cmd/zetae2e/local/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/zeta-chain/zetacore/e2e/runner"
)

// adminTestRoutine runs admin functions tests
// migrationTestRoutine runs migration related e2e tests
func migrationTestRoutine(
conf config.Config,
deployerRunner *runner.E2ERunner,
Expand All @@ -28,8 +28,8 @@ func migrationTestRoutine(
err = fmt.Errorf("admin panic: %v, stack trace %s", r, stack[:n])
}
}()
account := conf.AdditionalAccounts.UserBitcoin
// initialize runner for erc20 advanced test
account := conf.AdditionalAccounts.UserMigration
// initialize runner for migration test
migrationTestRunner, err := initTestRunner(
"migration",
conf,
Expand All @@ -49,7 +49,7 @@ func migrationTestRoutine(
migrationTestRunner.Logger.Print("🍾 migration tests completed in %s", time.Since(startTime).String())
return nil
}
// run erc20 advanced test
// run migration test
testsToRun, err := migrationTestRunner.GetE2ETestsToRunByName(
e2etests.AllE2ETests,
testNames...,
Expand All @@ -61,7 +61,6 @@ func migrationTestRoutine(
if err := migrationTestRunner.RunE2ETests(testsToRun); err != nil {
return fmt.Errorf("migration tests failed: %v", err)
}

if err := migrationTestRunner.CheckBtcTSSBalance(); err != nil {
migrationTestRunner.Logger.Print("🍾 BTC check error")
}
Expand All @@ -70,5 +69,4 @@ func migrationTestRoutine(

return err
}

}
25 changes: 3 additions & 22 deletions cmd/zetae2e/local/post_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
"github.com/zeta-chain/zetacore/e2e/runner"
)

// postMigrationTestRoutine runs Bitcoin related e2e tests
// postMigrationTestRoutine runs post migration tests
func postMigrationTestRoutine(
conf config.Config,
deployerRunner *runner.E2ERunner,
verbose bool,
testNames ...string,
) func() error {
return func() (err error) {
account := conf.AdditionalAccounts.UserBitcoin
// initialize runner for bitcoin test
account := conf.AdditionalAccounts.UserMigration
// initialize runner for post migration test
postMigrationRunner, err := initTestRunner(
"postMigration",
conf,
Expand All @@ -35,25 +35,6 @@ func postMigrationTestRoutine(
postMigrationRunner.Logger.Print("🏃 starting postMigration tests")
startTime := time.Now()

// funding the account
//txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1000)
//postMigrationRunner.WaitForTxReceiptOnEvm(txERC20Send)
//
//// depositing the necessary tokens on ZetaChain
//txEtherDeposit := postMigrationRunner.DepositEther(false)
//txERC20Deposit := postMigrationRunner.DepositERC20()
//
//postMigrationRunner.WaitForMinedCCTX(txEtherDeposit)
//postMigrationRunner.WaitForMinedCCTX(txERC20Deposit)
//
//postMigrationRunner.Name = "bitcoin"
//postMigrationRunner.SetupBitcoinAccount(initBitcoinNetwork)
//postMigrationRunner.Name = "postMigration"
//postMigrationRunner.DepositBTC(testHeader)

// 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 := postMigrationRunner.GetE2ETestsToRunByName(
e2etests.AllE2ETests,
testNames...,
Expand Down
3 changes: 3 additions & 0 deletions contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ then
# ethers tester
address=$(yq -r '.additional_accounts.user_ether.bech32_address' /root/config.yml)
zetacored add-genesis-account "$address" 100000000000000000000000000azeta
# migration tester
address=$(yq -r '.additional_accounts.user_migration.bech32_address' /root/config.yml)
zetacored add-genesis-account "$address" 100000000000000000000000000azeta

# 3. Copy the genesis.json to all the nodes .And use it to create a gentx for every node
zetacored gentx operator 1000000000000000000000azeta --chain-id=$CHAINID --keyring-backend=$KEYRING --gas-prices 20000000000azeta
Expand Down
6 changes: 6 additions & 0 deletions e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type AdditionalAccounts struct {
UserMisc Account `yaml:"user_misc"`
UserAdmin Account `yaml:"user_admin"`
UserFungibleAdmin Account `yaml:"user_fungible_admin"`
UserMigration Account `yaml:"user_migration"`
}

// RPCs contains the configuration for the RPC endpoints
Expand Down Expand Up @@ -193,6 +194,7 @@ func (a AdditionalAccounts) AsSlice() []Account {
a.UserMisc,
a.UserAdmin,
a.UserFungibleAdmin,
a.UserMigration,
}
}

Expand Down Expand Up @@ -261,6 +263,10 @@ func (c *Config) GenerateKeys() error {
if err != nil {
return err
}
c.AdditionalAccounts.UserMigration, err = generateAccount()
if err != nil {
return err
}
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions e2e/e2etests/test_migrate_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

func TestMigrateTss(r *runner.E2ERunner, args []string) {

func TestMigrateTss(r *runner.E2ERunner, _ []string) {
r.SetBtcAddress(r.Name, false)
stop := r.MineBlocksIfLocalBitcoin()
defer stop()
Expand Down
25 changes: 6 additions & 19 deletions e2e/runner/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,42 @@ func (r *E2ERunner) CheckZRC20ReserveAndSupply() error {
return r.checkZetaTSSBalance()
}

func (runner *E2ERunner) checkEthTSSBalance() error {
func (r *E2ERunner) checkEthTSSBalance() error {

Check failure on line 36 in e2e/runner/accounting.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

allTssAddress, err := runner.ObserverClient.TssHistory(runner.Ctx, &observertypes.QueryTssHistoryRequest{})
allTssAddress, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{})
if err != nil {
return err
}

tssTotalBalance := big.NewInt(0)

for _, tssAddress := range allTssAddress.TssList {
evmAddress, err := runner.ObserverClient.GetTssAddressByFinalizedHeight(runner.Ctx, &observertypes.QueryGetTssAddressByFinalizedHeightRequest{
evmAddress, err := r.ObserverClient.GetTssAddressByFinalizedHeight(r.Ctx, &observertypes.QueryGetTssAddressByFinalizedHeightRequest{
FinalizedZetaHeight: tssAddress.FinalizedZetaHeight,
})
if err != nil {
continue
}

tssBal, err := runner.EVMClient.BalanceAt(runner.Ctx, common.HexToAddress(evmAddress.Eth), nil)
tssBal, err := r.EVMClient.BalanceAt(r.Ctx, common.HexToAddress(evmAddress.Eth), nil)
if err != nil {
continue
}
tssTotalBalance.Add(tssTotalBalance, tssBal)
}

zrc20Supply, err := runner.ETHZRC20.TotalSupply(&bind.CallOpts{})
zrc20Supply, err := r.ETHZRC20.TotalSupply(&bind.CallOpts{})
if err != nil {
return err
}
if tssTotalBalance.Cmp(zrc20Supply) < 0 {
return fmt.Errorf("ETH: TSS balance (%d) < ZRC20 TotalSupply (%d) ", tssTotalBalance, zrc20Supply)
}
runner.Logger.Info("ETH: TSS balance (%d) >= ZRC20 TotalSupply (%d)", tssTotalBalance, zrc20Supply)
r.Logger.Info("ETH: TSS balance (%d) >= ZRC20 TotalSupply (%d)", tssTotalBalance, zrc20Supply)
return nil
}

func (r *E2ERunner) CheckBtcTSSBalance() error {

allTssAddress, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{})
if err != nil {
return err
Expand All @@ -91,20 +90,8 @@ func (r *E2ERunner) CheckBtcTSSBalance() error {
tssTotalBalance += utxo.Amount
}
}

}

//utxos, err := r.BtcRPCClient.ListUnspent()
//if err != nil {
// return err
//}
//var btcBalance float64
//for _, utxo := range utxos {
// if utxo.Address == r.BTCTSSAddress.EncodeAddress() {
// btcBalance += utxo.Amount
// }
//}

zrc20Supply, err := r.BTCZRC20.TotalSupply(&bind.CallOpts{})
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion x/crosschain/keeper/cctx_orchestrator_validate_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func (k Keeper) ValidateInbound(
msg *types.MsgVoteInbound,
shouldPayGas bool,
) (*types.CrossChainTx, error) {

err := k.CheckMigration(ctx, msg)
if err != nil {
return nil, err
Expand Down
12 changes: 1 addition & 11 deletions zetaclient/chains/bitcoin/observer/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,30 +433,20 @@ func (ob *Observer) setIncludedTx(nonce uint64, getTxResult *btcjson.GetTransact
ob.Mu().Lock()
defer ob.Mu().Unlock()
res, found := ob.includedTxResults[outboundID]

fmt.Printf("latest confirmations %d", getTxResult.Confirmations)

if !found { // not found.

fmt.Printf("setIncludedTx: included new bitcoin outbound %s outboundID %s pending nonce %d", txHash, outboundID, ob.pendingNonce)

ob.includedTxHashes[txHash] = true
ob.includedTxResults[outboundID] = getTxResult // include new outbound and enforce rigid 1-to-1 mapping: nonce <===> txHash
if nonce >= ob.pendingNonce { // try increasing pending nonce on every newly included outbound
ob.pendingNonce = nonce + 1
}
ob.logger.Outbound.Info().
Msgf("setIncludedTx: included new bitcoin outbound %s outboundID %s pending nonce %d", txHash, outboundID, ob.pendingNonce)
} else if txHash == res.TxID { // found same hash.

fmt.Printf("setIncludedTx: update bitcoin outbound %s got confirmations %d", txHash, getTxResult.Confirmations)
} else if txHash == res.TxID { // found same hash
ob.includedTxResults[outboundID] = getTxResult // update tx result as confirmations may increase
if getTxResult.Confirmations > res.Confirmations {
ob.logger.Outbound.Info().Msgf("setIncludedTx: bitcoin outbound %s got confirmations %d", txHash, getTxResult.Confirmations)
}
} else { // found other hash.

fmt.Printf("setIncludedTx: duplicate payment by bitcoin outbound %s outboundID %s, prior outbound %s", txHash, outboundID, res.TxID)
// be alert for duplicate payment!!! As we got a new hash paying same cctx (for whatever reason).
delete(ob.includedTxResults, outboundID) // we can't tell which txHash is true, so we remove all to be safe
ob.logger.Outbound.Error().Msgf("setIncludedTx: duplicate payment by bitcoin outbound %s outboundID %s, prior outbound %s", txHash, outboundID, res.TxID)
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/tss/tss_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (tss *TSS) EVMAddress() ethcommon.Address {
}

func (tss *TSS) EVMAddressList() []ethcommon.Address {
var addresses []ethcommon.Address
addresses := make([]ethcommon.Address, 0)
for _, key := range tss.Keys {
addr, err := GetTssAddrEVM(key.PubkeyInBech32)
if err != nil {
Expand Down

0 comments on commit 353f962

Please sign in to comment.