Skip to content

Commit

Permalink
test(network): graceful cleanup for more consistent CI runs (#1960)
Browse files Browse the repository at this point in the history
* test(network): graceful cleanup for more consistent CI runs

* test: panicked as expected with max retry. Try longer timeouts

* linter

* test: try graceful json-rpc shutdown

* test(network): fix IsStopped condition check

* test(network): changelog, linter, grpc query hack

* refactor: cli -> testnetwork and doc comments
  • Loading branch information
Unique-Divine authored Jul 10, 2024
1 parent 76bdaaa commit d24f7a1
Show file tree
Hide file tree
Showing 21 changed files with 389 additions and 246 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1956](https://github.com/NibiruChain/nibiru/pull/1956) - feat(evm): msg to send bank coin to erc20
- [#1958](https://github.com/NibiruChain/nibiru/pull/1958) - chore(evm): wiped deprecated evm apis: miner, personal
- [#1959](https://github.com/NibiruChain/nibiru/pull/1959) - feat(evm): Add precompile to the EVM that enables trasnfers of ERC20 tokens to "nibi" accounts as regular Ethereum transactions
- [#1960](https://github.com/NibiruChain/nibiru/pull/1960) - test(network): graceful cleanup for more consistent CI runs

#### Dapp modules: perp, spot, oracle, etc

Expand Down
14 changes: 7 additions & 7 deletions app/wasmext/wasm_cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/NibiruChain/nibiru/app"
"github.com/NibiruChain/nibiru/x/common/denoms"
"github.com/NibiruChain/nibiru/x/common/testutil"
testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli"
"github.com/NibiruChain/nibiru/x/common/testutil/genesis"
"github.com/NibiruChain/nibiru/x/common/testutil/testapp"
"github.com/NibiruChain/nibiru/x/common/testutil/testnetwork"
)

// commonArgs is args for CLI test commands.
Expand All @@ -36,8 +36,8 @@ var _ suite.TearDownAllSuite = (*TestSuite)(nil)
type TestSuite struct {
suite.Suite

cfg testutilcli.Config
network *testutilcli.Network
cfg testnetwork.Config
network *testnetwork.Network
}

func (s *TestSuite) SetupSuite() {
Expand All @@ -46,8 +46,8 @@ func (s *TestSuite) SetupSuite() {

encodingConfig := app.MakeEncodingConfig()
genesisState := genesis.NewTestGenesisState(encodingConfig)
s.cfg = testutilcli.BuildNetworkConfig(genesisState)
network, err := testutilcli.New(s.T(), s.T().TempDir(), s.cfg)
s.cfg = testnetwork.BuildNetworkConfig(genesisState)
network, err := testnetwork.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)

s.network = network
Expand Down Expand Up @@ -96,7 +96,7 @@ func (s *TestSuite) deployWasmContract(path string) (uint64, error) {
return 0, err
}

resp, err = testutilcli.QueryTx(val.ClientCtx, resp.TxHash)
resp, err = testnetwork.QueryTx(val.ClientCtx, resp.TxHash)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *TestSuite) deployWasmContract(path string) (uint64, error) {
func (s *TestSuite) requiredDeployedContractsLen(total int) {
val := s.network.Validators[0]
var queryCodeResponse types.QueryCodesResponse
err := testutilcli.ExecQuery(
err := testnetwork.ExecQuery(
val.ClientCtx,
wasmcli.GetCmdListCode(),
[]string{},
Expand Down
20 changes: 10 additions & 10 deletions eth/rpc/rpcapi/eth_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ import (

"github.com/NibiruChain/nibiru/app"
"github.com/NibiruChain/nibiru/x/common/testutil"
testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli"
"github.com/NibiruChain/nibiru/x/common/testutil/genesis"
"github.com/NibiruChain/nibiru/x/common/testutil/testapp"
"github.com/NibiruChain/nibiru/x/common/testutil/testnetwork"
)

var _ suite.TearDownAllSuite = (*TestSuite)(nil)

type TestSuite struct {
suite.Suite
cfg testutilcli.Config
network *testutilcli.Network
cfg testnetwork.Config
network *testnetwork.Network

ethClient *ethclient.Client

Expand All @@ -57,8 +57,8 @@ func (s *TestSuite) SetupSuite() {

genState := genesis.NewTestGenesisState(app.MakeEncodingConfig())
homeDir := s.T().TempDir()
s.cfg = testutilcli.BuildNetworkConfig(genState)
network, err := testutilcli.New(s.T(), homeDir, s.cfg)
s.cfg = testnetwork.BuildNetworkConfig(genState)
network, err := testnetwork.New(s.T(), homeDir, s.cfg)
s.Require().NoError(err)

s.network = network
Expand All @@ -75,7 +75,7 @@ func (s *TestSuite) SetupSuite() {
val := s.network.Validators[0]

funds := sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 100_000_000)) // 10 NIBI
s.NoError(testutilcli.FillWalletFromValidator(s.fundedAccNibiAddr, funds, val, denoms.NIBI))
s.NoError(testnetwork.FillWalletFromValidator(s.fundedAccNibiAddr, funds, val, denoms.NIBI))
s.NoError(s.network.WaitForNextBlock())
}

Expand Down Expand Up @@ -110,7 +110,7 @@ func (s *TestSuite) Test_BlockByNumber() {

// Test_BalanceAt EVM method: eth_getBalance
func (s *TestSuite) Test_BalanceAt() {
testAccEthAddr := gethcommon.BytesToAddress(testutilcli.NewAccount(s.network, "new-user"))
testAccEthAddr := gethcommon.BytesToAddress(testnetwork.NewAccount(s.network, "new-user"))

// New user balance should be 0
balance, err := s.ethClient.BalanceAt(context.Background(), testAccEthAddr, nil)
Expand Down Expand Up @@ -166,7 +166,7 @@ func (s *TestSuite) Test_PendingCodeAt() {

// Test_EstimateGas EVM method: eth_estimateGas
func (s *TestSuite) Test_EstimateGas() {
testAccEthAddr := gethcommon.BytesToAddress(testutilcli.NewAccount(s.network, "new-user"))
testAccEthAddr := gethcommon.BytesToAddress(testnetwork.NewAccount(s.network, "new-user"))
gasLimit := uint64(21000)
msg := geth.CallMsg{
From: s.fundedAccEthAddr,
Expand Down Expand Up @@ -197,7 +197,7 @@ func (s *TestSuite) Test_SimpleTransferTransaction() {
context.Background(), s.fundedAccEthAddr, nil,
)
s.NoError(err)
recipientAddr := gethcommon.BytesToAddress(testutilcli.NewAccount(s.network, "recipient"))
recipientAddr := gethcommon.BytesToAddress(testnetwork.NewAccount(s.network, "recipient"))
recipientBalanceBefore, err := s.ethClient.BalanceAt(context.Background(), recipientAddr, nil)
s.NoError(err)
s.Equal(int64(0), recipientBalanceBefore.Int64())
Expand Down Expand Up @@ -266,7 +266,7 @@ func (s *TestSuite) Test_SmartContract() {
s.assertERC20Balance(contractAddress, s.fundedAccEthAddr, ownerInitialBalance)

// Querying contract: recipient balance should be 0
recipientAddr := gethcommon.BytesToAddress(testutilcli.NewAccount(s.network, "contract_recipient"))
recipientAddr := gethcommon.BytesToAddress(testnetwork.NewAccount(s.network, "contract_recipient"))
s.assertERC20Balance(contractAddress, recipientAddr, big.NewInt(0))

// Execute contract: send 1000 anibi to recipient
Expand Down
22 changes: 11 additions & 11 deletions gosdk/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ import (
"google.golang.org/grpc"

"github.com/NibiruChain/nibiru/app"
"github.com/NibiruChain/nibiru/x/common/testutil/cli"
"github.com/NibiruChain/nibiru/x/common/testutil/genesis"
"github.com/NibiruChain/nibiru/x/common/testutil/testnetwork"

tmconfig "github.com/cometbft/cometbft/config"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
)

type Blockchain struct {
GrpcConn *grpc.ClientConn
Cfg *cli.Config
Network *cli.Network
Val *cli.Validator
Cfg *testnetwork.Config
Network *testnetwork.Network
Val *testnetwork.Validator
}

func CreateBlockchain(t *testing.T) (nibiru Blockchain, err error) {
EnsureNibiruPrefix()
encConfig := app.MakeEncodingConfig()
genState := genesis.NewTestGenesisState(encConfig)
cliCfg := cli.BuildNetworkConfig(genState)
cliCfg := testnetwork.BuildNetworkConfig(genState)
cfg := &cliCfg
cfg.NumValidators = 1

network, err := cli.New(
network, err := testnetwork.New(
t,
t.TempDir(),
*cfg,
Expand Down Expand Up @@ -57,24 +57,24 @@ func CreateBlockchain(t *testing.T) (nibiru Blockchain, err error) {
}, err
}

func ConnectGrpcToVal(val *cli.Validator) (*grpc.ClientConn, error) {
func ConnectGrpcToVal(val *testnetwork.Validator) (*grpc.ClientConn, error) {
grpcUrl := val.AppConfig.GRPC.Address
return GetGRPCConnection(
grpcUrl, true, 5,
)
}

func AbsorbServerConfig(
cfg *cli.Config, srvCfg *serverconfig.Config,
) *cli.Config {
cfg *testnetwork.Config, srvCfg *serverconfig.Config,
) *testnetwork.Config {
cfg.GRPCAddress = srvCfg.GRPC.Address
cfg.APIAddress = srvCfg.API.Address
return cfg
}

func AbsorbTmConfig(
cfg *cli.Config, tmCfg *tmconfig.Config,
) *cli.Config {
cfg *testnetwork.Config, tmCfg *tmconfig.Config,
) *testnetwork.Config {
cfg.RPCAddress = tmCfg.RPC.ListenAddress
return cfg
}
Expand Down
10 changes: 5 additions & 5 deletions gosdk/gosdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/NibiruChain/nibiru/gosdk"
"github.com/NibiruChain/nibiru/x/common/denoms"
"github.com/NibiruChain/nibiru/x/common/testutil"
"github.com/NibiruChain/nibiru/x/common/testutil/cli"
"github.com/NibiruChain/nibiru/x/common/testutil/testnetwork"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -31,9 +31,9 @@ type TestSuite struct {

nibiruSdk *gosdk.NibiruSDK
grpcConn *grpc.ClientConn
cfg *cli.Config
network *cli.Network
val *cli.Validator
cfg *testnetwork.Config
network *testnetwork.Network
val *testnetwork.Validator
}

func TestSuite_RunAll(t *testing.T) {
Expand All @@ -59,7 +59,7 @@ func (s *TestSuite) SetupSuite() {
s.grpcConn = nibiru.GrpcConn
}

func ConnectGrpcToVal(val *cli.Validator) (*grpc.ClientConn, error) {
func ConnectGrpcToVal(val *testnetwork.Validator) (*grpc.ClientConn, error) {
grpcUrl := val.AppConfig.GRPC.Address
return gosdk.GetGRPCConnection(
grpcUrl, true, 5,
Expand Down
2 changes: 1 addition & 1 deletion gosdk/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *TestSuite) DoTestSequenceExpectations() {
s.EqualValues(seq, newSeq)

t.Log("broadcast msg n times, expect sequence += n")
numTxs := uint64(5)
numTxs := uint64(2)
seqs := []uint64{}
txResults := make(map[string]*cmtcoretypes.ResultTx)
for broadcastCount := uint64(0); broadcastCount < numTxs; broadcastCount++ {
Expand Down
14 changes: 0 additions & 14 deletions x/common/testutil/cli/logger.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package network implements and exposes a fully operational in-process Tendermint
Package "testnetwork" implements and exposes a fully operational in-process Tendermint
test network that consists of at least one or potentially many validators. This
test network can be used primarily for integration tests or unit test suites.
Expand Down Expand Up @@ -62,4 +62,4 @@ A typical testing flow might look like the following:
suite.Run(t, new(IntegrationTestSuite))
}
*/
package cli
package testnetwork
18 changes: 18 additions & 0 deletions x/common/testutil/testnetwork/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package testnetwork

import (
"testing"
)

// Logger is a network logger interface that exposes testnet-level Log() methods
// for an in-process testing network This is not to be confused with logging that
// may happen at an individual node or validator level
//
// Typically, a `testing.T` struct is used as the logger for both the "Network"
// and corresponding "Validators".
type Logger interface {
Log(args ...interface{})
Logf(format string, args ...interface{})
}

var _ Logger = (*testing.T)(nil)
Loading

0 comments on commit d24f7a1

Please sign in to comment.