Skip to content

Commit

Permalink
chore: add test cases
Browse files Browse the repository at this point in the history
Signed-off-by: 170210 <[email protected]>
  • Loading branch information
170210 committed Mar 19, 2024
1 parent 2870e3f commit 8963976
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
26 changes: 19 additions & 7 deletions x/collection/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,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": {
Expand All @@ -400,22 +400,34 @@ 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)
if tc.err != nil {
return
}

require.Equal(t, []sdk.AccAddress{tc.holder}, msg.GetSigners())
require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(tc.holder)}, msg.GetSigners())
})
}
}
Expand Down
20 changes: 13 additions & 7 deletions x/token/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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()
Expand All @@ -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())
})
}
}
Expand Down

0 comments on commit 8963976

Please sign in to comment.