diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b4086cffb..e34dab5c1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,5 +23,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: "v1.52.2" + version: "v1.55.0" args: --timeout=5m diff --git a/Makefile b/Makefile index 47043a23f..4ef49b654 100644 --- a/Makefile +++ b/Makefile @@ -238,6 +238,12 @@ rm-testcache: ############################################################################### ### Linting ### ############################################################################### +golangci_version=v1.55.0 + +lint-install: + @echo "--> Installing golangci-lint $(golangci_version)" + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) + lint: golangci-lint run diff --git a/ante/ante.go b/ante/ante.go index 7d0d4f78d..44cb79991 100644 --- a/ante/ante.go +++ b/ante/ante.go @@ -29,7 +29,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } - var sigGasConsumer = opts.SigGasConsumer + sigGasConsumer := opts.SigGasConsumer if sigGasConsumer == nil { sigGasConsumer = ante.DefaultSigVerificationGasConsumer } diff --git a/app/app.go b/app/app.go index ec37f0346..0b4a6322c 100644 --- a/app/app.go +++ b/app/app.go @@ -466,8 +466,8 @@ func NewpStakeApp( app.BankKeeper, scopedTransferKeeper, ) - //transferModule := transfer.NewAppModule(app.TransferKeeper) - //transferIBCModule := transfer.NewIBCModule(app.TransferKeeper) + // transferModule := transfer.NewAppModule(app.TransferKeeper) + // transferIBCModule := transfer.NewIBCModule(app.TransferKeeper) app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( appCodec, keys[icacontrollertypes.StoreKey], @@ -487,7 +487,7 @@ func NewpStakeApp( app.MsgServiceRouter(), ) - //icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper) + // icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper) app.InterchainQueryKeeper = interchainquerykeeper.NewKeeper(appCodec, keys[interchainquerytypes.StoreKey], app.IBCKeeper) interchainQueryModule := interchainquery.NewAppModule(appCodec, app.InterchainQueryKeeper) @@ -623,7 +623,7 @@ func NewpStakeApp( transfer.NewAppModule(app.TransferKeeper), ibcfee.NewAppModule(app.IBCFeeKeeper), ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), - //ibchooker.NewAppModule(), + // ibchooker.NewAppModule(), interchainQueryModule, liquidstakeibc.NewAppModule(app.LiquidStakeIBCKeeper), liquidstake.NewAppModule(app.LiquidStakeKeeper), @@ -659,7 +659,7 @@ func NewpStakeApp( feegrant.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, - ibchookertypes.ModuleName, //Noop + ibchookertypes.ModuleName, // Noop interchainquerytypes.ModuleName, liquidstakeibctypes.ModuleName, liquidstaketypes.ModuleName, @@ -688,7 +688,7 @@ func NewpStakeApp( paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - ibchookertypes.ModuleName, //Noop + ibchookertypes.ModuleName, // Noop interchainquerytypes.ModuleName, liquidstakeibctypes.ModuleName, liquidstaketypes.ModuleName, @@ -724,7 +724,7 @@ func NewpStakeApp( paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - ibchookertypes.ModuleName, //Noop + ibchookertypes.ModuleName, // Noop interchainquerytypes.ModuleName, liquidstakeibctypes.ModuleName, liquidstaketypes.ModuleName, @@ -849,6 +849,7 @@ func (app *PstakeApp) ModuleAccountAddrs() map[string]bool { return modAccAddrs } + func (app *PstakeApp) SendCoinBlockedAddrs() map[string]bool { modAccAddrs := make(map[string]bool) for acc := range maccPerms { @@ -1018,7 +1019,6 @@ func (app *PstakeApp) RegisterUpgradeHandler() { app.UpgradeKeeper.SetUpgradeHandler( UpgradeName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // stuck unbonding epoch numbers RemovableUnbondings := map[string]map[int64]any{"cosmoshub-4": {312: nil}, "osmosis-1": {429: nil, 432: nil}} diff --git a/app/helpers/test_helpers.go b/app/helpers/test_helpers.go index 4093be41e..43427eedf 100644 --- a/app/helpers/test_helpers.go +++ b/app/helpers/test_helpers.go @@ -263,7 +263,7 @@ func NewConfig(dbm *dbm.MemDB) network.Config { // NewAppConstructor returns a new network AppConstructor. // -//nolint:interfacer +//nolint:interfacer // only used for tests func NewAppConstructor(encodingCfg appparams.EncodingConfig, db *dbm.MemDB) network.AppConstructor { return func(val network.ValidatorI) types.Application { return app.NewpStakeApp( diff --git a/cmd/pstaked/cmd/root.go b/cmd/pstaked/cmd/root.go index 37191677e..cb571ba5f 100644 --- a/cmd/pstaked/cmd/root.go +++ b/cmd/pstaked/cmd/root.go @@ -90,6 +90,7 @@ func initTendermintConfig() *tmcfg.Config { return cfg } + func initAppConfig() (string, interface{}) { srvCfg := serverconfig.DefaultConfig() srvCfg.StateSync.SnapshotInterval = 1000 @@ -245,5 +246,4 @@ func (ac appCreator) appExport( } return pStakeApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) - } diff --git a/cmd/pstaked/cmd/root_test.go b/cmd/pstaked/cmd/root_test.go index ffb617e71..98ebec4a1 100644 --- a/cmd/pstaked/cmd/root_test.go +++ b/cmd/pstaked/cmd/root_test.go @@ -11,7 +11,6 @@ import ( ) func TestRootCmdConfig(t *testing.T) { - rootCmd, _ := cmd.NewRootCmd() rootCmd.SetArgs([]string{ "config", // Test the config cmd diff --git a/cmd/pstaked/cmd/testnet.go b/cmd/pstaked/cmd/testnet.go index 12bff6a6f..b20af550c 100644 --- a/cmd/pstaked/cmd/testnet.go +++ b/cmd/pstaked/cmd/testnet.go @@ -107,7 +107,7 @@ Example: return cmd } -const nodeDirPerm = 0755 +const nodeDirPerm = 0o755 // Initialize the testnet func InitTestnet( @@ -126,7 +126,6 @@ func InitTestnet( algoStr string, numValidators int, ) error { - if chainID == "" { chainID = "chain-" + tmrand.NewRand().Str(6) } @@ -288,7 +287,6 @@ func initGenFiles( genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string, numValidators int, ) error { - appGenState := mbm.DefaultGenesis(clientCtx.Codec) // set the accounts in the genesis state @@ -337,7 +335,6 @@ func collectGenFiles( nodeIDs []string, valPubKeys []cryptotypes.PubKey, numValidators int, outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator, ) error { - var appState json.RawMessage genTime := tmtime.Now() @@ -406,12 +403,12 @@ func writeFile(name string, dir string, contents []byte) error { writePath := filepath.Clean(dir) file := filepath.Join(writePath, name) - err := tmos.EnsureDir(writePath, 0755) + err := tmos.EnsureDir(writePath, 0o755) if err != nil { return err } - err = tmos.WriteFile(file, contents, 0644) + err = tmos.WriteFile(file, contents, 0o644) if err != nil { return err } diff --git a/x/liquidstake/keeper/keeper_test.go b/x/liquidstake/keeper/keeper_test.go index a14483cc1..2666a19a3 100644 --- a/x/liquidstake/keeper/keeper_test.go +++ b/x/liquidstake/keeper/keeper_test.go @@ -28,9 +28,7 @@ import ( "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types" ) -var ( - BlockTime = 10 * time.Second -) +var BlockTime = 10 * time.Second type KeeperTestSuite struct { suite.Suite @@ -246,7 +244,6 @@ func (s *KeeperTestSuite) RequireNetAmountStateZero() { s.Require().EqualValues(nas.TotalRemainingRewards, sdk.ZeroDec()) s.Require().EqualValues(nas.TotalUnbondingBalance, sdk.ZeroDec()) s.Require().EqualValues(nas.ProxyAccBalance, sdk.ZeroInt()) - } // advance block time and height for complete redelegations and unbondings @@ -396,8 +393,8 @@ func (s *KeeperTestSuite) doubleSign(valOper sdk.ValAddress, consAddr sdk.ConsAd // make evidence evidence := &evidencetypes.Equivocation{ - //Height: 0, - //Time: time.Unix(0, 0), + // Height: 0, + // Time: time.Unix(0, 0), Height: s.ctx.BlockHeight(), Time: s.ctx.BlockTime(), Power: s.app.StakingKeeper.TokensToConsensusPower(s.ctx, tokens), @@ -407,10 +404,10 @@ func (s *KeeperTestSuite) doubleSign(valOper sdk.ValAddress, consAddr sdk.ConsAd // Double sign s.app.EvidenceKeeper.HandleEquivocationEvidence(s.ctx, evidence) // HandleEquivocationEvidence call below functions - //s.app.SlashingKeeper.Slash() - //s.app.SlashingKeeper.Jail(s.ctx, consAddr) - //s.app.SlashingKeeper.JailUntil(s.ctx, consAddr, evidencetypes.DoubleSignJailEndTime) - //s.app.SlashingKeeper.Tombstone(s.ctx, consAddr) + // s.app.SlashingKeeper.Slash() + // s.app.SlashingKeeper.Jail(s.ctx, consAddr) + // s.app.SlashingKeeper.JailUntil(s.ctx, consAddr, evidencetypes.DoubleSignJailEndTime) + // s.app.SlashingKeeper.Tombstone(s.ctx, consAddr) // should be jailed and tombstoned s.Require().True(s.app.StakingKeeper.Validator(s.ctx, liquidValidator.GetOperator()).IsJailed()) diff --git a/x/liquidstake/keeper/liquidstake.go b/x/liquidstake/keeper/liquidstake.go index b32c9146c..62fa0f84b 100644 --- a/x/liquidstake/keeper/liquidstake.go +++ b/x/liquidstake/keeper/liquidstake.go @@ -49,7 +49,8 @@ func (k Keeper) GetNetAmountState(ctx sdk.Context) (nas types.NetAmountState) { // LiquidStake mints stkXPRT worth of staking coin value according to NetAmount and performs LiquidDelegate. func (k Keeper) LiquidStake( - ctx sdk.Context, proxyAcc, liquidStaker sdk.AccAddress, stakingCoin sdk.Coin) (newShares math.LegacyDec, stkXPRTMintAmount math.Int, err error) { + ctx sdk.Context, proxyAcc, liquidStaker sdk.AccAddress, stakingCoin sdk.Coin, +) (newShares math.LegacyDec, stkXPRTMintAmount math.Int, err error) { params := k.GetParams(ctx) // check minimum liquid stake amount @@ -343,7 +344,6 @@ func (k Keeper) LiquidDelegate(ctx sdk.Context, proxyAcc sdk.AccAddress, activeV func (k Keeper) LiquidUnstake( ctx sdk.Context, proxyAcc, liquidStaker sdk.AccAddress, unstakingStkXPRT sdk.Coin, ) (time.Time, math.Int, []stakingtypes.UnbondingDelegation, math.Int, error) { - // check bond denomination params := k.GetParams(ctx) liquidBondDenom := k.LiquidBondDenom(ctx) diff --git a/x/liquidstake/keeper/rebalancing_test.go b/x/liquidstake/keeper/rebalancing_test.go index 244281c2a..081d54543 100644 --- a/x/liquidstake/keeper/rebalancing_test.go +++ b/x/liquidstake/keeper/rebalancing_test.go @@ -81,7 +81,7 @@ func (s *KeeperTestSuite) TestRebalancingCase1() { s.Require().EqualValues(stakingAmt, totalLiquidTokens) s.printRedelegationsLiquidTokens() - //reds := s.app.StakingKeeper.GetRedelegations(s.ctx, types.LiquidStakeProxyAcc, 20) + // reds := s.app.StakingKeeper.GetRedelegations(s.ctx, types.LiquidStakeProxyAcc, 20) s.Require().Len(reds, 3) testhelpers.PP("before complete") @@ -278,7 +278,8 @@ func (s *KeeperTestSuite) TestRebalancingConsecutiveCase() { _, valOpers, _ := s.CreateValidators([]int64{ 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, - 1000000, 1000000, 1000000, 1000000, 1000000}) + 1000000, 1000000, 1000000, 1000000, 1000000, + }) s.ctx = s.ctx.WithBlockHeight(100).WithBlockTime(testhelpers.ParseTime("2022-03-01T00:00:00Z")) params := s.keeper.GetParams(s.ctx) params.UnstakeFeeRate = sdk.ZeroDec() diff --git a/x/liquidstake/module.go b/x/liquidstake/module.go index eb15f54a8..df1082fcc 100644 --- a/x/liquidstake/module.go +++ b/x/liquidstake/module.go @@ -26,8 +26,7 @@ var ( ) // AppModuleBasic defines the basic application module used by the liquidstake module. -type AppModuleBasic struct { -} +type AppModuleBasic struct{} // Name returns the liquidstake module's name. func (AppModuleBasic) Name() string { diff --git a/x/liquidstake/types/liquidstake.go b/x/liquidstake/types/liquidstake.go index 7b27c6704..373d7eae9 100644 --- a/x/liquidstake/types/liquidstake.go +++ b/x/liquidstake/types/liquidstake.go @@ -96,8 +96,10 @@ func ActiveCondition(validator stakingtypes.Validator, whitelisted bool, tombsto } // LiquidValidators is a collection of LiquidValidator -type LiquidValidators []LiquidValidator -type ActiveLiquidValidators LiquidValidators +type ( + LiquidValidators []LiquidValidator + ActiveLiquidValidators LiquidValidators +) // MinMaxGap Return the list of LiquidValidator with the maximum gap and minimum gap from the target weight of LiquidValidators, respectively. func (vs LiquidValidators) MinMaxGap(targetMap, liquidTokenMap map[string]math.Int) (minGapVal LiquidValidator, maxGapVal LiquidValidator, amountNeeded math.Int, lastRedelegation bool) { diff --git a/x/liquidstake/types/liquidstake_test.go b/x/liquidstake/types/liquidstake_test.go index e242c70a0..00a01ac8f 100644 --- a/x/liquidstake/types/liquidstake_test.go +++ b/x/liquidstake/types/liquidstake_test.go @@ -20,26 +20,24 @@ import ( "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types" ) -var ( - whitelistedValidators = []types.WhitelistedValidator{ - { - ValidatorAddress: "cosmosvaloper10e4vsut6suau8tk9m6dnrm0slgd6npe3jx5xpv", - TargetWeight: math.NewInt(10), - }, - { - ValidatorAddress: "cosmosvaloper18hfzxheyknesfgcrttr5dg50ffnfphtwtar9fz", - TargetWeight: math.NewInt(1), - }, - { - ValidatorAddress: "cosmosvaloper18hfzxheyknesfgcrttr5dg50ffnfphtwtar9fz", - TargetWeight: math.NewInt(-1), - }, - { - ValidatorAddress: "cosmosvaloper1ld6vlyy24906u3aqp5lj54f3nsg2592nm9nj5c", - TargetWeight: math.NewInt(0), - }, - } -) +var whitelistedValidators = []types.WhitelistedValidator{ + { + ValidatorAddress: "cosmosvaloper10e4vsut6suau8tk9m6dnrm0slgd6npe3jx5xpv", + TargetWeight: math.NewInt(10), + }, + { + ValidatorAddress: "cosmosvaloper18hfzxheyknesfgcrttr5dg50ffnfphtwtar9fz", + TargetWeight: math.NewInt(1), + }, + { + ValidatorAddress: "cosmosvaloper18hfzxheyknesfgcrttr5dg50ffnfphtwtar9fz", + TargetWeight: math.NewInt(-1), + }, + { + ValidatorAddress: "cosmosvaloper1ld6vlyy24906u3aqp5lj54f3nsg2592nm9nj5c", + TargetWeight: math.NewInt(0), + }, +} func TestStkXPRTToNativeTokenWithFee(t *testing.T) { testCases := []struct { diff --git a/x/liquidstake/types/params_test.go b/x/liquidstake/types/params_test.go index ca4f14eca..dbd36930d 100644 --- a/x/liquidstake/types/params_test.go +++ b/x/liquidstake/types/params_test.go @@ -11,7 +11,6 @@ import ( ) func TestParams(t *testing.T) { - params := types.DefaultParams() paramsStr := `{ diff --git a/x/liquidstake/types/rebalancing_test.go b/x/liquidstake/types/rebalancing_test.go index 3fcce76f7..da6d085c8 100644 --- a/x/liquidstake/types/rebalancing_test.go +++ b/x/liquidstake/types/rebalancing_test.go @@ -10,22 +10,20 @@ import ( "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types" ) -var ( - liquidValidators = []types.LiquidValidator{ - { - OperatorAddress: "persistencevaloper15kdfwczhpmccprekhlzrvkhzw92940l3w37qqj", - }, - { - OperatorAddress: "persistencevaloper1x73gyvh74ahs2rt9cqrpjkkk74nczwfpnskv3rczmsf0m6aj5dksqr58m3", - }, - { - OperatorAddress: "persistencevaloper10ngyx42lfpylpllm4k3g7fz4gufnt3ptyhm5pn", - }, - { - OperatorAddress: "persistencevaloper10fcwju2n8vvffkp8judj3skqpvnphasxjar5yx", - }, - } -) +var liquidValidators = []types.LiquidValidator{ + { + OperatorAddress: "persistencevaloper15kdfwczhpmccprekhlzrvkhzw92940l3w37qqj", + }, + { + OperatorAddress: "persistencevaloper1x73gyvh74ahs2rt9cqrpjkkk74nczwfpnskv3rczmsf0m6aj5dksqr58m3", + }, + { + OperatorAddress: "persistencevaloper10ngyx42lfpylpllm4k3g7fz4gufnt3ptyhm5pn", + }, + { + OperatorAddress: "persistencevaloper10fcwju2n8vvffkp8judj3skqpvnphasxjar5yx", + }, +} func TestDivideByWeight(t *testing.T) { testCases := []struct { @@ -417,7 +415,8 @@ func TestDivideByCurrentWeight(t *testing.T) { totalLiquidTokens = totalLiquidTokens.Add(v.LiquidTokens) liquidTokenMap[v.OperatorAddress] = v.LiquidTokens lvs = append(lvs, types.LiquidValidator{ - OperatorAddress: v.OperatorAddress}) + OperatorAddress: v.OperatorAddress, + }) } outputs, crumb := types.DivideByCurrentWeight(lvs, tc.addStakingAmt, totalLiquidTokens, liquidTokenMap) for _, v := range outputs { diff --git a/x/liquidstakeibc/client/tx.go b/x/liquidstakeibc/client/tx.go index c4046fe39..5f7d0e10b 100644 --- a/x/liquidstakeibc/client/tx.go +++ b/x/liquidstakeibc/client/tx.go @@ -174,7 +174,6 @@ func NewLiquidStakeCmd() *cobra.Command { ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientctx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -215,7 +214,6 @@ $ %s tx liquidstakeibc liquid-stake-lsm '[ ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientctx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -250,7 +248,6 @@ func NewLiquidUnstakeCmd() *cobra.Command { ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientctx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -285,7 +282,6 @@ func NewRedeemCmd() *cobra.Command { ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientctx, err := client.GetClientTxContext(cmd) if err != nil { return err diff --git a/x/liquidstakeibc/genesis.go b/x/liquidstakeibc/genesis.go index d5f4b4e91..eb6120481 100644 --- a/x/liquidstakeibc/genesis.go +++ b/x/liquidstakeibc/genesis.go @@ -35,13 +35,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState *types.GenesisState) // ExportGenesis returns the liquidstakeibc module's genesis state. func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { - return &types.GenesisState{ Params: k.GetParams(ctx), HostChains: k.GetAllHostChains(ctx), Deposits: k.GetAllDeposits(ctx), - Unbondings: k.FilterUnbondings(ctx, func(u types.Unbonding) bool { return true }), //GetAll - UserUnbondings: k.FilterUserUnbondings(ctx, func(u types.UserUnbonding) bool { return true }), //GetAll + Unbondings: k.FilterUnbondings(ctx, func(u types.Unbonding) bool { return true }), // GetAll + UserUnbondings: k.FilterUserUnbondings(ctx, func(u types.UserUnbonding) bool { return true }), // GetAll ValidatorUnbondings: k.FilterValidatorUnbondings(ctx, func(u types.ValidatorUnbonding) bool { return true }), } } diff --git a/x/liquidstakeibc/keeper/abci.go b/x/liquidstakeibc/keeper/abci.go index a718c0b3f..f22d1398c 100644 --- a/x/liquidstakeibc/keeper/abci.go +++ b/x/liquidstakeibc/keeper/abci.go @@ -16,7 +16,6 @@ import ( ) func (k *Keeper) BeginBlock(ctx sdk.Context) { - // perform BeginBlocker tasks for each chain for _, hc := range k.GetAllHostChains(ctx) { if !hc.Active { @@ -43,7 +42,6 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) { } // delete acked redelegations k.DoDeleteRedelegationTxs(ctx) - } func (k *Keeper) DoDelegate(ctx sdk.Context, hc *types.HostChain) { diff --git a/x/liquidstakeibc/keeper/abci_test.go b/x/liquidstakeibc/keeper/abci_test.go index 690d5843b..acf8ef2f2 100644 --- a/x/liquidstakeibc/keeper/abci_test.go +++ b/x/liquidstakeibc/keeper/abci_test.go @@ -155,5 +155,4 @@ func (suite *IntegrationTestSuite) TestKeeper_BeginBlockCode() { valubd, found := k.GetValidatorUnbonding(ctx, hc.ChainId, "val1", 0) suite.Require().True(found) suite.Require().NotEqual("", valubd.IbcSequenceId) - } diff --git a/x/liquidstakeibc/keeper/deposit_test.go b/x/liquidstakeibc/keeper/deposit_test.go index 07d94655a..35d85d1ad 100644 --- a/x/liquidstakeibc/keeper/deposit_test.go +++ b/x/liquidstakeibc/keeper/deposit_test.go @@ -200,7 +200,6 @@ func (suite *IntegrationTestSuite) TestAdjustDepositsForRedemption() { for _, t := range tc { suite.Run(t.name, func() { - for _, deposit := range t.deposits { suite.app.LiquidStakeIBCKeeper.SetDeposit(suite.ctx, deposit) } @@ -222,7 +221,6 @@ func (suite *IntegrationTestSuite) TestAdjustDepositsForRedemption() { suite.True(ok) suite.Require().Equal(depositState.Amount, deposit) } - }) } } @@ -499,7 +497,6 @@ func (suite *IntegrationTestSuite) TestGetDelegatingDepositsForChain() { } func (suite *IntegrationTestSuite) TestGetDepositAmountOnPersistence() { - tc := []struct { name string deposits []types.Deposit @@ -517,7 +514,8 @@ func (suite *IntegrationTestSuite) TestGetDepositAmountOnPersistence() { }, chainID: suite.chainB.ChainID, expected: sdk.NewInt(3), - }} + }, + } for _, t := range tc { suite.Run(t.name, func() { for _, deposit := range t.deposits { @@ -526,10 +524,10 @@ func (suite *IntegrationTestSuite) TestGetDepositAmountOnPersistence() { amt := suite.app.LiquidStakeIBCKeeper.GetDepositAmountOnPersistence(suite.ctx, t.chainID) suite.Require().Equal(t.expected, amt) - }) } } + func (suite *IntegrationTestSuite) TestGetDepositAmountOnHostChain() { tc := []struct { name string @@ -548,7 +546,8 @@ func (suite *IntegrationTestSuite) TestGetDepositAmountOnHostChain() { }, chainID: suite.chainB.ChainID, expected: sdk.NewInt(9), - }} + }, + } for _, t := range tc { suite.Run(t.name, func() { for _, deposit := range t.deposits { @@ -557,7 +556,6 @@ func (suite *IntegrationTestSuite) TestGetDepositAmountOnHostChain() { amt := suite.app.LiquidStakeIBCKeeper.GetDepositAmountOnHostChain(suite.ctx, t.chainID) suite.Require().Equal(t.expected, amt) - }) } } diff --git a/x/liquidstakeibc/keeper/grpc_querier_test.go b/x/liquidstakeibc/keeper/grpc_querier_test.go index 430638afb..866ef9813 100644 --- a/x/liquidstakeibc/keeper/grpc_querier_test.go +++ b/x/liquidstakeibc/keeper/grpc_querier_test.go @@ -48,7 +48,6 @@ func (suite *IntegrationTestSuite) TestQueryParams() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.Params(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -58,7 +57,6 @@ func (suite *IntegrationTestSuite) TestQueryParams() { } func (suite *IntegrationTestSuite) TestQueryHostChain() { - hostChains := suite.app.LiquidStakeIBCKeeper.GetAllHostChains(suite.ctx) tc := []struct { @@ -85,7 +83,6 @@ func (suite *IntegrationTestSuite) TestQueryHostChain() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.HostChain(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -116,7 +113,6 @@ func (suite *IntegrationTestSuite) TestQueryHostChains() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.HostChains(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -164,7 +160,6 @@ func (suite *IntegrationTestSuite) TestQueryDeposits() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.Deposits(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -210,7 +205,6 @@ func (suite *IntegrationTestSuite) TestQueryLSMDeposits() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.LSMDeposits(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -256,7 +250,6 @@ func (suite *IntegrationTestSuite) TestQueryUnbondings() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.Unbondings(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -306,7 +299,6 @@ func (suite *IntegrationTestSuite) TestQueryUserUnbondings() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.UserUnbondings(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -356,7 +348,6 @@ func (suite *IntegrationTestSuite) TestQueryValidatorUnbondings() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.ValidatorUnbondings(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -374,31 +365,31 @@ func (suite *IntegrationTestSuite) TestQueryUnbonding() { req *types.QueryUnbondingRequest resp *types.QueryUnbondingResponse err error - }{{ - name: "Valid", - req: &types.QueryUnbondingRequest{ - ChainId: suite.chainB.ChainID, - Epoch: 1, + }{ + { + name: "Valid", + req: &types.QueryUnbondingRequest{ + ChainId: suite.chainB.ChainID, + Epoch: 1, + }, + resp: &types.QueryUnbondingResponse{Unbonding: unbonding}, + err: nil, + }, { + name: "NotFound", + req: &types.QueryUnbondingRequest{ChainId: "chain-1"}, + resp: nil, + err: sdkerrors.ErrKeyNotFound, + }, { + name: "InvalidRequest", + req: &types.QueryUnbondingRequest{ChainId: ""}, + err: status.Error(codes.InvalidArgument, "chain_id cannot be empty"), + }, { + name: "InvalidRequest", + err: status.Error(codes.InvalidArgument, "empty request"), }, - resp: &types.QueryUnbondingResponse{Unbonding: unbonding}, - err: nil, - }, { - name: "NotFound", - req: &types.QueryUnbondingRequest{ChainId: "chain-1"}, - resp: nil, - err: sdkerrors.ErrKeyNotFound, - }, { - name: "InvalidRequest", - req: &types.QueryUnbondingRequest{ChainId: ""}, - err: status.Error(codes.InvalidArgument, "chain_id cannot be empty"), - }, { - name: "InvalidRequest", - err: status.Error(codes.InvalidArgument, "empty request"), - }, } for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.Unbonding(suite.ctx, t.req) suite.Require().Equal(t.err, err) @@ -408,7 +399,6 @@ func (suite *IntegrationTestSuite) TestQueryUnbonding() { } func (suite *IntegrationTestSuite) TestQueryDepositAccountBalance() { - err := testutil.FundAccount(suite.app.BankKeeper, suite.ctx, authtypes.NewModuleAddress(types.DepositModuleAccount), sdktypes.NewCoins(sdktypes.NewInt64Coin("ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", 1000))) @@ -435,7 +425,6 @@ func (suite *IntegrationTestSuite) TestQueryDepositAccountBalance() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.DepositAccountBalance(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -443,8 +432,8 @@ func (suite *IntegrationTestSuite) TestQueryDepositAccountBalance() { }) } } -func (suite *IntegrationTestSuite) TestQueryExchangeRate() { +func (suite *IntegrationTestSuite) TestQueryExchangeRate() { tc := []struct { name string req *types.QueryExchangeRateRequest @@ -466,7 +455,6 @@ func (suite *IntegrationTestSuite) TestQueryExchangeRate() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.ExchangeRate(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -476,7 +464,6 @@ func (suite *IntegrationTestSuite) TestQueryExchangeRate() { } func (suite *IntegrationTestSuite) TestQueryRedelegations() { - tc := []struct { name string req *types.QueryRedelegationsRequest @@ -498,7 +485,6 @@ func (suite *IntegrationTestSuite) TestQueryRedelegations() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.Redelegations(suite.ctx, t.req) suite.Require().Equal(err, t.err) @@ -508,7 +494,6 @@ func (suite *IntegrationTestSuite) TestQueryRedelegations() { } func (suite *IntegrationTestSuite) TestQueryRedelegationTx() { - tc := []struct { name string req *types.QueryRedelegationTxRequest @@ -530,7 +515,6 @@ func (suite *IntegrationTestSuite) TestQueryRedelegationTx() { for _, t := range tc { suite.Run(t.name, func() { - resp, err := suite.app.LiquidStakeIBCKeeper.RedelegationTx(suite.ctx, t.req) suite.Require().Equal(err, t.err) diff --git a/x/liquidstakeibc/keeper/hooks.go b/x/liquidstakeibc/keeper/hooks.go index 713c62b8d..d78909e49 100644 --- a/x/liquidstakeibc/keeper/hooks.go +++ b/x/liquidstakeibc/keeper/hooks.go @@ -106,7 +106,7 @@ func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNum if epochIdentifier == liquidstakeibctypes.UndelegationEpoch { // attempt to fully undelegate any validators that have been more than - //UnbondingStateEpochLimit epochs in UNBONDING state + // UnbondingStateEpochLimit epochs in UNBONDING state k.ValidatorUndelegationWorkflow(ctx, epochNumber) k.UndelegationWorkflow(ctx, epochNumber) diff --git a/x/liquidstakeibc/keeper/host_chain_test.go b/x/liquidstakeibc/keeper/host_chain_test.go index 017835856..f0f61baf1 100644 --- a/x/liquidstakeibc/keeper/host_chain_test.go +++ b/x/liquidstakeibc/keeper/host_chain_test.go @@ -1058,7 +1058,6 @@ func (suite *IntegrationTestSuite) TestGetHostChainFromIBCDenom() { } else { suite.Require().Equal("", hc.ChainId) } - }) } } diff --git a/x/liquidstakeibc/keeper/ica.go b/x/liquidstakeibc/keeper/ica.go index 5b6c78265..25b7121d9 100644 --- a/x/liquidstakeibc/keeper/ica.go +++ b/x/liquidstakeibc/keeper/ica.go @@ -19,7 +19,6 @@ func (k *Keeper) GenerateAndExecuteICATx( ownerID string, messages []proto.Message, ) (string, error) { - msgData, err := icatypes.SerializeCosmosTx(k.cdc, messages) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("could not serialize tx data: %v", err)) diff --git a/x/liquidstakeibc/keeper/icq.go b/x/liquidstakeibc/keeper/icq.go index 2e6281f0f..b054ff2de 100644 --- a/x/liquidstakeibc/keeper/icq.go +++ b/x/liquidstakeibc/keeper/icq.go @@ -34,6 +34,7 @@ var _ icqtypes.QueryCallbacks = Callbacks{} func (k *Keeper) CallbackHandler() Callbacks { return Callbacks{*k, make(map[string]CallbackFn)} } + func (c Callbacks) AddCallback(id string, fn interface{}) icqtypes.QueryCallbacks { c.callbacks[id] = fn.(CallbackFn) return c diff --git a/x/liquidstakeibc/keeper/icq_queries.go b/x/liquidstakeibc/keeper/icq_queries.go index d571466ee..bb4b6d6fa 100644 --- a/x/liquidstakeibc/keeper/icq_queries.go +++ b/x/liquidstakeibc/keeper/icq_queries.go @@ -15,7 +15,6 @@ func (k *Keeper) QueryHostChainValidator( hc *types.HostChain, validatorAddress string, ) error { - _, byteAddress, err := bech32.DecodeAndConvert(validatorAddress) if err != nil { return err diff --git a/x/liquidstakeibc/keeper/icq_queries_test.go b/x/liquidstakeibc/keeper/icq_queries_test.go index 882ecaf41..37ea19109 100644 --- a/x/liquidstakeibc/keeper/icq_queries_test.go +++ b/x/liquidstakeibc/keeper/icq_queries_test.go @@ -37,7 +37,6 @@ func (suite *IntegrationTestSuite) TestKeeper_QueryHostChainValidator() { } for _, tt := range tests { suite.Run(tt.name, func() { - if err := k.QueryHostChainValidator(ctx, tt.args.hc, tt.args.validatorAddress); (err != nil) != tt.wantErr { suite.T().Errorf("QueryHostChainValidator() error = %v, wantErr %v", err, tt.wantErr) } @@ -76,7 +75,8 @@ func (suite *IntegrationTestSuite) TestKeeper_QueryValidatorDelegation() { validator: hc.Validators[0], }, wantErr: true, - }} + }, + } for _, tt := range tests { suite.Run(tt.name, func() { if err := k.QueryValidatorDelegation(ctx, tt.args.hc, tt.args.validator); (err != nil) != tt.wantErr { @@ -120,6 +120,7 @@ func (suite *IntegrationTestSuite) TestKeeper_QueryDelegationHostChainAccountBal }) } } + func (suite *IntegrationTestSuite) TestKeeper_QueryRewardsHostChainAccountBalance() { pstakeApp, ctx := suite.app, suite.ctx k := pstakeApp.LiquidStakeIBCKeeper @@ -148,7 +149,6 @@ func (suite *IntegrationTestSuite) TestKeeper_QueryRewardsHostChainAccountBalanc } for _, tt := range tests { suite.Run(tt.name, func() { - if err := k.QueryRewardsHostChainAccountBalance(ctx, tt.args.hc); (err != nil) != tt.wantErr { suite.T().Errorf("QueryRewardsHostChainAccountBalance() error = %v, wantErr %v", err, tt.wantErr) } @@ -187,7 +187,6 @@ func (suite *IntegrationTestSuite) TestKeeper_QueryNonCompoundableRewardsHostCha } for _, tt := range tests { suite.Run(tt.name, func() { - if err := k.QueryRewardsHostChainAccountBalance(ctx, tt.args.hc); (err != nil) != tt.wantErr { suite.T().Errorf("QueryRewardsHostChainAccountBalance() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/x/liquidstakeibc/keeper/icq_test.go b/x/liquidstakeibc/keeper/icq_test.go index f5ac6b6af..c32b3f2df 100644 --- a/x/liquidstakeibc/keeper/icq_test.go +++ b/x/liquidstakeibc/keeper/icq_test.go @@ -52,7 +52,8 @@ func (suite *IntegrationTestSuite) TestValidatorCallback() { query: icqtypes.Query{ChainId: "invalid-1"}, }, wantErr: true, - }, { + }, + { name: "Invalid Data", args: args{ data: []byte("invalid data"), @@ -83,7 +84,6 @@ func (suite *IntegrationTestSuite) TestDelegationCallback() { makeData := func(delegation stakingtypes.Delegation) []byte { return stakingtypes.MustMarshalDelegation(pstakeApp.AppCodec(), delegation) - } type args struct { ctx sdk.Context diff --git a/x/liquidstakeibc/keeper/keeper_test.go b/x/liquidstakeibc/keeper/keeper_test.go index 6422d88a0..a54d84500 100644 --- a/x/liquidstakeibc/keeper/keeper_test.go +++ b/x/liquidstakeibc/keeper/keeper_test.go @@ -158,7 +158,7 @@ func (suite *IntegrationTestSuite) TestGetClientState() { suite.Require().NoError(err) suite.Require().Equal(ibcexported.Localhost, state.ClientType()) - //no connection found + // no connection found _, err = pstakeApp.LiquidStakeIBCKeeper.GetClientState(ctx, "connection-2") suite.Require().Error(err) @@ -186,10 +186,9 @@ func (suite *IntegrationTestSuite) TestGetChainID() { _, err = pstakeApp.LiquidStakeIBCKeeper.GetChainID(ctx, "connection-2") suite.Require().Error(err) - //connection not found + // connection not found _, err = pstakeApp.LiquidStakeIBCKeeper.GetChainID(ctx, "connection-3") suite.Require().Error(err) - } func (suite *IntegrationTestSuite) TestGetPortID() { @@ -217,6 +216,7 @@ func (suite *IntegrationTestSuite) TestSetWithdrawAddress() { err = pstakeApp.LiquidStakeIBCKeeper.SetWithdrawAddress(ctx, hc2) suite.Require().Error(err) } + func (suite *IntegrationTestSuite) TestIsICAChannelActive() { pstakeApp, ctx := suite.app, suite.ctx hc, found := pstakeApp.LiquidStakeIBCKeeper.GetHostChain(ctx, suite.chainB.ChainID) @@ -226,6 +226,7 @@ func (suite *IntegrationTestSuite) TestIsICAChannelActive() { active := pstakeApp.LiquidStakeIBCKeeper.IsICAChannelActive(ctx, hc, pstakeApp.LiquidStakeIBCKeeper.GetPortID(hc.DelegationAccount.Owner)) suite.Require().Equal(true, active) } + func (suite *IntegrationTestSuite) TestSendICATransfer() { pstakeApp, ctx := suite.app, suite.ctx hc, found := pstakeApp.LiquidStakeIBCKeeper.GetHostChain(ctx, suite.chainB.ChainID) @@ -248,6 +249,7 @@ func (suite *IntegrationTestSuite) TestSendICATransfer() { hc.DelegationAccount.Owner) suite.Require().Error(err) } + func (suite *IntegrationTestSuite) TestUpdateCValues() { pstakeApp, ctx := suite.app, suite.ctx hc, found := pstakeApp.LiquidStakeIBCKeeper.GetHostChain(ctx, suite.chainB.ChainID) @@ -263,7 +265,7 @@ func (suite *IntegrationTestSuite) TestUpdateCValues() { suite.Require().NoError(err) senderAcc := suite.chainA.SenderAccount - //user liquidstakes + // user liquidstakes msgLiquidStake := types.NewMsgLiquidStake(sdk.NewInt64Coin(hc.IBCDenom(), 1000000), senderAcc.GetAddress()) result, err := suite.app.MsgServiceRouter().Handler(msgLiquidStake)(suite.chainA.GetContext(), msgLiquidStake) suite.NotNil(result) @@ -271,7 +273,7 @@ func (suite *IntegrationTestSuite) TestUpdateCValues() { } suite.Require().NotPanics(func() { pstakeApp.LiquidStakeIBCKeeper.UpdateCValues(ctx) }) - //lower limits so that chain goes out of limits + // lower limits so that chain goes out of limits params := pstakeApp.LiquidStakeIBCKeeper.GetParams(ctx) params.UpperCValueLimit = sdk.MustNewDecFromStr("0.5") pstakeApp.LiquidStakeIBCKeeper.SetParams(ctx, params) diff --git a/x/liquidstakeibc/keeper/lsm_deposit_test.go b/x/liquidstakeibc/keeper/lsm_deposit_test.go index da4dec762..483f6660e 100644 --- a/x/liquidstakeibc/keeper/lsm_deposit_test.go +++ b/x/liquidstakeibc/keeper/lsm_deposit_test.go @@ -125,7 +125,6 @@ func (suite *IntegrationTestSuite) TestGetLSMDepositsFromIbcDenom() { TestLSMDenom, deposits[0].Denom, ) } - }) } } @@ -173,7 +172,6 @@ func (suite *IntegrationTestSuite) TestGetLSMDepositsFromIbcSequenceID() { TestLSMDenom, deposits[0].Denom, ) } - }) } } @@ -221,7 +219,6 @@ func (suite *IntegrationTestSuite) TestGetTransferableLSMDeposits() { TestLSMDenom, deposits[0].Denom, ) } - }) } } @@ -269,7 +266,6 @@ func (suite *IntegrationTestSuite) TestGetRedeemableLSMDeposits() { TestLSMDenom, deposits[0].Denom, ) } - }) } } diff --git a/x/liquidstakeibc/keeper/msg_server.go b/x/liquidstakeibc/keeper/msg_server.go index 6f4b4253f..a3b50ca96 100644 --- a/x/liquidstakeibc/keeper/msg_server.go +++ b/x/liquidstakeibc/keeper/msg_server.go @@ -193,42 +193,42 @@ func (k msgServer) UpdateHostChain( if err != nil { return nil, fmt.Errorf("unable to parse string to sdk.Dec: %w", err) } - //fee limits validated in msg.ValidateBasic() + // fee limits validated in msg.ValidateBasic() hc.Params.DepositFee = fee case types.KeyRestakeFee: fee, err := sdktypes.NewDecFromStr(update.Value) if err != nil { return nil, fmt.Errorf("unable to parse string to sdk.Dec: %w", err) } - //fee limits validated in msg.ValidateBasic() + // fee limits validated in msg.ValidateBasic() hc.Params.RestakeFee = fee case types.KeyRedemptionFee: fee, err := sdktypes.NewDecFromStr(update.Value) if err != nil { return nil, fmt.Errorf("unable to parse string to sdk.Dec: %w", err) } - //fee limits validated in msg.ValidateBasic() + // fee limits validated in msg.ValidateBasic() hc.Params.RedemptionFee = fee case types.KeyUnstakeFee: fee, err := sdktypes.NewDecFromStr(update.Value) if err != nil { return nil, fmt.Errorf("unable to parse string to sdk.Dec: %w", err) } - //fee limits validated in msg.ValidateBasic() + // fee limits validated in msg.ValidateBasic() hc.Params.UnstakeFee = fee case types.KeyLSMValidatorCap: validatorCap, err := sdktypes.NewDecFromStr(update.Value) if err != nil { return nil, fmt.Errorf("unable to parse string to sdk.Dec: %w", err) } - //cap limits validated in msg.ValidateBasic() + // cap limits validated in msg.ValidateBasic() hc.Params.LsmValidatorCap = validatorCap case types.KeyLSMBondFactor: bondFactor, err := sdktypes.NewDecFromStr(update.Value) if err != nil { return nil, fmt.Errorf("unable to parse string to sdk.Dec: %w", err) } - //factor limits validated in msg.ValidateBasic() + // factor limits validated in msg.ValidateBasic() hc.Params.LsmBondFactor = bondFactor case types.KeyMaxEntries: entries, err := strconv.ParseUint(update.Value, 10, 32) @@ -247,7 +247,7 @@ func (k msgServer) UpdateHostChain( if !ok { return nil, fmt.Errorf("unable to parse string to sdk.Int") } - //min deposit limits validated in msg.ValidateBasic() + // min deposit limits validated in msg.ValidateBasic() hc.MinimumDeposit = minimumDeposit case types.KeyActive: active, err := strconv.ParseBool(update.Value) @@ -267,7 +267,7 @@ func (k msgServer) UpdateHostChain( if err != nil { return nil, fmt.Errorf("unable to parse string to sdk.Dec") } - //autoCompoundFactor limits validated in msg.ValidateBasic() + // autoCompoundFactor limits validated in msg.ValidateBasic() hc.AutoCompoundFactor = k.CalculateAutocompoundLimit(autocompoundFactor) case types.KeyFlags: var flags types.HostChainFlags @@ -435,7 +435,8 @@ func (k msgServer) LiquidStake( sdktypes.EventTypeMessage, sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory), sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.DelegatorAddress), - )}, + ), + }, ) telemetry.IncrCounter(float32(1), hostChain.ChainId, "liquid_stake") @@ -569,7 +570,8 @@ func (k msgServer) LiquidStakeLSM( sdktypes.EventTypeMessage, sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory), sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.DelegatorAddress), - )}, + ), + }, ) } @@ -691,7 +693,8 @@ func (k msgServer) LiquidUnstake( sdktypes.EventTypeMessage, sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory), sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.GetDelegatorAddress()), - )}, + ), + }, ) telemetry.IncrCounter(float32(1), hc.ChainId, "liquid_unstake") @@ -799,7 +802,7 @@ func (k msgServer) Redeem( } // send the instant redeemed token from module to the account, - //this will error out if there are insufficient redeemTokens + // this will error out if there are insufficient redeemTokens err = k.bankKeeper.SendCoinsFromModuleToAccount( ctx, types.DepositModuleAccount, @@ -848,7 +851,8 @@ func (k msgServer) Redeem( sdktypes.EventTypeMessage, sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory), sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.DelegatorAddress), - )}, + ), + }, ) telemetry.IncrCounter(float32(1), hc.ChainId, "redeem") @@ -893,7 +897,6 @@ func (k msgServer) validateLiquidStakeLSMDeposit( delegatorAddress sdktypes.AccAddress, delegation sdktypes.Coin, ) (*types.HostChain, *types.Validator, *transfertypes.DenomTrace, error) { - // check if the ibc denom is valid if err := transfertypes.ValidateIBCDenom(delegation.Denom); err != nil { return nil, nil, nil, errorsmod.Wrapf(types.ErrInvalidLSMDenom, "IBC denom %s doesn't belong to a LSM token", delegation.Denom) diff --git a/x/liquidstakeibc/keeper/msg_server_test.go b/x/liquidstakeibc/keeper/msg_server_test.go index 4eccd2eb9..6a8047da0 100644 --- a/x/liquidstakeibc/keeper/msg_server_test.go +++ b/x/liquidstakeibc/keeper/msg_server_test.go @@ -347,7 +347,8 @@ func (suite *IntegrationTestSuite) Test_msgServer_Redeem() { }, want: nil, wantErr: true, - }} + }, + } for _, tt := range tests { suite.T().Run(tt.name, func(t *testing.T) { k := keeper.NewMsgServerImpl(pstakeapp.LiquidStakeIBCKeeper) @@ -398,7 +399,8 @@ func (suite *IntegrationTestSuite) Test_msgServer_RegisterHostChain() { }, want: &types.MsgRegisterHostChainResponse{}, wantErr: false, - }} + }, + } for _, tt := range tests { suite.T().Run(tt.name, func(t *testing.T) { k := keeper.NewMsgServerImpl(pstakeapp.LiquidStakeIBCKeeper) @@ -448,7 +450,8 @@ func (suite *IntegrationTestSuite) Test_msgServer_UpdateHostChain() { }, want: &types.MsgUpdateHostChainResponse{}, wantErr: false, - }} + }, + } for _, tt := range tests { suite.T().Run(tt.name, func(t *testing.T) { k := keeper.NewMsgServerImpl(pstakeapp.LiquidStakeIBCKeeper) @@ -494,7 +497,8 @@ func (suite *IntegrationTestSuite) Test_msgServer_UpdateParams() { }, want: &types.MsgUpdateParamsResponse{}, wantErr: false, - }} + }, + } for _, tt := range tests { suite.T().Run(tt.name, func(t *testing.T) { k := keeper.NewMsgServerImpl(pstakeapp.LiquidStakeIBCKeeper) diff --git a/x/liquidstakeibc/keeper/rebalance.go b/x/liquidstakeibc/keeper/rebalance.go index d7563c6a9..ff6b8d8ff 100644 --- a/x/liquidstakeibc/keeper/rebalance.go +++ b/x/liquidstakeibc/keeper/rebalance.go @@ -20,8 +20,8 @@ type delegation struct { } func (k Keeper) GenerateRedelegateMsgs(ctx sdk.Context, hc types.HostChain) []proto.Message { - var AcceptableDelta = hc.Params.RedelegationAcceptableDelta - var MaxRedelegationEntries = hc.Params.MaxEntries + AcceptableDelta := hc.Params.RedelegationAcceptableDelta + MaxRedelegationEntries := hc.Params.MaxEntries sum := math.ZeroInt() for _, validator := range hc.Validators { sum = sum.Add(validator.DelegatedAmount) @@ -66,7 +66,7 @@ L1: } // RedelegationExistsToValidator: This is not updated inside the loop (with newer msgs), so some ICA redelegate txns might fail, and it is ok. if !k.RedelegationExistsToValidator(redelegations.Redelegations, revIdealList[i].validator) { - //re-sort idealDelegationAsc + // re-sort idealDelegationAsc idealDelegationList = sortDelegationListAsc(idealDelegationList) L2: for j := range idealDelegationList { diff --git a/x/liquidstakeibc/keeper/redelegation_test.go b/x/liquidstakeibc/keeper/redelegation_test.go index 45e5bfe50..62e8e0faa 100644 --- a/x/liquidstakeibc/keeper/redelegation_test.go +++ b/x/liquidstakeibc/keeper/redelegation_test.go @@ -22,7 +22,6 @@ var redelegation = &stakingtypes.Redelegation{ } func (suite *IntegrationTestSuite) TestSetGetRedelegations() { - suite.app.LiquidStakeIBCKeeper.SetRedelegations( suite.ctx, suite.chainB.ChainID, []*stakingtypes.Redelegation{redelegation}, @@ -40,7 +39,6 @@ func (suite *IntegrationTestSuite) TestSetGetRedelegations() { } func (suite *IntegrationTestSuite) TestAddRedelegationEntry() { - suite.app.LiquidStakeIBCKeeper.SetRedelegations( suite.ctx, suite.chainB.ChainID, []*stakingtypes.Redelegation{redelegation}, @@ -78,7 +76,8 @@ func (suite *IntegrationTestSuite) TestAddRedelegationEntry() { resp: stakingtypes.MsgBeginRedelegateResponse{CompletionTime: time.Now().Add(time.Second)}, lenEntries: 3, index: 0, - }, { + }, + { name: "new chainid", chainID: suite.chainC.ChainID, msg: stakingtypes.MsgBeginRedelegate{ @@ -90,7 +89,8 @@ func (suite *IntegrationTestSuite) TestAddRedelegationEntry() { resp: stakingtypes.MsgBeginRedelegateResponse{CompletionTime: time.Now().Add(time.Second)}, lenEntries: 1, index: 0, - }, { + }, + { name: "new chainid", chainID: suite.chainC.ChainID, msg: stakingtypes.MsgBeginRedelegate{ @@ -107,7 +107,6 @@ func (suite *IntegrationTestSuite) TestAddRedelegationEntry() { for _, t := range tc { suite.Run(t.name, func() { - suite.app.LiquidStakeIBCKeeper.AddRedelegationEntry( suite.ctx, t.chainID, diff --git a/x/liquidstakeibc/keeper/redelegation_txs_test.go b/x/liquidstakeibc/keeper/redelegation_txs_test.go index bd94a4a34..ef1dd1025 100644 --- a/x/liquidstakeibc/keeper/redelegation_txs_test.go +++ b/x/liquidstakeibc/keeper/redelegation_txs_test.go @@ -5,7 +5,6 @@ import ( ) func (suite *IntegrationTestSuite) TestSetGetDeleteRedelegationTx() { - suite.app.LiquidStakeIBCKeeper.SetRedelegationTx( suite.ctx, &types.RedelegateTx{ @@ -40,5 +39,4 @@ func (suite *IntegrationTestSuite) TestSetGetDeleteRedelegationTx() { suite.chainB.ChainID, "channel-100-sequence-1", ) suite.Require().Equal(false, found) - } diff --git a/x/liquidstakeibc/keeper/setup_suite_test.go b/x/liquidstakeibc/keeper/setup_suite_test.go index 44e789b13..abc04ba6c 100644 --- a/x/liquidstakeibc/keeper/setup_suite_test.go +++ b/x/liquidstakeibc/keeper/setup_suite_test.go @@ -51,9 +51,9 @@ type IntegrationTestSuite struct { govHandler govtypes.Handler coordinator *ibctesting.Coordinator - chainA *ibctesting.TestChain //pstake chain - chainB *ibctesting.TestChain //host chain, run tests of active chains - chainC *ibctesting.TestChain //host chain 2, run tests of to activate chains + chainA *ibctesting.TestChain // pstake chain + chainB *ibctesting.TestChain // host chain, run tests of active chains + chainC *ibctesting.TestChain // host chain 2, run tests of to activate chains transferPathAB *ibctesting.Path // chainA - chainB transfer path transferPathAC *ibctesting.Path // chainA - chainC transfer path @@ -67,7 +67,6 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *IntegrationTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 0) ibctesting.DefaultTestingAppInit = helpers.SetupTestingApp @@ -116,10 +115,11 @@ func (suite *IntegrationTestSuite) CleanupSetup() { epoch := suite.app.EpochsKeeper.GetEpochInfo(suite.chainA.GetContext(), types.DelegationEpoch).CurrentEpoch pstakeApp.LiquidStakeIBCKeeper.DepositWorkflow(suite.chainA.GetContext(), epoch) } + func (suite *IntegrationTestSuite) ResetEpochs() { ctx := suite.chainA.GetContext() - //ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) + // ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) epochsKeeper := suite.chainA.App.(*app.PstakeApp).EpochsKeeper for _, epoch := range epochsKeeper.AllEpochInfos(ctx) { @@ -182,16 +182,16 @@ func (suite *IntegrationTestSuite) SetupHostChainAB() { ConnectionId: suite.transferPathAB.EndpointA.ConnectionID, Params: hostChainLSParams, HostDenom: HostDenom, - ChannelId: "channel-0", //suite.transferPathAB.EndpointA.ChannelID, + ChannelId: "channel-0", // suite.transferPathAB.EndpointA.ChannelID, PortId: suite.transferPathAB.EndpointA.ChannelConfig.PortID, DelegationAccount: &types.ICAAccount{ - Address: "cosmos1mykw6u6dq4z7qhw9aztpk5yp8j8y5n0c6usg9faqepw83y2u4nzq2qxaxc", //gets replaced + Address: "cosmos1mykw6u6dq4z7qhw9aztpk5yp8j8y5n0c6usg9faqepw83y2u4nzq2qxaxc", // gets replaced Balance: sdk.Coin{Denom: HostDenom, Amount: sdk.ZeroInt()}, Owner: types.DefaultDelegateAccountPortOwner(suite.chainB.ChainID), ChannelState: types.ICAAccount_ICA_CHANNEL_CREATED, }, RewardsAccount: &types.ICAAccount{ - Address: "cosmos19dade3sxq2wqvy6fenytxmn0y3njw8r2p88cn27pj4naxcyzzs8qgxrun3", //gets replaced + Address: "cosmos19dade3sxq2wqvy6fenytxmn0y3njw8r2p88cn27pj4naxcyzzs8qgxrun3", // gets replaced Balance: sdk.Coin{Denom: HostDenom, Amount: sdk.ZeroInt()}, Owner: types.DefaultRewardsAccountPortOwner(suite.chainB.ChainID), ChannelState: types.ICAAccount_ICA_CHANNEL_CREATED, @@ -249,6 +249,7 @@ func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { return path } + func (suite *IntegrationTestSuite) Transfer(path *ibctesting.Path, coin sdk.Coin) { transferMsg := ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coin, path.EndpointB.Chain.SenderAccount.GetAddress().String(), @@ -263,6 +264,7 @@ func (suite *IntegrationTestSuite) Transfer(path *ibctesting.Path, coin sdk.Coin err = path.RelayPacket(packet) suite.Require().NoError(err) } + func (suite *IntegrationTestSuite) SetupICAChannelsAB() { icapath := NewICAPath(suite.chainA, suite.chainB) icapath.EndpointA.ClientID = suite.transferPathAB.EndpointA.ClientID @@ -292,6 +294,7 @@ func (suite *IntegrationTestSuite) SetupICAChannelsAB() { err = suite.SetupICAPath(suite.rewardsPathAB, types.DefaultRewardsAccountPortOwner(suite.chainB.ChainID)) suite.Require().NoError(err) } + func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { path := ibctesting.NewPath(chainA, chainB) path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID @@ -360,7 +363,7 @@ func (suite *IntegrationTestSuite) TestOneFullFlow() { suite.Require().NoError(err) senderAcc := suite.chainA.SenderAccount - //user liquidstakes + // user liquidstakes msgLiquidStake := types.NewMsgLiquidStake(sdk.NewInt64Coin(hc.IBCDenom(), 1000000), senderAcc.GetAddress()) result, err := suite.app.MsgServiceRouter().Handler(msgLiquidStake)(suite.chainA.GetContext(), msgLiquidStake) suite.NotNil(result) @@ -380,7 +383,7 @@ func (suite *IntegrationTestSuite) TestOneFullFlow() { suite.Require().True(found) suite.Require().Equal(types.Deposit_DEPOSIT_PENDING, deposit.State) - ctx := suite.chainA.GetContext() //use separate context so we can fetch events out of it + ctx := suite.chainA.GetContext() // use separate context so we can fetch events out of it err = k.AfterEpochEnd(ctx, epoch.Identifier, epoch.CurrentEpoch) suite.NoError(err) packets, err := ParsePacketsFromEvents(ctx.EventManager().Events()) @@ -390,22 +393,22 @@ func (suite *IntegrationTestSuite) TestOneFullFlow() { suite.Require().True(found) suite.Require().Equal(types.Deposit_DEPOSIT_SENT, deposit.State) - suite.chainA.NextBlock() //commit the packets and their commitments so its available in context + suite.chainA.NextBlock() // commit the packets and their commitments so its available in context - suite.RelayAllPacketsAB(packets) //also calls for Next Block causing Deposit_DEPOSIT_RECEIVED to just pass + suite.RelayAllPacketsAB(packets) // also calls for Next Block causing Deposit_DEPOSIT_RECEIVED to just pass deposit, found = k.GetDepositForChainAndEpoch(suite.chainA.GetContext(), hc.ChainId, epoch.CurrentEpoch) suite.Require().True(found) suite.Require().Equal(types.Deposit_DEPOSIT_DELEGATING, deposit.State) - timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().UnixNano()) + uint64(types.ICATimeoutTimestamp.Nanoseconds()) - uint64(time.Second*5) //sub one b + timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().UnixNano()) + uint64(types.ICATimeoutTimestamp.Nanoseconds()) - uint64(time.Second*5) // sub one b data, err := suite.CreateICAData(deposit.Amount.Amount, hc, 0) suite.NoError(err) packet, err := CreateICADelegatePacketHardcoded(data, "1", "0-0", fmt.Sprintf("%d", timeoutTimestamp)) suite.NoError(err) - suite.chainA.NextBlock() //commit the packets and their commitments so its available in context + suite.chainA.NextBlock() // commit the packets and their commitments so its available in context suite.RelayAllPacketsAB([]channeltypes.Packet{packet}) deposit, found = k.GetDepositForChainAndEpoch(suite.chainA.GetContext(), hc.ChainId, epoch.CurrentEpoch) suite.Require().False(found) @@ -429,7 +432,7 @@ func (suite *IntegrationTestSuite) TestOneFullFlow() { unbonding, found := k.GetUnbonding(suite.chainA.GetContext(), hc.ChainId, types.CurrentUnbondingEpoch(hc.UnbondingFactor, epoch.CurrentEpoch)) suite.Require().True(found) suite.Require().Equal(types.Unbonding_UNBONDING_PENDING, unbonding.State) - //Force undelegation by manipulating epoch number + // Force undelegation by manipulating epoch number ctx = suite.chainA.GetContext() err = k.AfterEpochEnd(ctx, epoch.Identifier, types.CurrentUnbondingEpoch(hc.UnbondingFactor, epoch.CurrentEpoch)) packets, err = ParsePacketsFromEvents(ctx.EventManager().Events()) @@ -438,7 +441,7 @@ func (suite *IntegrationTestSuite) TestOneFullFlow() { suite.Require().True(found) suite.Require().Equal(types.Unbonding_UNBONDING_INITIATED, unbonding.State) - suite.chainA.NextBlock() //commit the packets and their commitments so its available in context + suite.chainA.NextBlock() // commit the packets and their commitments so its available in context suite.RelayAllPacketsAB(packets) unbonding, found = k.GetUnbonding(suite.chainA.GetContext(), hc.ChainId, types.CurrentUnbondingEpoch(hc.UnbondingFactor, epoch.CurrentEpoch)) @@ -526,7 +529,6 @@ func ParsePacketsFromEvents(events sdk.Events) ([]channeltypes.Packet, error) { } func (suite *IntegrationTestSuite) CreateICAData(amount math.Int, hc *types.HostChain, txtype int) (string, error) { - messages := make([]proto.Message, 0) for _, vals := range hc.Validators { var message proto.Message @@ -586,6 +588,7 @@ func CreateICADelegatePacketHardcoded(data, sequence, timeoutHeight, timeoutTime } return packet, nil } + func CreateICARewardsPacketHardcoded(data, sequence, timeoutHeight, timeoutTimestamp string) (channeltypes.Packet, error) { seq, err := strconv.ParseUint(sequence, 10, 64) if err != nil { diff --git a/x/liquidstakeibc/keeper/unbonding_test.go b/x/liquidstakeibc/keeper/unbonding_test.go index 6a860aee3..cb228a467 100644 --- a/x/liquidstakeibc/keeper/unbonding_test.go +++ b/x/liquidstakeibc/keeper/unbonding_test.go @@ -107,7 +107,6 @@ func (suite *IntegrationTestSuite) TestIncreaseUndelegatingAmountForEpoch() { for _, t := range tc { suite.Run(t.name, func() { - suite.app.LiquidStakeIBCKeeper.IncreaseUndelegatingAmountForEpoch( suite.ctx, t.unbonding.ChainId, diff --git a/x/liquidstakeibc/keeper/user_unbonding_test.go b/x/liquidstakeibc/keeper/user_unbonding_test.go index 17482af49..965e071e4 100644 --- a/x/liquidstakeibc/keeper/user_unbonding_test.go +++ b/x/liquidstakeibc/keeper/user_unbonding_test.go @@ -113,7 +113,6 @@ func (suite *IntegrationTestSuite) TestIncreaseUserUnbondingAmountForEpoch() { for _, t := range tc { suite.Run(t.name, func() { - suite.app.LiquidStakeIBCKeeper.IncreaseUserUnbondingAmountForEpoch( suite.ctx, t.unbonding.ChainId, diff --git a/x/liquidstakeibc/migrations/v2/store.go b/x/liquidstakeibc/migrations/v2/store.go index 6ea36ad4d..2607ae171 100644 --- a/x/liquidstakeibc/migrations/v2/store.go +++ b/x/liquidstakeibc/migrations/v2/store.go @@ -16,7 +16,6 @@ import ( // - Migrate host chain validators to include the delegable flag. // - Migrate host chain to include the LSM validator cap and the LSM bond factor. func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { - for _, hc := range getAllHostChains(ctx, storeKey, cdc) { hc.Flags = &types.HostChainFlags{Lsm: false} diff --git a/x/liquidstakeibc/migrations/v3/store.go b/x/liquidstakeibc/migrations/v3/store.go index c1a0d0f4b..0117dad7f 100644 --- a/x/liquidstakeibc/migrations/v3/store.go +++ b/x/liquidstakeibc/migrations/v3/store.go @@ -14,7 +14,6 @@ import ( // // - Migrate host chains to include the MaxEntries and AcceptableDelta attribute. func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { - for _, hc := range getAllHostChains(ctx, storeKey, cdc) { hc.Params.MaxEntries = 7 hc.Params.RedelegationAcceptableDelta = sdk.NewInt(1000000000) diff --git a/x/liquidstakeibc/module.go b/x/liquidstakeibc/module.go index de4df6f7e..01c2fcd7c 100644 --- a/x/liquidstakeibc/module.go +++ b/x/liquidstakeibc/module.go @@ -29,8 +29,7 @@ var ( _ module.AppModuleSimulation = AppModule{} ) -type AppModuleBasic struct { -} +type AppModuleBasic struct{} func (a AppModuleBasic) Name() string { return types.ModuleName @@ -65,12 +64,10 @@ func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, m func (a AppModuleBasic) GetTxCmd() *cobra.Command { return client.NewTxCmd() - } func (a AppModuleBasic) GetQueryCmd() *cobra.Command { return client.NewQueryCmd() - } type AppModule struct { diff --git a/x/liquidstakeibc/types/genesis_test.go b/x/liquidstakeibc/types/genesis_test.go index fa4488a4f..393adc069 100644 --- a/x/liquidstakeibc/types/genesis_test.go +++ b/x/liquidstakeibc/types/genesis_test.go @@ -60,7 +60,8 @@ func TestGenesisState_Validate(t *testing.T) { Amount: sdk.NewInt64Coin("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", 100), Epoch: 0, State: 0, - IbcSequenceId: ""}) + IbcSequenceId: "", + }) return genesis }, valid: false, @@ -74,11 +75,13 @@ func TestGenesisState_Validate(t *testing.T) { Amount: sdk.NewInt64Coin("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", 100), Epoch: 0, State: 4, - IbcSequenceId: ""}) + IbcSequenceId: "", + }) return genesis }, valid: false, - }, { + }, + { desc: "invalid amount denom", genState: func() *types.GenesisState { genesis := ValidGenesis() @@ -87,7 +90,8 @@ func TestGenesisState_Validate(t *testing.T) { Amount: sdk.NewInt64Coin("uatom", 100), Epoch: 0, State: 0, - IbcSequenceId: ""}) + IbcSequenceId: "", + }) return genesis }, valid: false, @@ -117,7 +121,8 @@ func TestGenesisState_Validate(t *testing.T) { return genesis }, valid: false, - }, { + }, + { desc: "invalid unbound amount", genState: func() *types.GenesisState { genesis := ValidGenesis() @@ -133,7 +138,8 @@ func TestGenesisState_Validate(t *testing.T) { return genesis }, valid: false, - }, { + }, + { desc: "invalid unbonding state", genState: func() *types.GenesisState { genesis := ValidGenesis() @@ -174,7 +180,8 @@ func TestGenesisState_Validate(t *testing.T) { return genesis }, valid: false, - }, { + }, + { desc: "user unbondings incorrect unboundAmount denom", genState: func() *types.GenesisState { genesis := ValidGenesis() @@ -189,7 +196,8 @@ func TestGenesisState_Validate(t *testing.T) { return genesis }, valid: false, - }, { + }, + { desc: "user unbondings invalid", genState: func() *types.GenesisState { genesis := ValidGenesis() diff --git a/x/liquidstakeibc/types/host_chain_test.go b/x/liquidstakeibc/types/host_chain_test.go index c6ea21154..0c13aaad7 100644 --- a/x/liquidstakeibc/types/host_chain_test.go +++ b/x/liquidstakeibc/types/host_chain_test.go @@ -13,7 +13,6 @@ import ( ) func TestHostChain_GetHostChainTotalDelegations(t *testing.T) { - tests := []struct { name string hostChain func() types.HostChain @@ -121,8 +120,8 @@ func validHostChain() *types.HostChain { Active: false, AutoCompoundFactor: sdk.Dec{}, } - } + func makeVal(valoperAddr string) *types.Validator { return &types.Validator{ OperatorAddress: valoperAddr, diff --git a/x/liquidstakeibc/types/liquidstakeibc.go b/x/liquidstakeibc/types/liquidstakeibc.go index 7f726e90a..75eaa529a 100644 --- a/x/liquidstakeibc/types/liquidstakeibc.go +++ b/x/liquidstakeibc/types/liquidstakeibc.go @@ -71,7 +71,7 @@ func (hc *HostChain) Validate() error { if hc.MinimumDeposit.LT(sdk.ZeroInt()) { return fmt.Errorf("host chain %s has negative minimum deposit", hc.ChainId) } - if hc.CValue.LT(sdk.ZeroDec()) { //GT limits should be checked by module level params, invariants. + if hc.CValue.LT(sdk.ZeroDec()) { // GT limits should be checked by module level params, invariants. return fmt.Errorf("host chain %s has c value out of bounds: %d", hc.ChainId, hc.CValue) } diff --git a/x/liquidstakeibc/types/liquidstakeibc_test.go b/x/liquidstakeibc/types/liquidstakeibc_test.go index 657f1b2c8..9d11a9c9c 100644 --- a/x/liquidstakeibc/types/liquidstakeibc_test.go +++ b/x/liquidstakeibc/types/liquidstakeibc_test.go @@ -126,7 +126,8 @@ func TestDefaultRewardsAccountPortOwner(t *testing.T) { name: "valid", args: args{chainID: "chain-1"}, want: "chain-1.rewards", - }} + }, + } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := types.DefaultRewardsAccountPortOwner(tt.args.chainID); got != tt.want { @@ -173,7 +174,8 @@ func TestDeposit_Validate(t *testing.T) { IbcSequenceId: "", }, wantErr: true, - }, { + }, + { name: "invalid state", fields: fields{ ChainId: "chain-1", @@ -450,7 +452,8 @@ func TestUserUnbonding_Validate(t *testing.T) { UnbondAmount: invalidCoin, }, wantErr: true, - }, { + }, + { name: "invalid addr", fields: fields{ ChainId: "chain-1", @@ -590,7 +593,8 @@ func TestHostChainLSParams_Validate(t *testing.T) { RedemptionFee: sdk.ZeroDec(), }, wantErr: true, - }, { + }, + { name: "invalid unstake fee", fields: fields{ DepositFee: sdk.ZeroDec(), @@ -599,7 +603,8 @@ func TestHostChainLSParams_Validate(t *testing.T) { RedemptionFee: sdk.ZeroDec(), }, wantErr: true, - }, { + }, + { name: "invalid redemption fee", fields: fields{ DepositFee: sdk.ZeroDec(), @@ -650,7 +655,8 @@ func TestValidator_Validate(t *testing.T) { UnbondingEpoch: 0, }, wantErr: false, - }, { + }, + { name: "invalid operatorAddr", fields: fields{ OperatorAddress: "testval", @@ -661,7 +667,8 @@ func TestValidator_Validate(t *testing.T) { UnbondingEpoch: 0, }, wantErr: true, - }, { + }, + { name: "invalid status", fields: fields{ OperatorAddress: authtypes.NewModuleAddressOrBech32Address("testval").String(), @@ -672,7 +679,8 @@ func TestValidator_Validate(t *testing.T) { UnbondingEpoch: 0, }, wantErr: true, - }, { + }, + { name: "invalid weight", fields: fields{ OperatorAddress: authtypes.NewModuleAddressOrBech32Address("testval").String(), diff --git a/x/liquidstakeibc/types/msgs_test.go b/x/liquidstakeibc/types/msgs_test.go index fd6e053ba..dd3870944 100644 --- a/x/liquidstakeibc/types/msgs_test.go +++ b/x/liquidstakeibc/types/msgs_test.go @@ -44,6 +44,7 @@ func TestMsgLiquidStake(t *testing.T) { require.Error(t, invalidAddrMsg.ValidateBasic()) require.Panics(t, func() { invalidAddrMsg.GetSigners() }) } + func TestMsgLiquidStakeLSM(t *testing.T) { msgLiquidStakeLSM := &types.MsgLiquidStakeLSM{ DelegatorAddress: addr1.String(), @@ -72,6 +73,7 @@ func TestMsgLiquidStakeLSM(t *testing.T) { require.Error(t, invalidAddrMsg.ValidateBasic()) require.Panics(t, func() { invalidAddrMsg.GetSigners() }) } + func TestMsgLiquidUnstake(t *testing.T) { msgLiquidUnstake := &types.MsgLiquidUnstake{ DelegatorAddress: addr1.String(), @@ -101,6 +103,7 @@ func TestMsgLiquidUnstake(t *testing.T) { require.Error(t, invalidAddrMsg.ValidateBasic()) require.Panics(t, func() { invalidAddrMsg.GetSigners() }) } + func TestMsgRedeem(t *testing.T) { msgRedeem := &types.MsgRedeem{ DelegatorAddress: addr1.String(), @@ -392,5 +395,4 @@ func TestMsgUpdateParams(t *testing.T) { invalidParamsMsg := *msgUpdateParams invalidParamsMsg.Params.AdminAddress = "test" require.Error(t, invalidParamsMsg.ValidateBasic()) - } diff --git a/x/liquidstakeibc/types/params.go b/x/liquidstakeibc/types/params.go index 97025f96c..135877c97 100644 --- a/x/liquidstakeibc/types/params.go +++ b/x/liquidstakeibc/types/params.go @@ -19,7 +19,6 @@ func NewParams( upperCValueLimit sdktypes.Dec, lowerCValueLimit sdktypes.Dec, ) Params { - return Params{ AdminAddress: adminAddress, FeeAddress: feeAddress, diff --git a/x/lscosmos/types/msgs.go b/x/lscosmos/types/msgs.go index 99792c914..da46b92b7 100644 --- a/x/lscosmos/types/msgs.go +++ b/x/lscosmos/types/msgs.go @@ -54,7 +54,6 @@ func (m *MsgLiquidUnstake) ValidateBasic() error { // GetSignBytes encodes the message for signing func (m *MsgLiquidUnstake) GetSignBytes() []byte { return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(m)) - } // GetSigners defines whose signature is required @@ -80,7 +79,6 @@ func (m *MsgRedeem) ValidateBasic() error { // GetSignBytes encodes the message for signing func (m *MsgRedeem) GetSignBytes() []byte { return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(m)) - } // GetSigners defines whose signature is required diff --git a/x/ratesync/client/cli/tx.go b/x/ratesync/client/cli/tx.go index 2c89d4f43..548584fef 100644 --- a/x/ratesync/client/cli/tx.go +++ b/x/ratesync/client/cli/tx.go @@ -15,9 +15,7 @@ import ( "github.com/persistenceOne/pstake-native/v2/x/ratesync/types" ) -var ( - DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds()) -) +var DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds()) const ( flagPacketTimeoutTimestamp = "packet-timeout-timestamp" @@ -70,7 +68,6 @@ func CmdMsgUpdateParams() *cobra.Command { msg := types.NewMsgUpdateParams(authority.String(), params) return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, } @@ -124,7 +121,6 @@ func CmdUpdateChain() *cobra.Command { Short: "Update a chain", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { - // Get value arguments clientCtx, err := client.GetClientTxContext(cmd) diff --git a/x/ratesync/keeper/abci.go b/x/ratesync/keeper/abci.go index f27a027a2..ed318b0c4 100644 --- a/x/ratesync/keeper/abci.go +++ b/x/ratesync/keeper/abci.go @@ -8,7 +8,6 @@ import ( ) func (k *Keeper) BeginBlock(ctx sdk.Context) { - // perform BeginBlocker tasks for each chain for _, hc := range k.GetAllHostChain(ctx) { if !hc.IsActive() { @@ -21,7 +20,6 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) { // reset hc before going into next function, as it might have changed in earlier function // as we do not want to re-write and omit the last write. } - } func (k *Keeper) DoRecreateICA(ctx sdk.Context, hc types.HostChain) { diff --git a/x/ratesync/keeper/abci_test.go b/x/ratesync/keeper/abci_test.go index 7bc2d2d40..463008b00 100644 --- a/x/ratesync/keeper/abci_test.go +++ b/x/ratesync/keeper/abci_test.go @@ -28,5 +28,4 @@ func (suite *IntegrationTestSuite) TestDoRecreateICA() { suite.Require().NotPanics(func() { keeper.DoRecreateICA(ctx, hc) }) - } diff --git a/x/ratesync/keeper/chain.go b/x/ratesync/keeper/chain.go index 6afd82a01..c168173d4 100644 --- a/x/ratesync/keeper/chain.go +++ b/x/ratesync/keeper/chain.go @@ -41,7 +41,6 @@ func (k Keeper) SetHostChain(ctx sdk.Context, chain types.HostChain) { func (k Keeper) GetHostChain( ctx sdk.Context, id uint64, - ) (val types.HostChain, found bool) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.HostChainKeyPrefix) diff --git a/x/ratesync/keeper/chain_test.go b/x/ratesync/keeper/chain_test.go index 859501ea0..81473354e 100644 --- a/x/ratesync/keeper/chain_test.go +++ b/x/ratesync/keeper/chain_test.go @@ -41,7 +41,8 @@ var ValidHostChainInMsg = func(id uint64) types.HostChain { ContractAddress: "", Denoms: nil, Enabled: false, - }}, + }, + }, } } @@ -65,6 +66,7 @@ func (suite *IntegrationTestSuite) TestHostChainGet() { suite.Require().Equal(&item, &rst) } } + func (suite *IntegrationTestSuite) TestHostChainRemove() { keeper, ctx := suite.app.RatesyncKeeper, suite.ctx items := createNChain(keeper, ctx, 10) @@ -84,7 +86,6 @@ func (suite *IntegrationTestSuite) TestGetHostChainsByChainID() { items := createNChain(keeper, ctx, 10) suite.Require().ElementsMatch(items, keeper.GetAllHostChain(ctx)) suite.Require().ElementsMatch(items, keeper.GetHostChainsByChainID(ctx, "test-1")) - } func (suite *IntegrationTestSuite) TestHostChainGetAll() { diff --git a/x/ratesync/keeper/hooks.go b/x/ratesync/keeper/hooks.go index 03dbd6792..6a29a9379 100644 --- a/x/ratesync/keeper/hooks.go +++ b/x/ratesync/keeper/hooks.go @@ -26,6 +26,7 @@ func (h LiquidStakeIBCHooks) PostCValueUpdate(ctx sdk.Context, mintDenom, hostDe h.k.Logger(ctx).Info("called ratesync hook for PostCValueUpdate") return h.k.PostCValueUpdate(ctx, mintDenom, hostDenom, cValue) } + func (k Keeper) PostCValueUpdate(ctx sdk.Context, mintDenom, hostDenom string, cValue sdk.Dec) error { hcs := k.GetAllHostChain(ctx) for _, hc := range hcs { @@ -78,10 +79,10 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb "err:", err) } } - } return nil } + func (e EpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error { e.k.Logger(ctx).Info("called ratesync hook for BeforeEpochStart") return nil diff --git a/x/ratesync/keeper/hooks_test.go b/x/ratesync/keeper/hooks_test.go index ffb15a316..a96a13a61 100644 --- a/x/ratesync/keeper/hooks_test.go +++ b/x/ratesync/keeper/hooks_test.go @@ -12,10 +12,9 @@ func (suite *IntegrationTestSuite) TestPostCValueUpdate() { keeper.SetHostChain(ctx, hc) suite.Require().NoError(keeper.PostCValueUpdate(ctx, "uatom", "stk/uatom", sdk.OneDec())) - hc.ICAAccount.Address = "InvalidAddr" //outer functions do not return errors + hc.ICAAccount.Address = "InvalidAddr" // outer functions do not return errors keeper.SetHostChain(ctx, hc) suite.Require().NoError(keeper.PostCValueUpdate(ctx, "uatom", "stk/uatom", sdk.OneDec())) - } func (suite *IntegrationTestSuite) TestAfterEpochEnd() { diff --git a/x/ratesync/keeper/ibc.go b/x/ratesync/keeper/ibc.go index 7ebe33882..7f0a93a31 100644 --- a/x/ratesync/keeper/ibc.go +++ b/x/ratesync/keeper/ibc.go @@ -103,7 +103,6 @@ func (k *Keeper) OnAcknowledgementPacket( acknowledgement []byte, relayer sdk.AccAddress, ) error { - id, err := types.IDFromPortID(packet.SourcePort) if err != nil { // Port is not related to this module @@ -179,7 +178,6 @@ func (k *Keeper) OnTimeoutPacket( packet channeltypes.Packet, relayer sdk.AccAddress, ) error { - id, err := types.IDFromPortID(packet.SourcePort) if err != nil { // Port is not related to this module @@ -253,7 +251,7 @@ func (k *Keeper) handleUnsuccessfulAck( ) continue } - //reset instantiation state so can be retried. + // reset instantiation state so can be retried. switch icaMemo.FeatureType { case types.FeatureType_LIQUID_STAKE_IBC: hc.Features.LiquidStakeIBC.Instantiation = types.InstantiationState_INSTANTIATION_NOT_INITIATED @@ -283,7 +281,7 @@ func (k *Keeper) handleUnsuccessfulAck( ) continue } - //Do nothing, relay next epoch + // Do nothing, relay next epoch // emit an event for the execution confirmation ctx.EventManager().EmitEvent( diff --git a/x/ratesync/keeper/ibc_test.go b/x/ratesync/keeper/ibc_test.go index 41543f6bf..aa3fe7ae4 100644 --- a/x/ratesync/keeper/ibc_test.go +++ b/x/ratesync/keeper/ibc_test.go @@ -24,7 +24,7 @@ func (suite *IntegrationTestSuite) TestOnAcknowledgementPacket() { k, ctx := suite.app.RatesyncKeeper, suite.ctx _ = createNChain(k, ctx, 2) hc, _ := k.GetHostChain(ctx, 1) - //case 1, instantiate msg. + // case 1, instantiate msg. { msg, memo, err := keeper.GenerateInstantiateLiquidStakeContractMsg(hc.ICAAccount, hc.Features.LiquidStakeIBC, hc.ID) suite.Require().NoError(err) @@ -79,7 +79,7 @@ func (suite *IntegrationTestSuite) TestOnAcknowledgementPacket() { suite.Require().NoError(k.OnAcknowledgementPacket(ctx, packet, ackbz, authtypes.NewModuleAddress("test"))) } - //case 3, execute msg. + // case 3, execute msg. { msg, memo, err := keeper.GenerateExecuteLiquidStakeRateTxMsg(ctx.BlockTime().Unix(), hc.Features.LiquidStake, "stk/uatom", "uatom", sdk.OneDec(), hc.ID, hc.ICAAccount) @@ -139,7 +139,7 @@ func (suite *IntegrationTestSuite) TestOnTimeoutPacket() { k, ctx := suite.app.RatesyncKeeper, suite.ctx _ = createNChain(k, ctx, 2) hc, _ := k.GetHostChain(ctx, 1) - //case 1, instantiate msg. + // case 1, instantiate msg. { msg, memo, err := keeper.GenerateInstantiateLiquidStakeContractMsg(hc.ICAAccount, hc.Features.LiquidStakeIBC, hc.ID) suite.Require().NoError(err) @@ -158,7 +158,7 @@ func (suite *IntegrationTestSuite) TestOnTimeoutPacket() { } suite.Require().NoError(k.OnTimeoutPacket(ctx, packet, authtypes.NewModuleAddress("test"))) } - //case 2, execute msg. + // case 2, execute msg. { msg, memo, err := keeper.GenerateExecuteLiquidStakeRateTxMsg(ctx.BlockTime().Unix(), hc.Features.LiquidStake, "stk/uatom", "uatom", sdk.OneDec(), hc.ID, hc.ICAAccount) diff --git a/x/ratesync/keeper/ica_tx.go b/x/ratesync/keeper/ica_tx.go index 0980a4331..f5951f5c2 100644 --- a/x/ratesync/keeper/ica_tx.go +++ b/x/ratesync/keeper/ica_tx.go @@ -23,7 +23,6 @@ func (k *Keeper) GenerateAndExecuteICATx( messages []proto.Message, memo string, ) (icacontrollertypes.MsgSendTxResponse, error) { - msgData, err := icatypes.SerializeCosmosTx(k.cdc, messages) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("could not serialize tx data: %v", err)) @@ -100,7 +99,8 @@ func (k *Keeper) GenerateAndExecuteICATx( func (k *Keeper) ExecuteLiquidStakeRateTx(ctx sdk.Context, feature types.LiquidStake, mintDenom, hostDenom string, cValue sdk.Dec, hostchainId uint64, - connectionID string, icaAccount liquidstakeibctypes.ICAAccount) error { + connectionID string, icaAccount liquidstakeibctypes.ICAAccount, +) error { if feature.AllowsDenom(mintDenom) { msg, memoBz, err := GenerateExecuteLiquidStakeRateTxMsg(ctx.BlockTime().Unix(), feature, mintDenom, hostDenom, cValue, hostchainId, icaAccount) if err != nil { @@ -116,7 +116,8 @@ func (k *Keeper) ExecuteLiquidStakeRateTx(ctx sdk.Context, feature types.LiquidS func GenerateExecuteLiquidStakeRateTxMsg(blockTime int64, feature types.LiquidStake, mintDenom, hostDenom string, cValue sdk.Dec, hostchainId uint64, - icaAccount liquidstakeibctypes.ICAAccount) (sdk.Msg, []byte, error) { + icaAccount liquidstakeibctypes.ICAAccount, +) (sdk.Msg, []byte, error) { contractMsg := types.ExecuteLiquidStakeRate{ LiquidStakeRate: types.LiquidStakeRate{ DefaultBondDenom: hostDenom, @@ -142,13 +143,13 @@ func GenerateExecuteLiquidStakeRateTxMsg(blockTime int64, feature types.LiquidSt memoBz, err := json.Marshal(memo) if err != nil { return nil, nil, err - } return msg, memoBz, nil } func (k *Keeper) InstantiateLiquidStakeContract(ctx sdk.Context, icaAccount liquidstakeibctypes.ICAAccount, - feature types.LiquidStake, id uint64, connectionID string) error { + feature types.LiquidStake, id uint64, connectionID string, +) error { // generate contract msg{msg} msg, memoBz, err := GenerateInstantiateLiquidStakeContractMsg(icaAccount, feature, id) _, err = k.GenerateAndExecuteICATx(ctx, connectionID, icaAccount.Owner, []proto.Message{msg}, string(memoBz)) @@ -159,7 +160,8 @@ func (k *Keeper) InstantiateLiquidStakeContract(ctx sdk.Context, icaAccount liqu } func GenerateInstantiateLiquidStakeContractMsg(icaAccount liquidstakeibctypes.ICAAccount, - feature types.LiquidStake, id uint64) (sdk.Msg, []byte, error) { + feature types.LiquidStake, id uint64, +) (sdk.Msg, []byte, error) { contractMsg := types.InstantiateLiquidStakeRateContract{ Admin: icaAccount.Address, } diff --git a/x/ratesync/keeper/msg_server.go b/x/ratesync/keeper/msg_server.go index 5696d711c..5b5a65b75 100644 --- a/x/ratesync/keeper/msg_server.go +++ b/x/ratesync/keeper/msg_server.go @@ -137,7 +137,7 @@ func (k msgServer) UpdateHostChain(goCtx context.Context, msg *types.MsgUpdateHo isOneUpdated, updateStr = saveUpdate(fmt.Sprintf("updates host chain chainID %v to %v \n", oldHC.ChainID, msg.HostChain.ChainID)) } - //allow only one feature update per tx. + // allow only one feature update per tx. if !isOneUpdated && !msg.HostChain.Features.LiquidStakeIBC.Equals(oldHC.Features.LiquidStakeIBC) { if oldHC.Features.LiquidStakeIBC.Instantiation == types.InstantiationState_INSTANTIATION_NOT_INITIATED { // allow to add details and instantiate or just save if trying to recover. diff --git a/x/ratesync/keeper/msg_server_test.go b/x/ratesync/keeper/msg_server_test.go index d439623a0..672cdeaef 100644 --- a/x/ratesync/keeper/msg_server_test.go +++ b/x/ratesync/keeper/msg_server_test.go @@ -31,7 +31,8 @@ func (suite *IntegrationTestSuite) TestChainMsgServerCreate() { for i := 0; i < 5; i++ { hc := ValidHostChainInMsg(0) hc.ChainID = ctx.ChainID() - expected := &types.MsgCreateHostChain{Authority: GovAddress.String(), + expected := &types.MsgCreateHostChain{ + Authority: GovAddress.String(), HostChain: hc, } _, err := srv.CreateHostChain(wctx, expected) @@ -70,33 +71,38 @@ func (suite *IntegrationTestSuite) TestChainMsgServerUpdate() { }{ { desc: "Completed", - request: &types.MsgUpdateHostChain{Authority: GovAddress.String(), + request: &types.MsgUpdateHostChain{ + Authority: GovAddress.String(), HostChain: hc, }, }, { desc: "Unauthorized", - request: &types.MsgUpdateHostChain{Authority: "B", + request: &types.MsgUpdateHostChain{ + Authority: "B", HostChain: hc, }, err: sdkerrors.ErrorInvalidSigner, }, { desc: "KeyNotFound", - request: &types.MsgUpdateHostChain{Authority: GovAddress.String(), + request: &types.MsgUpdateHostChain{ + Authority: GovAddress.String(), HostChain: hc2, }, err: sdkerrors.ErrKeyNotFound, }, { desc: "Update feature", - request: &types.MsgUpdateHostChain{Authority: GovAddress.String(), + request: &types.MsgUpdateHostChain{ + Authority: GovAddress.String(), HostChain: hc3, }, }, { desc: "Update feature2", - request: &types.MsgUpdateHostChain{Authority: GovAddress.String(), + request: &types.MsgUpdateHostChain{ + Authority: GovAddress.String(), HostChain: hc4, }, }, @@ -105,7 +111,8 @@ func (suite *IntegrationTestSuite) TestChainMsgServerUpdate() { suite.T().Run(tc.desc, func(t *testing.T) { srv := keeper.NewMsgServerImpl(*k) wctx := sdk.WrapSDKContext(ctx) - expected := &types.MsgCreateHostChain{Authority: GovAddress.String(), + expected := &types.MsgCreateHostChain{ + Authority: GovAddress.String(), HostChain: hc, } @@ -137,21 +144,24 @@ func (suite *IntegrationTestSuite) TestChainMsgServerDelete() { }{ { desc: "Completed", - request: &types.MsgDeleteHostChain{Authority: GovAddress.String(), - ID: 1, + request: &types.MsgDeleteHostChain{ + Authority: GovAddress.String(), + ID: 1, }, }, { desc: "Unauthorized", - request: &types.MsgDeleteHostChain{Authority: "B", - ID: 2, + request: &types.MsgDeleteHostChain{ + Authority: "B", + ID: 2, }, err: sdkerrors.ErrorInvalidSigner, }, { desc: "KeyNotFound", - request: &types.MsgDeleteHostChain{Authority: GovAddress.String(), - ID: 10, + request: &types.MsgDeleteHostChain{ + Authority: GovAddress.String(), + ID: 10, }, err: sdkerrors.ErrKeyNotFound, }, @@ -185,14 +195,16 @@ func (suite *IntegrationTestSuite) TestChainMsgServerUpdateParams() { }{ { desc: "Completed", - request: &types.MsgUpdateParams{Authority: GovAddress.String(), - Params: types.Params{Admin: GovAddress.String()}, + request: &types.MsgUpdateParams{ + Authority: GovAddress.String(), + Params: types.Params{Admin: GovAddress.String()}, }, }, { desc: "Unauthorized", - request: &types.MsgUpdateParams{Authority: "B", - Params: types.Params{Admin: GovAddress.String()}, + request: &types.MsgUpdateParams{ + Authority: "B", + Params: types.Params{Admin: GovAddress.String()}, }, err: sdkerrors.ErrorInvalidSigner, }, diff --git a/x/ratesync/keeper/query.go b/x/ratesync/keeper/query.go index 82503ced5..dd0befe7b 100644 --- a/x/ratesync/keeper/query.go +++ b/x/ratesync/keeper/query.go @@ -43,7 +43,6 @@ func (k Keeper) AllHostChains(goCtx context.Context, req *types.QueryAllHostChai chains = append(chains, chain) return nil }) - if err != nil { return nil, status.Error(codes.Internal, err.Error()) } diff --git a/x/ratesync/keeper/setup_suite_test.go b/x/ratesync/keeper/setup_suite_test.go index f57faeb24..bf5093c33 100644 --- a/x/ratesync/keeper/setup_suite_test.go +++ b/x/ratesync/keeper/setup_suite_test.go @@ -48,9 +48,9 @@ type IntegrationTestSuite struct { govHandler govtypes.Handler coordinator *ibctesting.Coordinator - chainA *ibctesting.TestChain //pstake chain - chainB *ibctesting.TestChain //host chain, run tests of active chains - chainC *ibctesting.TestChain //host chain 2, run tests of to activate chains + chainA *ibctesting.TestChain // pstake chain + chainB *ibctesting.TestChain // host chain, run tests of active chains + chainC *ibctesting.TestChain // host chain 2, run tests of to activate chains transferPathAB *ibctesting.Path // chainA - chainB transfer path transferPathAC *ibctesting.Path // chainA - chainC transfer path @@ -63,7 +63,6 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *IntegrationTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 0) ibctesting.DefaultTestingAppInit = helpers.SetupTestingApp @@ -90,13 +89,13 @@ func (suite *IntegrationTestSuite) SetupTest() { suite.app = suite.chainA.App.(*app.PstakeApp) - //suite.SetupHostChainAB() + // suite.SetupHostChainAB() suite.SetupICAChannelsAB() suite.Transfer(suite.transferPathAB, sdk.NewCoin("uatom", sdk.NewInt(1000000000000))) suite.Transfer(suite.transferPathAC, sdk.NewCoin("uosmo", sdk.NewInt(1000000000000))) - //suite.SetupLSM() + // suite.SetupLSM() suite.CleanupSetup() suite.ctx = suite.chainA.GetContext() @@ -104,10 +103,11 @@ func (suite *IntegrationTestSuite) SetupTest() { func (suite *IntegrationTestSuite) CleanupSetup() { } + func (suite *IntegrationTestSuite) ResetEpochs() { ctx := suite.chainA.GetContext() - //ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) + // ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) epochsKeeper := suite.chainA.App.(*app.PstakeApp).EpochsKeeper for _, epoch := range epochsKeeper.AllEpochInfos(ctx) { @@ -132,6 +132,7 @@ func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { return path } + func (suite *IntegrationTestSuite) Transfer(path *ibctesting.Path, coin sdk.Coin) { transferMsg := ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coin, path.EndpointB.Chain.SenderAccount.GetAddress().String(), @@ -146,6 +147,7 @@ func (suite *IntegrationTestSuite) Transfer(path *ibctesting.Path, coin sdk.Coin err = path.RelayPacket(packet) suite.Require().NoError(err) } + func (suite *IntegrationTestSuite) SetupICAChannelsAB() { icapath := NewICAPath(suite.chainA, suite.chainB) icapath.EndpointA.ClientID = suite.transferPathAB.EndpointA.ClientID @@ -160,8 +162,8 @@ func (suite *IntegrationTestSuite) SetupICAChannelsAB() { err := suite.SetupICAPath(suite.ratesyncPathAB, types.DefaultPortOwner(1)) suite.Require().NoError(err) - } + func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { path := ibctesting.NewPath(chainA, chainB) path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID diff --git a/x/ratesync/module_ibc.go b/x/ratesync/module_ibc.go index de7566da5..ee92ad386 100644 --- a/x/ratesync/module_ibc.go +++ b/x/ratesync/module_ibc.go @@ -66,7 +66,6 @@ func (m IBCModule) OnChanOpenAck( return err } return m.appStack.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) - } func (m IBCModule) OnAcknowledgementPacket( diff --git a/x/ratesync/types/codec.go b/x/ratesync/types/codec.go index a9a3f267d..9e5fa9e9f 100644 --- a/x/ratesync/types/codec.go +++ b/x/ratesync/types/codec.go @@ -26,7 +26,6 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // this line is used by starport scaffolding # 3 msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) - } var ( diff --git a/x/ratesync/types/msgs.go b/x/ratesync/types/msgs.go index 9bccfbdf9..6bdd66f7d 100644 --- a/x/ratesync/types/msgs.go +++ b/x/ratesync/types/msgs.go @@ -58,7 +58,6 @@ var _ sdk.Msg = &MsgCreateHostChain{} func NewMsgCreateHostChain( authority string, hc HostChain, - ) *MsgCreateHostChain { return &MsgCreateHostChain{ Authority: authority, @@ -114,7 +113,6 @@ var _ sdk.Msg = &MsgUpdateHostChain{} func NewMsgUpdateHostChain( creator string, hc HostChain, - ) *MsgUpdateHostChain { return &MsgUpdateHostChain{ Authority: creator, @@ -166,13 +164,13 @@ var _ sdk.Msg = &MsgDeleteHostChain{} func NewMsgDeleteHostChain( creator string, id uint64, - ) *MsgDeleteHostChain { return &MsgDeleteHostChain{ Authority: creator, ID: id, } } + func (msg *MsgDeleteHostChain) Route() string { return RouterKey } diff --git a/x/ratesync/types/msgs_test.go b/x/ratesync/types/msgs_test.go index dbbc81830..52059cf35 100644 --- a/x/ratesync/types/msgs_test.go +++ b/x/ratesync/types/msgs_test.go @@ -39,7 +39,8 @@ var ValidHostChainInMsg = func(id uint64) HostChain { ContractAddress: "", Denoms: nil, Enabled: false, - }}, + }, + }, } } diff --git a/x/ratesync/types/types.go b/x/ratesync/types/types.go index 79a075502..54c652bf5 100644 --- a/x/ratesync/types/types.go +++ b/x/ratesync/types/types.go @@ -31,7 +31,7 @@ func (hc HostChain) ValidateBasic() error { if err != nil { return err } - //Make sure it matches default. + // Make sure it matches default. _, err = IDFromPortID(portID) if err != nil { return err @@ -134,18 +134,21 @@ func (lsConfig LiquidStake) ValdidateBasic() error { } return nil } + func (lsConfig LiquidStake) AllowsAllDenoms() bool { if len(lsConfig.Denoms) == 1 && lsConfig.Denoms[0] == LiquidStakeAllowAllDenoms { return true } return false } + func (lsConfig LiquidStake) AllowsDenom(denom string) bool { if lsConfig.AllowsAllDenoms() { return true } return slices.Contains(lsConfig.Denoms, denom) } + func (lsConfig LiquidStake) Equals(l2 LiquidStake) bool { if lsConfig.CodeID != l2.CodeID { return false @@ -174,12 +177,12 @@ func MustICAPortIDFromOwner(owner string) string { panic(err) } return id - } func DefaultPortOwner(id uint64) string { return fmt.Sprintf("%s%v", DefaultPortOwnerPrefix, id) } + func OwnerFromPortID(portID string) (string, error) { prefix := fmt.Sprintf("%s", icatypes.ControllerPortPrefix) idStr, found := strings.CutPrefix(portID, prefix) diff --git a/x/ratesync/types/types_test.go b/x/ratesync/types/types_test.go index 38d03d0d9..e38e6ccee 100644 --- a/x/ratesync/types/types_test.go +++ b/x/ratesync/types/types_test.go @@ -1,9 +1,10 @@ package types import ( + "testing" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/require" - "testing" liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" ) @@ -61,7 +62,7 @@ func TestTypes(t *testing.T) { features.LiquidStake.Enabled = true require.Error(t, features.ValdidateBasic()) - //liquidstakeFeature + // liquidstakeFeature lsfeature := ValidHostChainInMsg(0).Features.LiquidStake require.NoError(t, lsfeature.ValdidateBasic()) lsfeature.Instantiation = InstantiationState_INSTANTIATION_INITIATED @@ -74,7 +75,7 @@ func TestTypes(t *testing.T) { require.Error(t, lsfeature.ValdidateBasic()) lsfeature = ValidHostChainInMsg(0).Features.LiquidStake - lsfeature.CodeID = 1 //non zero + lsfeature.CodeID = 1 // non zero lsfeature.Instantiation = InstantiationState_INSTANTIATION_INITIATED require.NoError(t, lsfeature.ValdidateBasic()) lsfeature.Enabled = true @@ -83,7 +84,7 @@ func TestTypes(t *testing.T) { require.Error(t, lsfeature.ValdidateBasic()) lsfeature = ValidHostChainInMsg(0).Features.LiquidStake - lsfeature.CodeID = 1 //non zero + lsfeature.CodeID = 1 // non zero lsfeature.Instantiation = InstantiationState_INSTANTIATION_COMPLETED require.Error(t, lsfeature.ValdidateBasic()) lsfeature.ContractAddress = authtypes.NewModuleAddress("contract").String()