Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(test)!: refactor simapp.Setup function #9938

Merged
merged 9 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9576](https://github.com/cosmos/cosmos-sdk/pull/9576) Add debug error message to `sdkerrors.QueryResult` when enabled
* [\#9650](https://github.com/cosmos/cosmos-sdk/pull/9650) Removed deprecated message handler implementation from the SDK modules.
* (x/bank) [\#9832] (https://github.com/cosmos/cosmos-sdk/pull/9832) `AddressFromBalancesStore` renamed to `AddressAndDenomFromBalancesStore`.
* (tests) [\#9938](https://github.com/cosmos/cosmos-sdk/pull/9938) `simapp.Setup` accepts additional `testing.T` argument.


### Client Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion server/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type IntegrationTestSuite struct {

func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
s.app = simapp.Setup(false)
s.app = simapp.Setup(s.T(), false)
s.cfg = network.DefaultConfig()
s.cfg.NumValidators = 1

Expand Down
8 changes: 4 additions & 4 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) {
}

// Setup initializes a new SimApp. A Nop logger is set in SimApp.
func Setup(isCheckTx bool) *SimApp {
func Setup(t *testing.T, isCheckTx bool) *SimApp {
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
t.Helper()

app, genesisState := setup(!isCheckTx, 5)
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
}
require.NoError(t, err)

// Initialize the chain
app.InitChain(
Expand Down
9 changes: 5 additions & 4 deletions types/query/filtered_pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package query_test

import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
Expand All @@ -15,7 +16,7 @@ import (
var addr1 = sdk.AccAddress([]byte("addr1"))

func (s *paginationTestSuite) TestFilteredPaginations() {
app, ctx, appCodec := setupTest()
app, ctx, appCodec := setupTest(s.T())

var balances sdk.Coins
for i := 0; i < numBalances; i++ {
Expand Down Expand Up @@ -90,7 +91,7 @@ func (s *paginationTestSuite) TestFilteredPaginations() {
}

func (s *paginationTestSuite) TestReverseFilteredPaginations() {
app, ctx, appCodec := setupTest()
app, ctx, appCodec := setupTest(s.T())

var balances sdk.Coins
for i := 0; i < numBalances; i++ {
Expand Down Expand Up @@ -170,8 +171,8 @@ func (s *paginationTestSuite) TestReverseFilteredPaginations() {

}

func ExampleFilteredPaginate() {
app, ctx, _ := setupTest()
func ExampleFilteredPaginate(t *testing.T) {
app, ctx, _ := setupTest(t)

var balances sdk.Coins
for i := 0; i < numBalances; i++ {
Expand Down
12 changes: 6 additions & 6 deletions types/query/pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *paginationTestSuite) TestParsePagination() {
}

func (s *paginationTestSuite) TestPagination() {
app, ctx, _ := setupTest()
app, ctx, _ := setupTest(s.T())
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, app.BankKeeper)
queryClient := types.NewQueryClient(queryHelper)
Expand Down Expand Up @@ -170,7 +170,7 @@ func (s *paginationTestSuite) TestPagination() {
}

func (s *paginationTestSuite) TestReversePagination() {
app, ctx, _ := setupTest()
app, ctx, _ := setupTest(s.T())
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, app.BankKeeper)
queryClient := types.NewQueryClient(queryHelper)
Expand Down Expand Up @@ -293,8 +293,8 @@ func (s *paginationTestSuite) TestReversePagination() {
s.Require().Nil(res.Pagination.NextKey)
}

func ExamplePaginate() {
app, ctx, _ := setupTest()
func ExamplePaginate(t *testing.T) {
app, ctx, _ := setupTest(t)

var balances sdk.Coins

Expand Down Expand Up @@ -335,8 +335,8 @@ func ExamplePaginate() {
// balances:<denom:"foo0denom" amount:"100" > pagination:<next_key:"foo1denom" total:2 >
}

func setupTest() (*simapp.SimApp, sdk.Context, codec.Codec) {
app := simapp.Setup(false)
func setupTest(t *testing.T) (*simapp.SimApp, sdk.Context, codec.Codec) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1})
appCodec := app.AppCodec()

Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/sigverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (suite *AnteTestSuite) TestSigVerification() {
// In the meantime, we want to make double-sure amino compatibility works.
// ref: https://github.com/cosmos/cosmos-sdk/issues/7229
func (suite *AnteTestSuite) TestSigVerification_ExplicitAmino() {
suite.app, suite.ctx = createTestApp(true)
suite.app, suite.ctx = createTestApp(suite.T(), true)
suite.ctx = suite.ctx.WithBlockHeight(1)

// Set up TxConfig.
Expand Down
6 changes: 3 additions & 3 deletions x/auth/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type AnteTestSuite struct {
}

// returns context and app with params set on account keeper
func createTestApp(isCheckTx bool) (*simapp.SimApp, sdk.Context) {
app := simapp.Setup(isCheckTx)
func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) {
app := simapp.Setup(t, isCheckTx)
ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{})
app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams())

Expand All @@ -51,7 +51,7 @@ func createTestApp(isCheckTx bool) (*simapp.SimApp, sdk.Context) {

// SetupTest setups a new test, with new app, context, and anteHandler.
func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {
suite.app, suite.ctx = createTestApp(isCheckTx)
suite.app, suite.ctx = createTestApp(suite.T(), isCheckTx)
suite.ctx = suite.ctx.WithBlockHeight(1)

// Set up TxConfig.
Expand Down
6 changes: 4 additions & 2 deletions x/auth/keeper/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper_test

import (
"testing"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/simapp"
Expand All @@ -9,8 +11,8 @@ import (
)

// returns context and app with params set on account keeper
func createTestApp(isCheckTx bool) (*simapp.SimApp, sdk.Context) {
app := simapp.Setup(isCheckTx)
func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) {
app := simapp.Setup(t, isCheckTx)
ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{})
app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams())

Expand Down
4 changes: 2 additions & 2 deletions x/auth/keeper/keeper_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func BenchmarkAccountMapperGetAccountFound(b *testing.B) {
b.ReportAllocs()
app, ctx := createTestApp(false)
app, ctx := createTestApp(&testing.T{}, false)

// assumes b.N < 2**24
for i := 0; i < b.N; i++ {
Expand All @@ -27,7 +27,7 @@ func BenchmarkAccountMapperGetAccountFound(b *testing.B) {

func BenchmarkAccountMapperSetAccount(b *testing.B) {
b.ReportAllocs()
app, ctx := createTestApp(false)
app, ctx := createTestApp(&testing.T{}, false)

b.ResetTimer()

Expand Down
10 changes: 5 additions & 5 deletions x/auth/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type KeeperTestSuite struct {
}

func (suite *KeeperTestSuite) SetupTest() {
suite.app, suite.ctx = createTestApp(true)
suite.app, suite.ctx = createTestApp(suite.T(), true)

queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, suite.app.AccountKeeper)
Expand All @@ -46,7 +46,7 @@ func TestKeeperTestSuite(t *testing.T) {
}

func TestAccountMapperGetSet(t *testing.T) {
app, ctx := createTestApp(true)
app, ctx := createTestApp(t, true)
addr := sdk.AccAddress([]byte("some---------address"))

// no account before its created
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestAccountMapperGetSet(t *testing.T) {
}

func TestAccountMapperRemoveAccount(t *testing.T) {
app, ctx := createTestApp(true)
app, ctx := createTestApp(t, true)
addr1 := sdk.AccAddress([]byte("addr1---------------"))
addr2 := sdk.AccAddress([]byte("addr2---------------"))

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestAccountMapperRemoveAccount(t *testing.T) {
}

func TestGetSetParams(t *testing.T) {
app, ctx := createTestApp(true)
app, ctx := createTestApp(t, true)
params := types.DefaultParams()

app.AccountKeeper.SetParams(ctx, params)
Expand All @@ -119,7 +119,7 @@ func TestGetSetParams(t *testing.T) {
}

func TestSupply_ValidatePermissions(t *testing.T) {
app, _ := createTestApp(true)
app, _ := createTestApp(t, true)

// add module accounts to supply keeper
maccPerms := simapp.GetMaccPerms()
Expand Down
2 changes: 1 addition & 1 deletion x/auth/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func TestQueryAccount(t *testing.T) {
app, ctx := createTestApp(true)
app, ctx := createTestApp(t, true)
legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino())

req := abci.RequestQuery{
Expand Down
2 changes: 1 addition & 1 deletion x/auth/migrations/v043/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
app := simapp.Setup(false)
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{
Time: time.Now(),
})
Expand Down
2 changes: 1 addition & 1 deletion x/auth/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
app := simapp.Setup(false)
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

app.InitChain(
Expand Down
6 changes: 3 additions & 3 deletions x/auth/signing/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestVerifySignature(t *testing.T) {
chainId = "test-chain"
)

app, ctx := createTestApp(false)
app, ctx := createTestApp(t, false)
ctx = ctx.WithBlockHeight(1)

cdc := codec.NewLegacyAmino()
Expand Down Expand Up @@ -97,8 +97,8 @@ func TestVerifySignature(t *testing.T) {
}

// returns context and app with params set on account keeper
func createTestApp(isCheckTx bool) (*simapp.SimApp, sdk.Context) {
app := simapp.Setup(isCheckTx)
func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) {
app := simapp.Setup(t, isCheckTx)
ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{})
app.AccountKeeper.SetParams(ctx, types.DefaultParams())

Expand Down
2 changes: 1 addition & 1 deletion x/auth/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
)

func TestDecodeStore(t *testing.T) {
app := simapp.Setup(false)
app := simapp.Setup(t, false)
cdc := simapp.MakeTestEncodingConfig().Codec
acc := types.NewBaseAccountWithAddress(delAddr1)
dec := simulation.NewDecodeStore(app.AccountKeeper)
Expand Down
2 changes: 2 additions & 0 deletions x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
yaml "gopkg.in/yaml.v2"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -59,6 +60,7 @@ func TestBaseSequence(t *testing.T) {
}

func TestBaseAccountMarshal(t *testing.T) {
app := simapp.Setup(t, false)
_, pub, addr := testdata.KeyTestPubAddr()
acc := types.NewBaseAccountWithAddress(addr)
seq := uint64(7)
Expand Down
1 change: 0 additions & 1 deletion x/auth/types/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

var (
app = simapp.Setup(false)
ecdc = simapp.MakeTestEncodingConfig()
appCodec, legacyAmino = ecdc.Codec, ecdc.Amino
)
9 changes: 0 additions & 9 deletions x/auth/vesting/types/common_test.go

This file was deleted.

Loading