From 8e91043ee790f8a3a9707d362dd7cc3cc604f50b Mon Sep 17 00:00:00 2001 From: DongLieu Date: Fri, 6 Oct 2023 14:58:04 +0700 Subject: [PATCH 01/10] test for HandleCompleteSend --- .../keeper/ibc_packet_handlers_test.go | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index dc037147e..3cf1679fc 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" "time" + "errors" + "context" "github.com/stretchr/testify/require" @@ -2785,3 +2787,75 @@ func (suite *KeeperTestSuite) TestTriggerRedemptionRate() { suite.Equal(prevAllBalancesQueryCnt+1, allBalancesQueryCnt) }) } +func (suite *KeeperTestSuite) TestHandleCompleteSend() { + suite.Run("TestHandleCompleteSend", func() { + suite.SetupTest() + suite.setupTestZones() + + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + ctx = ctx.WithContext(context.WithValue(ctx.Context(), utils.ContextKey("connectionID"), suite.path.EndpointA.ConnectionID)) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + if !found { + suite.Fail("unable to retrieve zone for test") + } + quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel) + complete := time.Now().UTC() + + // trigger handler with testcases + testCases := []struct { + name string + msg banktypes.MsgSend + memo string + expectedError error + }{ + { + name: "unexpected completed send", + msg: banktypes.MsgSend{ + FromAddress: "", + ToAddress: "", + Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), + }, + expectedError: errors.New("unexpected completed send (2) from to (amount: 1000000uatom)"), + }, + { + name: "is withdrawal address", + msg: banktypes.MsgSend{ + FromAddress: zone.WithdrawalAddress.Address, + ToAddress: "", + Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), + }, + expectedError: nil, + }, + { + name: "is to delegation address", + msg: banktypes.MsgSend{ + FromAddress: zone.DepositAddress.Address, + ToAddress: zone.DelegationAddress.Address, + Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), + }, + memo: fmt.Sprintf("unbondSend/%d", complete.Unix()), + expectedError: nil, + }, + { + name: "is from delegation address", // There is a separate test for handles withdraw for user + msg: banktypes.MsgSend{ + FromAddress: zone.DelegationAddress.Address, + ToAddress: "", + Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), + }, + memo: fmt.Sprintf("unbondSend/%d", complete.Unix()), + expectedError: errors.New("no matching withdrawal record found"), + }, + } + + for _, tc := range testCases { + err := quicksilver.InterchainstakingKeeper.HandleCompleteSend(ctx, &tc.msg, tc.memo) + if tc.expectedError != nil { + suite.Equal(tc.expectedError, err) + } else { + suite.NoError(err) + } + } + }) +} From 64167d038665d6f2f845f8dbf575be2953374707 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Sun, 8 Oct 2023 07:20:42 +0400 Subject: [PATCH 02/10] Update x/interchainstaking/keeper/ibc_packet_handlers_test.go --- x/interchainstaking/keeper/ibc_packet_handlers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 3cf1679fc..a0e3aae87 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -2834,7 +2834,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { ToAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), }, - memo: fmt.Sprintf("unbondSend/%d", complete.Unix()), + memo: "", expectedError: nil, }, { From fad039999077faffcaa00f1fe4608ba8271c27d3 Mon Sep 17 00:00:00 2001 From: DongLieu Date: Mon, 9 Oct 2023 11:28:18 +0700 Subject: [PATCH 03/10] fix memo --- x/interchainstaking/keeper/ibc_packet_handlers_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index d690d8c98..037e174b0 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -2,11 +2,10 @@ package keeper_test import ( "context" + "errors" "fmt" "testing" "time" - "errors" - "context" "github.com/stretchr/testify/require" @@ -2802,7 +2801,6 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { suite.Fail("unable to retrieve zone for test") } quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel) - complete := time.Now().UTC() // trigger handler with testcases testCases := []struct { @@ -2836,7 +2834,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { ToAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), }, - memo: "", + memo: "unbondSend/7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", expectedError: nil, }, { @@ -2846,7 +2844,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { ToAddress: "", Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), }, - memo: fmt.Sprintf("unbondSend/%d", complete.Unix()), + memo: "unbondSend/7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", expectedError: errors.New("no matching withdrawal record found"), }, } @@ -2862,7 +2860,6 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { }) } - func (suite *KeeperTestSuite) TestHandleFailedBankSend() { v1 := addressutils.GenerateValAddressForTest().String() v2 := addressutils.GenerateValAddressForTest().String() From 0ff1c9473c1eb2f7912d297344a35e0c8b6c1637 Mon Sep 17 00:00:00 2001 From: DongLieu Date: Wed, 11 Oct 2023 11:32:02 +0700 Subject: [PATCH 04/10] lint --- app/app.go | 2 +- app/export.go | 2 +- app/upgrades.go | 2 +- app/upgrades/types.go | 8 ++++---- cmd/quicksilverd/bulk_airdrop.go | 6 +++--- docs/handler.go | 2 +- test/simulation/helpers.go | 2 +- .../osmosis-types/gamm/pool-models/balancer/pool.go | 2 +- third-party-chains/osmosis-types/osmoutils/parse.go | 10 +++++----- tools/tools.go | 2 +- utils/verify.go | 2 +- wasmbinding/query_plugin_test.go | 2 +- wasmbinding/test/custom_query_test.go | 6 +++--- wasmbinding/test/helpers_test.go | 2 +- x/interchainstaking/keeper/ibc_packet_handlers.go | 4 ++-- x/interchainstaking/keeper/ibc_packet_handlers_test.go | 4 ++-- x/interchainstaking/keeper/redemptions.go | 4 ++-- x/interchainstaking/types/accounts_test.go | 4 ++-- x/interchainstaking/types/params.go | 4 ++-- x/interchainstaking/types/redemptions.go | 2 +- x/mint/simulation/genesis.go | 2 +- x/participationrewards/keeper/callbacks.go | 2 +- x/tokenfactory/keeper/bankactions.go | 2 +- x/tokenfactory/simulation/operations.go | 10 +++++----- x/tokenfactory/types/events.go | 2 +- 25 files changed, 45 insertions(+), 45 deletions(-) diff --git a/app/app.go b/app/app.go index 1d3d88f22..177e11381 100644 --- a/app/app.go +++ b/app/app.go @@ -229,7 +229,7 @@ func NewQuicksilver( go func() { // Unfortunately golangci-lint is so pedantic // so we have to ignore this error explicitly. - _ = app.tpsCounter.start(context.Background()) //nolint:errcheck + _ = app.tpsCounter.start(context.Background()) // nolint:errcheck }() return app diff --git a/app/export.go b/app/export.go index 5b34b6c13..7efd8a3dc 100644 --- a/app/export.go +++ b/app/export.go @@ -79,7 +79,7 @@ func (app *Quicksilver) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAdd // withdraw all validator commission // withdraw all validator commission app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) //nolint + _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) // nolint return false }) // withdraw all delegator rewards diff --git a/app/upgrades.go b/app/upgrades.go index af0849c07..90f71b100 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -39,7 +39,7 @@ func (app *Quicksilver) setUpgradeStoreLoaders() { var storeUpgrades *storetypes.StoreUpgrades - switch upgradeInfo.Name { //nolint:gocritic + switch upgradeInfo.Name { // nolint:gocritic // case v001000UpgradeName: // storeUpgrades = &storetypes.StoreUpgrades{ diff --git a/app/upgrades/types.go b/app/upgrades/types.go index cd2a3dd35..c6917499d 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -57,22 +57,22 @@ type Upgrade struct { StoreUpgrades storetypes.StoreUpgrades } -//nolint:all //function useful for writing network specific upgrade handlers +// nolint:all //function useful for writing network specific upgrade handlers func isTest(ctx sdk.Context) bool { return ctx.ChainID() == TestChainID } -//nolint:all //function useful for writing network specific upgrade handlers +// nolint:all //function useful for writing network specific upgrade handlers func isDevnet(ctx sdk.Context) bool { return ctx.ChainID() == DevnetChainID } -//nolint:all //function useful for writing network specific upgrade handlers +// nolint:all //function useful for writing network specific upgrade handlers func isTestnet(ctx sdk.Context) bool { return ctx.ChainID() == RhyeChainID } -//nolint:all //function useful for writing network specific upgrade handlers +// nolint:all //function useful for writing network specific upgrade handlers func isMainnet(ctx sdk.Context) bool { return ctx.ChainID() == ProductionChainID } diff --git a/cmd/quicksilverd/bulk_airdrop.go b/cmd/quicksilverd/bulk_airdrop.go index 2b9cc8794..1eccf87f0 100644 --- a/cmd/quicksilverd/bulk_airdrop.go +++ b/cmd/quicksilverd/bulk_airdrop.go @@ -190,13 +190,13 @@ func BulkGenesisAirdropCmd(defaultNodeHome string) *cobra.Command { } for _, zd := range airdropGenState.ZoneDrops { - if zd.ChainId == claimRecords[0].ChainId { //nolint:gosec + if zd.ChainId == claimRecords[0].ChainId { // nolint:gosec zoneDrop = zd } } if zoneDrop == nil { - return fmt.Errorf("zoneDrop doesn't exist for chain ID: %s", claimRecords[0].ChainId) //nolint:gosec // TODO: remove + return fmt.Errorf("zoneDrop doesn't exist for chain ID: %s", claimRecords[0].ChainId) // nolint:gosec // TODO: remove } authGenState := authtypes.GetGenesisStateFromAppState(clientCtx.Codec, appState) @@ -211,7 +211,7 @@ func BulkGenesisAirdropCmd(defaultNodeHome string) *cobra.Command { existing := airdropGenState.ClaimRecords for _, i := range existing { - if i.ChainId == claimRecords[0].ChainId { //nolint:gosec // TODO: remove + if i.ChainId == claimRecords[0].ChainId { // nolint:gosec // TODO: remove zoneclaims[i.Address] = true } } diff --git a/docs/handler.go b/docs/handler.go index 74fc376d0..29d8b66e4 100644 --- a/docs/handler.go +++ b/docs/handler.go @@ -22,6 +22,6 @@ func Handler(title, specURL string) http.HandlerFunc { }{ title, specURL, - }) //nolint:errcheck non-critical for docs + }) // nolint:errcheck non-critical for docs } } diff --git a/test/simulation/helpers.go b/test/simulation/helpers.go index f597b8981..68be77301 100644 --- a/test/simulation/helpers.go +++ b/test/simulation/helpers.go @@ -23,7 +23,7 @@ import ( // SetupSimulation creates the config, db (levelDB), temporary directory and logger for // the simulation tests. If `FlagEnabledValue` is false it skips the current test. // Returns error on an invalid db instantiation or temp dir creation. -func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, log.Logger, bool, error) { //nolint:gocritic test util does not need to be simplified +func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, log.Logger, bool, error) { // nolint:gocritic test util does not need to be simplified if !FlagEnabledValue { return simtypes.Config{}, nil, "", nil, true, nil } diff --git a/third-party-chains/osmosis-types/gamm/pool-models/balancer/pool.go b/third-party-chains/osmosis-types/gamm/pool-models/balancer/pool.go index d7fb2f878..78189c55f 100644 --- a/third-party-chains/osmosis-types/gamm/pool-models/balancer/pool.go +++ b/third-party-chains/osmosis-types/gamm/pool-models/balancer/pool.go @@ -17,7 +17,7 @@ import ( "github.com/quicksilver-zone/quicksilver/utils/addressutils" ) -//nolint:deadcode +// nolint:deadcode const ( nonPostiveSharesAmountErrFormat = "shares amount must be positive, was %d" nonPostiveTokenAmountErrFormat = "token amount must be positive, was %d" diff --git a/third-party-chains/osmosis-types/osmoutils/parse.go b/third-party-chains/osmosis-types/osmoutils/parse.go index 590607386..49137ebe1 100644 --- a/third-party-chains/osmosis-types/osmoutils/parse.go +++ b/third-party-chains/osmosis-types/osmoutils/parse.go @@ -17,8 +17,8 @@ type Proposal struct { } var ProposalFlags = []string{ - cli.FlagTitle, //nolint:staticcheck // using this to support govv1beta1 - cli.FlagDescription, //nolint:staticcheck // using this to support govv1beta1 + cli.FlagTitle, // nolint:staticcheck // using this to support govv1beta1 + cli.FlagDescription, // nolint:staticcheck // using this to support govv1beta1 cli.FlagDeposit, } @@ -35,11 +35,11 @@ func (p Proposal) validate() error { func ParseProposalFlags(fs *pflag.FlagSet) (*Proposal, error) { proposal := &Proposal{} - proposalFile, _ := fs.GetString(cli.FlagProposal) //nolint:staticcheck // using this to support govv1beta1 + proposalFile, _ := fs.GetString(cli.FlagProposal) // nolint:staticcheck // using this to support govv1beta1 if proposalFile == "" { - proposal.Title, _ = fs.GetString(cli.FlagTitle) //nolint:staticcheck // using this to support govv1beta1 - proposal.Description, _ = fs.GetString(cli.FlagDescription) //nolint:staticcheck // using this to support govv1beta1 + proposal.Title, _ = fs.GetString(cli.FlagTitle) // nolint:staticcheck // using this to support govv1beta1 + proposal.Description, _ = fs.GetString(cli.FlagDescription) // nolint:staticcheck // using this to support govv1beta1 proposal.Deposit, _ = fs.GetString(cli.FlagDeposit) if err := proposal.validate(); err != nil { return nil, err diff --git a/tools/tools.go b/tools/tools.go index 157bbe7e1..7e8ab4524 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -8,7 +8,7 @@ package tools // https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module // https://github.com/golang/go/issues/25922 -//nolint:all +// nolint:all import ( _ "github.com/client9/misspell/cmd/misspell" _ "github.com/golangci/golangci-lint/cmd/golangci-lint" diff --git a/utils/verify.go b/utils/verify.go index cf74bd063..bb9569aed 100644 --- a/utils/verify.go +++ b/utils/verify.go @@ -68,7 +68,7 @@ func VerifyAdjacent( untrustedVals *types.ValidatorSet, // height=X+1 trustingPeriod time.Duration, now time.Time, - maxClockDrift time.Duration, //nolint:revive + maxClockDrift time.Duration, // nolint:revive ) error { if untrustedHeader.Height != trustedHeader.Height+1 { return errors.New("headers must be adjacent in height") diff --git a/wasmbinding/query_plugin_test.go b/wasmbinding/query_plugin_test.go index d70c6275e..a322564c7 100644 --- a/wasmbinding/query_plugin_test.go +++ b/wasmbinding/query_plugin_test.go @@ -7,7 +7,7 @@ import ( "time" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - "github.com/golang/protobuf/proto" //nolint:staticcheck + "github.com/golang/protobuf/proto" // nolint:staticcheck "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" diff --git a/wasmbinding/test/custom_query_test.go b/wasmbinding/test/custom_query_test.go index 0ece2d3b6..5f2edeb12 100644 --- a/wasmbinding/test/custom_query_test.go +++ b/wasmbinding/test/custom_query_test.go @@ -21,9 +21,9 @@ import ( ) // we must pay this many uosmo for every pool we create. -var poolFee int64 = 1000000000 //nolint:unused +var poolFee int64 = 1000000000 // nolint:unused -var defaultFunds = sdk.NewCoins( //nolint:unused +var defaultFunds = sdk.NewCoins( // nolint:unused sdk.NewInt64Coin("qck", 333000000), sdk.NewInt64Coin("umai", 555000000+2*poolFee), sdk.NewInt64Coin("uck", 999000000), @@ -139,7 +139,7 @@ func instantiateReflectContract(t *testing.T, ctx sdk.Context, quicksilverApp *a return addr } -func fundAccount(t *testing.T, ctx sdk.Context, quicksilver *app.Quicksilver, addr sdk.AccAddress, coins sdk.Coins) { //nolint:unused +func fundAccount(t *testing.T, ctx sdk.Context, quicksilver *app.Quicksilver, addr sdk.AccAddress, coins sdk.Coins) { // nolint:unused t.Helper() err := FundAccount( diff --git a/wasmbinding/test/helpers_test.go b/wasmbinding/test/helpers_test.go index 132b7921d..7db0f4eaf 100644 --- a/wasmbinding/test/helpers_test.go +++ b/wasmbinding/test/helpers_test.go @@ -22,7 +22,7 @@ func CreateTestInput(t *testing.T) (*app.Quicksilver, sdk.Context) { } // we need to make this deterministic (same every test run), as content might affect gas costs. -func keyPubAddr() (key crypto.PrivKey, pub crypto.PubKey, addr sdk.AccAddress) { //nolint:unparam +func keyPubAddr() (key crypto.PrivKey, pub crypto.PubKey, addr sdk.AccAddress) { // nolint:unparam key = ed25519.GenPrivKey() pub = key.PubKey() addr = sdk.AccAddress(pub.Address()) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers.go b/x/interchainstaking/keeper/ibc_packet_handlers.go index 106facb68..0472782b4 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/golang/protobuf/proto" //nolint:staticcheck + "github.com/golang/protobuf/proto" // nolint:staticcheck lsmstakingtypes "github.com/iqlusioninc/liquidity-staking-module/x/staking/types" sdkmath "cosmossdk.io/math" @@ -108,7 +108,7 @@ func (k *Keeper) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.Pack for msgIndex, msg := range msgs { // use msgData for v0.45 and below and msgResponse for v0.46+ - //nolint:staticcheck // SA1019 ignore this! + // nolint:staticcheck // SA1019 ignore this! var msgResponse []byte // check that the msgResponses slice is at least the length of the current index. diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 037e174b0..3e44966a8 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -1579,7 +1579,7 @@ func (suite *KeeperTestSuite) Test_v045Callback() { txMsgData := &sdk.TxMsgData{ // we need to support this older deprecated type - Data: []*sdk.MsgData{{MsgType: "/bob", Data: msgResponseBytes}}, //nolint:staticcheck + Data: []*sdk.MsgData{{MsgType: "/bob", Data: msgResponseBytes}}, // nolint:staticcheck MsgResponses: []*codectypes.Any{}, } @@ -1710,7 +1710,7 @@ func (suite *KeeperTestSuite) Test_v046Callback() { msg, anyResp := test.setStatements(ctx, quicksilver) txMsgData := &sdk.TxMsgData{ - Data: []*sdk.MsgData{}, //nolint:staticcheck + Data: []*sdk.MsgData{}, // nolint:staticcheck MsgResponses: []*codectypes.Any{anyResp}, } diff --git a/x/interchainstaking/keeper/redemptions.go b/x/interchainstaking/keeper/redemptions.go index a03488f2b..d562b0840 100644 --- a/x/interchainstaking/keeper/redemptions.go +++ b/x/interchainstaking/keeper/redemptions.go @@ -61,7 +61,7 @@ func (k *Keeper) processRedemptionForLsm(ctx sdk.Context, zone *types.Zone, send }) } // add unallocated dust. - msgs[0].Amount = msgs[0].Amount.AddAmount(outstanding) //nolint:gosec + msgs[0].Amount = msgs[0].Amount.AddAmount(outstanding) // nolint:gosec sdkMsgs := make([]sdk.Msg, 0) for _, msg := range msgs { sdkMsgs = append(sdkMsgs, sdk.Msg(msg)) @@ -81,7 +81,7 @@ func (k *Keeper) queueRedemption( nativeTokens math.Int, burnAmount sdk.Coin, hash string, -) error { //nolint:unparam // we know that the error is always nil +) error { // nolint:unparam // we know that the error is always nil distribution := make([]*types.Distribution, 0) amount := sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, nativeTokens)) diff --git a/x/interchainstaking/types/accounts_test.go b/x/interchainstaking/types/accounts_test.go index 013aef50d..30828335b 100644 --- a/x/interchainstaking/types/accounts_test.go +++ b/x/interchainstaking/types/accounts_test.go @@ -39,13 +39,13 @@ func TestAccountSetBalanceGood(t *testing.T) { // tests that the balance panics when set to an invalid denomination. func TestAccountSetBalanceBadDenom(t *testing.T) { ica := NewICA() - require.PanicsWithError(t, "invalid denom: _fail", func() { ica.SetBalance(sdk.NewCoins(sdk.NewCoin("_fail", sdk.NewInt(300)))) }) //nolint:errcheck // we're checking for a panic with error here + require.PanicsWithError(t, "invalid denom: _fail", func() { ica.SetBalance(sdk.NewCoins(sdk.NewCoin("_fail", sdk.NewInt(300)))) }) // nolint:errcheck // we're checking for a panic with error here } // tests that the balance panics when set to a negative number. func TestAccountSetBalanceNegativeAmount(t *testing.T) { ica := NewICA() - require.PanicsWithError(t, "negative coin amount: -300", func() { ica.SetBalance(sdk.NewCoins(sdk.NewCoin("uqck", sdk.NewInt(-300)))) }) //nolint:errcheck // we're checking for a panic with error here + require.PanicsWithError(t, "negative coin amount: -300", func() { ica.SetBalance(sdk.NewCoins(sdk.NewCoin("uqck", sdk.NewInt(-300)))) }) // nolint:errcheck // we're checking for a panic with error here } // tests that the balance panics when set to a negative number. diff --git a/x/interchainstaking/types/params.go b/x/interchainstaking/types/params.go index fd84b9391..2d391fa29 100644 --- a/x/interchainstaking/types/params.go +++ b/x/interchainstaking/types/params.go @@ -115,13 +115,13 @@ func (p ParamsV1) ParamSetPairs() paramtypes.ParamSetPairs { } func (p Params) String() string { - out, _ := yaml.Marshal(p) //nolint:errcheck not needed + out, _ := yaml.Marshal(p) // nolint:errcheck not needed return string(out) } // String implements the Stringer interface. func (p ParamsV1) String() string { - out, _ := yaml.Marshal(p) //nolint:errcheck not needed + out, _ := yaml.Marshal(p) // nolint:errcheck not needed return string(out) } diff --git a/x/interchainstaking/types/redemptions.go b/x/interchainstaking/types/redemptions.go index f5b67cea8..5966d8dda 100644 --- a/x/interchainstaking/types/redemptions.go +++ b/x/interchainstaking/types/redemptions.go @@ -52,7 +52,7 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int, // negate all values in underallocated. underAllocated.Negate() // append the two slices - //nolint:gocritic + // nolint:gocritic deltas := append(overAllocated, underAllocated...) deltas.Sort() diff --git a/x/mint/simulation/genesis.go b/x/mint/simulation/genesis.go index 10adb047c..72035972b 100644 --- a/x/mint/simulation/genesis.go +++ b/x/mint/simulation/genesis.go @@ -15,7 +15,7 @@ import ( // Simulation parameter constants. const ( - epochProvisionsKey = "genesis_epoch_provisions" //nolint:gosec // these are not hard coded credentials + epochProvisionsKey = "genesis_epoch_provisions" // nolint:gosec // these are not hard coded credentials reductionFactorKey = "reduction_factor" reductionPeriodInEpochsKey = "reduction_period_in_epochs" distributionProportionsKey = "distribution_proportions" diff --git a/x/participationrewards/keeper/callbacks.go b/x/participationrewards/keeper/callbacks.go index 9447c51b5..f893e8d63 100644 --- a/x/participationrewards/keeper/callbacks.go +++ b/x/participationrewards/keeper/callbacks.go @@ -385,7 +385,7 @@ func SetEpochBlockCallback(ctx sdk.Context, k *Keeper, args []byte, query icqtyp if blockResponse.SdkBlock == nil { // v0.45 and below - //nolint:staticcheck // SA1019 ignore this! + // nolint:staticcheck // SA1019 ignore this! connectionData.LastEpoch = blockResponse.Block.Header.Height } else { // v0.46 and above diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index 3d9464d05..01a0b7307 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -51,7 +51,7 @@ func (k Keeper) burnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom string) erro return k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(amount)) } -func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr, toAddr string) error { //nolint:unused +func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr, toAddr string) error { // nolint:unused // verify that denom is an x/tokenfactory denom _, _, err := types.DeconstructDenom(amount.Denom) diff --git a/x/tokenfactory/simulation/operations.go b/x/tokenfactory/simulation/operations.go index 62303d8a2..47056e515 100644 --- a/x/tokenfactory/simulation/operations.go +++ b/x/tokenfactory/simulation/operations.go @@ -18,11 +18,11 @@ import ( ) const ( - OpWeightMsgCreateDenom = "op_weight_msg_create_denom" //nolint:gosec // not credentials - OpWeightMsgMint = "op_weight_msg_mint" //nolint:gosec // not credentials - OpWeightMsgBurn = "op_weight_msg_burn" //nolint:gosec // not credentials - OpWeightMsgChangeAdmin = "op_weight_msg_change_admin" //nolint:gosec // not credentials - OpWeightMsgSetDenomMetadata = "op_weight_msg_set_denom_metadata" //nolint:gosec // not credentials + OpWeightMsgCreateDenom = "op_weight_msg_create_denom" // nolint:gosec // not credentials + OpWeightMsgMint = "op_weight_msg_mint" // nolint:gosec // not credentials + OpWeightMsgBurn = "op_weight_msg_burn" // nolint:gosec // not credentials + OpWeightMsgChangeAdmin = "op_weight_msg_change_admin" // nolint:gosec // not credentials + OpWeightMsgSetDenomMetadata = "op_weight_msg_set_denom_metadata" // nolint:gosec // not credentials DefaultWeightMsgCreateDenom int = 50 DefaultWeightMsgMint int = 10 DefaultWeightMsgBurn int = 10 diff --git a/x/tokenfactory/types/events.go b/x/tokenfactory/types/events.go index 8fc63f75f..c69c645e4 100644 --- a/x/tokenfactory/types/events.go +++ b/x/tokenfactory/types/events.go @@ -2,7 +2,7 @@ package types // event types -//nolint:gosec +// nolint:gosec const ( AttributeAmount = "amount" AttributeCreator = "creator" From 52c5278969f563fb11e08d81c6a65e7f9d67454f Mon Sep 17 00:00:00 2001 From: DongLieu Date: Tue, 24 Oct 2023 12:18:59 +0700 Subject: [PATCH 05/10] lint --- .../keeper/ibc_packet_handlers_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 7b095c6c7..1f5070c12 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -2880,13 +2880,13 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { // trigger handler with testcases testCases := []struct { name string - msg banktypes.MsgSend + msg sdk.Msg memo string expectedError error }{ { name: "unexpected completed send", - msg: banktypes.MsgSend{ + msg: &banktypes.MsgSend{ FromAddress: "", ToAddress: "", Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), @@ -2895,7 +2895,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { }, { name: "is withdrawal address", - msg: banktypes.MsgSend{ + msg: &banktypes.MsgSend{ FromAddress: zone.WithdrawalAddress.Address, ToAddress: "", Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), @@ -2904,7 +2904,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { }, { name: "is to delegation address", - msg: banktypes.MsgSend{ + msg: &banktypes.MsgSend{ FromAddress: zone.DepositAddress.Address, ToAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), @@ -2914,7 +2914,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { }, { name: "is from delegation address", // There is a separate test for handles withdraw for user - msg: banktypes.MsgSend{ + msg: &banktypes.MsgSend{ FromAddress: zone.DelegationAddress.Address, ToAddress: "", Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), @@ -2925,7 +2925,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { } for _, tc := range testCases { - err := quicksilver.InterchainstakingKeeper.HandleCompleteSend(ctx, &tc.msg, tc.memo) + err := quicksilver.InterchainstakingKeeper.HandleCompleteSend(ctx, tc.msg, tc.memo) if tc.expectedError != nil { suite.Equal(tc.expectedError, err) } else { From 0f5d8cd988521616cef6f7f25e15699a19911766 Mon Sep 17 00:00:00 2001 From: DongLieu Date: Wed, 25 Oct 2023 14:59:22 +0700 Subject: [PATCH 06/10] refacter --- .../keeper/ibc_packet_handlers_test.go | 103 ++++++++++-------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 1f5070c12..e9f9a4bb5 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -2864,75 +2864,84 @@ func (suite *KeeperTestSuite) TestGetValidatorForToken() { } func (suite *KeeperTestSuite) TestHandleCompleteSend() { - suite.Run("TestHandleCompleteSend", func() { - suite.SetupTest() - suite.setupTestZones() - - quicksilver := suite.GetQuicksilverApp(suite.chainA) - ctx := suite.chainA.GetContext() - ctx = ctx.WithContext(context.WithValue(ctx.Context(), utils.ContextKey("connectionID"), suite.path.EndpointA.ConnectionID)) - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) - if !found { - suite.Fail("unable to retrieve zone for test") - } - quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel) - - // trigger handler with testcases - testCases := []struct { - name string - msg sdk.Msg - memo string - expectedError error - }{ - { - name: "unexpected completed send", - msg: &banktypes.MsgSend{ + testCases := []struct { + name string + message func(zone *icstypes.Zone) sdk.Msg + memo string + expectedError error + }{ + { + name: "unexpected completed send", + message: func(zone *icstypes.Zone) sdk.Msg { + return &banktypes.MsgSend{ FromAddress: "", ToAddress: "", Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), - }, - expectedError: errors.New("unexpected completed send (2) from to (amount: 1000000uatom)"), + } }, - { - name: "is withdrawal address", - msg: &banktypes.MsgSend{ + expectedError: errors.New("unexpected completed send (2) from to (amount: 1000000uatom)"), + }, + { + name: "is withdrawal address", + message: func(zone *icstypes.Zone) sdk.Msg { + return &banktypes.MsgSend{ FromAddress: zone.WithdrawalAddress.Address, ToAddress: "", Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), - }, - expectedError: nil, + } }, - { - name: "is to delegation address", - msg: &banktypes.MsgSend{ + expectedError: nil, + }, + { + name: "is to delegation address", + message: func(zone *icstypes.Zone) sdk.Msg { + return &banktypes.MsgSend{ FromAddress: zone.DepositAddress.Address, ToAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), - }, - memo: "unbondSend/7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", - expectedError: nil, + } }, - { - name: "is from delegation address", // There is a separate test for handles withdraw for user - msg: &banktypes.MsgSend{ + memo: "unbondSend/7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", + expectedError: nil, + }, + { + name: "is from delegation address", // There is a separate test for handles withdraw for user + message: func(zone *icstypes.Zone) sdk.Msg { + return &banktypes.MsgSend{ FromAddress: zone.DelegationAddress.Address, ToAddress: "", Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))), - }, - memo: "unbondSend/7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", - expectedError: errors.New("no matching withdrawal record found"), + } }, - } + memo: "unbondSend/7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", + expectedError: errors.New("no matching withdrawal record found"), + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + suite.setupTestZones() - for _, tc := range testCases { - err := quicksilver.InterchainstakingKeeper.HandleCompleteSend(ctx, tc.msg, tc.memo) + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + ctx = ctx.WithContext(context.WithValue(ctx.Context(), utils.ContextKey("connectionID"), suite.path.EndpointA.ConnectionID)) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + if !found { + suite.Fail("unable to retrieve zone for test") + } + quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel) + + msg := tc.message(&zone) + + err := quicksilver.InterchainstakingKeeper.HandleCompleteSend(ctx, msg, tc.memo) if tc.expectedError != nil { suite.Equal(tc.expectedError, err) } else { suite.NoError(err) } - } - }) + }) + } } func (suite *KeeperTestSuite) TestHandleFailedBankSend() { From c228784f5fd68b59dd9d8e485626431d0b8364f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=C3=B4ng=20Li=E1=BB=81u?= <93205232+DongLieu@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:36:00 +0700 Subject: [PATCH 07/10] Update x/interchainstaking/keeper/ibc_packet_handlers_test.go Co-authored-by: Nguyen Thanh Nhan --- x/interchainstaking/keeper/ibc_packet_handlers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 94b55e687..c5502f95f 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -2883,7 +2883,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { expectedError: errors.New("unexpected completed send (2) from to (amount: 1000000uatom)"), }, { - name: "is withdrawal address", + name: "From WithdrawalAddress", message: func(zone *icstypes.Zone) sdk.Msg { return &banktypes.MsgSend{ FromAddress: zone.WithdrawalAddress.Address, From aa1da97b5fd4845ea9f2f4a45dda52d1c1bb72e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=C3=B4ng=20Li=E1=BB=81u?= <93205232+DongLieu@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:36:11 +0700 Subject: [PATCH 08/10] Update x/interchainstaking/keeper/ibc_packet_handlers_test.go Co-authored-by: Nguyen Thanh Nhan --- x/interchainstaking/keeper/ibc_packet_handlers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index c5502f95f..32a0feb78 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -2894,7 +2894,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { expectedError: nil, }, { - name: "is to delegation address", + name: "From DepositAddress to DelegateAddress", message: func(zone *icstypes.Zone) sdk.Msg { return &banktypes.MsgSend{ FromAddress: zone.DepositAddress.Address, From a759da45988516cf943551fa1500039d1913f001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=C3=B4ng=20Li=E1=BB=81u?= <93205232+DongLieu@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:36:17 +0700 Subject: [PATCH 09/10] Update x/interchainstaking/keeper/ibc_packet_handlers_test.go Co-authored-by: Nguyen Thanh Nhan --- x/interchainstaking/keeper/ibc_packet_handlers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 32a0feb78..aa1c6a51c 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -2906,7 +2906,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { expectedError: nil, }, { - name: "is from delegation address", // There is a separate test for handles withdraw for user + name: "From DepositAddress" message: func(zone *icstypes.Zone) sdk.Msg { return &banktypes.MsgSend{ FromAddress: zone.DelegationAddress.Address, From 2405b1cf3ea4baa7a6e6e76ee64eb4ed9195ac74 Mon Sep 17 00:00:00 2001 From: DongLieu Date: Fri, 27 Oct 2023 10:39:48 +0700 Subject: [PATCH 10/10] lint --- x/interchainstaking/keeper/ibc_packet_handlers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index aa1c6a51c..c1912882a 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -2906,7 +2906,7 @@ func (suite *KeeperTestSuite) TestHandleCompleteSend() { expectedError: nil, }, { - name: "From DepositAddress" + name: "From DepositAddress", message: func(zone *icstypes.Zone) sdk.Msg { return &banktypes.MsgSend{ FromAddress: zone.DelegationAddress.Address,