From 887c2962319ef7c0253f6a500ff7c95317ae6ece Mon Sep 17 00:00:00 2001 From: kevinssgh Date: Fri, 14 Jul 2023 18:56:46 -0400 Subject: [PATCH 1/5] initial commit --- .../orchestrator/smoketest/test_stress.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/contrib/localnet/orchestrator/smoketest/test_stress.go b/contrib/localnet/orchestrator/smoketest/test_stress.go index ffa7708b0f..9878392570 100644 --- a/contrib/localnet/orchestrator/smoketest/test_stress.go +++ b/contrib/localnet/orchestrator/smoketest/test_stress.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" + "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/x/crosschain/types" types2 "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -81,7 +82,7 @@ func StressTest(_ *cobra.Command, _ []string) { if err != nil { panic(err) } - fmt.Printf("Deployer address: %s, balance: %d Ether\n", DeployerAddress.Hex(), bal.Div(bal, big.NewInt(1e18))) + fmt.Printf("Deployer address: %s, balance: %d Wei\n", DeployerAddress.Hex(), bal) chainid, err := goerliClient.ChainID(context.Background()) deployerPrivkey, err := crypto.HexToECDSA(stressTestArgs.deployerPrivateKey) @@ -143,9 +144,20 @@ func StressTest(_ *cobra.Command, _ []string) { smokeTest.TestSetupZetaTokenAndConnectorAndZEVMContracts() smokeTest.TestDepositEtherIntoZRC20() smokeTest.TestSendZetaIn() + } else { + ethZRC20Addr, _ := smokeTest.SystemContract.GasCoinZRC20ByChainId(&bind.CallOpts{}, big.NewInt(5)) + smokeTest.ETHZRC20Addr = ethZRC20Addr + smokeTest.ETHZRC20, _ = zrc20.NewZRC20(smokeTest.ETHZRC20Addr, smokeTest.zevmClient) } - //Pre-approve USDT withdraw on ZEVM + // Check zrc20 balance of Deployer address + ethZRC20Balance, err := smokeTest.ETHZRC20.BalanceOf(nil, DeployerAddress) + if err != nil { + panic(err) + } + fmt.Printf("eth zrc20 balance: %s\n Wei", ethZRC20Balance.String()) + + //Pre-approve ETH withdraw on ZEVM fmt.Printf("approving ETH ZRC20...\n") ethZRC20 := smokeTest.ETHZRC20 tx, err := ethZRC20.Approve(smokeTest.zevmAuth, smokeTest.ETHZRC20Addr, big.NewInt(1e18)) From 3afc358fb3aeb3dee81f6635cbdd778cdc72773a Mon Sep 17 00:00:00 2001 From: kevinssgh Date: Fri, 14 Jul 2023 19:01:03 -0400 Subject: [PATCH 2/5] fix format --- contrib/localnet/orchestrator/smoketest/test_stress.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/localnet/orchestrator/smoketest/test_stress.go b/contrib/localnet/orchestrator/smoketest/test_stress.go index 9878392570..c2ef992f4f 100644 --- a/contrib/localnet/orchestrator/smoketest/test_stress.go +++ b/contrib/localnet/orchestrator/smoketest/test_stress.go @@ -155,7 +155,7 @@ func StressTest(_ *cobra.Command, _ []string) { if err != nil { panic(err) } - fmt.Printf("eth zrc20 balance: %s\n Wei", ethZRC20Balance.String()) + fmt.Printf("eth zrc20 balance: %s Wei \n", ethZRC20Balance.String()) //Pre-approve ETH withdraw on ZEVM fmt.Printf("approving ETH ZRC20...\n") From 3f1c0746c202becc6e0dc1612aa276f8b9270d7d Mon Sep 17 00:00:00 2001 From: kevinssgh Date: Thu, 27 Jul 2023 15:44:03 -0400 Subject: [PATCH 3/5] update stress test --- .../orchestrator/smoketest/test_stress.go | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/contrib/localnet/orchestrator/smoketest/test_stress.go b/contrib/localnet/orchestrator/smoketest/test_stress.go index c2ef992f4f..5fedcf7ee3 100644 --- a/contrib/localnet/orchestrator/smoketest/test_stress.go +++ b/contrib/localnet/orchestrator/smoketest/test_stress.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" - "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/x/crosschain/types" types2 "github.com/zeta-chain/zetacore/x/crosschain/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" @@ -25,7 +24,6 @@ import ( const ( StatInterval = 5 - WithdrawInterval = 500 StressTestTimeout = 100 * time.Minute ) @@ -45,7 +43,8 @@ type stressArguments struct { zevmURL string deployerAddress string deployerPrivateKey string - local bool + network string + txnInterval int64 } var stressTestArgs = stressArguments{} @@ -57,7 +56,8 @@ func init() { StressCmd.Flags().StringVar(&stressTestArgs.zevmURL, "zevmURL", "http://zetacore0:8545", "--zevmURL http://zetacore0:8545") StressCmd.Flags().StringVar(&stressTestArgs.deployerAddress, "addr", "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC", "--addr ") StressCmd.Flags().StringVar(&stressTestArgs.deployerPrivateKey, "privKey", "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263", "--privKey ") - StressCmd.Flags().BoolVar(&stressTestArgs.local, "local", true, "--local") + StressCmd.Flags().StringVar(&stressTestArgs.network, "network", "PRIVNET", "--network PRIVNET") + StressCmd.Flags().Int64Var(&stressTestArgs.txnInterval, "tx-interval", 500, "--tx-interval [TIME_INTERVAL_MILLISECONDS]") DeployerAddress = ethcommon.HexToAddress(stressTestArgs.deployerAddress) } @@ -140,7 +140,7 @@ func StressTest(_ *cobra.Command, _ []string) { smokeTest := NewSmokeTest(goerliClient, zevmClient, cctxClient, fungibleClient, goerliAuth, zevmAuth, nil) // If stress test is running on local docker environment - if stressTestArgs.local { + if stressTestArgs.network == "PRIVNET" { smokeTest.TestSetupZetaTokenAndConnectorAndZEVMContracts() smokeTest.TestDepositEtherIntoZRC20() smokeTest.TestSendZetaIn() @@ -190,7 +190,7 @@ func StressTest(_ *cobra.Command, _ []string) { // WithdrawCCtx withdraw USDT from ZEVM to EVM func (sm *SmokeTest) WithdrawCCtx() { - ticker := time.NewTicker(time.Millisecond * WithdrawInterval) + ticker := time.NewTicker(time.Millisecond * time.Duration(stressTestArgs.txnInterval)) for { select { case <-ticker.C: @@ -205,13 +205,14 @@ func (sm *SmokeTest) EchoNetworkMetrics() { var numTicks = 0 var totalMinedTxns = uint64(0) var previousMinedTxns = uint64(0) + for { select { case <-ticker.C: numTicks++ // Get all pending outbound transactions cctxResp, err := sm.cctxClient.CctxAllPending(context.Background(), &types2.QueryAllCctxPendingRequest{ - ChainId: uint64(common.GoerliChain().ChainId), + ChainId: getChainID(), }) if err != nil { continue @@ -267,3 +268,17 @@ func (sm *SmokeTest) WithdrawETHZRC20() { panic(err) } } + +// Get ETH based chain ID - Build flags are conflicting with current lib, need to do this manually +func getChainID() uint64 { + switch stressTestArgs.network { + case "PRIVNET": + return 1337 + case "TESTNET": + return 5 + case "MAINNET": + return 1 + default: + return 1337 + } +} From 178929c9bcf9feb4a599777d01e45046e3670444 Mon Sep 17 00:00:00 2001 From: kevinssgh Date: Wed, 9 Aug 2023 12:23:23 -0400 Subject: [PATCH 4/5] fix potential crash --- contrib/localnet/orchestrator/smoketest/test_stress.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/localnet/orchestrator/smoketest/test_stress.go b/contrib/localnet/orchestrator/smoketest/test_stress.go index 5fedcf7ee3..79b7fae475 100644 --- a/contrib/localnet/orchestrator/smoketest/test_stress.go +++ b/contrib/localnet/orchestrator/smoketest/test_stress.go @@ -223,6 +223,8 @@ func (sm *SmokeTest) EchoNetworkMetrics() { }) if len(sends) > 0 { fmt.Printf("pending nonces %d to %d\n", sends[0].GetCurrentOutTxParam().OutboundTxTssNonce, sends[len(sends)-1].GetCurrentOutTxParam().OutboundTxTssNonce) + } else { + continue } // // Get all trackers From e62816d242e1df45467b70ef4dc93afd6d9efec0 Mon Sep 17 00:00:00 2001 From: kevinssgh Date: Thu, 21 Sep 2023 12:20:23 -0400 Subject: [PATCH 5/5] assert valid network type --- contrib/localnet/orchestrator/smoketest/test_stress.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/localnet/orchestrator/smoketest/test_stress.go b/contrib/localnet/orchestrator/smoketest/test_stress.go index 20b0584da1..5bf4db0f50 100644 --- a/contrib/localnet/orchestrator/smoketest/test_stress.go +++ b/contrib/localnet/orchestrator/smoketest/test_stress.go @@ -5,6 +5,7 @@ package main import ( "context" + "errors" "fmt" "math/big" "os" @@ -163,10 +164,13 @@ func StressTest(_ *cobra.Command, _ []string) { smokeTest.TestSetupZetaTokenAndConnectorAndZEVMContracts() smokeTest.TestDepositEtherIntoZRC20() smokeTest.TestSendZetaIn() - } else { + } else if stressTestArgs.network == "TESTNET" { ethZRC20Addr, _ := smokeTest.SystemContract.GasCoinZRC20ByChainId(&bind.CallOpts{}, big.NewInt(5)) smokeTest.ETHZRC20Addr = ethZRC20Addr smokeTest.ETHZRC20, _ = zrc20.NewZRC20(smokeTest.ETHZRC20Addr, smokeTest.zevmClient) + } else { + err := errors.New("invalid network argument: " + stressTestArgs.network) + panic(err) } // Check zrc20 balance of Deployer address