From 3ac2700abe04831b348afa543a78ee77c4b0b673 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: Wed, 11 Oct 2023 14:47:20 +0700 Subject: [PATCH 1/3] Test for GCCompletedUnbondings (#687) * Test for GCCompletedUnbondings * lint --------- Co-authored-by: Nguyen Thanh Nhan --- 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 +- .../gamm/pool-models/balancer/pool.go | 2 +- .../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 +- .../keeper/ibc_packet_handlers.go | 4 +- .../keeper/ibc_packet_handlers_test.go | 4 +- .../keeper/redelegation_record_test.go | 98 +++++++++++++++++++ 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 +- 26 files changed, 143 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 60bf35958..dae54b28b 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -1578,7 +1578,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{}, } @@ -1709,7 +1709,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/redelegation_record_test.go b/x/interchainstaking/keeper/redelegation_record_test.go index 7a5bfee4a..a4604df6b 100644 --- a/x/interchainstaking/keeper/redelegation_record_test.go +++ b/x/interchainstaking/keeper/redelegation_record_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/quicksilver-zone/quicksilver/utils/addressutils" "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types" ) @@ -108,3 +110,99 @@ func (suite *KeeperTestSuite) TestGCCompletedRedelegations() { _, found := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorThree, 1) suite.False(found) } + +func (suite *KeeperTestSuite) TestGCCompletedUnbondings() { + suite.SetupTest() + suite.setupTestZones() + + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + if !found { + suite.Fail("unable to retrieve zone for test") + } + records := quicksilver.InterchainstakingKeeper.AllWithdrawalRecords(ctx) + suite.Equal(0, len(records)) + + vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) + currentTime := ctx.BlockTime() + + record1 := types.WithdrawalRecord{ + ChainId: suite.chainB.ChainID, + Delegator: zone.DelegationAddress.Address, + Distribution: []*types.Distribution{ + { + Valoper: vals[0].ValoperAddress, + Amount: 500, + }, + { + Valoper: vals[1].ValoperAddress, + Amount: 500, + }, + }, + Recipient: user1.String(), + Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), + BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1000)), + Txhash: "1613D2E8FBF7C7294A4D2247B55EE89FB22FC68C62D61050B944F1191DF092BD", + Status: types.WithdrawStatusCompleted, + CompletionTime: currentTime.Add(-25 * time.Hour).UTC(), + } + quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record1) + + record2 := types.WithdrawalRecord{ + ChainId: suite.chainB.ChainID, + Delegator: zone.DelegationAddress.Address, + Distribution: []*types.Distribution{ + { + Valoper: vals[0].ValoperAddress, + Amount: 500, + }, + { + Valoper: vals[1].ValoperAddress, + Amount: 500, + }, + }, + Recipient: user2.String(), + Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), + BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1000)), + Txhash: "91DF093BD1613D2E8FBF7C7294A4D2247B55EE89FB22FC68C62D61050B944F11", + Status: types.WithdrawStatusUnbond, + CompletionTime: currentTime.Add(25 * time.Hour).UTC(), + } + quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record2) + + record3 := types.WithdrawalRecord{ + ChainId: suite.chainB.ChainID, + Delegator: zone.DelegationAddress.Address, + Distribution: []*types.Distribution{ + { + Valoper: vals[0].ValoperAddress, + Amount: 500, + }, + { + Valoper: vals[1].ValoperAddress, + Amount: 500, + }, + }, + Recipient: user2.String(), + Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), + BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1000)), + Txhash: "2247B55EE89FB22FC68C62D61050B944F1191DF093BD1613D2E8FBF7C7294A4D", + Status: types.WithdrawStatusUnbond, + CompletionTime: time.Time{}, + } + quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record3) + + records = quicksilver.InterchainstakingKeeper.AllWithdrawalRecords(ctx) + suite.Equal(3, len(records)) + + err := quicksilver.InterchainstakingKeeper.GCCompletedUnbondings(ctx, &zone) + suite.NoError(err) + + records = quicksilver.InterchainstakingKeeper.AllWithdrawalRecords(ctx) + suite.Equal(2, len(records)) + + _, found = quicksilver.InterchainstakingKeeper.GetWithdrawalRecord(ctx, record1.ChainId, record1.Txhash, record1.Status) + suite.False(found) +} 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 eccff60e3981f50fc340ba32a467854286dba1e0 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: Wed, 11 Oct 2023 16:35:59 +0700 Subject: [PATCH 2/3] Test for IteratePortConnection (#686) * Test for IteratePortConnection * lint --------- Co-authored-by: Nguyen Thanh Nhan --- x/interchainstaking/keeper/keeper_test.go | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/x/interchainstaking/keeper/keeper_test.go b/x/interchainstaking/keeper/keeper_test.go index 97d7dada8..5361e2a71 100644 --- a/x/interchainstaking/keeper/keeper_test.go +++ b/x/interchainstaking/keeper/keeper_test.go @@ -664,3 +664,30 @@ func (suite *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { suite.Equal(sdk.NewDecWithPrec(676666666666666667, 18), zone.RedemptionRate) } + +func (suite *KeeperTestSuite) TestIteratePortConnection() { + suite.SetupTest() + suite.setupTestZones() + + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + icsKeeper := quicksilver.InterchainstakingKeeper + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.True(found) + // After setup, there are 4 port connections available + pcs := icsKeeper.AllPortConnections(ctx) + suite.Equal(4, len(pcs)) + // set add 4 port connections + icsKeeper.SetConnectionForPort(ctx, "connection-1", zone.ChainId+"."+"deposit") + icsKeeper.SetConnectionForPort(ctx, "connection-2", zone.ChainId+"."+"withdrawal") + icsKeeper.SetConnectionForPort(ctx, "connection-3", zone.ChainId+"."+"performance") + icsKeeper.SetConnectionForPort(ctx, "connection-4", zone.ChainId+"."+"delegate") + + // iterate + var portConnection []icstypes.PortConnectionTuple + icsKeeper.IteratePortConnections(ctx, func(pc icstypes.PortConnectionTuple) (stop bool) { + portConnection = append(portConnection, pc) + return false + }) + suite.Equal(8, len(portConnection)) +} From 6072f0bb1d92172c7e3b5ac1e8d9178ae3b7f262 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: Wed, 11 Oct 2023 19:25:22 +0700 Subject: [PATCH 3/3] Test for GetChainIDFromContext (#685) * Test for GetChainIDFromContext * lint --- x/interchainstaking/keeper/keeper_test.go | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/x/interchainstaking/keeper/keeper_test.go b/x/interchainstaking/keeper/keeper_test.go index 5361e2a71..1ad9a87bb 100644 --- a/x/interchainstaking/keeper/keeper_test.go +++ b/x/interchainstaking/keeper/keeper_test.go @@ -1,6 +1,8 @@ package keeper_test import ( + "context" + "errors" "testing" "time" @@ -20,9 +22,11 @@ import ( ibctesting "github.com/cosmos/ibc-go/v5/testing" "github.com/quicksilver-zone/quicksilver/app" + "github.com/quicksilver-zone/quicksilver/utils" "github.com/quicksilver-zone/quicksilver/utils/addressutils" "github.com/quicksilver-zone/quicksilver/utils/randomutils" ics "github.com/quicksilver-zone/quicksilver/x/interchainstaking" + interchainstakingkeeper "github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper" icstypes "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types" ) @@ -665,6 +669,54 @@ func (suite *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { suite.Equal(sdk.NewDecWithPrec(676666666666666667, 18), zone.RedemptionRate) } +func (suite *KeeperTestSuite) TestGetChainIDFromContext() { + testCase := []struct { + name string + setup func() (*interchainstakingkeeper.Keeper, sdk.Context) + wantErr bool + expectedErr error + expectedChainID string + }{ + { + name: "connectionID not in context", + setup: func() (*interchainstakingkeeper.Keeper, sdk.Context) { + suite.SetupTest() + suite.setupTestZones() + return suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper, suite.chainA.GetContext() + }, + wantErr: true, + expectedErr: errors.New("connectionID not in context"), + }, + { + name: "get chainID success", + setup: func() (*interchainstakingkeeper.Keeper, sdk.Context) { + suite.SetupTest() + suite.setupTestZones() + ctx := suite.chainA.GetContext() + + ctx = ctx.WithContext(context.WithValue(ctx.Context(), utils.ContextKey("connectionID"), suite.path.EndpointA.ConnectionID)) + return suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper, ctx + }, + wantErr: false, + expectedErr: nil, + expectedChainID: "testchain2", + }, + } + for _, tc := range testCase { + suite.Run(tc.name, func() { + keeper, ctx := tc.setup() + + chainID, err := keeper.GetChainIDFromContext(ctx) + if tc.wantErr { + suite.Equal(tc.expectedErr, err) + return + } + suite.NoError(err) + suite.Equal(tc.expectedChainID, chainID) + }) + } +} + func (suite *KeeperTestSuite) TestIteratePortConnection() { suite.SetupTest() suite.setupTestZones()