Skip to content

Commit

Permalink
refactor(test)!: refactor simapp.Setup function (cosmos#9938)
Browse files Browse the repository at this point in the history
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

ref: cosmos#8961 

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on [cosmos#9697](cosmos#9697 (review)), this PR is the first step for the cosmos#8961.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
aleem1314 authored Aug 17, 2021
1 parent 3022865 commit 23e864b
Show file tree
Hide file tree
Showing 87 changed files with 264 additions and 242 deletions.
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 {
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

0 comments on commit 23e864b

Please sign in to comment.