* remove client type struct Remove the client type struct, remove ClientType interface function from Header and Misbehaviour. ClientState and ConsensusState return the ClientType as a string. All uses of client type in testing are now pointing at the testing package so changing the location of the client type const will be painless. * update godoc and add back client type interface func Add godoc to client type constant for solo machine, tendermint, and localhost as per @fedekunze review suggestion. Add back the ClientType interface function for misbehaviour and header for solo machine and tendermint and add back the one liner unit tests as per @AdityaSripal suggestion. * remove client state from return remove client state from the return of CreateClient, UpdateClient, and CheckMisbehaviourAndUpdateState as well as update tests to reflect this change. * fix build error introduced by latest merge Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
234 lines
6.4 KiB
Go
234 lines
6.4 KiB
Go
package transfer_test
|
|
|
|
import (
|
|
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
|
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
|
|
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
|
|
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
|
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
|
|
)
|
|
|
|
func (suite *TransferTestSuite) TestOnChanOpenInit() {
|
|
var (
|
|
channel *channeltypes.Channel
|
|
testChannel ibctesting.TestChannel
|
|
connA *ibctesting.TestConnection
|
|
chanCap *capabilitytypes.Capability
|
|
)
|
|
|
|
testCases := []struct {
|
|
name string
|
|
malleate func()
|
|
expPass bool
|
|
}{
|
|
|
|
{
|
|
"success", func() {}, true,
|
|
},
|
|
{
|
|
"invalid order - ORDERED", func() {
|
|
channel.Ordering = channeltypes.ORDERED
|
|
}, false,
|
|
},
|
|
{
|
|
"invalid port ID", func() {
|
|
testChannel = connA.NextTestChannel(ibctesting.MockPort)
|
|
}, false,
|
|
},
|
|
{
|
|
"invalid version", func() {
|
|
channel.Version = "version"
|
|
}, false,
|
|
},
|
|
{
|
|
"capability already claimed", func() {
|
|
err := suite.chainA.App.ScopedTransferKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(testChannel.PortID, testChannel.ID))
|
|
suite.Require().NoError(err)
|
|
}, false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
|
|
suite.Run(tc.name, func() {
|
|
suite.SetupTest() // reset
|
|
|
|
_, _, connA, _ = suite.coordinator.SetupClientConnections(suite.chainA, suite.chainB, ibctesting.Tendermint)
|
|
testChannel = connA.NextTestChannel(ibctesting.TransferPort)
|
|
counterparty := channeltypes.NewCounterparty(testChannel.PortID, testChannel.ID)
|
|
channel = &channeltypes.Channel{
|
|
State: channeltypes.INIT,
|
|
Ordering: channeltypes.UNORDERED,
|
|
Counterparty: counterparty,
|
|
ConnectionHops: []string{connA.ID},
|
|
Version: types.Version,
|
|
}
|
|
|
|
module, _, err := suite.chainA.App.IBCKeeper.PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.TransferPort)
|
|
suite.Require().NoError(err)
|
|
|
|
chanCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(ibctesting.TransferPort, testChannel.ID))
|
|
suite.Require().NoError(err)
|
|
|
|
cbs, ok := suite.chainA.App.IBCKeeper.Router.GetRoute(module)
|
|
suite.Require().True(ok)
|
|
|
|
tc.malleate() // explicitly change fields in channel and testChannel
|
|
|
|
err = cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(),
|
|
testChannel.PortID, testChannel.ID, chanCap, channel.Counterparty, channel.GetVersion(),
|
|
)
|
|
|
|
if tc.expPass {
|
|
suite.Require().NoError(err)
|
|
} else {
|
|
suite.Require().Error(err)
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|
|
|
|
func (suite *TransferTestSuite) TestOnChanOpenTry() {
|
|
var (
|
|
channel *channeltypes.Channel
|
|
testChannel ibctesting.TestChannel
|
|
connA *ibctesting.TestConnection
|
|
chanCap *capabilitytypes.Capability
|
|
counterpartyVersion string
|
|
)
|
|
|
|
testCases := []struct {
|
|
name string
|
|
malleate func()
|
|
expPass bool
|
|
}{
|
|
|
|
{
|
|
"success", func() {}, true,
|
|
},
|
|
{
|
|
"invalid order - ORDERED", func() {
|
|
channel.Ordering = channeltypes.ORDERED
|
|
}, false,
|
|
},
|
|
{
|
|
"invalid port ID", func() {
|
|
testChannel = connA.NextTestChannel(ibctesting.MockPort)
|
|
}, false,
|
|
},
|
|
{
|
|
"invalid version", func() {
|
|
channel.Version = "version"
|
|
}, false,
|
|
},
|
|
{
|
|
"invalid counterparty version", func() {
|
|
counterpartyVersion = "version"
|
|
}, false,
|
|
},
|
|
{
|
|
"capability already claimed", func() {
|
|
err := suite.chainA.App.ScopedTransferKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(testChannel.PortID, testChannel.ID))
|
|
suite.Require().NoError(err)
|
|
}, false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
|
|
suite.Run(tc.name, func() {
|
|
suite.SetupTest() // reset
|
|
|
|
_, _, connA, _ = suite.coordinator.SetupClientConnections(suite.chainA, suite.chainB, ibctesting.Tendermint)
|
|
testChannel = connA.NextTestChannel(ibctesting.TransferPort)
|
|
counterparty := channeltypes.NewCounterparty(testChannel.PortID, testChannel.ID)
|
|
channel = &channeltypes.Channel{
|
|
State: channeltypes.TRYOPEN,
|
|
Ordering: channeltypes.UNORDERED,
|
|
Counterparty: counterparty,
|
|
ConnectionHops: []string{connA.ID},
|
|
Version: types.Version,
|
|
}
|
|
counterpartyVersion = types.Version
|
|
|
|
module, _, err := suite.chainA.App.IBCKeeper.PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.TransferPort)
|
|
suite.Require().NoError(err)
|
|
|
|
chanCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(ibctesting.TransferPort, testChannel.ID))
|
|
suite.Require().NoError(err)
|
|
|
|
cbs, ok := suite.chainA.App.IBCKeeper.Router.GetRoute(module)
|
|
suite.Require().True(ok)
|
|
|
|
tc.malleate() // explicitly change fields in channel and testChannel
|
|
|
|
err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(),
|
|
testChannel.PortID, testChannel.ID, chanCap, channel.Counterparty, channel.GetVersion(), counterpartyVersion,
|
|
)
|
|
|
|
if tc.expPass {
|
|
suite.Require().NoError(err)
|
|
} else {
|
|
suite.Require().Error(err)
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|
|
|
|
func (suite *TransferTestSuite) TestOnChanOpenAck() {
|
|
var (
|
|
testChannel ibctesting.TestChannel
|
|
connA *ibctesting.TestConnection
|
|
counterpartyVersion string
|
|
)
|
|
|
|
testCases := []struct {
|
|
name string
|
|
malleate func()
|
|
expPass bool
|
|
}{
|
|
|
|
{
|
|
"success", func() {}, true,
|
|
},
|
|
{
|
|
"invalid counterparty version", func() {
|
|
counterpartyVersion = "version"
|
|
}, false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
|
|
suite.Run(tc.name, func() {
|
|
suite.SetupTest() // reset
|
|
|
|
_, _, connA, _ = suite.coordinator.SetupClientConnections(suite.chainA, suite.chainB, ibctesting.Tendermint)
|
|
testChannel = connA.NextTestChannel(ibctesting.TransferPort)
|
|
counterpartyVersion = types.Version
|
|
|
|
module, _, err := suite.chainA.App.IBCKeeper.PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.TransferPort)
|
|
suite.Require().NoError(err)
|
|
|
|
cbs, ok := suite.chainA.App.IBCKeeper.Router.GetRoute(module)
|
|
suite.Require().True(ok)
|
|
|
|
tc.malleate() // explicitly change fields in channel and testChannel
|
|
|
|
err = cbs.OnChanOpenAck(suite.chainA.GetContext(), testChannel.PortID, testChannel.ID, counterpartyVersion)
|
|
|
|
if tc.expPass {
|
|
suite.Require().NoError(err)
|
|
} else {
|
|
suite.Require().Error(err)
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|