Skip to content

Commit

Permalink
fixup: 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 2c64d22 commit bda7705
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 @@ -440,15 +440,15 @@ func TestMsgAuthorizeOperator(t *testing.T) {
}

func TestMsgRevokeOperator(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 @@ -471,22 +471,34 @@ func TestMsgRevokeOperator(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.MsgRevokeOperator{
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 @@ -162,15 +162,15 @@ func TestMsgOperatorSend(t *testing.T) {
}

func TestMsgRevokeOperator(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 @@ -199,14 +199,20 @@ func TestMsgRevokeOperator(t *testing.T) {
operator: addrs[0],
err: token.ErrApproverProxySame,
},
"operator and holder 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.MsgRevokeOperator{
ContractId: tc.contractID,
Holder: tc.holder.String(),
Operator: tc.operator.String(),
Holder: tc.holder,
Operator: tc.operator,
}

err := msg.ValidateBasic()
Expand All @@ -215,7 +221,7 @@ func TestMsgRevokeOperator(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 bda7705

Please sign in to comment.