Skip to content

Commit

Permalink
Merge pull request #1697 from CosmWasm/1693_default_version
Browse files Browse the repository at this point in the history
Prevent empty channel version
  • Loading branch information
alpe authored Nov 10, 2023
2 parents 62d91d9 + fc549d4 commit 7c8f1e8
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 @@ -22,21 +22,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 All @@ -63,10 +73,17 @@ func TestOnChanOpenInitVersion(t *testing.T) {
coordinator.CreateConnections(path)
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 7c8f1e8

Please sign in to comment.