From 22a2ed3276c114f40d155bfd981e11b23946c7ab Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 11:12:12 +0100 Subject: [PATCH 01/23] Adds TODO to remove hack --- x/ccv/parent/parent_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/ccv/parent/parent_test.go b/x/ccv/parent/parent_test.go index f50cef8f8a..d4cb3f4cd2 100644 --- a/x/ccv/parent/parent_test.go +++ b/x/ccv/parent/parent_test.go @@ -36,6 +36,9 @@ import ( ) func init() { + /* + TODO: This overwrites a default param so it's pretty hacky and should be removed + */ ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp } From a84b12508aa46d3a2aa4154b6cf4cf187c912214 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 14:00:11 +0100 Subject: [PATCH 02/23] Replaces ibg-go with local version for dev --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 269441f32b..b03138e405 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 - github.com/cosmos/ibc-go/v3 => github.com/informalsystems/ibc-go/v3 v3.0.0-alpha1.0.20220405190259-988da4519455 + github.com/cosmos/ibc-go/v3 => /Users/danwt/Documents/work/ibc-go github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 google.golang.org/grpc => google.golang.org/grpc v1.33.2 ) From 31a67d2ca202dfd62a9ae414f3e626b1825800a2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 15:53:26 +0100 Subject: [PATCH 03/23] (nobuild) makes minimal changes to allow 2 app.go --- testutil/simapp/simapp.go | 22 +++++++++++++++++++++- x/ccv/parent/parent_test.go | 14 +++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index 1f3674e2a6..4caddcdb15 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -2,6 +2,7 @@ package simapp import ( "encoding/json" + "testing" "time" "github.com/cosmos/cosmos-sdk/simapp" @@ -52,10 +53,29 @@ var defaultConsensusParams = &abci.ConsensusParams{ }, } -func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { +func SetupTestingParentApp() (ibctesting.TestingApp, map[string]json.RawMessage) { db := tmdb.NewMemDB() // encCdc := app.MakeTestEncodingConfig() encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) testApp := app.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) return testApp, app.NewDefaultGenesisState(encoding.Marshaler) } + +func SetupTestingChildApp() (ibctesting.TestingApp, map[string]json.RawMessage) { + db := tmdb.NewMemDB() + // encCdc := app.MakeTestEncodingConfig() + encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) + testApp := app.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) + return testApp, app.NewDefaultGenesisState(encoding.Marshaler) +} + +// NewCoordinator initializes Coordinator with 0 TestChains +func NewBasicCoordinator(t *testing.T) *ibctesting.Coordinator { + chains := make(map[string]*ibctesting.TestChain) + coord := &ibctesting.Coordinator{ + T: t, + CurrentTime: ibctesting.GlobalStartTime, + } + coord.Chains = chains + return coord +} diff --git a/x/ccv/parent/parent_test.go b/x/ccv/parent/parent_test.go index d4cb3f4cd2..39ea255fb4 100644 --- a/x/ccv/parent/parent_test.go +++ b/x/ccv/parent/parent_test.go @@ -63,11 +63,15 @@ type ParentTestSuite struct { } func (suite *ParentTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 1) - suite.parentChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - // create child chain with parent chain valset - suite.CreateChildChain() - suite.childChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.coordinator = simapp.NewBasicCoordinator(suite.T()) + chainID := ibctesting.GetChainID(0) + suite.coordinator.Chains[chainID] = ibctesting.NewTestChain(suite.T(), suite.coordinator, simapp.SetupTestingParentApp, chainID) + suite.parentChain = suite.coordinator.GetChain(chainID) + chainID = ibctesting.GetChainID(1) + suite.coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(suite.T(), suite.coordinator, + simapp.SetupTestingChildApp, chainID, suite.parentChain.Vals, suite.parentChain.Signers) + suite.childChain = suite.coordinator.GetChain(chainID) + suite.DisableConsumerDistribution() tmConfig := ibctesting.NewTendermintConfig() From e766d6eafc549c0d2580a0d4e5306ae92f089c62 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 16:06:48 +0100 Subject: [PATCH 04/23] Use NewParentChildCoordinator in tests Reuse a shared util function instead of overwriting global variable --- testutil/simapp/simapp.go | 13 +++++++++++++ x/ccv/child/keeper/keeper_test.go | 5 +---- x/ccv/child/module_test.go | 8 +------- x/ccv/parent/keeper/keeper_test.go | 5 +---- x/ccv/parent/parent_test.go | 25 ++----------------------- 5 files changed, 18 insertions(+), 38 deletions(-) diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index 4caddcdb15..b6807597f1 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -79,3 +79,16 @@ func NewBasicCoordinator(t *testing.T) *ibctesting.Coordinator { coord.Chains = chains return coord } + +// NewCoordinator initializes Coordinator with 0 TestChains +func NewParentChildCoordinator(t *testing.T) (*ibctesting.Coordinator, *ibctesting.TestChain, *ibctesting.TestChain) { + coordinator := NewBasicCoordinator(t) + chainID := ibctesting.GetChainID(0) + coordinator.Chains[chainID] = ibctesting.NewTestChain(t, coordinator, SetupTestingParentApp, chainID) + parentChain := coordinator.GetChain(chainID) + chainID = ibctesting.GetChainID(1) + coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(t, coordinator, + SetupTestingChildApp, chainID, parentChain.Vals, parentChain.Signers) + childChain := coordinator.GetChain(chainID) + return coordinator, parentChain, childChain +} diff --git a/x/ccv/child/keeper/keeper_test.go b/x/ccv/child/keeper/keeper_test.go index ead061414a..4ea0bf8ec6 100644 --- a/x/ccv/child/keeper/keeper_test.go +++ b/x/ccv/child/keeper/keeper_test.go @@ -23,10 +23,6 @@ import ( tmtypes "github.com/tendermint/tendermint/types" ) -func init() { - ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp -} - type KeeperTestSuite struct { suite.Suite @@ -48,6 +44,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) suite.parentChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) suite.childChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) tmConfig := ibctesting.NewTendermintConfig() diff --git a/x/ccv/child/module_test.go b/x/ccv/child/module_test.go index d369599ebe..e53dbbcb9e 100644 --- a/x/ccv/child/module_test.go +++ b/x/ccv/child/module_test.go @@ -26,10 +26,6 @@ import ( "github.com/stretchr/testify/suite" ) -func init() { - ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp -} - type ChildTestSuite struct { suite.Suite @@ -48,9 +44,7 @@ type ChildTestSuite struct { } func (suite *ChildTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.parentChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.childChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) tmConfig := ibctesting.NewTendermintConfig() diff --git a/x/ccv/parent/keeper/keeper_test.go b/x/ccv/parent/keeper/keeper_test.go index 7dd508fdd9..8244e3f3b4 100644 --- a/x/ccv/parent/keeper/keeper_test.go +++ b/x/ccv/parent/keeper/keeper_test.go @@ -22,10 +22,6 @@ import ( "github.com/stretchr/testify/suite" ) -func init() { - ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp -} - type KeeperTestSuite struct { suite.Suite @@ -47,6 +43,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) suite.parentChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) suite.childChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) tmConfig := ibctesting.NewTendermintConfig() diff --git a/x/ccv/parent/parent_test.go b/x/ccv/parent/parent_test.go index 39ea255fb4..340e308c27 100644 --- a/x/ccv/parent/parent_test.go +++ b/x/ccv/parent/parent_test.go @@ -2,7 +2,6 @@ package parent_test import ( "fmt" - "strconv" "testing" "time" @@ -35,13 +34,6 @@ import ( "github.com/stretchr/testify/suite" ) -func init() { - /* - TODO: This overwrites a default param so it's pretty hacky and should be removed - */ - ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp -} - type ParentTestSuite struct { suite.Suite @@ -63,14 +55,8 @@ type ParentTestSuite struct { } func (suite *ParentTestSuite) SetupTest() { - suite.coordinator = simapp.NewBasicCoordinator(suite.T()) - chainID := ibctesting.GetChainID(0) - suite.coordinator.Chains[chainID] = ibctesting.NewTestChain(suite.T(), suite.coordinator, simapp.SetupTestingParentApp, chainID) - suite.parentChain = suite.coordinator.GetChain(chainID) - chainID = ibctesting.GetChainID(1) - suite.coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(suite.T(), suite.coordinator, - simapp.SetupTestingChildApp, chainID, suite.parentChain.Vals, suite.parentChain.Signers) - suite.childChain = suite.coordinator.GetChain(chainID) + + suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) suite.DisableConsumerDistribution() @@ -164,13 +150,6 @@ func (suite *ParentTestSuite) SetupCCVChannel() { suite.transferPath.EndpointA.UpdateClient() } -func (s *ParentTestSuite) CreateChildChain() { - parent := s.parentChain - chainID := ibctesting.ChainIDPrefix + strconv.Itoa(len(s.coordinator.Chains)+1) - child := ibctesting.NewTestChainWithValSet(s.T(), s.coordinator, chainID, parent.Vals, parent.Signers) - s.coordinator.Chains[child.ChainID] = child -} - func TestParentTestSuite(t *testing.T) { suite.Run(t, new(ParentTestSuite)) } From aa2df7216d1a2bfeb5026426b8256b35fc9624af Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 16:47:56 +0100 Subject: [PATCH 05/23] Use seperate cmd binaries for p and c --- .../main.go | 0 cmd/interchain-security-pd/main.go | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+) rename cmd/{interchain-securityd => interchain-security-cd}/main.go (100%) create mode 100644 cmd/interchain-security-pd/main.go diff --git a/cmd/interchain-securityd/main.go b/cmd/interchain-security-cd/main.go similarity index 100% rename from cmd/interchain-securityd/main.go rename to cmd/interchain-security-cd/main.go diff --git a/cmd/interchain-security-pd/main.go b/cmd/interchain-security-pd/main.go new file mode 100644 index 0000000000..554f2ada55 --- /dev/null +++ b/cmd/interchain-security-pd/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "os" + + "github.com/cosmos/cosmos-sdk/server" + svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + "github.com/cosmos/interchain-security/app" + "github.com/tendermint/spm/cosmoscmd" +) + +func main() { + rootCmd, _ := cosmoscmd.NewRootCmd( + app.AppName, + app.AccountAddressPrefix, + app.DefaultNodeHome, + app.AppName, + app.ModuleBasics, + app.New, + // this line is used by starport scaffolding # root/arguments + ) + + if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil { + switch e := err.(type) { + case server.ErrorCode: + os.Exit(e.Code) + + default: + os.Exit(1) + } + } +} From 6c65d9240b44a7b19840b5bef55cf70ca349797d Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 16:56:54 +0100 Subject: [PATCH 06/23] (nobuild) simply dup app/ dir for parent, child --- {app => app_child}/ante_handler.go | 0 {app => app_child}/app.go | 0 {app => app_child}/export.go | 0 {app => app_child}/genesis.go | 0 app_parent/ante_handler.go | 54 ++ app_parent/app.go | 954 +++++++++++++++++++++++++++++ app_parent/export.go | 185 ++++++ app_parent/genesis.go | 21 + cmd/interchain-security-cd/main.go | 2 +- cmd/interchain-security-pd/main.go | 2 +- 10 files changed, 1216 insertions(+), 2 deletions(-) rename {app => app_child}/ante_handler.go (100%) rename {app => app_child}/app.go (100%) rename {app => app_child}/export.go (100%) rename {app => app_child}/genesis.go (100%) create mode 100644 app_parent/ante_handler.go create mode 100644 app_parent/app.go create mode 100644 app_parent/export.go create mode 100644 app_parent/genesis.go diff --git a/app/ante_handler.go b/app_child/ante_handler.go similarity index 100% rename from app/ante_handler.go rename to app_child/ante_handler.go diff --git a/app/app.go b/app_child/app.go similarity index 100% rename from app/app.go rename to app_child/app.go diff --git a/app/export.go b/app_child/export.go similarity index 100% rename from app/export.go rename to app_child/export.go diff --git a/app/genesis.go b/app_child/genesis.go similarity index 100% rename from app/genesis.go rename to app_child/genesis.go diff --git a/app_parent/ante_handler.go b/app_parent/ante_handler.go new file mode 100644 index 0000000000..9066af69f3 --- /dev/null +++ b/app_parent/ante_handler.go @@ -0,0 +1,54 @@ +package app + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + channelkeeper "github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper" + ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante" +) + +// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC +// channel keeper. +type HandlerOptions struct { + ante.HandlerOptions + + IBCChannelkeeper channelkeeper.Keeper +} + +func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { + if options.AccountKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + } + if options.BankKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + } + if options.SignModeHandler == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + } + + var sigGasConsumer = options.SigGasConsumer + if sigGasConsumer == nil { + sigGasConsumer = ante.DefaultSigVerificationGasConsumer + } + + anteDecorators := []sdk.AnteDecorator{ + ante.NewSetUpContextDecorator(), + ante.NewRejectExtensionOptionsDecorator(), + ante.NewMempoolFeeDecorator(), + ante.NewValidateBasicDecorator(), + ante.NewTxTimeoutHeightDecorator(), + ante.NewValidateMemoDecorator(options.AccountKeeper), + ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), + ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper), + // SetPubKeyDecorator must be called before all signature verification decorators + ante.NewSetPubKeyDecorator(options.AccountKeeper), + ante.NewValidateSigCountDecorator(options.AccountKeeper), + ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), + ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), + ante.NewIncrementSequenceDecorator(options.AccountKeeper), + ibcante.NewAnteDecorator(options.IBCChannelkeeper), + } + + return sdk.ChainAnteDecorators(anteDecorators...), nil +} diff --git a/app_parent/app.go b/app_parent/app.go new file mode 100644 index 0000000000..e738980a49 --- /dev/null +++ b/app_parent/app.go @@ -0,0 +1,954 @@ +package app + +import ( + "fmt" + "io" + stdlog "log" + "net/http" + "os" + "path/filepath" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" + "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/server/api" + "github.com/cosmos/cosmos-sdk/server/config" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/simapp" + store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/version" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + "github.com/cosmos/cosmos-sdk/x/authz" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" + "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/capability" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distr "github.com/cosmos/cosmos-sdk/x/distribution" + distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/evidence" + evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" + feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/gov" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/mint" + mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/params" + paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/x/upgrade" + upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/ibc-go/v3/modules/apps/transfer" + ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v3/modules/core" + ibcclient "github.com/cosmos/ibc-go/v3/modules/core/02-client" + ibcclientclient "github.com/cosmos/ibc-go/v3/modules/core/02-client/client" + ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" + ibcconnectiontypes "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types" + porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types" + ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host" + ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" + ibctesting "github.com/cosmos/ibc-go/v3/testing" + + "github.com/gorilla/mux" + "github.com/gravity-devs/liquidity/x/liquidity" + liquiditykeeper "github.com/gravity-devs/liquidity/x/liquidity/keeper" + liquiditytypes "github.com/gravity-devs/liquidity/x/liquidity/types" + "github.com/rakyll/statik/fs" + "github.com/spf13/cast" + abci "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" + tmos "github.com/tendermint/tendermint/libs/os" + dbm "github.com/tendermint/tm-db" + + ibcchild "github.com/cosmos/interchain-security/x/ccv/child" + ibcchildkeeper "github.com/cosmos/interchain-security/x/ccv/child/keeper" + ibcchildtypes "github.com/cosmos/interchain-security/x/ccv/child/types" + ibcparent "github.com/cosmos/interchain-security/x/ccv/parent" + ibcparentclient "github.com/cosmos/interchain-security/x/ccv/parent/client" + ibcparentkeeper "github.com/cosmos/interchain-security/x/ccv/parent/keeper" + ibcparenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" + + "github.com/tendermint/spm/cosmoscmd" + + // unnamed import of statik for swagger UI support + _ "github.com/cosmos/cosmos-sdk/client/docs/statik" +) + +const ( + AppName = "interchain-security" + upgradeName = "v07-Theta" + AccountAddressPrefix = "cosmos" +) + +// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals + +func getGovProposalHandlers() []govclient.ProposalHandler { + var govProposalHandlers []govclient.ProposalHandler + // this line is used by starport scaffolding # stargate/app/govProposalHandlers + + govProposalHandlers = append(govProposalHandlers, + paramsclient.ProposalHandler, + distrclient.ProposalHandler, + upgradeclient.ProposalHandler, + upgradeclient.CancelProposalHandler, + ibcparentclient.ProposalHandler, + // this line is used by starport scaffolding # stargate/app/govProposalHandler + ) + + return govProposalHandlers +} + +var ( + // DefaultNodeHome default home directories for the application daemon + DefaultNodeHome string + + // ModuleBasics defines the module BasicManager is in charge of setting up basic, + // non-dependant module elements, such as codec registration + // and genesis verification. + ModuleBasics = module.NewBasicManager( + auth.AppModuleBasic{}, + genutil.AppModuleBasic{}, + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + staking.AppModuleBasic{}, + mint.AppModuleBasic{}, + distr.AppModuleBasic{}, + gov.NewAppModuleBasic( + paramsclient.ProposalHandler, + distrclient.ProposalHandler, + upgradeclient.ProposalHandler, + upgradeclient.CancelProposalHandler, + ibcclientclient.UpdateClientProposalHandler, + ibcclientclient.UpgradeProposalHandler, + ibcparentclient.ProposalHandler, + ), + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, + ibc.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + transfer.AppModuleBasic{}, + vesting.AppModuleBasic{}, + liquidity.AppModuleBasic{}, + //router.AppModuleBasic{}, + ibcchild.AppModuleBasic{}, + ibcparent.AppModuleBasic{}, + ) + + // module account permissions + maccPerms = map[string][]string{ + authtypes.FeeCollectorName: nil, + ibcchildtypes.ConsumerRedistributeName: nil, + ibcchildtypes.ConsumerToSendToProviderName: nil, + distrtypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + } +) + +var ( + _ simapp.App = (*App)(nil) + _ servertypes.Application = (*App)(nil) + _ cosmoscmd.CosmosApp = (*App)(nil) + _ ibctesting.TestingApp = (*App)(nil) +) + +// App extends an ABCI application, but with most of its parameters exported. +// They are exported for convenience in creating helper functions, as object +// capabilities aren't needed for testing. +type App struct { // nolint: golint + *baseapp.BaseApp + legacyAmino *codec.LegacyAmino + appCodec codec.Codec + interfaceRegistry types.InterfaceRegistry + + invCheckPeriod uint + + // keys to access the substores + keys map[string]*sdk.KVStoreKey + tkeys map[string]*sdk.TransientStoreKey + memKeys map[string]*sdk.MemoryStoreKey + + // keepers + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + + // NOTE the distribution keeper should either be removed + // from consumer chain or set to use an independant + // different fee-pool from the consumer chain ChildKeeper + DistrKeeper distrkeeper.Keeper + + GovKeeper govkeeper.Keeper + CrisisKeeper crisiskeeper.Keeper + UpgradeKeeper upgradekeeper.Keeper + ParamsKeeper paramskeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + AuthzKeeper authzkeeper.Keeper + LiquidityKeeper liquiditykeeper.Keeper + ChildKeeper ibcchildkeeper.Keeper + ParentKeeper ibcparentkeeper.Keeper + + // make scoped keepers public for test purposes + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedIBCChildKeeper capabilitykeeper.ScopedKeeper + ScopedIBCParentKeeper capabilitykeeper.ScopedKeeper + + // the module manager + MM *module.Manager + + // simulation manager + sm *module.SimulationManager + configurator module.Configurator +} + +func init() { + userHomeDir, err := os.UserHomeDir() + if err != nil { + stdlog.Println("Failed to get home dir %2", err) + } + + DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName) +} + +// New returns a reference to an initialized App. +func New( + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + loadLatest bool, + skipUpgradeHeights map[int64]bool, + homePath string, + invCheckPeriod uint, + encodingConfig cosmoscmd.EncodingConfig, + appOpts servertypes.AppOptions, + baseAppOptions ...func(*baseapp.BaseApp), +) cosmoscmd.App { + + appCodec := encodingConfig.Marshaler + legacyAmino := encodingConfig.Amino + interfaceRegistry := encodingConfig.InterfaceRegistry + + bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) + bApp.SetCommitMultiStoreTracer(traceStore) + bApp.SetVersion(version.Version) + bApp.SetInterfaceRegistry(interfaceRegistry) + + keys := sdk.NewKVStoreKeys( + authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, + evidencetypes.StoreKey, liquiditytypes.StoreKey, ibctransfertypes.StoreKey, + capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, + ibcchildtypes.StoreKey, ibcparenttypes.StoreKey, + ) + tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, stakingtypes.TStoreKey) + memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + + app := &App{ + BaseApp: bApp, + legacyAmino: legacyAmino, + appCodec: appCodec, + interfaceRegistry: interfaceRegistry, + invCheckPeriod: invCheckPeriod, + keys: keys, + tkeys: tkeys, + memKeys: memKeys, + } + + app.ParamsKeeper = initParamsKeeper( + appCodec, + legacyAmino, + keys[paramstypes.StoreKey], + tkeys[paramstypes.TStoreKey], + ) + + // set the BaseApp's parameter store + bApp.SetParamStore( + app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable( + paramskeeper.ConsensusParamsKeyTable()), + ) + + // add capability keeper and ScopeToModule for ibc module + app.CapabilityKeeper = capabilitykeeper.NewKeeper( + appCodec, + keys[capabilitytypes.StoreKey], + memKeys[capabilitytypes.MemStoreKey], + ) + scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) + scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedIBCChildKeeper := app.CapabilityKeeper.ScopeToModule(ibcchildtypes.ModuleName) + scopedIBCParentKeeper := app.CapabilityKeeper.ScopeToModule(ibcparenttypes.ModuleName) + app.CapabilityKeeper.Seal() + + // add keepers + app.AccountKeeper = authkeeper.NewAccountKeeper( + appCodec, + keys[authtypes.StoreKey], + app.GetSubspace(authtypes.ModuleName), + authtypes.ProtoBaseAccount, + maccPerms, + ) + + // Remove the fee-pool from the group of blocked recipient addresses in bank + // this is required for the provider chain to be able to receive tokens from + // the consumer chain + bankBlockedAddrs := app.ModuleAccountAddrs() + delete(bankBlockedAddrs, authtypes.NewModuleAddress( + authtypes.FeeCollectorName).String()) + + app.BankKeeper = bankkeeper.NewBaseKeeper( + appCodec, + keys[banktypes.StoreKey], + app.AccountKeeper, + app.GetSubspace(banktypes.ModuleName), + bankBlockedAddrs, + ) + app.AuthzKeeper = authzkeeper.NewKeeper( + keys[authzkeeper.StoreKey], + appCodec, + app.BaseApp.MsgServiceRouter(), + ) + app.FeeGrantKeeper = feegrantkeeper.NewKeeper( + appCodec, + keys[feegrant.StoreKey], + app.AccountKeeper, + ) + stakingKeeper := stakingkeeper.NewKeeper( + appCodec, + keys[stakingtypes.StoreKey], + tkeys[stakingtypes.TStoreKey], + app.AccountKeeper, + app.BankKeeper, + app.GetSubspace(stakingtypes.ModuleName), + ) + app.MintKeeper = mintkeeper.NewKeeper( + appCodec, + keys[minttypes.StoreKey], + app.GetSubspace(minttypes.ModuleName), + &stakingKeeper, + app.AccountKeeper, + app.BankKeeper, + authtypes.FeeCollectorName, + ) + app.DistrKeeper = distrkeeper.NewKeeper( + appCodec, + keys[distrtypes.StoreKey], + app.GetSubspace(distrtypes.ModuleName), + app.AccountKeeper, + app.BankKeeper, + &stakingKeeper, + authtypes.FeeCollectorName, + app.ModuleAccountAddrs(), + ) + app.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, + keys[slashingtypes.StoreKey], + &stakingKeeper, + app.GetSubspace(slashingtypes.ModuleName), + ) + app.CrisisKeeper = crisiskeeper.NewKeeper( + app.GetSubspace(crisistypes.ModuleName), + invCheckPeriod, + app.BankKeeper, + authtypes.FeeCollectorName, + ) + app.UpgradeKeeper = upgradekeeper.NewKeeper( + skipUpgradeHeights, + keys[upgradetypes.StoreKey], + appCodec, + homePath, + app.BaseApp, + ) + app.LiquidityKeeper = liquiditykeeper.NewKeeper( + appCodec, + keys[liquiditytypes.StoreKey], + app.GetSubspace(liquiditytypes.ModuleName), + app.BankKeeper, + app.AccountKeeper, + app.DistrKeeper, + ) + + // register the staking hooks + // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks + app.StakingKeeper = *stakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), + app.SlashingKeeper.Hooks(), + app.ParentKeeper.Hooks(), + ), + ) + + app.IBCKeeper = ibckeeper.NewKeeper( + appCodec, + keys[ibchost.StoreKey], + app.GetSubspace(ibchost.ModuleName), + app.StakingKeeper, + app.UpgradeKeeper, + scopedIBCKeeper, + ) + + // Create CCV child and parent keepers and modules + app.ChildKeeper = ibcchildkeeper.NewKeeper( + appCodec, + keys[ibcchildtypes.StoreKey], + app.GetSubspace(ibcchildtypes.ModuleName), + scopedIBCChildKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.IBCKeeper.ConnectionKeeper, + app.IBCKeeper.ClientKeeper, + app.SlashingKeeper, + app.BankKeeper, + app.AccountKeeper, + &app.TransferKeeper, + app.IBCKeeper, + authtypes.FeeCollectorName, + ) + + app.ParentKeeper = ibcparentkeeper.NewKeeper( + appCodec, + keys[ibcparenttypes.StoreKey], + app.GetSubspace(ibcparenttypes.ModuleName), + scopedIBCParentKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.IBCKeeper.ConnectionKeeper, + app.IBCKeeper.ClientKeeper, + app.StakingKeeper, + app.SlashingKeeper, + app.AccountKeeper, + authtypes.FeeCollectorName, + ) + parentModule := ibcparent.NewAppModule(&app.ParentKeeper) + + // child keeper satisfies the staking keeper interface + // of the slashing module + app.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, + keys[slashingtypes.StoreKey], + app.ChildKeeper, + app.GetSubspace(slashingtypes.ModuleName), + ) + + // register slashing module StakingHooks to the child keeper + app.ChildKeeper = *app.ChildKeeper.SetHooks(app.SlashingKeeper.Hooks()) + childModule := ibcchild.NewAppModule(app.ChildKeeper) + + // register the proposal types + govRouter := govtypes.NewRouter() + govRouter. + AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). + AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). + AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). + AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). + AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). + AddRoute(ibcparenttypes.RouterKey, ibcparent.NewCreateChildChainHandler(app.ParentKeeper)). + AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)) + + app.GovKeeper = govkeeper.NewKeeper( + appCodec, + keys[govtypes.StoreKey], + app.GetSubspace(govtypes.ModuleName), + app.AccountKeeper, + app.BankKeeper, + &stakingKeeper, + govRouter, + ) + + app.TransferKeeper = ibctransferkeeper.NewKeeper( + appCodec, + keys[ibctransfertypes.StoreKey], + app.GetSubspace(ibctransfertypes.ModuleName), + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.BankKeeper, + scopedTransferKeeper, + ) + transferModule := transfer.NewAppModule(app.TransferKeeper) + ibcmodule := transfer.NewIBCModule(app.TransferKeeper) + + // create static IBC router, add transfer route, then set and seal it + ibcRouter := porttypes.NewRouter() + ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule) + ibcRouter.AddRoute(ibcchildtypes.ModuleName, childModule) + ibcRouter.AddRoute(ibcparenttypes.ModuleName, parentModule) + app.IBCKeeper.SetRouter(ibcRouter) + + // create evidence keeper with router + evidenceKeeper := evidencekeeper.NewKeeper( + appCodec, + keys[evidencetypes.StoreKey], + &app.StakingKeeper, + app.SlashingKeeper, + ) + + app.EvidenceKeeper = *evidenceKeeper + + skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) + + // NOTE: Any module instantiated in the module manager that is later modified + // must be passed by reference here. + app.MM = module.NewManager( + genutil.NewAppModule( + app.AccountKeeper, + app.StakingKeeper, + app.BaseApp.DeliverTx, + encodingConfig.TxConfig, + ), + auth.NewAppModule(appCodec, app.AccountKeeper, nil), + vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(appCodec, *app.CapabilityKeeper), + crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + upgrade.NewAppModule(app.UpgradeKeeper), + evidence.NewAppModule(app.EvidenceKeeper), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + ibc.NewAppModule(app.IBCKeeper), + params.NewAppModule(app.ParamsKeeper), + liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper), + transferModule, + childModule, + parentModule, + ) + + // During begin block slashing happens after distr.BeginBlocker so that + // there is nothing left over in the validator fee pool, so as to keep the + // CanWithdrawInvariant invariant. + // NOTE: staking module is required if HistoricalEntries param > 0 + // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) + app.MM.SetOrderBeginBlockers( + // upgrades should be run first + upgradetypes.ModuleName, + capabilitytypes.ModuleName, + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + liquiditytypes.ModuleName, + ibctransfertypes.ModuleName, + ibchost.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + authz.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + vestingtypes.ModuleName, + ibcchildtypes.ModuleName, + ibcparenttypes.ModuleName, + ) + app.MM.SetOrderEndBlockers( + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + liquiditytypes.ModuleName, + ibctransfertypes.ModuleName, + ibchost.ModuleName, + feegrant.ModuleName, + authz.ModuleName, + capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + vestingtypes.ModuleName, + ibcchildtypes.ModuleName, + ibcparenttypes.ModuleName, + ) + + // NOTE: The genutils module must occur after staking so that pools are + // properly initialized with tokens from genesis accounts. + // NOTE: The genutils module must also occur after auth so that it can access the params from auth. + // NOTE: Capability module must occur first so that it can initialize any capabilities + // so that other modules that want to create or claim capabilities afterwards in InitChain + // can do so safely. + app.MM.SetOrderInitGenesis( + capabilitytypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + slashingtypes.ModuleName, + govtypes.ModuleName, + minttypes.ModuleName, + crisistypes.ModuleName, + ibchost.ModuleName, + evidencetypes.ModuleName, + liquiditytypes.ModuleName, + ibctransfertypes.ModuleName, + feegrant.ModuleName, + authz.ModuleName, + authtypes.ModuleName, + genutiltypes.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + vestingtypes.ModuleName, + ibcchildtypes.ModuleName, + ibcparenttypes.ModuleName, + ) + + app.MM.RegisterInvariants(&app.CrisisKeeper) + app.MM.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) + + app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) + app.MM.RegisterServices(app.configurator) + + // create the simulation manager and define the order of the modules for deterministic simulations + // + // NOTE: this is not required apps that don't use the simulator for fuzz testing + // transactions + app.sm = module.NewSimulationManager( + auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(appCodec, *app.CapabilityKeeper), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), + staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + params.NewAppModule(app.ParamsKeeper), + evidence.NewAppModule(app.EvidenceKeeper), + liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper), + ibc.NewAppModule(app.IBCKeeper), + transferModule, + ) + + app.sm.RegisterStoreDecoders() + + // initialize stores + app.MountKVStores(keys) + app.MountTransientStores(tkeys) + app.MountMemoryStores(memKeys) + + anteHandler, err := NewAnteHandler( + HandlerOptions{ + HandlerOptions: ante.HandlerOptions{ + AccountKeeper: app.AccountKeeper, + BankKeeper: app.BankKeeper, + FeegrantKeeper: app.FeeGrantKeeper, + SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + IBCChannelkeeper: app.IBCKeeper.ChannelKeeper, + }, + ) + if err != nil { + panic(fmt.Errorf("failed to create AnteHandler: %s", err)) + } + app.SetAnteHandler(anteHandler) + + app.SetInitChainer(app.InitChainer) + app.SetBeginBlocker(app.BeginBlocker) + app.SetEndBlocker(app.EndBlocker) + + app.UpgradeKeeper.SetUpgradeHandler( + upgradeName, + func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { + app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams()) + + fromVM := make(map[string]uint64) + + for moduleName, eachModule := range app.MM.Modules { + fromVM[moduleName] = eachModule.ConsensusVersion() + } + + ctx.Logger().Info("start to run module migrations...") + + return app.MM.RunMigrations(ctx, app.configurator, fromVM) + }, + ) + + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) + } + + if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + storeUpgrades := store.StoreUpgrades{} + + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } + + if loadLatest { + if err := app.LoadLatestVersion(); err != nil { + tmos.Exit(fmt.Sprintf("failed to load latest version: %s", err)) + } + } + + app.ScopedIBCKeeper = scopedIBCKeeper + app.ScopedTransferKeeper = scopedTransferKeeper + app.ScopedIBCChildKeeper = scopedIBCChildKeeper + app.ScopedIBCParentKeeper = scopedIBCParentKeeper + + return app +} + +// Name returns the name of the App +func (app *App) Name() string { return app.BaseApp.Name() } + +// BeginBlocker application updates every begin block +func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + return app.MM.BeginBlock(ctx, req) +} + +// EndBlocker application updates every end block +func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { + return app.MM.EndBlock(ctx, req) +} + +// InitChainer application update at chain initialization +func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { + var genesisState GenesisState + if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { + panic(err) + } + + app.UpgradeKeeper.SetModuleVersionMap(ctx, app.MM.GetVersionMap()) + + return app.MM.InitGenesis(ctx, app.appCodec, genesisState) +} + +// LoadHeight loads a particular height +func (app *App) LoadHeight(height int64) error { + return app.LoadVersion(height) +} + +// ModuleAccountAddrs returns all the app's module account addresses. +func (app *App) ModuleAccountAddrs() map[string]bool { + modAccAddrs := make(map[string]bool) + for acc := range maccPerms { + modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true + } + + return modAccAddrs +} + +// LegacyAmino returns App's amino codec. +// +// NOTE: This is solely to be used for testing purposes as it may be desirable +// for modules to register their own custom testing types. +func (app *App) LegacyAmino() *codec.LegacyAmino { + return app.legacyAmino +} + +// AppCodec returns the app codec. +// +// NOTE: This is solely to be used for testing purposes as it may be desirable +// for modules to register their own custom testing types. +func (app *App) AppCodec() codec.Codec { + return app.appCodec +} + +// InterfaceRegistry returns the InterfaceRegistry +func (app *App) InterfaceRegistry() types.InterfaceRegistry { + return app.interfaceRegistry +} + +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *App) GetKey(storeKey string) *sdk.KVStoreKey { + return app.keys[storeKey] +} + +// GetTKey returns the TransientStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *App) GetTKey(storeKey string) *sdk.TransientStoreKey { + return app.tkeys[storeKey] +} + +// GetMemKey returns the MemStoreKey for the provided mem key. +// +// NOTE: This is solely used for testing purposes. +func (app *App) GetMemKey(storeKey string) *sdk.MemoryStoreKey { + return app.memKeys[storeKey] +} + +// GetSubspace returns a param subspace for a given module name. +// +// NOTE: This is solely to be used for testing purposes. +func (app *App) GetSubspace(moduleName string) paramstypes.Subspace { + subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) + return subspace +} + +// SimulationManager implements the SimulationApp interface +func (app *App) SimulationManager() *module.SimulationManager { + return app.sm +} + +// TestingApp functions + +// GetBaseApp implements the TestingApp interface. +func (app *App) GetBaseApp() *baseapp.BaseApp { + return app.BaseApp +} + +// GetStakingKeeper implements the TestingApp interface. +func (app *App) GetStakingKeeper() stakingkeeper.Keeper { + return app.StakingKeeper +} + +// GetIBCKeeper implements the TestingApp interface. +func (app *App) GetIBCKeeper() *ibckeeper.Keeper { + return app.IBCKeeper +} + +// GetScopedIBCKeeper implements the TestingApp interface. +func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { + return app.ScopedIBCKeeper +} + +// GetTxConfig implements the TestingApp interface. +func (app *App) GetTxConfig() client.TxConfig { + return cosmoscmd.MakeEncodingConfig(ModuleBasics).TxConfig +} + +// RegisterAPIRoutes registers all application module routes with the provided +// API server. +func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { + clientCtx := apiSvr.ClientCtx + rpc.RegisterRoutes(clientCtx, apiSvr.Router) + // Register legacy tx routes. + authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) + // Register new tx routes from grpc-gateway. + authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + // Register new tendermint queries routes from grpc-gateway. + tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // Register legacy and grpc-gateway routes for all modules. + ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) + ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // register swagger API from root so that other applications can override easily + if apiConfig.Swagger { + RegisterSwaggerAPI(apiSvr.Router) + } +} + +// RegisterTxService implements the Application.RegisterTxService method. +func (app *App) RegisterTxService(clientCtx client.Context) { + authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) +} + +// RegisterTendermintService implements the Application.RegisterTendermintService method. +func (app *App) RegisterTendermintService(clientCtx client.Context) { + tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry) +} + +// RegisterSwaggerAPI registers swagger route with API Server +func RegisterSwaggerAPI(rtr *mux.Router) { + statikFS, err := fs.New() + if err != nil { + panic(err) + } + + staticServer := http.FileServer(statikFS) + rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) +} + +// GetMaccPerms returns a copy of the module account permissions +func GetMaccPerms() map[string][]string { + dupMaccPerms := make(map[string][]string) + for k, v := range maccPerms { + dupMaccPerms[k] = v + } + return dupMaccPerms +} + +// initParamsKeeper init params keeper and its subspaces +func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper { + paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + + paramsKeeper.Subspace(authtypes.ModuleName) + paramsKeeper.Subspace(banktypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName) + paramsKeeper.Subspace(minttypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) + paramsKeeper.Subspace(slashingtypes.ModuleName) + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) + paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(liquiditytypes.ModuleName) + paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(ibcparenttypes.ModuleName) + paramsKeeper.Subspace(ibcchildtypes.ModuleName) + + return paramsKeeper +} diff --git a/app_parent/export.go b/app_parent/export.go new file mode 100644 index 0000000000..590c9e9163 --- /dev/null +++ b/app_parent/export.go @@ -0,0 +1,185 @@ +package app + +import ( + "encoding/json" + "log" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + servertypes "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// ExportAppStateAndValidators exports the state of the application for a genesis +// file. +func (app *App) ExportAppStateAndValidators( + forZeroHeight bool, jailAllowedAddrs []string, +) (servertypes.ExportedApp, error) { + + // as if they could withdraw from the start of the next block + ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + + // We export at last height + 1, because that's the height at which + // Tendermint will start InitChain. + height := app.LastBlockHeight() + 1 + if forZeroHeight { + height = 0 + app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) + } + + genState := app.MM.ExportGenesis(ctx, app.appCodec) + appState, err := json.MarshalIndent(genState, "", " ") + if err != nil { + return servertypes.ExportedApp{}, err + } + + validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + if err != nil { + return servertypes.ExportedApp{}, err + } + return servertypes.ExportedApp{ + AppState: appState, + Validators: validators, + Height: height, + ConsensusParams: app.BaseApp.GetConsensusParams(ctx), + }, nil +} + +// prepare for fresh start at zero height +// NOTE zero height genesis is a temporary feature which will be deprecated +// in favour of export at a block height +func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { + applyAllowedAddrs := false + + // check if there is a allowed address list + if len(jailAllowedAddrs) > 0 { + applyAllowedAddrs = true + } + + allowedAddrsMap := make(map[string]bool) + + for _, addr := range jailAllowedAddrs { + _, err := sdk.ValAddressFromBech32(addr) + if err != nil { + log.Fatal(err) + } + allowedAddrsMap[addr] = true + } + + /* Just to be safe, assert the invariants on current state. */ + app.CrisisKeeper.AssertInvariants(ctx) + + /* Handle fee distribution state. */ + + // withdraw all validator commission + app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + _, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) + if err != nil { + panic(err) + } + return false + }) + + // withdraw all delegator rewards + dels := app.StakingKeeper.GetAllDelegations(ctx) + for _, delegation := range dels { + _, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr()) + if err != nil { + panic(err) + } + } + + // clear validator slash events + app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx) + + // clear validator historical rewards + app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) + + // set context height to zero + height := ctx.BlockHeight() + ctx = ctx.WithBlockHeight(0) + + // reinitialize all validators + app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + // donate any unwithdrawn outstanding reward fraction tokens to the community pool + scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) + feePool := app.DistrKeeper.GetFeePool(ctx) + feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) + app.DistrKeeper.SetFeePool(ctx, feePool) + + app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) + return false + }) + + // reinitialize all delegations + for _, del := range dels { + app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) + app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) + } + + // reset context height + ctx = ctx.WithBlockHeight(height) + + /* Handle staking state. */ + + // iterate through redelegations, reset creation height + app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { + for i := range red.Entries { + red.Entries[i].CreationHeight = 0 + } + app.StakingKeeper.SetRedelegation(ctx, red) + return false + }) + + // iterate through unbonding delegations, reset creation height + app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { + for i := range ubd.Entries { + ubd.Entries[i].CreationHeight = 0 + } + app.StakingKeeper.SetUnbondingDelegation(ctx, ubd) + return false + }) + + // Iterate through validators by power descending, reset bond heights, and + // update bond intra-tx counters. + store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) + iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) + counter := int16(0) + + for ; iter.Valid(); iter.Next() { + addr := sdk.ValAddress(iter.Key()[1:]) + validator, found := app.StakingKeeper.GetValidator(ctx, addr) + if !found { + panic("expected validator, not found") + } + + validator.UnbondingHeight = 0 + if applyAllowedAddrs && !allowedAddrsMap[addr.String()] { + validator.Jailed = true + } + + app.StakingKeeper.SetValidator(ctx, validator) + counter++ + } + + iter.Close() + + if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil { + panic(err) + } + + /* Handle slashing state. */ + + // reset start height on signing infos + app.SlashingKeeper.IterateValidatorSigningInfos( + ctx, + func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { + info.StartHeight = 0 + app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info) + return false + }, + ) +} diff --git a/app_parent/genesis.go b/app_parent/genesis.go new file mode 100644 index 0000000000..5bf0c1da80 --- /dev/null +++ b/app_parent/genesis.go @@ -0,0 +1,21 @@ +package app + +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/codec" +) + +// The genesis state of the blockchain is represented here as a map of raw json +// messages key'd by a identifier string. +// The identifier is used to determine which module genesis information belongs +// to so it may be appropriately routed during init chain. +// Within this application default genesis information is retrieved from +// the ModuleBasicManager which populates json from each BasicModule +// object provided to it during init. +type GenesisState map[string]json.RawMessage + +// NewDefaultGenesisState generates the default state for the application. +func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { + return ModuleBasics.DefaultGenesis(cdc) +} diff --git a/cmd/interchain-security-cd/main.go b/cmd/interchain-security-cd/main.go index 554f2ada55..54d8e16657 100644 --- a/cmd/interchain-security-cd/main.go +++ b/cmd/interchain-security-cd/main.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - "github.com/cosmos/interchain-security/app" + app "github.com/cosmos/interchain-security/app_child" "github.com/tendermint/spm/cosmoscmd" ) diff --git a/cmd/interchain-security-pd/main.go b/cmd/interchain-security-pd/main.go index 554f2ada55..6c6c4d8540 100644 --- a/cmd/interchain-security-pd/main.go +++ b/cmd/interchain-security-pd/main.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - "github.com/cosmos/interchain-security/app" + app "github.com/cosmos/interchain-security/app_parent" "github.com/tendermint/spm/cosmoscmd" ) From 745d96da89f8e98bebb14a8d4fdc3dea5da46fc7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 17:02:05 +0100 Subject: [PATCH 07/23] (nobuild) delete testutils/../network.go --- testutil/network/network.go | 79 ------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 testutil/network/network.go diff --git a/testutil/network/network.go b/testutil/network/network.go deleted file mode 100644 index 8779ceca85..0000000000 --- a/testutil/network/network.go +++ /dev/null @@ -1,79 +0,0 @@ -package network - -import ( - "fmt" - "testing" - "time" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/simapp" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/testutil/network" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/tendermint/spm/cosmoscmd" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmdb "github.com/tendermint/tm-db" - - "github.com/cosmos/interchain-security/app" -) - -type ( - Network = network.Network - Config = network.Config -) - -// New creates instance with fully configured cosmos network. -// Accepts optional config, that will be used in place of the DefaultConfig() if provided. -func New(t *testing.T, configs ...network.Config) *network.Network { - if len(configs) > 1 { - panic("at most one config should be provided") - } - var cfg network.Config - if len(configs) == 0 { - cfg = DefaultConfig() - } else { - cfg = configs[0] - } - net := network.New(t, cfg) - t.Cleanup(net.Cleanup) - return net -} - -// DefaultConfig will initialize config for the network with custom application, -// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig -func DefaultConfig() network.Config { - encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) - return network.Config{ - Codec: encoding.Marshaler, - TxConfig: encoding.TxConfig, - LegacyAmino: encoding.Amino, - InterfaceRegistry: encoding.InterfaceRegistry, - AccountRetriever: authtypes.AccountRetriever{}, - AppConstructor: func(val network.Validator) servertypes.Application { - return app.New( - val.Ctx.Logger, tmdb.NewMemDB(), nil, true, map[int64]bool{}, val.Ctx.Config.RootDir, 0, - encoding, - simapp.EmptyAppOptions{}, - baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), - baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), - ) - }, - GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), - TimeoutCommit: 2 * time.Second, - ChainID: "chain-" + tmrand.NewRand().Str(6), - NumValidators: 1, - BondDenom: sdk.DefaultBondDenom, - MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), - AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), - StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), - BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), - PruningStrategy: storetypes.PruningOptionNothing, - CleanupDir: true, - SigningAlgo: string(hd.Secp256k1Type), - KeyringOptions: []keyring.Option{}, - } -} From 5d761f2312928a15fe0eea43a1be0f00c877fedc Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 17:11:24 +0100 Subject: [PATCH 08/23] Use distinct parent, child in simapp --- testutil/simapp/simapp.go | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index b6807597f1..5f117c63a9 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -16,26 +16,10 @@ import ( tmtypes "github.com/tendermint/tendermint/types" tmdb "github.com/tendermint/tm-db" - "github.com/cosmos/interchain-security/app" + childApp "github.com/cosmos/interchain-security/app_child" + parentApp "github.com/cosmos/interchain-security/app_parent" ) -// New creates application instance with in-memory database and disabled logging. -func New(dir string) cosmoscmd.App { - db := tmdb.NewMemDB() - logger := log.NewNopLogger() - - encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) - - a := app.New(logger, db, nil, true, map[int64]bool{}, dir, 0, encoding, - simapp.EmptyAppOptions{}) - // InitChain updates deliverState which is required when app.NewContext is called - a.InitChain(abci.RequestInitChain{ - ConsensusParams: defaultConsensusParams, - AppStateBytes: []byte("{}"), - }) - return a -} - var defaultConsensusParams = &abci.ConsensusParams{ Block: &abci.BlockParams{ MaxBytes: 200000, @@ -56,17 +40,17 @@ var defaultConsensusParams = &abci.ConsensusParams{ func SetupTestingParentApp() (ibctesting.TestingApp, map[string]json.RawMessage) { db := tmdb.NewMemDB() // encCdc := app.MakeTestEncodingConfig() - encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) - testApp := app.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) - return testApp, app.NewDefaultGenesisState(encoding.Marshaler) + encoding := cosmoscmd.MakeEncodingConfig(parentApp.ModuleBasics) + testApp := parentApp.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) + return testApp, parentApp.NewDefaultGenesisState(encoding.Marshaler) } func SetupTestingChildApp() (ibctesting.TestingApp, map[string]json.RawMessage) { db := tmdb.NewMemDB() // encCdc := app.MakeTestEncodingConfig() - encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) - testApp := app.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) - return testApp, app.NewDefaultGenesisState(encoding.Marshaler) + encoding := cosmoscmd.MakeEncodingConfig(childApp.ModuleBasics) + testApp := childApp.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) + return testApp, childApp.NewDefaultGenesisState(encoding.Marshaler) } // NewCoordinator initializes Coordinator with 0 TestChains From bfb00064feb150cda0e57952c17f8c45c4940133 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 17:48:34 +0100 Subject: [PATCH 09/23] (testfail) replace all app instances with parentApp --- app_child/app.go | 2 +- app_parent/app.go | 2 +- x/ccv/child/keeper/genesis_test.go | 20 +++---- x/ccv/child/keeper/keeper_test.go | 85 +++++++++++++-------------- x/ccv/child/keeper/params_test.go | 24 ++++---- x/ccv/child/keeper/relay_test.go | 38 ++++++------ x/ccv/child/keeper/validators_test.go | 4 +- x/ccv/child/module_test.go | 28 ++++----- x/ccv/parent/keeper/genesis_test.go | 18 +++--- x/ccv/parent/keeper/keeper_test.go | 16 ++--- x/ccv/parent/keeper/params_test.go | 8 +-- x/ccv/parent/keeper/proposal_test.go | 14 ++--- x/ccv/parent/parent_test.go | 46 +++++++-------- x/ccv/parent/proposal_handler_test.go | 4 +- x/ccv/parent/unbonding_hook_test.go | 12 ++-- 15 files changed, 159 insertions(+), 162 deletions(-) diff --git a/app_child/app.go b/app_child/app.go index e738980a49..5de903bdec 100644 --- a/app_child/app.go +++ b/app_child/app.go @@ -117,7 +117,7 @@ import ( ) const ( - AppName = "interchain-security" + AppName = "interchain-security-c" upgradeName = "v07-Theta" AccountAddressPrefix = "cosmos" ) diff --git a/app_parent/app.go b/app_parent/app.go index e738980a49..db9afed14c 100644 --- a/app_parent/app.go +++ b/app_parent/app.go @@ -117,7 +117,7 @@ import ( ) const ( - AppName = "interchain-security" + AppName = "interchain-security-p" upgradeName = "v07-Theta" AccountAddressPrefix = "cosmos" ) diff --git a/x/ccv/child/keeper/genesis_test.go b/x/ccv/child/keeper/genesis_test.go index af12837967..76c4245461 100644 --- a/x/ccv/child/keeper/genesis_test.go +++ b/x/ccv/child/keeper/genesis_test.go @@ -7,7 +7,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -17,22 +17,22 @@ import ( ) func (suite *KeeperTestSuite) TestGenesis() { - genesis := suite.childChain.App.(*app.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + genesis := suite.childChain.App.(*parentApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) suite.Require().Equal(suite.parentClient, genesis.ParentClientState) suite.Require().Equal(suite.parentConsState, genesis.ParentConsensusState) suite.Require().NotPanics(func() { - suite.childChain.App.(*app.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) + suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) // reset suite to reset parent client suite.SetupTest() }) ctx := suite.childChain.GetContext() - portId := suite.childChain.App.(*app.App).ChildKeeper.GetPort(ctx) + portId := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPort(ctx) suite.Require().Equal(childtypes.PortID, portId) - clientId, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentClient(ctx) + clientId, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(ctx) suite.Require().True(ok) clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(ctx, clientId) suite.Require().True(ok) @@ -62,25 +62,25 @@ func (suite *KeeperTestSuite) TestGenesis() { ) packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*app.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) + suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) // mocking the fact that child chain validators should be parent chain validators // TODO: Fix testing suite so we can initialize both chains with the same validator set valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) - restartGenesis := suite.childChain.App.(*app.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + restartGenesis := suite.childChain.App.(*parentApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) restartGenesis.InitialValSet = valUpdates // ensure reset genesis is set correctly parentChannel := suite.path.EndpointA.ChannelID suite.Require().Equal(parentChannel, restartGenesis.ParentChannelId) - unbondingTime := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) + unbondingTime := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) suite.Require().Equal(uint64(origTime.Add(childtypes.UnbondingTime).UnixNano()), unbondingTime, "unbonding time is not set correctly in genesis") - unbondingPacket, err := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) + unbondingPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) suite.Require().NoError(err) suite.Require().Equal(&packet, unbondingPacket, "unbonding packet is not set correctly in genesis") suite.Require().NotPanics(func() { - suite.childChain.App.(*app.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) + suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) }) } diff --git a/x/ccv/child/keeper/keeper_test.go b/x/ccv/child/keeper/keeper_test.go index 4ea0bf8ec6..d3086b0e83 100644 --- a/x/ccv/child/keeper/keeper_test.go +++ b/x/ccv/child/keeper/keeper_test.go @@ -12,7 +12,7 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/child/types" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -41,9 +41,6 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.parentChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.childChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) tmConfig := ibctesting.NewTendermintConfig() @@ -66,7 +63,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*app.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.childChain.GetContext() @@ -77,7 +74,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = ccv.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.ctx) if !ok { panic("must already have parent client on child chain") } @@ -90,7 +87,7 @@ func (suite *KeeperTestSuite) SetupTest() { // create child client on parent chain and set as child client for child chainID in parent keeper. suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*app.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) + suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) } func (suite *KeeperTestSuite) SetupCCVChannel() { @@ -99,7 +96,7 @@ func (suite *KeeperTestSuite) SetupCCVChannel() { } func (suite *KeeperTestSuite) TestParentClient() { - parentClient, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.ctx) suite.Require().True(ok) clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, parentClient) @@ -107,10 +104,10 @@ func (suite *KeeperTestSuite) TestParentClient() { } func (suite *KeeperTestSuite) TestParentChannel() { - _, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentChannel(suite.ctx) + _, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().False(ok) - suite.childChain.App.(*app.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") - channelID, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentChannel(suite.ctx) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") + channelID, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal("channelID", channelID) } @@ -136,34 +133,34 @@ func (suite *KeeperTestSuite) TestPendingChanges() { nil, ) - suite.childChain.App.(*app.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) - gotPd, ok := suite.childChain.App.(*app.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) + gotPd, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) suite.Require().Equal(&pd, gotPd, "packet data in store does not equal packet data set") - suite.childChain.App.(*app.App).ChildKeeper.DeletePendingChanges(suite.ctx) - gotPd, ok = suite.childChain.App.(*app.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*parentApp.App).ChildKeeper.DeletePendingChanges(suite.ctx) + gotPd, ok = suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().False(ok) suite.Require().Nil(gotPd, "got non-nil pending changes after Delete") } func (suite *KeeperTestSuite) TestUnbondingTime() { - suite.childChain.App.(*app.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) - suite.childChain.App.(*app.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) - suite.childChain.App.(*app.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) - suite.childChain.App.(*app.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) - suite.childChain.App.(*app.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) + suite.childChain.App.(*parentApp.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) - suite.Require().Equal(uint64(10), suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) - suite.Require().Equal(uint64(25), suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) - suite.Require().Equal(uint64(15), suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) + suite.Require().Equal(uint64(10), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) + suite.Require().Equal(uint64(25), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) + suite.Require().Equal(uint64(15), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) orderedTimes := [][]uint64{{1, 10}, {2, 25}, {5, 15}} i := 0 - suite.childChain.App.(*app.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { + suite.childChain.App.(*parentApp.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { // require that we iterate through unbonding time in order of sequence suite.Require().Equal(orderedTimes[i][0], seq) suite.Require().Equal(orderedTimes[i][1], time) @@ -195,22 +192,22 @@ func (suite *KeeperTestSuite) TestUnbondingPacket() { ) packet := channeltypes.NewPacket(pd.GetBytes(), uint64(i), "parent", "channel-1", "child", "channel-1", clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*app.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) } // ensure that packets are iterated by sequence i := 0 - suite.childChain.App.(*app.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { + suite.childChain.App.(*parentApp.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { suite.Require().Equal(uint64(i), seq) - gotPacket, err := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) + gotPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) suite.Require().NoError(err) suite.Require().Equal(&packet, gotPacket, "packet from get and iteration do not match") i++ return false }) - suite.childChain.App.(*app.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) - gotPacket, err := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) + suite.childChain.App.(*parentApp.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) + gotPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) suite.Require().Error(err) suite.Require().Nil(gotPacket, "packet is not nil after delete") } @@ -233,7 +230,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*app.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -249,7 +246,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to validating - suite.childChain.App.(*app.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -264,7 +261,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*app.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID, "connection-2"} }, @@ -274,7 +271,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { name: "connection does not exist", setup: func(suite *KeeperTestSuite) { // set channel status to INITIALIZING - suite.childChain.App.(*app.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{"connection-dne"} }, @@ -292,7 +289,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*app.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -308,7 +305,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { tc.setup(suite) // Verify ParentChain on child chain using path returned by setup - err := suite.childChain.App.(*app.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) + err := suite.childChain.App.(*parentApp.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) if tc.expError { suite.Require().Error(err, "invalid case did not return error") @@ -327,7 +324,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { suite.SetupCCVChannel() suite.SendEmptyVSCPacket() - app, ctx := suite.childChain.App.(*app.App), suite.childChain.GetContext() + app, ctx := suite.childChain.App.(*parentApp.App), suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID // pick a cross-chain validator @@ -395,7 +392,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { suite.SetupCCVChannel() - app := suite.childChain.App.(*app.App) + app := suite.childChain.App.(*parentApp.App) ctx := suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID @@ -460,7 +457,7 @@ func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { } func (suite *KeeperTestSuite) TestCrossChainValidator() { - app := suite.childChain.App.(*app.App) + app := suite.childChain.App.(*parentApp.App) ctx := suite.childChain.GetContext() // should return false @@ -487,7 +484,7 @@ func (suite *KeeperTestSuite) TestCrossChainValidator() { } func (suite *KeeperTestSuite) TestPendingSlashRequests() { - childKeeper := suite.childChain.App.(*app.App).ChildKeeper + childKeeper := suite.childChain.App.(*parentApp.App).ChildKeeper ctx := suite.childChain.GetContext() // prepare test setup by storing 10 pending slash requests @@ -524,8 +521,8 @@ func (suite *KeeperTestSuite) TestPendingSlashRequests() { // to ensure that the channel gets established func (suite *KeeperTestSuite) SendEmptyVSCPacket() { - childKeeper := suite.childChain.App.(*app.App).ChildKeeper - parentKeeper := suite.parentChain.App.(*app.App).ParentKeeper + childKeeper := suite.childChain.App.(*parentApp.App).ChildKeeper + parentKeeper := suite.parentChain.App.(*parentApp.App).ParentKeeper oldBlockTime := suite.parentChain.GetContext().BlockTime() timeout := uint64(ccv.GetTimeoutTimestamp(oldBlockTime).UnixNano()) @@ -538,7 +535,7 @@ func (suite *KeeperTestSuite) SendEmptyVSCPacket() { nil, ) - seq, ok := suite.parentChain.App.(*app.App).GetIBCKeeper().ChannelKeeper.GetNextSequenceSend( + seq, ok := suite.parentChain.App.(*parentApp.App).GetIBCKeeper().ChannelKeeper.GetNextSequenceSend( suite.parentChain.GetContext(), parenttypes.PortID, suite.path.EndpointB.ChannelID) suite.Require().True(ok) diff --git a/x/ccv/child/keeper/params_test.go b/x/ccv/child/keeper/params_test.go index d9c46b194a..1325bb8517 100644 --- a/x/ccv/child/keeper/params_test.go +++ b/x/ccv/child/keeper/params_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/x/ccv/child/types" ) @@ -9,35 +9,35 @@ func (suite *KeeperTestSuite) TestParams() { // suite setup initializes genesis expParams := types.NewParams(true, 1000, "", "", "0") // these are the default params - params := suite.childChain.App.(*app.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + params := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) suite.Require().Equal(expParams, params) newParams := types.NewParams(false, 1000, "abc", "def", "0.6") - suite.childChain.App.(*app.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) - params = suite.childChain.App.(*app.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) + params = suite.childChain.App.(*parentApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) suite.Require().Equal(newParams, params) - suite.childChain.App.(*app.App).ChildKeeper. + suite.childChain.App.(*parentApp.App).ChildKeeper. SetBlocksPerDistributionTransmission(suite.childChain.GetContext(), 10) - gotBPDT := suite.childChain.App.(*app.App).ChildKeeper. + gotBPDT := suite.childChain.App.(*parentApp.App).ChildKeeper. GetBlocksPerDistributionTransmission(suite.childChain.GetContext()) suite.Require().Equal(gotBPDT, int64(10)) - suite.childChain.App.(*app.App).ChildKeeper. + suite.childChain.App.(*parentApp.App).ChildKeeper. SetDistributionTransmissionChannel(suite.childChain.GetContext(), "foobarbaz") - gotChan := suite.childChain.App.(*app.App).ChildKeeper. + gotChan := suite.childChain.App.(*parentApp.App).ChildKeeper. GetDistributionTransmissionChannel(suite.childChain.GetContext()) suite.Require().Equal(gotChan, "foobarbaz") - suite.childChain.App.(*app.App).ChildKeeper. + suite.childChain.App.(*parentApp.App).ChildKeeper. SetProviderFeePoolAddrStr(suite.childChain.GetContext(), "foobar") - gotAddr := suite.childChain.App.(*app.App).ChildKeeper. + gotAddr := suite.childChain.App.(*parentApp.App).ChildKeeper. GetProviderFeePoolAddrStr(suite.childChain.GetContext()) suite.Require().Equal(gotAddr, "foobar") - suite.childChain.App.(*app.App).ChildKeeper. + suite.childChain.App.(*parentApp.App).ChildKeeper. SetConsumerRedistributeFrac(suite.childChain.GetContext(), "0.75") - gotFrac := suite.childChain.App.(*app.App).ChildKeeper. + gotFrac := suite.childChain.App.(*parentApp.App).ChildKeeper. GetConsumerRedistributeFrac(suite.childChain.GetContext()) suite.Require().Equal(gotFrac, "0.75") } diff --git a/x/ccv/child/keeper/relay_test.go b/x/ccv/child/keeper/relay_test.go index cd175e7047..c69c2a6723 100644 --- a/x/ccv/child/keeper/relay_test.go +++ b/x/ccv/child/keeper/relay_test.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -117,22 +117,22 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } for _, tc := range testCases { - ack := suite.childChain.App.(*app.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) + ack := suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) if tc.expErrorAck { suite.Require().NotNil(ack, "invalid test case: %s did not return ack", tc.name) suite.Require().False(ack.Success(), "invalid test case: %s did not return an Error Acknowledgment") } else { suite.Require().Nil(ack, "successful packet must send ack asynchronously. case: %s", tc.name) - suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*app.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), + suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*parentApp.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), "channel status is not valdidating after receive packet for valid test case: %s", tc.name) - parentChannel, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentChannel(suite.ctx) + parentChannel, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal(tc.packet.DestinationChannel, parentChannel, "parent channel is not destination channel on successful receive for valid test case: %s", tc.name) // Check that pending changes are accumulated and stored correctly - actualPendingChanges, ok := suite.childChain.App.(*app.App).ChildKeeper.GetPendingChanges(suite.ctx) + actualPendingChanges, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) // Sort to avoid dumb inequalities sort.SliceStable(actualPendingChanges.ValidatorUpdates, func(i, j int) bool { @@ -144,9 +144,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { suite.Require().Equal(tc.expectedPendingChanges, *actualPendingChanges, "pending changes not equal to expected changes after successful packet receive. case: %s", tc.name) expectedTime := uint64(suite.ctx.BlockTime().Add(childtypes.UnbondingTime).UnixNano()) - unbondingTime := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) + unbondingTime := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) suite.Require().Equal(expectedTime, unbondingTime, "unbonding time has unexpected value for case: %s", tc.name) - unbondingPacket, err := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) + unbondingPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) suite.Require().NoError(err) suite.Require().Equal(&tc.packet, unbondingPacket, "packet is not added to unbonding queue after successful receive. case: %s", tc.name) } @@ -183,7 +183,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { // send first packet packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - ack := suite.childChain.App.(*app.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack := suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send second packet @@ -191,7 +191,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[0].Power = 15 packet.Data = pd.GetBytes() packet.Sequence = 2 - ack = suite.childChain.App.(*app.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send third packet @@ -199,25 +199,25 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[1].Power = 40 packet.Data = pd.GetBytes() packet.Sequence = 3 - ack = suite.childChain.App.(*app.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // move ctx time forward such that first two packets are unbonded but third is not. suite.ctx = suite.ctx.WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) - suite.childChain.App.(*app.App).ChildKeeper.UnbondMaturePackets(suite.ctx) + suite.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(suite.ctx) // ensure first two packets are unbonded and acknowledgement is written // unbonded time is deleted - time1 := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) - time2 := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) + time1 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) + time2 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) suite.Require().Equal(uint64(0), time1, "unbonding time not deleted for mature packet 1") suite.Require().Equal(uint64(0), time2, "unbonding time not deleted for mature packet 2") // unbonded packets are deleted - _, err = suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) + _, err = suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") - _, err = suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) + _, err = suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") expectedWriteAckBytes := channeltypes.CommitAcknowledgement(channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()) @@ -231,9 +231,9 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { suite.Require().Equal(expectedWriteAckBytes, ackBytes2, "did not write successful ack for matue packet 1") // ensure that third packet did not get ack written and is still in store - time3 := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) + time3 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) suite.Require().True(time3 > uint64(suite.ctx.BlockTime().UnixNano()), "Unbonding time for packet 3 is not after current time") - packet3, err := suite.childChain.App.(*app.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) + packet3, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) suite.Require().NoError(err, "retrieving unbonding packet 3 returned error") suite.Require().Equal(&packet, packet3, "unbonding packet 3 has unexpected value") @@ -254,12 +254,12 @@ func (suite *KeeperTestSuite) TestOnAcknowledgement() { ack := channeltypes.NewResultAcknowledgement([]byte{1}) // expect no error - err := suite.childChain.App.(*app.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err := suite.childChain.App.(*parentApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.Nil(err) // expect an error ack = channeltypes.NewErrorAcknowledgement("error") - err = suite.childChain.App.(*app.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err = suite.childChain.App.(*parentApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.NotNil(err) } diff --git a/x/ccv/child/keeper/validators_test.go b/x/ccv/child/keeper/validators_test.go index 80168c0c69..83528c6ca7 100644 --- a/x/ccv/child/keeper/validators_test.go +++ b/x/ccv/child/keeper/validators_test.go @@ -1,14 +1,14 @@ package keeper_test import ( - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/x/ccv/child/types" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (k KeeperTestSuite) TestApplyCCValidatorChanges() { - childKeeper := k.childChain.App.(*app.App).ChildKeeper + childKeeper := k.childChain.App.(*parentApp.App).ChildKeeper ctx := k.ctx // utility functions diff --git a/x/ccv/child/module_test.go b/x/ccv/child/module_test.go index e53dbbcb9e..26fc76f697 100644 --- a/x/ccv/child/module_test.go +++ b/x/ccv/child/module_test.go @@ -13,7 +13,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/child" "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -68,7 +68,7 @@ func (suite *ChildTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*app.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) // create the ccv path and set child's clientID to genesis client path := ibctesting.NewPath(suite.childChain, suite.parentChain) @@ -78,7 +78,7 @@ func (suite *ChildTestSuite) SetupTest() { path.EndpointB.ChannelConfig.Version = ccv.Version path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -91,7 +91,7 @@ func (suite *ChildTestSuite) SetupTest() { // create child client on parent chain and set as child client for child chainID in parent keeper. path.EndpointB.CreateClient() - suite.parentChain.App.(*app.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, path.EndpointB.ClientID) + suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, path.EndpointB.ClientID) suite.coordinator.CreateConnections(path) @@ -123,7 +123,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { { name: "invalid: parent channel already established", setup: func(suite *ChildTestSuite) { - suite.childChain.App.(*app.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") + suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") // Set INIT channel on child chain suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, channeltypes.NewChannel( @@ -216,7 +216,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*app.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) suite.Require().NoError(err) @@ -234,7 +234,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { func (suite *ChildTestSuite) TestOnChanOpenTry() { // OnOpenTry must error even with correct arguments - childModule := child.NewAppModule(suite.childChain.App.(*app.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) suite.Require().NoError(err) @@ -265,7 +265,7 @@ func (suite *ChildTestSuite) TestOnChanOpenAck() { { name: "invalid: parent channel already established", setup: func(suite *ChildTestSuite) { - suite.childChain.App.(*app.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") + suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") // Set INIT channel on child chain suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, channeltypes.NewChannel( @@ -299,7 +299,7 @@ func (suite *ChildTestSuite) TestOnChanOpenAck() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*app.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) md := parenttypes.HandshakeMetadata{ ProviderFeePoolAddr: "", // dummy address used @@ -325,7 +325,7 @@ func (suite *ChildTestSuite) TestOnChanOpenConfirm() { []string{"connection-1"}, ccv.Version, )) - childModule := child.NewAppModule(suite.childChain.App.(*app.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) err := childModule.OnChanOpenConfirm(suite.ctx, childtypes.PortID, "channel-1") suite.Require().Error(err, "OnChanOpenConfirm must always fail") @@ -348,7 +348,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), ) suite.path.EndpointA.ChannelID = channelID - suite.childChain.App.(*app.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") + suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") }, expError: false, }, @@ -357,7 +357,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { setup: func(suite *ChildTestSuite) { // create open channel suite.coordinator.CreateChannels(suite.path) - suite.childChain.App.(*app.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") + suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") }, expError: false, }, @@ -379,7 +379,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { setup: func(suite *ChildTestSuite) { // create open channel suite.coordinator.CreateChannels(suite.path) - suite.childChain.App.(*app.App).ChildKeeper.SetParentChannel(suite.ctx, suite.path.EndpointA.ChannelID) + suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, suite.path.EndpointA.ChannelID) }, expError: true, }, @@ -391,7 +391,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*app.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) err := childModule.OnChanCloseInit(suite.ctx, childtypes.PortID, suite.path.EndpointA.ChannelID) diff --git a/x/ccv/parent/keeper/genesis_test.go b/x/ccv/parent/keeper/genesis_test.go index 6e6764e132..560b5a2b10 100644 --- a/x/ccv/parent/keeper/genesis_test.go +++ b/x/ccv/parent/keeper/genesis_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "fmt" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/x/ccv/types" ) @@ -11,27 +11,27 @@ func (suite *KeeperTestSuite) TestGenesis() { // set some chain-channel pairs before exporting ctx := suite.parentChain.GetContext() for i := 0; i < 4; i++ { - suite.parentChain.App.(*app.App).ParentKeeper.SetChainToChannel(ctx, fmt.Sprintf("chainid-%d", i), fmt.Sprintf("channelid-%d", i)) - suite.parentChain.App.(*app.App).ParentKeeper.SetChannelToChain(ctx, fmt.Sprintf("channelid-%d", i), fmt.Sprintf("chainid-%d", i)) - suite.parentChain.App.(*app.App).ParentKeeper.SetChannelStatus(ctx, fmt.Sprintf("channelid-%d", i), types.Status(i)) + suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChainToChannel(ctx, fmt.Sprintf("chainid-%d", i), fmt.Sprintf("channelid-%d", i)) + suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChannelToChain(ctx, fmt.Sprintf("channelid-%d", i), fmt.Sprintf("chainid-%d", i)) + suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChannelStatus(ctx, fmt.Sprintf("channelid-%d", i), types.Status(i)) } - genState := suite.parentChain.App.(*app.App).ParentKeeper.ExportGenesis(suite.parentChain.GetContext()) + genState := suite.parentChain.App.(*parentApp.App).ParentKeeper.ExportGenesis(suite.parentChain.GetContext()) - suite.childChain.App.(*app.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) + suite.childChain.App.(*parentApp.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) ctx = suite.childChain.GetContext() for i := 0; i < 4; i++ { expectedChainId := fmt.Sprintf("chainid-%d", i) expectedChannelId := fmt.Sprintf("channelid-%d", i) - channelID, channelOk := suite.childChain.App.(*app.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) - chainID, chainOk := suite.childChain.App.(*app.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) + channelID, channelOk := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) + chainID, chainOk := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) suite.Require().True(channelOk) suite.Require().True(chainOk) suite.Require().Equal(expectedChainId, chainID, "did not store correct chain id for given channel id") suite.Require().Equal(expectedChannelId, channelID, "did not store correct channel id for given chain id") - status := suite.childChain.App.(*app.App).ParentKeeper.GetChannelStatus(ctx, channelID) + status := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChannelStatus(ctx, channelID) suite.Require().Equal(types.Status(i), status, "status is unexpected for given channel id: %s", channelID) } } diff --git a/x/ccv/parent/keeper/keeper_test.go b/x/ccv/parent/keeper/keeper_test.go index 8244e3f3b4..696e3a49a2 100644 --- a/x/ccv/parent/keeper/keeper_test.go +++ b/x/ccv/parent/keeper/keeper_test.go @@ -11,7 +11,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" @@ -65,7 +65,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*app.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.parentChain.GetContext() @@ -76,7 +76,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -89,7 +89,7 @@ func (suite *KeeperTestSuite) SetupTest() { // create child client on parent chain and set as child client for child chainID in parent keeper. suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*app.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) + suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) } func TestKeeperTestSuite(t *testing.T) { @@ -97,7 +97,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *KeeperTestSuite) TestValsetUpdateBlockHeight() { - app := suite.parentChain.App.(*app.App) + app := suite.parentChain.App.(*parentApp.App) ctx := suite.ctx blockHeight := app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(0)) @@ -118,7 +118,7 @@ func (suite *KeeperTestSuite) TestValsetUpdateBlockHeight() { } func (suite *KeeperTestSuite) TestSlashAcks() { - app := suite.parentChain.App.(*app.App) + app := suite.parentChain.App.(*parentApp.App) ctx := suite.ctx var chainsAcks [][]string @@ -160,7 +160,7 @@ func (suite *KeeperTestSuite) TestSlashAcks() { } func (suite *KeeperTestSuite) TestAppendslashingAck() { - app := suite.parentChain.App.(*app.App) + app := suite.parentChain.App.(*parentApp.App) ctx := suite.ctx p := []string{"alice", "bob", "charlie"} @@ -179,7 +179,7 @@ func (suite *KeeperTestSuite) TestAppendslashingAck() { } func (suite *KeeperTestSuite) TestInitHeight() { - app := suite.parentChain.App.(*app.App) + app := suite.parentChain.App.(*parentApp.App) ctx := suite.ctx tc := []struct { diff --git a/x/ccv/parent/keeper/params_test.go b/x/ccv/parent/keeper/params_test.go index 7d1cbcad74..875d0ffdab 100644 --- a/x/ccv/parent/keeper/params_test.go +++ b/x/ccv/parent/keeper/params_test.go @@ -6,19 +6,19 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/x/ccv/parent/types" ) func (suite *KeeperTestSuite) TestParams() { expParams := types.DefaultParams() - params := suite.parentChain.App.(*app.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) + params := suite.parentChain.App.(*parentApp.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) suite.Require().Equal(expParams, params) newParams := types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false)) - suite.parentChain.App.(*app.App).ParentKeeper.SetParams(suite.parentChain.GetContext(), newParams) - params = suite.parentChain.App.(*app.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) + suite.parentChain.App.(*parentApp.App).ParentKeeper.SetParams(suite.parentChain.GetContext(), newParams) + params = suite.parentChain.App.(*parentApp.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) suite.Require().Equal(newParams, params) } diff --git a/x/ccv/parent/keeper/proposal_test.go b/x/ccv/parent/keeper/proposal_test.go index d44c67ad8c..4010ed8592 100644 --- a/x/ccv/parent/keeper/proposal_test.go +++ b/x/ccv/parent/keeper/proposal_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" "github.com/cosmos/interchain-security/x/ccv/parent/types" abci "github.com/tendermint/tendermint/abci/types" @@ -19,7 +19,7 @@ func (suite *KeeperTestSuite) TestMakeChildGenesis() { suite.SetupTest() ctx = suite.parentChain.GetContext().WithBlockTime(time.Now()) - actualGenesis, err := suite.parentChain.App.(*app.App).ParentKeeper.MakeChildGenesis(ctx) + actualGenesis, err := suite.parentChain.App.(*parentApp.App).ParentKeeper.MakeChildGenesis(ctx) suite.Require().NoError(err) jsonString := `{"params":{"Enabled":true},"new_chain":true,"parent_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"parent_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` @@ -88,21 +88,21 @@ func (suite *KeeperTestSuite) TestCreateChildChainProposal() { tc.malleate(suite) - err := suite.parentChain.App.(*app.App).ParentKeeper.CreateChildChainProposal(ctx, proposal) + err := suite.parentChain.App.(*parentApp.App).ParentKeeper.CreateChildChainProposal(ctx, proposal) if tc.expPass { suite.Require().NoError(err, "error returned on valid case") if tc.spawnReached { - clientId := suite.parentChain.App.(*app.App).ParentKeeper.GetChildClient(ctx, chainID) - childGenesis, ok := suite.parentChain.App.(*app.App).ParentKeeper.GetChildGenesis(ctx, chainID) + clientId := suite.parentChain.App.(*parentApp.App).ParentKeeper.GetChildClient(ctx, chainID) + childGenesis, ok := suite.parentChain.App.(*parentApp.App).ParentKeeper.GetChildGenesis(ctx, chainID) suite.Require().True(ok) - expectedGenesis, err := suite.parentChain.App.(*app.App).ParentKeeper.MakeChildGenesis(ctx) + expectedGenesis, err := suite.parentChain.App.(*parentApp.App).ParentKeeper.MakeChildGenesis(ctx) suite.Require().NoError(err) suite.Require().Equal(expectedGenesis, childGenesis) suite.Require().NotEqual("", clientId, "child client was not created after spawn time reached") } else { - gotHeight := suite.parentChain.App.(*app.App).ParentKeeper.GetPendingClientInfo(ctx, proposal.SpawnTime, chainID) + gotHeight := suite.parentChain.App.(*parentApp.App).ParentKeeper.GetPendingClientInfo(ctx, proposal.SpawnTime, chainID) suite.Require().Equal(initialHeight, gotHeight, "pending client not equal to clientstate in proposal") } } else { diff --git a/x/ccv/parent/parent_test.go b/x/ccv/parent/parent_test.go index 340e308c27..18d7ff03c0 100644 --- a/x/ccv/parent/parent_test.go +++ b/x/ccv/parent/parent_test.go @@ -22,7 +22,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" @@ -85,7 +85,7 @@ func (suite *ParentTestSuite) SetupTest() { "0.5", // 50% ) childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*app.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.parentChain.GetContext() @@ -96,7 +96,7 @@ func (suite *ParentTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*app.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -109,7 +109,7 @@ func (suite *ParentTestSuite) SetupTest() { // create child client on parent chain and set as child client for child chainID in parent keeper. suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*app.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) + suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) suite.transferPath = ibctesting.NewPath(suite.childChain, suite.parentChain) suite.transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID @@ -133,7 +133,7 @@ func (suite *ParentTestSuite) SetupCCVChannel() { suite.transferPath.EndpointB.ConnectionID = suite.path.EndpointB.ConnectionID // INIT step for transfer path has already been called during CCV channel setup - suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*app.App). + suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*parentApp.App). ChildKeeper.GetDistributionTransmissionChannel(suite.childChain.GetContext()) // Complete TRY, ACK, CONFIRM for transfer path @@ -176,7 +176,7 @@ func (s *ParentTestSuite) TestPacketRoundtrip() { s.Require().NoError(err) // Save valset update ID to reconstruct packet - valUpdateID := s.parentChain.App.(*app.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valUpdateID := s.parentChain.App.(*parentApp.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) // Send CCV packet to consumer s.parentChain.App.EndBlock(abci.RequestEndBlock{}) @@ -209,7 +209,7 @@ func (s *ParentTestSuite) TestPacketRoundtrip() { // - End consumer unbonding period childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) // TODO: why doesn't this work: s.childChain.App.EndBlock(abci.RequestEndBlock{}) - err = s.childChain.App.(*app.App).ChildKeeper.UnbondMaturePackets(childCtx) + err = s.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) // commit child chain and update parent chain client @@ -233,7 +233,7 @@ func (s *ParentTestSuite) childCtx() sdk.Context { } func (s *ParentTestSuite) parentBondDenom() string { - return s.parentChain.App.(*app.App).StakingKeeper.BondDenom(s.parentCtx()) + return s.parentChain.App.(*parentApp.App).StakingKeeper.BondDenom(s.parentCtx()) } // TestSendDowntimePacket tests consumer initiated slashing @@ -242,9 +242,9 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { validatorsPerChain := len(s.childChain.Vals.Validators) parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentSlashingKeeper := s.parentChain.App.(*app.App).SlashingKeeper + parentSlashingKeeper := s.parentChain.App.(*parentApp.App).SlashingKeeper - childKeeper := s.childChain.App.(*app.App).ChildKeeper + childKeeper := s.childChain.App.(*parentApp.App).ChildKeeper // get a cross-chain validator address, pubkey and balance tmVals := s.childChain.Vals.Validators @@ -287,12 +287,12 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { s.Require().NoError(err) // Set outstanding slashing flag - s.childChain.App.(*app.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) + s.childChain.App.(*parentApp.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) // save next VSC packet info oldBlockTime = s.parentCtx().BlockTime() timeout = uint64(types.GetTimeoutTimestamp(oldBlockTime).UnixNano()) - valsetUpdateID := s.parentChain.App.(*app.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valsetUpdateID := s.parentChain.App.(*parentApp.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) // receive the downtime packet on the parent chain; // RecvPacket() calls the parent endblocker thus sends a VSC packet to the consumer @@ -351,7 +351,7 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { s.Require().True(valSignInfo.JailedUntil.After(s.parentCtx().BlockHeader().Time)) // check that the outstanding slashing flag is reset on the child - pFlag := s.childChain.App.(*app.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) + pFlag := s.childChain.App.(*parentApp.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) s.Require().False(pFlag) // check that slashing packet gets acknowledged @@ -375,8 +375,8 @@ func (s *ParentTestSuite) getVal(index int) (validator stakingtypes.Validator, v func (s *ParentTestSuite) TestHandleConsumerDowntime() { s.SetupCCVChannel() parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentSlashingKeeper := s.parentChain.App.(*app.App).SlashingKeeper - parentKeeper := s.parentChain.App.(*app.App).ParentKeeper + parentSlashingKeeper := s.parentChain.App.(*parentApp.App).SlashingKeeper + parentKeeper := s.parentChain.App.(*parentApp.App).ParentKeeper // bonded amount bondAmt := sdk.NewInt(1000000) @@ -484,8 +484,8 @@ func (s *ParentTestSuite) TestHandleConsumerDowntime() { func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentKeeper := s.parentChain.App.(*app.App).ParentKeeper - parentSlashingKeeper := s.parentChain.App.(*app.App).SlashingKeeper + parentKeeper := s.parentChain.App.(*parentApp.App).ParentKeeper + parentSlashingKeeper := s.parentChain.App.(*parentApp.App).SlashingKeeper childChainID := s.childChain.ChainID // expect an error if initial block height isn't set for child chain @@ -554,8 +554,8 @@ func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { } func (s *ParentTestSuite) TestslashingPacketAcknowldgement() { - parentKeeper := s.parentChain.App.(*app.App).ParentKeeper - childKeeper := s.childChain.App.(*app.App).ChildKeeper + parentKeeper := s.parentChain.App.(*parentApp.App).ParentKeeper + childKeeper := s.childChain.App.(*parentApp.App).ChildKeeper packet := channeltypes.NewPacket([]byte{}, 1, childtypes.PortID, s.path.EndpointA.ChannelID, parenttypes.PortID, "wrongchannel", clienttypes.Height{}, 0) @@ -612,7 +612,7 @@ func (s *ParentTestSuite) UpdateChildHistInfo(changes []abci.ValidatorUpdate) { func (s *ParentTestSuite) DisableConsumerDistribution() { cChain := s.childChain - cApp := cChain.App.(*app.App) + cApp := cChain.App.(*parentApp.App) for i, moduleName := range cApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { cApp.MM.OrderBeginBlockers = append(cApp.MM.OrderBeginBlockers[:i], cApp.MM.OrderBeginBlockers[i+1:]...) @@ -623,7 +623,7 @@ func (s *ParentTestSuite) DisableConsumerDistribution() { func (s *ParentTestSuite) DisableProviderDistribution() { pChain := s.parentChain - pApp := pChain.App.(*app.App) + pApp := pChain.App.(*parentApp.App) for i, moduleName := range pApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { s.providerDistrIndex = i @@ -635,7 +635,7 @@ func (s *ParentTestSuite) DisableProviderDistribution() { func (s *ParentTestSuite) ReenableProviderDistribution() { pChain := s.parentChain - pApp := pChain.App.(*app.App) + pApp := pChain.App.(*parentApp.App) i := s.providerDistrIndex pApp.MM.OrderBeginBlockers = append( pApp.MM.OrderBeginBlockers[:i+1], pApp.MM.OrderBeginBlockers[i:]...) // make space @@ -650,7 +650,7 @@ func (s *ParentTestSuite) TestDistribution() { // s.transferPath.EndpointB == Provider Chain pChain, cChain := s.parentChain, s.childChain - pApp, cApp := pChain.App.(*app.App), cChain.App.(*app.App) + pApp, cApp := pChain.App.(*parentApp.App), cChain.App.(*parentApp.App) cKeep := cApp.ChildKeeper // Get the receiving fee pool on the provider chain diff --git a/x/ccv/parent/proposal_handler_test.go b/x/ccv/parent/proposal_handler_test.go index b6f38f22d9..096b5e9b6b 100644 --- a/x/ccv/parent/proposal_handler_test.go +++ b/x/ccv/parent/proposal_handler_test.go @@ -8,7 +8,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/x/ccv/parent" "github.com/cosmos/interchain-security/x/ccv/parent/types" ) @@ -56,7 +56,7 @@ func (suite *ParentTestSuite) TestCreateChildChainProposalHandler() { tc.malleate(suite) - proposalHandler := parent.NewCreateChildChainHandler(suite.parentChain.App.(*app.App).ParentKeeper) + proposalHandler := parent.NewCreateChildChainHandler(suite.parentChain.App.(*parentApp.App).ParentKeeper) err = proposalHandler(ctx, content) diff --git a/x/ccv/parent/unbonding_hook_test.go b/x/ccv/parent/unbonding_hook_test.go index 2a362dbea6..fc42cc5667 100644 --- a/x/ccv/parent/unbonding_hook_test.go +++ b/x/ccv/parent/unbonding_hook_test.go @@ -11,7 +11,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - "github.com/cosmos/interchain-security/app" + parentApp "github.com/cosmos/interchain-security/app_parent" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -160,7 +160,7 @@ func (s *ParentTestSuite) TestStakingHooks1() { } func getBalance(s *ParentTestSuite, parentCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int { - return s.parentChain.App.(*app.App).BankKeeper.GetBalance(parentCtx, delAddr, s.parentBondDenom()).Amount + return s.parentChain.App.(*parentApp.App).BankKeeper.GetBalance(parentCtx, delAddr, s.parentBondDenom()).Amount } func doUnbonding(s *ParentTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (initBalance sdk.Int, valsetUpdateId uint64) { @@ -186,7 +186,7 @@ func doUnbonding(s *ParentTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (i s.Require().True(getBalance(s, s.parentCtx(), delAddr).Equal(initBalance.Sub(bondAmt))) // save the current valset update ID - valsetUpdateID := s.parentChain.App.(*app.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valsetUpdateID := s.parentChain.App.(*parentApp.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) return initBalance, valsetUpdateID } @@ -204,7 +204,7 @@ func endChildUnbondingPeriod(s *ParentTestSuite, origTime time.Time) { // - End consumer unbonding period childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) // s.childChain.App.EndBlock(abci.RequestEndBlock{}) // <- this doesn't work because we can't modify the ctx - err := s.childChain.App.(*app.App).ChildKeeper.UnbondMaturePackets(childCtx) + err := s.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) } @@ -215,7 +215,7 @@ func checkStakingUnbondingOps(s *ParentTestSuite, id uint64, found bool, onHold } func checkCCVUnbondingOp(s *ParentTestSuite, parentCtx sdk.Context, chainID string, valUpdateID uint64, found bool) { - _, wasFound := s.parentChain.App.(*app.App).ParentKeeper.GetUnbondingOpsFromIndex(parentCtx, chainID, valUpdateID) + _, wasFound := s.parentChain.App.(*parentApp.App).ParentKeeper.GetUnbondingOpsFromIndex(parentCtx, chainID, valUpdateID) s.Require().True(found == wasFound) } @@ -258,7 +258,7 @@ func sendValUpdateAck(s *ParentTestSuite, parentCtx sdk.Context, packet channelt // err := s.path.EndpointB.AcknowledgePacket(packet, ack.Acknowledgement()) // s.Require().NoError(err) - err := s.parentChain.App.(*app.App).ParentKeeper.OnAcknowledgementPacket(parentCtx, packet, packetData, ack) + err := s.parentChain.App.(*parentApp.App).ParentKeeper.OnAcknowledgementPacket(parentCtx, packet, packetData, ack) s.Require().NoError(err) } From f21435d53eae3d0036c454957751a46b4185f7a0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 18:40:59 +0100 Subject: [PATCH 10/23] Use correct app in child/module_test --- x/ccv/child/module_test.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/x/ccv/child/module_test.go b/x/ccv/child/module_test.go index 26fc76f697..66651ec705 100644 --- a/x/ccv/child/module_test.go +++ b/x/ccv/child/module_test.go @@ -13,6 +13,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/child" @@ -68,7 +69,7 @@ func (suite *ChildTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) // create the ccv path and set child's clientID to genesis client path := ibctesting.NewPath(suite.childChain, suite.parentChain) @@ -78,7 +79,7 @@ func (suite *ChildTestSuite) SetupTest() { path.EndpointB.ChannelConfig.Version = ccv.Version path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -123,7 +124,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { { name: "invalid: parent channel already established", setup: func(suite *ChildTestSuite) { - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") + suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") // Set INIT channel on child chain suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, channeltypes.NewChannel( @@ -216,7 +217,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) suite.Require().NoError(err) @@ -234,7 +235,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { func (suite *ChildTestSuite) TestOnChanOpenTry() { // OnOpenTry must error even with correct arguments - childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) suite.Require().NoError(err) @@ -265,7 +266,7 @@ func (suite *ChildTestSuite) TestOnChanOpenAck() { { name: "invalid: parent channel already established", setup: func(suite *ChildTestSuite) { - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") + suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") // Set INIT channel on child chain suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, channeltypes.NewChannel( @@ -299,7 +300,7 @@ func (suite *ChildTestSuite) TestOnChanOpenAck() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) md := parenttypes.HandshakeMetadata{ ProviderFeePoolAddr: "", // dummy address used @@ -325,7 +326,7 @@ func (suite *ChildTestSuite) TestOnChanOpenConfirm() { []string{"connection-1"}, ccv.Version, )) - childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) err := childModule.OnChanOpenConfirm(suite.ctx, childtypes.PortID, "channel-1") suite.Require().Error(err, "OnChanOpenConfirm must always fail") @@ -348,7 +349,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), ) suite.path.EndpointA.ChannelID = channelID - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") + suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") }, expError: false, }, @@ -357,7 +358,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { setup: func(suite *ChildTestSuite) { // create open channel suite.coordinator.CreateChannels(suite.path) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") + suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") }, expError: false, }, @@ -379,7 +380,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { setup: func(suite *ChildTestSuite) { // create open channel suite.coordinator.CreateChannels(suite.path) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, suite.path.EndpointA.ChannelID) + suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, suite.path.EndpointA.ChannelID) }, expError: true, }, @@ -391,7 +392,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*parentApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) err := childModule.OnChanCloseInit(suite.ctx, childtypes.PortID, suite.path.EndpointA.ChannelID) From d94a8d159b41c41ae77df7e1a91ee5c75b564455 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 18:48:35 +0100 Subject: [PATCH 11/23] Uses child or parent app correctly in tests --- x/ccv/child/keeper/genesis_test.go | 20 +++---- x/ccv/child/keeper/keeper_test.go | 75 ++++++++++++++------------- x/ccv/child/keeper/params_test.go | 24 ++++----- x/ccv/child/keeper/relay_test.go | 38 +++++++------- x/ccv/child/keeper/validators_test.go | 4 +- x/ccv/parent/keeper/genesis_test.go | 9 ++-- x/ccv/parent/keeper/keeper_test.go | 5 +- x/ccv/parent/parent_test.go | 21 ++++---- x/ccv/parent/unbonding_hook_test.go | 3 +- 9 files changed, 102 insertions(+), 97 deletions(-) diff --git a/x/ccv/child/keeper/genesis_test.go b/x/ccv/child/keeper/genesis_test.go index 76c4245461..e138eb8e39 100644 --- a/x/ccv/child/keeper/genesis_test.go +++ b/x/ccv/child/keeper/genesis_test.go @@ -7,32 +7,32 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - parentApp "github.com/cosmos/interchain-security/app_parent" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" + childApp "github.com/cosmos/interchain-security/app_child" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (suite *KeeperTestSuite) TestGenesis() { - genesis := suite.childChain.App.(*parentApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + genesis := suite.childChain.App.(*childApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) suite.Require().Equal(suite.parentClient, genesis.ParentClientState) suite.Require().Equal(suite.parentConsState, genesis.ParentConsensusState) suite.Require().NotPanics(func() { - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) // reset suite to reset parent client suite.SetupTest() }) ctx := suite.childChain.GetContext() - portId := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPort(ctx) + portId := suite.childChain.App.(*childApp.App).ChildKeeper.GetPort(ctx) suite.Require().Equal(childtypes.PortID, portId) - clientId, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(ctx) + clientId, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(ctx) suite.Require().True(ok) clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(ctx, clientId) suite.Require().True(ok) @@ -62,25 +62,25 @@ func (suite *KeeperTestSuite) TestGenesis() { ) packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) + suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) // mocking the fact that child chain validators should be parent chain validators // TODO: Fix testing suite so we can initialize both chains with the same validator set valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) - restartGenesis := suite.childChain.App.(*parentApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + restartGenesis := suite.childChain.App.(*childApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) restartGenesis.InitialValSet = valUpdates // ensure reset genesis is set correctly parentChannel := suite.path.EndpointA.ChannelID suite.Require().Equal(parentChannel, restartGenesis.ParentChannelId) - unbondingTime := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) + unbondingTime := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) suite.Require().Equal(uint64(origTime.Add(childtypes.UnbondingTime).UnixNano()), unbondingTime, "unbonding time is not set correctly in genesis") - unbondingPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) + unbondingPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) suite.Require().NoError(err) suite.Require().Equal(&packet, unbondingPacket, "unbonding packet is not set correctly in genesis") suite.Require().NotPanics(func() { - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) }) } diff --git a/x/ccv/child/keeper/keeper_test.go b/x/ccv/child/keeper/keeper_test.go index d3086b0e83..9ef38abe98 100644 --- a/x/ccv/child/keeper/keeper_test.go +++ b/x/ccv/child/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -63,7 +64,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.childChain.GetContext() @@ -74,7 +75,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = ccv.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.ctx) if !ok { panic("must already have parent client on child chain") } @@ -96,7 +97,7 @@ func (suite *KeeperTestSuite) SetupCCVChannel() { } func (suite *KeeperTestSuite) TestParentClient() { - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.ctx) suite.Require().True(ok) clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, parentClient) @@ -104,10 +105,10 @@ func (suite *KeeperTestSuite) TestParentClient() { } func (suite *KeeperTestSuite) TestParentChannel() { - _, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) + _, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().False(ok) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") - channelID, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) + suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") + channelID, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal("channelID", channelID) } @@ -133,34 +134,34 @@ func (suite *KeeperTestSuite) TestPendingChanges() { nil, ) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) - gotPd, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*childApp.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) + gotPd, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) suite.Require().Equal(&pd, gotPd, "packet data in store does not equal packet data set") - suite.childChain.App.(*parentApp.App).ChildKeeper.DeletePendingChanges(suite.ctx) - gotPd, ok = suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*childApp.App).ChildKeeper.DeletePendingChanges(suite.ctx) + gotPd, ok = suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().False(ok) suite.Require().Nil(gotPd, "got non-nil pending changes after Delete") } func (suite *KeeperTestSuite) TestUnbondingTime() { - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) - suite.childChain.App.(*parentApp.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) + suite.childChain.App.(*childApp.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) - suite.Require().Equal(uint64(10), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) - suite.Require().Equal(uint64(25), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) - suite.Require().Equal(uint64(15), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) + suite.Require().Equal(uint64(10), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) + suite.Require().Equal(uint64(25), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) + suite.Require().Equal(uint64(15), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) orderedTimes := [][]uint64{{1, 10}, {2, 25}, {5, 15}} i := 0 - suite.childChain.App.(*parentApp.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { + suite.childChain.App.(*childApp.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { // require that we iterate through unbonding time in order of sequence suite.Require().Equal(orderedTimes[i][0], seq) suite.Require().Equal(orderedTimes[i][1], time) @@ -192,22 +193,22 @@ func (suite *KeeperTestSuite) TestUnbondingPacket() { ) packet := channeltypes.NewPacket(pd.GetBytes(), uint64(i), "parent", "channel-1", "child", "channel-1", clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) } // ensure that packets are iterated by sequence i := 0 - suite.childChain.App.(*parentApp.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { + suite.childChain.App.(*childApp.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { suite.Require().Equal(uint64(i), seq) - gotPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) + gotPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) suite.Require().NoError(err) suite.Require().Equal(&packet, gotPacket, "packet from get and iteration do not match") i++ return false }) - suite.childChain.App.(*parentApp.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) - gotPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) + suite.childChain.App.(*childApp.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) + gotPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) suite.Require().Error(err) suite.Require().Nil(gotPacket, "packet is not nil after delete") } @@ -230,7 +231,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -246,7 +247,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to validating - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -261,7 +262,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID, "connection-2"} }, @@ -271,7 +272,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { name: "connection does not exist", setup: func(suite *KeeperTestSuite) { // set channel status to INITIALIZING - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{"connection-dne"} }, @@ -289,7 +290,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -305,7 +306,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { tc.setup(suite) // Verify ParentChain on child chain using path returned by setup - err := suite.childChain.App.(*parentApp.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) + err := suite.childChain.App.(*childApp.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) if tc.expError { suite.Require().Error(err, "invalid case did not return error") @@ -324,7 +325,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { suite.SetupCCVChannel() suite.SendEmptyVSCPacket() - app, ctx := suite.childChain.App.(*parentApp.App), suite.childChain.GetContext() + app, ctx := suite.childChain.App.(*childApp.App), suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID // pick a cross-chain validator @@ -392,7 +393,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { suite.SetupCCVChannel() - app := suite.childChain.App.(*parentApp.App) + app := suite.childChain.App.(*childApp.App) ctx := suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID @@ -457,7 +458,7 @@ func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { } func (suite *KeeperTestSuite) TestCrossChainValidator() { - app := suite.childChain.App.(*parentApp.App) + app := suite.childChain.App.(*childApp.App) ctx := suite.childChain.GetContext() // should return false @@ -484,7 +485,7 @@ func (suite *KeeperTestSuite) TestCrossChainValidator() { } func (suite *KeeperTestSuite) TestPendingSlashRequests() { - childKeeper := suite.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := suite.childChain.App.(*childApp.App).ChildKeeper ctx := suite.childChain.GetContext() // prepare test setup by storing 10 pending slash requests @@ -521,7 +522,7 @@ func (suite *KeeperTestSuite) TestPendingSlashRequests() { // to ensure that the channel gets established func (suite *KeeperTestSuite) SendEmptyVSCPacket() { - childKeeper := suite.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := suite.childChain.App.(*childApp.App).ChildKeeper parentKeeper := suite.parentChain.App.(*parentApp.App).ParentKeeper oldBlockTime := suite.parentChain.GetContext().BlockTime() diff --git a/x/ccv/child/keeper/params_test.go b/x/ccv/child/keeper/params_test.go index 1325bb8517..b2f92ef164 100644 --- a/x/ccv/child/keeper/params_test.go +++ b/x/ccv/child/keeper/params_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - parentApp "github.com/cosmos/interchain-security/app_parent" + childApp "github.com/cosmos/interchain-security/app_child" "github.com/cosmos/interchain-security/x/ccv/child/types" ) @@ -9,35 +9,35 @@ func (suite *KeeperTestSuite) TestParams() { // suite setup initializes genesis expParams := types.NewParams(true, 1000, "", "", "0") // these are the default params - params := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + params := suite.childChain.App.(*childApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) suite.Require().Equal(expParams, params) newParams := types.NewParams(false, 1000, "abc", "def", "0.6") - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) - params = suite.childChain.App.(*parentApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + suite.childChain.App.(*childApp.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) + params = suite.childChain.App.(*childApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) suite.Require().Equal(newParams, params) - suite.childChain.App.(*parentApp.App).ChildKeeper. + suite.childChain.App.(*childApp.App).ChildKeeper. SetBlocksPerDistributionTransmission(suite.childChain.GetContext(), 10) - gotBPDT := suite.childChain.App.(*parentApp.App).ChildKeeper. + gotBPDT := suite.childChain.App.(*childApp.App).ChildKeeper. GetBlocksPerDistributionTransmission(suite.childChain.GetContext()) suite.Require().Equal(gotBPDT, int64(10)) - suite.childChain.App.(*parentApp.App).ChildKeeper. + suite.childChain.App.(*childApp.App).ChildKeeper. SetDistributionTransmissionChannel(suite.childChain.GetContext(), "foobarbaz") - gotChan := suite.childChain.App.(*parentApp.App).ChildKeeper. + gotChan := suite.childChain.App.(*childApp.App).ChildKeeper. GetDistributionTransmissionChannel(suite.childChain.GetContext()) suite.Require().Equal(gotChan, "foobarbaz") - suite.childChain.App.(*parentApp.App).ChildKeeper. + suite.childChain.App.(*childApp.App).ChildKeeper. SetProviderFeePoolAddrStr(suite.childChain.GetContext(), "foobar") - gotAddr := suite.childChain.App.(*parentApp.App).ChildKeeper. + gotAddr := suite.childChain.App.(*childApp.App).ChildKeeper. GetProviderFeePoolAddrStr(suite.childChain.GetContext()) suite.Require().Equal(gotAddr, "foobar") - suite.childChain.App.(*parentApp.App).ChildKeeper. + suite.childChain.App.(*childApp.App).ChildKeeper. SetConsumerRedistributeFrac(suite.childChain.GetContext(), "0.75") - gotFrac := suite.childChain.App.(*parentApp.App).ChildKeeper. + gotFrac := suite.childChain.App.(*childApp.App).ChildKeeper. GetConsumerRedistributeFrac(suite.childChain.GetContext()) suite.Require().Equal(gotFrac, "0.75") } diff --git a/x/ccv/child/keeper/relay_test.go b/x/ccv/child/keeper/relay_test.go index c69c2a6723..aeda3eba7e 100644 --- a/x/ccv/child/keeper/relay_test.go +++ b/x/ccv/child/keeper/relay_test.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - parentApp "github.com/cosmos/interchain-security/app_parent" + childApp "github.com/cosmos/interchain-security/app_child" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -117,22 +117,22 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } for _, tc := range testCases { - ack := suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) + ack := suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) if tc.expErrorAck { suite.Require().NotNil(ack, "invalid test case: %s did not return ack", tc.name) suite.Require().False(ack.Success(), "invalid test case: %s did not return an Error Acknowledgment") } else { suite.Require().Nil(ack, "successful packet must send ack asynchronously. case: %s", tc.name) - suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*parentApp.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), + suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*childApp.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), "channel status is not valdidating after receive packet for valid test case: %s", tc.name) - parentChannel, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) + parentChannel, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal(tc.packet.DestinationChannel, parentChannel, "parent channel is not destination channel on successful receive for valid test case: %s", tc.name) // Check that pending changes are accumulated and stored correctly - actualPendingChanges, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + actualPendingChanges, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) // Sort to avoid dumb inequalities sort.SliceStable(actualPendingChanges.ValidatorUpdates, func(i, j int) bool { @@ -144,9 +144,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { suite.Require().Equal(tc.expectedPendingChanges, *actualPendingChanges, "pending changes not equal to expected changes after successful packet receive. case: %s", tc.name) expectedTime := uint64(suite.ctx.BlockTime().Add(childtypes.UnbondingTime).UnixNano()) - unbondingTime := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) + unbondingTime := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) suite.Require().Equal(expectedTime, unbondingTime, "unbonding time has unexpected value for case: %s", tc.name) - unbondingPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) + unbondingPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) suite.Require().NoError(err) suite.Require().Equal(&tc.packet, unbondingPacket, "packet is not added to unbonding queue after successful receive. case: %s", tc.name) } @@ -183,7 +183,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { // send first packet packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - ack := suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack := suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send second packet @@ -191,7 +191,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[0].Power = 15 packet.Data = pd.GetBytes() packet.Sequence = 2 - ack = suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send third packet @@ -199,25 +199,25 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[1].Power = 40 packet.Data = pd.GetBytes() packet.Sequence = 3 - ack = suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // move ctx time forward such that first two packets are unbonded but third is not. suite.ctx = suite.ctx.WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) - suite.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(suite.ctx) + suite.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(suite.ctx) // ensure first two packets are unbonded and acknowledgement is written // unbonded time is deleted - time1 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) - time2 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) + time1 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) + time2 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) suite.Require().Equal(uint64(0), time1, "unbonding time not deleted for mature packet 1") suite.Require().Equal(uint64(0), time2, "unbonding time not deleted for mature packet 2") // unbonded packets are deleted - _, err = suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) + _, err = suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") - _, err = suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) + _, err = suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") expectedWriteAckBytes := channeltypes.CommitAcknowledgement(channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()) @@ -231,9 +231,9 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { suite.Require().Equal(expectedWriteAckBytes, ackBytes2, "did not write successful ack for matue packet 1") // ensure that third packet did not get ack written and is still in store - time3 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) + time3 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) suite.Require().True(time3 > uint64(suite.ctx.BlockTime().UnixNano()), "Unbonding time for packet 3 is not after current time") - packet3, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) + packet3, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) suite.Require().NoError(err, "retrieving unbonding packet 3 returned error") suite.Require().Equal(&packet, packet3, "unbonding packet 3 has unexpected value") @@ -254,12 +254,12 @@ func (suite *KeeperTestSuite) TestOnAcknowledgement() { ack := channeltypes.NewResultAcknowledgement([]byte{1}) // expect no error - err := suite.childChain.App.(*parentApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err := suite.childChain.App.(*childApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.Nil(err) // expect an error ack = channeltypes.NewErrorAcknowledgement("error") - err = suite.childChain.App.(*parentApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err = suite.childChain.App.(*childApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.NotNil(err) } diff --git a/x/ccv/child/keeper/validators_test.go b/x/ccv/child/keeper/validators_test.go index 83528c6ca7..441dff1b91 100644 --- a/x/ccv/child/keeper/validators_test.go +++ b/x/ccv/child/keeper/validators_test.go @@ -1,14 +1,14 @@ package keeper_test import ( - parentApp "github.com/cosmos/interchain-security/app_parent" + childApp "github.com/cosmos/interchain-security/app_child" "github.com/cosmos/interchain-security/x/ccv/child/types" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (k KeeperTestSuite) TestApplyCCValidatorChanges() { - childKeeper := k.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := k.childChain.App.(*childApp.App).ChildKeeper ctx := k.ctx // utility functions diff --git a/x/ccv/parent/keeper/genesis_test.go b/x/ccv/parent/keeper/genesis_test.go index 560b5a2b10..a9219efc89 100644 --- a/x/ccv/parent/keeper/genesis_test.go +++ b/x/ccv/parent/keeper/genesis_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "fmt" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/x/ccv/types" ) @@ -18,20 +19,20 @@ func (suite *KeeperTestSuite) TestGenesis() { genState := suite.parentChain.App.(*parentApp.App).ParentKeeper.ExportGenesis(suite.parentChain.GetContext()) - suite.childChain.App.(*parentApp.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) + suite.childChain.App.(*childApp.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) ctx = suite.childChain.GetContext() for i := 0; i < 4; i++ { expectedChainId := fmt.Sprintf("chainid-%d", i) expectedChannelId := fmt.Sprintf("channelid-%d", i) - channelID, channelOk := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) - chainID, chainOk := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) + channelID, channelOk := suite.childChain.App.(*childApp.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) + chainID, chainOk := suite.childChain.App.(*childApp.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) suite.Require().True(channelOk) suite.Require().True(chainOk) suite.Require().Equal(expectedChainId, chainID, "did not store correct chain id for given channel id") suite.Require().Equal(expectedChannelId, channelID, "did not store correct channel id for given chain id") - status := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChannelStatus(ctx, channelID) + status := suite.childChain.App.(*childApp.App).ParentKeeper.GetChannelStatus(ctx, channelID) suite.Require().Equal(types.Status(i), status, "status is unexpected for given channel id: %s", channelID) } } diff --git a/x/ccv/parent/keeper/keeper_test.go b/x/ccv/parent/keeper/keeper_test.go index 696e3a49a2..556332fed6 100644 --- a/x/ccv/parent/keeper/keeper_test.go +++ b/x/ccv/parent/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -65,7 +66,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.parentChain.GetContext() @@ -76,7 +77,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } diff --git a/x/ccv/parent/parent_test.go b/x/ccv/parent/parent_test.go index 18d7ff03c0..4718b337c3 100644 --- a/x/ccv/parent/parent_test.go +++ b/x/ccv/parent/parent_test.go @@ -22,6 +22,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -85,7 +86,7 @@ func (suite *ParentTestSuite) SetupTest() { "0.5", // 50% ) childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.parentChain.GetContext() @@ -96,7 +97,7 @@ func (suite *ParentTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -133,7 +134,7 @@ func (suite *ParentTestSuite) SetupCCVChannel() { suite.transferPath.EndpointB.ConnectionID = suite.path.EndpointB.ConnectionID // INIT step for transfer path has already been called during CCV channel setup - suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*parentApp.App). + suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*childApp.App). ChildKeeper.GetDistributionTransmissionChannel(suite.childChain.GetContext()) // Complete TRY, ACK, CONFIRM for transfer path @@ -209,7 +210,7 @@ func (s *ParentTestSuite) TestPacketRoundtrip() { // - End consumer unbonding period childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) // TODO: why doesn't this work: s.childChain.App.EndBlock(abci.RequestEndBlock{}) - err = s.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(childCtx) + err = s.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) // commit child chain and update parent chain client @@ -244,7 +245,7 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { parentStakingKeeper := s.parentChain.App.GetStakingKeeper() parentSlashingKeeper := s.parentChain.App.(*parentApp.App).SlashingKeeper - childKeeper := s.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := s.childChain.App.(*childApp.App).ChildKeeper // get a cross-chain validator address, pubkey and balance tmVals := s.childChain.Vals.Validators @@ -287,7 +288,7 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { s.Require().NoError(err) // Set outstanding slashing flag - s.childChain.App.(*parentApp.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) + s.childChain.App.(*childApp.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) // save next VSC packet info oldBlockTime = s.parentCtx().BlockTime() @@ -351,7 +352,7 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { s.Require().True(valSignInfo.JailedUntil.After(s.parentCtx().BlockHeader().Time)) // check that the outstanding slashing flag is reset on the child - pFlag := s.childChain.App.(*parentApp.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) + pFlag := s.childChain.App.(*childApp.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) s.Require().False(pFlag) // check that slashing packet gets acknowledged @@ -555,7 +556,7 @@ func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { func (s *ParentTestSuite) TestslashingPacketAcknowldgement() { parentKeeper := s.parentChain.App.(*parentApp.App).ParentKeeper - childKeeper := s.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := s.childChain.App.(*childApp.App).ChildKeeper packet := channeltypes.NewPacket([]byte{}, 1, childtypes.PortID, s.path.EndpointA.ChannelID, parenttypes.PortID, "wrongchannel", clienttypes.Height{}, 0) @@ -612,7 +613,7 @@ func (s *ParentTestSuite) UpdateChildHistInfo(changes []abci.ValidatorUpdate) { func (s *ParentTestSuite) DisableConsumerDistribution() { cChain := s.childChain - cApp := cChain.App.(*parentApp.App) + cApp := cChain.App.(*childApp.App) for i, moduleName := range cApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { cApp.MM.OrderBeginBlockers = append(cApp.MM.OrderBeginBlockers[:i], cApp.MM.OrderBeginBlockers[i+1:]...) @@ -650,7 +651,7 @@ func (s *ParentTestSuite) TestDistribution() { // s.transferPath.EndpointB == Provider Chain pChain, cChain := s.parentChain, s.childChain - pApp, cApp := pChain.App.(*parentApp.App), cChain.App.(*parentApp.App) + pApp, cApp := pChain.App.(*parentApp.App), cChain.App.(*childApp.App) cKeep := cApp.ChildKeeper // Get the receiving fee pool on the provider chain diff --git a/x/ccv/parent/unbonding_hook_test.go b/x/ccv/parent/unbonding_hook_test.go index fc42cc5667..629d2a8fc8 100644 --- a/x/ccv/parent/unbonding_hook_test.go +++ b/x/ccv/parent/unbonding_hook_test.go @@ -11,6 +11,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" @@ -204,7 +205,7 @@ func endChildUnbondingPeriod(s *ParentTestSuite, origTime time.Time) { // - End consumer unbonding period childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) // s.childChain.App.EndBlock(abci.RequestEndBlock{}) // <- this doesn't work because we can't modify the ctx - err := s.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(childCtx) + err := s.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) } From f95925c2d04ae155d8877efc2115d3791a20a9a3 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Wed, 4 May 2022 07:41:07 +0100 Subject: [PATCH 12/23] Delete Untitled-1.json (#83) Json file accidentally added during last merge --- x/ccv/provider/keeper/Untitled-1.json | 82 --------------------------- 1 file changed, 82 deletions(-) delete mode 100644 x/ccv/provider/keeper/Untitled-1.json diff --git a/x/ccv/provider/keeper/Untitled-1.json b/x/ccv/provider/keeper/Untitled-1.json deleted file mode 100644 index 8ca2e0dda9..0000000000 --- a/x/ccv/provider/keeper/Untitled-1.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "params": { - "Enabled": true - }, - "new_chain": true, - "provider_client_state": { - "chain_id": "testchain1", - "trust_level": { - "numerator": 1, - "denominator": 3 - }, - "trusting_period": 907200000000000, - "unbonding_period": 1814400000000000, - "max_clock_drift": 10000000000, - "frozen_height": {}, - "latest_height": { - "revision_height": 5 - }, - "proof_specs": [ - { - "leaf_spec": { - "hash": 1, - "prehash_value": 1, - "length": 1, - "prefix": "AA==" - }, - "inner_spec": { - "child_order": [ - 0, - 1 - ], - "child_size": 33, - "min_prefix_length": 4, - "max_prefix_length": 12, - "hash": 1 - } - }, - { - "leaf_spec": { - "hash": 1, - "prehash_value": 1, - "length": 1, - "prefix": "AA==" - }, - "inner_spec": { - "child_order": [ - 0, - 1 - ], - "child_size": 32, - "min_prefix_length": 1, - "max_prefix_length": 1, - "hash": 1 - } - } - ], - "upgrade_path": [ - "upgrade", - "upgradedIBCState" - ], - "allow_update_after_expiry": true, - "allow_update_after_misbehaviour": true - }, - "provider_consensus_state": { - "timestamp": "2020-01-02T00:00:25Z", - "root": { - "hash": "LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA=" - }, - "next_validators_hash": "E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE" - }, - "unbonding_sequences": null, - "initial_val_set": [ - { - "pub_key": { - "Sum": { - "ed25519": "dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro=" - } - }, - "power": 1 - } - ] -} \ No newline at end of file From e43290f7744701c9008e7f1109801a0abc312753 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 May 2022 11:21:00 +0100 Subject: [PATCH 13/23] Renames child,parent->consumer,provider --- {app_child => app_consumer}/ante_handler.go | 0 {app_child => app_consumer}/app.go | 0 {app_child => app_consumer}/export.go | 0 {app_child => app_consumer}/genesis.go | 0 {app_parent => app_provider}/ante_handler.go | 0 {app_parent => app_provider}/app.go | 0 {app_parent => app_provider}/export.go | 0 {app_parent => app_provider}/genesis.go | 0 cmd/interchain-security-cd/main.go | 2 +- cmd/interchain-security-pd/main.go | 2 +- testutil/simapp/simapp.go | 24 +++--- x/ccv/child/keeper/genesis_test.go | 20 ++--- x/ccv/child/keeper/keeper_test.go | 84 ++++++++++---------- x/ccv/child/keeper/params_test.go | 24 +++--- x/ccv/child/keeper/relay_test.go | 38 ++++----- x/ccv/child/keeper/validators_test.go | 4 +- x/ccv/child/module_test.go | 30 +++---- x/ccv/parent/keeper/genesis_test.go | 20 ++--- x/ccv/parent/keeper/keeper_test.go | 18 ++--- x/ccv/parent/keeper/params_test.go | 8 +- x/ccv/parent/keeper/proposal_test.go | 14 ++-- x/ccv/parent/parent_test.go | 48 +++++------ x/ccv/parent/proposal_handler_test.go | 4 +- x/ccv/parent/unbonding_hook_test.go | 14 ++-- 24 files changed, 177 insertions(+), 177 deletions(-) rename {app_child => app_consumer}/ante_handler.go (100%) rename {app_child => app_consumer}/app.go (100%) rename {app_child => app_consumer}/export.go (100%) rename {app_child => app_consumer}/genesis.go (100%) rename {app_parent => app_provider}/ante_handler.go (100%) rename {app_parent => app_provider}/app.go (100%) rename {app_parent => app_provider}/export.go (100%) rename {app_parent => app_provider}/genesis.go (100%) diff --git a/app_child/ante_handler.go b/app_consumer/ante_handler.go similarity index 100% rename from app_child/ante_handler.go rename to app_consumer/ante_handler.go diff --git a/app_child/app.go b/app_consumer/app.go similarity index 100% rename from app_child/app.go rename to app_consumer/app.go diff --git a/app_child/export.go b/app_consumer/export.go similarity index 100% rename from app_child/export.go rename to app_consumer/export.go diff --git a/app_child/genesis.go b/app_consumer/genesis.go similarity index 100% rename from app_child/genesis.go rename to app_consumer/genesis.go diff --git a/app_parent/ante_handler.go b/app_provider/ante_handler.go similarity index 100% rename from app_parent/ante_handler.go rename to app_provider/ante_handler.go diff --git a/app_parent/app.go b/app_provider/app.go similarity index 100% rename from app_parent/app.go rename to app_provider/app.go diff --git a/app_parent/export.go b/app_provider/export.go similarity index 100% rename from app_parent/export.go rename to app_provider/export.go diff --git a/app_parent/genesis.go b/app_provider/genesis.go similarity index 100% rename from app_parent/genesis.go rename to app_provider/genesis.go diff --git a/cmd/interchain-security-cd/main.go b/cmd/interchain-security-cd/main.go index 54d8e16657..9d1b592704 100644 --- a/cmd/interchain-security-cd/main.go +++ b/cmd/interchain-security-cd/main.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - app "github.com/cosmos/interchain-security/app_child" + app "github.com/cosmos/interchain-security/app_consumer" "github.com/tendermint/spm/cosmoscmd" ) diff --git a/cmd/interchain-security-pd/main.go b/cmd/interchain-security-pd/main.go index 6c6c4d8540..01ef7bf19e 100644 --- a/cmd/interchain-security-pd/main.go +++ b/cmd/interchain-security-pd/main.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - app "github.com/cosmos/interchain-security/app_parent" + app "github.com/cosmos/interchain-security/app_provider" "github.com/tendermint/spm/cosmoscmd" ) diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index 5f117c63a9..c454064a4b 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -16,8 +16,8 @@ import ( tmtypes "github.com/tendermint/tendermint/types" tmdb "github.com/tendermint/tm-db" - childApp "github.com/cosmos/interchain-security/app_child" - parentApp "github.com/cosmos/interchain-security/app_parent" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" ) var defaultConsensusParams = &abci.ConsensusParams{ @@ -37,20 +37,20 @@ var defaultConsensusParams = &abci.ConsensusParams{ }, } -func SetupTestingParentApp() (ibctesting.TestingApp, map[string]json.RawMessage) { +func SetupTestingappProvider() (ibctesting.TestingApp, map[string]json.RawMessage) { db := tmdb.NewMemDB() // encCdc := app.MakeTestEncodingConfig() - encoding := cosmoscmd.MakeEncodingConfig(parentApp.ModuleBasics) - testApp := parentApp.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) - return testApp, parentApp.NewDefaultGenesisState(encoding.Marshaler) + encoding := cosmoscmd.MakeEncodingConfig(appProvider.ModuleBasics) + testApp := appProvider.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) + return testApp, appProvider.NewDefaultGenesisState(encoding.Marshaler) } -func SetupTestingChildApp() (ibctesting.TestingApp, map[string]json.RawMessage) { +func SetupTestingappConsumer() (ibctesting.TestingApp, map[string]json.RawMessage) { db := tmdb.NewMemDB() // encCdc := app.MakeTestEncodingConfig() - encoding := cosmoscmd.MakeEncodingConfig(childApp.ModuleBasics) - testApp := childApp.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) - return testApp, childApp.NewDefaultGenesisState(encoding.Marshaler) + encoding := cosmoscmd.MakeEncodingConfig(appConsumer.ModuleBasics) + testApp := appConsumer.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) + return testApp, appConsumer.NewDefaultGenesisState(encoding.Marshaler) } // NewCoordinator initializes Coordinator with 0 TestChains @@ -68,11 +68,11 @@ func NewBasicCoordinator(t *testing.T) *ibctesting.Coordinator { func NewParentChildCoordinator(t *testing.T) (*ibctesting.Coordinator, *ibctesting.TestChain, *ibctesting.TestChain) { coordinator := NewBasicCoordinator(t) chainID := ibctesting.GetChainID(0) - coordinator.Chains[chainID] = ibctesting.NewTestChain(t, coordinator, SetupTestingParentApp, chainID) + coordinator.Chains[chainID] = ibctesting.NewTestChain(t, coordinator, SetupTestingappProvider, chainID) parentChain := coordinator.GetChain(chainID) chainID = ibctesting.GetChainID(1) coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(t, coordinator, - SetupTestingChildApp, chainID, parentChain.Vals, parentChain.Signers) + SetupTestingappConsumer, chainID, parentChain.Vals, parentChain.Signers) childChain := coordinator.GetChain(chainID) return coordinator, parentChain, childChain } diff --git a/x/ccv/child/keeper/genesis_test.go b/x/ccv/child/keeper/genesis_test.go index e138eb8e39..ad6a540046 100644 --- a/x/ccv/child/keeper/genesis_test.go +++ b/x/ccv/child/keeper/genesis_test.go @@ -11,28 +11,28 @@ import ( parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" - childApp "github.com/cosmos/interchain-security/app_child" + appConsumer "github.com/cosmos/interchain-security/app_consumer" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (suite *KeeperTestSuite) TestGenesis() { - genesis := suite.childChain.App.(*childApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + genesis := suite.childChain.App.(*appConsumer.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) suite.Require().Equal(suite.parentClient, genesis.ParentClientState) suite.Require().Equal(suite.parentConsState, genesis.ParentConsensusState) suite.Require().NotPanics(func() { - suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) // reset suite to reset parent client suite.SetupTest() }) ctx := suite.childChain.GetContext() - portId := suite.childChain.App.(*childApp.App).ChildKeeper.GetPort(ctx) + portId := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPort(ctx) suite.Require().Equal(childtypes.PortID, portId) - clientId, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(ctx) + clientId, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(ctx) suite.Require().True(ok) clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(ctx, clientId) suite.Require().True(ok) @@ -62,25 +62,25 @@ func (suite *KeeperTestSuite) TestGenesis() { ) packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) + suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) // mocking the fact that child chain validators should be parent chain validators // TODO: Fix testing suite so we can initialize both chains with the same validator set valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) - restartGenesis := suite.childChain.App.(*childApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + restartGenesis := suite.childChain.App.(*appConsumer.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) restartGenesis.InitialValSet = valUpdates // ensure reset genesis is set correctly parentChannel := suite.path.EndpointA.ChannelID suite.Require().Equal(parentChannel, restartGenesis.ParentChannelId) - unbondingTime := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) + unbondingTime := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) suite.Require().Equal(uint64(origTime.Add(childtypes.UnbondingTime).UnixNano()), unbondingTime, "unbonding time is not set correctly in genesis") - unbondingPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) + unbondingPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) suite.Require().NoError(err) suite.Require().Equal(&packet, unbondingPacket, "unbonding packet is not set correctly in genesis") suite.Require().NotPanics(func() { - suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) }) } diff --git a/x/ccv/child/keeper/keeper_test.go b/x/ccv/child/keeper/keeper_test.go index 9ef38abe98..1e51b571dc 100644 --- a/x/ccv/child/keeper/keeper_test.go +++ b/x/ccv/child/keeper/keeper_test.go @@ -12,8 +12,8 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - childApp "github.com/cosmos/interchain-security/app_child" - parentApp "github.com/cosmos/interchain-security/app_parent" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/child/types" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -64,7 +64,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.childChain.GetContext() @@ -75,7 +75,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = ccv.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.ctx) if !ok { panic("must already have parent client on child chain") } @@ -88,7 +88,7 @@ func (suite *KeeperTestSuite) SetupTest() { // create child client on parent chain and set as child client for child chainID in parent keeper. suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) } func (suite *KeeperTestSuite) SetupCCVChannel() { @@ -97,7 +97,7 @@ func (suite *KeeperTestSuite) SetupCCVChannel() { } func (suite *KeeperTestSuite) TestParentClient() { - parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.ctx) suite.Require().True(ok) clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, parentClient) @@ -105,10 +105,10 @@ func (suite *KeeperTestSuite) TestParentClient() { } func (suite *KeeperTestSuite) TestParentChannel() { - _, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) + _, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().False(ok) - suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") - channelID, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") + channelID, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal("channelID", channelID) } @@ -134,34 +134,34 @@ func (suite *KeeperTestSuite) TestPendingChanges() { nil, ) - suite.childChain.App.(*childApp.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) - gotPd, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) + gotPd, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) suite.Require().Equal(&pd, gotPd, "packet data in store does not equal packet data set") - suite.childChain.App.(*childApp.App).ChildKeeper.DeletePendingChanges(suite.ctx) - gotPd, ok = suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*appConsumer.App).ChildKeeper.DeletePendingChanges(suite.ctx) + gotPd, ok = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().False(ok) suite.Require().Nil(gotPd, "got non-nil pending changes after Delete") } func (suite *KeeperTestSuite) TestUnbondingTime() { - suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) - suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) - suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) - suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) - suite.childChain.App.(*childApp.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) + suite.childChain.App.(*appConsumer.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) - suite.Require().Equal(uint64(10), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) - suite.Require().Equal(uint64(25), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) - suite.Require().Equal(uint64(15), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) + suite.Require().Equal(uint64(10), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) + suite.Require().Equal(uint64(25), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) + suite.Require().Equal(uint64(15), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) orderedTimes := [][]uint64{{1, 10}, {2, 25}, {5, 15}} i := 0 - suite.childChain.App.(*childApp.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { + suite.childChain.App.(*appConsumer.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { // require that we iterate through unbonding time in order of sequence suite.Require().Equal(orderedTimes[i][0], seq) suite.Require().Equal(orderedTimes[i][1], time) @@ -193,22 +193,22 @@ func (suite *KeeperTestSuite) TestUnbondingPacket() { ) packet := channeltypes.NewPacket(pd.GetBytes(), uint64(i), "parent", "channel-1", "child", "channel-1", clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) } // ensure that packets are iterated by sequence i := 0 - suite.childChain.App.(*childApp.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { + suite.childChain.App.(*appConsumer.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { suite.Require().Equal(uint64(i), seq) - gotPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) + gotPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) suite.Require().NoError(err) suite.Require().Equal(&packet, gotPacket, "packet from get and iteration do not match") i++ return false }) - suite.childChain.App.(*childApp.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) - gotPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) + suite.childChain.App.(*appConsumer.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) + gotPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) suite.Require().Error(err) suite.Require().Nil(gotPacket, "packet is not nil after delete") } @@ -231,7 +231,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -247,7 +247,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to validating - suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -262,7 +262,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID, "connection-2"} }, @@ -272,7 +272,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { name: "connection does not exist", setup: func(suite *KeeperTestSuite) { // set channel status to INITIALIZING - suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{"connection-dne"} }, @@ -290,7 +290,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -306,7 +306,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { tc.setup(suite) // Verify ParentChain on child chain using path returned by setup - err := suite.childChain.App.(*childApp.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) + err := suite.childChain.App.(*appConsumer.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) if tc.expError { suite.Require().Error(err, "invalid case did not return error") @@ -325,7 +325,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { suite.SetupCCVChannel() suite.SendEmptyVSCPacket() - app, ctx := suite.childChain.App.(*childApp.App), suite.childChain.GetContext() + app, ctx := suite.childChain.App.(*appConsumer.App), suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID // pick a cross-chain validator @@ -393,7 +393,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { suite.SetupCCVChannel() - app := suite.childChain.App.(*childApp.App) + app := suite.childChain.App.(*appConsumer.App) ctx := suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID @@ -458,7 +458,7 @@ func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { } func (suite *KeeperTestSuite) TestCrossChainValidator() { - app := suite.childChain.App.(*childApp.App) + app := suite.childChain.App.(*appConsumer.App) ctx := suite.childChain.GetContext() // should return false @@ -485,7 +485,7 @@ func (suite *KeeperTestSuite) TestCrossChainValidator() { } func (suite *KeeperTestSuite) TestPendingSlashRequests() { - childKeeper := suite.childChain.App.(*childApp.App).ChildKeeper + childKeeper := suite.childChain.App.(*appConsumer.App).ChildKeeper ctx := suite.childChain.GetContext() // prepare test setup by storing 10 pending slash requests @@ -522,8 +522,8 @@ func (suite *KeeperTestSuite) TestPendingSlashRequests() { // to ensure that the channel gets established func (suite *KeeperTestSuite) SendEmptyVSCPacket() { - childKeeper := suite.childChain.App.(*childApp.App).ChildKeeper - parentKeeper := suite.parentChain.App.(*parentApp.App).ParentKeeper + childKeeper := suite.childChain.App.(*appConsumer.App).ChildKeeper + parentKeeper := suite.parentChain.App.(*appProvider.App).ParentKeeper oldBlockTime := suite.parentChain.GetContext().BlockTime() timeout := uint64(ccv.GetTimeoutTimestamp(oldBlockTime).UnixNano()) @@ -536,7 +536,7 @@ func (suite *KeeperTestSuite) SendEmptyVSCPacket() { nil, ) - seq, ok := suite.parentChain.App.(*parentApp.App).GetIBCKeeper().ChannelKeeper.GetNextSequenceSend( + seq, ok := suite.parentChain.App.(*appProvider.App).GetIBCKeeper().ChannelKeeper.GetNextSequenceSend( suite.parentChain.GetContext(), parenttypes.PortID, suite.path.EndpointB.ChannelID) suite.Require().True(ok) diff --git a/x/ccv/child/keeper/params_test.go b/x/ccv/child/keeper/params_test.go index b2f92ef164..4420bfa491 100644 --- a/x/ccv/child/keeper/params_test.go +++ b/x/ccv/child/keeper/params_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - childApp "github.com/cosmos/interchain-security/app_child" + appConsumer "github.com/cosmos/interchain-security/app_consumer" "github.com/cosmos/interchain-security/x/ccv/child/types" ) @@ -9,35 +9,35 @@ func (suite *KeeperTestSuite) TestParams() { // suite setup initializes genesis expParams := types.NewParams(true, 1000, "", "", "0") // these are the default params - params := suite.childChain.App.(*childApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + params := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParams(suite.childChain.GetContext()) suite.Require().Equal(expParams, params) newParams := types.NewParams(false, 1000, "abc", "def", "0.6") - suite.childChain.App.(*childApp.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) - params = suite.childChain.App.(*childApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) + params = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParams(suite.childChain.GetContext()) suite.Require().Equal(newParams, params) - suite.childChain.App.(*childApp.App).ChildKeeper. + suite.childChain.App.(*appConsumer.App).ChildKeeper. SetBlocksPerDistributionTransmission(suite.childChain.GetContext(), 10) - gotBPDT := suite.childChain.App.(*childApp.App).ChildKeeper. + gotBPDT := suite.childChain.App.(*appConsumer.App).ChildKeeper. GetBlocksPerDistributionTransmission(suite.childChain.GetContext()) suite.Require().Equal(gotBPDT, int64(10)) - suite.childChain.App.(*childApp.App).ChildKeeper. + suite.childChain.App.(*appConsumer.App).ChildKeeper. SetDistributionTransmissionChannel(suite.childChain.GetContext(), "foobarbaz") - gotChan := suite.childChain.App.(*childApp.App).ChildKeeper. + gotChan := suite.childChain.App.(*appConsumer.App).ChildKeeper. GetDistributionTransmissionChannel(suite.childChain.GetContext()) suite.Require().Equal(gotChan, "foobarbaz") - suite.childChain.App.(*childApp.App).ChildKeeper. + suite.childChain.App.(*appConsumer.App).ChildKeeper. SetProviderFeePoolAddrStr(suite.childChain.GetContext(), "foobar") - gotAddr := suite.childChain.App.(*childApp.App).ChildKeeper. + gotAddr := suite.childChain.App.(*appConsumer.App).ChildKeeper. GetProviderFeePoolAddrStr(suite.childChain.GetContext()) suite.Require().Equal(gotAddr, "foobar") - suite.childChain.App.(*childApp.App).ChildKeeper. + suite.childChain.App.(*appConsumer.App).ChildKeeper. SetConsumerRedistributeFrac(suite.childChain.GetContext(), "0.75") - gotFrac := suite.childChain.App.(*childApp.App).ChildKeeper. + gotFrac := suite.childChain.App.(*appConsumer.App).ChildKeeper. GetConsumerRedistributeFrac(suite.childChain.GetContext()) suite.Require().Equal(gotFrac, "0.75") } diff --git a/x/ccv/child/keeper/relay_test.go b/x/ccv/child/keeper/relay_test.go index aeda3eba7e..6fdc7e5e65 100644 --- a/x/ccv/child/keeper/relay_test.go +++ b/x/ccv/child/keeper/relay_test.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - childApp "github.com/cosmos/interchain-security/app_child" + appConsumer "github.com/cosmos/interchain-security/app_consumer" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -117,22 +117,22 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } for _, tc := range testCases { - ack := suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) + ack := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) if tc.expErrorAck { suite.Require().NotNil(ack, "invalid test case: %s did not return ack", tc.name) suite.Require().False(ack.Success(), "invalid test case: %s did not return an Error Acknowledgment") } else { suite.Require().Nil(ack, "successful packet must send ack asynchronously. case: %s", tc.name) - suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*childApp.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), + suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*appConsumer.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), "channel status is not valdidating after receive packet for valid test case: %s", tc.name) - parentChannel, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) + parentChannel, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal(tc.packet.DestinationChannel, parentChannel, "parent channel is not destination channel on successful receive for valid test case: %s", tc.name) // Check that pending changes are accumulated and stored correctly - actualPendingChanges, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + actualPendingChanges, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) // Sort to avoid dumb inequalities sort.SliceStable(actualPendingChanges.ValidatorUpdates, func(i, j int) bool { @@ -144,9 +144,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { suite.Require().Equal(tc.expectedPendingChanges, *actualPendingChanges, "pending changes not equal to expected changes after successful packet receive. case: %s", tc.name) expectedTime := uint64(suite.ctx.BlockTime().Add(childtypes.UnbondingTime).UnixNano()) - unbondingTime := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) + unbondingTime := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) suite.Require().Equal(expectedTime, unbondingTime, "unbonding time has unexpected value for case: %s", tc.name) - unbondingPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) + unbondingPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) suite.Require().NoError(err) suite.Require().Equal(&tc.packet, unbondingPacket, "packet is not added to unbonding queue after successful receive. case: %s", tc.name) } @@ -183,7 +183,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { // send first packet packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - ack := suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send second packet @@ -191,7 +191,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[0].Power = 15 packet.Data = pd.GetBytes() packet.Sequence = 2 - ack = suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send third packet @@ -199,25 +199,25 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[1].Power = 40 packet.Data = pd.GetBytes() packet.Sequence = 3 - ack = suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // move ctx time forward such that first two packets are unbonded but third is not. suite.ctx = suite.ctx.WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) - suite.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(suite.ctx) + suite.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(suite.ctx) // ensure first two packets are unbonded and acknowledgement is written // unbonded time is deleted - time1 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) - time2 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) + time1 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) + time2 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) suite.Require().Equal(uint64(0), time1, "unbonding time not deleted for mature packet 1") suite.Require().Equal(uint64(0), time2, "unbonding time not deleted for mature packet 2") // unbonded packets are deleted - _, err = suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) + _, err = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") - _, err = suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) + _, err = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") expectedWriteAckBytes := channeltypes.CommitAcknowledgement(channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()) @@ -231,9 +231,9 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { suite.Require().Equal(expectedWriteAckBytes, ackBytes2, "did not write successful ack for matue packet 1") // ensure that third packet did not get ack written and is still in store - time3 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) + time3 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) suite.Require().True(time3 > uint64(suite.ctx.BlockTime().UnixNano()), "Unbonding time for packet 3 is not after current time") - packet3, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) + packet3, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) suite.Require().NoError(err, "retrieving unbonding packet 3 returned error") suite.Require().Equal(&packet, packet3, "unbonding packet 3 has unexpected value") @@ -254,12 +254,12 @@ func (suite *KeeperTestSuite) TestOnAcknowledgement() { ack := channeltypes.NewResultAcknowledgement([]byte{1}) // expect no error - err := suite.childChain.App.(*childApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.Nil(err) // expect an error ack = channeltypes.NewErrorAcknowledgement("error") - err = suite.childChain.App.(*childApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.NotNil(err) } diff --git a/x/ccv/child/keeper/validators_test.go b/x/ccv/child/keeper/validators_test.go index 441dff1b91..9a8468a259 100644 --- a/x/ccv/child/keeper/validators_test.go +++ b/x/ccv/child/keeper/validators_test.go @@ -1,14 +1,14 @@ package keeper_test import ( - childApp "github.com/cosmos/interchain-security/app_child" + appConsumer "github.com/cosmos/interchain-security/app_consumer" "github.com/cosmos/interchain-security/x/ccv/child/types" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (k KeeperTestSuite) TestApplyCCValidatorChanges() { - childKeeper := k.childChain.App.(*childApp.App).ChildKeeper + childKeeper := k.childChain.App.(*appConsumer.App).ChildKeeper ctx := k.ctx // utility functions diff --git a/x/ccv/child/module_test.go b/x/ccv/child/module_test.go index 66651ec705..3d7c48e0ad 100644 --- a/x/ccv/child/module_test.go +++ b/x/ccv/child/module_test.go @@ -13,8 +13,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - childApp "github.com/cosmos/interchain-security/app_child" - parentApp "github.com/cosmos/interchain-security/app_parent" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/child" "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -69,7 +69,7 @@ func (suite *ChildTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) // create the ccv path and set child's clientID to genesis client path := ibctesting.NewPath(suite.childChain, suite.parentChain) @@ -79,7 +79,7 @@ func (suite *ChildTestSuite) SetupTest() { path.EndpointB.ChannelConfig.Version = ccv.Version path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -92,7 +92,7 @@ func (suite *ChildTestSuite) SetupTest() { // create child client on parent chain and set as child client for child chainID in parent keeper. path.EndpointB.CreateClient() - suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, path.EndpointB.ClientID) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, path.EndpointB.ClientID) suite.coordinator.CreateConnections(path) @@ -124,7 +124,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { { name: "invalid: parent channel already established", setup: func(suite *ChildTestSuite) { - suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") // Set INIT channel on child chain suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, channeltypes.NewChannel( @@ -217,7 +217,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) suite.Require().NoError(err) @@ -235,7 +235,7 @@ func (suite *ChildTestSuite) TestOnChanOpenInit() { func (suite *ChildTestSuite) TestOnChanOpenTry() { // OnOpenTry must error even with correct arguments - childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) suite.Require().NoError(err) @@ -266,7 +266,7 @@ func (suite *ChildTestSuite) TestOnChanOpenAck() { { name: "invalid: parent channel already established", setup: func(suite *ChildTestSuite) { - suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") // Set INIT channel on child chain suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, channeltypes.NewChannel( @@ -300,7 +300,7 @@ func (suite *ChildTestSuite) TestOnChanOpenAck() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) md := parenttypes.HandshakeMetadata{ ProviderFeePoolAddr: "", // dummy address used @@ -326,7 +326,7 @@ func (suite *ChildTestSuite) TestOnChanOpenConfirm() { []string{"connection-1"}, ccv.Version, )) - childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) err := childModule.OnChanOpenConfirm(suite.ctx, childtypes.PortID, "channel-1") suite.Require().Error(err, "OnChanOpenConfirm must always fail") @@ -349,7 +349,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), ) suite.path.EndpointA.ChannelID = channelID - suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") }, expError: false, }, @@ -358,7 +358,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { setup: func(suite *ChildTestSuite) { // create open channel suite.coordinator.CreateChannels(suite.path) - suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") }, expError: false, }, @@ -380,7 +380,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { setup: func(suite *ChildTestSuite) { // create open channel suite.coordinator.CreateChannels(suite.path) - suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, suite.path.EndpointA.ChannelID) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, suite.path.EndpointA.ChannelID) }, expError: true, }, @@ -392,7 +392,7 @@ func (suite *ChildTestSuite) TestOnChanCloseInit() { suite.SetupTest() // reset suite tc.setup(suite) - childModule := child.NewAppModule(suite.childChain.App.(*childApp.App).ChildKeeper) + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) err := childModule.OnChanCloseInit(suite.ctx, childtypes.PortID, suite.path.EndpointA.ChannelID) diff --git a/x/ccv/parent/keeper/genesis_test.go b/x/ccv/parent/keeper/genesis_test.go index a9219efc89..43669b3cf6 100644 --- a/x/ccv/parent/keeper/genesis_test.go +++ b/x/ccv/parent/keeper/genesis_test.go @@ -3,8 +3,8 @@ package keeper_test import ( "fmt" - childApp "github.com/cosmos/interchain-security/app_child" - parentApp "github.com/cosmos/interchain-security/app_parent" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/x/ccv/types" ) @@ -12,27 +12,27 @@ func (suite *KeeperTestSuite) TestGenesis() { // set some chain-channel pairs before exporting ctx := suite.parentChain.GetContext() for i := 0; i < 4; i++ { - suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChainToChannel(ctx, fmt.Sprintf("chainid-%d", i), fmt.Sprintf("channelid-%d", i)) - suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChannelToChain(ctx, fmt.Sprintf("channelid-%d", i), fmt.Sprintf("chainid-%d", i)) - suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChannelStatus(ctx, fmt.Sprintf("channelid-%d", i), types.Status(i)) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChainToChannel(ctx, fmt.Sprintf("chainid-%d", i), fmt.Sprintf("channelid-%d", i)) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChannelToChain(ctx, fmt.Sprintf("channelid-%d", i), fmt.Sprintf("chainid-%d", i)) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChannelStatus(ctx, fmt.Sprintf("channelid-%d", i), types.Status(i)) } - genState := suite.parentChain.App.(*parentApp.App).ParentKeeper.ExportGenesis(suite.parentChain.GetContext()) + genState := suite.parentChain.App.(*appProvider.App).ParentKeeper.ExportGenesis(suite.parentChain.GetContext()) - suite.childChain.App.(*childApp.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) + suite.childChain.App.(*appConsumer.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) ctx = suite.childChain.GetContext() for i := 0; i < 4; i++ { expectedChainId := fmt.Sprintf("chainid-%d", i) expectedChannelId := fmt.Sprintf("channelid-%d", i) - channelID, channelOk := suite.childChain.App.(*childApp.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) - chainID, chainOk := suite.childChain.App.(*childApp.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) + channelID, channelOk := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) + chainID, chainOk := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) suite.Require().True(channelOk) suite.Require().True(chainOk) suite.Require().Equal(expectedChainId, chainID, "did not store correct chain id for given channel id") suite.Require().Equal(expectedChannelId, channelID, "did not store correct channel id for given chain id") - status := suite.childChain.App.(*childApp.App).ParentKeeper.GetChannelStatus(ctx, channelID) + status := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChannelStatus(ctx, channelID) suite.Require().Equal(types.Status(i), status, "status is unexpected for given channel id: %s", channelID) } } diff --git a/x/ccv/parent/keeper/keeper_test.go b/x/ccv/parent/keeper/keeper_test.go index 556332fed6..4a479ca9d6 100644 --- a/x/ccv/parent/keeper/keeper_test.go +++ b/x/ccv/parent/keeper/keeper_test.go @@ -11,8 +11,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - childApp "github.com/cosmos/interchain-security/app_child" - parentApp "github.com/cosmos/interchain-security/app_parent" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/testutil/simapp" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" @@ -66,7 +66,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.parentChain.GetContext() @@ -77,7 +77,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -90,7 +90,7 @@ func (suite *KeeperTestSuite) SetupTest() { // create child client on parent chain and set as child client for child chainID in parent keeper. suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) } func TestKeeperTestSuite(t *testing.T) { @@ -98,7 +98,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *KeeperTestSuite) TestValsetUpdateBlockHeight() { - app := suite.parentChain.App.(*parentApp.App) + app := suite.parentChain.App.(*appProvider.App) ctx := suite.ctx blockHeight := app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(0)) @@ -119,7 +119,7 @@ func (suite *KeeperTestSuite) TestValsetUpdateBlockHeight() { } func (suite *KeeperTestSuite) TestSlashAcks() { - app := suite.parentChain.App.(*parentApp.App) + app := suite.parentChain.App.(*appProvider.App) ctx := suite.ctx var chainsAcks [][]string @@ -161,7 +161,7 @@ func (suite *KeeperTestSuite) TestSlashAcks() { } func (suite *KeeperTestSuite) TestAppendslashingAck() { - app := suite.parentChain.App.(*parentApp.App) + app := suite.parentChain.App.(*appProvider.App) ctx := suite.ctx p := []string{"alice", "bob", "charlie"} @@ -180,7 +180,7 @@ func (suite *KeeperTestSuite) TestAppendslashingAck() { } func (suite *KeeperTestSuite) TestInitHeight() { - app := suite.parentChain.App.(*parentApp.App) + app := suite.parentChain.App.(*appProvider.App) ctx := suite.ctx tc := []struct { diff --git a/x/ccv/parent/keeper/params_test.go b/x/ccv/parent/keeper/params_test.go index 875d0ffdab..ec0513fdf0 100644 --- a/x/ccv/parent/keeper/params_test.go +++ b/x/ccv/parent/keeper/params_test.go @@ -6,19 +6,19 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - parentApp "github.com/cosmos/interchain-security/app_parent" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/x/ccv/parent/types" ) func (suite *KeeperTestSuite) TestParams() { expParams := types.DefaultParams() - params := suite.parentChain.App.(*parentApp.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) + params := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) suite.Require().Equal(expParams, params) newParams := types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false)) - suite.parentChain.App.(*parentApp.App).ParentKeeper.SetParams(suite.parentChain.GetContext(), newParams) - params = suite.parentChain.App.(*parentApp.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetParams(suite.parentChain.GetContext(), newParams) + params = suite.parentChain.App.(*appProvider.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) suite.Require().Equal(newParams, params) } diff --git a/x/ccv/parent/keeper/proposal_test.go b/x/ccv/parent/keeper/proposal_test.go index 4010ed8592..4105fd7ea8 100644 --- a/x/ccv/parent/keeper/proposal_test.go +++ b/x/ccv/parent/keeper/proposal_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - parentApp "github.com/cosmos/interchain-security/app_parent" + appProvider "github.com/cosmos/interchain-security/app_provider" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" "github.com/cosmos/interchain-security/x/ccv/parent/types" abci "github.com/tendermint/tendermint/abci/types" @@ -19,7 +19,7 @@ func (suite *KeeperTestSuite) TestMakeChildGenesis() { suite.SetupTest() ctx = suite.parentChain.GetContext().WithBlockTime(time.Now()) - actualGenesis, err := suite.parentChain.App.(*parentApp.App).ParentKeeper.MakeChildGenesis(ctx) + actualGenesis, err := suite.parentChain.App.(*appProvider.App).ParentKeeper.MakeChildGenesis(ctx) suite.Require().NoError(err) jsonString := `{"params":{"Enabled":true},"new_chain":true,"parent_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"parent_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` @@ -88,21 +88,21 @@ func (suite *KeeperTestSuite) TestCreateChildChainProposal() { tc.malleate(suite) - err := suite.parentChain.App.(*parentApp.App).ParentKeeper.CreateChildChainProposal(ctx, proposal) + err := suite.parentChain.App.(*appProvider.App).ParentKeeper.CreateChildChainProposal(ctx, proposal) if tc.expPass { suite.Require().NoError(err, "error returned on valid case") if tc.spawnReached { - clientId := suite.parentChain.App.(*parentApp.App).ParentKeeper.GetChildClient(ctx, chainID) - childGenesis, ok := suite.parentChain.App.(*parentApp.App).ParentKeeper.GetChildGenesis(ctx, chainID) + clientId := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetChildClient(ctx, chainID) + childGenesis, ok := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetChildGenesis(ctx, chainID) suite.Require().True(ok) - expectedGenesis, err := suite.parentChain.App.(*parentApp.App).ParentKeeper.MakeChildGenesis(ctx) + expectedGenesis, err := suite.parentChain.App.(*appProvider.App).ParentKeeper.MakeChildGenesis(ctx) suite.Require().NoError(err) suite.Require().Equal(expectedGenesis, childGenesis) suite.Require().NotEqual("", clientId, "child client was not created after spawn time reached") } else { - gotHeight := suite.parentChain.App.(*parentApp.App).ParentKeeper.GetPendingClientInfo(ctx, proposal.SpawnTime, chainID) + gotHeight := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetPendingClientInfo(ctx, proposal.SpawnTime, chainID) suite.Require().Equal(initialHeight, gotHeight, "pending client not equal to clientstate in proposal") } } else { diff --git a/x/ccv/parent/parent_test.go b/x/ccv/parent/parent_test.go index 4718b337c3..6b0655bd38 100644 --- a/x/ccv/parent/parent_test.go +++ b/x/ccv/parent/parent_test.go @@ -22,8 +22,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - childApp "github.com/cosmos/interchain-security/app_child" - parentApp "github.com/cosmos/interchain-security/app_parent" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/testutil/simapp" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" @@ -86,7 +86,7 @@ func (suite *ParentTestSuite) SetupTest() { "0.5", // 50% ) childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.parentChain.GetContext() @@ -97,7 +97,7 @@ func (suite *ParentTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -110,7 +110,7 @@ func (suite *ParentTestSuite) SetupTest() { // create child client on parent chain and set as child client for child chainID in parent keeper. suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*parentApp.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) suite.transferPath = ibctesting.NewPath(suite.childChain, suite.parentChain) suite.transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID @@ -134,7 +134,7 @@ func (suite *ParentTestSuite) SetupCCVChannel() { suite.transferPath.EndpointB.ConnectionID = suite.path.EndpointB.ConnectionID // INIT step for transfer path has already been called during CCV channel setup - suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*childApp.App). + suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*appConsumer.App). ChildKeeper.GetDistributionTransmissionChannel(suite.childChain.GetContext()) // Complete TRY, ACK, CONFIRM for transfer path @@ -177,7 +177,7 @@ func (s *ParentTestSuite) TestPacketRoundtrip() { s.Require().NoError(err) // Save valset update ID to reconstruct packet - valUpdateID := s.parentChain.App.(*parentApp.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) // Send CCV packet to consumer s.parentChain.App.EndBlock(abci.RequestEndBlock{}) @@ -210,7 +210,7 @@ func (s *ParentTestSuite) TestPacketRoundtrip() { // - End consumer unbonding period childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) // TODO: why doesn't this work: s.childChain.App.EndBlock(abci.RequestEndBlock{}) - err = s.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(childCtx) + err = s.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) // commit child chain and update parent chain client @@ -234,7 +234,7 @@ func (s *ParentTestSuite) childCtx() sdk.Context { } func (s *ParentTestSuite) parentBondDenom() string { - return s.parentChain.App.(*parentApp.App).StakingKeeper.BondDenom(s.parentCtx()) + return s.parentChain.App.(*appProvider.App).StakingKeeper.BondDenom(s.parentCtx()) } // TestSendDowntimePacket tests consumer initiated slashing @@ -243,9 +243,9 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { validatorsPerChain := len(s.childChain.Vals.Validators) parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentSlashingKeeper := s.parentChain.App.(*parentApp.App).SlashingKeeper + parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper - childKeeper := s.childChain.App.(*childApp.App).ChildKeeper + childKeeper := s.childChain.App.(*appConsumer.App).ChildKeeper // get a cross-chain validator address, pubkey and balance tmVals := s.childChain.Vals.Validators @@ -288,12 +288,12 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { s.Require().NoError(err) // Set outstanding slashing flag - s.childChain.App.(*childApp.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) + s.childChain.App.(*appConsumer.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) // save next VSC packet info oldBlockTime = s.parentCtx().BlockTime() timeout = uint64(types.GetTimeoutTimestamp(oldBlockTime).UnixNano()) - valsetUpdateID := s.parentChain.App.(*parentApp.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valsetUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) // receive the downtime packet on the parent chain; // RecvPacket() calls the parent endblocker thus sends a VSC packet to the consumer @@ -352,7 +352,7 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { s.Require().True(valSignInfo.JailedUntil.After(s.parentCtx().BlockHeader().Time)) // check that the outstanding slashing flag is reset on the child - pFlag := s.childChain.App.(*childApp.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) + pFlag := s.childChain.App.(*appConsumer.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) s.Require().False(pFlag) // check that slashing packet gets acknowledged @@ -376,8 +376,8 @@ func (s *ParentTestSuite) getVal(index int) (validator stakingtypes.Validator, v func (s *ParentTestSuite) TestHandleConsumerDowntime() { s.SetupCCVChannel() parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentSlashingKeeper := s.parentChain.App.(*parentApp.App).SlashingKeeper - parentKeeper := s.parentChain.App.(*parentApp.App).ParentKeeper + parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper + parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper // bonded amount bondAmt := sdk.NewInt(1000000) @@ -485,8 +485,8 @@ func (s *ParentTestSuite) TestHandleConsumerDowntime() { func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentKeeper := s.parentChain.App.(*parentApp.App).ParentKeeper - parentSlashingKeeper := s.parentChain.App.(*parentApp.App).SlashingKeeper + parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper + parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper childChainID := s.childChain.ChainID // expect an error if initial block height isn't set for child chain @@ -555,8 +555,8 @@ func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { } func (s *ParentTestSuite) TestslashingPacketAcknowldgement() { - parentKeeper := s.parentChain.App.(*parentApp.App).ParentKeeper - childKeeper := s.childChain.App.(*childApp.App).ChildKeeper + parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper + childKeeper := s.childChain.App.(*appConsumer.App).ChildKeeper packet := channeltypes.NewPacket([]byte{}, 1, childtypes.PortID, s.path.EndpointA.ChannelID, parenttypes.PortID, "wrongchannel", clienttypes.Height{}, 0) @@ -613,7 +613,7 @@ func (s *ParentTestSuite) UpdateChildHistInfo(changes []abci.ValidatorUpdate) { func (s *ParentTestSuite) DisableConsumerDistribution() { cChain := s.childChain - cApp := cChain.App.(*childApp.App) + cApp := cChain.App.(*appConsumer.App) for i, moduleName := range cApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { cApp.MM.OrderBeginBlockers = append(cApp.MM.OrderBeginBlockers[:i], cApp.MM.OrderBeginBlockers[i+1:]...) @@ -624,7 +624,7 @@ func (s *ParentTestSuite) DisableConsumerDistribution() { func (s *ParentTestSuite) DisableProviderDistribution() { pChain := s.parentChain - pApp := pChain.App.(*parentApp.App) + pApp := pChain.App.(*appProvider.App) for i, moduleName := range pApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { s.providerDistrIndex = i @@ -636,7 +636,7 @@ func (s *ParentTestSuite) DisableProviderDistribution() { func (s *ParentTestSuite) ReenableProviderDistribution() { pChain := s.parentChain - pApp := pChain.App.(*parentApp.App) + pApp := pChain.App.(*appProvider.App) i := s.providerDistrIndex pApp.MM.OrderBeginBlockers = append( pApp.MM.OrderBeginBlockers[:i+1], pApp.MM.OrderBeginBlockers[i:]...) // make space @@ -651,7 +651,7 @@ func (s *ParentTestSuite) TestDistribution() { // s.transferPath.EndpointB == Provider Chain pChain, cChain := s.parentChain, s.childChain - pApp, cApp := pChain.App.(*parentApp.App), cChain.App.(*childApp.App) + pApp, cApp := pChain.App.(*appProvider.App), cChain.App.(*appConsumer.App) cKeep := cApp.ChildKeeper // Get the receiving fee pool on the provider chain diff --git a/x/ccv/parent/proposal_handler_test.go b/x/ccv/parent/proposal_handler_test.go index 096b5e9b6b..ab12c590f7 100644 --- a/x/ccv/parent/proposal_handler_test.go +++ b/x/ccv/parent/proposal_handler_test.go @@ -8,7 +8,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - parentApp "github.com/cosmos/interchain-security/app_parent" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/x/ccv/parent" "github.com/cosmos/interchain-security/x/ccv/parent/types" ) @@ -56,7 +56,7 @@ func (suite *ParentTestSuite) TestCreateChildChainProposalHandler() { tc.malleate(suite) - proposalHandler := parent.NewCreateChildChainHandler(suite.parentChain.App.(*parentApp.App).ParentKeeper) + proposalHandler := parent.NewCreateChildChainHandler(suite.parentChain.App.(*appProvider.App).ParentKeeper) err = proposalHandler(ctx, content) diff --git a/x/ccv/parent/unbonding_hook_test.go b/x/ccv/parent/unbonding_hook_test.go index 629d2a8fc8..d1e93e7d01 100644 --- a/x/ccv/parent/unbonding_hook_test.go +++ b/x/ccv/parent/unbonding_hook_test.go @@ -11,8 +11,8 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - childApp "github.com/cosmos/interchain-security/app_child" - parentApp "github.com/cosmos/interchain-security/app_parent" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -161,7 +161,7 @@ func (s *ParentTestSuite) TestStakingHooks1() { } func getBalance(s *ParentTestSuite, parentCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int { - return s.parentChain.App.(*parentApp.App).BankKeeper.GetBalance(parentCtx, delAddr, s.parentBondDenom()).Amount + return s.parentChain.App.(*appProvider.App).BankKeeper.GetBalance(parentCtx, delAddr, s.parentBondDenom()).Amount } func doUnbonding(s *ParentTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (initBalance sdk.Int, valsetUpdateId uint64) { @@ -187,7 +187,7 @@ func doUnbonding(s *ParentTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (i s.Require().True(getBalance(s, s.parentCtx(), delAddr).Equal(initBalance.Sub(bondAmt))) // save the current valset update ID - valsetUpdateID := s.parentChain.App.(*parentApp.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valsetUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) return initBalance, valsetUpdateID } @@ -205,7 +205,7 @@ func endChildUnbondingPeriod(s *ParentTestSuite, origTime time.Time) { // - End consumer unbonding period childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) // s.childChain.App.EndBlock(abci.RequestEndBlock{}) // <- this doesn't work because we can't modify the ctx - err := s.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(childCtx) + err := s.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) } @@ -216,7 +216,7 @@ func checkStakingUnbondingOps(s *ParentTestSuite, id uint64, found bool, onHold } func checkCCVUnbondingOp(s *ParentTestSuite, parentCtx sdk.Context, chainID string, valUpdateID uint64, found bool) { - _, wasFound := s.parentChain.App.(*parentApp.App).ParentKeeper.GetUnbondingOpsFromIndex(parentCtx, chainID, valUpdateID) + _, wasFound := s.parentChain.App.(*appProvider.App).ParentKeeper.GetUnbondingOpsFromIndex(parentCtx, chainID, valUpdateID) s.Require().True(found == wasFound) } @@ -259,7 +259,7 @@ func sendValUpdateAck(s *ParentTestSuite, parentCtx sdk.Context, packet channelt // err := s.path.EndpointB.AcknowledgePacket(packet, ack.Acknowledgement()) // s.Require().NoError(err) - err := s.parentChain.App.(*parentApp.App).ParentKeeper.OnAcknowledgementPacket(parentCtx, packet, packetData, ack) + err := s.parentChain.App.(*appProvider.App).ParentKeeper.OnAcknowledgementPacket(parentCtx, packet, packetData, ack) s.Require().NoError(err) } From 52634463cb755dbc0d8bb7eef419020b68381b30 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 May 2022 12:43:07 +0100 Subject: [PATCH 14/23] Squashed commit of the following: commit e43290f7744701c9008e7f1109801a0abc312753 Author: Daniel Date: Wed May 4 11:21:00 2022 +0100 Renames child,parent->consumer,provider commit d94a8d159b41c41ae77df7e1a91ee5c75b564455 Author: Daniel Date: Tue May 3 18:48:35 2022 +0100 Uses child or parent app correctly in tests commit f21435d53eae3d0036c454957751a46b4185f7a0 Author: Daniel Date: Tue May 3 18:40:59 2022 +0100 Use correct app in child/module_test commit bfb00064feb150cda0e57952c17f8c45c4940133 Author: Daniel Date: Tue May 3 17:48:34 2022 +0100 (testfail) replace all app instances with parentApp commit 5d761f2312928a15fe0eea43a1be0f00c877fedc Author: Daniel Date: Tue May 3 17:11:24 2022 +0100 Use distinct parent, child in simapp commit 745d96da89f8e98bebb14a8d4fdc3dea5da46fc7 Author: Daniel Date: Tue May 3 17:02:05 2022 +0100 (nobuild) delete testutils/../network.go commit 6c65d9240b44a7b19840b5bef55cf70ca349797d Author: Daniel Date: Tue May 3 16:56:54 2022 +0100 (nobuild) simply dup app/ dir for parent, child commit aa2df7216d1a2bfeb5026426b8256b35fc9624af Author: Daniel Date: Tue May 3 16:47:56 2022 +0100 Use seperate cmd binaries for p and c commit e766d6eafc549c0d2580a0d4e5306ae92f089c62 Author: Daniel Date: Tue May 3 16:06:48 2022 +0100 Use NewParentChildCoordinator in tests Reuse a shared util function instead of overwriting global variable commit 31a67d2ca202dfd62a9ae414f3e626b1825800a2 Author: Daniel Date: Tue May 3 15:53:26 2022 +0100 (nobuild) makes minimal changes to allow 2 app.go commit a84b12508aa46d3a2aa4154b6cf4cf187c912214 Author: Daniel Date: Tue May 3 14:00:11 2022 +0100 Replaces ibg-go with local version for dev commit 22a2ed3276c114f40d155bfd981e11b23946c7ab Author: Daniel Date: Tue May 3 11:12:12 2022 +0100 Adds TODO to remove hack --- {app => app_consumer}/ante_handler.go | 0 {app => app_consumer}/app.go | 2 +- {app => app_consumer}/export.go | 0 {app => app_consumer}/genesis.go | 0 app_provider/ante_handler.go | 54 + app_provider/app.go | 954 ++++++++++++++++++ app_provider/export.go | 185 ++++ app_provider/genesis.go | 21 + .../main.go | 2 +- cmd/interchain-security-pd/main.go | 32 + go.mod | 2 +- testutil/network/network.go | 79 -- testutil/simapp/simapp.go | 61 +- x/ccv/child/keeper/genesis_test.go | 86 ++ x/ccv/child/keeper/params_test.go | 43 + x/ccv/child/module_test.go | 410 ++++++++ x/ccv/consumer/keeper/keeper_test.go | 109 +- x/ccv/consumer/keeper/relay_test.go | 41 +- x/ccv/consumer/keeper/validators_test.go | 6 +- x/ccv/parent/keeper/genesis_test.go | 38 + x/ccv/parent/keeper/keeper_test.go | 202 ++++ x/ccv/parent/keeper/proposal_test.go | 113 +++ x/ccv/provider/keeper/params_test.go | 10 +- x/ccv/provider/proposal_handler_test.go | 8 +- x/ccv/provider/provider_test.go | 117 +-- x/ccv/provider/unbonding_hook_test.go | 24 +- 26 files changed, 2329 insertions(+), 270 deletions(-) rename {app => app_consumer}/ante_handler.go (100%) rename {app => app_consumer}/app.go (99%) rename {app => app_consumer}/export.go (100%) rename {app => app_consumer}/genesis.go (100%) create mode 100644 app_provider/ante_handler.go create mode 100644 app_provider/app.go create mode 100644 app_provider/export.go create mode 100644 app_provider/genesis.go rename cmd/{interchain-securityd => interchain-security-cd}/main.go (90%) create mode 100644 cmd/interchain-security-pd/main.go delete mode 100644 testutil/network/network.go create mode 100644 x/ccv/child/keeper/genesis_test.go create mode 100644 x/ccv/child/keeper/params_test.go create mode 100644 x/ccv/child/module_test.go create mode 100644 x/ccv/parent/keeper/genesis_test.go create mode 100644 x/ccv/parent/keeper/keeper_test.go create mode 100644 x/ccv/parent/keeper/proposal_test.go diff --git a/app/ante_handler.go b/app_consumer/ante_handler.go similarity index 100% rename from app/ante_handler.go rename to app_consumer/ante_handler.go diff --git a/app/app.go b/app_consumer/app.go similarity index 99% rename from app/app.go rename to app_consumer/app.go index 4da663a1e2..45faadcc7c 100644 --- a/app/app.go +++ b/app_consumer/app.go @@ -117,7 +117,7 @@ import ( ) const ( - AppName = "interchain-security" + AppName = "interchain-security-c" upgradeName = "v07-Theta" AccountAddressPrefix = "cosmos" ) diff --git a/app/export.go b/app_consumer/export.go similarity index 100% rename from app/export.go rename to app_consumer/export.go diff --git a/app/genesis.go b/app_consumer/genesis.go similarity index 100% rename from app/genesis.go rename to app_consumer/genesis.go diff --git a/app_provider/ante_handler.go b/app_provider/ante_handler.go new file mode 100644 index 0000000000..9066af69f3 --- /dev/null +++ b/app_provider/ante_handler.go @@ -0,0 +1,54 @@ +package app + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + channelkeeper "github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper" + ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante" +) + +// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC +// channel keeper. +type HandlerOptions struct { + ante.HandlerOptions + + IBCChannelkeeper channelkeeper.Keeper +} + +func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { + if options.AccountKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + } + if options.BankKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + } + if options.SignModeHandler == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + } + + var sigGasConsumer = options.SigGasConsumer + if sigGasConsumer == nil { + sigGasConsumer = ante.DefaultSigVerificationGasConsumer + } + + anteDecorators := []sdk.AnteDecorator{ + ante.NewSetUpContextDecorator(), + ante.NewRejectExtensionOptionsDecorator(), + ante.NewMempoolFeeDecorator(), + ante.NewValidateBasicDecorator(), + ante.NewTxTimeoutHeightDecorator(), + ante.NewValidateMemoDecorator(options.AccountKeeper), + ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), + ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper), + // SetPubKeyDecorator must be called before all signature verification decorators + ante.NewSetPubKeyDecorator(options.AccountKeeper), + ante.NewValidateSigCountDecorator(options.AccountKeeper), + ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), + ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), + ante.NewIncrementSequenceDecorator(options.AccountKeeper), + ibcante.NewAnteDecorator(options.IBCChannelkeeper), + } + + return sdk.ChainAnteDecorators(anteDecorators...), nil +} diff --git a/app_provider/app.go b/app_provider/app.go new file mode 100644 index 0000000000..db9afed14c --- /dev/null +++ b/app_provider/app.go @@ -0,0 +1,954 @@ +package app + +import ( + "fmt" + "io" + stdlog "log" + "net/http" + "os" + "path/filepath" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" + "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/server/api" + "github.com/cosmos/cosmos-sdk/server/config" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/simapp" + store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/version" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + "github.com/cosmos/cosmos-sdk/x/authz" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" + "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/capability" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distr "github.com/cosmos/cosmos-sdk/x/distribution" + distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/evidence" + evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" + feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/gov" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/mint" + mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/params" + paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/x/upgrade" + upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/ibc-go/v3/modules/apps/transfer" + ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v3/modules/core" + ibcclient "github.com/cosmos/ibc-go/v3/modules/core/02-client" + ibcclientclient "github.com/cosmos/ibc-go/v3/modules/core/02-client/client" + ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" + ibcconnectiontypes "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types" + porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types" + ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host" + ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" + ibctesting "github.com/cosmos/ibc-go/v3/testing" + + "github.com/gorilla/mux" + "github.com/gravity-devs/liquidity/x/liquidity" + liquiditykeeper "github.com/gravity-devs/liquidity/x/liquidity/keeper" + liquiditytypes "github.com/gravity-devs/liquidity/x/liquidity/types" + "github.com/rakyll/statik/fs" + "github.com/spf13/cast" + abci "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" + tmos "github.com/tendermint/tendermint/libs/os" + dbm "github.com/tendermint/tm-db" + + ibcchild "github.com/cosmos/interchain-security/x/ccv/child" + ibcchildkeeper "github.com/cosmos/interchain-security/x/ccv/child/keeper" + ibcchildtypes "github.com/cosmos/interchain-security/x/ccv/child/types" + ibcparent "github.com/cosmos/interchain-security/x/ccv/parent" + ibcparentclient "github.com/cosmos/interchain-security/x/ccv/parent/client" + ibcparentkeeper "github.com/cosmos/interchain-security/x/ccv/parent/keeper" + ibcparenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" + + "github.com/tendermint/spm/cosmoscmd" + + // unnamed import of statik for swagger UI support + _ "github.com/cosmos/cosmos-sdk/client/docs/statik" +) + +const ( + AppName = "interchain-security-p" + upgradeName = "v07-Theta" + AccountAddressPrefix = "cosmos" +) + +// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals + +func getGovProposalHandlers() []govclient.ProposalHandler { + var govProposalHandlers []govclient.ProposalHandler + // this line is used by starport scaffolding # stargate/app/govProposalHandlers + + govProposalHandlers = append(govProposalHandlers, + paramsclient.ProposalHandler, + distrclient.ProposalHandler, + upgradeclient.ProposalHandler, + upgradeclient.CancelProposalHandler, + ibcparentclient.ProposalHandler, + // this line is used by starport scaffolding # stargate/app/govProposalHandler + ) + + return govProposalHandlers +} + +var ( + // DefaultNodeHome default home directories for the application daemon + DefaultNodeHome string + + // ModuleBasics defines the module BasicManager is in charge of setting up basic, + // non-dependant module elements, such as codec registration + // and genesis verification. + ModuleBasics = module.NewBasicManager( + auth.AppModuleBasic{}, + genutil.AppModuleBasic{}, + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + staking.AppModuleBasic{}, + mint.AppModuleBasic{}, + distr.AppModuleBasic{}, + gov.NewAppModuleBasic( + paramsclient.ProposalHandler, + distrclient.ProposalHandler, + upgradeclient.ProposalHandler, + upgradeclient.CancelProposalHandler, + ibcclientclient.UpdateClientProposalHandler, + ibcclientclient.UpgradeProposalHandler, + ibcparentclient.ProposalHandler, + ), + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, + ibc.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + transfer.AppModuleBasic{}, + vesting.AppModuleBasic{}, + liquidity.AppModuleBasic{}, + //router.AppModuleBasic{}, + ibcchild.AppModuleBasic{}, + ibcparent.AppModuleBasic{}, + ) + + // module account permissions + maccPerms = map[string][]string{ + authtypes.FeeCollectorName: nil, + ibcchildtypes.ConsumerRedistributeName: nil, + ibcchildtypes.ConsumerToSendToProviderName: nil, + distrtypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + } +) + +var ( + _ simapp.App = (*App)(nil) + _ servertypes.Application = (*App)(nil) + _ cosmoscmd.CosmosApp = (*App)(nil) + _ ibctesting.TestingApp = (*App)(nil) +) + +// App extends an ABCI application, but with most of its parameters exported. +// They are exported for convenience in creating helper functions, as object +// capabilities aren't needed for testing. +type App struct { // nolint: golint + *baseapp.BaseApp + legacyAmino *codec.LegacyAmino + appCodec codec.Codec + interfaceRegistry types.InterfaceRegistry + + invCheckPeriod uint + + // keys to access the substores + keys map[string]*sdk.KVStoreKey + tkeys map[string]*sdk.TransientStoreKey + memKeys map[string]*sdk.MemoryStoreKey + + // keepers + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + + // NOTE the distribution keeper should either be removed + // from consumer chain or set to use an independant + // different fee-pool from the consumer chain ChildKeeper + DistrKeeper distrkeeper.Keeper + + GovKeeper govkeeper.Keeper + CrisisKeeper crisiskeeper.Keeper + UpgradeKeeper upgradekeeper.Keeper + ParamsKeeper paramskeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + AuthzKeeper authzkeeper.Keeper + LiquidityKeeper liquiditykeeper.Keeper + ChildKeeper ibcchildkeeper.Keeper + ParentKeeper ibcparentkeeper.Keeper + + // make scoped keepers public for test purposes + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedIBCChildKeeper capabilitykeeper.ScopedKeeper + ScopedIBCParentKeeper capabilitykeeper.ScopedKeeper + + // the module manager + MM *module.Manager + + // simulation manager + sm *module.SimulationManager + configurator module.Configurator +} + +func init() { + userHomeDir, err := os.UserHomeDir() + if err != nil { + stdlog.Println("Failed to get home dir %2", err) + } + + DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName) +} + +// New returns a reference to an initialized App. +func New( + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + loadLatest bool, + skipUpgradeHeights map[int64]bool, + homePath string, + invCheckPeriod uint, + encodingConfig cosmoscmd.EncodingConfig, + appOpts servertypes.AppOptions, + baseAppOptions ...func(*baseapp.BaseApp), +) cosmoscmd.App { + + appCodec := encodingConfig.Marshaler + legacyAmino := encodingConfig.Amino + interfaceRegistry := encodingConfig.InterfaceRegistry + + bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) + bApp.SetCommitMultiStoreTracer(traceStore) + bApp.SetVersion(version.Version) + bApp.SetInterfaceRegistry(interfaceRegistry) + + keys := sdk.NewKVStoreKeys( + authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, + evidencetypes.StoreKey, liquiditytypes.StoreKey, ibctransfertypes.StoreKey, + capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, + ibcchildtypes.StoreKey, ibcparenttypes.StoreKey, + ) + tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, stakingtypes.TStoreKey) + memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + + app := &App{ + BaseApp: bApp, + legacyAmino: legacyAmino, + appCodec: appCodec, + interfaceRegistry: interfaceRegistry, + invCheckPeriod: invCheckPeriod, + keys: keys, + tkeys: tkeys, + memKeys: memKeys, + } + + app.ParamsKeeper = initParamsKeeper( + appCodec, + legacyAmino, + keys[paramstypes.StoreKey], + tkeys[paramstypes.TStoreKey], + ) + + // set the BaseApp's parameter store + bApp.SetParamStore( + app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable( + paramskeeper.ConsensusParamsKeyTable()), + ) + + // add capability keeper and ScopeToModule for ibc module + app.CapabilityKeeper = capabilitykeeper.NewKeeper( + appCodec, + keys[capabilitytypes.StoreKey], + memKeys[capabilitytypes.MemStoreKey], + ) + scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) + scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedIBCChildKeeper := app.CapabilityKeeper.ScopeToModule(ibcchildtypes.ModuleName) + scopedIBCParentKeeper := app.CapabilityKeeper.ScopeToModule(ibcparenttypes.ModuleName) + app.CapabilityKeeper.Seal() + + // add keepers + app.AccountKeeper = authkeeper.NewAccountKeeper( + appCodec, + keys[authtypes.StoreKey], + app.GetSubspace(authtypes.ModuleName), + authtypes.ProtoBaseAccount, + maccPerms, + ) + + // Remove the fee-pool from the group of blocked recipient addresses in bank + // this is required for the provider chain to be able to receive tokens from + // the consumer chain + bankBlockedAddrs := app.ModuleAccountAddrs() + delete(bankBlockedAddrs, authtypes.NewModuleAddress( + authtypes.FeeCollectorName).String()) + + app.BankKeeper = bankkeeper.NewBaseKeeper( + appCodec, + keys[banktypes.StoreKey], + app.AccountKeeper, + app.GetSubspace(banktypes.ModuleName), + bankBlockedAddrs, + ) + app.AuthzKeeper = authzkeeper.NewKeeper( + keys[authzkeeper.StoreKey], + appCodec, + app.BaseApp.MsgServiceRouter(), + ) + app.FeeGrantKeeper = feegrantkeeper.NewKeeper( + appCodec, + keys[feegrant.StoreKey], + app.AccountKeeper, + ) + stakingKeeper := stakingkeeper.NewKeeper( + appCodec, + keys[stakingtypes.StoreKey], + tkeys[stakingtypes.TStoreKey], + app.AccountKeeper, + app.BankKeeper, + app.GetSubspace(stakingtypes.ModuleName), + ) + app.MintKeeper = mintkeeper.NewKeeper( + appCodec, + keys[minttypes.StoreKey], + app.GetSubspace(minttypes.ModuleName), + &stakingKeeper, + app.AccountKeeper, + app.BankKeeper, + authtypes.FeeCollectorName, + ) + app.DistrKeeper = distrkeeper.NewKeeper( + appCodec, + keys[distrtypes.StoreKey], + app.GetSubspace(distrtypes.ModuleName), + app.AccountKeeper, + app.BankKeeper, + &stakingKeeper, + authtypes.FeeCollectorName, + app.ModuleAccountAddrs(), + ) + app.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, + keys[slashingtypes.StoreKey], + &stakingKeeper, + app.GetSubspace(slashingtypes.ModuleName), + ) + app.CrisisKeeper = crisiskeeper.NewKeeper( + app.GetSubspace(crisistypes.ModuleName), + invCheckPeriod, + app.BankKeeper, + authtypes.FeeCollectorName, + ) + app.UpgradeKeeper = upgradekeeper.NewKeeper( + skipUpgradeHeights, + keys[upgradetypes.StoreKey], + appCodec, + homePath, + app.BaseApp, + ) + app.LiquidityKeeper = liquiditykeeper.NewKeeper( + appCodec, + keys[liquiditytypes.StoreKey], + app.GetSubspace(liquiditytypes.ModuleName), + app.BankKeeper, + app.AccountKeeper, + app.DistrKeeper, + ) + + // register the staking hooks + // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks + app.StakingKeeper = *stakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), + app.SlashingKeeper.Hooks(), + app.ParentKeeper.Hooks(), + ), + ) + + app.IBCKeeper = ibckeeper.NewKeeper( + appCodec, + keys[ibchost.StoreKey], + app.GetSubspace(ibchost.ModuleName), + app.StakingKeeper, + app.UpgradeKeeper, + scopedIBCKeeper, + ) + + // Create CCV child and parent keepers and modules + app.ChildKeeper = ibcchildkeeper.NewKeeper( + appCodec, + keys[ibcchildtypes.StoreKey], + app.GetSubspace(ibcchildtypes.ModuleName), + scopedIBCChildKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.IBCKeeper.ConnectionKeeper, + app.IBCKeeper.ClientKeeper, + app.SlashingKeeper, + app.BankKeeper, + app.AccountKeeper, + &app.TransferKeeper, + app.IBCKeeper, + authtypes.FeeCollectorName, + ) + + app.ParentKeeper = ibcparentkeeper.NewKeeper( + appCodec, + keys[ibcparenttypes.StoreKey], + app.GetSubspace(ibcparenttypes.ModuleName), + scopedIBCParentKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.IBCKeeper.ConnectionKeeper, + app.IBCKeeper.ClientKeeper, + app.StakingKeeper, + app.SlashingKeeper, + app.AccountKeeper, + authtypes.FeeCollectorName, + ) + parentModule := ibcparent.NewAppModule(&app.ParentKeeper) + + // child keeper satisfies the staking keeper interface + // of the slashing module + app.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, + keys[slashingtypes.StoreKey], + app.ChildKeeper, + app.GetSubspace(slashingtypes.ModuleName), + ) + + // register slashing module StakingHooks to the child keeper + app.ChildKeeper = *app.ChildKeeper.SetHooks(app.SlashingKeeper.Hooks()) + childModule := ibcchild.NewAppModule(app.ChildKeeper) + + // register the proposal types + govRouter := govtypes.NewRouter() + govRouter. + AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). + AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). + AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). + AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). + AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). + AddRoute(ibcparenttypes.RouterKey, ibcparent.NewCreateChildChainHandler(app.ParentKeeper)). + AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)) + + app.GovKeeper = govkeeper.NewKeeper( + appCodec, + keys[govtypes.StoreKey], + app.GetSubspace(govtypes.ModuleName), + app.AccountKeeper, + app.BankKeeper, + &stakingKeeper, + govRouter, + ) + + app.TransferKeeper = ibctransferkeeper.NewKeeper( + appCodec, + keys[ibctransfertypes.StoreKey], + app.GetSubspace(ibctransfertypes.ModuleName), + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.BankKeeper, + scopedTransferKeeper, + ) + transferModule := transfer.NewAppModule(app.TransferKeeper) + ibcmodule := transfer.NewIBCModule(app.TransferKeeper) + + // create static IBC router, add transfer route, then set and seal it + ibcRouter := porttypes.NewRouter() + ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule) + ibcRouter.AddRoute(ibcchildtypes.ModuleName, childModule) + ibcRouter.AddRoute(ibcparenttypes.ModuleName, parentModule) + app.IBCKeeper.SetRouter(ibcRouter) + + // create evidence keeper with router + evidenceKeeper := evidencekeeper.NewKeeper( + appCodec, + keys[evidencetypes.StoreKey], + &app.StakingKeeper, + app.SlashingKeeper, + ) + + app.EvidenceKeeper = *evidenceKeeper + + skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) + + // NOTE: Any module instantiated in the module manager that is later modified + // must be passed by reference here. + app.MM = module.NewManager( + genutil.NewAppModule( + app.AccountKeeper, + app.StakingKeeper, + app.BaseApp.DeliverTx, + encodingConfig.TxConfig, + ), + auth.NewAppModule(appCodec, app.AccountKeeper, nil), + vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(appCodec, *app.CapabilityKeeper), + crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + upgrade.NewAppModule(app.UpgradeKeeper), + evidence.NewAppModule(app.EvidenceKeeper), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + ibc.NewAppModule(app.IBCKeeper), + params.NewAppModule(app.ParamsKeeper), + liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper), + transferModule, + childModule, + parentModule, + ) + + // During begin block slashing happens after distr.BeginBlocker so that + // there is nothing left over in the validator fee pool, so as to keep the + // CanWithdrawInvariant invariant. + // NOTE: staking module is required if HistoricalEntries param > 0 + // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) + app.MM.SetOrderBeginBlockers( + // upgrades should be run first + upgradetypes.ModuleName, + capabilitytypes.ModuleName, + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + liquiditytypes.ModuleName, + ibctransfertypes.ModuleName, + ibchost.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + authz.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + vestingtypes.ModuleName, + ibcchildtypes.ModuleName, + ibcparenttypes.ModuleName, + ) + app.MM.SetOrderEndBlockers( + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + liquiditytypes.ModuleName, + ibctransfertypes.ModuleName, + ibchost.ModuleName, + feegrant.ModuleName, + authz.ModuleName, + capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + vestingtypes.ModuleName, + ibcchildtypes.ModuleName, + ibcparenttypes.ModuleName, + ) + + // NOTE: The genutils module must occur after staking so that pools are + // properly initialized with tokens from genesis accounts. + // NOTE: The genutils module must also occur after auth so that it can access the params from auth. + // NOTE: Capability module must occur first so that it can initialize any capabilities + // so that other modules that want to create or claim capabilities afterwards in InitChain + // can do so safely. + app.MM.SetOrderInitGenesis( + capabilitytypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + slashingtypes.ModuleName, + govtypes.ModuleName, + minttypes.ModuleName, + crisistypes.ModuleName, + ibchost.ModuleName, + evidencetypes.ModuleName, + liquiditytypes.ModuleName, + ibctransfertypes.ModuleName, + feegrant.ModuleName, + authz.ModuleName, + authtypes.ModuleName, + genutiltypes.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + vestingtypes.ModuleName, + ibcchildtypes.ModuleName, + ibcparenttypes.ModuleName, + ) + + app.MM.RegisterInvariants(&app.CrisisKeeper) + app.MM.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) + + app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) + app.MM.RegisterServices(app.configurator) + + // create the simulation manager and define the order of the modules for deterministic simulations + // + // NOTE: this is not required apps that don't use the simulator for fuzz testing + // transactions + app.sm = module.NewSimulationManager( + auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(appCodec, *app.CapabilityKeeper), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), + staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + params.NewAppModule(app.ParamsKeeper), + evidence.NewAppModule(app.EvidenceKeeper), + liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper), + ibc.NewAppModule(app.IBCKeeper), + transferModule, + ) + + app.sm.RegisterStoreDecoders() + + // initialize stores + app.MountKVStores(keys) + app.MountTransientStores(tkeys) + app.MountMemoryStores(memKeys) + + anteHandler, err := NewAnteHandler( + HandlerOptions{ + HandlerOptions: ante.HandlerOptions{ + AccountKeeper: app.AccountKeeper, + BankKeeper: app.BankKeeper, + FeegrantKeeper: app.FeeGrantKeeper, + SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + IBCChannelkeeper: app.IBCKeeper.ChannelKeeper, + }, + ) + if err != nil { + panic(fmt.Errorf("failed to create AnteHandler: %s", err)) + } + app.SetAnteHandler(anteHandler) + + app.SetInitChainer(app.InitChainer) + app.SetBeginBlocker(app.BeginBlocker) + app.SetEndBlocker(app.EndBlocker) + + app.UpgradeKeeper.SetUpgradeHandler( + upgradeName, + func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { + app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams()) + + fromVM := make(map[string]uint64) + + for moduleName, eachModule := range app.MM.Modules { + fromVM[moduleName] = eachModule.ConsensusVersion() + } + + ctx.Logger().Info("start to run module migrations...") + + return app.MM.RunMigrations(ctx, app.configurator, fromVM) + }, + ) + + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) + } + + if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + storeUpgrades := store.StoreUpgrades{} + + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } + + if loadLatest { + if err := app.LoadLatestVersion(); err != nil { + tmos.Exit(fmt.Sprintf("failed to load latest version: %s", err)) + } + } + + app.ScopedIBCKeeper = scopedIBCKeeper + app.ScopedTransferKeeper = scopedTransferKeeper + app.ScopedIBCChildKeeper = scopedIBCChildKeeper + app.ScopedIBCParentKeeper = scopedIBCParentKeeper + + return app +} + +// Name returns the name of the App +func (app *App) Name() string { return app.BaseApp.Name() } + +// BeginBlocker application updates every begin block +func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + return app.MM.BeginBlock(ctx, req) +} + +// EndBlocker application updates every end block +func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { + return app.MM.EndBlock(ctx, req) +} + +// InitChainer application update at chain initialization +func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { + var genesisState GenesisState + if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { + panic(err) + } + + app.UpgradeKeeper.SetModuleVersionMap(ctx, app.MM.GetVersionMap()) + + return app.MM.InitGenesis(ctx, app.appCodec, genesisState) +} + +// LoadHeight loads a particular height +func (app *App) LoadHeight(height int64) error { + return app.LoadVersion(height) +} + +// ModuleAccountAddrs returns all the app's module account addresses. +func (app *App) ModuleAccountAddrs() map[string]bool { + modAccAddrs := make(map[string]bool) + for acc := range maccPerms { + modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true + } + + return modAccAddrs +} + +// LegacyAmino returns App's amino codec. +// +// NOTE: This is solely to be used for testing purposes as it may be desirable +// for modules to register their own custom testing types. +func (app *App) LegacyAmino() *codec.LegacyAmino { + return app.legacyAmino +} + +// AppCodec returns the app codec. +// +// NOTE: This is solely to be used for testing purposes as it may be desirable +// for modules to register their own custom testing types. +func (app *App) AppCodec() codec.Codec { + return app.appCodec +} + +// InterfaceRegistry returns the InterfaceRegistry +func (app *App) InterfaceRegistry() types.InterfaceRegistry { + return app.interfaceRegistry +} + +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *App) GetKey(storeKey string) *sdk.KVStoreKey { + return app.keys[storeKey] +} + +// GetTKey returns the TransientStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *App) GetTKey(storeKey string) *sdk.TransientStoreKey { + return app.tkeys[storeKey] +} + +// GetMemKey returns the MemStoreKey for the provided mem key. +// +// NOTE: This is solely used for testing purposes. +func (app *App) GetMemKey(storeKey string) *sdk.MemoryStoreKey { + return app.memKeys[storeKey] +} + +// GetSubspace returns a param subspace for a given module name. +// +// NOTE: This is solely to be used for testing purposes. +func (app *App) GetSubspace(moduleName string) paramstypes.Subspace { + subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) + return subspace +} + +// SimulationManager implements the SimulationApp interface +func (app *App) SimulationManager() *module.SimulationManager { + return app.sm +} + +// TestingApp functions + +// GetBaseApp implements the TestingApp interface. +func (app *App) GetBaseApp() *baseapp.BaseApp { + return app.BaseApp +} + +// GetStakingKeeper implements the TestingApp interface. +func (app *App) GetStakingKeeper() stakingkeeper.Keeper { + return app.StakingKeeper +} + +// GetIBCKeeper implements the TestingApp interface. +func (app *App) GetIBCKeeper() *ibckeeper.Keeper { + return app.IBCKeeper +} + +// GetScopedIBCKeeper implements the TestingApp interface. +func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { + return app.ScopedIBCKeeper +} + +// GetTxConfig implements the TestingApp interface. +func (app *App) GetTxConfig() client.TxConfig { + return cosmoscmd.MakeEncodingConfig(ModuleBasics).TxConfig +} + +// RegisterAPIRoutes registers all application module routes with the provided +// API server. +func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { + clientCtx := apiSvr.ClientCtx + rpc.RegisterRoutes(clientCtx, apiSvr.Router) + // Register legacy tx routes. + authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) + // Register new tx routes from grpc-gateway. + authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + // Register new tendermint queries routes from grpc-gateway. + tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // Register legacy and grpc-gateway routes for all modules. + ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) + ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // register swagger API from root so that other applications can override easily + if apiConfig.Swagger { + RegisterSwaggerAPI(apiSvr.Router) + } +} + +// RegisterTxService implements the Application.RegisterTxService method. +func (app *App) RegisterTxService(clientCtx client.Context) { + authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) +} + +// RegisterTendermintService implements the Application.RegisterTendermintService method. +func (app *App) RegisterTendermintService(clientCtx client.Context) { + tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry) +} + +// RegisterSwaggerAPI registers swagger route with API Server +func RegisterSwaggerAPI(rtr *mux.Router) { + statikFS, err := fs.New() + if err != nil { + panic(err) + } + + staticServer := http.FileServer(statikFS) + rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) +} + +// GetMaccPerms returns a copy of the module account permissions +func GetMaccPerms() map[string][]string { + dupMaccPerms := make(map[string][]string) + for k, v := range maccPerms { + dupMaccPerms[k] = v + } + return dupMaccPerms +} + +// initParamsKeeper init params keeper and its subspaces +func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper { + paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + + paramsKeeper.Subspace(authtypes.ModuleName) + paramsKeeper.Subspace(banktypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName) + paramsKeeper.Subspace(minttypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) + paramsKeeper.Subspace(slashingtypes.ModuleName) + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) + paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(liquiditytypes.ModuleName) + paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(ibcparenttypes.ModuleName) + paramsKeeper.Subspace(ibcchildtypes.ModuleName) + + return paramsKeeper +} diff --git a/app_provider/export.go b/app_provider/export.go new file mode 100644 index 0000000000..590c9e9163 --- /dev/null +++ b/app_provider/export.go @@ -0,0 +1,185 @@ +package app + +import ( + "encoding/json" + "log" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + servertypes "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// ExportAppStateAndValidators exports the state of the application for a genesis +// file. +func (app *App) ExportAppStateAndValidators( + forZeroHeight bool, jailAllowedAddrs []string, +) (servertypes.ExportedApp, error) { + + // as if they could withdraw from the start of the next block + ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + + // We export at last height + 1, because that's the height at which + // Tendermint will start InitChain. + height := app.LastBlockHeight() + 1 + if forZeroHeight { + height = 0 + app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) + } + + genState := app.MM.ExportGenesis(ctx, app.appCodec) + appState, err := json.MarshalIndent(genState, "", " ") + if err != nil { + return servertypes.ExportedApp{}, err + } + + validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + if err != nil { + return servertypes.ExportedApp{}, err + } + return servertypes.ExportedApp{ + AppState: appState, + Validators: validators, + Height: height, + ConsensusParams: app.BaseApp.GetConsensusParams(ctx), + }, nil +} + +// prepare for fresh start at zero height +// NOTE zero height genesis is a temporary feature which will be deprecated +// in favour of export at a block height +func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { + applyAllowedAddrs := false + + // check if there is a allowed address list + if len(jailAllowedAddrs) > 0 { + applyAllowedAddrs = true + } + + allowedAddrsMap := make(map[string]bool) + + for _, addr := range jailAllowedAddrs { + _, err := sdk.ValAddressFromBech32(addr) + if err != nil { + log.Fatal(err) + } + allowedAddrsMap[addr] = true + } + + /* Just to be safe, assert the invariants on current state. */ + app.CrisisKeeper.AssertInvariants(ctx) + + /* Handle fee distribution state. */ + + // withdraw all validator commission + app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + _, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) + if err != nil { + panic(err) + } + return false + }) + + // withdraw all delegator rewards + dels := app.StakingKeeper.GetAllDelegations(ctx) + for _, delegation := range dels { + _, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr()) + if err != nil { + panic(err) + } + } + + // clear validator slash events + app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx) + + // clear validator historical rewards + app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) + + // set context height to zero + height := ctx.BlockHeight() + ctx = ctx.WithBlockHeight(0) + + // reinitialize all validators + app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + // donate any unwithdrawn outstanding reward fraction tokens to the community pool + scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) + feePool := app.DistrKeeper.GetFeePool(ctx) + feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) + app.DistrKeeper.SetFeePool(ctx, feePool) + + app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) + return false + }) + + // reinitialize all delegations + for _, del := range dels { + app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) + app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) + } + + // reset context height + ctx = ctx.WithBlockHeight(height) + + /* Handle staking state. */ + + // iterate through redelegations, reset creation height + app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { + for i := range red.Entries { + red.Entries[i].CreationHeight = 0 + } + app.StakingKeeper.SetRedelegation(ctx, red) + return false + }) + + // iterate through unbonding delegations, reset creation height + app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { + for i := range ubd.Entries { + ubd.Entries[i].CreationHeight = 0 + } + app.StakingKeeper.SetUnbondingDelegation(ctx, ubd) + return false + }) + + // Iterate through validators by power descending, reset bond heights, and + // update bond intra-tx counters. + store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) + iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) + counter := int16(0) + + for ; iter.Valid(); iter.Next() { + addr := sdk.ValAddress(iter.Key()[1:]) + validator, found := app.StakingKeeper.GetValidator(ctx, addr) + if !found { + panic("expected validator, not found") + } + + validator.UnbondingHeight = 0 + if applyAllowedAddrs && !allowedAddrsMap[addr.String()] { + validator.Jailed = true + } + + app.StakingKeeper.SetValidator(ctx, validator) + counter++ + } + + iter.Close() + + if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil { + panic(err) + } + + /* Handle slashing state. */ + + // reset start height on signing infos + app.SlashingKeeper.IterateValidatorSigningInfos( + ctx, + func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { + info.StartHeight = 0 + app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info) + return false + }, + ) +} diff --git a/app_provider/genesis.go b/app_provider/genesis.go new file mode 100644 index 0000000000..5bf0c1da80 --- /dev/null +++ b/app_provider/genesis.go @@ -0,0 +1,21 @@ +package app + +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/codec" +) + +// The genesis state of the blockchain is represented here as a map of raw json +// messages key'd by a identifier string. +// The identifier is used to determine which module genesis information belongs +// to so it may be appropriately routed during init chain. +// Within this application default genesis information is retrieved from +// the ModuleBasicManager which populates json from each BasicModule +// object provided to it during init. +type GenesisState map[string]json.RawMessage + +// NewDefaultGenesisState generates the default state for the application. +func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { + return ModuleBasics.DefaultGenesis(cdc) +} diff --git a/cmd/interchain-securityd/main.go b/cmd/interchain-security-cd/main.go similarity index 90% rename from cmd/interchain-securityd/main.go rename to cmd/interchain-security-cd/main.go index 554f2ada55..9d1b592704 100644 --- a/cmd/interchain-securityd/main.go +++ b/cmd/interchain-security-cd/main.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - "github.com/cosmos/interchain-security/app" + app "github.com/cosmos/interchain-security/app_consumer" "github.com/tendermint/spm/cosmoscmd" ) diff --git a/cmd/interchain-security-pd/main.go b/cmd/interchain-security-pd/main.go new file mode 100644 index 0000000000..01ef7bf19e --- /dev/null +++ b/cmd/interchain-security-pd/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "os" + + "github.com/cosmos/cosmos-sdk/server" + svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + app "github.com/cosmos/interchain-security/app_provider" + "github.com/tendermint/spm/cosmoscmd" +) + +func main() { + rootCmd, _ := cosmoscmd.NewRootCmd( + app.AppName, + app.AccountAddressPrefix, + app.DefaultNodeHome, + app.AppName, + app.ModuleBasics, + app.New, + // this line is used by starport scaffolding # root/arguments + ) + + if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil { + switch e := err.(type) { + case server.ErrorCode: + os.Exit(e.Code) + + default: + os.Exit(1) + } + } +} diff --git a/go.mod b/go.mod index 269441f32b..b03138e405 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 - github.com/cosmos/ibc-go/v3 => github.com/informalsystems/ibc-go/v3 v3.0.0-alpha1.0.20220405190259-988da4519455 + github.com/cosmos/ibc-go/v3 => /Users/danwt/Documents/work/ibc-go github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 google.golang.org/grpc => google.golang.org/grpc v1.33.2 ) diff --git a/testutil/network/network.go b/testutil/network/network.go deleted file mode 100644 index 8779ceca85..0000000000 --- a/testutil/network/network.go +++ /dev/null @@ -1,79 +0,0 @@ -package network - -import ( - "fmt" - "testing" - "time" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/simapp" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/testutil/network" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/tendermint/spm/cosmoscmd" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmdb "github.com/tendermint/tm-db" - - "github.com/cosmos/interchain-security/app" -) - -type ( - Network = network.Network - Config = network.Config -) - -// New creates instance with fully configured cosmos network. -// Accepts optional config, that will be used in place of the DefaultConfig() if provided. -func New(t *testing.T, configs ...network.Config) *network.Network { - if len(configs) > 1 { - panic("at most one config should be provided") - } - var cfg network.Config - if len(configs) == 0 { - cfg = DefaultConfig() - } else { - cfg = configs[0] - } - net := network.New(t, cfg) - t.Cleanup(net.Cleanup) - return net -} - -// DefaultConfig will initialize config for the network with custom application, -// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig -func DefaultConfig() network.Config { - encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) - return network.Config{ - Codec: encoding.Marshaler, - TxConfig: encoding.TxConfig, - LegacyAmino: encoding.Amino, - InterfaceRegistry: encoding.InterfaceRegistry, - AccountRetriever: authtypes.AccountRetriever{}, - AppConstructor: func(val network.Validator) servertypes.Application { - return app.New( - val.Ctx.Logger, tmdb.NewMemDB(), nil, true, map[int64]bool{}, val.Ctx.Config.RootDir, 0, - encoding, - simapp.EmptyAppOptions{}, - baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), - baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), - ) - }, - GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), - TimeoutCommit: 2 * time.Second, - ChainID: "chain-" + tmrand.NewRand().Str(6), - NumValidators: 1, - BondDenom: sdk.DefaultBondDenom, - MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), - AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), - StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), - BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), - PruningStrategy: storetypes.PruningOptionNothing, - CleanupDir: true, - SigningAlgo: string(hd.Secp256k1Type), - KeyringOptions: []keyring.Option{}, - } -} diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index 1f3674e2a6..c454064a4b 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -2,6 +2,7 @@ package simapp import ( "encoding/json" + "testing" "time" "github.com/cosmos/cosmos-sdk/simapp" @@ -15,26 +16,10 @@ import ( tmtypes "github.com/tendermint/tendermint/types" tmdb "github.com/tendermint/tm-db" - "github.com/cosmos/interchain-security/app" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" ) -// New creates application instance with in-memory database and disabled logging. -func New(dir string) cosmoscmd.App { - db := tmdb.NewMemDB() - logger := log.NewNopLogger() - - encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) - - a := app.New(logger, db, nil, true, map[int64]bool{}, dir, 0, encoding, - simapp.EmptyAppOptions{}) - // InitChain updates deliverState which is required when app.NewContext is called - a.InitChain(abci.RequestInitChain{ - ConsensusParams: defaultConsensusParams, - AppStateBytes: []byte("{}"), - }) - return a -} - var defaultConsensusParams = &abci.ConsensusParams{ Block: &abci.BlockParams{ MaxBytes: 200000, @@ -52,10 +37,42 @@ var defaultConsensusParams = &abci.ConsensusParams{ }, } -func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { +func SetupTestingappProvider() (ibctesting.TestingApp, map[string]json.RawMessage) { db := tmdb.NewMemDB() // encCdc := app.MakeTestEncodingConfig() - encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics) - testApp := app.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) - return testApp, app.NewDefaultGenesisState(encoding.Marshaler) + encoding := cosmoscmd.MakeEncodingConfig(appProvider.ModuleBasics) + testApp := appProvider.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) + return testApp, appProvider.NewDefaultGenesisState(encoding.Marshaler) +} + +func SetupTestingappConsumer() (ibctesting.TestingApp, map[string]json.RawMessage) { + db := tmdb.NewMemDB() + // encCdc := app.MakeTestEncodingConfig() + encoding := cosmoscmd.MakeEncodingConfig(appConsumer.ModuleBasics) + testApp := appConsumer.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{}).(ibctesting.TestingApp) + return testApp, appConsumer.NewDefaultGenesisState(encoding.Marshaler) +} + +// NewCoordinator initializes Coordinator with 0 TestChains +func NewBasicCoordinator(t *testing.T) *ibctesting.Coordinator { + chains := make(map[string]*ibctesting.TestChain) + coord := &ibctesting.Coordinator{ + T: t, + CurrentTime: ibctesting.GlobalStartTime, + } + coord.Chains = chains + return coord +} + +// NewCoordinator initializes Coordinator with 0 TestChains +func NewParentChildCoordinator(t *testing.T) (*ibctesting.Coordinator, *ibctesting.TestChain, *ibctesting.TestChain) { + coordinator := NewBasicCoordinator(t) + chainID := ibctesting.GetChainID(0) + coordinator.Chains[chainID] = ibctesting.NewTestChain(t, coordinator, SetupTestingappProvider, chainID) + parentChain := coordinator.GetChain(chainID) + chainID = ibctesting.GetChainID(1) + coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(t, coordinator, + SetupTestingappConsumer, chainID, parentChain.Vals, parentChain.Signers) + childChain := coordinator.GetChain(chainID) + return coordinator, parentChain, childChain } diff --git a/x/ccv/child/keeper/genesis_test.go b/x/ccv/child/keeper/genesis_test.go new file mode 100644 index 0000000000..ad6a540046 --- /dev/null +++ b/x/ccv/child/keeper/genesis_test.go @@ -0,0 +1,86 @@ +package keeper_test + +import ( + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + + childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" + parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" + "github.com/cosmos/interchain-security/x/ccv/types" + + appConsumer "github.com/cosmos/interchain-security/app_consumer" + abci "github.com/tendermint/tendermint/abci/types" + tmtypes "github.com/tendermint/tendermint/types" +) + +func (suite *KeeperTestSuite) TestGenesis() { + genesis := suite.childChain.App.(*appConsumer.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + + suite.Require().Equal(suite.parentClient, genesis.ParentClientState) + suite.Require().Equal(suite.parentConsState, genesis.ParentConsensusState) + + suite.Require().NotPanics(func() { + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) + // reset suite to reset parent client + suite.SetupTest() + }) + + ctx := suite.childChain.GetContext() + portId := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPort(ctx) + suite.Require().Equal(childtypes.PortID, portId) + + clientId, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(ctx) + suite.Require().True(ok) + clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(ctx, clientId) + suite.Require().True(ok) + suite.Require().Equal(genesis.ParentClientState, clientState, "client state not set correctly after InitGenesis") + + suite.SetupCCVChannel() + + origTime := suite.childChain.GetContext().BlockTime() + + pk1, err := cryptocodec.ToTmProtoPublicKey(ed25519.GenPrivKey().PubKey()) + suite.Require().NoError(err) + pk2, err := cryptocodec.ToTmProtoPublicKey(ed25519.GenPrivKey().PubKey()) + suite.Require().NoError(err) + pd := types.NewValidatorSetChangePacketData( + []abci.ValidatorUpdate{ + { + PubKey: pk1, + Power: 30, + }, + { + PubKey: pk2, + Power: 20, + }, + }, + 1, + nil, + ) + packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, + clienttypes.NewHeight(1, 0), 0) + suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) + + // mocking the fact that child chain validators should be parent chain validators + // TODO: Fix testing suite so we can initialize both chains with the same validator set + valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) + + restartGenesis := suite.childChain.App.(*appConsumer.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + restartGenesis.InitialValSet = valUpdates + + // ensure reset genesis is set correctly + parentChannel := suite.path.EndpointA.ChannelID + suite.Require().Equal(parentChannel, restartGenesis.ParentChannelId) + unbondingTime := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) + suite.Require().Equal(uint64(origTime.Add(childtypes.UnbondingTime).UnixNano()), unbondingTime, "unbonding time is not set correctly in genesis") + unbondingPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) + suite.Require().NoError(err) + suite.Require().Equal(&packet, unbondingPacket, "unbonding packet is not set correctly in genesis") + + suite.Require().NotPanics(func() { + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) + }) +} diff --git a/x/ccv/child/keeper/params_test.go b/x/ccv/child/keeper/params_test.go new file mode 100644 index 0000000000..4420bfa491 --- /dev/null +++ b/x/ccv/child/keeper/params_test.go @@ -0,0 +1,43 @@ +package keeper_test + +import ( + appConsumer "github.com/cosmos/interchain-security/app_consumer" + "github.com/cosmos/interchain-security/x/ccv/child/types" +) + +func (suite *KeeperTestSuite) TestParams() { + // suite setup initializes genesis + expParams := types.NewParams(true, 1000, "", "", "0") // these are the default params + + params := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + suite.Require().Equal(expParams, params) + + newParams := types.NewParams(false, 1000, "abc", "def", "0.6") + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) + params = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + suite.Require().Equal(newParams, params) + + suite.childChain.App.(*appConsumer.App).ChildKeeper. + SetBlocksPerDistributionTransmission(suite.childChain.GetContext(), 10) + gotBPDT := suite.childChain.App.(*appConsumer.App).ChildKeeper. + GetBlocksPerDistributionTransmission(suite.childChain.GetContext()) + suite.Require().Equal(gotBPDT, int64(10)) + + suite.childChain.App.(*appConsumer.App).ChildKeeper. + SetDistributionTransmissionChannel(suite.childChain.GetContext(), "foobarbaz") + gotChan := suite.childChain.App.(*appConsumer.App).ChildKeeper. + GetDistributionTransmissionChannel(suite.childChain.GetContext()) + suite.Require().Equal(gotChan, "foobarbaz") + + suite.childChain.App.(*appConsumer.App).ChildKeeper. + SetProviderFeePoolAddrStr(suite.childChain.GetContext(), "foobar") + gotAddr := suite.childChain.App.(*appConsumer.App).ChildKeeper. + GetProviderFeePoolAddrStr(suite.childChain.GetContext()) + suite.Require().Equal(gotAddr, "foobar") + + suite.childChain.App.(*appConsumer.App).ChildKeeper. + SetConsumerRedistributeFrac(suite.childChain.GetContext(), "0.75") + gotFrac := suite.childChain.App.(*appConsumer.App).ChildKeeper. + GetConsumerRedistributeFrac(suite.childChain.GetContext()) + suite.Require().Equal(gotFrac, "0.75") +} diff --git a/x/ccv/child/module_test.go b/x/ccv/child/module_test.go new file mode 100644 index 0000000000..3d7c48e0ad --- /dev/null +++ b/x/ccv/child/module_test.go @@ -0,0 +1,410 @@ +package child_test + +import ( + "fmt" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" + host "github.com/cosmos/ibc-go/v3/modules/core/24-host" + ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" + ibctesting "github.com/cosmos/ibc-go/v3/testing" + + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" + "github.com/cosmos/interchain-security/testutil/simapp" + "github.com/cosmos/interchain-security/x/ccv/child" + "github.com/cosmos/interchain-security/x/ccv/child/types" + childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" + parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" + ccv "github.com/cosmos/interchain-security/x/ccv/types" + + tmtypes "github.com/tendermint/tendermint/types" + + "github.com/stretchr/testify/suite" +) + +type ChildTestSuite struct { + suite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains + parentChain *ibctesting.TestChain + childChain *ibctesting.TestChain + + parentClient *ibctmtypes.ClientState + parentConsState *ibctmtypes.ConsensusState + + path *ibctesting.Path + + ctx sdk.Context +} + +func (suite *ChildTestSuite) SetupTest() { + suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) + + tmConfig := ibctesting.NewTendermintConfig() + + // commit a block on parent chain before creating client + suite.coordinator.CommitBlock(suite.parentChain) + + // create client and consensus state of parent chain to initialize child chain genesis. + height := suite.parentChain.LastHeader.GetHeight().(clienttypes.Height) + UpgradePath := []string{"upgrade", "upgradedIBCState"} + + suite.parentClient = ibctmtypes.NewClientState( + suite.parentChain.ChainID, tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, + height, commitmenttypes.GetSDKSpecs(), UpgradePath, tmConfig.AllowUpdateAfterExpiry, tmConfig.AllowUpdateAfterMisbehaviour, + ) + suite.parentConsState = suite.parentChain.LastHeader.ConsensusState() + + // mocking the fact that child chain validators should be parent chain validators + // TODO: Fix testing suite so we can initialize both chains with the same validator set + valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) + + params := childtypes.DefaultParams() + params.Enabled = true + childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + + // create the ccv path and set child's clientID to genesis client + path := ibctesting.NewPath(suite.childChain, suite.parentChain) + path.EndpointA.ChannelConfig.PortID = childtypes.PortID + path.EndpointB.ChannelConfig.PortID = parenttypes.PortID + path.EndpointA.ChannelConfig.Version = ccv.Version + path.EndpointB.ChannelConfig.Version = ccv.Version + path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + if !ok { + panic("must already have parent client on child chain") + } + // set child endpoint's clientID + path.EndpointA.ClientID = parentClient + + // TODO: No idea why or how this works, but it seems that it needs to be done. + path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) + path.EndpointA.Chain.SenderAccount.SetAccountNumber(6) + + // create child client on parent chain and set as child client for child chainID in parent keeper. + path.EndpointB.CreateClient() + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, path.EndpointB.ClientID) + + suite.coordinator.CreateConnections(path) + + suite.ctx = suite.childChain.GetContext() + + suite.path = path +} + +func (suite *ChildTestSuite) TestOnChanOpenInit() { + channelID := "channel-1" + testCases := []struct { + name string + setup func(suite *ChildTestSuite) + expError bool + }{ + { + name: "success", + setup: func(suite *ChildTestSuite) { + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: false, + }, + { + name: "invalid: parent channel already established", + setup: func(suite *ChildTestSuite) { + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: true, + }, + { + name: "invalid: UNORDERED channel", + setup: func(suite *ChildTestSuite) { + // set path ORDER to UNORDERED + suite.path.EndpointA.ChannelConfig.Order = channeltypes.UNORDERED + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.UNORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: true, + }, + { + name: "invalid: incorrect port", + setup: func(suite *ChildTestSuite) { + // set path port to invalid portID + suite.path.EndpointA.ChannelConfig.PortID = "invalidPort" + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.UNORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: true, + }, + { + name: "invalid: incorrect version", + setup: func(suite *ChildTestSuite) { + // set path port to invalid version + suite.path.EndpointA.ChannelConfig.Version = "invalidVersion" + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.UNORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: true, + }, + { + name: "invalid: verify parent chain failed", + setup: func(suite *ChildTestSuite) { + // setup a new path with parent client on child chain being different from genesis client + path := ibctesting.NewPath(suite.childChain, suite.parentChain) + path.EndpointA.ChannelConfig.PortID = childtypes.PortID + path.EndpointB.ChannelConfig.PortID = parenttypes.PortID + path.EndpointA.ChannelConfig.Version = ccv.Version + path.EndpointB.ChannelConfig.Version = ccv.Version + path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED + + // create child client on parent chain, and parent client on child chain + path.EndpointB.CreateClient() + path.EndpointA.CreateClient() + + suite.coordinator.CreateConnections(path) + suite.path = path + + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: true, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case: %s", tc.name), func() { + suite.SetupTest() // reset suite + tc.setup(suite) + + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) + chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) + suite.Require().NoError(err) + + err = childModule.OnChanOpenInit(suite.ctx, suite.path.EndpointA.ChannelConfig.Order, []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.PortID, + suite.path.EndpointA.ChannelID, chanCap, channeltypes.NewCounterparty(parenttypes.PortID, ""), suite.path.EndpointA.ChannelConfig.Version) + + if tc.expError { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } + }) + } +} + +func (suite *ChildTestSuite) TestOnChanOpenTry() { + // OnOpenTry must error even with correct arguments + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) + chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) + suite.Require().NoError(err) + + _, err = childModule.OnChanOpenTry(suite.ctx, channeltypes.ORDERED, []string{"connection-1"}, childtypes.PortID, "channel-1", chanCap, channeltypes.NewCounterparty(parenttypes.PortID, "channel-1"), ccv.Version) + suite.Require().Error(err, "OnChanOpenTry callback must error on child chain") +} + +func (suite *ChildTestSuite) TestOnChanOpenAck() { + channelID := "channel-1" + testCases := []struct { + name string + setup func(suite *ChildTestSuite) + expError bool + }{ + { + name: "success", + setup: func(suite *ChildTestSuite) { + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: false, + }, + { + name: "invalid: parent channel already established", + setup: func(suite *ChildTestSuite) { + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: true, + }, + { + name: "invalid: mismatched versions", + setup: func(suite *ChildTestSuite) { + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + // set parent version to invalid version + suite.path.EndpointB.ChannelConfig.Version = "invalidVersion" + }, + expError: true, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case: %s", tc.name), func() { + suite.SetupTest() // reset suite + tc.setup(suite) + + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) + + md := parenttypes.HandshakeMetadata{ + ProviderFeePoolAddr: "", // dummy address used + Version: suite.path.EndpointB.ChannelConfig.Version, + } + mdBz, err := (&md).Marshal() + suite.Require().NoError(err) + + err = childModule.OnChanOpenAck(suite.ctx, childtypes.PortID, channelID, string(mdBz)) + if tc.expError { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } + }) + } +} + +func (suite *ChildTestSuite) TestOnChanOpenConfirm() { + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, "channel-1", + channeltypes.NewChannel( + channeltypes.TRYOPEN, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, "channel-1"), + []string{"connection-1"}, ccv.Version, + )) + + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) + + err := childModule.OnChanOpenConfirm(suite.ctx, childtypes.PortID, "channel-1") + suite.Require().Error(err, "OnChanOpenConfirm must always fail") +} + +func (suite *ChildTestSuite) TestOnChanCloseInit() { + channelID := "channel-1" + testCases := []struct { + name string + setup func(suite *ChildTestSuite) + expError bool + }{ + { + name: "can close duplicate in-progress channel once parent channel is established", + setup: func(suite *ChildTestSuite) { + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") + }, + expError: false, + }, + { + name: "can close duplicate open channel once parent channel is established", + setup: func(suite *ChildTestSuite) { + // create open channel + suite.coordinator.CreateChannels(suite.path) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") + }, + expError: false, + }, + { + name: "cannot close in-progress channel, no established channel yet", + setup: func(suite *ChildTestSuite) { + // Set INIT channel on child chain + suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, + channeltypes.NewChannel( + channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), + []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), + ) + suite.path.EndpointA.ChannelID = channelID + }, + expError: true, + }, + { + name: "cannot close parent channel", + setup: func(suite *ChildTestSuite) { + // create open channel + suite.coordinator.CreateChannels(suite.path) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, suite.path.EndpointA.ChannelID) + }, + expError: true, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case: %s", tc.name), func() { + suite.SetupTest() // reset suite + tc.setup(suite) + + childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) + + err := childModule.OnChanCloseInit(suite.ctx, childtypes.PortID, suite.path.EndpointA.ChannelID) + + if tc.expError { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } + }) + } +} + +func TestChildTestSuite(t *testing.T) { + suite.Run(t, new(ChildTestSuite)) +} diff --git a/x/ccv/consumer/keeper/keeper_test.go b/x/ccv/consumer/keeper/keeper_test.go index 187a61db7d..8aabb0531e 100644 --- a/x/ccv/consumer/keeper/keeper_test.go +++ b/x/ccv/consumer/keeper/keeper_test.go @@ -12,7 +12,8 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/consumer/types" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" @@ -23,10 +24,6 @@ import ( tmtypes "github.com/tendermint/tendermint/types" ) -func init() { - ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp -} - type KeeperTestSuite struct { suite.Suite @@ -34,7 +31,7 @@ type KeeperTestSuite struct { // testing chains providerChain *ibctesting.TestChain - consumerChain *ibctesting.TestChain + consumerChain *ibctesting.TestChain providerClient *ibctmtypes.ClientState providerConsState *ibctmtypes.ConsensusState @@ -45,9 +42,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.providerChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.consumerChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) tmConfig := ibctesting.NewTendermintConfig() @@ -68,8 +63,8 @@ func (suite *KeeperTestSuite) SetupTest() { params := consumertypes.DefaultParams() params.Enabled = true - consumerGenesis := types.NewInitialGenesisState(suite.providerClient, suite.providerConsState, valUpdates, params) - suite.consumerChain.App.(*app.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), consumerGenesis) + childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.consumerChain.GetContext() @@ -80,7 +75,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = ccv.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - providerClient, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetProviderClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.ctx) if !ok { panic("must already have provider client on consumer chain") } @@ -93,7 +88,7 @@ func (suite *KeeperTestSuite) SetupTest() { // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. suite.path.EndpointB.CreateClient() - suite.providerChain.App.(*app.App).ProviderKeeper.SetConsumerClient(suite.providerChain.GetContext(), suite.consumerChain.ChainID, suite.path.EndpointB.ClientID) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) } func (suite *KeeperTestSuite) SetupCCVChannel() { @@ -101,19 +96,19 @@ func (suite *KeeperTestSuite) SetupCCVChannel() { suite.coordinator.CreateChannels(suite.path) } -func (suite *KeeperTestSuite) TestProviderClient() { - providerClient, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetProviderClient(suite.ctx) +func (suite *KeeperTestSuite) TestParentClient() { + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.ctx) suite.Require().True(ok) clientState, ok := suite.consumerChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, providerClient) suite.Require().Equal(suite.providerClient, clientState, "stored client state does not match genesis provider client") } -func (suite *KeeperTestSuite) TestProviderChannel() { - _, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetProviderChannel(suite.ctx) +func (suite *KeeperTestSuite) TestParentChannel() { + _, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().False(ok) - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "channelID") - channelID, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetProviderChannel(suite.ctx) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") + channelID, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal("channelID", channelID) } @@ -139,34 +134,34 @@ func (suite *KeeperTestSuite) TestPendingChanges() { nil, ) - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetPendingChanges(suite.ctx, pd) - gotPd, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) + gotPd, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) suite.Require().Equal(&pd, gotPd, "packet data in store does not equal packet data set") - suite.consumerChain.App.(*app.App).ConsumerKeeper.DeletePendingChanges(suite.ctx) - gotPd, ok = suite.consumerChain.App.(*app.App).ConsumerKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*appConsumer.App).ChildKeeper.DeletePendingChanges(suite.ctx) + gotPd, ok = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().False(ok) suite.Require().Nil(gotPd, "got non-nil pending changes after Delete") } func (suite *KeeperTestSuite) TestUnbondingTime() { - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetUnbondingTime(suite.ctx, 1, 10) - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetUnbondingTime(suite.ctx, 2, 25) - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetUnbondingTime(suite.ctx, 5, 15) - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetUnbondingTime(suite.ctx, 6, 40) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) - suite.consumerChain.App.(*app.App).ConsumerKeeper.DeleteUnbondingTime(suite.ctx, 6) + suite.childChain.App.(*appConsumer.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) - suite.Require().Equal(uint64(10), suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 1)) - suite.Require().Equal(uint64(25), suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 2)) - suite.Require().Equal(uint64(15), suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 5)) - suite.Require().Equal(uint64(0), suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 3)) - suite.Require().Equal(uint64(0), suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 6)) + suite.Require().Equal(uint64(10), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) + suite.Require().Equal(uint64(25), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) + suite.Require().Equal(uint64(15), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) orderedTimes := [][]uint64{{1, 10}, {2, 25}, {5, 15}} i := 0 - suite.consumerChain.App.(*app.App).ConsumerKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { + suite.childChain.App.(*appConsumer.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { // require that we iterate through unbonding time in order of sequence suite.Require().Equal(orderedTimes[i][0], seq) suite.Require().Equal(orderedTimes[i][1], time) @@ -198,22 +193,22 @@ func (suite *KeeperTestSuite) TestUnbondingPacket() { ) packet := channeltypes.NewPacket(pd.GetBytes(), uint64(i), "provider", "channel-1", "consumer", "channel-1", clienttypes.NewHeight(1, 0), 0) - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) } // ensure that packets are iterated by sequence i := 0 - suite.consumerChain.App.(*app.App).ConsumerKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { + suite.childChain.App.(*appConsumer.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { suite.Require().Equal(uint64(i), seq) - gotPacket, err := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, seq) + gotPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) suite.Require().NoError(err) suite.Require().Equal(&packet, gotPacket, "packet from get and iteration do not match") i++ return false }) - suite.consumerChain.App.(*app.App).ConsumerKeeper.DeleteUnbondingPacket(suite.ctx, 0) - gotPacket, err := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 0) + suite.childChain.App.(*appConsumer.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) + gotPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) suite.Require().Error(err) suite.Require().Nil(gotPacket, "packet is not nil after delete") } @@ -236,7 +231,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -252,7 +247,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to validating - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -267,7 +262,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID, "connection-2"} }, @@ -277,7 +272,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { name: "connection does not exist", setup: func(suite *KeeperTestSuite) { // set channel status to INITIALIZING - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{"connection-dne"} }, @@ -295,7 +290,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -310,8 +305,8 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { tc.setup(suite) - // Verify ProviderChain on consumer chain using path returned by setup - err := suite.consumerChain.App.(*app.App).ConsumerKeeper.VerifyProviderChain(suite.ctx, channelID, connectionHops) + // Verify ParentChain on child chain using path returned by setup + err := suite.childChain.App.(*appConsumer.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) if tc.expError { suite.Require().Error(err, "invalid case did not return error") @@ -330,7 +325,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { suite.SetupCCVChannel() suite.SendEmptyVSCPacket() - app, ctx := suite.consumerChain.App.(*app.App), suite.consumerChain.GetContext() + app, ctx := suite.childChain.App.(*appConsumer.App), suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID // pick a cross-chain validator @@ -398,8 +393,8 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { suite.SetupCCVChannel() - app := suite.consumerChain.App.(*app.App) - ctx := suite.consumerChain.GetContext() + app := suite.childChain.App.(*appConsumer.App) + ctx := suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID // check that CCV channel isn't established @@ -463,8 +458,8 @@ func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { } func (suite *KeeperTestSuite) TestCrossChainValidator() { - app := suite.consumerChain.App.(*app.App) - ctx := suite.consumerChain.GetContext() + app := suite.childChain.App.(*appConsumer.App) + ctx := suite.childChain.GetContext() // should return false ccVal, foud := app.ConsumerKeeper.GetCCValidator(ctx, ed25519.GenPrivKey().PubKey().Address()) @@ -490,8 +485,8 @@ func (suite *KeeperTestSuite) TestCrossChainValidator() { } func (suite *KeeperTestSuite) TestPendingSlashRequests() { - consumerKeeper := suite.consumerChain.App.(*app.App).ConsumerKeeper - ctx := suite.consumerChain.GetContext() + childKeeper := suite.childChain.App.(*appConsumer.App).ChildKeeper + ctx := suite.childChain.GetContext() // prepare test setup by storing 10 pending slash requests request := []types.SlashRequest{} @@ -527,8 +522,8 @@ func (suite *KeeperTestSuite) TestPendingSlashRequests() { // to ensure that the channel gets established func (suite *KeeperTestSuite) SendEmptyVSCPacket() { - consumerKeeper := suite.consumerChain.App.(*app.App).ConsumerKeeper - providerKeeper := suite.providerChain.App.(*app.App).ProviderKeeper + childKeeper := suite.childChain.App.(*appConsumer.App).ChildKeeper + parentKeeper := suite.parentChain.App.(*appProvider.App).ParentKeeper oldBlockTime := suite.providerChain.GetContext().BlockTime() timeout := uint64(ccv.GetTimeoutTimestamp(oldBlockTime).UnixNano()) @@ -541,8 +536,8 @@ func (suite *KeeperTestSuite) SendEmptyVSCPacket() { nil, ) - seq, ok := suite.providerChain.App.(*app.App).GetIBCKeeper().ChannelKeeper.GetNextSequenceSend( - suite.providerChain.GetContext(), providertypes.PortID, suite.path.EndpointB.ChannelID) + seq, ok := suite.parentChain.App.(*appProvider.App).GetIBCKeeper().ChannelKeeper.GetNextSequenceSend( + suite.parentChain.GetContext(), parenttypes.PortID, suite.path.EndpointB.ChannelID) suite.Require().True(ok) packet := channeltypes.NewPacket(pd.GetBytes(), seq, providertypes.PortID, suite.path.EndpointB.ChannelID, diff --git a/x/ccv/consumer/keeper/relay_test.go b/x/ccv/consumer/keeper/relay_test.go index 17d6157a20..493be74908 100644 --- a/x/ccv/consumer/keeper/relay_test.go +++ b/x/ccv/consumer/keeper/relay_test.go @@ -8,7 +8,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - "github.com/cosmos/interchain-security/app" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -117,22 +118,22 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } for _, tc := range testCases { - ack := suite.consumerChain.App.(*app.App).ConsumerKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) + ack := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) if tc.expErrorAck { suite.Require().NotNil(ack, "invalid test case: %s did not return ack", tc.name) suite.Require().False(ack.Success(), "invalid test case: %s did not return an Error Acknowledgment") } else { suite.Require().Nil(ack, "successful packet must send ack asynchronously. case: %s", tc.name) - suite.Require().Equal(ccv.VALIDATING, suite.consumerChain.App.(*app.App).ConsumerKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), + suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*appConsumer.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), "channel status is not valdidating after receive packet for valid test case: %s", tc.name) - providerChannel, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetProviderChannel(suite.ctx) + parentChannel, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal(tc.packet.DestinationChannel, providerChannel, "provider channel is not destination channel on successful receive for valid test case: %s", tc.name) // Check that pending changes are accumulated and stored correctly - actualPendingChanges, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetPendingChanges(suite.ctx) + actualPendingChanges, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) // Sort to avoid dumb inequalities sort.SliceStable(actualPendingChanges.ValidatorUpdates, func(i, j int) bool { @@ -143,10 +144,10 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { }) suite.Require().Equal(tc.expectedPendingChanges, *actualPendingChanges, "pending changes not equal to expected changes after successful packet receive. case: %s", tc.name) - expectedTime := uint64(suite.ctx.BlockTime().Add(consumertypes.UnbondingTime).UnixNano()) - unbondingTime := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) + expectedTime := uint64(suite.ctx.BlockTime().Add(childtypes.UnbondingTime).UnixNano()) + unbondingTime := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) suite.Require().Equal(expectedTime, unbondingTime, "unbonding time has unexpected value for case: %s", tc.name) - unbondingPacket, err := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) + unbondingPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) suite.Require().NoError(err) suite.Require().Equal(&tc.packet, unbondingPacket, "packet is not added to unbonding queue after successful receive. case: %s", tc.name) } @@ -183,7 +184,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { // send first packet packet := channeltypes.NewPacket(pd.GetBytes(), 1, providertypes.PortID, suite.path.EndpointB.ChannelID, consumertypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - ack := suite.consumerChain.App.(*app.App).ConsumerKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send second packet @@ -191,7 +192,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[0].Power = 15 packet.Data = pd.GetBytes() packet.Sequence = 2 - ack = suite.consumerChain.App.(*app.App).ConsumerKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send third packet @@ -199,25 +200,25 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[1].Power = 40 packet.Data = pd.GetBytes() packet.Sequence = 3 - ack = suite.consumerChain.App.(*app.App).ConsumerKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // move ctx time forward such that first two packets are unbonded but third is not. suite.ctx = suite.ctx.WithBlockTime(origTime.Add(consumertypes.UnbondingTime).Add(3 * time.Hour)) - suite.consumerChain.App.(*app.App).ConsumerKeeper.UnbondMaturePackets(suite.ctx) + suite.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(suite.ctx) // ensure first two packets are unbonded and acknowledgement is written // unbonded time is deleted - time1 := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 1) - time2 := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 2) + time1 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) + time2 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) suite.Require().Equal(uint64(0), time1, "unbonding time not deleted for mature packet 1") suite.Require().Equal(uint64(0), time2, "unbonding time not deleted for mature packet 2") // unbonded packets are deleted - _, err = suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 1) + _, err = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") - _, err = suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 2) + _, err = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") expectedWriteAckBytes := channeltypes.CommitAcknowledgement(channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()) @@ -231,9 +232,9 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { suite.Require().Equal(expectedWriteAckBytes, ackBytes2, "did not write successful ack for matue packet 1") // ensure that third packet did not get ack written and is still in store - time3 := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 3) + time3 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) suite.Require().True(time3 > uint64(suite.ctx.BlockTime().UnixNano()), "Unbonding time for packet 3 is not after current time") - packet3, err := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 3) + packet3, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) suite.Require().NoError(err, "retrieving unbonding packet 3 returned error") suite.Require().Equal(&packet, packet3, "unbonding packet 3 has unexpected value") @@ -254,12 +255,12 @@ func (suite *KeeperTestSuite) TestOnAcknowledgement() { ack := channeltypes.NewResultAcknowledgement([]byte{1}) // expect no error - err := suite.consumerChain.App.(*app.App).ConsumerKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.Nil(err) // expect an error ack = channeltypes.NewErrorAcknowledgement("error") - err = suite.consumerChain.App.(*app.App).ConsumerKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.NotNil(err) } diff --git a/x/ccv/consumer/keeper/validators_test.go b/x/ccv/consumer/keeper/validators_test.go index ab6c778e53..6538f68aee 100644 --- a/x/ccv/consumer/keeper/validators_test.go +++ b/x/ccv/consumer/keeper/validators_test.go @@ -1,14 +1,14 @@ package keeper_test import ( - "github.com/cosmos/interchain-security/app" - "github.com/cosmos/interchain-security/x/ccv/consumer/types" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + "github.com/cosmos/interchain-security/x/ccv/child/types" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (k KeeperTestSuite) TestApplyCCValidatorChanges() { - consumerKeeper := k.consumerChain.App.(*app.App).ConsumerKeeper + childKeeper := k.childChain.App.(*appConsumer.App).ChildKeeper ctx := k.ctx // utility functions diff --git a/x/ccv/parent/keeper/genesis_test.go b/x/ccv/parent/keeper/genesis_test.go new file mode 100644 index 0000000000..43669b3cf6 --- /dev/null +++ b/x/ccv/parent/keeper/genesis_test.go @@ -0,0 +1,38 @@ +package keeper_test + +import ( + "fmt" + + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" + "github.com/cosmos/interchain-security/x/ccv/types" +) + +func (suite *KeeperTestSuite) TestGenesis() { + // set some chain-channel pairs before exporting + ctx := suite.parentChain.GetContext() + for i := 0; i < 4; i++ { + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChainToChannel(ctx, fmt.Sprintf("chainid-%d", i), fmt.Sprintf("channelid-%d", i)) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChannelToChain(ctx, fmt.Sprintf("channelid-%d", i), fmt.Sprintf("chainid-%d", i)) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChannelStatus(ctx, fmt.Sprintf("channelid-%d", i), types.Status(i)) + } + + genState := suite.parentChain.App.(*appProvider.App).ParentKeeper.ExportGenesis(suite.parentChain.GetContext()) + + suite.childChain.App.(*appConsumer.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) + + ctx = suite.childChain.GetContext() + for i := 0; i < 4; i++ { + expectedChainId := fmt.Sprintf("chainid-%d", i) + expectedChannelId := fmt.Sprintf("channelid-%d", i) + channelID, channelOk := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) + chainID, chainOk := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) + suite.Require().True(channelOk) + suite.Require().True(chainOk) + suite.Require().Equal(expectedChainId, chainID, "did not store correct chain id for given channel id") + suite.Require().Equal(expectedChannelId, channelID, "did not store correct channel id for given chain id") + + status := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChannelStatus(ctx, channelID) + suite.Require().Equal(types.Status(i), status, "status is unexpected for given channel id: %s", channelID) + } +} diff --git a/x/ccv/parent/keeper/keeper_test.go b/x/ccv/parent/keeper/keeper_test.go new file mode 100644 index 0000000000..4a479ca9d6 --- /dev/null +++ b/x/ccv/parent/keeper/keeper_test.go @@ -0,0 +1,202 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" + ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" + ibctesting "github.com/cosmos/ibc-go/v3/testing" + + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" + "github.com/cosmos/interchain-security/testutil/simapp" + childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" + parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" + "github.com/cosmos/interchain-security/x/ccv/types" + + tmtypes "github.com/tendermint/tendermint/types" + + "github.com/stretchr/testify/suite" +) + +type KeeperTestSuite struct { + suite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains + parentChain *ibctesting.TestChain + childChain *ibctesting.TestChain + + parentClient *ibctmtypes.ClientState + parentConsState *ibctmtypes.ConsensusState + + path *ibctesting.Path + + ctx sdk.Context +} + +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) + suite.parentChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.childChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) + + tmConfig := ibctesting.NewTendermintConfig() + + // commit a block on parent chain before creating client + suite.coordinator.CommitBlock(suite.parentChain) + + // create client and consensus state of parent chain to initialize child chain genesis. + height := suite.parentChain.LastHeader.GetHeight().(clienttypes.Height) + UpgradePath := []string{"upgrade", "upgradedIBCState"} + + suite.parentClient = ibctmtypes.NewClientState( + suite.parentChain.ChainID, tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, + height, commitmenttypes.GetSDKSpecs(), UpgradePath, tmConfig.AllowUpdateAfterExpiry, tmConfig.AllowUpdateAfterMisbehaviour, + ) + suite.parentConsState = suite.parentChain.LastHeader.ConsensusState() + + valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) + + params := childtypes.DefaultParams() + params.Enabled = true + childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + + suite.ctx = suite.parentChain.GetContext() + + suite.path = ibctesting.NewPath(suite.childChain, suite.parentChain) + suite.path.EndpointA.ChannelConfig.PortID = childtypes.PortID + suite.path.EndpointB.ChannelConfig.PortID = parenttypes.PortID + suite.path.EndpointA.ChannelConfig.Version = types.Version + suite.path.EndpointB.ChannelConfig.Version = types.Version + suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED + suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + if !ok { + panic("must already have parent client on child chain") + } + // set child endpoint's clientID + suite.path.EndpointA.ClientID = parentClient + + // TODO: No idea why or how this works, but it seems that it needs to be done. + suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) + suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(6) + + // create child client on parent chain and set as child client for child chainID in parent keeper. + suite.path.EndpointB.CreateClient() + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} + +func (suite *KeeperTestSuite) TestValsetUpdateBlockHeight() { + app := suite.parentChain.App.(*appProvider.App) + ctx := suite.ctx + + blockHeight := app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(0)) + suite.Require().Zero(blockHeight) + + app.ParentKeeper.SetValsetUpdateBlockHeight(ctx, uint64(1), uint64(2)) + blockHeight = app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(1)) + suite.Require().Equal(blockHeight, uint64(2)) + + app.ParentKeeper.DeleteValsetUpdateBlockHeight(ctx, uint64(1)) + blockHeight = app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(1)) + suite.Require().Zero(blockHeight) + + app.ParentKeeper.SetValsetUpdateBlockHeight(ctx, uint64(1), uint64(2)) + app.ParentKeeper.SetValsetUpdateBlockHeight(ctx, uint64(3), uint64(4)) + blockHeight = app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(3)) + suite.Require().Equal(blockHeight, uint64(4)) +} + +func (suite *KeeperTestSuite) TestSlashAcks() { + app := suite.parentChain.App.(*appProvider.App) + ctx := suite.ctx + + var chainsAcks [][]string + + penaltiesfN := func() (penalties []string) { + app.ParentKeeper.IterateSlashAcks(ctx, func(id string, acks []string) bool { + chainsAcks = append(chainsAcks, acks) + return true + }) + return + } + + chainID := "consumer" + + acks := app.ParentKeeper.GetSlashAcks(ctx, chainID) + suite.Require().Nil(acks) + + p := []string{"alice", "bob", "charlie"} + app.ParentKeeper.SetSlashAcks(ctx, chainID, p) + + acks = app.ParentKeeper.GetSlashAcks(ctx, chainID) + suite.Require().NotNil(acks) + + suite.Require().Len(acks, 3) + emptied := app.ParentKeeper.EmptySlashAcks(ctx, chainID) + suite.Require().Len(emptied, 3) + + acks = app.ParentKeeper.GetSlashAcks(ctx, chainID) + suite.Require().Nil(acks) + + chains := []string{"c1", "c2", "c3"} + + for _, c := range chains { + app.ParentKeeper.SetSlashAcks(ctx, c, p) + } + + penaltiesfN() + suite.Require().Len(chainsAcks, len(chains)) +} + +func (suite *KeeperTestSuite) TestAppendslashingAck() { + app := suite.parentChain.App.(*appProvider.App) + ctx := suite.ctx + + p := []string{"alice", "bob", "charlie"} + chains := []string{"c1", "c2"} + app.ParentKeeper.SetSlashAcks(ctx, chains[0], p) + + app.ParentKeeper.AppendslashingAck(ctx, chains[0], p[0]) + acks := app.ParentKeeper.GetSlashAcks(ctx, chains[0]) + suite.Require().NotNil(acks) + suite.Require().Len(acks, len(p)+1) + + app.ParentKeeper.AppendslashingAck(ctx, chains[1], p[0]) + acks = app.ParentKeeper.GetSlashAcks(ctx, chains[1]) + suite.Require().NotNil(acks) + suite.Require().Len(acks, 1) +} + +func (suite *KeeperTestSuite) TestInitHeight() { + app := suite.parentChain.App.(*appProvider.App) + ctx := suite.ctx + + tc := []struct { + chainID string + expected uint64 + }{ + {expected: 0, chainID: "chain"}, + {expected: 10, chainID: "chain1"}, + {expected: 12, chainID: "chain2"}, + } + + app.ParentKeeper.SetInitChainHeight(ctx, tc[1].chainID, tc[1].expected) + app.ParentKeeper.SetInitChainHeight(ctx, tc[2].chainID, tc[2].expected) + + for _, t := range tc { + height := app.ParentKeeper.GetInitChainHeight(ctx, t.chainID) + suite.Require().EqualValues(t.expected, height) + } +} diff --git a/x/ccv/parent/keeper/proposal_test.go b/x/ccv/parent/keeper/proposal_test.go new file mode 100644 index 0000000000..4105fd7ea8 --- /dev/null +++ b/x/ccv/parent/keeper/proposal_test.go @@ -0,0 +1,113 @@ +package keeper_test + +import ( + "encoding/json" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" + appProvider "github.com/cosmos/interchain-security/app_provider" + childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" + "github.com/cosmos/interchain-security/x/ccv/parent/types" + abci "github.com/tendermint/tendermint/abci/types" + crypto "github.com/tendermint/tendermint/proto/tendermint/crypto" +) + +func (suite *KeeperTestSuite) TestMakeChildGenesis() { + var ctx sdk.Context + suite.SetupTest() + ctx = suite.parentChain.GetContext().WithBlockTime(time.Now()) + + actualGenesis, err := suite.parentChain.App.(*appProvider.App).ParentKeeper.MakeChildGenesis(ctx) + suite.Require().NoError(err) + + jsonString := `{"params":{"Enabled":true},"new_chain":true,"parent_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"parent_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` + + var expectedGenesis childtypes.GenesisState + json.Unmarshal([]byte(jsonString), &expectedGenesis) + + // Zero out differing fields- TODO: figure out how to get the test suite to + // keep these deterministic + actualGenesis.ParentConsensusState.NextValidatorsHash = []byte{} + expectedGenesis.ParentConsensusState.NextValidatorsHash = []byte{} + + // set valset to one empty validator because SetupTest() creates 4 validators per chain + actualGenesis.InitialValSet = []abci.ValidatorUpdate{{PubKey: crypto.PublicKey{}, Power: actualGenesis.InitialValSet[0].Power}} + expectedGenesis.InitialValSet[0].PubKey = crypto.PublicKey{} + + actualGenesis.ParentConsensusState.Root.Hash = []byte{} + expectedGenesis.ParentConsensusState.Root.Hash = []byte{} + + suite.Require().Equal(actualGenesis, expectedGenesis, "child chain genesis created incorrectly") +} + +func (suite *KeeperTestSuite) TestCreateChildChainProposal() { + var ( + ctx sdk.Context + proposal *types.CreateChildChainProposal + ok bool + ) + + chainID := "chainID" + initialHeight := clienttypes.NewHeight(2, 3) + + testCases := []struct { + name string + malleate func(*KeeperTestSuite) + expPass bool + spawnReached bool + }{ + { + "valid create child chain proposal: spawn time reached", func(suite *KeeperTestSuite) { + // ctx blocktime is after proposal's spawn time + ctx = suite.parentChain.GetContext().WithBlockTime(time.Now().Add(time.Hour)) + content, err := types.NewCreateChildChainProposal("title", "description", chainID, initialHeight, []byte("gen_hash"), []byte("bin_hash"), time.Now()) + suite.Require().NoError(err) + proposal, ok = content.(*types.CreateChildChainProposal) + suite.Require().True(ok) + }, true, true, + }, + { + "valid proposal: spawn time has not yet been reached", func(suite *KeeperTestSuite) { + // ctx blocktime is before proposal's spawn time + ctx = suite.parentChain.GetContext().WithBlockTime(time.Now()) + content, err := types.NewCreateChildChainProposal("title", "description", chainID, initialHeight, []byte("gen_hash"), []byte("bin_hash"), time.Now().Add(time.Hour)) + suite.Require().NoError(err) + proposal, ok = content.(*types.CreateChildChainProposal) + suite.Require().True(ok) + }, true, false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + tc.malleate(suite) + + err := suite.parentChain.App.(*appProvider.App).ParentKeeper.CreateChildChainProposal(ctx, proposal) + if tc.expPass { + suite.Require().NoError(err, "error returned on valid case") + if tc.spawnReached { + clientId := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetChildClient(ctx, chainID) + childGenesis, ok := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetChildGenesis(ctx, chainID) + suite.Require().True(ok) + + expectedGenesis, err := suite.parentChain.App.(*appProvider.App).ParentKeeper.MakeChildGenesis(ctx) + suite.Require().NoError(err) + + suite.Require().Equal(expectedGenesis, childGenesis) + suite.Require().NotEqual("", clientId, "child client was not created after spawn time reached") + } else { + gotHeight := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetPendingClientInfo(ctx, proposal.SpawnTime, chainID) + suite.Require().Equal(initialHeight, gotHeight, "pending client not equal to clientstate in proposal") + } + } else { + suite.Require().Error(err, "did not return error on invalid case") + } + }) + } +} diff --git a/x/ccv/provider/keeper/params_test.go b/x/ccv/provider/keeper/params_test.go index 8865fa8336..ec0513fdf0 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -6,19 +6,19 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - "github.com/cosmos/interchain-security/app" - "github.com/cosmos/interchain-security/x/ccv/provider/types" + appProvider "github.com/cosmos/interchain-security/app_provider" + "github.com/cosmos/interchain-security/x/ccv/parent/types" ) func (suite *KeeperTestSuite) TestParams() { expParams := types.DefaultParams() - params := suite.providerChain.App.(*app.App).ProviderKeeper.GetParams(suite.providerChain.GetContext()) + params := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) suite.Require().Equal(expParams, params) newParams := types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false)) - suite.providerChain.App.(*app.App).ProviderKeeper.SetParams(suite.providerChain.GetContext(), newParams) - params = suite.providerChain.App.(*app.App).ProviderKeeper.GetParams(suite.providerChain.GetContext()) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetParams(suite.parentChain.GetContext(), newParams) + params = suite.parentChain.App.(*appProvider.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) suite.Require().Equal(newParams, params) } diff --git a/x/ccv/provider/proposal_handler_test.go b/x/ccv/provider/proposal_handler_test.go index 6ce588eede..3a39ec3a97 100644 --- a/x/ccv/provider/proposal_handler_test.go +++ b/x/ccv/provider/proposal_handler_test.go @@ -8,9 +8,9 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" - "github.com/cosmos/interchain-security/x/ccv/provider" - "github.com/cosmos/interchain-security/x/ccv/provider/types" + appProvider "github.com/cosmos/interchain-security/app_provider" + "github.com/cosmos/interchain-security/x/ccv/parent" + "github.com/cosmos/interchain-security/x/ccv/parent/types" ) func (suite *ProviderTestSuite) TestCreateConsumerChainProposalHandler() { @@ -56,7 +56,7 @@ func (suite *ProviderTestSuite) TestCreateConsumerChainProposalHandler() { tc.malleate(suite) - proposalHandler := provider.NewCreateConsumerChainHandler(suite.providerChain.App.(*app.App).ProviderKeeper) + proposalHandler := parent.NewCreateChildChainHandler(suite.parentChain.App.(*appProvider.App).ParentKeeper) err = proposalHandler(ctx, content) diff --git a/x/ccv/provider/provider_test.go b/x/ccv/provider/provider_test.go index cb6fa4469a..b36caabf06 100644 --- a/x/ccv/provider/provider_test.go +++ b/x/ccv/provider/provider_test.go @@ -2,7 +2,6 @@ package provider_test import ( "fmt" - "strconv" "testing" "time" @@ -23,7 +22,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/testutil/simapp" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" @@ -35,18 +35,14 @@ import ( "github.com/stretchr/testify/suite" ) -func init() { - ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp -} - -type ProviderTestSuite struct { +type ParentTestSuite struct { suite.Suite coordinator *ibctesting.Coordinator // testing chains providerChain *ibctesting.TestChain - consumerChain *ibctesting.TestChain + consumerChain *ibctesting.TestChain providerClient *ibctmtypes.ClientState providerConsState *ibctmtypes.ConsensusState @@ -59,12 +55,10 @@ type ProviderTestSuite struct { ctx sdk.Context } -func (suite *ProviderTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 1) - suite.providerChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - // create consumer chain with provider chain valset - suite.CreateConsumerChain() - suite.consumerChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) +func (suite *ParentTestSuite) SetupTest() { + + suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) + suite.DisableConsumerDistribution() tmConfig := ibctesting.NewTendermintConfig() @@ -91,8 +85,8 @@ func (suite *ProviderTestSuite) SetupTest() { "", "0.5", // 50% ) - consumerGenesis := consumertypes.NewInitialGenesisState(suite.providerClient, suite.providerConsState, valUpdates, params) - suite.consumerChain.App.(*app.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), consumerGenesis) + childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) + suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.providerChain.GetContext() @@ -103,7 +97,7 @@ func (suite *ProviderTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - providerClient, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetProviderClient(suite.consumerChain.GetContext()) + parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have provider client on consumer chain") } @@ -116,7 +110,7 @@ func (suite *ProviderTestSuite) SetupTest() { // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. suite.path.EndpointB.CreateClient() - suite.providerChain.App.(*app.App).ProviderKeeper.SetConsumerClient(suite.providerChain.GetContext(), suite.consumerChain.ChainID, suite.path.EndpointB.ClientID) + suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) suite.transferPath = ibctesting.NewPath(suite.consumerChain, suite.providerChain) suite.transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID @@ -140,8 +134,8 @@ func (suite *ProviderTestSuite) SetupCCVChannel() { suite.transferPath.EndpointB.ConnectionID = suite.path.EndpointB.ConnectionID // INIT step for transfer path has already been called during CCV channel setup - suite.transferPath.EndpointA.ChannelID = suite.consumerChain.App.(*app.App). - ConsumerKeeper.GetDistributionTransmissionChannel(suite.consumerChain.GetContext()) + suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*appConsumer.App). + ChildKeeper.GetDistributionTransmissionChannel(suite.childChain.GetContext()) // Complete TRY, ACK, CONFIRM for transfer path err := suite.transferPath.EndpointB.ChanOpenTry() @@ -157,15 +151,8 @@ func (suite *ProviderTestSuite) SetupCCVChannel() { suite.transferPath.EndpointA.UpdateClient() } -func (s *ProviderTestSuite) CreateConsumerChain() { - provider := s.providerChain - chainID := ibctesting.ChainIDPrefix + strconv.Itoa(len(s.coordinator.Chains)+1) - consumer := ibctesting.NewTestChainWithValSet(s.T(), s.coordinator, chainID, provider.Vals, provider.Signers) - s.coordinator.Chains[consumer.ChainID] = consumer -} - -func TestProviderTestSuite(t *testing.T) { - suite.Run(t, new(ProviderTestSuite)) +func TestParentTestSuite(t *testing.T) { + suite.Run(t, new(ParentTestSuite)) } func (s *ProviderTestSuite) TestPacketRoundtrip() { @@ -190,7 +177,7 @@ func (s *ProviderTestSuite) TestPacketRoundtrip() { s.Require().NoError(err) // Save valset update ID to reconstruct packet - valUpdateID := s.providerChain.App.(*app.App).ProviderKeeper.GetValidatorSetUpdateId(s.providerCtx()) + valUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) // Send CCV packet to consumer s.providerChain.App.EndBlock(abci.RequestEndBlock{}) @@ -221,9 +208,9 @@ func (s *ProviderTestSuite) TestPacketRoundtrip() { s.providerChain.App.EndBlock(abci.RequestEndBlock{}) // - End consumer unbonding period - consumerCtx := s.consumerCtx().WithBlockTime(origTime.Add(consumertypes.UnbondingTime).Add(3 * time.Hour)) - // TODO: why doesn't this work: s.consumerChain.App.EndBlock(abci.RequestEndBlock{}) - err = s.consumerChain.App.(*app.App).ConsumerKeeper.UnbondMaturePackets(consumerCtx) + childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) + // TODO: why doesn't this work: s.childChain.App.EndBlock(abci.RequestEndBlock{}) + err = s.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) // commit consumer chain and update provider chain client @@ -246,8 +233,8 @@ func (s *ProviderTestSuite) consumerCtx() sdk.Context { return s.consumerChain.GetContext() } -func (s *ProviderTestSuite) providerBondDenom() string { - return s.providerChain.App.(*app.App).StakingKeeper.BondDenom(s.providerCtx()) +func (s *ParentTestSuite) parentBondDenom() string { + return s.parentChain.App.(*appProvider.App).StakingKeeper.BondDenom(s.parentCtx()) } // TestSendDowntimePacket tests consumer initiated slashing @@ -255,10 +242,10 @@ func (s *ProviderTestSuite) TestSendDowntimePacket() { s.SetupCCVChannel() validatorsPerChain := len(s.consumerChain.Vals.Validators) - providerStakingKeeper := s.providerChain.App.GetStakingKeeper() - providerSlashingKeeper := s.providerChain.App.(*app.App).SlashingKeeper + parentStakingKeeper := s.parentChain.App.GetStakingKeeper() + parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper - consumerKeeper := s.consumerChain.App.(*app.App).ConsumerKeeper + childKeeper := s.childChain.App.(*appConsumer.App).ChildKeeper // get a cross-chain validator address, pubkey and balance tmVals := s.consumerChain.Vals.Validators @@ -301,12 +288,12 @@ func (s *ProviderTestSuite) TestSendDowntimePacket() { s.Require().NoError(err) // Set outstanding slashing flag - s.consumerChain.App.(*app.App).ConsumerKeeper.SetOutstandingDowntime(s.consumerCtx(), consAddr) + s.childChain.App.(*appConsumer.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) // save next VSC packet info oldBlockTime = s.providerCtx().BlockTime() timeout = uint64(types.GetTimeoutTimestamp(oldBlockTime).UnixNano()) - valsetUpdateID := s.providerChain.App.(*app.App).ProviderKeeper.GetValidatorSetUpdateId(s.providerCtx()) + valsetUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) // receive the downtime packet on the provider chain; // RecvPacket() calls the provider endblocker thus sends a VSC packet to the consumer @@ -364,8 +351,8 @@ func (s *ProviderTestSuite) TestSendDowntimePacket() { s.Require().True(found) s.Require().True(valSignInfo.JailedUntil.After(s.providerCtx().BlockHeader().Time)) - // check that the outstanding slashing flag is reset on the consumer - pFlag := s.consumerChain.App.(*app.App).ConsumerKeeper.OutstandingDowntime(s.consumerCtx(), consAddr) + // check that the outstanding slashing flag is reset on the child + pFlag := s.childChain.App.(*appConsumer.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) s.Require().False(pFlag) // check that slashing packet gets acknowledged @@ -388,9 +375,9 @@ func (s *ProviderTestSuite) getVal(index int) (validator stakingtypes.Validator, // TestHandleConsumerDowntime tests the slashing distribution func (s *ProviderTestSuite) TestHandleConsumerDowntime() { s.SetupCCVChannel() - providerStakingKeeper := s.providerChain.App.GetStakingKeeper() - providerSlashingKeeper := s.providerChain.App.(*app.App).SlashingKeeper - providerKeeper := s.providerChain.App.(*app.App).ProviderKeeper + parentStakingKeeper := s.parentChain.App.GetStakingKeeper() + parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper + parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper // bonded amount bondAmt := sdk.NewInt(1000000) @@ -496,11 +483,11 @@ func (s *ProviderTestSuite) TestHandleConsumerDowntime() { } } -func (s *ProviderTestSuite) TestHandleConsumerDowntimeErrors() { - providerStakingKeeper := s.providerChain.App.GetStakingKeeper() - providerKeeper := s.providerChain.App.(*app.App).ProviderKeeper - providerSlashingKeeper := s.providerChain.App.(*app.App).SlashingKeeper - consumerChainID := s.consumerChain.ChainID +func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { + parentStakingKeeper := s.parentChain.App.GetStakingKeeper() + parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper + parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper + childChainID := s.childChain.ChainID // expect an error if initial block height isn't set for consumer chain err := providerKeeper.HandleConsumerDowntime(s.providerCtx(), consumerChainID, types.SlashPacketData{}) @@ -567,9 +554,9 @@ func (s *ProviderTestSuite) TestHandleConsumerDowntimeErrors() { s.Require().NoError(err) } -func (s *ProviderTestSuite) TestslashingPacketAcknowldgement() { - providerKeeper := s.providerChain.App.(*app.App).ProviderKeeper - consumerKeeper := s.consumerChain.App.(*app.App).ConsumerKeeper +func (s *ParentTestSuite) TestslashingPacketAcknowldgement() { + parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper + childKeeper := s.childChain.App.(*appConsumer.App).ChildKeeper packet := channeltypes.NewPacket([]byte{}, 1, consumertypes.PortID, s.path.EndpointA.ChannelID, providertypes.PortID, "wrongchannel", clienttypes.Height{}, 0) @@ -624,9 +611,9 @@ func (s *ProviderTestSuite) UpdateConsumerHistInfo(changes []abci.ValidatorUpdat s.consumerChain.App.GetStakingKeeper().SetHistoricalInfo(s.consumerCtx(), s.consumerCtx().BlockHeight(), &hi) } -func (s *ProviderTestSuite) DisableConsumerDistribution() { - cChain := s.consumerChain - cApp := cChain.App.(*app.App) +func (s *ParentTestSuite) DisableConsumerDistribution() { + cChain := s.childChain + cApp := cChain.App.(*appConsumer.App) for i, moduleName := range cApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { cApp.MM.OrderBeginBlockers = append(cApp.MM.OrderBeginBlockers[:i], cApp.MM.OrderBeginBlockers[i+1:]...) @@ -635,9 +622,9 @@ func (s *ProviderTestSuite) DisableConsumerDistribution() { } } -func (s *ProviderTestSuite) DisableProviderDistribution() { - pChain := s.providerChain - pApp := pChain.App.(*app.App) +func (s *ParentTestSuite) DisableProviderDistribution() { + pChain := s.parentChain + pApp := pChain.App.(*appProvider.App) for i, moduleName := range pApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { s.providerDistrIndex = i @@ -647,9 +634,9 @@ func (s *ProviderTestSuite) DisableProviderDistribution() { } } -func (s *ProviderTestSuite) ReenableProviderDistribution() { - pChain := s.providerChain - pApp := pChain.App.(*app.App) +func (s *ParentTestSuite) ReenableProviderDistribution() { + pChain := s.parentChain + pApp := pChain.App.(*appProvider.App) i := s.providerDistrIndex pApp.MM.OrderBeginBlockers = append( pApp.MM.OrderBeginBlockers[:i+1], pApp.MM.OrderBeginBlockers[i:]...) // make space @@ -663,9 +650,9 @@ func (s *ProviderTestSuite) TestDistribution() { // NOTE s.transferPath.EndpointA == Consumer Chain // s.transferPath.EndpointB == Provider Chain - pChain, cChain := s.providerChain, s.consumerChain - pApp, cApp := pChain.App.(*app.App), cChain.App.(*app.App) - cKeep := cApp.ConsumerKeeper + pChain, cChain := s.parentChain, s.childChain + pApp, cApp := pChain.App.(*appProvider.App), cChain.App.(*appConsumer.App) + cKeep := cApp.ChildKeeper // Get the receiving fee pool on the provider chain fcAddr := pApp.ProviderKeeper.GetFeeCollectorAddressStr(pChain.GetContext()) diff --git a/x/ccv/provider/unbonding_hook_test.go b/x/ccv/provider/unbonding_hook_test.go index 2e40b969f6..8f5348c217 100644 --- a/x/ccv/provider/unbonding_hook_test.go +++ b/x/ccv/provider/unbonding_hook_test.go @@ -11,9 +11,9 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - "github.com/cosmos/interchain-security/app" - consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" - providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" + childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" "github.com/cosmos/interchain-security/x/ccv/types" abci "github.com/tendermint/tendermint/abci/types" @@ -159,8 +159,8 @@ func (s *ProviderTestSuite) TestStakingHooks1() { s.Require().True(getBalance(s, newProviderCtx, delAddr).Equal(initBalance.Sub(bondAmt.Quo(sdk.NewInt(2))))) } -func getBalance(s *ProviderTestSuite, providerCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int { - return s.providerChain.App.(*app.App).BankKeeper.GetBalance(providerCtx, delAddr, s.providerBondDenom()).Amount +func getBalance(s *ParentTestSuite, parentCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int { + return s.parentChain.App.(*appProvider.App).BankKeeper.GetBalance(parentCtx, delAddr, s.parentBondDenom()).Amount } func doUnbonding(s *ProviderTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (initBalance sdk.Int, valsetUpdateId uint64) { @@ -186,7 +186,7 @@ func doUnbonding(s *ProviderTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) s.Require().True(getBalance(s, s.providerCtx(), delAddr).Equal(initBalance.Sub(bondAmt))) // save the current valset update ID - valsetUpdateID := s.providerChain.App.(*app.App).ProviderKeeper.GetValidatorSetUpdateId(s.providerCtx()) + valsetUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) return initBalance, valsetUpdateID } @@ -202,9 +202,9 @@ func endProviderUnbondingPeriod(s *ProviderTestSuite, origTime time.Time) sdk.Co func endConsumerUnbondingPeriod(s *ProviderTestSuite, origTime time.Time) { // - End consumer unbonding period - consumerCtx := s.consumerCtx().WithBlockTime(origTime.Add(consumertypes.UnbondingTime).Add(3 * time.Hour)) - // s.consumerChain.App.EndBlock(abci.RequestEndBlock{}) // <- this doesn't work because we can't modify the ctx - err := s.consumerChain.App.(*app.App).ConsumerKeeper.UnbondMaturePackets(consumerCtx) + childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) + // s.childChain.App.EndBlock(abci.RequestEndBlock{}) // <- this doesn't work because we can't modify the ctx + err := s.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) } @@ -214,8 +214,8 @@ func checkStakingUnbondingOps(s *ProviderTestSuite, id uint64, found bool, onHol s.Require().True(onHold == stakingUnbondingOp.UnbondingOnHold) } -func checkCCVUnbondingOp(s *ProviderTestSuite, providerCtx sdk.Context, chainID string, valUpdateID uint64, found bool) { - _, wasFound := s.providerChain.App.(*app.App).ProviderKeeper.GetUnbondingOpsFromIndex(providerCtx, chainID, valUpdateID) +func checkCCVUnbondingOp(s *ParentTestSuite, parentCtx sdk.Context, chainID string, valUpdateID uint64, found bool) { + _, wasFound := s.parentChain.App.(*appProvider.App).ParentKeeper.GetUnbondingOpsFromIndex(parentCtx, chainID, valUpdateID) s.Require().True(found == wasFound) } @@ -258,7 +258,7 @@ func sendValUpdateAck(s *ProviderTestSuite, providerCtx sdk.Context, packet chan // err := s.path.EndpointB.AcknowledgePacket(packet, ack.Acknowledgement()) // s.Require().NoError(err) - err := s.providerChain.App.(*app.App).ProviderKeeper.OnAcknowledgementPacket(providerCtx, packet, packetData, ack) + err := s.parentChain.App.(*appProvider.App).ParentKeeper.OnAcknowledgementPacket(parentCtx, packet, packetData, ack) s.Require().NoError(err) } From e99b62351b447b3e5862bf1f6a6cff0fc1e5445a Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 May 2022 12:45:03 +0100 Subject: [PATCH 15/23] Deletes old parent/child --- x/ccv/child/keeper/genesis_test.go | 86 ------ x/ccv/child/keeper/params_test.go | 43 --- x/ccv/child/module_test.go | 410 --------------------------- x/ccv/parent/keeper/genesis_test.go | 38 --- x/ccv/parent/keeper/keeper_test.go | 202 ------------- x/ccv/parent/keeper/proposal_test.go | 113 -------- 6 files changed, 892 deletions(-) delete mode 100644 x/ccv/child/keeper/genesis_test.go delete mode 100644 x/ccv/child/keeper/params_test.go delete mode 100644 x/ccv/child/module_test.go delete mode 100644 x/ccv/parent/keeper/genesis_test.go delete mode 100644 x/ccv/parent/keeper/keeper_test.go delete mode 100644 x/ccv/parent/keeper/proposal_test.go diff --git a/x/ccv/child/keeper/genesis_test.go b/x/ccv/child/keeper/genesis_test.go deleted file mode 100644 index ad6a540046..0000000000 --- a/x/ccv/child/keeper/genesis_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package keeper_test - -import ( - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - - clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - - childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" - parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" - "github.com/cosmos/interchain-security/x/ccv/types" - - appConsumer "github.com/cosmos/interchain-security/app_consumer" - abci "github.com/tendermint/tendermint/abci/types" - tmtypes "github.com/tendermint/tendermint/types" -) - -func (suite *KeeperTestSuite) TestGenesis() { - genesis := suite.childChain.App.(*appConsumer.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) - - suite.Require().Equal(suite.parentClient, genesis.ParentClientState) - suite.Require().Equal(suite.parentConsState, genesis.ParentConsensusState) - - suite.Require().NotPanics(func() { - suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) - // reset suite to reset parent client - suite.SetupTest() - }) - - ctx := suite.childChain.GetContext() - portId := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPort(ctx) - suite.Require().Equal(childtypes.PortID, portId) - - clientId, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(ctx) - suite.Require().True(ok) - clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(ctx, clientId) - suite.Require().True(ok) - suite.Require().Equal(genesis.ParentClientState, clientState, "client state not set correctly after InitGenesis") - - suite.SetupCCVChannel() - - origTime := suite.childChain.GetContext().BlockTime() - - pk1, err := cryptocodec.ToTmProtoPublicKey(ed25519.GenPrivKey().PubKey()) - suite.Require().NoError(err) - pk2, err := cryptocodec.ToTmProtoPublicKey(ed25519.GenPrivKey().PubKey()) - suite.Require().NoError(err) - pd := types.NewValidatorSetChangePacketData( - []abci.ValidatorUpdate{ - { - PubKey: pk1, - Power: 30, - }, - { - PubKey: pk2, - Power: 20, - }, - }, - 1, - nil, - ) - packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, - clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) - - // mocking the fact that child chain validators should be parent chain validators - // TODO: Fix testing suite so we can initialize both chains with the same validator set - valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) - - restartGenesis := suite.childChain.App.(*appConsumer.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) - restartGenesis.InitialValSet = valUpdates - - // ensure reset genesis is set correctly - parentChannel := suite.path.EndpointA.ChannelID - suite.Require().Equal(parentChannel, restartGenesis.ParentChannelId) - unbondingTime := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) - suite.Require().Equal(uint64(origTime.Add(childtypes.UnbondingTime).UnixNano()), unbondingTime, "unbonding time is not set correctly in genesis") - unbondingPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) - suite.Require().NoError(err) - suite.Require().Equal(&packet, unbondingPacket, "unbonding packet is not set correctly in genesis") - - suite.Require().NotPanics(func() { - suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) - }) -} diff --git a/x/ccv/child/keeper/params_test.go b/x/ccv/child/keeper/params_test.go deleted file mode 100644 index 4420bfa491..0000000000 --- a/x/ccv/child/keeper/params_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package keeper_test - -import ( - appConsumer "github.com/cosmos/interchain-security/app_consumer" - "github.com/cosmos/interchain-security/x/ccv/child/types" -) - -func (suite *KeeperTestSuite) TestParams() { - // suite setup initializes genesis - expParams := types.NewParams(true, 1000, "", "", "0") // these are the default params - - params := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParams(suite.childChain.GetContext()) - suite.Require().Equal(expParams, params) - - newParams := types.NewParams(false, 1000, "abc", "def", "0.6") - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) - params = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParams(suite.childChain.GetContext()) - suite.Require().Equal(newParams, params) - - suite.childChain.App.(*appConsumer.App).ChildKeeper. - SetBlocksPerDistributionTransmission(suite.childChain.GetContext(), 10) - gotBPDT := suite.childChain.App.(*appConsumer.App).ChildKeeper. - GetBlocksPerDistributionTransmission(suite.childChain.GetContext()) - suite.Require().Equal(gotBPDT, int64(10)) - - suite.childChain.App.(*appConsumer.App).ChildKeeper. - SetDistributionTransmissionChannel(suite.childChain.GetContext(), "foobarbaz") - gotChan := suite.childChain.App.(*appConsumer.App).ChildKeeper. - GetDistributionTransmissionChannel(suite.childChain.GetContext()) - suite.Require().Equal(gotChan, "foobarbaz") - - suite.childChain.App.(*appConsumer.App).ChildKeeper. - SetProviderFeePoolAddrStr(suite.childChain.GetContext(), "foobar") - gotAddr := suite.childChain.App.(*appConsumer.App).ChildKeeper. - GetProviderFeePoolAddrStr(suite.childChain.GetContext()) - suite.Require().Equal(gotAddr, "foobar") - - suite.childChain.App.(*appConsumer.App).ChildKeeper. - SetConsumerRedistributeFrac(suite.childChain.GetContext(), "0.75") - gotFrac := suite.childChain.App.(*appConsumer.App).ChildKeeper. - GetConsumerRedistributeFrac(suite.childChain.GetContext()) - suite.Require().Equal(gotFrac, "0.75") -} diff --git a/x/ccv/child/module_test.go b/x/ccv/child/module_test.go deleted file mode 100644 index 3d7c48e0ad..0000000000 --- a/x/ccv/child/module_test.go +++ /dev/null @@ -1,410 +0,0 @@ -package child_test - -import ( - "fmt" - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - - clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" - host "github.com/cosmos/ibc-go/v3/modules/core/24-host" - ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - ibctesting "github.com/cosmos/ibc-go/v3/testing" - - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" - "github.com/cosmos/interchain-security/testutil/simapp" - "github.com/cosmos/interchain-security/x/ccv/child" - "github.com/cosmos/interchain-security/x/ccv/child/types" - childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" - parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" - ccv "github.com/cosmos/interchain-security/x/ccv/types" - - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/stretchr/testify/suite" -) - -type ChildTestSuite struct { - suite.Suite - - coordinator *ibctesting.Coordinator - - // testing chains - parentChain *ibctesting.TestChain - childChain *ibctesting.TestChain - - parentClient *ibctmtypes.ClientState - parentConsState *ibctmtypes.ConsensusState - - path *ibctesting.Path - - ctx sdk.Context -} - -func (suite *ChildTestSuite) SetupTest() { - suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) - - tmConfig := ibctesting.NewTendermintConfig() - - // commit a block on parent chain before creating client - suite.coordinator.CommitBlock(suite.parentChain) - - // create client and consensus state of parent chain to initialize child chain genesis. - height := suite.parentChain.LastHeader.GetHeight().(clienttypes.Height) - UpgradePath := []string{"upgrade", "upgradedIBCState"} - - suite.parentClient = ibctmtypes.NewClientState( - suite.parentChain.ChainID, tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, - height, commitmenttypes.GetSDKSpecs(), UpgradePath, tmConfig.AllowUpdateAfterExpiry, tmConfig.AllowUpdateAfterMisbehaviour, - ) - suite.parentConsState = suite.parentChain.LastHeader.ConsensusState() - - // mocking the fact that child chain validators should be parent chain validators - // TODO: Fix testing suite so we can initialize both chains with the same validator set - valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) - - params := childtypes.DefaultParams() - params.Enabled = true - childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) - - // create the ccv path and set child's clientID to genesis client - path := ibctesting.NewPath(suite.childChain, suite.parentChain) - path.EndpointA.ChannelConfig.PortID = childtypes.PortID - path.EndpointB.ChannelConfig.PortID = parenttypes.PortID - path.EndpointA.ChannelConfig.Version = ccv.Version - path.EndpointB.ChannelConfig.Version = ccv.Version - path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED - path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) - if !ok { - panic("must already have parent client on child chain") - } - // set child endpoint's clientID - path.EndpointA.ClientID = parentClient - - // TODO: No idea why or how this works, but it seems that it needs to be done. - path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) - path.EndpointA.Chain.SenderAccount.SetAccountNumber(6) - - // create child client on parent chain and set as child client for child chainID in parent keeper. - path.EndpointB.CreateClient() - suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, path.EndpointB.ClientID) - - suite.coordinator.CreateConnections(path) - - suite.ctx = suite.childChain.GetContext() - - suite.path = path -} - -func (suite *ChildTestSuite) TestOnChanOpenInit() { - channelID := "channel-1" - testCases := []struct { - name string - setup func(suite *ChildTestSuite) - expError bool - }{ - { - name: "success", - setup: func(suite *ChildTestSuite) { - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: false, - }, - { - name: "invalid: parent channel already established", - setup: func(suite *ChildTestSuite) { - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: true, - }, - { - name: "invalid: UNORDERED channel", - setup: func(suite *ChildTestSuite) { - // set path ORDER to UNORDERED - suite.path.EndpointA.ChannelConfig.Order = channeltypes.UNORDERED - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.UNORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: true, - }, - { - name: "invalid: incorrect port", - setup: func(suite *ChildTestSuite) { - // set path port to invalid portID - suite.path.EndpointA.ChannelConfig.PortID = "invalidPort" - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.UNORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: true, - }, - { - name: "invalid: incorrect version", - setup: func(suite *ChildTestSuite) { - // set path port to invalid version - suite.path.EndpointA.ChannelConfig.Version = "invalidVersion" - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.UNORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: true, - }, - { - name: "invalid: verify parent chain failed", - setup: func(suite *ChildTestSuite) { - // setup a new path with parent client on child chain being different from genesis client - path := ibctesting.NewPath(suite.childChain, suite.parentChain) - path.EndpointA.ChannelConfig.PortID = childtypes.PortID - path.EndpointB.ChannelConfig.PortID = parenttypes.PortID - path.EndpointA.ChannelConfig.Version = ccv.Version - path.EndpointB.ChannelConfig.Version = ccv.Version - path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED - path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - - // create child client on parent chain, and parent client on child chain - path.EndpointB.CreateClient() - path.EndpointA.CreateClient() - - suite.coordinator.CreateConnections(path) - suite.path = path - - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: true, - }, - } - - for _, tc := range testCases { - tc := tc - suite.Run(fmt.Sprintf("Case: %s", tc.name), func() { - suite.SetupTest() // reset suite - tc.setup(suite) - - childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) - chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) - suite.Require().NoError(err) - - err = childModule.OnChanOpenInit(suite.ctx, suite.path.EndpointA.ChannelConfig.Order, []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.PortID, - suite.path.EndpointA.ChannelID, chanCap, channeltypes.NewCounterparty(parenttypes.PortID, ""), suite.path.EndpointA.ChannelConfig.Version) - - if tc.expError { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - } - }) - } -} - -func (suite *ChildTestSuite) TestOnChanOpenTry() { - // OnOpenTry must error even with correct arguments - childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) - chanCap, err := suite.childChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(childtypes.PortID, suite.path.EndpointA.ChannelID)) - suite.Require().NoError(err) - - _, err = childModule.OnChanOpenTry(suite.ctx, channeltypes.ORDERED, []string{"connection-1"}, childtypes.PortID, "channel-1", chanCap, channeltypes.NewCounterparty(parenttypes.PortID, "channel-1"), ccv.Version) - suite.Require().Error(err, "OnChanOpenTry callback must error on child chain") -} - -func (suite *ChildTestSuite) TestOnChanOpenAck() { - channelID := "channel-1" - testCases := []struct { - name string - setup func(suite *ChildTestSuite) - expError bool - }{ - { - name: "success", - setup: func(suite *ChildTestSuite) { - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: false, - }, - { - name: "invalid: parent channel already established", - setup: func(suite *ChildTestSuite) { - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channel-2") - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: true, - }, - { - name: "invalid: mismatched versions", - setup: func(suite *ChildTestSuite) { - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - // set parent version to invalid version - suite.path.EndpointB.ChannelConfig.Version = "invalidVersion" - }, - expError: true, - }, - } - - for _, tc := range testCases { - tc := tc - suite.Run(fmt.Sprintf("Case: %s", tc.name), func() { - suite.SetupTest() // reset suite - tc.setup(suite) - - childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) - - md := parenttypes.HandshakeMetadata{ - ProviderFeePoolAddr: "", // dummy address used - Version: suite.path.EndpointB.ChannelConfig.Version, - } - mdBz, err := (&md).Marshal() - suite.Require().NoError(err) - - err = childModule.OnChanOpenAck(suite.ctx, childtypes.PortID, channelID, string(mdBz)) - if tc.expError { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - } - }) - } -} - -func (suite *ChildTestSuite) TestOnChanOpenConfirm() { - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, "channel-1", - channeltypes.NewChannel( - channeltypes.TRYOPEN, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, "channel-1"), - []string{"connection-1"}, ccv.Version, - )) - - childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) - - err := childModule.OnChanOpenConfirm(suite.ctx, childtypes.PortID, "channel-1") - suite.Require().Error(err, "OnChanOpenConfirm must always fail") -} - -func (suite *ChildTestSuite) TestOnChanCloseInit() { - channelID := "channel-1" - testCases := []struct { - name string - setup func(suite *ChildTestSuite) - expError bool - }{ - { - name: "can close duplicate in-progress channel once parent channel is established", - setup: func(suite *ChildTestSuite) { - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") - }, - expError: false, - }, - { - name: "can close duplicate open channel once parent channel is established", - setup: func(suite *ChildTestSuite) { - // create open channel - suite.coordinator.CreateChannels(suite.path) - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "different-channel") - }, - expError: false, - }, - { - name: "cannot close in-progress channel, no established channel yet", - setup: func(suite *ChildTestSuite) { - // Set INIT channel on child chain - suite.childChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, childtypes.PortID, channelID, - channeltypes.NewChannel( - channeltypes.INIT, channeltypes.ORDERED, channeltypes.NewCounterparty(parenttypes.PortID, ""), - []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), - ) - suite.path.EndpointA.ChannelID = channelID - }, - expError: true, - }, - { - name: "cannot close parent channel", - setup: func(suite *ChildTestSuite) { - // create open channel - suite.coordinator.CreateChannels(suite.path) - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, suite.path.EndpointA.ChannelID) - }, - expError: true, - }, - } - - for _, tc := range testCases { - tc := tc - suite.Run(fmt.Sprintf("Case: %s", tc.name), func() { - suite.SetupTest() // reset suite - tc.setup(suite) - - childModule := child.NewAppModule(suite.childChain.App.(*appConsumer.App).ChildKeeper) - - err := childModule.OnChanCloseInit(suite.ctx, childtypes.PortID, suite.path.EndpointA.ChannelID) - - if tc.expError { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - } - }) - } -} - -func TestChildTestSuite(t *testing.T) { - suite.Run(t, new(ChildTestSuite)) -} diff --git a/x/ccv/parent/keeper/genesis_test.go b/x/ccv/parent/keeper/genesis_test.go deleted file mode 100644 index 43669b3cf6..0000000000 --- a/x/ccv/parent/keeper/genesis_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package keeper_test - -import ( - "fmt" - - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" - "github.com/cosmos/interchain-security/x/ccv/types" -) - -func (suite *KeeperTestSuite) TestGenesis() { - // set some chain-channel pairs before exporting - ctx := suite.parentChain.GetContext() - for i := 0; i < 4; i++ { - suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChainToChannel(ctx, fmt.Sprintf("chainid-%d", i), fmt.Sprintf("channelid-%d", i)) - suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChannelToChain(ctx, fmt.Sprintf("channelid-%d", i), fmt.Sprintf("chainid-%d", i)) - suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChannelStatus(ctx, fmt.Sprintf("channelid-%d", i), types.Status(i)) - } - - genState := suite.parentChain.App.(*appProvider.App).ParentKeeper.ExportGenesis(suite.parentChain.GetContext()) - - suite.childChain.App.(*appConsumer.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) - - ctx = suite.childChain.GetContext() - for i := 0; i < 4; i++ { - expectedChainId := fmt.Sprintf("chainid-%d", i) - expectedChannelId := fmt.Sprintf("channelid-%d", i) - channelID, channelOk := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) - chainID, chainOk := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) - suite.Require().True(channelOk) - suite.Require().True(chainOk) - suite.Require().Equal(expectedChainId, chainID, "did not store correct chain id for given channel id") - suite.Require().Equal(expectedChannelId, channelID, "did not store correct channel id for given chain id") - - status := suite.childChain.App.(*appConsumer.App).ParentKeeper.GetChannelStatus(ctx, channelID) - suite.Require().Equal(types.Status(i), status, "status is unexpected for given channel id: %s", channelID) - } -} diff --git a/x/ccv/parent/keeper/keeper_test.go b/x/ccv/parent/keeper/keeper_test.go deleted file mode 100644 index 4a479ca9d6..0000000000 --- a/x/ccv/parent/keeper/keeper_test.go +++ /dev/null @@ -1,202 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - - clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" - ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - ibctesting "github.com/cosmos/ibc-go/v3/testing" - - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" - "github.com/cosmos/interchain-security/testutil/simapp" - childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" - parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" - "github.com/cosmos/interchain-security/x/ccv/types" - - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/stretchr/testify/suite" -) - -type KeeperTestSuite struct { - suite.Suite - - coordinator *ibctesting.Coordinator - - // testing chains - parentChain *ibctesting.TestChain - childChain *ibctesting.TestChain - - parentClient *ibctmtypes.ClientState - parentConsState *ibctmtypes.ConsensusState - - path *ibctesting.Path - - ctx sdk.Context -} - -func (suite *KeeperTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.parentChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.childChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) - suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) - - tmConfig := ibctesting.NewTendermintConfig() - - // commit a block on parent chain before creating client - suite.coordinator.CommitBlock(suite.parentChain) - - // create client and consensus state of parent chain to initialize child chain genesis. - height := suite.parentChain.LastHeader.GetHeight().(clienttypes.Height) - UpgradePath := []string{"upgrade", "upgradedIBCState"} - - suite.parentClient = ibctmtypes.NewClientState( - suite.parentChain.ChainID, tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, - height, commitmenttypes.GetSDKSpecs(), UpgradePath, tmConfig.AllowUpdateAfterExpiry, tmConfig.AllowUpdateAfterMisbehaviour, - ) - suite.parentConsState = suite.parentChain.LastHeader.ConsensusState() - - valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) - - params := childtypes.DefaultParams() - params.Enabled = true - childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) - - suite.ctx = suite.parentChain.GetContext() - - suite.path = ibctesting.NewPath(suite.childChain, suite.parentChain) - suite.path.EndpointA.ChannelConfig.PortID = childtypes.PortID - suite.path.EndpointB.ChannelConfig.PortID = parenttypes.PortID - suite.path.EndpointA.ChannelConfig.Version = types.Version - suite.path.EndpointB.ChannelConfig.Version = types.Version - suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED - suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) - if !ok { - panic("must already have parent client on child chain") - } - // set child endpoint's clientID - suite.path.EndpointA.ClientID = parentClient - - // TODO: No idea why or how this works, but it seems that it needs to be done. - suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) - suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(6) - - // create child client on parent chain and set as child client for child chainID in parent keeper. - suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) -} - -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) -} - -func (suite *KeeperTestSuite) TestValsetUpdateBlockHeight() { - app := suite.parentChain.App.(*appProvider.App) - ctx := suite.ctx - - blockHeight := app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(0)) - suite.Require().Zero(blockHeight) - - app.ParentKeeper.SetValsetUpdateBlockHeight(ctx, uint64(1), uint64(2)) - blockHeight = app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(1)) - suite.Require().Equal(blockHeight, uint64(2)) - - app.ParentKeeper.DeleteValsetUpdateBlockHeight(ctx, uint64(1)) - blockHeight = app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(1)) - suite.Require().Zero(blockHeight) - - app.ParentKeeper.SetValsetUpdateBlockHeight(ctx, uint64(1), uint64(2)) - app.ParentKeeper.SetValsetUpdateBlockHeight(ctx, uint64(3), uint64(4)) - blockHeight = app.ParentKeeper.GetValsetUpdateBlockHeight(ctx, uint64(3)) - suite.Require().Equal(blockHeight, uint64(4)) -} - -func (suite *KeeperTestSuite) TestSlashAcks() { - app := suite.parentChain.App.(*appProvider.App) - ctx := suite.ctx - - var chainsAcks [][]string - - penaltiesfN := func() (penalties []string) { - app.ParentKeeper.IterateSlashAcks(ctx, func(id string, acks []string) bool { - chainsAcks = append(chainsAcks, acks) - return true - }) - return - } - - chainID := "consumer" - - acks := app.ParentKeeper.GetSlashAcks(ctx, chainID) - suite.Require().Nil(acks) - - p := []string{"alice", "bob", "charlie"} - app.ParentKeeper.SetSlashAcks(ctx, chainID, p) - - acks = app.ParentKeeper.GetSlashAcks(ctx, chainID) - suite.Require().NotNil(acks) - - suite.Require().Len(acks, 3) - emptied := app.ParentKeeper.EmptySlashAcks(ctx, chainID) - suite.Require().Len(emptied, 3) - - acks = app.ParentKeeper.GetSlashAcks(ctx, chainID) - suite.Require().Nil(acks) - - chains := []string{"c1", "c2", "c3"} - - for _, c := range chains { - app.ParentKeeper.SetSlashAcks(ctx, c, p) - } - - penaltiesfN() - suite.Require().Len(chainsAcks, len(chains)) -} - -func (suite *KeeperTestSuite) TestAppendslashingAck() { - app := suite.parentChain.App.(*appProvider.App) - ctx := suite.ctx - - p := []string{"alice", "bob", "charlie"} - chains := []string{"c1", "c2"} - app.ParentKeeper.SetSlashAcks(ctx, chains[0], p) - - app.ParentKeeper.AppendslashingAck(ctx, chains[0], p[0]) - acks := app.ParentKeeper.GetSlashAcks(ctx, chains[0]) - suite.Require().NotNil(acks) - suite.Require().Len(acks, len(p)+1) - - app.ParentKeeper.AppendslashingAck(ctx, chains[1], p[0]) - acks = app.ParentKeeper.GetSlashAcks(ctx, chains[1]) - suite.Require().NotNil(acks) - suite.Require().Len(acks, 1) -} - -func (suite *KeeperTestSuite) TestInitHeight() { - app := suite.parentChain.App.(*appProvider.App) - ctx := suite.ctx - - tc := []struct { - chainID string - expected uint64 - }{ - {expected: 0, chainID: "chain"}, - {expected: 10, chainID: "chain1"}, - {expected: 12, chainID: "chain2"}, - } - - app.ParentKeeper.SetInitChainHeight(ctx, tc[1].chainID, tc[1].expected) - app.ParentKeeper.SetInitChainHeight(ctx, tc[2].chainID, tc[2].expected) - - for _, t := range tc { - height := app.ParentKeeper.GetInitChainHeight(ctx, t.chainID) - suite.Require().EqualValues(t.expected, height) - } -} diff --git a/x/ccv/parent/keeper/proposal_test.go b/x/ccv/parent/keeper/proposal_test.go deleted file mode 100644 index 4105fd7ea8..0000000000 --- a/x/ccv/parent/keeper/proposal_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package keeper_test - -import ( - "encoding/json" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - - clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - appProvider "github.com/cosmos/interchain-security/app_provider" - childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" - "github.com/cosmos/interchain-security/x/ccv/parent/types" - abci "github.com/tendermint/tendermint/abci/types" - crypto "github.com/tendermint/tendermint/proto/tendermint/crypto" -) - -func (suite *KeeperTestSuite) TestMakeChildGenesis() { - var ctx sdk.Context - suite.SetupTest() - ctx = suite.parentChain.GetContext().WithBlockTime(time.Now()) - - actualGenesis, err := suite.parentChain.App.(*appProvider.App).ParentKeeper.MakeChildGenesis(ctx) - suite.Require().NoError(err) - - jsonString := `{"params":{"Enabled":true},"new_chain":true,"parent_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"parent_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` - - var expectedGenesis childtypes.GenesisState - json.Unmarshal([]byte(jsonString), &expectedGenesis) - - // Zero out differing fields- TODO: figure out how to get the test suite to - // keep these deterministic - actualGenesis.ParentConsensusState.NextValidatorsHash = []byte{} - expectedGenesis.ParentConsensusState.NextValidatorsHash = []byte{} - - // set valset to one empty validator because SetupTest() creates 4 validators per chain - actualGenesis.InitialValSet = []abci.ValidatorUpdate{{PubKey: crypto.PublicKey{}, Power: actualGenesis.InitialValSet[0].Power}} - expectedGenesis.InitialValSet[0].PubKey = crypto.PublicKey{} - - actualGenesis.ParentConsensusState.Root.Hash = []byte{} - expectedGenesis.ParentConsensusState.Root.Hash = []byte{} - - suite.Require().Equal(actualGenesis, expectedGenesis, "child chain genesis created incorrectly") -} - -func (suite *KeeperTestSuite) TestCreateChildChainProposal() { - var ( - ctx sdk.Context - proposal *types.CreateChildChainProposal - ok bool - ) - - chainID := "chainID" - initialHeight := clienttypes.NewHeight(2, 3) - - testCases := []struct { - name string - malleate func(*KeeperTestSuite) - expPass bool - spawnReached bool - }{ - { - "valid create child chain proposal: spawn time reached", func(suite *KeeperTestSuite) { - // ctx blocktime is after proposal's spawn time - ctx = suite.parentChain.GetContext().WithBlockTime(time.Now().Add(time.Hour)) - content, err := types.NewCreateChildChainProposal("title", "description", chainID, initialHeight, []byte("gen_hash"), []byte("bin_hash"), time.Now()) - suite.Require().NoError(err) - proposal, ok = content.(*types.CreateChildChainProposal) - suite.Require().True(ok) - }, true, true, - }, - { - "valid proposal: spawn time has not yet been reached", func(suite *KeeperTestSuite) { - // ctx blocktime is before proposal's spawn time - ctx = suite.parentChain.GetContext().WithBlockTime(time.Now()) - content, err := types.NewCreateChildChainProposal("title", "description", chainID, initialHeight, []byte("gen_hash"), []byte("bin_hash"), time.Now().Add(time.Hour)) - suite.Require().NoError(err) - proposal, ok = content.(*types.CreateChildChainProposal) - suite.Require().True(ok) - }, true, false, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() - - tc.malleate(suite) - - err := suite.parentChain.App.(*appProvider.App).ParentKeeper.CreateChildChainProposal(ctx, proposal) - if tc.expPass { - suite.Require().NoError(err, "error returned on valid case") - if tc.spawnReached { - clientId := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetChildClient(ctx, chainID) - childGenesis, ok := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetChildGenesis(ctx, chainID) - suite.Require().True(ok) - - expectedGenesis, err := suite.parentChain.App.(*appProvider.App).ParentKeeper.MakeChildGenesis(ctx) - suite.Require().NoError(err) - - suite.Require().Equal(expectedGenesis, childGenesis) - suite.Require().NotEqual("", clientId, "child client was not created after spawn time reached") - } else { - gotHeight := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetPendingClientInfo(ctx, proposal.SpawnTime, chainID) - suite.Require().Equal(initialHeight, gotHeight, "pending client not equal to clientstate in proposal") - } - } else { - suite.Require().Error(err, "did not return error on invalid case") - } - }) - } -} From 398ac1a537f6c4291df3b777fb631696250cab68 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 May 2022 13:15:02 +0100 Subject: [PATCH 16/23] (nobuild) partially complete name changes --- app_provider/app.go | 124 +++++++++++------------ testutil/simapp/simapp.go | 10 +- x/ccv/consumer/keeper/genesis_test.go | 2 +- x/ccv/consumer/keeper/keeper_test.go | 98 +++++++++--------- x/ccv/consumer/keeper/params_test.go | 2 +- x/ccv/consumer/keeper/relay_test.go | 39 ++++--- x/ccv/consumer/keeper/validators_test.go | 4 +- x/ccv/consumer/module_test.go | 10 +- x/ccv/provider/keeper/keeper_test.go | 10 +- x/ccv/provider/keeper/params_test.go | 8 +- x/ccv/provider/keeper/proposal_test.go | 2 +- x/ccv/provider/proposal_handler_test.go | 6 +- x/ccv/provider/provider_test.go | 86 ++++++++-------- x/ccv/provider/unbonding_hook_test.go | 21 ++-- 14 files changed, 205 insertions(+), 217 deletions(-) diff --git a/app_provider/app.go b/app_provider/app.go index db9afed14c..55e5304a6d 100644 --- a/app_provider/app.go +++ b/app_provider/app.go @@ -102,13 +102,13 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" - ibcchild "github.com/cosmos/interchain-security/x/ccv/child" - ibcchildkeeper "github.com/cosmos/interchain-security/x/ccv/child/keeper" - ibcchildtypes "github.com/cosmos/interchain-security/x/ccv/child/types" - ibcparent "github.com/cosmos/interchain-security/x/ccv/parent" - ibcparentclient "github.com/cosmos/interchain-security/x/ccv/parent/client" - ibcparentkeeper "github.com/cosmos/interchain-security/x/ccv/parent/keeper" - ibcparenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" + ibcconsumer "github.com/cosmos/interchain-security/x/ccv/consumer" + ibcconsumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper" + ibcconsumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" + ibcprovider "github.com/cosmos/interchain-security/x/ccv/provider" + ibcproviderclient "github.com/cosmos/interchain-security/x/ccv/provider/client" + ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" + ibcprovidertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" "github.com/tendermint/spm/cosmoscmd" @@ -133,7 +133,7 @@ func getGovProposalHandlers() []govclient.ProposalHandler { distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, - ibcparentclient.ProposalHandler, + ibcproviderclient.ProposalHandler, // this line is used by starport scaffolding # stargate/app/govProposalHandler ) @@ -162,7 +162,7 @@ var ( upgradeclient.CancelProposalHandler, ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler, - ibcparentclient.ProposalHandler, + ibcproviderclient.ProposalHandler, ), params.AppModuleBasic{}, crisis.AppModuleBasic{}, @@ -176,22 +176,22 @@ var ( vesting.AppModuleBasic{}, liquidity.AppModuleBasic{}, //router.AppModuleBasic{}, - ibcchild.AppModuleBasic{}, - ibcparent.AppModuleBasic{}, + ibcconsumer.AppModuleBasic{}, + ibcprovider.AppModuleBasic{}, ) // module account permissions maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - ibcchildtypes.ConsumerRedistributeName: nil, - ibcchildtypes.ConsumerToSendToProviderName: nil, - distrtypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + authtypes.FeeCollectorName: nil, + ibcconsumertypes.ConsumerRedistributeName: nil, + ibcconsumertypes.ConsumerToSendToProviderName: nil, + distrtypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, } ) @@ -228,7 +228,7 @@ type App struct { // nolint: golint // NOTE the distribution keeper should either be removed // from consumer chain or set to use an independant - // different fee-pool from the consumer chain ChildKeeper + // different fee-pool from the consumer chain ConsumerKeeper DistrKeeper distrkeeper.Keeper GovKeeper govkeeper.Keeper @@ -241,14 +241,14 @@ type App struct { // nolint: golint FeeGrantKeeper feegrantkeeper.Keeper AuthzKeeper authzkeeper.Keeper LiquidityKeeper liquiditykeeper.Keeper - ChildKeeper ibcchildkeeper.Keeper - ParentKeeper ibcparentkeeper.Keeper + ConsumerKeeper ibcconsumerkeeper.Keeper + ProviderKeeper ibcproviderkeeper.Keeper // make scoped keepers public for test purposes - ScopedIBCKeeper capabilitykeeper.ScopedKeeper - ScopedTransferKeeper capabilitykeeper.ScopedKeeper - ScopedIBCChildKeeper capabilitykeeper.ScopedKeeper - ScopedIBCParentKeeper capabilitykeeper.ScopedKeeper + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedIBCConsumerKeeper capabilitykeeper.ScopedKeeper + ScopedIBCProviderKeeper capabilitykeeper.ScopedKeeper // the module manager MM *module.Manager @@ -296,7 +296,7 @@ func New( govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, evidencetypes.StoreKey, liquiditytypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, - ibcchildtypes.StoreKey, ibcparenttypes.StoreKey, + ibcconsumertypes.StoreKey, ibcprovidertypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, stakingtypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -333,8 +333,8 @@ func New( ) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) - scopedIBCChildKeeper := app.CapabilityKeeper.ScopeToModule(ibcchildtypes.ModuleName) - scopedIBCParentKeeper := app.CapabilityKeeper.ScopeToModule(ibcparenttypes.ModuleName) + scopedIBCConsumerKeeper := app.CapabilityKeeper.ScopeToModule(ibcconsumertypes.ModuleName) + scopedIBCProviderKeeper := app.CapabilityKeeper.ScopeToModule(ibcprovidertypes.ModuleName) app.CapabilityKeeper.Seal() // add keepers @@ -431,7 +431,7 @@ func New( stakingtypes.NewMultiStakingHooks( app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks(), - app.ParentKeeper.Hooks(), + app.ProviderKeeper.Hooks(), ), ) @@ -444,12 +444,12 @@ func New( scopedIBCKeeper, ) - // Create CCV child and parent keepers and modules - app.ChildKeeper = ibcchildkeeper.NewKeeper( + // Create CCV consumer and provider keepers and modules + app.ConsumerKeeper = ibcconsumerkeeper.NewKeeper( appCodec, - keys[ibcchildtypes.StoreKey], - app.GetSubspace(ibcchildtypes.ModuleName), - scopedIBCChildKeeper, + keys[ibcconsumertypes.StoreKey], + app.GetSubspace(ibcconsumertypes.ModuleName), + scopedIBCConsumerKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.IBCKeeper.ConnectionKeeper, @@ -462,11 +462,11 @@ func New( authtypes.FeeCollectorName, ) - app.ParentKeeper = ibcparentkeeper.NewKeeper( + app.ProviderKeeper = ibcproviderkeeper.NewKeeper( appCodec, - keys[ibcparenttypes.StoreKey], - app.GetSubspace(ibcparenttypes.ModuleName), - scopedIBCParentKeeper, + keys[ibcprovidertypes.StoreKey], + app.GetSubspace(ibcprovidertypes.ModuleName), + scopedIBCProviderKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.IBCKeeper.ConnectionKeeper, @@ -476,20 +476,20 @@ func New( app.AccountKeeper, authtypes.FeeCollectorName, ) - parentModule := ibcparent.NewAppModule(&app.ParentKeeper) + providerModule := ibcprovider.NewAppModule(&app.ProviderKeeper) - // child keeper satisfies the staking keeper interface + // consumer keeper satisfies the staking keeper interface // of the slashing module app.SlashingKeeper = slashingkeeper.NewKeeper( appCodec, keys[slashingtypes.StoreKey], - app.ChildKeeper, + app.ConsumerKeeper, app.GetSubspace(slashingtypes.ModuleName), ) - // register slashing module StakingHooks to the child keeper - app.ChildKeeper = *app.ChildKeeper.SetHooks(app.SlashingKeeper.Hooks()) - childModule := ibcchild.NewAppModule(app.ChildKeeper) + // register slashing module StakingHooks to the consumer keeper + app.ConsumerKeeper = *app.ConsumerKeeper.SetHooks(app.SlashingKeeper.Hooks()) + consumerModule := ibcconsumer.NewAppModule(app.ConsumerKeeper) // register the proposal types govRouter := govtypes.NewRouter() @@ -499,7 +499,7 @@ func New( AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). - AddRoute(ibcparenttypes.RouterKey, ibcparent.NewCreateChildChainHandler(app.ParentKeeper)). + AddRoute(ibcprovidertypes.RouterKey, ibcprovider.NewCreateConsumerChainHandler(app.ProviderKeeper)). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)) app.GovKeeper = govkeeper.NewKeeper( @@ -529,8 +529,8 @@ func New( // create static IBC router, add transfer route, then set and seal it ibcRouter := porttypes.NewRouter() ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule) - ibcRouter.AddRoute(ibcchildtypes.ModuleName, childModule) - ibcRouter.AddRoute(ibcparenttypes.ModuleName, parentModule) + ibcRouter.AddRoute(ibcconsumertypes.ModuleName, consumerModule) + ibcRouter.AddRoute(ibcprovidertypes.ModuleName, providerModule) app.IBCKeeper.SetRouter(ibcRouter) // create evidence keeper with router @@ -572,8 +572,8 @@ func New( params.NewAppModule(app.ParamsKeeper), liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper), transferModule, - childModule, - parentModule, + consumerModule, + providerModule, ) // During begin block slashing happens after distr.BeginBlocker so that @@ -602,8 +602,8 @@ func New( feegrant.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, - ibcchildtypes.ModuleName, - ibcparenttypes.ModuleName, + ibcconsumertypes.ModuleName, + ibcprovidertypes.ModuleName, ) app.MM.SetOrderEndBlockers( crisistypes.ModuleName, @@ -625,8 +625,8 @@ func New( paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - ibcchildtypes.ModuleName, - ibcparenttypes.ModuleName, + ibcconsumertypes.ModuleName, + ibcprovidertypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -655,8 +655,8 @@ func New( paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - ibcchildtypes.ModuleName, - ibcparenttypes.ModuleName, + ibcconsumertypes.ModuleName, + ibcprovidertypes.ModuleName, ) app.MM.RegisterInvariants(&app.CrisisKeeper) @@ -752,8 +752,8 @@ func New( app.ScopedIBCKeeper = scopedIBCKeeper app.ScopedTransferKeeper = scopedTransferKeeper - app.ScopedIBCChildKeeper = scopedIBCChildKeeper - app.ScopedIBCParentKeeper = scopedIBCParentKeeper + app.ScopedIBCConsumerKeeper = scopedIBCConsumerKeeper + app.ScopedIBCProviderKeeper = scopedIBCProviderKeeper return app } @@ -947,8 +947,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(liquiditytypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) - paramsKeeper.Subspace(ibcparenttypes.ModuleName) - paramsKeeper.Subspace(ibcchildtypes.ModuleName) + paramsKeeper.Subspace(ibcprovidertypes.ModuleName) + paramsKeeper.Subspace(ibcconsumertypes.ModuleName) return paramsKeeper } diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index c454064a4b..7d05cdeb3a 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -65,14 +65,14 @@ func NewBasicCoordinator(t *testing.T) *ibctesting.Coordinator { } // NewCoordinator initializes Coordinator with 0 TestChains -func NewParentChildCoordinator(t *testing.T) (*ibctesting.Coordinator, *ibctesting.TestChain, *ibctesting.TestChain) { +func NewProviderConsumerCoordinator(t *testing.T) (*ibctesting.Coordinator, *ibctesting.TestChain, *ibctesting.TestChain) { coordinator := NewBasicCoordinator(t) chainID := ibctesting.GetChainID(0) coordinator.Chains[chainID] = ibctesting.NewTestChain(t, coordinator, SetupTestingappProvider, chainID) - parentChain := coordinator.GetChain(chainID) + providerChain := coordinator.GetChain(chainID) chainID = ibctesting.GetChainID(1) coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(t, coordinator, - SetupTestingappConsumer, chainID, parentChain.Vals, parentChain.Signers) - childChain := coordinator.GetChain(chainID) - return coordinator, parentChain, childChain + SetupTestingappConsumer, chainID, providerChain.Vals, providerChain.Signers) + consumerChain := coordinator.GetChain(chainID) + return coordinator, providerChain, consumerChain } diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index 8ace52e172..68d552804b 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -7,7 +7,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - "github.com/cosmos/interchain-security/app" + app "github.com/cosmos/interchain-security/app_consumer" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" "github.com/cosmos/interchain-security/x/ccv/types" diff --git a/x/ccv/consumer/keeper/keeper_test.go b/x/ccv/consumer/keeper/keeper_test.go index 8aabb0531e..9c0c7be5d4 100644 --- a/x/ccv/consumer/keeper/keeper_test.go +++ b/x/ccv/consumer/keeper/keeper_test.go @@ -42,7 +42,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) + suite.coordinator, suite.providerChain, suite.consumerChain = simapp.NewProviderConsumerCoordinator(suite.T()) tmConfig := ibctesting.NewTendermintConfig() @@ -63,8 +63,8 @@ func (suite *KeeperTestSuite) SetupTest() { params := consumertypes.DefaultParams() params.Enabled = true - childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + consumerGenesis := types.NewInitialGenesisState(suite.providerClient, suite.providerConsState, valUpdates, params) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), consumerGenesis) suite.ctx = suite.consumerChain.GetContext() @@ -75,7 +75,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = ccv.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.ctx) + providerClient, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClient(suite.ctx) if !ok { panic("must already have provider client on consumer chain") } @@ -88,7 +88,7 @@ func (suite *KeeperTestSuite) SetupTest() { // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) + suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetConsumerClient(suite.providerChain.GetContext(), suite.consumerChain.ChainID, suite.path.EndpointB.ClientID) } func (suite *KeeperTestSuite) SetupCCVChannel() { @@ -96,19 +96,19 @@ func (suite *KeeperTestSuite) SetupCCVChannel() { suite.coordinator.CreateChannels(suite.path) } -func (suite *KeeperTestSuite) TestParentClient() { - parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.ctx) +func (suite *KeeperTestSuite) TestproviderClient() { + providerClient, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClient(suite.ctx) suite.Require().True(ok) clientState, ok := suite.consumerChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, providerClient) suite.Require().Equal(suite.providerClient, clientState, "stored client state does not match genesis provider client") } -func (suite *KeeperTestSuite) TestParentChannel() { - _, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) +func (suite *KeeperTestSuite) TestProviderChannel() { + _, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderChannel(suite.ctx) suite.Require().False(ok) - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") - channelID, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "channelID") + channelID, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal("channelID", channelID) } @@ -134,34 +134,34 @@ func (suite *KeeperTestSuite) TestPendingChanges() { nil, ) - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) - gotPd, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetPendingChanges(suite.ctx, pd) + gotPd, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) suite.Require().Equal(&pd, gotPd, "packet data in store does not equal packet data set") - suite.childChain.App.(*appConsumer.App).ChildKeeper.DeletePendingChanges(suite.ctx) - gotPd, ok = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.DeletePendingChanges(suite.ctx) + gotPd, ok = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetPendingChanges(suite.ctx) suite.Require().False(ok) suite.Require().Nil(gotPd, "got non-nil pending changes after Delete") } func (suite *KeeperTestSuite) TestUnbondingTime() { - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetUnbondingTime(suite.ctx, 1, 10) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetUnbondingTime(suite.ctx, 2, 25) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetUnbondingTime(suite.ctx, 5, 15) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetUnbondingTime(suite.ctx, 6, 40) - suite.childChain.App.(*appConsumer.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.DeleteUnbondingTime(suite.ctx, 6) - suite.Require().Equal(uint64(10), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) - suite.Require().Equal(uint64(25), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) - suite.Require().Equal(uint64(15), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) + suite.Require().Equal(uint64(10), suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 1)) + suite.Require().Equal(uint64(25), suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 2)) + suite.Require().Equal(uint64(15), suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 5)) + suite.Require().Equal(uint64(0), suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 3)) + suite.Require().Equal(uint64(0), suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 6)) orderedTimes := [][]uint64{{1, 10}, {2, 25}, {5, 15}} i := 0 - suite.childChain.App.(*appConsumer.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { // require that we iterate through unbonding time in order of sequence suite.Require().Equal(orderedTimes[i][0], seq) suite.Require().Equal(orderedTimes[i][1], time) @@ -193,22 +193,22 @@ func (suite *KeeperTestSuite) TestUnbondingPacket() { ) packet := channeltypes.NewPacket(pd.GetBytes(), uint64(i), "provider", "channel-1", "consumer", "channel-1", clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) } // ensure that packets are iterated by sequence i := 0 - suite.childChain.App.(*appConsumer.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { suite.Require().Equal(uint64(i), seq) - gotPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) + gotPacket, err := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, seq) suite.Require().NoError(err) suite.Require().Equal(&packet, gotPacket, "packet from get and iteration do not match") i++ return false }) - suite.childChain.App.(*appConsumer.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) - gotPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.DeleteUnbondingPacket(suite.ctx, 0) + gotPacket, err := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 0) suite.Require().Error(err) suite.Require().Nil(gotPacket, "packet is not nil after delete") } @@ -231,7 +231,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -247,7 +247,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to validating - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -262,7 +262,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID, "connection-2"} }, @@ -272,7 +272,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { name: "connection does not exist", setup: func(suite *KeeperTestSuite) { // set channel status to INITIALIZING - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{"connection-dne"} }, @@ -290,7 +290,7 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*appConsumer.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -305,8 +305,8 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() { tc.setup(suite) - // Verify ParentChain on child chain using path returned by setup - err := suite.childChain.App.(*appConsumer.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) + // Verify ProviderChain on consumer chain using path returned by setup + err := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.VerifyProviderChain(suite.ctx, channelID, connectionHops) if tc.expError { suite.Require().Error(err, "invalid case did not return error") @@ -325,7 +325,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { suite.SetupCCVChannel() suite.SendEmptyVSCPacket() - app, ctx := suite.childChain.App.(*appConsumer.App), suite.childChain.GetContext() + app, ctx := suite.consumerChain.App.(*appConsumer.App), suite.consumerChain.GetContext() channelID := suite.path.EndpointA.ChannelID // pick a cross-chain validator @@ -393,8 +393,8 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { suite.SetupCCVChannel() - app := suite.childChain.App.(*appConsumer.App) - ctx := suite.childChain.GetContext() + app := suite.consumerChain.App.(*appConsumer.App) + ctx := suite.consumerChain.GetContext() channelID := suite.path.EndpointA.ChannelID // check that CCV channel isn't established @@ -458,8 +458,8 @@ func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { } func (suite *KeeperTestSuite) TestCrossChainValidator() { - app := suite.childChain.App.(*appConsumer.App) - ctx := suite.childChain.GetContext() + app := suite.consumerChain.App.(*appConsumer.App) + ctx := suite.consumerChain.GetContext() // should return false ccVal, foud := app.ConsumerKeeper.GetCCValidator(ctx, ed25519.GenPrivKey().PubKey().Address()) @@ -485,8 +485,8 @@ func (suite *KeeperTestSuite) TestCrossChainValidator() { } func (suite *KeeperTestSuite) TestPendingSlashRequests() { - childKeeper := suite.childChain.App.(*appConsumer.App).ChildKeeper - ctx := suite.childChain.GetContext() + consumerKeeper := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper + ctx := suite.consumerChain.GetContext() // prepare test setup by storing 10 pending slash requests request := []types.SlashRequest{} @@ -522,8 +522,8 @@ func (suite *KeeperTestSuite) TestPendingSlashRequests() { // to ensure that the channel gets established func (suite *KeeperTestSuite) SendEmptyVSCPacket() { - childKeeper := suite.childChain.App.(*appConsumer.App).ChildKeeper - parentKeeper := suite.parentChain.App.(*appProvider.App).ParentKeeper + consumerKeeper := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper + providerKeeper := suite.providerChain.App.(*appProvider.App).ProviderKeeper oldBlockTime := suite.providerChain.GetContext().BlockTime() timeout := uint64(ccv.GetTimeoutTimestamp(oldBlockTime).UnixNano()) @@ -536,8 +536,8 @@ func (suite *KeeperTestSuite) SendEmptyVSCPacket() { nil, ) - seq, ok := suite.parentChain.App.(*appProvider.App).GetIBCKeeper().ChannelKeeper.GetNextSequenceSend( - suite.parentChain.GetContext(), parenttypes.PortID, suite.path.EndpointB.ChannelID) + seq, ok := suite.providerChain.App.(*appProvider.App).GetIBCKeeper().ChannelKeeper.GetNextSequenceSend( + suite.providerChain.GetContext(), providertypes.PortID, suite.path.EndpointB.ChannelID) suite.Require().True(ok) packet := channeltypes.NewPacket(pd.GetBytes(), seq, providertypes.PortID, suite.path.EndpointB.ChannelID, diff --git a/x/ccv/consumer/keeper/params_test.go b/x/ccv/consumer/keeper/params_test.go index dbbc9cf68b..742842435b 100644 --- a/x/ccv/consumer/keeper/params_test.go +++ b/x/ccv/consumer/keeper/params_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - "github.com/cosmos/interchain-security/app" + app "github.com/cosmos/interchain-security/app_consumer" "github.com/cosmos/interchain-security/x/ccv/consumer/types" ) diff --git a/x/ccv/consumer/keeper/relay_test.go b/x/ccv/consumer/keeper/relay_test.go index 493be74908..25fd5a109f 100644 --- a/x/ccv/consumer/keeper/relay_test.go +++ b/x/ccv/consumer/keeper/relay_test.go @@ -9,7 +9,6 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" appConsumer "github.com/cosmos/interchain-security/app_consumer" - childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -118,22 +117,22 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } for _, tc := range testCases { - ack := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) + ack := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) if tc.expErrorAck { suite.Require().NotNil(ack, "invalid test case: %s did not return ack", tc.name) suite.Require().False(ack.Success(), "invalid test case: %s did not return an Error Acknowledgment") } else { suite.Require().Nil(ack, "successful packet must send ack asynchronously. case: %s", tc.name) - suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*appConsumer.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), + suite.Require().Equal(ccv.VALIDATING, suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), "channel status is not valdidating after receive packet for valid test case: %s", tc.name) - parentChannel, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentChannel(suite.ctx) + providerChannel, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal(tc.packet.DestinationChannel, providerChannel, "provider channel is not destination channel on successful receive for valid test case: %s", tc.name) // Check that pending changes are accumulated and stored correctly - actualPendingChanges, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetPendingChanges(suite.ctx) + actualPendingChanges, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) // Sort to avoid dumb inequalities sort.SliceStable(actualPendingChanges.ValidatorUpdates, func(i, j int) bool { @@ -144,10 +143,10 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { }) suite.Require().Equal(tc.expectedPendingChanges, *actualPendingChanges, "pending changes not equal to expected changes after successful packet receive. case: %s", tc.name) - expectedTime := uint64(suite.ctx.BlockTime().Add(childtypes.UnbondingTime).UnixNano()) - unbondingTime := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) + expectedTime := uint64(suite.ctx.BlockTime().Add(consumertypes.UnbondingTime).UnixNano()) + unbondingTime := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) suite.Require().Equal(expectedTime, unbondingTime, "unbonding time has unexpected value for case: %s", tc.name) - unbondingPacket, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) + unbondingPacket, err := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) suite.Require().NoError(err) suite.Require().Equal(&tc.packet, unbondingPacket, "packet is not added to unbonding queue after successful receive. case: %s", tc.name) } @@ -184,7 +183,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { // send first packet packet := channeltypes.NewPacket(pd.GetBytes(), 1, providertypes.PortID, suite.path.EndpointB.ChannelID, consumertypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - ack := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send second packet @@ -192,7 +191,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[0].Power = 15 packet.Data = pd.GetBytes() packet.Sequence = 2 - ack = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send third packet @@ -200,25 +199,25 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[1].Power = 40 packet.Data = pd.GetBytes() packet.Sequence = 3 - ack = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // move ctx time forward such that first two packets are unbonded but third is not. suite.ctx = suite.ctx.WithBlockTime(origTime.Add(consumertypes.UnbondingTime).Add(3 * time.Hour)) - suite.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(suite.ctx) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.UnbondMaturePackets(suite.ctx) // ensure first two packets are unbonded and acknowledgement is written // unbonded time is deleted - time1 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) - time2 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) + time1 := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 1) + time2 := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 2) suite.Require().Equal(uint64(0), time1, "unbonding time not deleted for mature packet 1") suite.Require().Equal(uint64(0), time2, "unbonding time not deleted for mature packet 2") // unbonded packets are deleted - _, err = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) + _, err = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 1) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") - _, err = suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) + _, err = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 2) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") expectedWriteAckBytes := channeltypes.CommitAcknowledgement(channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()) @@ -232,9 +231,9 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { suite.Require().Equal(expectedWriteAckBytes, ackBytes2, "did not write successful ack for matue packet 1") // ensure that third packet did not get ack written and is still in store - time3 := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) + time3 := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx, 3) suite.Require().True(time3 > uint64(suite.ctx.BlockTime().UnixNano()), "Unbonding time for packet 3 is not after current time") - packet3, err := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) + packet3, err := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 3) suite.Require().NoError(err, "retrieving unbonding packet 3 returned error") suite.Require().Equal(&packet, packet3, "unbonding packet 3 has unexpected value") @@ -255,12 +254,12 @@ func (suite *KeeperTestSuite) TestOnAcknowledgement() { ack := channeltypes.NewResultAcknowledgement([]byte{1}) // expect no error - err := suite.childChain.App.(*appConsumer.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.Nil(err) // expect an error ack = channeltypes.NewErrorAcknowledgement("error") - err = suite.childChain.App.(*appConsumer.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.NotNil(err) } diff --git a/x/ccv/consumer/keeper/validators_test.go b/x/ccv/consumer/keeper/validators_test.go index 6538f68aee..56721d59df 100644 --- a/x/ccv/consumer/keeper/validators_test.go +++ b/x/ccv/consumer/keeper/validators_test.go @@ -2,13 +2,13 @@ package keeper_test import ( appConsumer "github.com/cosmos/interchain-security/app_consumer" - "github.com/cosmos/interchain-security/x/ccv/child/types" + "github.com/cosmos/interchain-security/x/ccv/consumer/types" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (k KeeperTestSuite) TestApplyCCValidatorChanges() { - childKeeper := k.childChain.App.(*appConsumer.App).ChildKeeper + consumerKeeper := k.consumerChain.App.(*appConsumer.App).ConsumerKeeper ctx := k.ctx // utility functions diff --git a/x/ccv/consumer/module_test.go b/x/ccv/consumer/module_test.go index 9e32f2f92c..d3e15b281b 100644 --- a/x/ccv/consumer/module_test.go +++ b/x/ccv/consumer/module_test.go @@ -26,10 +26,6 @@ import ( "github.com/stretchr/testify/suite" ) -func init() { - ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp -} - type ConsumerTestSuite struct { suite.Suite @@ -37,7 +33,7 @@ type ConsumerTestSuite struct { // testing chains providerChain *ibctesting.TestChain - consumerChain *ibctesting.TestChain + consumerChain *ibctesting.TestChain providerClient *ibctmtypes.ClientState providerConsState *ibctmtypes.ConsensusState @@ -48,9 +44,7 @@ type ConsumerTestSuite struct { } func (suite *ConsumerTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.providerChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.consumerChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.coordinator, suite.providerChain, suite.consumerChain = simapp.NewProviderConsumerCoordinator(suite.T()) tmConfig := ibctesting.NewTendermintConfig() diff --git a/x/ccv/provider/keeper/keeper_test.go b/x/ccv/provider/keeper/keeper_test.go index 4ad12252ff..de09047d9e 100644 --- a/x/ccv/provider/keeper/keeper_test.go +++ b/x/ccv/provider/keeper/keeper_test.go @@ -22,10 +22,6 @@ import ( "github.com/stretchr/testify/suite" ) -func init() { - ibctesting.DefaultTestingAppInit = simapp.SetupTestingApp -} - type KeeperTestSuite struct { suite.Suite @@ -33,7 +29,7 @@ type KeeperTestSuite struct { // testing chains providerChain *ibctesting.TestChain - consumerChain *ibctesting.TestChain + consumerChain *ibctesting.TestChain providerClient *ibctmtypes.ClientState providerConsState *ibctmtypes.ConsensusState @@ -44,9 +40,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.providerChain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.consumerChain = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.coordinator, suite.providerChain, suite.consumerChain = simapp.NewProviderConsumerCoordinator(suite.T()) tmConfig := ibctesting.NewTendermintConfig() diff --git a/x/ccv/provider/keeper/params_test.go b/x/ccv/provider/keeper/params_test.go index ec0513fdf0..5e6da652b9 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -7,18 +7,18 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" appProvider "github.com/cosmos/interchain-security/app_provider" - "github.com/cosmos/interchain-security/x/ccv/parent/types" + "github.com/cosmos/interchain-security/x/ccv/provider/types" ) func (suite *KeeperTestSuite) TestParams() { expParams := types.DefaultParams() - params := suite.parentChain.App.(*appProvider.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) + params := suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetParams(suite.providerChain.GetContext()) suite.Require().Equal(expParams, params) newParams := types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false)) - suite.parentChain.App.(*appProvider.App).ParentKeeper.SetParams(suite.parentChain.GetContext(), newParams) - params = suite.parentChain.App.(*appProvider.App).ParentKeeper.GetParams(suite.parentChain.GetContext()) + suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetParams(suite.providerChain.GetContext(), newParams) + params = suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetParams(suite.providerChain.GetContext()) suite.Require().Equal(newParams, params) } diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index 20e8bf9c12..423a05e7ec 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -22,7 +22,7 @@ func (suite *KeeperTestSuite) TestMakeConsumerGenesis() { actualGenesis, err := suite.providerChain.App.(*app.App).ProviderKeeper.MakeConsumerGenesis(ctx) suite.Require().NoError(err) - jsonString := `{"params":{"Enabled":true, "BlocksPerDistributionTransmission":1000, "ConsumerRedistributeFrac":"0"},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` + jsonString := `{"params":{"Enabled":true, "BlocksPerDistributionTransmission":1000, "ConsumerRedistributeFrac":"0"},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"consumer_order":[0,1],"consumer_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"consumer_order":[0,1],"consumer_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` var expectedGenesis consumertypes.GenesisState json.Unmarshal([]byte(jsonString), &expectedGenesis) diff --git a/x/ccv/provider/proposal_handler_test.go b/x/ccv/provider/proposal_handler_test.go index 3a39ec3a97..67df960f93 100644 --- a/x/ccv/provider/proposal_handler_test.go +++ b/x/ccv/provider/proposal_handler_test.go @@ -9,8 +9,8 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" appProvider "github.com/cosmos/interchain-security/app_provider" - "github.com/cosmos/interchain-security/x/ccv/parent" - "github.com/cosmos/interchain-security/x/ccv/parent/types" + "github.com/cosmos/interchain-security/x/ccv/provider" + "github.com/cosmos/interchain-security/x/ccv/provider/types" ) func (suite *ProviderTestSuite) TestCreateConsumerChainProposalHandler() { @@ -56,7 +56,7 @@ func (suite *ProviderTestSuite) TestCreateConsumerChainProposalHandler() { tc.malleate(suite) - proposalHandler := parent.NewCreateChildChainHandler(suite.parentChain.App.(*appProvider.App).ParentKeeper) + proposalHandler := provider.NewCreateConsumerChainHandler(suite.providerChain.App.(*appProvider.App).ProviderKeeper) err = proposalHandler(ctx, content) diff --git a/x/ccv/provider/provider_test.go b/x/ccv/provider/provider_test.go index b36caabf06..01c5c3e59f 100644 --- a/x/ccv/provider/provider_test.go +++ b/x/ccv/provider/provider_test.go @@ -35,7 +35,7 @@ import ( "github.com/stretchr/testify/suite" ) -type ParentTestSuite struct { +type ProviderTestSuite struct { suite.Suite coordinator *ibctesting.Coordinator @@ -55,9 +55,9 @@ type ParentTestSuite struct { ctx sdk.Context } -func (suite *ParentTestSuite) SetupTest() { +func (suite *ProviderTestSuite) SetupTest() { - suite.coordinator, suite.parentChain, suite.childChain = simapp.NewParentChildCoordinator(suite.T()) + suite.coordinator, suite.providerChain, suite.consumerChain = simapp.NewProviderConsumerCoordinator(suite.T()) suite.DisableConsumerDistribution() @@ -85,8 +85,8 @@ func (suite *ParentTestSuite) SetupTest() { "", "0.5", // 50% ) - childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*appConsumer.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + consumerGenesis := consumertypes.NewInitialGenesisState(suite.providerClient, suite.providerConsState, valUpdates, params) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), consumerGenesis) suite.ctx = suite.providerChain.GetContext() @@ -97,7 +97,7 @@ func (suite *ParentTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*appConsumer.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + providerClient, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClient(suite.consumerChain.GetContext()) if !ok { panic("must already have provider client on consumer chain") } @@ -110,7 +110,7 @@ func (suite *ParentTestSuite) SetupTest() { // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. suite.path.EndpointB.CreateClient() - suite.parentChain.App.(*appProvider.App).ParentKeeper.SetChildClient(suite.parentChain.GetContext(), suite.childChain.ChainID, suite.path.EndpointB.ClientID) + suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetConsumerClient(suite.providerChain.GetContext(), suite.consumerChain.ChainID, suite.path.EndpointB.ClientID) suite.transferPath = ibctesting.NewPath(suite.consumerChain, suite.providerChain) suite.transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID @@ -134,8 +134,8 @@ func (suite *ProviderTestSuite) SetupCCVChannel() { suite.transferPath.EndpointB.ConnectionID = suite.path.EndpointB.ConnectionID // INIT step for transfer path has already been called during CCV channel setup - suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*appConsumer.App). - ChildKeeper.GetDistributionTransmissionChannel(suite.childChain.GetContext()) + suite.transferPath.EndpointA.ChannelID = suite.consumerChain.App.(*appConsumer.App). + ConsumerKeeper.GetDistributionTransmissionChannel(suite.consumerChain.GetContext()) // Complete TRY, ACK, CONFIRM for transfer path err := suite.transferPath.EndpointB.ChanOpenTry() @@ -151,8 +151,8 @@ func (suite *ProviderTestSuite) SetupCCVChannel() { suite.transferPath.EndpointA.UpdateClient() } -func TestParentTestSuite(t *testing.T) { - suite.Run(t, new(ParentTestSuite)) +func TestProviderTestSuite(t *testing.T) { + suite.Run(t, new(ProviderTestSuite)) } func (s *ProviderTestSuite) TestPacketRoundtrip() { @@ -177,7 +177,7 @@ func (s *ProviderTestSuite) TestPacketRoundtrip() { s.Require().NoError(err) // Save valset update ID to reconstruct packet - valUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valUpdateID := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetValidatorSetUpdateId(s.providerCtx()) // Send CCV packet to consumer s.providerChain.App.EndBlock(abci.RequestEndBlock{}) @@ -208,9 +208,9 @@ func (s *ProviderTestSuite) TestPacketRoundtrip() { s.providerChain.App.EndBlock(abci.RequestEndBlock{}) // - End consumer unbonding period - childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) - // TODO: why doesn't this work: s.childChain.App.EndBlock(abci.RequestEndBlock{}) - err = s.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(childCtx) + consumerCtx := s.consumerCtx().WithBlockTime(origTime.Add(consumertypes.UnbondingTime).Add(3 * time.Hour)) + // TODO: why doesn't this work: s.consumerChain.App.EndBlock(abci.RequestEndBlock{}) + err = s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.UnbondMaturePackets(consumerCtx) s.Require().NoError(err) // commit consumer chain and update provider chain client @@ -233,8 +233,8 @@ func (s *ProviderTestSuite) consumerCtx() sdk.Context { return s.consumerChain.GetContext() } -func (s *ParentTestSuite) parentBondDenom() string { - return s.parentChain.App.(*appProvider.App).StakingKeeper.BondDenom(s.parentCtx()) +func (s *ProviderTestSuite) providerBondDenom() string { + return s.providerChain.App.(*appProvider.App).StakingKeeper.BondDenom(s.providerCtx()) } // TestSendDowntimePacket tests consumer initiated slashing @@ -242,10 +242,10 @@ func (s *ProviderTestSuite) TestSendDowntimePacket() { s.SetupCCVChannel() validatorsPerChain := len(s.consumerChain.Vals.Validators) - parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper + providerStakingKeeper := s.providerChain.App.GetStakingKeeper() + providerSlashingKeeper := s.providerChain.App.(*appProvider.App).SlashingKeeper - childKeeper := s.childChain.App.(*appConsumer.App).ChildKeeper + consumerKeeper := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper // get a cross-chain validator address, pubkey and balance tmVals := s.consumerChain.Vals.Validators @@ -288,12 +288,12 @@ func (s *ProviderTestSuite) TestSendDowntimePacket() { s.Require().NoError(err) // Set outstanding slashing flag - s.childChain.App.(*appConsumer.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) + s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetOutstandingDowntime(s.consumerCtx(), consAddr) // save next VSC packet info oldBlockTime = s.providerCtx().BlockTime() timeout = uint64(types.GetTimeoutTimestamp(oldBlockTime).UnixNano()) - valsetUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valsetUpdateID := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetValidatorSetUpdateId(s.providerCtx()) // receive the downtime packet on the provider chain; // RecvPacket() calls the provider endblocker thus sends a VSC packet to the consumer @@ -351,8 +351,8 @@ func (s *ProviderTestSuite) TestSendDowntimePacket() { s.Require().True(found) s.Require().True(valSignInfo.JailedUntil.After(s.providerCtx().BlockHeader().Time)) - // check that the outstanding slashing flag is reset on the child - pFlag := s.childChain.App.(*appConsumer.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) + // check that the outstanding slashing flag is reset on the consumer + pFlag := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.OutstandingDowntime(s.consumerCtx(), consAddr) s.Require().False(pFlag) // check that slashing packet gets acknowledged @@ -375,9 +375,9 @@ func (s *ProviderTestSuite) getVal(index int) (validator stakingtypes.Validator, // TestHandleConsumerDowntime tests the slashing distribution func (s *ProviderTestSuite) TestHandleConsumerDowntime() { s.SetupCCVChannel() - parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper - parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper + providerStakingKeeper := s.providerChain.App.GetStakingKeeper() + providerSlashingKeeper := s.providerChain.App.(*appProvider.App).SlashingKeeper + providerKeeper := s.providerChain.App.(*appProvider.App).ProviderKeeper // bonded amount bondAmt := sdk.NewInt(1000000) @@ -483,11 +483,11 @@ func (s *ProviderTestSuite) TestHandleConsumerDowntime() { } } -func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { - parentStakingKeeper := s.parentChain.App.GetStakingKeeper() - parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper - parentSlashingKeeper := s.parentChain.App.(*appProvider.App).SlashingKeeper - childChainID := s.childChain.ChainID +func (s *ProviderTestSuite) TestHandleConsumerDowntimeErrors() { + providerStakingKeeper := s.providerChain.App.GetStakingKeeper() + providerKeeper := s.providerChain.App.(*appProvider.App).ProviderKeeper + providerSlashingKeeper := s.providerChain.App.(*appProvider.App).SlashingKeeper + consumerChainID := s.consumerChain.ChainID // expect an error if initial block height isn't set for consumer chain err := providerKeeper.HandleConsumerDowntime(s.providerCtx(), consumerChainID, types.SlashPacketData{}) @@ -554,9 +554,9 @@ func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { s.Require().NoError(err) } -func (s *ParentTestSuite) TestslashingPacketAcknowldgement() { - parentKeeper := s.parentChain.App.(*appProvider.App).ParentKeeper - childKeeper := s.childChain.App.(*appConsumer.App).ChildKeeper +func (s *ProviderTestSuite) TestslashingPacketAcknowldgement() { + providerKeeper := s.providerChain.App.(*appProvider.App).ProviderKeeper + consumerKeeper := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper packet := channeltypes.NewPacket([]byte{}, 1, consumertypes.PortID, s.path.EndpointA.ChannelID, providertypes.PortID, "wrongchannel", clienttypes.Height{}, 0) @@ -611,8 +611,8 @@ func (s *ProviderTestSuite) UpdateConsumerHistInfo(changes []abci.ValidatorUpdat s.consumerChain.App.GetStakingKeeper().SetHistoricalInfo(s.consumerCtx(), s.consumerCtx().BlockHeight(), &hi) } -func (s *ParentTestSuite) DisableConsumerDistribution() { - cChain := s.childChain +func (s *ProviderTestSuite) DisableConsumerDistribution() { + cChain := s.consumerChain cApp := cChain.App.(*appConsumer.App) for i, moduleName := range cApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { @@ -622,8 +622,8 @@ func (s *ParentTestSuite) DisableConsumerDistribution() { } } -func (s *ParentTestSuite) DisableProviderDistribution() { - pChain := s.parentChain +func (s *ProviderTestSuite) DisableProviderDistribution() { + pChain := s.providerChain pApp := pChain.App.(*appProvider.App) for i, moduleName := range pApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { @@ -634,8 +634,8 @@ func (s *ParentTestSuite) DisableProviderDistribution() { } } -func (s *ParentTestSuite) ReenableProviderDistribution() { - pChain := s.parentChain +func (s *ProviderTestSuite) ReenableProviderDistribution() { + pChain := s.providerChain pApp := pChain.App.(*appProvider.App) i := s.providerDistrIndex pApp.MM.OrderBeginBlockers = append( @@ -650,9 +650,9 @@ func (s *ProviderTestSuite) TestDistribution() { // NOTE s.transferPath.EndpointA == Consumer Chain // s.transferPath.EndpointB == Provider Chain - pChain, cChain := s.parentChain, s.childChain + pChain, cChain := s.providerChain, s.consumerChain pApp, cApp := pChain.App.(*appProvider.App), cChain.App.(*appConsumer.App) - cKeep := cApp.ChildKeeper + cKeep := cApp.ConsumerKeeper // Get the receiving fee pool on the provider chain fcAddr := pApp.ProviderKeeper.GetFeeCollectorAddressStr(pChain.GetContext()) diff --git a/x/ccv/provider/unbonding_hook_test.go b/x/ccv/provider/unbonding_hook_test.go index 8f5348c217..aabdbf4e07 100644 --- a/x/ccv/provider/unbonding_hook_test.go +++ b/x/ccv/provider/unbonding_hook_test.go @@ -6,6 +6,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" + providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" @@ -13,7 +15,6 @@ import ( appConsumer "github.com/cosmos/interchain-security/app_consumer" appProvider "github.com/cosmos/interchain-security/app_provider" - childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" "github.com/cosmos/interchain-security/x/ccv/types" abci "github.com/tendermint/tendermint/abci/types" @@ -159,8 +160,8 @@ func (s *ProviderTestSuite) TestStakingHooks1() { s.Require().True(getBalance(s, newProviderCtx, delAddr).Equal(initBalance.Sub(bondAmt.Quo(sdk.NewInt(2))))) } -func getBalance(s *ParentTestSuite, parentCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int { - return s.parentChain.App.(*appProvider.App).BankKeeper.GetBalance(parentCtx, delAddr, s.parentBondDenom()).Amount +func getBalance(s *ProviderTestSuite, providerCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int { + return s.providerChain.App.(*appProvider.App).BankKeeper.GetBalance(providerCtx, delAddr, s.providerBondDenom()).Amount } func doUnbonding(s *ProviderTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (initBalance sdk.Int, valsetUpdateId uint64) { @@ -186,7 +187,7 @@ func doUnbonding(s *ProviderTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) s.Require().True(getBalance(s, s.providerCtx(), delAddr).Equal(initBalance.Sub(bondAmt))) // save the current valset update ID - valsetUpdateID := s.parentChain.App.(*appProvider.App).ParentKeeper.GetValidatorSetUpdateId(s.parentCtx()) + valsetUpdateID := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetValidatorSetUpdateId(s.providerCtx()) return initBalance, valsetUpdateID } @@ -202,9 +203,9 @@ func endProviderUnbondingPeriod(s *ProviderTestSuite, origTime time.Time) sdk.Co func endConsumerUnbondingPeriod(s *ProviderTestSuite, origTime time.Time) { // - End consumer unbonding period - childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) - // s.childChain.App.EndBlock(abci.RequestEndBlock{}) // <- this doesn't work because we can't modify the ctx - err := s.childChain.App.(*appConsumer.App).ChildKeeper.UnbondMaturePackets(childCtx) + consumerCtx := s.consumerCtx().WithBlockTime(origTime.Add(consumertypes.UnbondingTime).Add(3 * time.Hour)) + // s.consumerChain.App.EndBlock(abci.RequestEndBlock{}) // <- this doesn't work because we can't modify the ctx + err := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.UnbondMaturePackets(consumerCtx) s.Require().NoError(err) } @@ -214,8 +215,8 @@ func checkStakingUnbondingOps(s *ProviderTestSuite, id uint64, found bool, onHol s.Require().True(onHold == stakingUnbondingOp.UnbondingOnHold) } -func checkCCVUnbondingOp(s *ParentTestSuite, parentCtx sdk.Context, chainID string, valUpdateID uint64, found bool) { - _, wasFound := s.parentChain.App.(*appProvider.App).ParentKeeper.GetUnbondingOpsFromIndex(parentCtx, chainID, valUpdateID) +func checkCCVUnbondingOp(s *ProviderTestSuite, providerCtx sdk.Context, chainID string, valUpdateID uint64, found bool) { + _, wasFound := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetUnbondingOpsFromIndex(providerCtx, chainID, valUpdateID) s.Require().True(found == wasFound) } @@ -258,7 +259,7 @@ func sendValUpdateAck(s *ProviderTestSuite, providerCtx sdk.Context, packet chan // err := s.path.EndpointB.AcknowledgePacket(packet, ack.Acknowledgement()) // s.Require().NoError(err) - err := s.parentChain.App.(*appProvider.App).ParentKeeper.OnAcknowledgementPacket(parentCtx, packet, packetData, ack) + err := s.providerChain.App.(*appProvider.App).ProviderKeeper.OnAcknowledgementPacket(providerCtx, packet, packetData, ack) s.Require().NoError(err) } From 8d88d0cea5d5b10f2f691832c5bf30d51e3ce944 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 May 2022 13:34:27 +0100 Subject: [PATCH 17/23] (builds and tests) finish rename --- x/ccv/consumer/module_test.go | 29 +++++++++++++------------- x/ccv/provider/keeper/genesis_test.go | 19 +++++++++-------- x/ccv/provider/keeper/keeper_test.go | 17 ++++++++------- x/ccv/provider/keeper/proposal_test.go | 14 ++++++------- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/x/ccv/consumer/module_test.go b/x/ccv/consumer/module_test.go index d3e15b281b..31a2ea922f 100644 --- a/x/ccv/consumer/module_test.go +++ b/x/ccv/consumer/module_test.go @@ -13,7 +13,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/consumer" "github.com/cosmos/interchain-security/x/ccv/consumer/types" @@ -68,7 +69,7 @@ func (suite *ConsumerTestSuite) SetupTest() { params := consumertypes.DefaultParams() params.Enabled = true consumerGenesis := types.NewInitialGenesisState(suite.providerClient, suite.providerConsState, valUpdates, params) - suite.consumerChain.App.(*app.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), consumerGenesis) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), consumerGenesis) // create the ccv path and set consumer's clientID to genesis client path := ibctesting.NewPath(suite.consumerChain, suite.providerChain) @@ -78,7 +79,7 @@ func (suite *ConsumerTestSuite) SetupTest() { path.EndpointB.ChannelConfig.Version = ccv.Version path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - providerClient, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetProviderClient(suite.consumerChain.GetContext()) + providerClient, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClient(suite.consumerChain.GetContext()) if !ok { panic("must already have provider client on consumer chain") } @@ -91,7 +92,7 @@ func (suite *ConsumerTestSuite) SetupTest() { // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. path.EndpointB.CreateClient() - suite.providerChain.App.(*app.App).ProviderKeeper.SetConsumerClient(suite.providerChain.GetContext(), suite.consumerChain.ChainID, path.EndpointB.ClientID) + suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetConsumerClient(suite.providerChain.GetContext(), suite.consumerChain.ChainID, path.EndpointB.ClientID) suite.coordinator.CreateConnections(path) @@ -123,7 +124,7 @@ func (suite *ConsumerTestSuite) TestOnChanOpenInit() { { name: "invalid: provider channel already established", setup: func(suite *ConsumerTestSuite) { - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "channel-2") + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "channel-2") // Set INIT channel on consumer chain suite.consumerChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, consumertypes.PortID, channelID, channeltypes.NewChannel( @@ -216,7 +217,7 @@ func (suite *ConsumerTestSuite) TestOnChanOpenInit() { suite.SetupTest() // reset suite tc.setup(suite) - consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*app.App).ConsumerKeeper) + consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper) chanCap, err := suite.consumerChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(consumertypes.PortID, suite.path.EndpointA.ChannelID)) suite.Require().NoError(err) @@ -234,7 +235,7 @@ func (suite *ConsumerTestSuite) TestOnChanOpenInit() { func (suite *ConsumerTestSuite) TestOnChanOpenTry() { // OnOpenTry must error even with correct arguments - consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*app.App).ConsumerKeeper) + consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper) chanCap, err := suite.consumerChain.App.GetScopedIBCKeeper().NewCapability(suite.ctx, host.ChannelCapabilityPath(consumertypes.PortID, suite.path.EndpointA.ChannelID)) suite.Require().NoError(err) @@ -265,7 +266,7 @@ func (suite *ConsumerTestSuite) TestOnChanOpenAck() { { name: "invalid: provider channel already established", setup: func(suite *ConsumerTestSuite) { - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "channel-2") + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "channel-2") // Set INIT channel on consumer chain suite.consumerChain.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.ctx, consumertypes.PortID, channelID, channeltypes.NewChannel( @@ -299,7 +300,7 @@ func (suite *ConsumerTestSuite) TestOnChanOpenAck() { suite.SetupTest() // reset suite tc.setup(suite) - consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*app.App).ConsumerKeeper) + consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper) md := providertypes.HandshakeMetadata{ ProviderFeePoolAddr: "", // dummy address used @@ -325,7 +326,7 @@ func (suite *ConsumerTestSuite) TestOnChanOpenConfirm() { []string{"connection-1"}, ccv.Version, )) - consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*app.App).ConsumerKeeper) + consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper) err := consumerModule.OnChanOpenConfirm(suite.ctx, consumertypes.PortID, "channel-1") suite.Require().Error(err, "OnChanOpenConfirm must always fail") @@ -348,7 +349,7 @@ func (suite *ConsumerTestSuite) TestOnChanCloseInit() { []string{suite.path.EndpointA.ConnectionID}, suite.path.EndpointA.ChannelConfig.Version), ) suite.path.EndpointA.ChannelID = channelID - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "different-channel") + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "different-channel") }, expError: false, }, @@ -357,7 +358,7 @@ func (suite *ConsumerTestSuite) TestOnChanCloseInit() { setup: func(suite *ConsumerTestSuite) { // create open channel suite.coordinator.CreateChannels(suite.path) - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "different-channel") + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetProviderChannel(suite.ctx, "different-channel") }, expError: false, }, @@ -379,7 +380,7 @@ func (suite *ConsumerTestSuite) TestOnChanCloseInit() { setup: func(suite *ConsumerTestSuite) { // create open channel suite.coordinator.CreateChannels(suite.path) - suite.consumerChain.App.(*app.App).ConsumerKeeper.SetProviderChannel(suite.ctx, suite.path.EndpointA.ChannelID) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetProviderChannel(suite.ctx, suite.path.EndpointA.ChannelID) }, expError: true, }, @@ -391,7 +392,7 @@ func (suite *ConsumerTestSuite) TestOnChanCloseInit() { suite.SetupTest() // reset suite tc.setup(suite) - consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*app.App).ConsumerKeeper) + consumerModule := consumer.NewAppModule(suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper) err := consumerModule.OnChanCloseInit(suite.ctx, consumertypes.PortID, suite.path.EndpointA.ChannelID) diff --git a/x/ccv/provider/keeper/genesis_test.go b/x/ccv/provider/keeper/genesis_test.go index 60e2ff6578..14d1fa88fe 100644 --- a/x/ccv/provider/keeper/genesis_test.go +++ b/x/ccv/provider/keeper/genesis_test.go @@ -3,7 +3,8 @@ package keeper_test import ( "fmt" - "github.com/cosmos/interchain-security/app" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/x/ccv/types" ) @@ -11,27 +12,27 @@ func (suite *KeeperTestSuite) TestGenesis() { // set some chain-channel pairs before exporting ctx := suite.providerChain.GetContext() for i := 0; i < 4; i++ { - suite.providerChain.App.(*app.App).ProviderKeeper.SetChainToChannel(ctx, fmt.Sprintf("chainid-%d", i), fmt.Sprintf("channelid-%d", i)) - suite.providerChain.App.(*app.App).ProviderKeeper.SetChannelToChain(ctx, fmt.Sprintf("channelid-%d", i), fmt.Sprintf("chainid-%d", i)) - suite.providerChain.App.(*app.App).ProviderKeeper.SetChannelStatus(ctx, fmt.Sprintf("channelid-%d", i), types.Status(i)) + suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetChainToChannel(ctx, fmt.Sprintf("chainid-%d", i), fmt.Sprintf("channelid-%d", i)) + suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetChannelToChain(ctx, fmt.Sprintf("channelid-%d", i), fmt.Sprintf("chainid-%d", i)) + suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetChannelStatus(ctx, fmt.Sprintf("channelid-%d", i), types.Status(i)) } - genState := suite.providerChain.App.(*app.App).ProviderKeeper.ExportGenesis(suite.providerChain.GetContext()) + genState := suite.providerChain.App.(*appProvider.App).ProviderKeeper.ExportGenesis(suite.providerChain.GetContext()) - suite.consumerChain.App.(*app.App).ProviderKeeper.InitGenesis(suite.consumerChain.GetContext(), genState) + suite.consumerChain.App.(*appConsumer.App).ProviderKeeper.InitGenesis(suite.consumerChain.GetContext(), genState) ctx = suite.consumerChain.GetContext() for i := 0; i < 4; i++ { expectedChainId := fmt.Sprintf("chainid-%d", i) expectedChannelId := fmt.Sprintf("channelid-%d", i) - channelID, channelOk := suite.consumerChain.App.(*app.App).ProviderKeeper.GetChainToChannel(ctx, expectedChainId) - chainID, chainOk := suite.consumerChain.App.(*app.App).ProviderKeeper.GetChannelToChain(ctx, expectedChannelId) + channelID, channelOk := suite.consumerChain.App.(*appConsumer.App).ProviderKeeper.GetChainToChannel(ctx, expectedChainId) + chainID, chainOk := suite.consumerChain.App.(*appConsumer.App).ProviderKeeper.GetChannelToChain(ctx, expectedChannelId) suite.Require().True(channelOk) suite.Require().True(chainOk) suite.Require().Equal(expectedChainId, chainID, "did not store correct chain id for given channel id") suite.Require().Equal(expectedChannelId, channelID, "did not store correct channel id for given chain id") - status := suite.consumerChain.App.(*app.App).ProviderKeeper.GetChannelStatus(ctx, channelID) + status := suite.consumerChain.App.(*appConsumer.App).ProviderKeeper.GetChannelStatus(ctx, channelID) suite.Require().Equal(types.Status(i), status, "status is unexpected for given channel id: %s", channelID) } } diff --git a/x/ccv/provider/keeper/keeper_test.go b/x/ccv/provider/keeper/keeper_test.go index de09047d9e..39bb15fd1e 100644 --- a/x/ccv/provider/keeper/keeper_test.go +++ b/x/ccv/provider/keeper/keeper_test.go @@ -11,7 +11,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - "github.com/cosmos/interchain-security/app" + appConsumer "github.com/cosmos/interchain-security/app_consumer" + appProvider "github.com/cosmos/interchain-security/app_provider" "github.com/cosmos/interchain-security/testutil/simapp" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" @@ -62,7 +63,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := consumertypes.DefaultParams() params.Enabled = true consumerGenesis := consumertypes.NewInitialGenesisState(suite.providerClient, suite.providerConsState, valUpdates, params) - suite.consumerChain.App.(*app.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), consumerGenesis) + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), consumerGenesis) suite.ctx = suite.providerChain.GetContext() @@ -73,7 +74,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - providerClient, ok := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetProviderClient(suite.consumerChain.GetContext()) + providerClient, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClient(suite.consumerChain.GetContext()) if !ok { panic("must already have provider client on consumer chain") } @@ -86,7 +87,7 @@ func (suite *KeeperTestSuite) SetupTest() { // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. suite.path.EndpointB.CreateClient() - suite.providerChain.App.(*app.App).ProviderKeeper.SetConsumerClient(suite.providerChain.GetContext(), suite.consumerChain.ChainID, suite.path.EndpointB.ClientID) + suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetConsumerClient(suite.providerChain.GetContext(), suite.consumerChain.ChainID, suite.path.EndpointB.ClientID) } func TestKeeperTestSuite(t *testing.T) { @@ -94,7 +95,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *KeeperTestSuite) TestValsetUpdateBlockHeight() { - app := suite.providerChain.App.(*app.App) + app := suite.providerChain.App.(*appProvider.App) ctx := suite.ctx blockHeight := app.ProviderKeeper.GetValsetUpdateBlockHeight(ctx, uint64(0)) @@ -115,7 +116,7 @@ func (suite *KeeperTestSuite) TestValsetUpdateBlockHeight() { } func (suite *KeeperTestSuite) TestSlashAcks() { - app := suite.providerChain.App.(*app.App) + app := suite.providerChain.App.(*appProvider.App) ctx := suite.ctx var chainsAcks [][]string @@ -157,7 +158,7 @@ func (suite *KeeperTestSuite) TestSlashAcks() { } func (suite *KeeperTestSuite) TestAppendslashingAck() { - app := suite.providerChain.App.(*app.App) + app := suite.providerChain.App.(*appProvider.App) ctx := suite.ctx p := []string{"alice", "bob", "charlie"} @@ -176,7 +177,7 @@ func (suite *KeeperTestSuite) TestAppendslashingAck() { } func (suite *KeeperTestSuite) TestInitHeight() { - app := suite.providerChain.App.(*app.App) + app := suite.providerChain.App.(*appProvider.App) ctx := suite.ctx tc := []struct { diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index 423a05e7ec..e3295358c1 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - "github.com/cosmos/interchain-security/app" + appProvider "github.com/cosmos/interchain-security/app_provider" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" "github.com/cosmos/interchain-security/x/ccv/provider/types" abci "github.com/tendermint/tendermint/abci/types" @@ -19,7 +19,7 @@ func (suite *KeeperTestSuite) TestMakeConsumerGenesis() { suite.SetupTest() ctx = suite.providerChain.GetContext().WithBlockTime(time.Now()) - actualGenesis, err := suite.providerChain.App.(*app.App).ProviderKeeper.MakeConsumerGenesis(ctx) + actualGenesis, err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.MakeConsumerGenesis(ctx) suite.Require().NoError(err) jsonString := `{"params":{"Enabled":true, "BlocksPerDistributionTransmission":1000, "ConsumerRedistributeFrac":"0"},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"consumer_order":[0,1],"consumer_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"consumer_order":[0,1],"consumer_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` @@ -88,21 +88,21 @@ func (suite *KeeperTestSuite) TestCreateConsumerChainProposal() { tc.malleate(suite) - err := suite.providerChain.App.(*app.App).ProviderKeeper.CreateConsumerChainProposal(ctx, proposal) + err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerChainProposal(ctx, proposal) if tc.expPass { suite.Require().NoError(err, "error returned on valid case") if tc.spawnReached { - clientId := suite.providerChain.App.(*app.App).ProviderKeeper.GetConsumerClient(ctx, chainID) - consumerGenesis, ok := suite.providerChain.App.(*app.App).ProviderKeeper.GetConsumerGenesis(ctx, chainID) + clientId := suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerClient(ctx, chainID) + consumerGenesis, ok := suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerGenesis(ctx, chainID) suite.Require().True(ok) - expectedGenesis, err := suite.providerChain.App.(*app.App).ProviderKeeper.MakeConsumerGenesis(ctx) + expectedGenesis, err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.MakeConsumerGenesis(ctx) suite.Require().NoError(err) suite.Require().Equal(expectedGenesis, consumerGenesis) suite.Require().NotEqual("", clientId, "consumer client was not created after spawn time reached") } else { - gotHeight := suite.providerChain.App.(*app.App).ProviderKeeper.GetPendingClientInfo(ctx, proposal.SpawnTime, chainID) + gotHeight := suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetPendingClientInfo(ctx, proposal.SpawnTime, chainID) suite.Require().Equal(initialHeight, gotHeight, "pending client not equal to clientstate in proposal") } } else { From d80e30244358ba061560efda8db0d00c74c6ac34 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 May 2022 13:44:58 +0100 Subject: [PATCH 18/23] Fixes typos --- x/ccv/consumer/keeper/keeper_test.go | 2 +- x/ccv/provider/keeper/proposal_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/ccv/consumer/keeper/keeper_test.go b/x/ccv/consumer/keeper/keeper_test.go index 9c0c7be5d4..c9b907a29b 100644 --- a/x/ccv/consumer/keeper/keeper_test.go +++ b/x/ccv/consumer/keeper/keeper_test.go @@ -96,7 +96,7 @@ func (suite *KeeperTestSuite) SetupCCVChannel() { suite.coordinator.CreateChannels(suite.path) } -func (suite *KeeperTestSuite) TestproviderClient() { +func (suite *KeeperTestSuite) TestProviderClient() { providerClient, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClient(suite.ctx) suite.Require().True(ok) diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index e3295358c1..c4c63f4ab9 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -22,7 +22,7 @@ func (suite *KeeperTestSuite) TestMakeConsumerGenesis() { actualGenesis, err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.MakeConsumerGenesis(ctx) suite.Require().NoError(err) - jsonString := `{"params":{"Enabled":true, "BlocksPerDistributionTransmission":1000, "ConsumerRedistributeFrac":"0"},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"consumer_order":[0,1],"consumer_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"consumer_order":[0,1],"consumer_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` + jsonString := `{"params":{"Enabled":true, "BlocksPerDistributionTransmission":1000, "ConsumerRedistributeFrac":"0"},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:25Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}` var expectedGenesis consumertypes.GenesisState json.Unmarshal([]byte(jsonString), &expectedGenesis) From a25082c0bc40e6e18d04032fe69abb0870b6dbb2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 5 May 2022 17:25:44 +0100 Subject: [PATCH 19/23] Updates ibc-go test FW vers --- go.mod | 2 +- go.sum | 2 ++ integration-tests/main.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b03138e405..ab46e9b4f6 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 - github.com/cosmos/ibc-go/v3 => /Users/danwt/Documents/work/ibc-go + github.com/cosmos/ibc-go/v3 => github.com/informalsystems/ibc-go/v3 v3.0.0-alpha1.0.20220505161112-1f45da82fc75 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 google.golang.org/grpc => google.golang.org/grpc v1.33.2 ) diff --git a/go.sum b/go.sum index 3258b44999..d3d190040a 100644 --- a/go.sum +++ b/go.sum @@ -630,6 +630,8 @@ github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZ github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/informalsystems/ibc-go/v3 v3.0.0-alpha1.0.20220405190259-988da4519455 h1:bfi2Qd01CntsSfN1/wyH5Imo+U/bqS/lOOfc86yY9Qo= github.com/informalsystems/ibc-go/v3 v3.0.0-alpha1.0.20220405190259-988da4519455/go.mod h1:VFtxCEVvhoTFJP6HA3oT2N27bcV5JbV72AiyCO253/Y= +github.com/informalsystems/ibc-go/v3 v3.0.0-alpha1.0.20220505161112-1f45da82fc75 h1:flrFoFHQYOW8ajzGsEdHURYu9TxOT+lqnrPmYj3AP24= +github.com/informalsystems/ibc-go/v3 v3.0.0-alpha1.0.20220505161112-1f45da82fc75/go.mod h1:VFtxCEVvhoTFJP6HA3oT2N27bcV5JbV72AiyCO253/Y= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= diff --git a/integration-tests/main.go b/integration-tests/main.go index ba368f66b9..a534c096cf 100644 --- a/integration-tests/main.go +++ b/integration-tests/main.go @@ -10,7 +10,7 @@ import ( "github.com/kylelemons/godebug/pretty" ) -var verbose = false +var verbose = true func main() { s := DefaultSystemConfig() From ff122d102979516c433a9c112a491bdbd96760a1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 6 May 2022 09:48:40 +0100 Subject: [PATCH 20/23] Updates integration tests to use 2 app.go's --- Makefile | 3 ++- integration-tests/actions.go | 15 ++++++++------- integration-tests/config.go | 5 +++-- integration-tests/state.go | 8 ++++---- integration-tests/testnet-scripts/start-chain.sh | 2 +- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 1189350fbb..a92f381e25 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ install: go.sum export GOFLAGS='-buildmode=pie' export CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2" export CGO_LDFLAGS="-Wl,-z,relro,-z,now -fstack-protector" - go install $(BUILD_FLAGS) ./cmd/interchain-securityd + go install $(BUILD_FLAGS) ./cmd/interchain-security-pd + go install $(BUILD_FLAGS) ./cmd/interchain-security-cd test: go test ./... diff --git a/integration-tests/actions.go b/integration-tests/actions.go index 6b62442b44..31873b0777 100644 --- a/integration-tests/actions.go +++ b/integration-tests/actions.go @@ -25,7 +25,8 @@ func (s System) sendTokens( action SendTokensAction, verbose bool, ) { - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + binaryName := s.chainConfigs[action.chain].binaryName + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, binaryName, "tx", "bank", "send", s.validatorConfigs[action.from].delAddress, @@ -97,7 +98,7 @@ func (s System) startChain( } cmd := exec.Command("docker", "exec", s.containerConfig.instanceName, "/bin/bash", - "/testnet-scripts/start-chain.sh", s.containerConfig.binaryName, string(vals), + "/testnet-scripts/start-chain.sh", chainConfig.binaryName, string(vals), chainConfig.chainId, chainConfig.ipPrefix, genesisChanges, fmt.Sprint(action.skipGentx), `s/timeout_commit = "5s"/timeout_commit = "500ms"/;`+ @@ -149,7 +150,7 @@ func (s System) submitTextProposal( action SubmitTextProposalAction, verbose bool, ) { - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[action.chain].binaryName, "tx", "gov", "submit-proposal", `--title`, action.title, @@ -219,7 +220,7 @@ func (s System) submitConsumerProposal( log.Fatal(err, "\n", string(bz)) } - bz, err = exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err = exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[action.chain].binaryName, "tx", "gov", "submit-proposal", "create-consumer-chain", "/temp-proposal.json", @@ -255,7 +256,7 @@ func (s System) voteGovProposal( vote := action.vote[i] go func(val uint, vote string) { defer wg.Done() - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[action.chain].binaryName, "tx", "gov", "vote", fmt.Sprint(action.propNumber), vote, @@ -289,7 +290,7 @@ func (s System) startConsumerChain( action StartConsumerChainAction, verbose bool, ) { - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[action.consumerChain].binaryName, "query", "provider", "consumer-genesis", s.chainConfigs[action.consumerChain].chainId, @@ -505,7 +506,7 @@ func (s System) delegateTokens( action DelegateTokensAction, verbose bool, ) { - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[action.chain].binaryName, "tx", "staking", "delegate", s.validatorConfigs[action.to].valoperAddress, diff --git a/integration-tests/config.go b/integration-tests/config.go index e604678a63..8368d51006 100644 --- a/integration-tests/config.go +++ b/integration-tests/config.go @@ -20,12 +20,12 @@ type ChainConfig struct { ipPrefix string votingWaitTime uint genesisChanges string + binaryName string } type ContainerConfig struct { containerName string instanceName string - binaryName string ccvVersion string now time.Time } @@ -43,7 +43,6 @@ func DefaultSystemConfig() System { containerConfig: ContainerConfig{ containerName: "interchain-security-container", instanceName: "interchain-security-instance", - binaryName: "interchain-securityd", ccvVersion: "1", now: time.Now(), }, @@ -76,12 +75,14 @@ func DefaultSystemConfig() System { chainConfigs: []ChainConfig{ { chainId: "provider", + binaryName: "interchain-security-pd", ipPrefix: "7.7.7", votingWaitTime: 5, genesisChanges: ".app_state.gov.voting_params.voting_period = \"5s\"", }, { chainId: "consumer", + binaryName: "interchain-security-cd", ipPrefix: "7.7.8", votingWaitTime: 10, genesisChanges: ".app_state.gov.voting_params.voting_period = \"10s\"", diff --git a/integration-tests/state.go b/integration-tests/state.go index c6e7f641a8..27507d48e9 100644 --- a/integration-tests/state.go +++ b/integration-tests/state.go @@ -80,7 +80,7 @@ func (s System) getChainState(chain uint, modelState ChainState) ChainState { var blockHeightRegex = regexp.MustCompile(`block_height: "(\d+)"`) func (s System) getBlockHeight(chain uint) uint { - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[chain].binaryName, "query", "tendermint-validator-set", @@ -139,7 +139,7 @@ func (s System) getValPowers(chain uint, modelState map[uint]uint) map[uint]uint } func (s System) getBalance(chain uint, validator uint) uint { - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[chain].binaryName, "query", "bank", "balances", s.validatorConfigs[validator].delAddress, @@ -161,7 +161,7 @@ var noProposalRegex = regexp.MustCompile(`doesn't exist: key not found`) // interchain-securityd query gov proposals func (s System) getProposal(chain uint, proposal uint) Proposal { - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[chain].binaryName, "query", "gov", "proposal", fmt.Sprint(proposal), @@ -239,7 +239,7 @@ type ValPubKey struct { } func (s System) getValPower(chain uint, validator uint) uint { - bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, + bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.chainConfigs[chain].binaryName, "query", "tendermint-validator-set", diff --git a/integration-tests/testnet-scripts/start-chain.sh b/integration-tests/testnet-scripts/start-chain.sh index 5382fbccbd..a2586b4f50 100644 --- a/integration-tests/testnet-scripts/start-chain.sh +++ b/integration-tests/testnet-scripts/start-chain.sh @@ -187,7 +187,7 @@ done # poll for chain start set +e -until interchain-securityd query block --node "tcp://$CHAIN_IP_PREFIX.$FIRST_VAL_ID:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done +until $BIN query block --node "tcp://$CHAIN_IP_PREFIX.$FIRST_VAL_ID:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done set -e echo "done!!!!!!!!" From 3f9a641ad66df663f98a95daf3164b56a894aad9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 10 May 2022 12:57:05 +0100 Subject: [PATCH 21/23] use app/ instead of app_ --- {app_consumer => app/consumer}/ante_handler.go | 0 {app_consumer => app/consumer}/app.go | 0 {app_consumer => app/consumer}/export.go | 0 {app_consumer => app/consumer}/genesis.go | 0 {app_provider => app/provider}/ante_handler.go | 0 {app_provider => app/provider}/app.go | 0 {app_provider => app/provider}/export.go | 0 {app_provider => app/provider}/genesis.go | 0 cmd/interchain-security-cd/main.go | 2 +- cmd/interchain-security-pd/main.go | 2 +- testutil/simapp/simapp.go | 4 ++-- x/ccv/consumer/keeper/genesis_test.go | 2 +- x/ccv/consumer/keeper/keeper_test.go | 4 ++-- x/ccv/consumer/keeper/params_test.go | 2 +- x/ccv/consumer/keeper/relay_test.go | 2 +- x/ccv/consumer/keeper/validators_test.go | 2 +- x/ccv/consumer/module_test.go | 4 ++-- x/ccv/provider/keeper/genesis_test.go | 4 ++-- x/ccv/provider/keeper/keeper_test.go | 4 ++-- x/ccv/provider/keeper/params_test.go | 2 +- x/ccv/provider/keeper/proposal_test.go | 2 +- x/ccv/provider/proposal_handler_test.go | 2 +- x/ccv/provider/provider_test.go | 4 ++-- x/ccv/provider/unbonding_hook_test.go | 4 ++-- 24 files changed, 23 insertions(+), 23 deletions(-) rename {app_consumer => app/consumer}/ante_handler.go (100%) rename {app_consumer => app/consumer}/app.go (100%) rename {app_consumer => app/consumer}/export.go (100%) rename {app_consumer => app/consumer}/genesis.go (100%) rename {app_provider => app/provider}/ante_handler.go (100%) rename {app_provider => app/provider}/app.go (100%) rename {app_provider => app/provider}/export.go (100%) rename {app_provider => app/provider}/genesis.go (100%) diff --git a/app_consumer/ante_handler.go b/app/consumer/ante_handler.go similarity index 100% rename from app_consumer/ante_handler.go rename to app/consumer/ante_handler.go diff --git a/app_consumer/app.go b/app/consumer/app.go similarity index 100% rename from app_consumer/app.go rename to app/consumer/app.go diff --git a/app_consumer/export.go b/app/consumer/export.go similarity index 100% rename from app_consumer/export.go rename to app/consumer/export.go diff --git a/app_consumer/genesis.go b/app/consumer/genesis.go similarity index 100% rename from app_consumer/genesis.go rename to app/consumer/genesis.go diff --git a/app_provider/ante_handler.go b/app/provider/ante_handler.go similarity index 100% rename from app_provider/ante_handler.go rename to app/provider/ante_handler.go diff --git a/app_provider/app.go b/app/provider/app.go similarity index 100% rename from app_provider/app.go rename to app/provider/app.go diff --git a/app_provider/export.go b/app/provider/export.go similarity index 100% rename from app_provider/export.go rename to app/provider/export.go diff --git a/app_provider/genesis.go b/app/provider/genesis.go similarity index 100% rename from app_provider/genesis.go rename to app/provider/genesis.go diff --git a/cmd/interchain-security-cd/main.go b/cmd/interchain-security-cd/main.go index 9d1b592704..655753b476 100644 --- a/cmd/interchain-security-cd/main.go +++ b/cmd/interchain-security-cd/main.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - app "github.com/cosmos/interchain-security/app_consumer" + app "github.com/cosmos/interchain-security/app/consumer" "github.com/tendermint/spm/cosmoscmd" ) diff --git a/cmd/interchain-security-pd/main.go b/cmd/interchain-security-pd/main.go index 01ef7bf19e..648c4fc7b9 100644 --- a/cmd/interchain-security-pd/main.go +++ b/cmd/interchain-security-pd/main.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - app "github.com/cosmos/interchain-security/app_provider" + app "github.com/cosmos/interchain-security/app/provider" "github.com/tendermint/spm/cosmoscmd" ) diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index 7d05cdeb3a..3abf60c2fd 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -16,8 +16,8 @@ import ( tmtypes "github.com/tendermint/tendermint/types" tmdb "github.com/tendermint/tm-db" - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" + appConsumer "github.com/cosmos/interchain-security/app/consumer" + appProvider "github.com/cosmos/interchain-security/app/provider" ) var defaultConsensusParams = &abci.ConsensusParams{ diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index 68d552804b..3463e85800 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -7,7 +7,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - app "github.com/cosmos/interchain-security/app_consumer" + app "github.com/cosmos/interchain-security/app/consumer" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" "github.com/cosmos/interchain-security/x/ccv/types" diff --git a/x/ccv/consumer/keeper/keeper_test.go b/x/ccv/consumer/keeper/keeper_test.go index c9b907a29b..f297700e83 100644 --- a/x/ccv/consumer/keeper/keeper_test.go +++ b/x/ccv/consumer/keeper/keeper_test.go @@ -12,8 +12,8 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" + appConsumer "github.com/cosmos/interchain-security/app/consumer" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/consumer/types" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" diff --git a/x/ccv/consumer/keeper/params_test.go b/x/ccv/consumer/keeper/params_test.go index 742842435b..6d88245003 100644 --- a/x/ccv/consumer/keeper/params_test.go +++ b/x/ccv/consumer/keeper/params_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - app "github.com/cosmos/interchain-security/app_consumer" + app "github.com/cosmos/interchain-security/app/consumer" "github.com/cosmos/interchain-security/x/ccv/consumer/types" ) diff --git a/x/ccv/consumer/keeper/relay_test.go b/x/ccv/consumer/keeper/relay_test.go index 25fd5a109f..eab04c224b 100644 --- a/x/ccv/consumer/keeper/relay_test.go +++ b/x/ccv/consumer/keeper/relay_test.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - appConsumer "github.com/cosmos/interchain-security/app_consumer" + appConsumer "github.com/cosmos/interchain-security/app/consumer" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" "github.com/cosmos/interchain-security/x/ccv/types" diff --git a/x/ccv/consumer/keeper/validators_test.go b/x/ccv/consumer/keeper/validators_test.go index 56721d59df..500327ad7d 100644 --- a/x/ccv/consumer/keeper/validators_test.go +++ b/x/ccv/consumer/keeper/validators_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - appConsumer "github.com/cosmos/interchain-security/app_consumer" + appConsumer "github.com/cosmos/interchain-security/app/consumer" "github.com/cosmos/interchain-security/x/ccv/consumer/types" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" diff --git a/x/ccv/consumer/module_test.go b/x/ccv/consumer/module_test.go index 31a2ea922f..7efc33af3a 100644 --- a/x/ccv/consumer/module_test.go +++ b/x/ccv/consumer/module_test.go @@ -13,8 +13,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" + appConsumer "github.com/cosmos/interchain-security/app/consumer" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/consumer" "github.com/cosmos/interchain-security/x/ccv/consumer/types" diff --git a/x/ccv/provider/keeper/genesis_test.go b/x/ccv/provider/keeper/genesis_test.go index 14d1fa88fe..33625784d4 100644 --- a/x/ccv/provider/keeper/genesis_test.go +++ b/x/ccv/provider/keeper/genesis_test.go @@ -3,8 +3,8 @@ package keeper_test import ( "fmt" - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" + appConsumer "github.com/cosmos/interchain-security/app/consumer" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/x/ccv/types" ) diff --git a/x/ccv/provider/keeper/keeper_test.go b/x/ccv/provider/keeper/keeper_test.go index 39bb15fd1e..f9e7eeadd4 100644 --- a/x/ccv/provider/keeper/keeper_test.go +++ b/x/ccv/provider/keeper/keeper_test.go @@ -11,8 +11,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" + appConsumer "github.com/cosmos/interchain-security/app/consumer" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" diff --git a/x/ccv/provider/keeper/params_test.go b/x/ccv/provider/keeper/params_test.go index 5e6da652b9..3e3d594ad2 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -6,7 +6,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - appProvider "github.com/cosmos/interchain-security/app_provider" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/x/ccv/provider/types" ) diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index c4c63f4ab9..020875bfca 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - appProvider "github.com/cosmos/interchain-security/app_provider" + appProvider "github.com/cosmos/interchain-security/app/provider" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" "github.com/cosmos/interchain-security/x/ccv/provider/types" abci "github.com/tendermint/tendermint/abci/types" diff --git a/x/ccv/provider/proposal_handler_test.go b/x/ccv/provider/proposal_handler_test.go index 67df960f93..9cc550b3c1 100644 --- a/x/ccv/provider/proposal_handler_test.go +++ b/x/ccv/provider/proposal_handler_test.go @@ -8,7 +8,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - appProvider "github.com/cosmos/interchain-security/app_provider" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/x/ccv/provider" "github.com/cosmos/interchain-security/x/ccv/provider/types" ) diff --git a/x/ccv/provider/provider_test.go b/x/ccv/provider/provider_test.go index 01c5c3e59f..226c29d4ef 100644 --- a/x/ccv/provider/provider_test.go +++ b/x/ccv/provider/provider_test.go @@ -22,8 +22,8 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" + appConsumer "github.com/cosmos/interchain-security/app/consumer" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" diff --git a/x/ccv/provider/unbonding_hook_test.go b/x/ccv/provider/unbonding_hook_test.go index aabdbf4e07..d1f0178a20 100644 --- a/x/ccv/provider/unbonding_hook_test.go +++ b/x/ccv/provider/unbonding_hook_test.go @@ -13,8 +13,8 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - appConsumer "github.com/cosmos/interchain-security/app_consumer" - appProvider "github.com/cosmos/interchain-security/app_provider" + appConsumer "github.com/cosmos/interchain-security/app/consumer" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/x/ccv/types" abci "github.com/tendermint/tendermint/abci/types" From 5409b39b9850521b0f8ad869b3a598a0c819670d Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 10 May 2022 13:08:29 +0100 Subject: [PATCH 22/23] Fixes chains ids used in simapp --- testutil/simapp/simapp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index 3abf60c2fd..133f2dde61 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -67,10 +67,10 @@ func NewBasicCoordinator(t *testing.T) *ibctesting.Coordinator { // NewCoordinator initializes Coordinator with 0 TestChains func NewProviderConsumerCoordinator(t *testing.T) (*ibctesting.Coordinator, *ibctesting.TestChain, *ibctesting.TestChain) { coordinator := NewBasicCoordinator(t) - chainID := ibctesting.GetChainID(0) + chainID := ibctesting.GetChainID(1) coordinator.Chains[chainID] = ibctesting.NewTestChain(t, coordinator, SetupTestingappProvider, chainID) providerChain := coordinator.GetChain(chainID) - chainID = ibctesting.GetChainID(1) + chainID = ibctesting.GetChainID(2) coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(t, coordinator, SetupTestingappConsumer, chainID, providerChain.Vals, providerChain.Signers) consumerChain := coordinator.GetChain(chainID) From 6ecc42ea905393828844652574ed79b1d1494a9b Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 10 May 2022 13:09:24 +0100 Subject: [PATCH 23/23] Fix capitalization of name --- testutil/simapp/simapp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index 133f2dde61..553fd0f757 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -45,7 +45,7 @@ func SetupTestingappProvider() (ibctesting.TestingApp, map[string]json.RawMessag return testApp, appProvider.NewDefaultGenesisState(encoding.Marshaler) } -func SetupTestingappConsumer() (ibctesting.TestingApp, map[string]json.RawMessage) { +func SetupTestingAppConsumer() (ibctesting.TestingApp, map[string]json.RawMessage) { db := tmdb.NewMemDB() // encCdc := app.MakeTestEncodingConfig() encoding := cosmoscmd.MakeEncodingConfig(appConsumer.ModuleBasics) @@ -72,7 +72,7 @@ func NewProviderConsumerCoordinator(t *testing.T) (*ibctesting.Coordinator, *ibc providerChain := coordinator.GetChain(chainID) chainID = ibctesting.GetChainID(2) coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(t, coordinator, - SetupTestingappConsumer, chainID, providerChain.Vals, providerChain.Signers) + SetupTestingAppConsumer, chainID, providerChain.Vals, providerChain.Signers) consumerChain := coordinator.GetChain(chainID) return coordinator, providerChain, consumerChain }