Skip to content

Commit

Permalink
test: enable ibc ante test
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed May 24, 2024
1 parent 0eee652 commit ff32028
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 116 deletions.
1 change: 0 additions & 1 deletion app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func setup(withGenesis bool, invCheckPeriod uint) (*composable.ComposableApp, co
composable.DefaultNodeHome,
invCheckPeriod,
EmptyAppOptions{},
nil,
)
if withGenesis {
return app, composable.NewDefaultGenesisState()
Expand Down
7 changes: 7 additions & 0 deletions app/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/ibctesting/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 0 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func setup(withGenesis bool, chainID string) (*ComposableApp, GenesisState) {
DefaultNodeHome,
5,
EmptyBaseAppOptions{},
nil,
baseapp.SetChainID(chainID),
)
if withGenesis {
Expand Down
5 changes: 5 additions & 0 deletions app/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/picad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ func appExport(
homePath,
uint(1),
appOpts,
nil,
)

if err := anApp.LoadHeight(height); err != nil {
Expand All @@ -338,7 +337,6 @@ func appExport(
homePath,
uint(1),
appOpts,
nil,
)
}

Expand Down
221 changes: 110 additions & 111 deletions x/transfermiddleware/ibc_ante_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit ff32028

Please sign in to comment.