From 628861db8be316d67145d4aa17a9f8e4a9e240fb Mon Sep 17 00:00:00 2001 From: 170210 Date: Tue, 19 Mar 2024 17:05:32 +0900 Subject: [PATCH] chore: add test cases Signed-off-by: 170210 --- x/collection/msgs_test.go | 26 +++++++++++++++++++------- x/token/msgs_test.go | 20 +++++++++++++------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/x/collection/msgs_test.go b/x/collection/msgs_test.go index 236629d1ab..bc6e690763 100644 --- a/x/collection/msgs_test.go +++ b/x/collection/msgs_test.go @@ -376,15 +376,15 @@ func TestMsgOperatorSendNFT(t *testing.T) { } func TestMsgAuthorizeOperator(t *testing.T) { - addrs := make([]sdk.AccAddress, 2) + addrs := make([]string, 2) for i := range addrs { - addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() } testCases := map[string]struct { contractID string - holder sdk.AccAddress - operator sdk.AccAddress + holder string + operator string err error }{ "valid msg": { @@ -407,14 +407,26 @@ func TestMsgAuthorizeOperator(t *testing.T) { holder: addrs[0], err: sdkerrors.ErrInvalidAddress, }, + "proxy and approver should be different": { + contractID: "deadbeef", + holder: addrs[0], + operator: addrs[0], + err: collection.ErrApproverProxySame, + }, + "proxy and approver should be different (uppercase)": { + contractID: "deadbeef", + holder: addrs[0], + operator: strings.ToUpper(addrs[0]), + err: collection.ErrApproverProxySame, + }, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { msg := collection.MsgAuthorizeOperator{ ContractId: tc.contractID, - Holder: tc.holder.String(), - Operator: tc.operator.String(), + Holder: tc.holder, + Operator: tc.operator, } require.ErrorIs(t, msg.ValidateBasic(), tc.err) @@ -422,7 +434,7 @@ func TestMsgAuthorizeOperator(t *testing.T) { return } - require.Equal(t, []sdk.AccAddress{tc.holder}, msg.GetSigners()) + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(tc.holder)}, msg.GetSigners()) }) } } diff --git a/x/token/msgs_test.go b/x/token/msgs_test.go index 298dfb6c4b..b41b2f403d 100644 --- a/x/token/msgs_test.go +++ b/x/token/msgs_test.go @@ -221,15 +221,15 @@ func TestMsgRevokeOperator(t *testing.T) { } func TestMsgAuthorizeOperator(t *testing.T) { - addrs := make([]sdk.AccAddress, 2) + addrs := make([]string, 2) for i := range addrs { - addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() } testCases := map[string]struct { contractID string - holder sdk.AccAddress - operator sdk.AccAddress + holder string + operator string err error }{ "valid msg": { @@ -258,14 +258,20 @@ func TestMsgAuthorizeOperator(t *testing.T) { operator: addrs[0], err: token.ErrApproverProxySame, }, + "proxy and approver should be different (uppercase)": { + contractID: "deadbeef", + holder: addrs[0], + operator: strings.ToUpper(addrs[0]), + err: token.ErrApproverProxySame, + }, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { msg := token.MsgAuthorizeOperator{ ContractId: tc.contractID, - Holder: tc.holder.String(), - Operator: tc.operator.String(), + Holder: tc.holder, + Operator: tc.operator, } err := msg.ValidateBasic() @@ -274,7 +280,7 @@ func TestMsgAuthorizeOperator(t *testing.T) { return } - require.Equal(t, []sdk.AccAddress{tc.holder}, msg.GetSigners()) + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(tc.holder)}, msg.GetSigners()) }) } }