Skip to content

Commit

Permalink
Chore/action lint fix (#41)
Browse files Browse the repository at this point in the history
* fix lint action and lint errors

* remove unnecessary goprivate from workflow
  • Loading branch information
Vritra4 authored Jul 17, 2024
1 parent 6bf40db commit 37e7d88
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 24 deletions.
38 changes: 29 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ jobs:
golangci:
env:
# for private repo access
GOPRIVATE: github.com/initia-labs/*
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
steps:
- uses: actions/[email protected]
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
- uses: technote-space/get-diff-action@v5
check-latest: true
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
Expand All @@ -41,26 +44,43 @@ jobs:
go.sum
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- name: run go linters
# install golangci-lint
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
- name: run go linters (long)
if: env.GIT_DIFF
id: lint_long
run: |
make tools
make lint
if: env.GIT_DIFF
- uses: technote-space/[email protected]
if: steps.lint_long.outcome == 'skipped'
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: run go linters (short)
if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
run: |
make lint
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
LINT_DIFF: 1
# 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/*
GOPRIVATE: github.com/initia-labs,github.com/skip-mev/slinky
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
runs-on: ubuntu-latest
name: tidy
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
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: |
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,17 @@ benchmark:
@go test -timeout 20m -mod=readonly -bench=. ./...

.PHONY: test test-all test-cover test-unit test-race benchmark contracts-gen

###############################################################################
### Linting ###
###############################################################################

lint:
golangci-lint run --out-format=tab --timeout=15m

lint-fix:
golangci-lint run --fix --out-format=tab --timeout=15m

.PHONY: lint lint-fix


2 changes: 1 addition & 1 deletion app/ante/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func internalSignModeToAPI(mode signing.SignMode) (signingv1beta1.SignMode, erro
case signing.SignMode_SIGN_MODE_DIRECT_AUX:
return signingv1beta1.SignMode_SIGN_MODE_DIRECT_AUX, nil
case signing.SignMode_SIGN_MODE_EIP_191:
return signingv1beta1.SignMode_SIGN_MODE_EIP_191, nil
return signingv1beta1.SignMode_SIGN_MODE_EIP_191, nil //nolint:staticcheck
default:
return signingv1beta1.SignMode_SIGN_MODE_UNSPECIFIED, fmt.Errorf("unsupported sign mode %s", mode)
}
Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,9 @@ func (app *MinitiaApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain)
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil {
panic(err)
}
return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func SetupWithGenesisAccounts(
// allow empty validator
if valSet == nil || len(valSet.Validators) == 0 {
privVal := ed25519.GenPrivKey()
pubKey, err := cryptocodec.ToTmPubKeyInterface(privVal.PubKey())
pubKey, err := cryptocodec.ToTmPubKeyInterface(privVal.PubKey()) //nolint:staticcheck
if err != nil {
panic(err)
}
Expand All @@ -104,7 +104,7 @@ func SetupWithGenesisAccounts(

validators := make([]opchildtypes.Validator, 0, len(valSet.Validators))
for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) //nolint:staticcheck
if err != nil {
panic(err)
}
Expand Down
10 changes: 8 additions & 2 deletions jsonrpc/backend/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ func (b *JSONRPCBackend) GetBlockByNumber(ethBlockNum rpc.BlockNumber, fullTx bo

txs := []*rpctypes.RPCTransaction{}
if fullTx {
b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) {
err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) {
txs = append(txs, tx)
return false, nil
})
if err != nil {
return nil, err
}
}

return formatBlock(header, txs), nil
Expand All @@ -129,10 +132,13 @@ func (b *JSONRPCBackend) GetBlockByHash(hash common.Hash, fullTx bool) (map[stri
txs := []*rpctypes.RPCTransaction{}
if fullTx {
blockNumber := header.Number.Uint64()
b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) {
err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) {
txs = append(txs, tx)
return false, nil
})
if err != nil {
return nil, err
}
}

return formatBlock(header, txs), nil
Expand Down
5 changes: 4 additions & 1 deletion jsonrpc/backend/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ func (b *JSONRPCBackend) GetLogsByHeight(height uint64) ([]*coretypes.Log, error
}

txs := []*rpctypes.RPCTransaction{}
b.app.EVMIndexer().IterateBlockTxs(queryCtx, height, func(tx *rpctypes.RPCTransaction) (bool, error) {
err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, height, func(tx *rpctypes.RPCTransaction) (bool, error) {
txs = append(txs, tx)
return false, nil
})
if err != nil {
return nil, err
}

for _, tx := range txs {
receipt, err := b.app.EVMIndexer().TxReceiptByHash(queryCtx, tx.Hash)
Expand Down
11 changes: 8 additions & 3 deletions jsonrpc/backend/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,21 @@ func (b *JSONRPCBackend) EstimateGas(args rpctypes.TransactionArgs, blockNrOrHas
}

txBuilder := b.app.TxConfig().NewTxBuilder()
txBuilder.SetMsgs(sdkMsgs...)
txBuilder.SetSignatures(signing.SignatureV2{
if err = txBuilder.SetMsgs(sdkMsgs...); err != nil {
return hexutil.Uint64(0), err
}
if err = txBuilder.SetSignatures(signing.SignatureV2{
PubKey: nil,
Data: &signing.SingleSignatureData{
SignMode: keeper.SignMode_SIGN_MODE_ETHEREUM,
Signature: nil,
},
Sequence: uint64(*args.Nonce),
})
}); err != nil {
return hexutil.Uint64(0), err
}
tx := txBuilder.GetTx()

txBytes, err := b.app.TxConfig().TxEncoder()(tx)
if err != nil {
return hexutil.Uint64(0), err
Expand Down
15 changes: 12 additions & 3 deletions x/evm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
}

kvs := []types.GenesisKeyValue{}
k.VMStore.Walk(ctx, nil, func(key, value []byte) (stop bool, err error) {
err = k.VMStore.Walk(ctx, nil, func(key, value []byte) (stop bool, err error) {
kvs = append(kvs, types.GenesisKeyValue{Key: key, Value: value})
return false, nil
})
if err != nil {
panic(err)
}

var stores *types.GenesisERC20Stores
erc20Stores := []types.GenesisERC20Stores{}
k.ERC20Stores.Walk(ctx, nil, func(key collections.Pair[[]byte, []byte]) (stop bool, err error) {
err = k.ERC20Stores.Walk(ctx, nil, func(key collections.Pair[[]byte, []byte]) (stop bool, err error) {
if stores == nil || !bytes.Equal(stores.Address, key.K1()) {
erc20Stores = append(erc20Stores, types.GenesisERC20Stores{
Address: key.K1(),
Expand All @@ -125,16 +128,22 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
stores.Stores = append(stores.Stores, key.K2())
return false, nil
})
if err != nil {
panic(err)
}

denomAddresses := []types.GenesisDenomAddress{}
k.ERC20ContractAddrsByDenom.Walk(ctx, nil, func(denom string, contractAddr []byte) (stop bool, err error) {
err = k.ERC20ContractAddrsByDenom.Walk(ctx, nil, func(denom string, contractAddr []byte) (stop bool, err error) {
denomAddresses = append(denomAddresses, types.GenesisDenomAddress{
Denom: denom,
ContractAddress: contractAddr,
})

return false, nil
})
if err != nil {
panic(err)
}

factoryAddr, err := k.ERC20FactoryAddr.Get(ctx)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions x/evm/keeper/txutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,14 @@ func (u *TxUtils) ConvertEthereumTxToCosmosTx(ctx context.Context, ethTx *corety
}

txBuilder := authtx.NewTxConfig(u.cdc, authtx.DefaultSignModes).NewTxBuilder()
txBuilder.SetMsgs(sdkMsgs...)
if err = txBuilder.SetMsgs(sdkMsgs...); err != nil {
return nil, err
}
txBuilder.SetFeeAmount(feeAmount)
txBuilder.SetGasLimit(gasLimit)
txBuilder.SetSignatures(sig)
if err = txBuilder.SetSignatures(sig); err != nil {
return nil, err
}

// set memo
memo, err := json.Marshal(metadata{
Expand Down

0 comments on commit 37e7d88

Please sign in to comment.