From c278d653dac90f48b526c521d2933ba427644bbb Mon Sep 17 00:00:00 2001 From: Charly Date: Wed, 17 Aug 2022 14:52:27 +0200 Subject: [PATCH 1/5] initial interface definition --- testing/app.go | 4 ++-- testing/chain.go | 2 +- testing/chain_test.go | 6 +++--- testing/types/expected_keepers.go | 22 ++++++++++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 testing/types/expected_keepers.go diff --git a/testing/app.go b/testing/app.go index 7cd218e010a..01e8169b5b1 100644 --- a/testing/app.go +++ b/testing/app.go @@ -16,7 +16,6 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -27,6 +26,7 @@ import ( "github.com/cosmos/ibc-go/v5/modules/core/keeper" "github.com/cosmos/ibc-go/v5/testing/simapp" + "github.com/cosmos/ibc-go/v5/testing/types" ) var DefaultTestingAppInit = SetupTestingApp @@ -36,7 +36,7 @@ type TestingApp interface { // ibc-go additions GetBaseApp() *baseapp.BaseApp - GetStakingKeeper() stakingkeeper.Keeper + GetIBCTestStakingKeeper() types.IBCTestingStakingKeeper GetIBCKeeper() *keeper.Keeper GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper GetTxConfig() client.TxConfig diff --git a/testing/chain.go b/testing/chain.go index 3cd574b4268..3df604d7c55 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -373,7 +373,7 @@ func (chain *TestChain) GetConsensusState(clientID string, height exported.Heigh // GetValsAtHeight will return the validator set of the chain at a given height. It will return // a success boolean depending on if the validator set exists or not at that height. func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bool) { - histInfo, ok := chain.App.GetStakingKeeper().GetHistoricalInfo(chain.GetContext(), height) + histInfo, ok := chain.App.GetIBCTestStakingKeeper().GetHistoricalInfo(chain.GetContext(), height) if !ok { return nil, false } diff --git a/testing/chain_test.go b/testing/chain_test.go index 6d2d32684fb..512b02be019 100644 --- a/testing/chain_test.go +++ b/testing/chain_test.go @@ -23,11 +23,11 @@ func TestChangeValSet(t *testing.T) { amount2, ok := sdk.NewIntFromString("30000000000000000000") require.True(t, ok) - val := chainA.App.GetStakingKeeper().GetValidators(chainA.GetContext(), 4) + val := chainA.App.GetIBCTestStakingKeeper().GetValidators(chainA.GetContext(), 4) - chainA.App.GetStakingKeeper().Delegate(chainA.GetContext(), chainA.SenderAccounts[1].SenderAccount.GetAddress(), + chainA.App.GetIBCTestStakingKeeper().Delegate(chainA.GetContext(), chainA.SenderAccounts[1].SenderAccount.GetAddress(), amount, types.Unbonded, val[1], true) - chainA.App.GetStakingKeeper().Delegate(chainA.GetContext(), chainA.SenderAccounts[3].SenderAccount.GetAddress(), + chainA.App.GetIBCTestStakingKeeper().Delegate(chainA.GetContext(), chainA.SenderAccounts[3].SenderAccount.GetAddress(), amount2, types.Unbonded, val[3], true) coord.CommitBlock(chainA) diff --git a/testing/types/expected_keepers.go b/testing/types/expected_keepers.go new file mode 100644 index 00000000000..a74b3b27dc5 --- /dev/null +++ b/testing/types/expected_keepers.go @@ -0,0 +1,22 @@ +package types + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// IBCTestingStakingKeeper defines the expected staking keeper interface used in the +// IBC testing package +type IBCTestingStakingKeeper interface { + GetValidators(ctx sdk.Context, maxRetrieve uint32) (validators []stakingtypes.Validator) + Delegate( + ctx sdk.Context, + delAddr sdk.AccAddress, + bondAmt math.Int, + tokenSrc stakingtypes.BondStatus, + validator stakingtypes.Validator, + subtractAccount bool, + ) (newShares sdk.Dec, err error) + GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool) +} From 4e374f5d38639eca1fe07b11853e82494e5a50c5 Mon Sep 17 00:00:00 2001 From: Charly Date: Thu, 18 Aug 2022 15:18:57 +0200 Subject: [PATCH 2/5] wip --- testing/chain_test.go | 6 +++--- testing/simapp/app.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/testing/chain_test.go b/testing/chain_test.go index 512b02be019..5ea1aec4aaa 100644 --- a/testing/chain_test.go +++ b/testing/chain_test.go @@ -23,11 +23,11 @@ func TestChangeValSet(t *testing.T) { amount2, ok := sdk.NewIntFromString("30000000000000000000") require.True(t, ok) - val := chainA.App.GetIBCTestStakingKeeper().GetValidators(chainA.GetContext(), 4) + val := chainA.GetSimApp().StakingKeeper.GetValidators(chainA.GetContext(), 4) - chainA.App.GetIBCTestStakingKeeper().Delegate(chainA.GetContext(), chainA.SenderAccounts[1].SenderAccount.GetAddress(), + chainA.GetSimApp().StakingKeeper.Delegate(chainA.GetContext(), chainA.SenderAccounts[1].SenderAccount.GetAddress(), amount, types.Unbonded, val[1], true) - chainA.App.GetIBCTestStakingKeeper().Delegate(chainA.GetContext(), chainA.SenderAccounts[3].SenderAccount.GetAddress(), + chainA.GetSimApp().StakingKeeper.Delegate(chainA.GetContext(), chainA.SenderAccounts[3].SenderAccount.GetAddress(), amount2, types.Unbonded, val[3], true) coord.CommitBlock(chainA) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 5b7d3fb8b53..ea2125160f9 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -108,6 +108,7 @@ import ( ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" ibcmock "github.com/cosmos/ibc-go/v5/testing/mock" simappparams "github.com/cosmos/ibc-go/v5/testing/simapp/params" + ibctestingtypes "github.com/cosmos/ibc-go/v5/testing/types" ) const appName = "SimApp" @@ -197,7 +198,7 @@ type SimApp struct { AccountKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper stakingkeeper.Keeper + StakingKeeper ibctestingtypes.IBCTestingStakingKeeper SlashingKeeper slashingkeeper.Keeper MintKeeper mintkeeper.Keeper DistrKeeper distrkeeper.Keeper @@ -748,7 +749,7 @@ func (app *SimApp) GetBaseApp() *baseapp.BaseApp { } // GetStakingKeeper implements the TestingApp interface. -func (app *SimApp) GetStakingKeeper() stakingkeeper.Keeper { +func (app *SimApp) GetIBCTestStakingKeeper() ibctestingtypes.IBCTestingStakingKeeper { return app.StakingKeeper } From 62916e140461682de3292b57135668f1f75134f9 Mon Sep 17 00:00:00 2001 From: Charly Date: Thu, 18 Aug 2022 16:29:46 +0200 Subject: [PATCH 3/5] update simapp --- testing/README.md | 2 +- testing/app.go | 4 ++-- testing/simapp/app.go | 4 ++-- testing/types/expected_keepers.go | 12 +----------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/testing/README.md b/testing/README.md index a488ffa42f1..89ee9825e3f 100644 --- a/testing/README.md +++ b/testing/README.md @@ -48,7 +48,7 @@ type TestingApp interface { // ibc-go additions GetBaseApp() *baseapp.BaseApp - GetStakingKeeper() stakingkeeper.Keeper + GetIBCTestStakingKeeper() ibctestingtypes.StakingKeeper GetIBCKeeper() *keeper.Keeper GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper GetTxConfig() client.TxConfig diff --git a/testing/app.go b/testing/app.go index 01e8169b5b1..58bac2e3f0b 100644 --- a/testing/app.go +++ b/testing/app.go @@ -26,7 +26,7 @@ import ( "github.com/cosmos/ibc-go/v5/modules/core/keeper" "github.com/cosmos/ibc-go/v5/testing/simapp" - "github.com/cosmos/ibc-go/v5/testing/types" + ibctestingtypes "github.com/cosmos/ibc-go/v5/testing/types" ) var DefaultTestingAppInit = SetupTestingApp @@ -36,7 +36,7 @@ type TestingApp interface { // ibc-go additions GetBaseApp() *baseapp.BaseApp - GetIBCTestStakingKeeper() types.IBCTestingStakingKeeper + GetIBCTestStakingKeeper() ibctestingtypes.StakingKeeper GetIBCKeeper() *keeper.Keeper GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper GetTxConfig() client.TxConfig diff --git a/testing/simapp/app.go b/testing/simapp/app.go index ea2125160f9..86244aff61a 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -198,7 +198,7 @@ type SimApp struct { AccountKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper ibctestingtypes.IBCTestingStakingKeeper + StakingKeeper stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper MintKeeper mintkeeper.Keeper DistrKeeper distrkeeper.Keeper @@ -749,7 +749,7 @@ func (app *SimApp) GetBaseApp() *baseapp.BaseApp { } // GetStakingKeeper implements the TestingApp interface. -func (app *SimApp) GetIBCTestStakingKeeper() ibctestingtypes.IBCTestingStakingKeeper { +func (app *SimApp) GetIBCTestStakingKeeper() ibctestingtypes.StakingKeeper { return app.StakingKeeper } diff --git a/testing/types/expected_keepers.go b/testing/types/expected_keepers.go index a74b3b27dc5..0a9a782454b 100644 --- a/testing/types/expected_keepers.go +++ b/testing/types/expected_keepers.go @@ -1,22 +1,12 @@ package types import ( - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // IBCTestingStakingKeeper defines the expected staking keeper interface used in the // IBC testing package -type IBCTestingStakingKeeper interface { - GetValidators(ctx sdk.Context, maxRetrieve uint32) (validators []stakingtypes.Validator) - Delegate( - ctx sdk.Context, - delAddr sdk.AccAddress, - bondAmt math.Int, - tokenSrc stakingtypes.BondStatus, - validator stakingtypes.Validator, - subtractAccount bool, - ) (newShares sdk.Dec, err error) +type StakingKeeper interface { GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool) } From d1d88daa6e4c3cd71c5066e3fb2c224652cc9b04 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 22 Aug 2022 15:50:05 +0200 Subject: [PATCH 4/5] updates re: comments --- CHANGELOG.md | 1 + testing/README.md | 2 +- testing/app.go | 2 +- testing/chain.go | 2 +- testing/simapp/app.go | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe94ea6e045..a1064619529 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking +* (testing)[\#2028](https://github.com/cosmos/ibc-go/pull/2028) New interface `ibctestingtypes.StakingKeeper` added and set for the testing app `StakingKeeper` setup. * (core/04-channel) [\#1418](https://github.com/cosmos/ibc-go/pull/1418) `NewPacketId` has been renamed to `NewPacketID` to comply with go linting rules. * (core/ante) [\#1418](https://github.com/cosmos/ibc-go/pull/1418) `AnteDecorator` has been renamed to `RedundancyDecorator` to comply with go linting rules and to give more clarity to the purpose of the Decorator. * (core/ante) [\#1820](https://github.com/cosmos/ibc-go/pull/1418) `RedundancyDecorator` has been renamed to `RedundantRelayDecorator` to make the name for explicit. diff --git a/testing/README.md b/testing/README.md index 89ee9825e3f..01e164e120b 100644 --- a/testing/README.md +++ b/testing/README.md @@ -48,7 +48,7 @@ type TestingApp interface { // ibc-go additions GetBaseApp() *baseapp.BaseApp - GetIBCTestStakingKeeper() ibctestingtypes.StakingKeeper + GetStakingKeeper() ibctestingtypes.StakingKeeper GetIBCKeeper() *keeper.Keeper GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper GetTxConfig() client.TxConfig diff --git a/testing/app.go b/testing/app.go index 58bac2e3f0b..2c41021f504 100644 --- a/testing/app.go +++ b/testing/app.go @@ -36,7 +36,7 @@ type TestingApp interface { // ibc-go additions GetBaseApp() *baseapp.BaseApp - GetIBCTestStakingKeeper() ibctestingtypes.StakingKeeper + GetStakingKeeper() ibctestingtypes.StakingKeeper GetIBCKeeper() *keeper.Keeper GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper GetTxConfig() client.TxConfig diff --git a/testing/chain.go b/testing/chain.go index 3df604d7c55..3cd574b4268 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -373,7 +373,7 @@ func (chain *TestChain) GetConsensusState(clientID string, height exported.Heigh // GetValsAtHeight will return the validator set of the chain at a given height. It will return // a success boolean depending on if the validator set exists or not at that height. func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bool) { - histInfo, ok := chain.App.GetIBCTestStakingKeeper().GetHistoricalInfo(chain.GetContext(), height) + histInfo, ok := chain.App.GetStakingKeeper().GetHistoricalInfo(chain.GetContext(), height) if !ok { return nil, false } diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 86244aff61a..d060ecdc092 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -749,7 +749,7 @@ func (app *SimApp) GetBaseApp() *baseapp.BaseApp { } // GetStakingKeeper implements the TestingApp interface. -func (app *SimApp) GetIBCTestStakingKeeper() ibctestingtypes.StakingKeeper { +func (app *SimApp) GetStakingKeeper() ibctestingtypes.StakingKeeper { return app.StakingKeeper } From b27f8e56d24a4a6a2f78b53cd0f82783f3fdfb87 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 22 Aug 2022 17:17:38 +0200 Subject: [PATCH 5/5] update godocs --- testing/types/expected_keepers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/types/expected_keepers.go b/testing/types/expected_keepers.go index 0a9a782454b..07034b57a25 100644 --- a/testing/types/expected_keepers.go +++ b/testing/types/expected_keepers.go @@ -5,7 +5,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -// IBCTestingStakingKeeper defines the expected staking keeper interface used in the +// StakingKeeper defines the expected staking keeper interface used in the // IBC testing package type StakingKeeper interface { GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool)