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

use thelper in golangci-lint #143

Merged
merged 2 commits into from
Apr 18, 2023
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linters:
- staticcheck
- stylecheck
- typecheck
- thelper
- unconvert
- unparam
- unused
Expand Down
1 change: 1 addition & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestGetEnabledProposals(t *testing.T) {
}

func SetupGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, _ []wasm.Option, app *MigalooApp, balances ...banktypes.Balance) GenesisState {
t.Helper()
genesisState := NewDefaultGenesisState()
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
Expand Down
6 changes: 4 additions & 2 deletions app/test_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ type TestSupport struct {
app *MigalooApp
}

func NewTestSupport(t testing.TB, app *MigalooApp) *TestSupport {
return &TestSupport{t: t, app: app}
// NewTestSupport creates a new TestSupport instance, which provides access to the app for testing.
func NewTestSupport(tb testing.TB, app *MigalooApp) *TestSupport {
Fixed Show fixed Hide fixed
tb.Helper()
return &TestSupport{t: tb, app: app}
}

func (s TestSupport) IBCKeeper() *ibckeeper.Keeper {
Expand Down
19 changes: 13 additions & 6 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ var DefaultConsensusParams = &tmproto.ConsensusParams{
},
}

func setup(t testing.TB, withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*MigalooApp, GenesisState) {
nodeHome := t.TempDir()
func setup(tb testing.TB, withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*MigalooApp, GenesisState) {
tb.Helper()
nodeHome := tb.TempDir()
snapshotDir := filepath.Join(nodeHome, "data", "snapshots")
snapshotDB, err := dbm.NewDB("metadata", dbm.MemDBBackend, snapshotDir)
require.NoError(t, err)
require.NoError(tb, err)
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
require.NoError(t, err)
require.NoError(tb, err)
baseAppOpts := []func(*bam.BaseApp){
bam.SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(50000, 2)),
}
Expand Down Expand Up @@ -102,6 +103,7 @@ func Setup(isCheckTx bool, opts ...wasm.Option) *MigalooApp {
}

func SetupMigalooAppWithValSet(t *testing.T) *MigalooApp {
t.Helper()
// generate validator private/public key
privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
Expand Down Expand Up @@ -131,6 +133,7 @@ func SetupMigalooAppWithValSet(t *testing.T) *MigalooApp {
// of one consensus engine unit (10^6) in the default token of the MigalooApp from first genesis
// account. A Nop logger is set in MigalooApp.
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, opts []wasm.Option, balances ...banktypes.Balance) *MigalooApp {
t.Helper()
app, genesisState := setup(t, true, 5, opts...)
genesisState, err := simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, genAccs, balances...)
require.NoError(t, err)
Expand Down Expand Up @@ -240,8 +243,9 @@ func GenesisStateWithValSet(app *MigalooApp) GenesisState {
}

// SetupWithEmptyStore setup a wasmd app instance with empty DB
func SetupWithEmptyStore(t testing.TB) *MigalooApp {
app, _ := setup(t, false, 0)
func SetupWithEmptyStore(tb testing.TB) *MigalooApp {
tb.Helper()
app, _ := setup(tb, false, 0)
return app
}

Expand Down Expand Up @@ -366,6 +370,7 @@ func TestAddr(addr string, bech string) (sdk.AccAddress, error) {

// CheckBalance checks the balance of an account.
func CheckBalance(t *testing.T, app *MigalooApp, addr sdk.AccAddress, balances sdk.Coins) {
t.Helper()
ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{})
require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr)))
}
Expand All @@ -380,6 +385,7 @@ func SignCheckDeliver(
t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {
t.Helper()
tx, err := simtestutil.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
Expand Down Expand Up @@ -430,6 +436,7 @@ func SignAndDeliver(
t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {
t.Helper()
tx, err := simtestutil.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
Expand Down