Skip to content

Commit

Permalink
Merge branch 'main' into dong/TestRemoveZoneAndAssociatedRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Oct 13, 2023
2 parents 7a06517 + 6072f0b commit b69b4d3
Show file tree
Hide file tree
Showing 27 changed files with 222 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions cmd/quicksilverd/bulk_airdrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion test/simulation/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions third-party-chains/osmosis-types/osmoutils/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion utils/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion wasmbinding/query_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions wasmbinding/test/custom_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion wasmbinding/test/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions x/interchainstaking/keeper/ibc_packet_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}

Expand Down Expand Up @@ -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},
}

Expand Down
79 changes: 79 additions & 0 deletions x/interchainstaking/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper_test

import (
"context"
"errors"
"testing"
"time"

Expand All @@ -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"
)

Expand Down Expand Up @@ -664,3 +668,78 @@ 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()

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))
}
Loading

0 comments on commit b69b4d3

Please sign in to comment.