Skip to content

Commit

Permalink
Merge pull request #1708 from CosmWasm/mergify/bp/releases/v0.4x/pr-1697
Browse files Browse the repository at this point in the history
Prevent empty channel version (backport #1697)
  • Loading branch information
alpe authored Nov 13, 2023
2 parents 15bc22a + b2aa4a4 commit 56af873
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions x/wasm/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func (i IBCHandler) OnChanOpenInit(
return "", err
}
if acceptedVersion == "" { // accept incoming version when nothing returned by contract
if version == "" {
return "", types.ErrEmpty.Wrap("version")
}
acceptedVersion = version
}

Expand Down
37 changes: 27 additions & 10 deletions x/wasm/ibc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,31 @@ import (
)

func TestOnChanOpenInitVersion(t *testing.T) {
const startVersion = "v1"
const v1 = "v1"
specs := map[string]struct {
contractRsp *wasmvmtypes.IBC3ChannelOpenResponse
expVersion string
startVersion string
contractRsp *wasmvmtypes.IBC3ChannelOpenResponse
expVersion string
expErr bool
}{
"different version": {
contractRsp: &wasmvmtypes.IBC3ChannelOpenResponse{Version: "v2"},
expVersion: "v2",
startVersion: v1,
contractRsp: &wasmvmtypes.IBC3ChannelOpenResponse{Version: "v2"},
expVersion: "v2",
},
"no response": {
expVersion: startVersion,
startVersion: v1,
expVersion: v1,
},
"empty result": {
contractRsp: &wasmvmtypes.IBC3ChannelOpenResponse{},
expVersion: startVersion,
startVersion: v1,
contractRsp: &wasmvmtypes.IBC3ChannelOpenResponse{},
expVersion: v1,
},
"empty versions should fail": {
startVersion: "",
contractRsp: &wasmvmtypes.IBC3ChannelOpenResponse{},
expErr: true,
},
}
for name, spec := range specs {
Expand Down Expand Up @@ -63,10 +73,17 @@ func TestOnChanOpenInitVersion(t *testing.T) {

path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: contractInfo.IBCPortID,
Version: startVersion,
Version: spec.startVersion,
Order: channeltypes.UNORDERED,
}
require.NoError(t, path.EndpointA.ChanOpenInit())
// when
gotErr := path.EndpointA.ChanOpenInit()
// then
if spec.expErr {
require.Error(t, gotErr)
return
}
require.NoError(t, gotErr)
assert.Equal(t, spec.expVersion, path.EndpointA.ChannelConfig.Version)
})
}
Expand Down

0 comments on commit 56af873

Please sign in to comment.