Skip to content

Commit

Permalink
Merge pull request #419 from irisnet/refactor/lint-code
Browse files Browse the repository at this point in the history
refactor: lint code
  • Loading branch information
mitch1024 authored Jul 2, 2024
2 parents 5969ca0 + e7bcb03 commit f865273
Show file tree
Hide file tree
Showing 281 changed files with 1,440 additions and 1,308 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Lint
on:
push:
branches:
- main
- release/**
pull_request:
merge_group:
permissions:
contents: read
jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v5
with:
go-version: "1.22.2"
check-latest: true
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
Makefile
**/Makefile
.golangci.yml
- name: run linting (long)
if: env.GIT_DIFF
id: lint_long
run: make lint
env:
NIX: 1
- uses: technote-space/[email protected]
if: steps.lint_long.outcome == 'skipped'
with:
PATTERNS: |
**/*.go
*.go
- name: run linting (short)
if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
run: make lint
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
LINT_DIFF: 1
NIX: 1
37 changes: 0 additions & 37 deletions .github/workflows/sims.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
paths:
- '**/*.go'
- '**/*.mod'
paths-ignore:
- '**/*' # 忽略其他所有文件
jobs:
test-unit:
name: Test Units
Expand Down
13 changes: 6 additions & 7 deletions e2e/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import (
upgrademodulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1"
vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1"
"cosmossdk.io/core/appconfig"
_ "github.com/cosmos/cosmos-sdk/x/upgrade" // import for side-effects
"google.golang.org/protobuf/types/known/durationpb"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
Expand All @@ -45,7 +42,9 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
_ "github.com/cosmos/cosmos-sdk/x/upgrade" // import for side-effects
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"google.golang.org/protobuf/types/known/durationpb"

coinswapmodule "mods.irisnet.org/api/irismod/coinswap/module/v1"
farmmodule "mods.irisnet.org/api/irismod/farm/module/v1"
Expand Down Expand Up @@ -92,7 +91,7 @@ var (
distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName,
minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
vestingtypes.ModuleName, consensustypes.ModuleName,
vestingtypes.ModuleName, consensustypes.ModuleName,
coinswaptypes.ModuleName,
farmtypes.ModuleName,
htlctypes.ModuleName,
Expand Down Expand Up @@ -311,7 +310,7 @@ var (
Config: appconfig.WrapAny(&consensusmodulev1.Module{}),
},
{
Name: coinswaptypes.ModuleName,
Name: coinswaptypes.ModuleName,
Config: appconfig.WrapAny(&coinswapmodule.Module{
FeeCollectorName: authtypes.FeeCollectorName,
}),
Expand Down Expand Up @@ -354,11 +353,11 @@ var (
Config: appconfig.WrapAny(&recordmodule.Module{}),
},
{
Name: tokentypes.ModuleName,
Name: tokentypes.ModuleName,
Config: appconfig.WrapAny(&tokenmodule.Module{
FeeCollectorName: authtypes.FeeCollectorName,
}),
},
},
})
)
)
2 changes: 1 addition & 1 deletion e2e/coinswap/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import (

func TestQueryTestSuite(t *testing.T) {
suite.Run(t, new(QueryTestSuite))
}
}
5 changes: 2 additions & 3 deletions e2e/coinswap/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"fmt"
"time"

"github.com/cosmos/gogoproto/proto"

"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"

