Skip to content

Commit

Permalink
Merge pull request #143 from White-Whale-Defi-Platform/use-thelper
Browse files Browse the repository at this point in the history
use thelper in golangci-lint
  • Loading branch information
faddat authored Apr 18, 2023
2 parents 9584edd + d9b2b1e commit 534f3a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
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 {
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

0 comments on commit 534f3a6

Please sign in to comment.