Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Jul 31, 2024
1 parent 02029ff commit 55d66bb
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 131 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ concurrency:
jobs:
golangci:
env:
# for private repo access
GOPRIVATE: github.com/initia-labs
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.1
name: golangci-lint
runs-on: ubuntu-latest
Expand All @@ -42,15 +39,15 @@ jobs:
**/**.go
go.mod
go.sum
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
# install golangci-lint
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${{ env.GOLANGCI_LINT_VERSION }}
- name: run go linters (long)
if: env.GIT_DIFF
id: lint_long
run: |
make lint
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
- uses: technote-space/[email protected]
if: steps.lint_long.outcome == 'skipped'
with:
Expand All @@ -68,10 +65,6 @@ jobs:
# Use --check or --exit-code when available (Go 1.19?)
# https://github.com/golang/go/issues/27005
tidy:
env:
# for private repo access
GOPRIVATE: github.com/initia-labs,github.com/skip-mev/slinky
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
runs-on: ubuntu-latest
name: tidy
steps:
Expand All @@ -81,8 +74,6 @@ jobs:
with:
go-version: 1.22
check-latest: true
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- run: |
go mod tidy
CHANGES_IN_REPO=$(git status --porcelain)
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ jobs:
test-coverage-upload:
name: Run test and upload codecov
env:
# for private repo access
GOPRIVATE: github.com/initia-labs/*
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
runs-on: ubuntu-latest
steps:
Expand All @@ -40,25 +37,29 @@ jobs:
**/**.go
go.mod
go.sum
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- name: test & coverage report creation
run: |
go test ./... -mod=readonly -timeout 12m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
if: ${{ env.GIT_DIFF != '' }}
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
- name: filter out DONTCOVER
run: |
excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')"
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/initia-labs\/initia/g')
filename=$(echo $filename | sed 's/^./github.com\/initia-labs\/OPinit/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
if: ${{ env.GIT_DIFF != '' }}
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.txt
fail_ci_if_error: true
if: ${{ env.GIT_DIFF != '' }}
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
23 changes: 1 addition & 22 deletions x/opchild/ante/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,6 @@ var (
addrs[4].String(),
}

valAddrs = []sdk.ValAddress{
sdk.ValAddress(pubKeys[0].Address()),
sdk.ValAddress(pubKeys[1].Address()),
sdk.ValAddress(pubKeys[2].Address()),
sdk.ValAddress(pubKeys[3].Address()),
sdk.ValAddress(pubKeys[4].Address()),
}

valAddrsStr = []string{
valAddrs[0].String(),
valAddrs[1].String(),
valAddrs[2].String(),
valAddrs[3].String(),
valAddrs[4].String(),
}

testDenoms = []string{
"test1",
"test2",
Expand Down Expand Up @@ -210,11 +194,6 @@ type TestKeepers struct {
Faucet *TestFaucet
}

// createDefaultTestInput common settings for createTestInput
func createDefaultTestInput(t testing.TB) (context.Context, TestKeepers) {
return createTestInput(t, false)
}

// createTestInput encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default)
func createTestInput(t testing.TB, isCheckTx bool) (context.Context, TestKeepers) {
return _createTestInput(t, isCheckTx, dbm.NewMemDB())
Expand Down Expand Up @@ -295,7 +274,7 @@ func _createTestInput(
authtypes.NewModuleAddress(opchildtypes.ModuleName).String(),
ctx.Logger(),
)
bankKeeper.SetParams(ctx, banktypes.DefaultParams())
require.NoError(t, bankKeeper.SetParams(ctx, banktypes.DefaultParams()))

msgRouter := baseapp.NewMsgServiceRouter()
msgRouter.SetInterfaceRegistry(encodingConfig.InterfaceRegistry)
Expand Down
6 changes: 4 additions & 2 deletions x/opchild/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ func (s *CLITestSuite) TestNewSetBridgeInfo() {
require.NoError(err)
defer os.Remove(validConfig.Name())

invalidConfig.WriteString(`{}`)
validConfig.WriteString(`{
_, err = invalidConfig.WriteString(`{}`)
s.NoError(err)
_, err = validConfig.WriteString(`{
"challengers": ["init1q6jhwnarkw2j5qqgx3qlu20k8nrdglft5ksr0g"],
"proposer": "init1k2svyvm60r8rhnzr9vemk5f6fksvm6tyeujp3c",
"submission_interval": "100s",
Expand All @@ -440,6 +441,7 @@ func (s *CLITestSuite) TestNewSetBridgeInfo() {
"chain_type": "INITIA"
}
}`)
s.NoError(err)

testCases := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion x/opchild/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func _createTestInput(
authtypes.NewModuleAddress(opchildtypes.ModuleName).String(),
ctx.Logger(),
)
bankKeeper.SetParams(ctx, banktypes.DefaultParams())
require.NoError(t, bankKeeper.SetParams(ctx, banktypes.DefaultParams()))

msgRouter := baseapp.NewMsgServiceRouter()
msgRouter.SetInterfaceRegistry(encodingConfig.InterfaceRegistry)
Expand Down
20 changes: 12 additions & 8 deletions x/opchild/keeper/executor_change_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package keeper_test

import (
"crypto/rand"
"encoding/base64"
"fmt"
"math/rand"
"math"
"math/big"
"testing"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
Expand All @@ -16,16 +18,18 @@ func Test_RegisterExecutorChangePlan(t *testing.T) {
_, input := createTestInput(t, false)

// Arguments
l1ProposalID := rand.Uint64()
height := rand.Uint64()
l1ProposalID, err := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
require.NoError(t, err)
height, err := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
require.NoError(t, err)
nextValAddr := valAddrsStr[0]
nextExecutorAddr := []string{addrsStr[0], addrsStr[1]}
consensusPubKey := "l7aqGv+Zjbm0rallfqfqz+3iN31iOmgJCafWV5pGs6o="
moniker := "moniker"
info := "info"

err := input.OPChildKeeper.RegisterExecutorChangePlan(
l1ProposalID, height, nextValAddr,
err = input.OPChildKeeper.RegisterExecutorChangePlan(
l1ProposalID.Uint64(), height.Uint64(), nextValAddr,
moniker,
fmt.Sprintf(`{"@type":"/cosmos.crypto.ed25519.PubKey","key":"%s"}`, consensusPubKey),
info,
Expand All @@ -42,10 +46,10 @@ func Test_RegisterExecutorChangePlan(t *testing.T) {
}, moniker)
require.NoError(t, err)
require.Equal(t, types.ExecutorChangePlan{
ProposalID: l1ProposalID,
Height: height,
ProposalID: l1ProposalID.Uint64(),
Height: height.Uint64(),
NextExecutors: []string{addrsStr[0], addrsStr[1]},
NextValidator: expectedValidator,
Info: info,
}, input.OPChildKeeper.ExecutorChangePlans[height])
}, input.OPChildKeeper.ExecutorChangePlans[height.Uint64()])
}
8 changes: 5 additions & 3 deletions x/opchild/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func Test_GenesisImportExport(t *testing.T) {
ctx, input := createDefaultTestInput(t)
input.OPChildKeeper.SetNextL2Sequence(ctx, 1)
require.NoError(t, input.OPChildKeeper.SetNextL2Sequence(ctx, 1))

seq, err := input.OPChildKeeper.IncreaseNextL2Sequence(ctx)
require.NoError(t, err)
Expand All @@ -23,8 +23,10 @@ func Test_GenesisImportExport(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(2), seq)

input.OPChildKeeper.IncreaseNextL1Sequence(ctx) // 2
input.OPChildKeeper.IncreaseNextL1Sequence(ctx) // 3
_, err = input.OPChildKeeper.IncreaseNextL1Sequence(ctx) // 2
require.NoError(t, err)
_, err = input.OPChildKeeper.IncreaseNextL1Sequence(ctx) // 3
require.NoError(t, err)

genState := input.OPChildKeeper.ExportGenesis(ctx)
require.Nil(t, genState.BridgeInfo)
Expand Down
8 changes: 4 additions & 4 deletions x/opchild/keeper/historical_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func Test_HistoricalInfo(t *testing.T) {
params, err := input.OPChildKeeper.GetParams(ctx)
require.NoError(t, err)
params.HistoricalEntries = 2
input.OPChildKeeper.SetParams(ctx, params)
require.NoError(t, input.OPChildKeeper.SetParams(ctx, params))

input.OPChildKeeper.TrackHistoricalInfo(sdkCtx.WithBlockHeight(1))
input.OPChildKeeper.TrackHistoricalInfo(sdkCtx.WithBlockHeight(2))
input.OPChildKeeper.TrackHistoricalInfo(sdkCtx.WithBlockHeight(3))
require.NoError(t, input.OPChildKeeper.TrackHistoricalInfo(sdkCtx.WithBlockHeight(1)))
require.NoError(t, input.OPChildKeeper.TrackHistoricalInfo(sdkCtx.WithBlockHeight(2)))
require.NoError(t, input.OPChildKeeper.TrackHistoricalInfo(sdkCtx.WithBlockHeight(3)))

_, err = input.OPChildKeeper.GetHistoricalInfo(ctx, 1)
require.ErrorIs(t, err, collections.ErrNotFound)
Expand Down
6 changes: 4 additions & 2 deletions x/opchild/keeper/host_validator_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func Test_GetHostPubKeyByConsAddr(t *testing.T) {
require.Error(t, err)

// set validator
hostValidatorStore.SetValidator(ctx, val)
err = hostValidatorStore.SetValidator(ctx, val)
require.NoError(t, err)

valPubKeyAfter, err := hostValidatorStore.GetPubKeyByConsAddr(ctx, consAddr)
require.NoError(t, err)
Expand All @@ -80,7 +81,8 @@ func Test_HostValidatorByConsAddr(t *testing.T) {
require.Error(t, err)

// set validator
hostValidatorStore.SetValidator(ctx, val)
err = hostValidatorStore.SetValidator(ctx, val)
require.NoError(t, err)

valAfter, err := hostValidatorStore.ValidatorByConsAddr(ctx, consAddr)
require.NoError(t, err)
Expand Down
18 changes: 12 additions & 6 deletions x/opchild/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ func Test_MsgServer_ExecuteMessages(t *testing.T) {
val, err := types.NewValidator(valAddrs[0], valPubKeys[0], "val1")
require.NoError(t, err)

input.OPChildKeeper.SetValidator(ctx, val)
err = input.OPChildKeeper.SetValidator(ctx, val)
require.NoError(t, err)

// apply validator updates
input.OPChildKeeper.BlockValidatorUpdates(ctx)
_, err = input.OPChildKeeper.BlockValidatorUpdates(ctx)
require.NoError(t, err)

moduleAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(types.ModuleName))
require.NoError(t, err)
Expand All @@ -83,7 +85,8 @@ func Test_MsgServer_ExecuteMessages(t *testing.T) {
require.NoError(t, err)

// apply validator updates
input.OPChildKeeper.BlockValidatorUpdates(ctx)
_, err = input.OPChildKeeper.BlockValidatorUpdates(ctx)
require.NoError(t, err)

vals, err := input.OPChildKeeper.GetAllValidators(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -148,7 +151,8 @@ func Test_MsgServer_AddValidator(t *testing.T) {
params, err := ms.GetParams(ctx)
require.NoError(t, err)
params.MaxValidators = 1
ms.SetParams(ctx, params)
err = ms.SetParams(ctx, params)
require.NoError(t, err)

msg, err = types.NewMsgAddValidator("val2", moduleAddr, valAddrsStr[1], valPubKeys[1])
require.NoError(t, err)
Expand All @@ -160,7 +164,8 @@ func Test_MsgServer_AddValidator(t *testing.T) {
params, err = ms.GetParams(ctx)
require.NoError(t, err)
params.MaxValidators = 2
ms.SetParams(ctx, params)
err = ms.SetParams(ctx, params)
require.NoError(t, err)

_, err = ms.AddValidator(ctx, msg)
require.NoError(t, err)
Expand All @@ -176,7 +181,8 @@ func Test_MsgServer_RemoveValidator(t *testing.T) {
val, err := types.NewValidator(valAddrs[0], valPubKeys[0], "val1")
require.NoError(t, err)

input.OPChildKeeper.SetValidator(ctx, val)
err = input.OPChildKeeper.SetValidator(ctx, val)
require.NoError(t, err)

// invalid signer
msg, err := types.NewMsgRemoveValidator(addrsStr[0], valAddrsStr[0])
Expand Down
7 changes: 4 additions & 3 deletions x/opchild/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func Test_Params(t *testing.T) {
params.MinGasPrices = sdk.NewDecCoins()
params.FeeWhitelist = []string{addrsStr[0], addrsStr[1]}

input.OPChildKeeper.SetParams(ctx, params)
err = input.OPChildKeeper.SetParams(ctx, params)
require.NoError(t, err)

minGasPrices, err := input.OPChildKeeper.MinGasPrices(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -45,9 +46,9 @@ func Test_Change_MaxValidators(t *testing.T) {
err = input.OPChildKeeper.SetParams(ctx, params)
require.NoError(t, err)

input.OPChildKeeper.Validators.Set(ctx, []byte{0}, types.Validator{})
err = input.OPChildKeeper.Validators.Set(ctx, []byte{0}, types.Validator{})
require.NoError(t, err)
input.OPChildKeeper.Validators.Set(ctx, []byte{1}, types.Validator{})
err = input.OPChildKeeper.Validators.Set(ctx, []byte{1}, types.Validator{})
require.NoError(t, err)

// cannot be lower than current number of validators
Expand Down
8 changes: 4 additions & 4 deletions x/opchild/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Test_QueryValidator(t *testing.T) {
val, err := types.NewValidator(valAddrs[0], valPubKeys[0], "validator1")
require.NoError(t, err)

input.OPChildKeeper.SetValidator(ctx, val)
require.NoError(t, input.OPChildKeeper.SetValidator(ctx, val))
q := keeper.NewQuerier(input.OPChildKeeper)

res, err := q.Validator(ctx, &types.QueryValidatorRequest{ValidatorAddr: val.OperatorAddress})
Expand All @@ -40,8 +40,8 @@ func Test_QueryValidators(t *testing.T) {

val2, err := types.NewValidator(valAddrs[1], valPubKeys[1], "validator2")
require.NoError(t, err)
input.OPChildKeeper.SetValidator(ctx, val1)
input.OPChildKeeper.SetValidator(ctx, val2)
require.NoError(t, input.OPChildKeeper.SetValidator(ctx, val1))
require.NoError(t, input.OPChildKeeper.SetValidator(ctx, val2))
q := keeper.NewQuerier(input.OPChildKeeper)

res, err := q.Validators(ctx, &types.QueryValidatorsRequest{})
Expand Down Expand Up @@ -83,7 +83,7 @@ func Test_QueryParams(t *testing.T) {
params, err := input.OPChildKeeper.GetParams(ctx)
require.NoError(t, err)
params.MinGasPrices = sdk.NewDecCoins(sdk.NewInt64DecCoin("stake", 1))
input.OPChildKeeper.SetParams(ctx, params)
require.NoError(t, input.OPChildKeeper.SetParams(ctx, params))

q := keeper.NewQuerier(input.OPChildKeeper)
res, err := q.Params(ctx, &types.QueryParamsRequest{})
Expand Down
5 changes: 3 additions & 2 deletions x/opchild/keeper/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func Test_NextL1GetNextL1Sequence(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(1), res)

input.OPChildKeeper.IncreaseNextL1Sequence(ctx)
_, err = input.OPChildKeeper.IncreaseNextL1Sequence(ctx)
require.NoError(t, err)
res, err = input.OPChildKeeper.GetNextL1Sequence(ctx)
require.NoError(t, err)
require.Equal(t, uint64(2), res)
Expand All @@ -26,7 +27,7 @@ func Test_SetAndSetNextL2Sequence(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(1), seq)

input.OPChildKeeper.SetNextL2Sequence(ctx, 1204)
require.NoError(t, input.OPChildKeeper.SetNextL2Sequence(ctx, 1204))
seq, err = input.OPChildKeeper.GetNextL2Sequence(ctx)
require.NoError(t, err)
require.Equal(t, uint64(1204), seq)
Expand Down
Loading

0 comments on commit 55d66bb

Please sign in to comment.