Add filtering to logic, tests pass

This commit is contained in:
Ethan Frey 2021-07-28 10:17:24 +02:00
parent 3016668d29
commit a428d5c605
2 changed files with 5 additions and 3 deletions

View File

@ -198,7 +198,8 @@ func IBCQuerier(wasm contractMetaDataSource, channelKeeper types.ChannelKeeper)
portID := request.ListChannels.PortID
channels := make(wasmvmtypes.IBCChannels, 0)
channelKeeper.IterateChannels(ctx, func(ch channeltypes.IdentifiedChannel) bool {
if portID == "" || portID == ch.PortId {
// it must match the port and be in open state
if (portID == "" || portID == ch.PortId) && ch.State == channeltypes.OPEN {
newChan := wasmvmtypes.IBCChannel{
Endpoint: wasmvmtypes.IBCEndpoint{
PortID: ch.PortId,
@ -230,7 +231,8 @@ func IBCQuerier(wasm contractMetaDataSource, channelKeeper types.ChannelKeeper)
}
got, found := channelKeeper.GetChannel(ctx, portID, channelID)
var channel *wasmvmtypes.IBCChannel
if found {
// it must be in open state
if found && got.State == channeltypes.OPEN {
channel = &wasmvmtypes.IBCChannel{
Endpoint: wasmvmtypes.IBCEndpoint{
PortID: portID,

View File

@ -171,7 +171,7 @@ func TestIBCQuerier(t *testing.T) {
channelKeeper: &wasmtesting.MockChannelKeeper{
GetChannelFn: func(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) {
return channeltypes.Channel{
State: channeltypes.INIT,
State: channeltypes.OPEN,
Ordering: channeltypes.UNORDERED,
Counterparty: channeltypes.Counterparty{
PortId: "counterPartyPortID",