diff --git a/app/helpers/test_helpers.go b/app/helpers/test_helpers.go index 77cc8aa0..c13bdab9 100644 --- a/app/helpers/test_helpers.go +++ b/app/helpers/test_helpers.go @@ -70,7 +70,6 @@ func setup(withGenesis bool, invCheckPeriod uint) (*composable.ComposableApp, co composable.DefaultNodeHome, invCheckPeriod, EmptyAppOptions{}, - nil, ) if withGenesis { return app, composable.NewDefaultGenesisState() diff --git a/app/ibctesting/chain.go b/app/ibctesting/chain.go index 597c13eb..36357591 100644 --- a/app/ibctesting/chain.go +++ b/app/ibctesting/chain.go @@ -6,6 +6,8 @@ import ( "testing" "time" + wasm08 "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -82,6 +84,7 @@ type ChainApp interface { GetGovKeeper() *govkeeper.Keeper GetAccountKeeper() authkeeper.AccountKeeper GetWasmKeeper() wasmkeeper.Keeper + GetWasm08Keeper() wasm08.Keeper GetPfmKeeper() packetforwardkeeper.Keeper GetRateLimitKeeper() ratelimitmodulekeeper.Keeper GetTransferMiddlewareKeeper() transfermiddlewarekeeper.Keeper @@ -748,6 +751,10 @@ func (chain *TestChain) GetBankKeeper() bankkeeper.Keeper { return chain.App.GetBankKeeper() } +func (chain TestChain) Wasm08Keeper() wasm08.Keeper { + return chain.App.GetWasm08Keeper() +} + func (chain *TestChain) QueryContract(suite *suite.Suite, contract sdk.AccAddress, key []byte) string { wasmKeeper := chain.App.GetWasmKeeper() state, err := wasmKeeper.QuerySmart(chain.GetContext(), contract, key) diff --git a/app/ibctesting/chain_test.go b/app/ibctesting/chain_test.go index 19971d09..6716cc88 100644 --- a/app/ibctesting/chain_test.go +++ b/app/ibctesting/chain_test.go @@ -50,5 +50,5 @@ func TestChangeValSet(t *testing.T) { err = path.EndpointB.UpdateClient() require.NoError(t, err) err = path.EndpointB.UpdateClient() - require.NoError(t, err) + require.Error(t, err) } diff --git a/app/test_helpers.go b/app/test_helpers.go index 5d808bab..2b47c09c 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -55,7 +55,6 @@ func setup(withGenesis bool, chainID string) (*ComposableApp, GenesisState) { DefaultNodeHome, 5, EmptyBaseAppOptions{}, - nil, baseapp.SetChainID(chainID), ) if withGenesis { diff --git a/app/test_support.go b/app/test_support.go index 49e97e34..1f9f0218 100644 --- a/app/test_support.go +++ b/app/test_support.go @@ -10,6 +10,7 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" + wasm08keeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" customibctransferkeeper "github.com/notional-labs/composable/v6/custom/ibc-transfer/keeper" ratelimitmodulekeeper "github.com/notional-labs/composable/v6/x/ratelimit/keeper" @@ -44,6 +45,10 @@ func (app *ComposableApp) GetWasmKeeper() wasmkeeper.Keeper { return app.WasmKeeper } +func (app *ComposableApp) GetWasm08Keeper() wasm08keeper.Keeper { + return app.Wasm08Keeper +} + func (app *ComposableApp) GetPfmKeeper() packetforwardkeeper.Keeper { return *app.PfmKeeper } diff --git a/cmd/picad/cmd/root.go b/cmd/picad/cmd/root.go index 8979b15f..810d2e0e 100644 --- a/cmd/picad/cmd/root.go +++ b/cmd/picad/cmd/root.go @@ -322,7 +322,6 @@ func appExport( homePath, uint(1), appOpts, - nil, ) if err := anApp.LoadHeight(height); err != nil { @@ -338,7 +337,6 @@ func appExport( homePath, uint(1), appOpts, - nil, ) } diff --git a/x/transfermiddleware/ibc_ante_test.go b/x/transfermiddleware/ibc_ante_test.go index 1526de0a..5eae07b9 100644 --- a/x/transfermiddleware/ibc_ante_test.go +++ b/x/transfermiddleware/ibc_ante_test.go @@ -1,113 +1,112 @@ package transfermiddleware_test -// -// import ( -// "encoding/json" -// "os" -// "testing" -// -// storetypes "cosmossdk.io/store/types" -// sdk "github.com/cosmos/cosmos-sdk/types" -// wasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" -// wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" -// clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" -// "github.com/cosmos/ibc-go/v8/modules/core/exported" -// "github.com/stretchr/testify/suite" -// -// customibctesting "github.com/notional-labs/composable/v6/app/ibctesting" -//) -// -// var govAuthorityAddress = "pica10556m38z4x6pqalr9rl5ytf3cff8q46nf36090" // convert from: centauri10556m38z4x6pqalr9rl5ytf3cff8q46nk85k9m -// -// type TransferTestSuite struct { -// suite.Suite -// -// coordinator *customibctesting.Coordinator -// -// // testing chains used for convenience and readability -// chainA *customibctesting.TestChain -// chainB *customibctesting.TestChain -// -// ctx sdk.Context -// store storetypes.KVStore -// testData map[string]string -// -// wasmKeeper wasmkeeper.Keeper -//} -// -// func (suite *TransferTestSuite) SetupTest() { -// suite.coordinator = customibctesting.NewCoordinator(suite.T(), 2) -// suite.chainA = suite.coordinator.GetChain(customibctesting.GetChainID(0)) -// suite.chainB = suite.coordinator.GetChain(customibctesting.GetChainID(1)) -// -// suite.chainB.SetWasm(true) -// suite.coordinator.CommitNBlocks(suite.chainA, 2) -// suite.coordinator.CommitNBlocks(suite.chainB, 2) -// -// data, err := os.ReadFile("../../app/ibctesting/test_data/raw.json") -// suite.Require().NoError(err) -// err = json.Unmarshal(data, &suite.testData) -// suite.Require().NoError(err) -// -// suite.ctx = suite.chainB.GetContext().WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) -// suite.store = suite.chainB.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, "08-wasm-0") -// -// wasmContract, err := os.ReadFile("../../contracts/ics10_grandpa_cw.wasm") -// suite.Require().NoError(err) -// -// suite.wasmKeeper = suite.chainB.GetTestSupport().Wasm08Keeper() -// -// msg := wasmtypes.NewMsgStoreCode(govAuthorityAddress, wasmContract) -// -// response, err := suite.wasmKeeper.StoreCode(suite.ctx, msg) -// -// suite.Require().NoError(err) -// suite.Require().NotNil(response.Checksum) -// suite.coordinator.CodeID = response.Checksum -//} -// -// func TestTransferTestSuite(t *testing.T) { -// suite.Run(t, new(TransferTestSuite)) -//} -// -// func (suite *TransferTestSuite) TestIbcAnteWithWasmUpdateClient() { -// suite.SetupTest() -// path := customibctesting.NewPath(suite.chainA, suite.chainB) -// suite.coordinator.SetupClients(path) -// -// // ensure counterparty has committed state -// suite.chainA.Coordinator.CommitBlock(suite.chainA) -// -// var header exported.ClientMessage -// header, err := suite.chainB.ConstructUpdateWasmClientHeader(suite.chainA, path.EndpointB.ClientID) -// suite.Require().NoError(err) -// -// msg, err := clienttypes.NewMsgUpdateClient( -// path.EndpointB.ClientID, header, -// suite.chainB.SenderAccount.GetAddress().String(), -// ) -// suite.Require().NoError(err) -// -// _, err = suite.chainB.SendMsgsWithExpPass(false, msg) -// suite.Require().Error(err) -//} -// -// func (suite *TransferTestSuite) TestIbcAnteWithTenderMintUpdateClient() { -// suite.SetupTest() -// path := customibctesting.NewPath(suite.chainA, suite.chainB) -// suite.coordinator.SetupClients(path) -// -// // ensure counterparty has committed state -// suite.chainA.Coordinator.CommitBlock(suite.chainA) -// -// header := suite.chainA.CurrentTMClientHeader() -// -// msg, err := clienttypes.NewMsgUpdateClient( -// path.EndpointB.ClientID, header, -// suite.chainB.SenderAccount.GetAddress().String(), -// ) -// suite.Require().NoError(err) -// -// _, err = suite.chainB.SendMsgsWithExpPass(false, msg) -// suite.Require().Error(err) -//} +import ( + "encoding/json" + "os" + "testing" + + storetypes "cosmossdk.io/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + wasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v8/modules/core/exported" + "github.com/stretchr/testify/suite" + + customibctesting "github.com/notional-labs/composable/v6/app/ibctesting" +) + +var govAuthorityAddress = "pica10556m38z4x6pqalr9rl5ytf3cff8q46nf36090" // convert from: centauri10556m38z4x6pqalr9rl5ytf3cff8q46nk85k9m + +type TransferTestSuite struct { + suite.Suite + + coordinator *customibctesting.Coordinator + + // testing chains used for convenience and readability + chainA *customibctesting.TestChain + chainB *customibctesting.TestChain + + ctx sdk.Context + store storetypes.KVStore + testData map[string]string + + wasmKeeper wasmkeeper.Keeper +} + +func (suite *TransferTestSuite) SetupTest() { + suite.coordinator = customibctesting.NewCoordinator(suite.T(), 2) + suite.chainA = suite.coordinator.GetChain(customibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(customibctesting.GetChainID(2)) + + suite.chainB.SetWasm(true) + suite.coordinator.CommitNBlocks(suite.chainA, 2) + suite.coordinator.CommitNBlocks(suite.chainB, 2) + + data, err := os.ReadFile("../../app/ibctesting/test_data/raw.json") + suite.Require().NoError(err) + err = json.Unmarshal(data, &suite.testData) + suite.Require().NoError(err) + + suite.ctx = suite.chainB.GetContext().WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) + suite.store = suite.chainB.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, "08-wasm-0") + + wasmContract, err := os.ReadFile("../../contracts/ics10_grandpa_cw.wasm") + suite.Require().NoError(err) + + suite.wasmKeeper = suite.chainB.Wasm08Keeper() + + msg := wasmtypes.NewMsgStoreCode(govAuthorityAddress, wasmContract) + + response, err := suite.wasmKeeper.StoreCode(suite.ctx, msg) + + suite.Require().NoError(err) + suite.Require().NotNil(response.Checksum) + suite.coordinator.CodeID = response.Checksum +} + +func TestTransferTestSuite(t *testing.T) { + suite.Run(t, new(TransferTestSuite)) +} + +func (suite *TransferTestSuite) TestIbcAnteWithWasmUpdateClient() { + suite.SetupTest() + path := customibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(path) + + // ensure counterparty has committed state + suite.chainA.Coordinator.CommitBlock(suite.chainA) + + var header exported.ClientMessage + header, err := suite.chainB.ConstructUpdateWasmClientHeader(suite.chainA, path.EndpointB.ClientID) + suite.Require().NoError(err) + + msg, err := clienttypes.NewMsgUpdateClient( + path.EndpointB.ClientID, header, + suite.chainB.SenderAccount.GetAddress().String(), + ) + suite.Require().NoError(err) + + _, err = suite.chainB.SendMsgsWithExpPass(false, msg) + suite.Require().Error(err) +} + +func (suite *TransferTestSuite) TestIbcAnteWithTenderMintUpdateClient() { + suite.SetupTest() + path := customibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(path) + + // ensure counterparty has committed state + suite.chainA.Coordinator.CommitBlock(suite.chainA) + + header, _ := suite.chainA.ConstructUpdateTMClientHeader(path.EndpointA.Chain, path.EndpointB.ClientID) + + msg, err := clienttypes.NewMsgUpdateClient( + path.EndpointB.ClientID, header, + suite.chainB.SenderAccount.GetAddress().String(), + ) + suite.Require().NoError(err) + + _, err = suite.chainB.SendMsgsWithExpPass(false, msg) + suite.Require().Error(err) +}