diff --git a/e2e/farm/query.go b/e2e/farm/query.go index e7590495..6a7124ec 100644 --- a/e2e/farm/query.go +++ b/e2e/farm/query.go @@ -153,13 +153,13 @@ func (s *QueryTestSuite) setup() { 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{ diff --git a/e2e/nft/query.go b/e2e/nft/query.go index 31b31976..778263be 100644 --- a/e2e/nft/query.go +++ b/e2e/nft/query.go @@ -13,6 +13,22 @@ import ( nfttypes "mods.irisnet.org/modules/nft/types" ) +const ( + tokenName = "Kitty Token" + uri = "uri" + uriHash = "uriHash" + description = "description" + data = "{\"key1\":\"value1\",\"key2\":\"value2\"}" + tokenID = "kitty" + // owner := "owner" + denomName = "name" + denomID = "denom" + schema = "schema" + symbol = "symbol" + mintRestricted = true + updateRestricted = false +) + // QueryTestSuite is a suite of end-to-end tests for the nft module type QueryTestSuite struct { e2e.TestSuite @@ -20,26 +36,9 @@ type QueryTestSuite struct { // TestQueryCmd tests all query command in the nft module func (s *QueryTestSuite) TestQueryCmd() { - // s.SetupSuite() - val := s.Network.Validators[0] clientCtx := val.ClientCtx - // --------------------------------------------------------------------------- - from := val.Address - tokenName := "Kitty Token" - uri := "uri" - uriHash := "uriHash" - description := "description" - data := "{\"key1\":\"value1\",\"key2\":\"value2\"}" - tokenID := "kitty" - // owner := "owner" - denomName := "name" - denomID := "denom" - schema := "schema" - symbol := "symbol" - mintRestricted := true - updateRestricted := false baseURL := val.APIAddress //------test GetCmdIssueDenom()------------- diff --git a/e2e/random/query.go b/e2e/random/query.go index 1270d71a..50c2a360 100644 --- a/e2e/random/query.go +++ b/e2e/random/query.go @@ -127,13 +127,13 @@ func (s *QueryTestSuite) TestQueryCmd() { s.Require().Len(qrrResp.Requests, 1) // ------get service request------------- - requestHeight ++ + requestHeight++ _, err = s.Network.WaitForHeightWithTimeout( requestHeight, time.Duration(int64(blockInterval+2)*int64(s.Network.TimeoutCommit)), ) if err != nil { - s.Network.WaitForNBlock(2) + s.Require().NoError(s.Network.WaitForNBlock(2)) } blockResult, err := val.RPCClient.BlockResults(context.Background(), &requestHeight) diff --git a/e2e/random/tx.go b/e2e/random/tx.go index 855dac3f..17f1753c 100644 --- a/e2e/random/tx.go +++ b/e2e/random/tx.go @@ -124,7 +124,7 @@ func (s *TxTestSuite) TestTxCmd() { s.Require().Len(qrrResp.Requests, 1) // ------get service request------------- - requestHeight ++ + requestHeight++ _, err := s.WaitForHeightWithTimeout( requestHeight, time.Duration(int64(blockInterval+5)*int64(s.TimeoutCommit)), diff --git a/e2e/service/query.go b/e2e/service/query.go index ddae4e60..7c4b1724 100644 --- a/e2e/service/query.go +++ b/e2e/service/query.go @@ -74,9 +74,9 @@ func (s *QueryTestSuite) TestQueryCmd() { s.Require().NoError(err) reqServiceFee := fmt.Sprintf("50%s", serviceDenom) - reqInput := `{"header":{},"body":{}}` - respResult := `{"code":200,"message":""}` - respOutput := `{"header":{},"body":{}}` + const reqInput = `{"header":{},"body":{}}` + const respResult = `{"code":200,"message":""}` + const respOutput = `{"header":{},"body":{}}` timeout := qos expectedEarnedFees := fmt.Sprintf("48%s", serviceDenom) @@ -307,11 +307,11 @@ func (s *QueryTestSuite) TestQueryCmd() { var requests []servicetypes.CompactRequest var requestsBz []byte for _, attribute := range event.Attributes { - if string(attribute.Key) == servicetypes.AttributeKeyRequests { + if attribute.Key == servicetypes.AttributeKeyRequests { requestsBz = []byte(attribute.Value) } - if string(attribute.Key) == servicetypes.AttributeKeyRequestContextID && - string(attribute.GetValue()) == requestContextId { + if attribute.Key == servicetypes.AttributeKeyRequestContextID && + attribute.GetValue() == requestContextId { found = true } } diff --git a/e2e/token/query.go b/e2e/token/query.go index ae7cee08..54665561 100644 --- a/e2e/token/query.go +++ b/e2e/token/query.go @@ -24,16 +24,7 @@ type QueryTestSuite struct { func (s *QueryTestSuite) TestQueryCmd() { val := s.Network.Validators[0] clientCtx := val.ClientCtx - // --------------------------------------------------------------------------- - from := val.Address - symbol := "kitty" - name := "Kitty Token" - minUnit := "kitty" - scale := 0 - initialSupply := int64(100000000) - maxSupply := int64(200000000) - mintable := true baseURL := val.APIAddress //------test GetCmdIssueToken()------------- diff --git a/e2e/token/tx.go b/e2e/token/tx.go index 6151a73e..ad71abe5 100644 --- a/e2e/token/tx.go +++ b/e2e/token/tx.go @@ -14,6 +14,16 @@ import ( "mods.irisnet.org/simapp" ) +const ( + symbol = "kitty" + name = "Kitty Token" + minUnit = "kitty" + scale = 0 + initialSupply = int64(100000000) + maxSupply = int64(200000000) + mintable = true +) + // TxTestSuite is a suite of end-to-end tests for the nft module type TxTestSuite struct { e2e.TestSuite @@ -23,16 +33,7 @@ type TxTestSuite struct { func (s *TxTestSuite) TestTxCmd() { val := s.Network.Validators[0] clientCtx := val.ClientCtx - // --------------------------------------------------------------------------- - from := val.Address - symbol := "kitty" - name := "Kitty Token" - minUnit := "kitty" - scale := 0 - initialSupply := int64(100000000) - maxSupply := int64(200000000) - mintable := true //------test GetCmdIssueToken()------------- args := []string{ diff --git a/modules/coinswap/keeper/genesis.go b/modules/coinswap/keeper/genesis.go index 589b0edf..4ade34f1 100644 --- a/modules/coinswap/keeper/genesis.go +++ b/modules/coinswap/keeper/genesis.go @@ -19,7 +19,8 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { k.SetStandardDenom(ctx, genState.StandardDenom) k.setSequence(ctx, genState.Sequence) for _, pool := range genState.Pool { - k.setPool(ctx, &pool) + poolCopy := pool // Create a copy of the pool variable + k.setPool(ctx, &poolCopy) } } diff --git a/modules/htlc/client/cli/flags.go b/modules/htlc/client/cli/flags.go index 5073caf2..2f9f99cc 100644 --- a/modules/htlc/client/cli/flags.go +++ b/modules/htlc/client/cli/flags.go @@ -1,4 +1,3 @@ -// nolint package cli import ( @@ -17,9 +16,7 @@ const ( FlagTransfer = "transfer" ) -var ( - FsCreateHTLC = flag.NewFlagSet("", flag.ContinueOnError) -) +var FsCreateHTLC = flag.NewFlagSet("", flag.ContinueOnError) func init() { FsCreateHTLC.String(FlagTo, "", "Bech32 encoding address to receive tokens") diff --git a/modules/htlc/genesis.go b/modules/htlc/genesis.go index 465bb375..5fc41f6a 100644 --- a/modules/htlc/genesis.go +++ b/modules/htlc/genesis.go @@ -18,7 +18,9 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) { } k.SetPreviousBlockTime(ctx, data.PreviousBlockTime) - k.SetParams(ctx, data.Params) + if err := k.SetParams(ctx, data.Params); err != nil { + panic(err.Error()) + } for _, supply := range data.Supplies { k.SetAssetSupply(ctx, supply, supply.CurrentSupply.Denom) } diff --git a/modules/htlc/keeper/asset_test.go b/modules/htlc/keeper/asset_test.go index 25edb08a..ba89cb30 100644 --- a/modules/htlc/keeper/asset_test.go +++ b/modules/htlc/keeper/asset_test.go @@ -686,7 +686,7 @@ func (suite *AssetTestSuite) TestUpdateTimeBasedSupplyLimits() { MaxBlockLock: MaxTimeLock, }}, } - suite.keeper.SetParams(suite.ctx, newParams) + suite.Require().NoError(suite.keeper.SetParams(suite.ctx, newParams), "SetParams should not panic") suite.ctx = suite.ctx.WithBlockTime(suite.ctx.BlockTime().Add(tc.args.duration)) suite.NotPanics( func() { diff --git a/modules/mt/client/cli/tx.go b/modules/mt/client/cli/tx.go index 144c9bfc..e51eeae6 100644 --- a/modules/mt/client/cli/tx.go +++ b/modules/mt/client/cli/tx.go @@ -277,7 +277,7 @@ func GetCmdTransferMT() *cobra.Command { if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil { return err } - + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err diff --git a/modules/mt/types/msgs.go b/modules/mt/types/msgs.go index c4ed75bf..97d5f632 100644 --- a/modules/mt/types/msgs.go +++ b/modules/mt/types/msgs.go @@ -46,7 +46,7 @@ func (msg MsgIssueDenom) Type() string { return TypeMsgIssueDenom } // ValidateBasic Implements Msg. func (msg MsgIssueDenom) ValidateBasic() error { - if len(strings.TrimSpace(msg.Name)) <= 0 { + if len(strings.TrimSpace(msg.Name)) == 0 { return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "name is required") } @@ -201,7 +201,7 @@ func (msg MsgMintMT) Type() string { return TypeMsgMintMT } // ValidateBasic Implements Msg. func (msg MsgMintMT) ValidateBasic() error { - if len(strings.TrimSpace(msg.DenomId)) <= 0 { + if len(strings.TrimSpace(msg.DenomId)) == 0 { return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "denom id is required") } diff --git a/modules/oracle/simulation/operation.go b/modules/oracle/simulation/operation.go index 22a15ac6..a43e02da 100644 --- a/modules/oracle/simulation/operation.go +++ b/modules/oracle/simulation/operation.go @@ -512,7 +512,7 @@ func GenServiceBindingsAndProviders( providers = append(providers, provider.Address.String()) } } - return + return providers } func GenFeed(k keeper.Keeper, r *rand.Rand, ctx sdk.Context) types.Feed { diff --git a/modules/service/keeper/keeper_test.go b/modules/service/keeper/keeper_test.go index 89b64271..da41a950 100644 --- a/modules/service/keeper/keeper_test.go +++ b/modules/service/keeper/keeper_test.go @@ -96,7 +96,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) suite.app = app - suite.NoError(suite.keeper.SetParams(suite.ctx, types.DefaultParams()),"set params failed") + suite.NoError(suite.keeper.SetParams(suite.ctx, types.DefaultParams()), "set params failed") suite.setTestAddrs() } diff --git a/modules/service/types/msgs_test.go b/modules/service/types/msgs_test.go index c6dd953a..504a612e 100644 --- a/modules/service/types/msgs_test.go +++ b/modules/service/types/msgs_test.go @@ -53,7 +53,7 @@ var ( // ------------- - invalidName = "invalid/service/name" + invalidName = "invalid/service/name" invalidRequestContextID = "invalid-request-context-id" ) diff --git a/modules/token/contracts/erc20.go b/modules/token/contracts/erc20.go index b54ba67a..efcaac54 100644 --- a/modules/token/contracts/erc20.go +++ b/modules/token/contracts/erc20.go @@ -1,8 +1,7 @@ package contracts import ( - _ "embed" //embed - + _ "embed" // embed "encoding/json" "mods.irisnet.org/modules/token/types" @@ -12,15 +11,15 @@ const ( // EventSwapToNative is the name of the event emitted when swapping to native EventSwapToNative = "SwapToNative" // MethodMint is the name of the method mint of the ERC20 contract - MethodMint = "mint" + MethodMint = "mint" // MethodBurn is the name of the method burn of the ERC20 contract - MethodBurn = "burn" + MethodBurn = "burn" // MethodBalanceOf is the name of the method balanceOf of the ERC20 contract - MethodBalanceOf = "balanceOf" + MethodBalanceOf = "balanceOf" // MethodInitialize is the name of the method initialize of the ERC20 contract - MethodInitialize = "initialize" + MethodInitialize = "initialize" // MethodUpgradeTo is the name of the method upgradeTo of the Beacon contract - MethodUpgradeTo = "upgradeTo" + MethodUpgradeTo = "upgradeTo" ) var ( diff --git a/modules/token/keeper/token.go b/modules/token/keeper/token.go index b2810e1c..6460554c 100644 --- a/modules/token/keeper/token.go +++ b/modules/token/keeper/token.go @@ -355,4 +355,4 @@ func (k Keeper) assertTokenValid(ctx sdk.Context, token v1.Token) error { ) } return nil -} \ No newline at end of file +} diff --git a/modules/token/types/errors.go b/modules/token/types/errors.go index 76343e34..d294031f 100644 --- a/modules/token/types/errors.go +++ b/modules/token/types/errors.go @@ -31,5 +31,5 @@ var ( ErrUnsupportedKey = errorsmod.Register(ModuleName, 24, "evm not supported public key") ErrInvalidContract = errorsmod.Register(ModuleName, 25, "invalid contract") ErrERC20Disabled = errorsmod.Register(ModuleName, 26, "erc20 swap is disabled") - ErrBeaconNotSet = errorsmod.Register(ModuleName, 27, "beacon contract not set") + ErrBeaconNotSet = errorsmod.Register(ModuleName, 27, "beacon contract not set") ) diff --git a/modules/token/types/types.go b/modules/token/types/types.go index 965f147e..b8cc47aa 100644 --- a/modules/token/types/types.go +++ b/modules/token/types/types.go @@ -4,7 +4,6 @@ import ( "encoding/json" "strconv" - "cosmossdk.io/math" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -76,7 +75,7 @@ func ParseBool(v string) (Bool, error) { // ratio: swap rate // inputScale: the decimal scale of input amount // outputScale: the decimal scale of output amount -func LossLessSwap(input math.Int, ratio sdk.Dec, inputScale, outputScale uint32) (math.Int, math.Int) { +func LossLessSwap(input sdkmath.Int, ratio sdk.Dec, inputScale, outputScale uint32) (sdkmath.Int, sdkmath.Int) { inputDec := sdk.NewDecFromInt(input) scaleFactor := int64(inputScale) - int64(outputScale) var scaleMultipler, scaleReverseMultipler sdk.Dec diff --git a/simapp/network.go b/simapp/network.go index 890aace1..687dd96d 100644 --- a/simapp/network.go +++ b/simapp/network.go @@ -50,7 +50,7 @@ func SetupNetwork(t *testing.T, depInjectOptions DepinjectOptions) Network { } func SetupNetworkWithConfig(t *testing.T, cfg network.Config) Network { - t.Helper() + t.Helper() network, err := network.New(t, t.TempDir(), cfg) require.NoError(t, err, "SetupNetwork failed") @@ -67,7 +67,7 @@ func (n Network) ExecTxCmdWithResult(t *testing.T, cmd *cobra.Command, extraArgs []string, ) *ResponseTx { - t.Helper() + t.Helper() buf, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, extraArgs) require.NoError(t, err, "ExecTestCLICmd failed") @@ -87,7 +87,7 @@ func (n Network) ExecQueryCmd(t *testing.T, extraArgs []string, resp proto.Message, ) { - t.Helper() + t.Helper() buf, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, extraArgs) require.NoError(t, err, "ExecTestCLICmd failed") require.NoError(t, clientCtx.Codec.UnmarshalJSON(buf.Bytes(), resp), buf.String()) @@ -111,7 +111,7 @@ func (n Network) QueryTx(t *testing.T, clientCtx client.Context, txHash string, ) *ResponseTx { - t.Helper() + t.Helper() var ( result *coretypes.ResultTx err error @@ -151,7 +151,7 @@ func (n Network) SendMsgs( t *testing.T, msgs ...sdk.Msg, ) *sdk.TxResponse { - t.Helper() + t.Helper() val := n.Validators[0] client := val.ClientCtx.WithBroadcastMode(flags.BroadcastSync) @@ -185,7 +185,7 @@ func (n Network) SendMsgs( func (n Network) BlockSendMsgs(t *testing.T, msgs ...sdk.Msg, ) *ResponseTx { - t.Helper() + t.Helper() response := n.SendMsgs(t, msgs...) return n.QueryTx(t, n.Validators[0].ClientCtx, response.TxHash) } diff --git a/simapp/state.go b/simapp/state.go index 4cd68d5a..7db0d302 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/rand" "os" "time" @@ -224,7 +223,7 @@ func AppStateFromGenesisFileFn( cdc codec.JSONCodec, genesisFile string, ) (tmtypes.GenesisDoc, []simtypes.Account) { - bytes, err := ioutil.ReadFile(genesisFile) + bytes, err := os.ReadFile(genesisFile) if err != nil { panic(err) } diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index b1bec3f4..27ea7973 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -24,7 +24,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - codectype "github.com/cosmos/cosmos-sdk/codec/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -43,7 +42,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module/testutil" authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/bank/client/cli" bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -780,11 +778,11 @@ func QueryAccountExec( out, err := clitestutil.ExecTestCLICmd(clientCtx, authcli.GetAccountCmd(), args) require.NoError(t, err, "QueryAccountExec failed") - respType := proto.Message(&codectype.Any{}) + respType := proto.Message(&codectypes.Any{}) require.NoError(t, clientCtx.Codec.UnmarshalJSON(out.Bytes(), respType)) var account authtypes.AccountI - err = clientCtx.InterfaceRegistry.UnpackAny(respType.(*codectype.Any), &account) + err = clientCtx.InterfaceRegistry.UnpackAny(respType.(*codectypes.Any), &account) require.NoError(t, err, "UnpackAccount failed") return account @@ -801,7 +799,7 @@ func MsgSendExec( args := []string{from.String(), to.String(), amount.String()} args = append(args, extraArgs...) - return network.ExecTxCmdWithResult(t, clientCtx, cli.NewSendTxCmd(), args) + return network.ExecTxCmdWithResult(t, clientCtx, bankcli.NewSendTxCmd(), args) } func QueryTx(t *testing.T, clientCtx client.Context, txHash string) abci.ResponseDeliverTx {