Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent empty channel version #1697

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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