forked from cosmos/ibc-go
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding Pack/Unpack acknowledgement helper fns (cosmos#895)
* feat: adding Pack/Unpack acknowledgement helper fns * chore: changelog * fix: docs * Update modules/core/04-channel/types/codec.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
- Loading branch information
1 parent
8f62a47
commit 843b459
Showing
3 changed files
with
94 additions
and
0 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
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
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,58 @@ | ||
package types_test | ||
|
||
import ( | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
|
||
"github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" | ||
"github.com/cosmos/ibc-go/v3/modules/core/exported" | ||
ibcmock "github.com/cosmos/ibc-go/v3/testing/mock" | ||
) | ||
|
||
type caseAny struct { | ||
name string | ||
any *codectypes.Any | ||
expPass bool | ||
} | ||
|
||
func (suite *TypesTestSuite) TestPackAcknowledgement() { | ||
|
||
testCases := []struct { | ||
name string | ||
acknowledgement exported.Acknowledgement | ||
expPass bool | ||
}{ | ||
{ | ||
"success", | ||
&ibcmock.MockAcknowledgement, | ||
true, | ||
}, | ||
{ | ||
"nil", | ||
nil, | ||
false, | ||
}, | ||
} | ||
|
||
testCasesAny := []caseAny{} | ||
|
||
for _, tc := range testCases { | ||
ackAny, err := types.PackAcknowledgement(tc.acknowledgement) | ||
if tc.expPass { | ||
suite.Require().NoError(err, tc.name) | ||
} else { | ||
suite.Require().Error(err, tc.name) | ||
} | ||
|
||
testCasesAny = append(testCasesAny, caseAny{tc.name, ackAny, tc.expPass}) | ||
} | ||
|
||
for i, tc := range testCasesAny { | ||
cs, err := types.UnpackAcknowledgement(tc.any) | ||
if tc.expPass { | ||
suite.Require().NoError(err, tc.name) | ||
suite.Require().Equal(testCases[i].acknowledgement, cs, tc.name) | ||
} else { | ||
suite.Require().Error(err, tc.name) | ||
} | ||
} | ||
} |