diff --git a/contrib/localnet/orchestrator/smoketest/test_stress.go b/contrib/localnet/orchestrator/smoketest/test_stress.go index bd03f5b1c7..02a424450d 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" @@ -18,7 +19,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" - "github.com/zeta-chain/zetacore/common" + "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" "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" @@ -28,7 +29,6 @@ import ( const ( StatInterval = 5 - WithdrawInterval = 500 StressTestTimeout = 100 * time.Minute ) @@ -48,7 +48,8 @@ type stressArguments struct { zevmURL string deployerAddress string deployerPrivateKey string - local bool + network string + txnInterval int64 } var stressTestArgs = stressArguments{} @@ -60,7 +61,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) } @@ -85,7 +87,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) @@ -158,13 +160,27 @@ func StressTest(_ *cobra.Command, _ []string) { ) // If stress test is running on local docker environment - if stressTestArgs.local { + if stressTestArgs.network == "PRIVNET" { smokeTest.TestSetupZetaTokenAndConnectorAndZEVMContracts() smokeTest.TestDepositEtherIntoZRC20() smokeTest.TestSendZetaIn() + } 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 + ethZRC20Balance, err := smokeTest.ETHZRC20.BalanceOf(nil, DeployerAddress) + if err != nil { + panic(err) } + fmt.Printf("eth zrc20 balance: %s Wei \n", ethZRC20Balance.String()) - //Pre-approve USDT withdraw on ZEVM + //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)) @@ -197,7 +213,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: @@ -212,13 +228,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: common.GoerliChain().ChainId, + ChainId: getChainID(), }) if err != nil { continue @@ -229,6 +246,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 @@ -274,3 +293,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() int64 { + switch stressTestArgs.network { + case "PRIVNET": + return 1337 + case "TESTNET": + return 5 + case "MAINNET": + return 1 + default: + return 1337 + } +}