Skip to content

Commit

Permalink
make token sending parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Dec 23, 2023
1 parent a660a34 commit 86ee742
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 49 deletions.
91 changes: 45 additions & 46 deletions contrib/localnet/orchestrator/smoketest/cmd/smoketest/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func localSmokeTest(cmd *cobra.Command, _ []string) {
setCosmosConfig()

// wait for Genesis
logger.Print("⏳ wait 40s for genesis")
logger.Print("⏳ wait 35s for genesis")
time.Sleep(40 * time.Second)

// initialize deployer runner with config
Expand All @@ -146,22 +146,6 @@ func localSmokeTest(cmd *cobra.Command, _ []string) {
deployerRunner.SetZEVMContracts()
logger.Print("✅ setup completed in %s", time.Since(startTime))

// fund accounts
logger.Print("⚙️ funding runner accounts")
startTime = time.Now()
deployerRunner.SendZetaOnEvm(UserERC20Address, 1000)
deployerRunner.SendUSDTOnEvm(UserERC20Address, 10)
deployerRunner.SendZetaOnEvm(UserZetaTestAddress, 1000)
deployerRunner.SendZetaOnEvm(UserBitcoinAddress, 1000)
deployerRunner.SendZetaOnEvm(UserEtherAddress, 1000)
deployerRunner.SendZetaOnEvm(UserMiscAddress, 1000)
deployerRunner.SendZetaOnEvm(UserERC20AdvancedAddress, 1000)
deployerRunner.SendUSDTOnEvm(UserERC20AdvancedAddress, 1000)
logger.Print("✅ funding completed in %s", time.Since(startTime))

// error group for running multiple smoke tests concurrently
var eg errgroup.Group

// initialize runner for erc20 test
erc20Runner, err := initERC20Runner(conf, deployerRunner, verbose)
if err != nil {
Expand Down Expand Up @@ -199,17 +183,13 @@ func localSmokeTest(cmd *cobra.Command, _ []string) {
}

// run tests
eg.Go(erc20TestRoutine(erc20Runner))
eg.Go(zetaTestRoutine(zetaRunner))
eg.Go(bitcoinTestRoutine(bitcoinRunner))
eg.Go(ethereumTestRoutine(etherRunner))
eg.Go(miscTestRoutine(miscRunner))
eg.Go(erc20AdvancedTestRoutine(erc20AdvancedRunner))

// deploy zevm swap and context apps
//logger.Print("⚙️ setting up ZEVM swap and context apps")
//sm.SetupZEVMSwapApp()
//sm.SetupContextApp()
var eg errgroup.Group
eg.Go(erc20TestRoutine(erc20Runner, deployerRunner))
eg.Go(zetaTestRoutine(zetaRunner, deployerRunner))
eg.Go(bitcoinTestRoutine(bitcoinRunner, deployerRunner))
eg.Go(ethereumTestRoutine(etherRunner, deployerRunner))
eg.Go(miscTestRoutine(miscRunner, deployerRunner))
eg.Go(erc20AdvancedTestRoutine(erc20AdvancedRunner, deployerRunner))

if err := eg.Wait(); err != nil {
logger.Print("❌ %v", err)
Expand All @@ -221,7 +201,7 @@ func localSmokeTest(cmd *cobra.Command, _ []string) {
}

// erc20TestRoutine runs erc20 related smoke tests
func erc20TestRoutine(erc20Runner *runner.SmokeTestRunner) func() error {
func erc20TestRoutine(erc20Runner, deployerRunner *runner.SmokeTestRunner) func() error {
return func() (err error) {
// return an error on panic
// TODO: remove and instead return errors in the smoke tests
Expand All @@ -235,11 +215,14 @@ func erc20TestRoutine(erc20Runner *runner.SmokeTestRunner) func() error {
erc20Runner.Logger.Print("🏃 starting erc20 tests")
startTime := time.Now()

// funding the account
deployerRunner.SendZetaOnEvm(UserERC20Address, 1000)
deployerRunner.SendUSDTOnEvm(UserERC20Address, 10)

// depositing the necessary tokens on ZetaChain
erc20Runner.DepositZeta()
erc20Runner.DepositEther()
erc20Runner.DepositERC20()
//erc20Runner.SetupBitcoinAccount()
//erc20Runner.CheckZRC20ReserveAndSupply()

// run erc20 test
if err := erc20Runner.RunSmokeTestsFromNames(
Expand All @@ -248,7 +231,7 @@ func erc20TestRoutine(erc20Runner *runner.SmokeTestRunner) func() error {
//smoketests.TestMultipleERC20DepositName,
smoketests.TestWithdrawERC20Name,
//smoketests.TestMultipleWithdrawsName,
smoketests.TestERC20DepositAndCallRefundName,
//smoketests.TestERC20DepositAndCallRefundName,
); err != nil {
return fmt.Errorf("erc20 tests failed: %v", err)
}
Expand All @@ -260,7 +243,7 @@ func erc20TestRoutine(erc20Runner *runner.SmokeTestRunner) func() error {
}

// zetaTestRoutine runs Zeta transfer and message passing related smoke tests
func zetaTestRoutine(zetaRunner *runner.SmokeTestRunner) func() error {
func zetaTestRoutine(zetaRunner, deployerRunner *runner.SmokeTestRunner) func() error {
return func() (err error) {
// return an error on panic
// TODO: remove and instead return errors in the smoke tests
Expand All @@ -274,12 +257,14 @@ func zetaTestRoutine(zetaRunner *runner.SmokeTestRunner) func() error {
zetaRunner.Logger.Print("🏃 starting Zeta tests")
startTime := time.Now()

// funding the account
deployerRunner.SendZetaOnEvm(UserZetaTestAddress, 1000)

// depositing the necessary tokens on ZetaChain
zetaRunner.DepositZeta()
zetaRunner.DepositEther()
//zetaRunner.SetupBitcoinAccount()
//zetaRunner.CheckZRC20ReserveAndSupply()

// run erc20 test
// run zeta test
if err := zetaRunner.RunSmokeTestsFromNames(
smoketests.AllSmokeTests,
smoketests.TestSendZetaOutName,
Expand All @@ -297,7 +282,7 @@ func zetaTestRoutine(zetaRunner *runner.SmokeTestRunner) func() error {
}

// bitcoinTestRoutine runs Bitcoin related smoke tests
func bitcoinTestRoutine(bitcoinRunner *runner.SmokeTestRunner) func() error {
func bitcoinTestRoutine(bitcoinRunner, deployerRunner *runner.SmokeTestRunner) func() error {
return func() (err error) {
// return an error on panic
// TODO: remove and instead return errors in the smoke tests
Expand All @@ -311,19 +296,22 @@ func bitcoinTestRoutine(bitcoinRunner *runner.SmokeTestRunner) func() error {
bitcoinRunner.Logger.Print("🏃 starting Bitcoin tests")
startTime := time.Now()

// funding the account
deployerRunner.SendZetaOnEvm(UserBitcoinAddress, 1000)

// depositing the necessary tokens on ZetaChain
bitcoinRunner.DepositZeta()
bitcoinRunner.DepositEther()
bitcoinRunner.SetupBitcoinAccount()
bitcoinRunner.DepositBTC()
bitcoinRunner.SetupZEVMSwapApp()
//bitcoinRunner.CheckZRC20ReserveAndSupply()

// run bitcoin test
if err := bitcoinRunner.RunSmokeTestsFromNames(
smoketests.AllSmokeTests,
smoketests.TestBitcoinWithdrawName,
smoketests.TestSendZetaOutBTCRevertName,
smoketests.TestCrosschainSwapName,
//smoketests.TestCrosschainSwapName,
); err != nil {
return fmt.Errorf("bitcoin tests failed: %v", err)
}
Expand All @@ -335,7 +323,7 @@ func bitcoinTestRoutine(bitcoinRunner *runner.SmokeTestRunner) func() error {
}

// ethereumTestRoutine runs Ethereum related smoke tests
func ethereumTestRoutine(ethereumRunner *runner.SmokeTestRunner) func() error {
func ethereumTestRoutine(ethereumRunner, deployerRunner *runner.SmokeTestRunner) func() error {
return func() (err error) {
// return an error on panic
// TODO: remove and instead return errors in the smoke tests
Expand All @@ -349,11 +337,13 @@ func ethereumTestRoutine(ethereumRunner *runner.SmokeTestRunner) func() error {
ethereumRunner.Logger.Print("🏃 starting Ethereum tests")
startTime := time.Now()

// funding the account
deployerRunner.SendZetaOnEvm(UserEtherAddress, 1000)

// depositing the necessary tokens on ZetaChain
ethereumRunner.DepositZeta()
ethereumRunner.DepositEther()
//ethereumRunner.SetupBitcoinAccount()
ethereumRunner.SetupContextApp()
//ethereumRunner.CheckZRC20ReserveAndSupply()

// run ethereum test
if err := ethereumRunner.RunSmokeTestsFromNames(
Expand All @@ -372,7 +362,7 @@ func ethereumTestRoutine(ethereumRunner *runner.SmokeTestRunner) func() error {
}

// miscTestRoutine runs miscellaneous smoke tests
func miscTestRoutine(miscRunner *runner.SmokeTestRunner) func() error {
func miscTestRoutine(miscRunner, deployerRunner *runner.SmokeTestRunner) func() error {
return func() (err error) {
// return an error on panic
// TODO: remove and instead return errors in the smoke tests
Expand All @@ -386,6 +376,10 @@ func miscTestRoutine(miscRunner *runner.SmokeTestRunner) func() error {
miscRunner.Logger.Print("🏃 starting miscellaneous tests")
startTime := time.Now()

// funding the account
deployerRunner.SendZetaOnEvm(UserMiscAddress, 1000)

// depositing the necessary tokens on ZetaChain
miscRunner.DepositZeta()

// run misc test
Expand All @@ -404,7 +398,7 @@ func miscTestRoutine(miscRunner *runner.SmokeTestRunner) func() error {
}

// erc20AdvancedTestRoutine runs erc20 advanced related smoke tests
func erc20AdvancedTestRoutine(erc20AdvancedRunner *runner.SmokeTestRunner) func() error {
func erc20AdvancedTestRoutine(erc20AdvancedRunner, deployerRunner *runner.SmokeTestRunner) func() error {
return func() (err error) {
// return an error on panic
// https://github.com/zeta-chain/node/issues/1500
Expand All @@ -417,6 +411,11 @@ func erc20AdvancedTestRoutine(erc20AdvancedRunner *runner.SmokeTestRunner) func(
erc20AdvancedRunner.Logger.Print("🏃 starting erc20 advanced tests")
startTime := time.Now()

// funding the account
deployerRunner.SendZetaOnEvm(UserERC20AdvancedAddress, 1000)
deployerRunner.SendUSDTOnEvm(UserERC20AdvancedAddress, 1000)

// depositing the necessary tokens on ZetaChain
erc20AdvancedRunner.DepositZeta()
erc20AdvancedRunner.DepositEther()
erc20AdvancedRunner.DepositERC20()
Expand All @@ -426,8 +425,8 @@ func erc20AdvancedTestRoutine(erc20AdvancedRunner *runner.SmokeTestRunner) func(
smoketests.AllSmokeTests,
smoketests.TestZRC20SwapName,
//smoketests.TestPauseZRC20Name,
smoketests.TestUpdateBytecodeName,
smoketests.TestWhitelistERC20Name,
//smoketests.TestUpdateBytecodeName,
//smoketests.TestWhitelistERC20Name,
); err != nil {
return fmt.Errorf("erc20 advanced tests failed: %v", err)
}
Expand Down
6 changes: 6 additions & 0 deletions contrib/localnet/orchestrator/smoketest/cmd/smoketest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ package main
import (
"fmt"
"os"

"github.com/fatih/color"
)

func main() {
// enable color output
color.NoColor = false

// initialize root command
rootCmd := NewRootCmd()
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func waitKeygenHeight(
logger *runner.Logger,
) {
// wait for keygen to be completed. ~ height 30
keygenHeight := int64(60)
keygenHeight := int64(45)
logger.Print("⏳ wait height %v for keygen to be completed", keygenHeight)
for {
time.Sleep(5 * time.Second)
Expand Down
6 changes: 6 additions & 0 deletions contrib/localnet/orchestrator/smoketest/runner/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import (
// this allows the USDT contract deployer to funds other accounts on EVM
// amountUSDT is a multiple of 1e18
func (sm *SmokeTestRunner) SendUSDTOnEvm(address ethcommon.Address, amountUSDT int64) {
// the deployer might be sending USDT in different goroutines
defer func() {
sm.Unlock()
}()
sm.Lock()

amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(amountUSDT))

// mint
Expand Down
16 changes: 14 additions & 2 deletions contrib/localnet/orchestrator/smoketest/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ type SmokeTestRunner struct {
SystemContract *systemcontract.SystemContract

// other
WG sync.WaitGroup
Logger *Logger
WG sync.WaitGroup
mutex sync.Mutex
}

func NewSmokeTestRunner(
Expand Down Expand Up @@ -126,8 +127,9 @@ func NewSmokeTestRunner(
ZevmAuth: zevmAuth,
BtcRPCClient: btcRPCClient,

WG: sync.WaitGroup{},
Logger: logger,

WG: sync.WaitGroup{},
}
}

Expand Down Expand Up @@ -273,3 +275,13 @@ func (sm *SmokeTestRunner) CopyAddressesFrom(other *SmokeTestRunner) (err error)
}
return nil
}

// Lock locks the mutex
func (sm *SmokeTestRunner) Lock() {
sm.mutex.Lock()
}

// Unlock unlocks the mutex
func (sm *SmokeTestRunner) Unlock() {
sm.mutex.Unlock()
}
6 changes: 6 additions & 0 deletions contrib/localnet/orchestrator/smoketest/runner/zeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import (
// SendZetaOnEvm sends ZETA to an address on EVM
// this allows the ZETA contract deployer to funds other accounts on EVM
func (sm *SmokeTestRunner) SendZetaOnEvm(address ethcommon.Address, zetaAmount int64) {
// the deployer might be sending ZETA in different goroutines
defer func() {
sm.Unlock()
}()
sm.Lock()

amount := big.NewInt(1e18)
amount = amount.Mul(amount, big.NewInt(zetaAmount))
tx, err := sm.ZetaEth.Transfer(sm.GoerliAuth, address, amount)
Expand Down

0 comments on commit 86ee742

Please sign in to comment.