"mods.irisnet.org/e2e"
coinswaptypes "mods.irisnet.org/modules/coinswap/types"
Expand Down Expand Up @@ -60,7 +59,7 @@ func (s *QueryTestSuite) TestCoinswap() {
txResult := s.BlockSendMsgs(s.T(), msgIssueToken)
s.Require().Equal(uint32(0), txResult.Code, "send issue token msg failed")

//_ = tokentestutil.IssueTokenExec(s.T(), s.Network, clientCtx, from.String(), args...)
// _ = tokentestutil.IssueTokenExec(s.T(), s.Network, clientCtx, from.String(), args...)

balances := simapp.QueryBalancesExec(s.T(), s.Network, clientCtx, from.String())
s.Require().Equal("100000000", balances.AmountOf(symbol).String())
Expand Down
2 changes: 1 addition & 1 deletion e2e/farm/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ func TestTxTestSuite(t *testing.T) {

func TestQueryTestSuite(t *testing.T) {
suite.Run(t, new(QueryTestSuite))
}
}
20 changes: 9 additions & 11 deletions e2e/farm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"fmt"
"time"

"github.com/cosmos/gogoproto/proto"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"

"mods.irisnet.org/e2e"
coinswaptypes "mods.irisnet.org/modules/coinswap/types"
Expand Down Expand Up @@ -108,7 +107,7 @@ func (s *QueryTestSuite) TestQueryCmd() {

_, err = s.WaitForHeight(startHeight)
s.Require().NoError(err)
s.WaitForNextBlock()
s.Require().NoError(s.WaitForNextBlock())

lpToken := sdk.NewCoin(lpTokenDenom, sdk.NewInt(100))
txResult = StakeExec(
Expand Down Expand Up @@ -150,18 +149,17 @@ func (s *QueryTestSuite) latestHeight() int64 {
}

func (s *QueryTestSuite) setup() {

val := s.Validators[0]
clientCtx := val.ClientCtx

from := val.Address
symbol := "kitty"
name := "Kitty Token"
minUnit := "kitty"
scale := uint32(0)
initialSupply := uint64(100000000)
maxSupply := uint64(200000000)
mintable := true
const symbol = "kitty"
const name = "Kitty Token"
const minUnit = "kitty"
const scale = uint32(0)
const initialSupply = uint64(100000000)
const maxSupply = uint64(200000000)
const mintable = true

// issue token
msgIssueToken := &tokentypes.MsgIssueToken{
Expand Down
31 changes: 23 additions & 8 deletions e2e/farm/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/cometbft/cometbft/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

Expand All @@ -17,7 +16,9 @@ import (
// CreateFarmPoolExec creates a redelegate message.
func CreateFarmPoolExec(t *testing.T, network simapp.Network, clientCtx client.Context,
creator string,
extraArgs ...string) *simapp.ResponseTx {
extraArgs ...string,
) *simapp.ResponseTx {
t.Helper()
args := []string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, creator),
}
Expand All @@ -32,6 +33,7 @@ func QueryFarmPoolsExec(
clientCtx client.Context,
extraArgs ...string,
) *farmtypes.QueryFarmPoolsResponse {
t.Helper()
args := []string{
fmt.Sprintf("--%s=json", cli.OutputFlag),
}
Expand All @@ -50,6 +52,7 @@ func QueryFarmPoolExec(
poolID string,
extraArgs ...string,
) *farmtypes.QueryFarmPoolResponse {
t.Helper()
args := []string{
poolID,
fmt.Sprintf("--%s=json", cli.OutputFlag),
Expand All @@ -64,7 +67,9 @@ func QueryFarmPoolExec(
func AppendRewardExec(t *testing.T, network simapp.Network, clientCtx client.Context,
creator,
poolID string,
extraArgs ...string) *simapp.ResponseTx {
extraArgs ...string,
) *simapp.ResponseTx {
t.Helper()
args := []string{
poolID,
fmt.Sprintf("--%s=%s", flags.FlagFrom, creator),
Expand All @@ -78,7 +83,9 @@ func StakeExec(t *testing.T, network simapp.Network, clientCtx client.Context,
creator,
poolID,
lpToken string,
extraArgs ...string) *simapp.ResponseTx {
extraArgs ...string,
) *simapp.ResponseTx {
t.Helper()
args := []string{
poolID,
lpToken,
Expand All @@ -93,7 +100,9 @@ func UnstakeExec(t *testing.T, network simapp.Network, clientCtx client.Context,
creator,
poolID,
lpToken string,
extraArgs ...string) *simapp.ResponseTx {
extraArgs ...string,
) *simapp.ResponseTx {
t.Helper()
args := []string{
poolID,
lpToken,
Expand All @@ -107,7 +116,9 @@ func UnstakeExec(t *testing.T, network simapp.Network, clientCtx client.Context,
func HarvestExec(t *testing.T, network simapp.Network, clientCtx client.Context,
creator,
poolID string,
extraArgs ...string) *simapp.ResponseTx {
extraArgs ...string,
) *simapp.ResponseTx {
t.Helper()
args := []string{
poolID,
fmt.Sprintf("--%s=%s", flags.FlagFrom, creator),
Expand All @@ -120,7 +131,9 @@ func HarvestExec(t *testing.T, network simapp.Network, clientCtx client.Context,
func DestroyExec(t *testing.T, network simapp.Network, clientCtx client.Context,
creator,
poolID string,
extraArgs ...string) *simapp.ResponseTx {
extraArgs ...string,
) *simapp.ResponseTx {
t.Helper()
args := []string{
poolID,
fmt.Sprintf("--%s=%s", flags.FlagFrom, creator),
Expand All @@ -132,7 +145,9 @@ func DestroyExec(t *testing.T, network simapp.Network, clientCtx client.Context,
// QueryFarmerExec creates a redelegate message.
func QueryFarmerExec(t *testing.T, network simapp.Network, clientCtx client.Context,
creator string,
extraArgs ...string) *farmtypes.QueryFarmerResponse {
extraArgs ...string,
) *farmtypes.QueryFarmerResponse {
t.Helper()
args := []string{
creator,
fmt.Sprintf("--%s=json", cli.OutputFlag),
Expand Down
5 changes: 2 additions & 3 deletions e2e/farm/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type TxTestSuite struct {

// TestTxCmd tests all tx command in the nft module
func (s *TxTestSuite) TestTxCmd() {
val := s.Network.Validators[0]
val := s.Network.Validators[0]
clientCtx := val.ClientCtx

s.setup()
Expand Down Expand Up @@ -185,7 +185,6 @@ func (s *TxTestSuite) latestHeight() int64 {
}

func (s *TxTestSuite) setup() {

val := s.Network.Validators[0]
clientCtx := val.ClientCtx

Expand Down Expand Up @@ -226,4 +225,4 @@ func (s *TxTestSuite) setup() {
}
res = s.Network.BlockSendMsgs(s.T(), msgAddLiquidity)
s.Require().Equal(uint32(0), res.Code, res.Log)
}
}
2 changes: 1 addition & 1 deletion e2e/htlc/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ func TestTxTestSuite(t *testing.T) {

func TestQueryTestSuite(t *testing.T) {
suite.Run(t, new(QueryTestSuite))
}
}
5 changes: 2 additions & 3 deletions e2e/htlc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/cometbft/cometbft/crypto"

"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -22,15 +21,15 @@ func (s *QueryTestSuite) TestQueryCmd() {
val := s.Network.Validators[0]

//------test GetCmdCreateHTLC()-------------
//baseURL := val.APIAddress
// baseURL := val.APIAddress
from := val.Address
to := sdk.AccAddress(crypto.AddressHash([]byte("dgsbl")))
amount := "1000" + sdk.DefaultBondDenom
receiverOnOtherChain := "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826"
hashLock := "e8d4133e1a82c74e2746e78c19385706ea7958a0ca441a08dacfa10c48ce2561"
timeLock := uint64(50)
timestamp := uint64(1580000000)
//stateOpen := "HTLC_STATE_OPEN"
// stateOpen := "HTLC_STATE_OPEN"

args := []string{
fmt.Sprintf("--%s=%s", htlccli.FlagTo, to),
Expand Down
Loading

0 comments on commit f865273

Please sign in to comment.