Skip to content

Commit

Permalink
stlye: use thelper without linting every test (#5064)
Browse files Browse the repository at this point in the history
* use thelper in golangci-lint without linting every test

* add changelog entry

* Update tests/e2e/containers/containers.go

Co-authored-by: Roman <[email protected]>

---------

Co-authored-by: Roman <[email protected]>
  • Loading branch information
faddat and p0mvn authored May 8, 2023
1 parent 7ec4c2f commit 5e6d539
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ linters:
- staticcheck
- stylecheck
- tenv
- thelper
- testpackage
- typecheck
- unconvert
Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Misc Improvements

* [#5103](https://github.com/osmosis-labs/osmosis/pull/5103) Run `make format`
* [#5105](https://github.com/osmosis-labs/osmosis/pull/5105) Lint stableswap in the same manner as all of Osmosis
* [#5065](https://github.com/osmosis-labs/osmosis/pull/5065) Use cosmossdk.io/errors
* [#4549](https://github.com/osmosis-labs/osmosis/pull/4549) Add single pool price estimate queries
Expand Down
1 change: 1 addition & 0 deletions simulation/executor/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type LogWriter interface {

// LogWriter - return a dummy or standard log writer given the testingmode
func NewLogWriter(tb testing.TB) LogWriter {
tb.Helper()
// TODO: Figure out whats going on / why here
testingMode, _, _ := getTestingMode(tb)

Expand Down
4 changes: 3 additions & 1 deletion simulation/executor/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func SimulateFromSeed(
initFunctions InitFunctions,
config Config,
) (lastCommitId storetypes.CommitID, stopEarly bool, err error) {
tb.Helper()
// in case we have to end early, don't os.Exit so that we can run cleanup code.
// TODO: Understand exit pattern, this is so screwed up. Then delete ^

Expand Down Expand Up @@ -122,6 +123,7 @@ func cursedInitializationLogic(
initFunctions InitFunctions,
config *Config,
) (*simtypes.SimCtx, *simState, Params, error) {
tb.Helper()
fmt.Fprintf(w, "Starting SimulateFromSeed with randomness created with seed %d\n", int(config.Seed))

r := rand.New(rand.NewSource(config.Seed))
Expand Down Expand Up @@ -156,7 +158,7 @@ func cursedInitializationLogic(
// must set version in order to generate hashes
initialHeader.Version.Block = 11

simState := newSimulatorState(simParams, initialHeader, tb, w, validators, *config)
simState := newSimulatorState(tb, simParams, initialHeader, w, validators, *config)

// TODO: If simulation has a param export path configured, export params here.

Expand Down
3 changes: 2 additions & 1 deletion simulation/executor/simulate_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type simState struct {
config Config
}

func newSimulatorState(simParams Params, initialHeader tmproto.Header, tb testing.TB, w io.Writer, validators mockValidators, config Config) *simState {
func newSimulatorState(tb testing.TB, simParams Params, initialHeader tmproto.Header, w io.Writer, validators mockValidators, config Config) *simState {
tb.Helper()
return &simState{
simParams: simParams,
header: initialHeader,
Expand Down
1 change: 1 addition & 0 deletions simulation/executor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B) {
tb.Helper()
testingMode = false

if _t, ok := tb.(*testing.T); ok {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/configurer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (
)

func New(t *testing.T, containerManager *containers.Manager, id string, initValidatorConfigs []*initialization.NodeConfig) *Config {
t.Helper()
numVal := float32(len(initValidatorConfigs))
return &Config{
ChainMeta: initialization.ChainMeta{
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/configurer/chain/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type NodeConfig struct {

// NewNodeConfig returens new initialized NodeConfig.
func NewNodeConfig(t *testing.T, initNode *initialization.Node, initConfig *initialization.NodeConfig, chainId string, containerManager *containers.Manager) *NodeConfig {
t.Helper()
return &NodeConfig{
Node: *initNode,
SnapshotInterval: initConfig.SnapshotInterval,
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/configurer/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type CurrentBranchConfigurer struct {
var _ Configurer = (*CurrentBranchConfigurer)(nil)

func NewCurrentBranchConfigurer(t *testing.T, chainConfigs []*chain.Config, setupTests setupFn, containerManager *containers.Manager) Configurer {
t.Helper()
return &CurrentBranchConfigurer{
baseConfigurer: baseConfigurer{
chainConfigs: chainConfigs,
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/configurer/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var (
// - If !isIBCEnabled and !isUpgradeEnabled, we only need one chain at the current
// Git branch version of the Osmosis code.
func New(t *testing.T, isIBCEnabled, isDebugLogEnabled bool, upgradeSettings UpgradeSettings) (Configurer, error) {
t.Helper()
containerManager, err := containers.NewManager(upgradeSettings.IsEnabled, upgradeSettings.ForkHeight > 0, isDebugLogEnabled)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type UpgradeConfigurer struct {
var _ Configurer = (*UpgradeConfigurer)(nil)

func NewUpgradeConfigurer(t *testing.T, chainConfigs []*chain.Config, setupTests setupFn, containerManager *containers.Manager, upgradeVersion string, forkHeight int64) Configurer {
t.Helper()
return &UpgradeConfigurer{
baseConfigurer: baseConfigurer{
chainConfigs: chainConfigs,
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ func NewManager(isUpgrade bool, isFork bool, isDebugLogEnabled bool) (docker *Ma

// ExecTxCmd Runs ExecTxCmdWithSuccessString searching for `code: 0`
func (m *Manager) ExecTxCmd(t *testing.T, chainId string, containerName string, command []string) (bytes.Buffer, bytes.Buffer, error) {
t.Helper()
return m.ExecTxCmdWithSuccessString(t, chainId, containerName, command, "code: 0")
}

// ExecTxCmdWithSuccessString Runs ExecCmd, with flags for txs added.
// namely adding flags `--chain-id={chain-id} -b=block --yes --keyring-backend=test "--log_format=json" --gas=400000`,
// and searching for `successStr`
func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, containerName string, command []string, successStr string) (bytes.Buffer, bytes.Buffer, error) {
t.Helper()
allTxArgs := []string{fmt.Sprintf("--chain-id=%s", chainId)}
allTxArgs = append(allTxArgs, txArgs...)
// parse to see if command has gas flags. If not, add default gas flags.
Expand All @@ -97,6 +99,7 @@ func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, conta

// ExecHermesCmd executes command on the hermes relaer container.
func (m *Manager) ExecHermesCmd(t *testing.T, command []string, success string) (bytes.Buffer, bytes.Buffer, error) {
t.Helper()
return m.ExecCmd(t, hermesContainerName, command, success)
}

Expand All @@ -106,6 +109,7 @@ func (m *Manager) ExecHermesCmd(t *testing.T, command []string, success string)
// returns container std out, container std err, and error if any.
// An error is returned if the command fails to execute or if the success string is not found in the output.
func (m *Manager) ExecCmd(t *testing.T, containerName string, command []string, success string) (bytes.Buffer, bytes.Buffer, error) {
t.Helper()
if _, ok := m.resources[containerName]; !ok {
return bytes.Buffer{}, bytes.Buffer{}, fmt.Errorf("no resource %s found", containerName)
}
Expand Down
1 change: 1 addition & 0 deletions x/poolmanager/client/testutil/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func MsgCreatePool(
futureGovernor string,
extraArgs ...string,
) (testutil.BufferWriter, error) {
t.Helper()
args := []string{}

jsonFile := testutil.WriteToNewTempFile(t,
Expand Down
2 changes: 1 addition & 1 deletion x/txfees/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (suite *KeeperTestSuite) SetupTest(isCheckTx bool) {
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithJSONCodec(encodingConfig.Marshaler)
WithCodec(encodingConfig.Marshaler)

// Mint some assets to the accounts.
for _, acc := range suite.TestAccs {
Expand Down

0 comments on commit 5e6d539

Please sign in to comment.