-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do handshake logic, create test file
- Loading branch information
1 parent
158a251
commit 7b51ebd
Showing
6 changed files
with
103 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package types | ||
|
||
import ( | ||
// sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// 29-fee sentinel errors | ||
var () | ||
var ( | ||
ErrInvalidVersion = sdkerrors.Register(ModuleName, 2, "invalid ICS29 middleware version") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,6 @@ const ( | |
|
||
// QuerierRoute is the querier route for IBC transfer | ||
QuerierRoute = ModuleName | ||
|
||
Version = "fee29-1" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package types | ||
|
||
import "strings" | ||
|
||
// SplitChannelVersion middleware version will split the channel version string | ||
// into the outermost middleware version and the underlying app version. | ||
// It will use the default delimiter `:` for middleware versions. | ||
// In case there's no delimeter, this function returns an empty string for the middleware version (first return argument), | ||
// and the full input as the second underlying app version. | ||
func SplitChannelVersion(version string) (middlewareVersion, appVersion string) { | ||
// only split out the first middleware version | ||
splitVersions := strings.Split(version, ":") | ||
if len(splitVersions) == 1 { | ||
return "", version | ||
} | ||
middlewareVersion = splitVersions[0] | ||
appVersion = strings.Join(splitVersions[1:], ":") | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/ibc-go/modules/core/04-channel/types" | ||
) | ||
|
||
func TestSplitVersions(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
version string | ||
mwVersion string | ||
appVersion string | ||
}{ | ||
{ | ||
"single wrapped middleware", | ||
"fee29-1:ics20-1", | ||
"fee29-1", | ||
"ics20-1", | ||
}, | ||
{ | ||
"multiple wrapped middleware", | ||
"fee29-1:whitelist:ics20-1", | ||
"fee29-1", | ||
"whitelist:ics20-1", | ||
}, | ||
{ | ||
"no middleware", | ||
"ics20-1", | ||
"", | ||
"ics20-1", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
mwVersion, appVersion := types.SplitChannelVersion(tc.version) | ||
require.Equal(t, tc.mwVersion, mwVersion, "middleware version is unexpected for case: %s", tc.name) | ||
require.Equal(t, tc.appVersion, appVersion, "app version is unexpected for case: %s", tc.name) | ||
} | ||
} |