From 9a63d23f5d5e3c61d8ac8ebd7d17c24b538e81b1 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 15 Apr 2024 17:14:41 +0200 Subject: [PATCH] testutil and supply checker --- zetaclient/interfaces/signer.go | 6 +- zetaclient/keys/keys.go | 48 ++++++------ zetaclient/metrics/burn_rate.go | 17 +++-- zetaclient/metrics/telemetry.go | 46 ++++++------ zetaclient/supplychecker/logger.go | 29 ++++++++ zetaclient/supplychecker/validate.go | 34 +++++++++ .../supplychecker/zeta_supply_checker.go | 73 ++++++------------- zetaclient/testutils/constant.go | 36 ++++++--- zetaclient/testutils/testdata.go | 36 +-------- 9 files changed, 171 insertions(+), 154 deletions(-) create mode 100644 zetaclient/supplychecker/logger.go create mode 100644 zetaclient/supplychecker/validate.go diff --git a/zetaclient/interfaces/signer.go b/zetaclient/interfaces/signer.go index 461902359c..f9ed6227b4 100644 --- a/zetaclient/interfaces/signer.go +++ b/zetaclient/interfaces/signer.go @@ -16,8 +16,11 @@ import ( type TSSSigner interface { Pubkey() []byte - // Sign: Specify optionalPubkey to use a different pubkey than the current pubkey set during keygen + + // Sign signs the data + // Note: it specifies optionalPubkey to use a different pubkey than the current pubkey set during keygen Sign(data []byte, height uint64, nonce uint64, chain *chains.Chain, optionalPubkey string) ([65]byte, error) + EVMAddress() ethcommon.Address BTCAddress() string BTCAddressWitnessPubkeyHash() *btcutil.AddressWitnessPubKeyHash @@ -90,6 +93,7 @@ func (s TestSigner) BTCAddressWitnessPubkeyHash() *btcutil.AddressWitnessPubKeyH fmt.Printf("error parsing pubkey: %v", err) return nil } + // witness program: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Witness_program // The HASH160 of the public key must match the 20-byte witness program. addrWPKH, err := btcutil.NewAddressWitnessPubKeyHash(btcutil.Hash160(pk.SerializeCompressed()), &chaincfg.TestNet3Params) diff --git a/zetaclient/keys/keys.go b/zetaclient/keys/keys.go index 1ca248aff9..3e8009acbe 100644 --- a/zetaclient/keys/keys.go +++ b/zetaclient/keys/keys.go @@ -86,25 +86,6 @@ func GetKeyringKeybase(cfg config.Config, hotkeyPassword string) (ckeys.Keyring, return kb, pubkeyBech32, nil } -// getKeybase will create an instance of Keybase -func getKeybase(zetaCoreHome string, reader io.Reader, keyringBackend config.KeyringBackend) (ckeys.Keyring, error) { - cliDir := zetaCoreHome - if len(zetaCoreHome) == 0 { - return nil, fmt.Errorf("zetaCoreHome is empty") - } - registry := codectypes.NewInterfaceRegistry() - cryptocodec.RegisterInterfaces(registry) - cdc := codec.NewProtoCodec(registry) - - // create a new keybase based on the selected backend - backend := ckeys.BackendTest - if keyringBackend == config.KeyringBackendFile { - backend = ckeys.BackendFile - } - - return ckeys.New(sdk.KeyringServiceName(), backend, cliDir, reader, cdc) -} - // GetSignerInfo return signer info func (k *Keys) GetSignerInfo() *ckeys.Record { signer := GetGranteeKeyName(k.signerName) @@ -184,13 +165,32 @@ func (k *Keys) GetHotkeyPassword() string { } func SetupConfigForTest() { - config := sdk.GetConfig() - config.SetBech32PrefixForAccount(cmd.Bech32PrefixAccAddr, cmd.Bech32PrefixAccPub) - config.SetBech32PrefixForValidator(cmd.Bech32PrefixValAddr, cmd.Bech32PrefixValPub) - config.SetBech32PrefixForConsensusNode(cmd.Bech32PrefixConsAddr, cmd.Bech32PrefixConsPub) + testConfig := sdk.GetConfig() + testConfig.SetBech32PrefixForAccount(cmd.Bech32PrefixAccAddr, cmd.Bech32PrefixAccPub) + testConfig.SetBech32PrefixForValidator(cmd.Bech32PrefixValAddr, cmd.Bech32PrefixValPub) + testConfig.SetBech32PrefixForConsensusNode(cmd.Bech32PrefixConsAddr, cmd.Bech32PrefixConsPub) //config.SetCoinType(cmd.MetaChainCoinType) - config.SetFullFundraiserPath(cmd.ZetaChainHDPath) + testConfig.SetFullFundraiserPath(cmd.ZetaChainHDPath) sdk.SetCoinDenomRegex(func() string { return cmd.DenomRegex }) } + +// getKeybase will create an instance of Keybase +func getKeybase(zetaCoreHome string, reader io.Reader, keyringBackend config.KeyringBackend) (ckeys.Keyring, error) { + cliDir := zetaCoreHome + if len(zetaCoreHome) == 0 { + return nil, fmt.Errorf("zetaCoreHome is empty") + } + registry := codectypes.NewInterfaceRegistry() + cryptocodec.RegisterInterfaces(registry) + cdc := codec.NewProtoCodec(registry) + + // create a new keybase based on the selected backend + backend := ckeys.BackendTest + if keyringBackend == config.KeyringBackendFile { + backend = ckeys.BackendFile + } + + return ckeys.New(sdk.KeyringServiceName(), backend, cliDir, reader, cdc) +} diff --git a/zetaclient/metrics/burn_rate.go b/zetaclient/metrics/burn_rate.go index e4c6053ccd..844a862fb7 100644 --- a/zetaclient/metrics/burn_rate.go +++ b/zetaclient/metrics/burn_rate.go @@ -6,6 +6,7 @@ import ( sdkmath "cosmossdk.io/math" ) +// BurnRate calculates the average burn rate for a range of blocks. type BurnRate struct { blockLow int64 blockHigh int64 @@ -14,6 +15,7 @@ type BurnRate struct { queue []int64 } +// NewBurnRate creates a new BurnRate instance with a window size. func NewBurnRate(windowSize int64) *BurnRate { return &BurnRate{ blockLow: 1, @@ -24,9 +26,8 @@ func NewBurnRate(windowSize int64) *BurnRate { } } -// AddFee - adds fee amount spent on a tx for a particular block. It is added to a queue which is used to calculate -// -// the average burn rate for a range of blocks determined by the window size. +// AddFee adds fee amount spent on a tx for a particular block. It is added to a queue which is used to calculate +// the average burn rate for a range of blocks determined by the window size. func (br *BurnRate) AddFee(amount int64, block int64) error { // Check if block is in range of the window if block < br.blockLow { @@ -58,9 +59,8 @@ func (br *BurnRate) AddFee(amount int64, block int64) error { return nil } -// enqueueEntry - add fee entry into queue if is in range of the window. A padding is added if the block height is -// -// more than one block greater than the highest range. +// enqueueEntry adds fee entry into queue if is in range of the window. A padding is added if the block height is +// more than one block greater than the highest range. func (br *BurnRate) enqueueEntry(block int64, amount int64) error { diff := block - br.blockHigh if diff < 1 { @@ -82,7 +82,8 @@ func (br *BurnRate) enqueueEntry(block int64, amount int64) error { return nil } -// dequeueOldEntries - when the window slides forward, older entries in the queue need to be cleared. +// dequeueOldEntries dequeues old entries +// when the window slides forward, older entries in the queue need to be cleared. func (br *BurnRate) dequeueOldEntries() error { diff := br.blockHigh - br.blockLow if diff < br.windowSize { @@ -102,7 +103,7 @@ func (br *BurnRate) dequeueOldEntries() error { return nil } -// GetBurnRate - calculate current burn rate and return the value. +// GetBurnRate calculates current burn rate and return the value. func (br *BurnRate) GetBurnRate() sdkmath.Int { if br.blockHigh < br.windowSize { return sdkmath.NewInt(br.total).QuoRaw(br.blockHigh) diff --git a/zetaclient/metrics/telemetry.go b/zetaclient/metrics/telemetry.go index 209bf61fed..bdedbd9c50 100644 --- a/zetaclient/metrics/telemetry.go +++ b/zetaclient/metrics/telemetry.go @@ -39,32 +39,35 @@ func NewTelemetryServer() *TelemetryServer { return hs } -// setter/getter for p2pid +// SetP2PID sets p2pid func (t *TelemetryServer) SetP2PID(p2pid string) { t.mu.Lock() t.p2pid = p2pid t.mu.Unlock() } +// GetP2PID gets p2pid func (t *TelemetryServer) GetP2PID() string { t.mu.Lock() defer t.mu.Unlock() return t.p2pid } -// setter/getter for p2pid +// SetIPAddress sets p2pid func (t *TelemetryServer) SetIPAddress(ip string) { t.mu.Lock() t.ipAddress = ip t.mu.Unlock() } +// GetIPAddress gets p2pid func (t *TelemetryServer) GetIPAddress() string { t.mu.Lock() defer t.mu.Unlock() return t.ipAddress } +// AddFeeEntry adds fee entry func (t *TelemetryServer) AddFeeEntry(block int64, amount int64) { t.mu.Lock() err := t.HotKeyBurnRate.AddFee(amount, block) @@ -74,7 +77,7 @@ func (t *TelemetryServer) AddFeeEntry(block int64, amount int64) { t.mu.Unlock() } -// NewHandler registers the API routes and returns a new HTTP handler +// Handlers registers the API routes and returns a new HTTP handler func (t *TelemetryServer) Handlers() http.Handler { router := mux.NewRouter() router.Handle("/ping", http.HandlerFunc(t.pingHandler)).Methods(http.MethodGet) @@ -82,13 +85,8 @@ func (t *TelemetryServer) Handlers() http.Handler { router.Handle("/ip", http.HandlerFunc(t.ipHandler)).Methods(http.MethodGet) router.Handle("/hotkeyburnrate", http.HandlerFunc(t.hotKeyFeeBurnRate)).Methods(http.MethodGet) - // router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) - // router.Handle("/debug/pprof/heap", pprof.Handler("heap")) - // router.HandleFunc("/debug/pprof/", pprof.Index) - // router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) - - //router.Handle("/pending", http.HandlerFunc(t.pendingHandler)).Methods(http.MethodGet) router.Use(logMiddleware()) + return router } @@ -97,7 +95,7 @@ func (t *TelemetryServer) Start() error { return errors.New("invalid http server instance") } if err := t.s.ListenAndServe(); err != nil { - if err != http.ErrServerClosed { + if !errors.Is(err, http.ErrServerClosed) { return fmt.Errorf("fail to start http server: %w", err) } } @@ -105,20 +103,6 @@ func (t *TelemetryServer) Start() error { return nil } -func logMiddleware() mux.MiddlewareFunc { - return func(handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - log.Debug(). - Str("route", r.URL.Path). - Str("port", r.URL.Port()). - Str("method", r.Method). - Msg("HTTP request received") - - handler.ServeHTTP(w, r) - }) - } -} - func (t *TelemetryServer) Stop() error { c, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -153,3 +137,17 @@ func (t *TelemetryServer) hotKeyFeeBurnRate(w http.ResponseWriter, _ *http.Reque defer t.mu.Unlock() fmt.Fprintf(w, "%v", t.HotKeyBurnRate.GetBurnRate()) } + +func logMiddleware() mux.MiddlewareFunc { + return func(handler http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + log.Debug(). + Str("route", r.URL.Path). + Str("port", r.URL.Port()). + Str("method", r.Method). + Msg("HTTP request received") + + handler.ServeHTTP(w, r) + }) + } +} diff --git a/zetaclient/supplychecker/logger.go b/zetaclient/supplychecker/logger.go new file mode 100644 index 0000000000..dc80c3e490 --- /dev/null +++ b/zetaclient/supplychecker/logger.go @@ -0,0 +1,29 @@ +package supplychecker + +import ( + sdkmath "cosmossdk.io/math" + "github.com/rs/zerolog" + "github.com/zeta-chain/zetacore/zetaclient/bitcoin" +) + +// ZetaSupplyCheckLogs is a struct to log the output of the ZetaSupplyChecker +type ZetaSupplyCheckLogs struct { + Logger zerolog.Logger + AbortedTxAmounts sdkmath.Int `json:"aborted_tx_amounts"` + ZetaInTransit sdkmath.Int `json:"zeta_in_transit"` + ExternalChainTotalSupply sdkmath.Int `json:"external_chain_total_supply"` + ZetaTokenSupplyOnNode sdkmath.Int `json:"zeta_token_supply_on_node"` + EthLockedAmount sdkmath.Int `json:"eth_locked_amount"` + NodeAmounts sdkmath.Int `json:"node_amounts"` + LHS sdkmath.Int `json:"LHS"` + RHS sdkmath.Int `json:"RHS"` + SupplyCheckSuccess bool `json:"supply_check_success"` +} + +func (z ZetaSupplyCheckLogs) LogOutput() { + output, err := bitcoin.PrettyPrintStruct(z) + if err != nil { + z.Logger.Error().Err(err).Msgf("error pretty printing struct") + } + z.Logger.Info().Msgf(output) +} diff --git a/zetaclient/supplychecker/validate.go b/zetaclient/supplychecker/validate.go new file mode 100644 index 0000000000..36c2ed68a5 --- /dev/null +++ b/zetaclient/supplychecker/validate.go @@ -0,0 +1,34 @@ +package supplychecker + +import ( + sdkmath "cosmossdk.io/math" + "github.com/rs/zerolog" +) + +func ValidateZetaSupply(logger zerolog.Logger, abortedTxAmounts, zetaInTransit, genesisAmounts, externalChainTotalSupply, zetaTokenSupplyOnNode, ethLockedAmount sdkmath.Int) bool { + lhs := ethLockedAmount.Sub(abortedTxAmounts) + rhs := zetaTokenSupplyOnNode.Add(zetaInTransit).Add(externalChainTotalSupply).Sub(genesisAmounts) + + copyZetaTokenSupplyOnNode := zetaTokenSupplyOnNode + copyGenesisAmounts := genesisAmounts + nodeAmounts := copyZetaTokenSupplyOnNode.Sub(copyGenesisAmounts) + logs := ZetaSupplyCheckLogs{ + Logger: logger, + AbortedTxAmounts: abortedTxAmounts, + ZetaInTransit: zetaInTransit, + ExternalChainTotalSupply: externalChainTotalSupply, + NodeAmounts: nodeAmounts, + ZetaTokenSupplyOnNode: zetaTokenSupplyOnNode, + EthLockedAmount: ethLockedAmount, + LHS: lhs, + RHS: rhs, + } + defer logs.LogOutput() + if !lhs.Equal(rhs) { + logs.SupplyCheckSuccess = false + return false + } + + logs.SupplyCheckSuccess = true + return true +} diff --git a/zetaclient/supplychecker/zeta_supply_checker.go b/zetaclient/supplychecker/zeta_supply_checker.go index 14b4c056d2..7e628247d9 100644 --- a/zetaclient/supplychecker/zeta_supply_checker.go +++ b/zetaclient/supplychecker/zeta_supply_checker.go @@ -4,7 +4,6 @@ import ( "fmt" appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context" - "github.com/zeta-chain/zetacore/zetaclient/bitcoin" "github.com/zeta-chain/zetacore/zetaclient/interfaces" "github.com/zeta-chain/zetacore/zetaclient/zetabridge" @@ -22,6 +21,7 @@ import ( clienttypes "github.com/zeta-chain/zetacore/zetaclient/types" ) +// ZetaSupplyChecker is a utility to check the total supply of Zeta tokens type ZetaSupplyChecker struct { coreContext *corecontext.ZetaCoreContext evmClient map[int64]*ethclient.Client @@ -34,7 +34,12 @@ type ZetaSupplyChecker struct { genesisSupply sdkmath.Int } -func NewZetaSupplyChecker(appContext *appcontext.AppContext, zetaClient *zetabridge.ZetaCoreBridge, logger zerolog.Logger) (ZetaSupplyChecker, error) { +// NewZetaSupplyChecker creates a new ZetaSupplyChecker +func NewZetaSupplyChecker( + appContext *appcontext.AppContext, + zetaClient *zetabridge.ZetaCoreBridge, + logger zerolog.Logger, +) (ZetaSupplyChecker, error) { dynamicTicker, err := clienttypes.NewDynamicTicker("ZETASupplyTicker", 15) if err != nil { return ZetaSupplyChecker{}, err @@ -50,6 +55,7 @@ func NewZetaSupplyChecker(appContext *appcontext.AppContext, zetaClient *zetabri coreContext: appContext.ZetaCoreContext(), zetaClient: zetaClient, } + for _, evmConfig := range appContext.Config().GetAllEVMConfigs() { if evmConfig.Chain.IsZetaChain() { continue @@ -70,10 +76,12 @@ func NewZetaSupplyChecker(appContext *appcontext.AppContext, zetaClient *zetabri zetaSupplyChecker.ethereumChain = *chain } } + balances, err := zetaSupplyChecker.zetaClient.GetGenesisSupply() if err != nil { return zetaSupplyChecker, err } + tokensMintedAtBeginBlock, ok := sdkmath.NewIntFromString("200000000000000000") if !ok { return zetaSupplyChecker, fmt.Errorf("error parsing tokens minted at begin block") @@ -84,6 +92,7 @@ func NewZetaSupplyChecker(appContext *appcontext.AppContext, zetaClient *zetabri return zetaSupplyChecker, nil } + func (zs *ZetaSupplyChecker) Start() { defer zs.ticker.Stop() for { @@ -119,15 +128,18 @@ func (zs *ZetaSupplyChecker) CheckZetaTokenSupply() error { if err != nil { return err } + totalSupply, err := zetatokenNonEth.TotalSupply(nil) if err != nil { return err } + totalSupplyInt, ok := sdkmath.NewIntFromString(totalSupply.String()) if !ok { zs.logger.Error().Msgf("error parsing total supply for chain %d", chain.ChainId) continue } + externalChainTotalSupply = externalChainTotalSupply.Add(totalSupplyInt) } @@ -135,6 +147,7 @@ func (zs *ZetaSupplyChecker) CheckZetaTokenSupply() error { if !ok { return fmt.Errorf("eth config not found for chain id %d", zs.ethereumChain.ChainId) } + ethConnectorAddressString := evmChainParams.ConnectorContractAddress ethConnectorAddress := ethcommon.HexToAddress(ethConnectorAddressString) ethConnectorContract, err := evm.FetchConnectorContractEth(ethConnectorAddress, zs.evmClient[zs.ethereumChain.ChainId]) @@ -146,6 +159,7 @@ func (zs *ZetaSupplyChecker) CheckZetaTokenSupply() error { if err != nil { return err } + ethLockedAmountInt, ok := sdkmath.NewIntFromString(ethLockedAmount.String()) if !ok { return fmt.Errorf("error parsing eth locked amount") @@ -156,60 +170,15 @@ func (zs *ZetaSupplyChecker) CheckZetaTokenSupply() error { if err != nil { return err } + abortedAmount, err := zs.AbortedTxAmount() if err != nil { return err } - ValidateZetaSupply(zs.logger, abortedAmount, zetaInTransit, zs.genesisSupply, externalChainTotalSupply, zetaTokenSupplyOnNode, ethLockedAmountInt) - return nil -} -type ZetaSupplyCheckLogs struct { - Logger zerolog.Logger - AbortedTxAmounts sdkmath.Int `json:"aborted_tx_amounts"` - ZetaInTransit sdkmath.Int `json:"zeta_in_transit"` - ExternalChainTotalSupply sdkmath.Int `json:"external_chain_total_supply"` - ZetaTokenSupplyOnNode sdkmath.Int `json:"zeta_token_supply_on_node"` - EthLockedAmount sdkmath.Int `json:"eth_locked_amount"` - NodeAmounts sdkmath.Int `json:"node_amounts"` - LHS sdkmath.Int `json:"LHS"` - RHS sdkmath.Int `json:"RHS"` - SupplyCheckSuccess bool `json:"supply_check_success"` -} - -func (z ZetaSupplyCheckLogs) LogOutput() { - output, err := bitcoin.PrettyPrintStruct(z) - if err != nil { - z.Logger.Error().Err(err).Msgf("error pretty printing struct") - } - z.Logger.Info().Msgf(output) -} + ValidateZetaSupply(zs.logger, abortedAmount, zetaInTransit, zs.genesisSupply, externalChainTotalSupply, zetaTokenSupplyOnNode, ethLockedAmountInt) -func ValidateZetaSupply(logger zerolog.Logger, abortedTxAmounts, zetaInTransit, genesisAmounts, externalChainTotalSupply, zetaTokenSupplyOnNode, ethLockedAmount sdkmath.Int) bool { - lhs := ethLockedAmount.Sub(abortedTxAmounts) - rhs := zetaTokenSupplyOnNode.Add(zetaInTransit).Add(externalChainTotalSupply).Sub(genesisAmounts) - - copyZetaTokenSupplyOnNode := zetaTokenSupplyOnNode - copyGenesisAmounts := genesisAmounts - nodeAmounts := copyZetaTokenSupplyOnNode.Sub(copyGenesisAmounts) - logs := ZetaSupplyCheckLogs{ - Logger: logger, - AbortedTxAmounts: abortedTxAmounts, - ZetaInTransit: zetaInTransit, - ExternalChainTotalSupply: externalChainTotalSupply, - NodeAmounts: nodeAmounts, - ZetaTokenSupplyOnNode: zetaTokenSupplyOnNode, - EthLockedAmount: ethLockedAmount, - LHS: lhs, - RHS: rhs, - } - defer logs.LogOutput() - if !lhs.Equal(rhs) { - logs.SupplyCheckSuccess = false - return false - } - logs.SupplyCheckSuccess = true - return true + return nil } func (zs *ZetaSupplyChecker) AbortedTxAmount() (sdkmath.Int, error) { @@ -229,6 +198,7 @@ func (zs *ZetaSupplyChecker) GetAmountOfZetaInTransit() sdkmath.Int { chainsToCheck = append(append(chainsToCheck, zs.externalEvmChain...), zs.ethereumChain) cctxs := zs.GetPendingCCTXInTransit(chainsToCheck) amount := sdkmath.ZeroUint() + for _, cctx := range cctxs { amount = amount.Add(cctx.GetCurrentOutTxParam().Amount) } @@ -236,8 +206,10 @@ func (zs *ZetaSupplyChecker) GetAmountOfZetaInTransit() sdkmath.Int { if !ok { panic("error parsing amount") } + return amountInt } + func (zs *ZetaSupplyChecker) GetPendingCCTXInTransit(receivingChains []chains.Chain) []*types.CrossChainTx { cctxInTransit := make([]*types.CrossChainTx, 0) for _, chain := range receivingChains { @@ -266,5 +238,6 @@ func (zs *ZetaSupplyChecker) GetPendingCCTXInTransit(receivingChains []chains.Ch } } } + return cctxInTransit } diff --git a/zetaclient/testutils/constant.go b/zetaclient/testutils/constant.go index 05cab82256..e9b37f6dba 100644 --- a/zetaclient/testutils/constant.go +++ b/zetaclient/testutils/constant.go @@ -3,16 +3,20 @@ package testutils import ethcommon "github.com/ethereum/go-ethereum/common" const ( - // tss addresses + // TSSAddressEVMMainnet the EVM TSS address for test purposes + // Note: public key is zetapub1addwnpepqtadxdyt037h86z60nl98t6zk56mw5zpnm79tsmvspln3hgt5phdc79kvfc TSSAddressEVMMainnet = "0x70e967acFcC17c3941E87562161406d41676FD83" + + // TSSAddressBTCMainnet the BTC TSS address for test purposes TSSAddressBTCMainnet = "bc1qm24wp577nk8aacckv8np465z3dvmu7ry45el6y" - TssPubkeyEVMMainnet = "zetapub1addwnpepqtadxdyt037h86z60nl98t6zk56mw5zpnm79tsmvspln3hgt5phdc79kvfc" + // TSSAddressEVMAthens3 the EVM TSS address for test purposes + // Note: public key is zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p TSSAddressEVMAthens3 = "0x8531a5aB847ff5B22D855633C25ED1DA3255247e" + + // TSSAddressBTCAthens3 the BTC TSS address for test purposes TSSAddressBTCAthens3 = "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur" - TssPubkeyEVMAthens3 = "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p" - // some other addresses OtherAddress1 = "0x21248Decd0B7EcB0F30186297766b8AB6496265b" OtherAddress2 = "0x33A351C90aF486AebC35042Bb0544123cAed26AB" OtherAddress3 = "0x86B77E4fBd07CFdCc486cAe4F2787fB5C5a62cd3" @@ -20,22 +24,30 @@ const ( // ConnectorAddresses contains constants ERC20 connector addresses for testing var ConnectorAddresses = map[int64]ethcommon.Address{ - // mainnet - 1: ethcommon.HexToAddress("0x000007Cf399229b2f5A4D043F20E90C9C98B7C6a"), + // Connector address on Ethereum mainnet + 1: ethcommon.HexToAddress("0x000007Cf399229b2f5A4D043F20E90C9C98B7C6a"), + + // Connector address on Binance Smart Chain mainnet 56: ethcommon.HexToAddress("0x000063A6e758D9e2f438d430108377564cf4077D"), - // testnet - 5: ethcommon.HexToAddress("0x00005E3125aBA53C5652f9F0CE1a4Cf91D8B15eA"), + // Connector address on Goerli testnet + 5: ethcommon.HexToAddress("0x00005E3125aBA53C5652f9F0CE1a4Cf91D8B15eA"), + + // Connector address on Binance Smart Chain testnet 97: ethcommon.HexToAddress("0x0000ecb8cdd25a18F12DAA23f6422e07fBf8B9E1"), } // CustodyAddresses contains constants ERC20 custody addresses for testing var CustodyAddresses = map[int64]ethcommon.Address{ - // mainnet - 1: ethcommon.HexToAddress("0x0000030Ec64DF25301d8414eE5a29588C4B0dE10"), + // ERC20 custody address on Ethereum mainnet + 1: ethcommon.HexToAddress("0x0000030Ec64DF25301d8414eE5a29588C4B0dE10"), + + // ERC20 custody address on Binance Smart Chain mainnet 56: ethcommon.HexToAddress("0x00000fF8fA992424957F97688015814e707A0115"), - // testnet - 5: ethcommon.HexToAddress("0x000047f11C6E42293F433C82473532E869Ce4Ec5"), + // ERC20 custody address on Goerli testnet + 5: ethcommon.HexToAddress("0x000047f11C6E42293F433C82473532E869Ce4Ec5"), + + // ERC20 custody address on Binance Smart Chain testnet 97: ethcommon.HexToAddress("0x0000a7Db254145767262C6A81a7eE1650684258e"), } diff --git a/zetaclient/testutils/testdata.go b/zetaclient/testutils/testdata.go index 37b6cbab14..01033a3157 100644 --- a/zetaclient/testutils/testdata.go +++ b/zetaclient/testutils/testdata.go @@ -24,19 +24,6 @@ const ( RestrictedBtcAddressTest = "bcrt1qzp4gt6fc7zkds09kfzaf9ln9c5rvrzxmy6qmpp" ) -// SaveObjectToJSONFile saves an object to a file in JSON format -func SaveObjectToJSONFile(obj interface{}, filename string) error { - file, err := os.Create(filepath.Clean(filename)) - if err != nil { - return err - } - defer file.Close() - - // write the struct to the file - encoder := json.NewEncoder(file) - return encoder.Encode(obj) -} - // LoadObjectFromJSONFile loads an object from a file in JSON format func LoadObjectFromJSONFile(t *testing.T, obj interface{}, filename string) { file, err := os.Open(filepath.Clean(filename)) @@ -55,27 +42,6 @@ func ComplianceConfigTest() config.ComplianceConfig { } } -// SaveTrimedEVMBlockTrimTxInput trims tx input data from a block and saves it to a file -func SaveEVMBlockTrimTxInput(block *ethrpc.Block, filename string) error { - for i := range block.Transactions { - block.Transactions[i].Input = "0x" - } - return SaveObjectToJSONFile(block, filename) -} - -// SaveTrimedBTCBlockTrimTx trims tx data from a block and saves it to a file -func SaveBTCBlockTrimTx(blockVb *btcjson.GetBlockVerboseTxResult, filename string) error { - for i := range blockVb.Tx { - // reserve one coinbase tx and one non-coinbase tx - if i >= 2 { - blockVb.Tx[i].Hex = "" - blockVb.Tx[i].Vin = nil - blockVb.Tx[i].Vout = nil - } - } - return SaveObjectToJSONFile(blockVb, filename) -} - // LoadEVMBlock loads archived evm block from file func LoadEVMBlock(t *testing.T, chainID int64, blockNumber uint64, trimmed bool) *ethrpc.Block { name := path.Join("../", TestDataPathEVM, FileNameEVMBlock(chainID, blockNumber, trimmed)) @@ -208,7 +174,7 @@ func LoadEVMIntxNReceiptDonation( return tx, receipt } -// LoadTxNReceiptNCctx loads archived intx, receipt and corresponding cctx from file +// LoadEVMIntxNReceiptNCctx loads archived intx, receipt and corresponding cctx from file func LoadEVMIntxNReceiptNCctx( t *testing.T, chainID int64,