-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codec registrations tests for apps (#4780)
* Add test for type registration for transfer. * Add test for type registration for fee. * Add test for type registration for ica. * Lint this bad boy * Apply suggestions from code review Co-authored-by: Damian Nolan <[email protected]> --------- Co-authored-by: Damian Nolan <[email protected]>
- Loading branch information
1 parent
500545b
commit 1e4eb1a
Showing
4 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
modules/apps/27-interchain-accounts/controller/types/codec_test.go
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,59 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
|
||
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" | ||
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" | ||
) | ||
|
||
func TestCodecTypeRegistration(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
typeURL string | ||
expPass bool | ||
}{ | ||
{ | ||
"success: MsgRegisterInterchainAccount", | ||
sdk.MsgTypeURL(&types.MsgRegisterInterchainAccount{}), | ||
true, | ||
}, | ||
{ | ||
"success: MsgSendTx", | ||
sdk.MsgTypeURL(&types.MsgSendTx{}), | ||
true, | ||
}, | ||
{ | ||
"success: MsgUpdateParams", | ||
sdk.MsgTypeURL(&types.MsgUpdateParams{}), | ||
true, | ||
}, | ||
{ | ||
"type not registered on codec", | ||
"ibc.invalid.MsgTypeURL", | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) | ||
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) | ||
|
||
if tc.expPass { | ||
require.NotNil(t, msg) | ||
require.NoError(t, err) | ||
} else { | ||
require.Nil(t, msg) | ||
require.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
modules/apps/27-interchain-accounts/host/types/codec_test.go
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,49 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
|
||
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" | ||
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" | ||
) | ||
|
||
func TestCodecTypeRegistration(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
typeURL string | ||
expPass bool | ||
}{ | ||
{ | ||
"success: MsgUpdateParams", | ||
sdk.MsgTypeURL(&types.MsgUpdateParams{}), | ||
true, | ||
}, | ||
{ | ||
"type not registered on codec", | ||
"ibc.invalid.MsgTypeURL", | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) | ||
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) | ||
|
||
if tc.expPass { | ||
require.NotNil(t, msg) | ||
require.NoError(t, err) | ||
} else { | ||
require.Nil(t, msg) | ||
require.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
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,64 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
|
||
fee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" | ||
"github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" | ||
) | ||
|
||
func TestCodecTypeRegistration(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
typeURL string | ||
expPass bool | ||
}{ | ||
{ | ||
"success: MsgPayPacketFee", | ||
sdk.MsgTypeURL(&types.MsgPayPacketFee{}), | ||
true, | ||
}, | ||
{ | ||
"success: MsgPayPacketFeeAsync", | ||
sdk.MsgTypeURL(&types.MsgPayPacketFeeAsync{}), | ||
true, | ||
}, | ||
{ | ||
"success: MsgRegisterPayee", | ||
sdk.MsgTypeURL(&types.MsgRegisterPayee{}), | ||
true, | ||
}, | ||
{ | ||
"success: MsgRegisterCounterpartyPayee", | ||
sdk.MsgTypeURL(&types.MsgRegisterCounterpartyPayee{}), | ||
true, | ||
}, | ||
{ | ||
"type not registered on codec", | ||
"ibc.invalid.MsgTypeURL", | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
encodingCfg := moduletestutil.MakeTestEncodingConfig(fee.AppModuleBasic{}) | ||
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) | ||
|
||
if tc.expPass { | ||
require.NotNil(t, msg) | ||
require.NoError(t, err) | ||
} else { | ||
require.Nil(t, msg) | ||
require.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
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