Skip to content

Commit

Permalink
Prevent empty channel version
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Nov 8, 2023
1 parent 62d91d9 commit fc549d4
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 fc549d4

Please sign in to comment.