diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a1ae768b..b8816b5a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#1859](https://github.com/NibiruChain/nibiru/pull/1859) - refactor(oracle): add oracle slashing events - [#1893](https://github.com/NibiruChain/nibiru/pull/1893) - feat(gosdk): migrate Go-sdk into the Nibiru blockchain repo. - [#1899](https://github.com/NibiruChain/nibiru/pull/1899) - build(deps): cometbft v0.37.5, cosmos-sdk v0.47.11, proto-builder v0.14.0 +- [#1913](https://github.com/NibiruChain/nibiru/pull/1913) - fix(tests): race condition from heavy Network tests ### Dependencies diff --git a/app/wasmext/wasm_cli_test/cli_test.go b/app/wasmext/wasm_cli_test/cli_test.go index 825c99715..72069d17d 100644 --- a/app/wasmext/wasm_cli_test/cli_test.go +++ b/app/wasmext/wasm_cli_test/cli_test.go @@ -31,14 +31,16 @@ var commonArgs = []string{ sdk.NewCoins(sdk.NewCoin(denoms.NIBI, math.NewInt(10_000_000))).String()), } -type IntegrationTestSuite struct { +var _ suite.TearDownAllSuite = (*TestSuite)(nil) + +type TestSuite struct { suite.Suite cfg testutilcli.Config network *testutilcli.Network } -func (s *IntegrationTestSuite) SetupSuite() { +func (s *TestSuite) SetupSuite() { testutil.BeforeIntegrationSuite(s.T()) testapp.EnsureNibiruPrefix() @@ -52,12 +54,12 @@ func (s *IntegrationTestSuite) SetupSuite() { s.Require().NoError(s.network.WaitForNextBlock()) } -func (s *IntegrationTestSuite) TearDownSuite() { +func (s *TestSuite) TearDownSuite() { s.T().Log("tearing down integration test suite") s.network.Cleanup() } -func (s *IntegrationTestSuite) TestWasmHappyPath() { +func (s *TestSuite) TestWasmHappyPath() { s.requiredDeployedContractsLen(0) _, err := s.deployWasmContract("testdata/cw_nameservice.wasm") @@ -70,7 +72,7 @@ func (s *IntegrationTestSuite) TestWasmHappyPath() { } // deployWasmContract deploys a wasm contract located in path. -func (s *IntegrationTestSuite) deployWasmContract(path string) (uint64, error) { +func (s *TestSuite) deployWasmContract(path string) (uint64, error) { val := s.network.Validators[0] codec := val.ClientCtx.Codec @@ -124,7 +126,7 @@ func (s *IntegrationTestSuite) deployWasmContract(path string) (uint64, error) { } // requiredDeployedContractsLen checks the number of deployed contracts. -func (s *IntegrationTestSuite) requiredDeployedContractsLen(total int) { +func (s *TestSuite) requiredDeployedContractsLen(total int) { val := s.network.Validators[0] var queryCodeResponse types.QueryCodesResponse err := testutilcli.ExecQuery( @@ -138,5 +140,5 @@ func (s *IntegrationTestSuite) requiredDeployedContractsLen(total int) { } func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, new(IntegrationTestSuite)) + suite.Run(t, new(TestSuite)) } diff --git a/eth/rpc/rpcapi/eth_api_test.go b/eth/rpc/rpcapi/eth_api_test.go index a34aae621..8b9527038 100644 --- a/eth/rpc/rpcapi/eth_api_test.go +++ b/eth/rpc/rpcapi/eth_api_test.go @@ -29,7 +29,9 @@ import ( "github.com/NibiruChain/nibiru/x/common/testutil/testapp" ) -type IntegrationSuite struct { +var _ suite.TearDownAllSuite = (*TestSuite)(nil) + +type TestSuite struct { suite.Suite cfg testutilcli.Config network *testutilcli.Network @@ -43,12 +45,12 @@ type IntegrationSuite struct { contractData evmtest.CompiledEvmContract } -func TestSuite_IntegrationSuite_RunAll(t *testing.T) { - suite.Run(t, new(IntegrationSuite)) +func TestSuite_RunAll(t *testing.T) { + suite.Run(t, new(TestSuite)) } // SetupSuite initialize network -func (s *IntegrationSuite) SetupSuite() { +func (s *TestSuite) SetupSuite() { testutil.BeforeIntegrationSuite(s.T()) testapp.EnsureNibiruPrefix() @@ -76,14 +78,14 @@ func (s *IntegrationSuite) SetupSuite() { } // Test_ChainID EVM method: eth_chainId -func (s *IntegrationSuite) Test_ChainID() { +func (s *TestSuite) Test_ChainID() { ethChainID, err := s.ethClient.ChainID(context.Background()) s.NoError(err) s.Equal(appconst.ETH_CHAIN_ID_DEFAULT, ethChainID.Int64()) } // Test_BlockNumber EVM method: eth_blockNumber -func (s *IntegrationSuite) Test_BlockNumber() { +func (s *TestSuite) Test_BlockNumber() { networkBlockNumber, err := s.network.LatestHeight() s.NoError(err) @@ -93,7 +95,7 @@ func (s *IntegrationSuite) Test_BlockNumber() { } // Test_BlockByNumber EVM method: eth_getBlockByNumber -func (s *IntegrationSuite) Test_BlockByNumber() { +func (s *TestSuite) Test_BlockByNumber() { networkBlockNumber, err := s.network.LatestHeight() s.NoError(err) @@ -105,7 +107,7 @@ func (s *IntegrationSuite) Test_BlockByNumber() { } // Test_BalanceAt EVM method: eth_getBalance -func (s *IntegrationSuite) Test_BalanceAt() { +func (s *TestSuite) Test_BalanceAt() { testAccEthAddr := gethcommon.BytesToAddress(testutilcli.NewAccount(s.network, "new-user")) // New user balance should be 0 @@ -122,7 +124,7 @@ func (s *IntegrationSuite) Test_BalanceAt() { } // Test_StorageAt EVM method: eth_getStorageAt -func (s *IntegrationSuite) Test_StorageAt() { +func (s *TestSuite) Test_StorageAt() { storage, err := s.ethClient.StorageAt( context.Background(), s.fundedAccEthAddr, gethcommon.Hash{}, nil, ) @@ -132,7 +134,7 @@ func (s *IntegrationSuite) Test_StorageAt() { } // Test_PendingStorageAt EVM method: eth_getStorageAt | pending -func (s *IntegrationSuite) Test_PendingStorageAt() { +func (s *TestSuite) Test_PendingStorageAt() { storage, err := s.ethClient.PendingStorageAt( context.Background(), s.fundedAccEthAddr, gethcommon.Hash{}, ) @@ -143,7 +145,7 @@ func (s *IntegrationSuite) Test_PendingStorageAt() { } // Test_CodeAt EVM method: eth_getCode -func (s *IntegrationSuite) Test_CodeAt() { +func (s *TestSuite) Test_CodeAt() { code, err := s.ethClient.CodeAt(context.Background(), s.fundedAccEthAddr, nil) s.NoError(err) @@ -152,7 +154,7 @@ func (s *IntegrationSuite) Test_CodeAt() { } // Test_PendingCodeAt EVM method: eth_getCode -func (s *IntegrationSuite) Test_PendingCodeAt() { +func (s *TestSuite) Test_PendingCodeAt() { code, err := s.ethClient.PendingCodeAt(context.Background(), s.fundedAccEthAddr) s.NoError(err) @@ -161,7 +163,7 @@ func (s *IntegrationSuite) Test_PendingCodeAt() { } // Test_EstimateGas EVM method: eth_estimateGas -func (s *IntegrationSuite) Test_EstimateGas() { +func (s *TestSuite) Test_EstimateGas() { testAccEthAddr := gethcommon.BytesToAddress(testutilcli.NewAccount(s.network, "new-user")) gasLimit := uint64(21000) msg := geth.CallMsg{ @@ -176,14 +178,14 @@ func (s *IntegrationSuite) Test_EstimateGas() { } // Test_SuggestGasPrice EVM method: eth_gasPrice -func (s *IntegrationSuite) Test_SuggestGasPrice() { +func (s *TestSuite) Test_SuggestGasPrice() { // TODO: the backend method is stubbed to 0 _, err := s.ethClient.SuggestGasPrice(context.Background()) s.NoError(err) } // Test_SimpleTransferTransaction EVM method: eth_sendRawTransaction -func (s *IntegrationSuite) Test_SimpleTransferTransaction() { +func (s *TestSuite) Test_SimpleTransferTransaction() { chainID, err := s.ethClient.ChainID(context.Background()) s.NoError(err) nonce, err := s.ethClient.PendingNonceAt(context.Background(), s.fundedAccEthAddr) @@ -230,7 +232,7 @@ func (s *IntegrationSuite) Test_SimpleTransferTransaction() { } // Test_SmartContract includes contract deployment, query, execution -func (s *IntegrationSuite) Test_SmartContract() { +func (s *TestSuite) Test_SmartContract() { chainID, err := s.ethClient.ChainID(context.Background()) s.NoError(err) nonce, err := s.ethClient.NonceAt(context.Background(), s.fundedAccEthAddr, nil) @@ -295,12 +297,12 @@ func (s *IntegrationSuite) Test_SmartContract() { s.assertERC20Balance(contractAddress, recipientAddr, recipientBalance) } -func (s *IntegrationSuite) TearDownSuite() { +func (s *TestSuite) TearDownSuite() { s.T().Log("tearing down integration test suite") s.network.Cleanup() } -func (s *IntegrationSuite) assertERC20Balance( +func (s *TestSuite) assertERC20Balance( contractAddress gethcommon.Address, userAddress gethcommon.Address, expectedBalance *big.Int, diff --git a/gosdk/gosdk_test.go b/gosdk/gosdk_test.go index 68bd6072d..ed4e607e4 100644 --- a/gosdk/gosdk_test.go +++ b/gosdk/gosdk_test.go @@ -22,6 +22,7 @@ import ( // -------------------------------------------------- var _ suite.SetupAllSuite = (*TestSuite)(nil) +var _ suite.TearDownAllSuite = (*TestSuite)(nil) type TestSuite struct { suite.Suite @@ -33,7 +34,7 @@ type TestSuite struct { val *cli.Validator } -func TestNibiruClientTestSuite_RunAll(t *testing.T) { +func TestSuite_RunAll(t *testing.T) { suite.Run(t, new(TestSuite)) } @@ -46,6 +47,8 @@ func (s *TestSuite) RPCEndpoint() string { func (s *TestSuite) SetupSuite() { testutil.BeforeIntegrationSuite(s.T()) + s.Run("DoTestGetGrpcConnection_NoNetwork", s.DoTestGetGrpcConnection_NoNetwork) + nibiru, err := gosdk.CreateBlockchain(s.T()) s.NoError(err) s.network = nibiru.Network @@ -141,21 +144,9 @@ func (s *TestSuite) TearDownSuite() { s.network.Cleanup() } -// -------------------------------------------------- -// NibiruClientSuite_NoNetwork -// -------------------------------------------------- - -type NibiruClientSuite_NoNetwork struct { - suite.Suite -} - -func TestNibiruClientSuite_NoNetwork_RunAll(t *testing.T) { - suite.Run(t, new(NibiruClientSuite_NoNetwork)) -} - -func (s *NibiruClientSuite_NoNetwork) TestGetGrpcConnection_NoNetwork() { +func (s *TestSuite) DoTestGetGrpcConnection_NoNetwork() { grpcConn, err := gosdk.GetGRPCConnection( - gosdk.DefaultNetworkInfo.GrpcEndpoint, true, 2, + gosdk.DefaultNetworkInfo.GrpcEndpoint+"notendpoint", true, 2, ) s.Error(err) s.Nil(grpcConn) diff --git a/justfile b/justfile index af0ff7d44..fbdcef302 100644 --- a/justfile +++ b/justfile @@ -16,6 +16,10 @@ install-clean: build: make build +# Cleans the Go cache, modcache, and testcashe +clean-cache: + go clean -cache -testcache -modcache + alias b := build # Generate protobuf code (Golang) for Nibiru @@ -82,3 +86,15 @@ test-release: release-publish: make release + +# Run Go tests (short mode) +test-unit: + go test ./... -short + +# Run Go tests (short mode) + coverage +test-coverage-unit: + make test-coverage-unit + +# Run Go tests, including live network tests + coverage +test-coverage-integration: + make test-coverage-integration diff --git a/x/common/testutil/cli/network.go b/x/common/testutil/cli/network.go index d43e264eb..8dbe769a5 100644 --- a/x/common/testutil/cli/network.go +++ b/x/common/testutil/cli/network.go @@ -224,7 +224,7 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { buf := bufio.NewReader(os.Stdin) // generate private keys, node IDs, and initial transactions - for i := 0; i < cfg.NumValidators; i++ { + for valIdx := 0; valIdx < cfg.NumValidators; valIdx++ { appCfg := serverconfig.DefaultConfig() appCfg.Pruning = cfg.PruningStrategy appCfg.MinGasPrices = cfg.MinGasPrices @@ -243,7 +243,7 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { appCfg.GRPC.Enable = false appCfg.GRPCWeb.Enable = false apiListenAddr := "" - if i == 0 { + if valIdx == 0 { if cfg.APIAddress != "" { apiListenAddr = cfg.APIAddress } else { @@ -309,7 +309,7 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { ctx.Logger = loggerNoOp - nodeDirName := fmt.Sprintf("node%d", i) + nodeDirName := fmt.Sprintf("node%d", valIdx) nodeDir := filepath.Join(network.BaseDir, nodeDirName, "simd") clientDir := filepath.Join(network.BaseDir, nodeDirName, "simcli") gentxsDir := filepath.Join(network.BaseDir, "gentxs") @@ -326,7 +326,7 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { tmCfg.SetRoot(nodeDir) tmCfg.Moniker = nodeDirName - monikers[i] = nodeDirName + monikers[valIdx] = nodeDirName proxyAddr, _, err := server.FreeTCPAddr() if err != nil { @@ -348,8 +348,8 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { return nil, err } - nodeIDs[i] = nodeID - valPubKeys[i] = pubKey + nodeIDs[valIdx] = nodeID + valPubKeys[valIdx] = pubKey kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, clientDir, buf, cfg.Codec, cfg.KeyringOptions...) if err != nil { @@ -363,8 +363,8 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { } var mnemonic string - if i < len(cfg.Mnemonics) { - mnemonic = cfg.Mnemonics[i] + if valIdx < len(cfg.Mnemonics) { + mnemonic = cfg.Mnemonics[valIdx] } addr, secret, err := sdktestutil.GenerateSaveCoinKey(kb, nodeDirName, mnemonic, true, algo) @@ -404,7 +404,7 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { createValMsg, err := stakingtypes.NewMsgCreateValidator( sdk.ValAddress(addr), - valPubKeys[i], + valPubKeys[valIdx], sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens), stakingtypes.NewDescription(nodeDirName, "", "", "", ""), stakingtypes.NewCommissionRates(commission, math.LegacyOneDec(), math.LegacyOneDec()), @@ -419,7 +419,7 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { return nil, err } - memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port()) + memo := fmt.Sprintf("%s@%s:%s", nodeIDs[valIdx], p2pURL.Hostname(), p2pURL.Port()) fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), math.ZeroInt())) txBuilder := cfg.TxConfig.NewTxBuilder() err = txBuilder.SetMsgs(createValMsg) @@ -464,7 +464,7 @@ func New(logger Logger, baseDir string, cfg Config) (*Network, error) { WithTxConfig(cfg.TxConfig). WithAccountRetriever(cfg.AccountRetriever) - network.Validators[i] = &Validator{ + network.Validators[valIdx] = &Validator{ AppConfig: appCfg, ClientCtx: clientCtx, Ctx: ctx, diff --git a/x/common/testutil/cli/network_test.go b/x/common/testutil/cli/network_test.go index 6bafe6370..f2a17bee4 100644 --- a/x/common/testutil/cli/network_test.go +++ b/x/common/testutil/cli/network_test.go @@ -16,31 +16,27 @@ import ( "github.com/stretchr/testify/suite" + "github.com/NibiruChain/nibiru/x/common/testutil" "github.com/NibiruChain/nibiru/x/common/testutil/cli" "github.com/NibiruChain/nibiru/x/common/testutil/genesis" ) func TestIntegrationTestSuite_RunAll(t *testing.T) { - suite.Run(t, new(IntegrationTestSuite)) + suite.Run(t, new(TestSuite)) } -type IntegrationTestSuite struct { +// Assert network cleanup +var _ suite.TearDownAllSuite = (*TestSuite)(nil) + +type TestSuite struct { suite.Suite network *cli.Network cfg *cli.Config } -func (s *IntegrationTestSuite) SetupSuite() { - /* Make test skip if -short is not used: - All tests: `go test ./...` - Unit tests only: `go test ./... -short` - Integration tests only: `go test ./... -run Integration` - https://stackoverflow.com/a/41407042/13305627 */ - if testing.Short() { - s.T().Skip("skipping integration test suite") - } - s.T().Log("setting up integration test suite") +func (s *TestSuite) SetupSuite() { + testutil.BeforeIntegrationSuite(s.T()) encConfig := app.MakeEncodingConfig() cfg := new(cli.Config) @@ -60,12 +56,12 @@ func (s *IntegrationTestSuite) SetupSuite() { s.Require().NoError(err) } -func (s *IntegrationTestSuite) TearDownSuite() { +func (s *TestSuite) TearDownSuite() { s.T().Log("tearing down integration test suite") s.network.Cleanup() } -func (s *IntegrationTestSuite) TestNetwork_Liveness() { +func (s *TestSuite) TestNetwork_Liveness() { height, err := s.network.WaitForHeightWithTimeout(4, time.Minute) s.Require().NoError(err, "expected to reach 4 blocks; got %d", height) @@ -73,7 +69,7 @@ func (s *IntegrationTestSuite) TestNetwork_Liveness() { s.NoError(err) } -func (s *IntegrationTestSuite) TestNetwork_LatestHeight() { +func (s *TestSuite) TestNetwork_LatestHeight() { height, err := s.network.LatestHeight() s.NoError(err) s.Positive(height) @@ -83,7 +79,7 @@ func (s *IntegrationTestSuite) TestNetwork_LatestHeight() { s.Error(err) } -func (s *IntegrationTestSuite) TestLogMnemonic() { +func (s *TestSuite) TestLogMnemonic() { kring, algo, nodeDirName := cli.NewKeyring(s.T()) var cdc sdkcodec.Codec = codec.MakeEncodingConfig().Codec @@ -101,7 +97,7 @@ func (s *IntegrationTestSuite) TestLogMnemonic() { }, secret) } -func (s *IntegrationTestSuite) TestValidatorGetSecret() { +func (s *TestSuite) TestValidatorGetSecret() { val := s.network.Validators[0] secret := val.SecretMnemonic() secretSlice := val.SecretMnemonicSlice() @@ -132,7 +128,7 @@ func (ml *mockLogger) Logf(format string, args ...interface{}) { ml.Logs = append(ml.Logs, fmt.Sprintf(format, args...)) } -func (s *IntegrationTestSuite) TestNewAccount() { +func (s *TestSuite) TestNewAccount() { s.NotPanics(func() { addr := cli.NewAccount(s.network, "newacc") s.NoError(sdk.VerifyAddressFormat(addr)) diff --git a/x/common/testutil/cli/tx_test.go b/x/common/testutil/cli/tx_test.go index e226c8fab..f14262b23 100644 --- a/x/common/testutil/cli/tx_test.go +++ b/x/common/testutil/cli/tx_test.go @@ -14,7 +14,7 @@ import ( "github.com/NibiruChain/nibiru/x/common/testutil/cli" ) -func (s *IntegrationTestSuite) TestSendTx() { +func (s *TestSuite) TestSendTx() { fromAddr := s.network.Validators[0].Address toAddr := testutil.AccAddress() sendCoin := sdk.NewCoin(denoms.NIBI, math.NewInt(42)) @@ -28,7 +28,7 @@ func (s *IntegrationTestSuite) TestSendTx() { s.EqualValues(0, txResp.Code) } -func (s *IntegrationTestSuite) TestExecTx() { +func (s *TestSuite) TestExecTx() { fromAddr := s.network.Validators[0].Address toAddr := testutil.AccAddress() sendCoin := sdk.NewCoin(denoms.NIBI, math.NewInt(69)) @@ -62,7 +62,7 @@ func (s *IntegrationTestSuite) TestExecTx() { }) } -func (s *IntegrationTestSuite) TestFillWalletFromValidator() { +func (s *TestSuite) TestFillWalletFromValidator() { toAddr := testutil.AccAddress() val := s.network.Validators[0] funds := sdk.NewCoins( diff --git a/x/oracle/integration/app_test.go b/x/oracle/integration/app_test.go index d8e46a3be..45f6a70c0 100644 --- a/x/oracle/integration/app_test.go +++ b/x/oracle/integration/app_test.go @@ -20,18 +20,20 @@ import ( "github.com/NibiruChain/nibiru/x/oracle/types" ) -type IntegrationTestSuite struct { +var _ suite.TearDownAllSuite = (*TestSuite)(nil) + +type TestSuite struct { suite.Suite cfg testutilcli.Config network *testutilcli.Network } -func (s *IntegrationTestSuite) SetupSuite() { +func (s *TestSuite) SetupSuite() { testutil.BeforeIntegrationSuite(s.T()) } -func (s *IntegrationTestSuite) SetupTest() { +func (s *TestSuite) SetupTest() { testapp.EnsureNibiruPrefix() homeDir := s.T().TempDir() @@ -60,7 +62,7 @@ func (s *IntegrationTestSuite) SetupTest() { require.NoError(s.T(), err) } -func (s *IntegrationTestSuite) TestSuccessfulVoting() { +func (s *TestSuite) TestSuccessfulVoting() { // assuming validators have equal power // we use the weighted median. // what happens is that prices are ordered @@ -105,7 +107,7 @@ func (s *IntegrationTestSuite) TestSuccessfulVoting() { ) } -func (s *IntegrationTestSuite) sendPrevotes(prices []map[asset.Pair]sdk.Dec) []string { +func (s *TestSuite) sendPrevotes(prices []map[asset.Pair]sdk.Dec) []string { strVotes := make([]string, len(prices)) for i, val := range s.network.Validators { raw := prices[i] @@ -129,7 +131,7 @@ func (s *IntegrationTestSuite) sendPrevotes(prices []map[asset.Pair]sdk.Dec) []s return strVotes } -func (s *IntegrationTestSuite) sendVotes(rates []string) { +func (s *TestSuite) sendVotes(rates []string) { for i, val := range s.network.Validators { _, err := s.network.BroadcastMsgs(val.Address, &types.MsgAggregateExchangeRateVote{ Salt: "1", @@ -141,7 +143,7 @@ func (s *IntegrationTestSuite) sendVotes(rates []string) { } } -func (s *IntegrationTestSuite) waitVoteRevealBlock() { +func (s *TestSuite) waitVoteRevealBlock() { params, err := types.NewQueryClient(s.network.Validators[0].ClientCtx).Params(context.Background(), &types.QueryParamsRequest{}) require.NoError(s.T(), err) @@ -157,11 +159,11 @@ func (s *IntegrationTestSuite) waitVoteRevealBlock() { } // it's an alias, but it exists to give better understanding of what we're doing in test cases scenarios -func (s *IntegrationTestSuite) waitPriceUpdateBlock() { +func (s *TestSuite) waitPriceUpdateBlock() { s.waitVoteRevealBlock() } -func (s *IntegrationTestSuite) currentPrices() map[asset.Pair]sdk.Dec { +func (s *TestSuite) currentPrices() map[asset.Pair]sdk.Dec { rawRates, err := types.NewQueryClient(s.network.Validators[0].ClientCtx).ExchangeRates(context.Background(), &types.QueryExchangeRatesRequest{}) require.NoError(s.T(), err) @@ -175,5 +177,10 @@ func (s *IntegrationTestSuite) currentPrices() map[asset.Pair]sdk.Dec { } func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, new(IntegrationTestSuite)) + suite.Run(t, new(TestSuite)) +} + +func (s *TestSuite) TearDownSuite() { + s.T().Log("tearing down integration test suite") + s.network.Cleanup() } diff --git a/x/sudo/cli/cli_test.go b/x/sudo/cli/cli_test.go index dc27bd6e2..bc7df60f6 100644 --- a/x/sudo/cli/cli_test.go +++ b/x/sudo/cli/cli_test.go @@ -80,7 +80,9 @@ func (MsgEditSudoersPlus) Exec( return network.ExecTxCmd(cli.CmdEditSudoers(), from, args) } -type IntegrationSuite struct { +var _ suite.TearDownAllSuite = (*TestSuite)(nil) + +type TestSuite struct { suite.Suite cfg testutilcli.Config network *testutilcli.Network @@ -94,14 +96,14 @@ type Account struct { } func TestSuite_IntegrationSuite_RunAll(t *testing.T) { - suite.Run(t, new(IntegrationSuite)) + suite.Run(t, new(TestSuite)) } // ——————————————————————————————————————————————————————————————————— // IntegrationSuite - Setup // ——————————————————————————————————————————————————————————————————— -func (s *IntegrationSuite) SetupSuite() { +func (s *TestSuite) SetupSuite() { testutil.BeforeIntegrationSuite(s.T()) testapp.EnsureNibiruPrefix() @@ -122,7 +124,7 @@ func (s *IntegrationSuite) SetupSuite() { s.AddRootToKeyring(s.root) } -func (s *IntegrationSuite) FundRoot(root Account) { +func (s *TestSuite) FundRoot(root Account) { val := s.network.Validators[0] funds := sdk.NewCoins( sdk.NewInt64Coin(denoms.NIBI, 420*common.TO_MICRO), @@ -133,7 +135,7 @@ func (s *IntegrationSuite) FundRoot(root Account) { )) } -func (s *IntegrationSuite) AddRootToKeyring(root Account) { +func (s *TestSuite) AddRootToKeyring(root Account) { s.T().Log("add the x/sudo root account to the clientCtx.Keyring") // Encrypt the x/sudo root account's private key to get its "armor" passphrase := root.passphrase @@ -150,7 +152,7 @@ func (s *IntegrationSuite) AddRootToKeyring(root Account) { // IntegrationSuite - Tests // ——————————————————————————————————————————————————————————————————— -func (s *IntegrationSuite) TestCmdEditSudoers() { +func (s *TestSuite) TestCmdEditSudoers() { val := s.network.Validators[0] _, contractAddrs := testutil.PrivKeyAddressPairs(3) @@ -221,7 +223,7 @@ func (s *IntegrationSuite) TestCmdEditSudoers() { } } -func (s *IntegrationSuite) Test_ZCmdChangeRoot() { +func (s *TestSuite) Test_ZCmdChangeRoot() { val := s.network.Validators[0] sudoers, err := testutilcli.QuerySudoers(val.ClientCtx) @@ -242,7 +244,7 @@ func (s *IntegrationSuite) Test_ZCmdChangeRoot() { // TestMarshal_EditSudoers verifies that the expected proto.Message for // the EditSudoders fn marshals and unmarshals properly from JSON. // This unmarshaling is used in the main body of the CmdEditSudoers command. -func (s *IntegrationSuite) TestMarshal_EditSudoers() { +func (s *TestSuite) TestMarshal_EditSudoers() { t := s.T() t.Log("create valid example json for the message") @@ -270,7 +272,7 @@ func (s *IntegrationSuite) TestMarshal_EditSudoers() { require.NoError(t, newMsg.ValidateBasic(), newMsg.String()) } -func (s *IntegrationSuite) TearDownSuite() { +func (s *TestSuite) TearDownSuite() { s.T().Log("tearing down integration test suite") s.network.Cleanup() } diff --git a/x/tokenfactory/cli/cli_test.go b/x/tokenfactory/cli/cli_test.go index c7d432cb4..bc26adb27 100644 --- a/x/tokenfactory/cli/cli_test.go +++ b/x/tokenfactory/cli/cli_test.go @@ -17,9 +17,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var _ suite.SetupAllSuite = (*IntegrationTestSuite)(nil) +var _ suite.SetupAllSuite = (*TestSuite)(nil) +var _ suite.TearDownAllSuite = (*TestSuite)(nil) -type IntegrationTestSuite struct { +type TestSuite struct { suite.Suite cfg testutilcli.Config @@ -28,17 +29,17 @@ type IntegrationTestSuite struct { } func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, new(IntegrationTestSuite)) + suite.Run(t, new(TestSuite)) } // TestTokenFactory: Runs the test suite with a deterministic order. -func (s *IntegrationTestSuite) TestTokenFactory() { +func (s *TestSuite) TestTokenFactory() { s.Run("CreateDenomTest", s.CreateDenomTest) s.Run("MintBurnTest", s.MintBurnTest) s.Run("ChangeAdminTest", s.ChangeAdminTest) } -func (s *IntegrationTestSuite) SetupSuite() { +func (s *TestSuite) SetupSuite() { testutil.BeforeIntegrationSuite(s.T()) testapp.EnsureNibiruPrefix() encodingConfig := app.MakeEncodingConfig() @@ -54,7 +55,7 @@ func (s *IntegrationTestSuite) SetupSuite() { s.NoError(s.network.WaitForNextBlock()) } -func (s *IntegrationTestSuite) CreateDenomTest() { +func (s *TestSuite) CreateDenomTest() { creator := s.val.Address createDenom := func(subdenom string, wantErr bool) { _, err := s.network.ExecTxCmd( @@ -88,7 +89,7 @@ func (s *IntegrationTestSuite) CreateDenomTest() { s.ElementsMatch(denoms, wantDenoms) } -func (s *IntegrationTestSuite) MintBurnTest() { +func (s *TestSuite) MintBurnTest() { creator := s.val.Address mint := func(coin string, mintTo string, wantErr bool) { mintToArg := fmt.Sprintf("--mint-to=%s", mintTo) @@ -145,7 +146,7 @@ func (s *IntegrationTestSuite) MintBurnTest() { burn(coin.String(), creator.String(), wantErr) // happy } -func (s *IntegrationTestSuite) ChangeAdminTest() { +func (s *TestSuite) ChangeAdminTest() { creator := s.val.Address admin := creator newAdmin := testutil.AccAddress() @@ -179,7 +180,7 @@ func (s *IntegrationTestSuite) ChangeAdminTest() { s.Equal(infoResp.Admin, newAdmin.String()) } -func (s *IntegrationTestSuite) TestQueryModuleParams() { +func (s *TestSuite) TestQueryModuleParams() { paramResp := new(types.QueryParamsResponse) s.NoError( s.network.ExecQuery( @@ -189,7 +190,7 @@ func (s *IntegrationTestSuite) TestQueryModuleParams() { s.Equal(paramResp.Params, types.DefaultModuleParams()) } -func (s *IntegrationTestSuite) TearDownSuite() { +func (s *TestSuite) TearDownSuite() { s.T().Log("tearing down integration test suite") s.network.Cleanup() }