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

ci: use thelper #3809

Merged
merged 13 commits into from
Jun 15, 2023
2 changes: 1 addition & 1 deletion .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.6.0
with:
version: v1.52.0
version: v1.53.1
args: --timeout 5m
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ run:
linters:
disable-all: true
enable:
- depguard
- dogsled
- exportloopref
- errcheck
Expand All @@ -20,6 +19,7 @@ linters:
- misspell
- nakedret
- staticcheck
- thelper
- stylecheck
- revive
- typecheck
Expand Down
2 changes: 2 additions & 0 deletions cmd/build_test_matrix/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ type FeeMiddlewareTestSuite struct {}
}

func assertGithubActionTestMatricesEqual(t *testing.T, expected, actual GithubActionTestMatrix) {
t.Helper()
// sort by both suite and test as the order of the end result does not matter as
// all tests will be run.
sort.SliceStable(expected.Include, func(i, j int) bool {
Expand Down Expand Up @@ -183,6 +184,7 @@ func helper() {}
}

func createFileWithTestSuiteAndTests(t *testing.T, suiteName, fn1Name, fn2Name, dir, filename string) {
t.Helper()
goFileContents := goTestFileContents(suiteName, fn1Name, fn2Name)
err := os.WriteFile(path.Join(dir, filename), []byte(goFileContents), os.FileMode(0o777))
assert.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const bankSendMessage = `{
var multiMsg = fmt.Sprintf("[ %s, %s ]", msgDelegateMessage, bankSendMessage)

func TestGeneratePacketData(t *testing.T) {
t.Helper()
tests := []struct {
name string
memo string
Expand All @@ -57,6 +58,7 @@ func TestGeneratePacketData(t *testing.T) {
banktypes.RegisterInterfaces(registry)
},
assertionFn: func(t *testing.T, msgs []sdk.Msg) {
t.Helper()
assertMsgDelegate(t, msgs[0])
assertMsgBankSend(t, msgs[1])
},
Expand All @@ -68,6 +70,7 @@ func TestGeneratePacketData(t *testing.T) {
message: msgDelegateMessage,
registerInterfaceFn: stakingtypes.RegisterInterfaces,
assertionFn: func(t *testing.T, msgs []sdk.Msg) {
t.Helper()
assertMsgDelegate(t, msgs[0])
},
},
Expand All @@ -78,6 +81,7 @@ func TestGeneratePacketData(t *testing.T) {
message: bankSendMessage,
registerInterfaceFn: banktypes.RegisterInterfaces,
assertionFn: func(t *testing.T, msgs []sdk.Msg) {
t.Helper()
assertMsgBankSend(t, msgs[0])
},
},
Expand Down Expand Up @@ -136,7 +140,7 @@ func TestGeneratePacketData(t *testing.T) {
}
}

func assertMsgBankSend(t *testing.T, msg sdk.Msg) {
func assertMsgBankSend(t *testing.T, msg sdk.Msg) { //nolint:thelper
bankSendMsg, ok := msg.(*banktypes.MsgSend)
require.True(t, ok)
require.Equal(t, "cosmos15ccshhmp0gsx29qpqq6g4zmltnnvgmyu9ueuadh9y2nc5zj0szls5gtddz", bankSendMsg.FromAddress)
Expand All @@ -145,7 +149,7 @@ func assertMsgBankSend(t *testing.T, msg sdk.Msg) {
require.Equal(t, uint64(1000), bankSendMsg.Amount[0].Amount.Uint64())
}

func assertMsgDelegate(t *testing.T, msg sdk.Msg) {
func assertMsgDelegate(t *testing.T, msg sdk.Msg) { //nolint:thelper
msgDelegate, ok := msg.(*stakingtypes.MsgDelegate)
require.True(t, ok)
require.Equal(t, "cosmos15ccshhmp0gsx29qpqq6g4zmltnnvgmyu9ueuadh9y2nc5zj0szls5gtddz", msgDelegate.DelegatorAddress)
Expand Down
9 changes: 5 additions & 4 deletions testing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func SetupTestingApp() (TestingApp, map[string]json.RawMessage) {
// that also act as delegators. For simplicity, each validator is bonded with a delegation
// of one consensus engine unit (10^6) in the default token of the simapp from first genesis
// account. A Nop logger is set in SimApp.
func SetupWithGenesisValSet(t testing.TB, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, powerReduction sdkmath.Int, balances ...banktypes.Balance) TestingApp {
func SetupWithGenesisValSet(tb testing.TB, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, powerReduction sdkmath.Int, balances ...banktypes.Balance) TestingApp {
tb.Helper()
app, genesisState := DefaultTestingAppInit()

// ensure baseapp has a chain-id set before running InitChain
Expand All @@ -78,9 +79,9 @@ func SetupWithGenesisValSet(t testing.TB, valSet *tmtypes.ValidatorSet, genAccs

for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
require.NoError(t, err)
require.NoError(tb, err)
pkAny, err := codectypes.NewAnyWithValue(pk)
require.NoError(t, err)
require.NoError(tb, err)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Expand Down Expand Up @@ -120,7 +121,7 @@ func SetupWithGenesisValSet(t testing.TB, valSet *tmtypes.ValidatorSet, genAccs
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)
require.NoError(tb, err)

// init chain will set the validator set and initialize the genesis accounts
app.InitChain(
Expand Down
2 changes: 2 additions & 0 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type TestChain struct {
// CONTRACT: Validator array must be provided in the order expected by Tendermint.
// i.e. sorted first by power and then lexicographically by address.
func NewTestChainWithValSet(tb testing.TB, coord *Coordinator, chainID string, valSet *tmtypes.ValidatorSet, signers map[string]tmtypes.PrivValidator) *TestChain {
tb.Helper()
genAccs := []authtypes.GenesisAccount{}
genBals := []banktypes.Balance{}
senderAccs := []SenderAccount{}
Expand Down Expand Up @@ -161,6 +162,7 @@ func NewTestChainWithValSet(tb testing.TB, coord *Coordinator, chainID string, v
// NewTestChain initializes a new test chain with a default of 4 validators
// Use this function if the tests do not need custom control over the validator set
func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
t.Helper()
// generate validators private/public key
var (
validatorsPerChain = 4
Expand Down
1 change: 1 addition & 0 deletions testing/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Coordinator struct {

// NewCoordinator initializes Coordinator with N TestChain's
func NewCoordinator(t *testing.T, n int) *Coordinator {
t.Helper()
chains := make(map[string]*TestChain)
coord := &Coordinator{
T: t,
Expand Down
1 change: 1 addition & 0 deletions testing/simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func SignAndDeliver(
tb testing.TB, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, expPass bool, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {
tb.Helper()
tx, err := simtestutil.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
Expand Down
2 changes: 2 additions & 0 deletions testing/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Solomachine struct {
// generated private/public key pairs and a sequence starting at 1. If nKeys
// is greater than 1 then a multisig public key is used.
func NewSolomachine(t *testing.T, cdc codec.BinaryCodec, clientID, diversifier string, nKeys uint64) *Solomachine {
t.Helper()
privKeys, pubKeys, pk := GenerateKeys(t, nKeys)

return &Solomachine{
Expand All @@ -77,6 +78,7 @@ func NewSolomachine(t *testing.T, cdc codec.BinaryCodec, clientID, diversifier s
// interface, if needed. The same is true for the amino based Multisignature
// public key.
func GenerateKeys(t *testing.T, n uint64) ([]cryptotypes.PrivKey, []cryptotypes.PubKey, cryptotypes.PubKey) {
t.Helper()
require.NotEqual(t, uint64(0), n, "generation of zero keys is not allowed")

privKeys := make([]cryptotypes.PrivKey, n)
Expand Down
1 change: 1 addition & 0 deletions testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// ApplyValSetChanges takes in tmtypes.ValidatorSet and []abci.ValidatorUpdate and will return a new tmtypes.ValidatorSet which has the
// provided validator updates applied to the provided validator set.
func ApplyValSetChanges(tb testing.TB, valSet *tmtypes.ValidatorSet, valUpdates []abci.ValidatorUpdate) *tmtypes.ValidatorSet {
tb.Helper()
updates, err := tmtypes.PB2TM.ValidatorUpdates(valUpdates)
require.NoError(tb, err)

Expand Down