Skip to content

Commit

Permalink
add ethers and bitcoin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Dec 22, 2023
1 parent 9732c23 commit cd0ea48
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 15 deletions.
195 changes: 181 additions & 14 deletions contrib/localnet/orchestrator/smoketest/cmd/smoketest/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"os"
"time"

"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/config"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/config"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/runner"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/smoketests"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/utils"
Expand Down Expand Up @@ -49,13 +48,13 @@ var (
UserEtherAddress = ethcommon.HexToAddress("0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A")
UserEtherPrivateKey = "098e74a1c2261fa3c1b8cfca8ef2b4ff96c73ce36710d208d1f6535aef42545d" // #nosec G101 - used for testing

// UserMiscAddress is the address of the account for miscellanous tests
UserMiscAddress = ethcommon.HexToAddress("0x283d810090EdF4043E75247eAeBcE848806237fD")
UserMiscPrivateKey = "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a" // #nosec G101 - used for testing
// UserMiscAddress is the address of the account for miscellaneous tests
UserMiscAddress = ethcommon.HexToAddress("0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf")
UserMiscPrivateKey = "853c0945b8035a501b1161df65a17a0a20fc848bda8975a8b4e9222cc6f84cd4" // #nosec G101 - used for testing

// UserERC20AdvancedAddress is the address of the account for testing ERC20 advanced features
UserERC20AdvancedAddress = ethcommon.HexToAddress("0x283d810090EdF4043E75247eAeBcE848806237fD")
UserERC20AdvancedPrivateKey = "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a" // #nosec G101 - used for testing
UserERC20AdvancedAddress = ethcommon.HexToAddress("0xcC8487562AAc220ea4406196Ee902C7c076966af")
UserERC20AdvancedPrivateKey = "95409f1f0e974871cc26ba98ffd31f613aa1287d40c0aea6a87475fc3521d083" // #nosec G101 - used for testing

FungibleAdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing
)
Expand Down Expand Up @@ -154,6 +153,8 @@ func localSmokeTest(cmd *cobra.Command, _ []string) {
deployerRunner.SendZetaOnEvm(UserERC20Address, 1000)
deployerRunner.SendUSDTOnEvm(UserERC20Address, 10)
deployerRunner.SendZetaOnEvm(UserZetaTestAddress, 1000)
deployerRunner.SendZetaOnEvm(UserBitcoinAddress, 1000)
deployerRunner.SendZetaOnEvm(UserEtherAddress, 1000)

// error group for running multiple smoke tests concurrently
var eg errgroup.Group
Expand All @@ -170,9 +171,23 @@ func localSmokeTest(cmd *cobra.Command, _ []string) {
panic(err)
}

// initialize runner for bitcoin test
bitcoinRunner, err := initBitcoinRunner(conf, deployerRunner, verbose)
if err != nil {
panic(err)
}

// initialize runner for ether test
etherRunner, err := initEtherRunner(conf, deployerRunner, verbose)
if err != nil {
panic(err)
}

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

// deploy zevm swap and context apps
//logger.Print("⚙️ setting up ZEVM swap and context apps")
Expand All @@ -181,9 +196,10 @@ func localSmokeTest(cmd *cobra.Command, _ []string) {

if err := eg.Wait(); err != nil {
logger.Print("❌ %v", err)
} else {
logger.Print("✅ smoke tests completed in %s", time.Since(testStartTime).String())
os.Exit(1)
}

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

// erc20TestRoutine runs erc20 related smoke tests
Expand All @@ -200,10 +216,9 @@ func erc20TestRoutine(erc20Runner *runner.SmokeTestRunner) func() error {

erc20Runner.DepositZeta()
erc20Runner.DepositEther()
erc20Runner.SetupBitcoinAccount()
erc20Runner.DepositERC20()
erc20Runner.CheckZRC20ReserveAndSupply()
//erc20Runner.DepositBTC()
//erc20Runner.SetupBitcoinAccount()
//erc20Runner.CheckZRC20ReserveAndSupply()

// run erc20 test
if err := erc20Runner.RunSmokeTestsFromNames(
Expand Down Expand Up @@ -238,8 +253,8 @@ func zetaTestRoutine(zetaRunner *runner.SmokeTestRunner) func() error {

zetaRunner.DepositZeta()
zetaRunner.DepositEther()
zetaRunner.SetupBitcoinAccount()
zetaRunner.CheckZRC20ReserveAndSupply()
//zetaRunner.SetupBitcoinAccount()
//zetaRunner.CheckZRC20ReserveAndSupply()

// run erc20 test
if err := zetaRunner.RunSmokeTestsFromNames(
Expand All @@ -256,6 +271,70 @@ func zetaTestRoutine(zetaRunner *runner.SmokeTestRunner) func() error {
}
}

// bitcoinTestRoutine runs Bitcoin related smoke tests
func bitcoinTestRoutine(bitcoinRunner *runner.SmokeTestRunner) func() error {
return func() (err error) {
// return an error on panic
// TODO: remove and instead return errors in the smoke tests
// https://github.com/zeta-chain/node/issues/1500
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("bitcoin panic: %v", r)
}
}()

bitcoinRunner.DepositZeta()
bitcoinRunner.DepositEther()
bitcoinRunner.SetupBitcoinAccount()
bitcoinRunner.DepositBTC()
//bitcoinRunner.CheckZRC20ReserveAndSupply()

// run bitcoin test
if err := bitcoinRunner.RunSmokeTestsFromNames(
smoketests.AllSmokeTests,
smoketests.TestBitcoinWithdrawName,
smoketests.TestSendZetaOutBTCRevertName,
smoketests.TestCrosschainSwapName,
); err != nil {
return err
}

return err
}
}

// ethereumTestRoutine runs Ethereum related smoke tests
func ethereumTestRoutine(ethereumRunner *runner.SmokeTestRunner) func() error {
return func() (err error) {
// return an error on panic
// TODO: remove and instead return errors in the smoke tests
// https://github.com/zeta-chain/node/issues/1500
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ethereum panic: %v", r)
}
}()

ethereumRunner.DepositZeta()
ethereumRunner.DepositEther()
//ethereumRunner.SetupBitcoinAccount()
ethereumRunner.SetupContextApp()
//ethereumRunner.CheckZRC20ReserveAndSupply()

// run ethereum test
if err := ethereumRunner.RunSmokeTestsFromNames(
smoketests.AllSmokeTests,
smoketests.TestContextUpgradeName,
smoketests.TestEtherDepositAndCallName,
smoketests.TestDepositEtherLiquidityCapName,
); err != nil {
return err
}

return err
}
}

// initERC20Runner initializes a runner for erc20 tests
func initERC20Runner(
conf config.Config,
Expand Down Expand Up @@ -299,3 +378,91 @@ func initZetaRunner(
}
return zetaRunner, nil
}

// initBitcoinRunner initializes a runner for bitcoin tests
func initBitcoinRunner(
conf config.Config,
deployerRunner *runner.SmokeTestRunner,
verbose bool,
) (*runner.SmokeTestRunner, error) {
// initialize runner for bitcoin test
bitcoinRunner, err := runnerFromConfig(
conf,
UserBitcoinAddress,
UserBitcoinPrivateKey,
runner.NewLogger(verbose, color.FgYellow, "bitcoin"),
)
if err != nil {
return nil, err
}
if err := bitcoinRunner.CopyAddressesFrom(deployerRunner); err != nil {
return nil, err
}
return bitcoinRunner, nil
}

// initEtherRunner initializes a runner for ether tests
func initEtherRunner(
conf config.Config,
deployerRunner *runner.SmokeTestRunner,
verbose bool,
) (*runner.SmokeTestRunner, error) {
// initialize runner for ether test
etherRunner, err := runnerFromConfig(
conf,
UserEtherAddress,
UserEtherPrivateKey,
runner.NewLogger(verbose, color.FgMagenta, "ether"),
)
if err != nil {
return nil, err
}
if err := etherRunner.CopyAddressesFrom(deployerRunner); err != nil {
return nil, err
}
return etherRunner, nil
}

// initMiscRunner initializes a runner for miscellaneous tests
func initMiscRunner(

Check failure on line 427 in contrib/localnet/orchestrator/smoketest/cmd/smoketest/local.go

View workflow job for this annotation

GitHub Actions / lint

func `initMiscRunner` is unused (unused)
conf config.Config,
deployerRunner *runner.SmokeTestRunner,
verbose bool,
) (*runner.SmokeTestRunner, error) {
// initialize runner for misc test
miscRunner, err := runnerFromConfig(
conf,
UserMiscAddress,
UserMiscPrivateKey,
runner.NewLogger(verbose, color.FgCyan, "misc"),
)
if err != nil {
return nil, err
}
if err := miscRunner.CopyAddressesFrom(deployerRunner); err != nil {
return nil, err
}
return miscRunner, nil
}

// initERC20AdvancedRunner initializes a runner for erc20 advanced tests
func initERC20AdvancedRunner(

Check failure on line 449 in contrib/localnet/orchestrator/smoketest/cmd/smoketest/local.go

View workflow job for this annotation

GitHub Actions / lint

func `initERC20AdvancedRunner` is unused (unused)
conf config.Config,
deployerRunner *runner.SmokeTestRunner,
verbose bool,
) (*runner.SmokeTestRunner, error) {
// initialize runner for erc20 advanced test
erc20AdvancedRunner, err := runnerFromConfig(
conf,
UserERC20AdvancedAddress,
UserERC20AdvancedPrivateKey,
runner.NewLogger(verbose, color.FgHiGreen, "erc20advanced"),
)
if err != nil {
return nil, err
}
if err := erc20AdvancedRunner.CopyAddressesFrom(deployerRunner); err != nil {
return nil, err
}
return erc20AdvancedRunner, nil
}
2 changes: 1 addition & 1 deletion contrib/localnet/orchestrator/smoketest/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (sm *SmokeTestRunner) RunSmokeTest(smokeTestWithName SmokeTest) {
smokeTestWithName.SmokeTest(sm)

// check supplies
sm.CheckZRC20ReserveAndSupply()
//sm.CheckZRC20ReserveAndSupply()

sm.Logger.Print("✅ completed in %s - %s", time.Since(startTime), smokeTestWithName.Description)
}
Expand Down
17 changes: 17 additions & 0 deletions contrib/localnet/orchestrator/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x6F57D5E7c6DBb75e59F
echo "funding deployer address 0x5cC2fBb200A929B372e3016F1925DcF988E081fd with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x5cC2fBb200A929B372e3016F1925DcF988E081fd", value: web3.toWei(100,"ether")})' attach http://eth:8545

# unlock bitcoin tester accounts
echo "funding deployer address 0x283d810090EdF4043E75247eAeBcE848806237fD with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x283d810090EdF4043E75247eAeBcE848806237fD", value: web3.toWei(100,"ether")})' attach http://eth:8545

# unlock ethers tester accounts
echo "funding deployer address 0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A", value: web3.toWei(100,"ether")})' attach http://eth:8545

# unlock miscellaneous tests accounts
echo "funding deployer address 0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf", value: web3.toWei(100,"ether")})' attach http://eth:8545

# unlock advanced erc20 tests accounts
echo "funding deployer address 0xcC8487562AAc220ea4406196Ee902C7c076966af with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xcC8487562AAc220ea4406196Ee902C7c076966af", value: web3.toWei(100,"ether")})' attach http://eth:8545


# unlock the TSS account
echo "funding TSS address 0xF421292cb0d3c97b90EEEADfcD660B893592c6A2 with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xF421292cb0d3c97b90EEEADfcD660B893592c6A2", value: web3.toWei(100,"ether")})' attach http://eth:8545
Expand Down

0 comments on commit cd0ea48

Please sign in to comment.