Skip to content

Commit

Permalink
add validate basic for MsgChangeStatusProposalRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Apr 30, 2024
1 parent b8d480e commit a42c30a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
16 changes: 16 additions & 0 deletions x/marker/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,19 @@ func (msg MsgRemoveAdministratorProposalRequest) ValidateBasic() error {
}
return nil
}

func NewMsgChangeStatusProposalRequest(denom string, status MarkerStatus, authority string) *MsgChangeStatusProposalRequest {
return &MsgChangeStatusProposalRequest{
Denom: denom,
NewStatus: status,
Authority: authority,
}
}

func (msg MsgChangeStatusProposalRequest) ValidateBasic() error {
if err := sdk.ValidateDenom(msg.Denom); err != nil {
return err
}
_, err := sdk.AccAddressFromBech32(msg.Authority)
return err
}
61 changes: 61 additions & 0 deletions x/marker/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,3 +1066,64 @@ func TestMsgRemoveAdministratorProposalRequestValidateBasic(t *testing.T) {
})
}
}

func TestMsgChangeStatusProposalRequestValidateBasic(t *testing.T) {
validAuthority := "cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck"
invalidAuthority := "invalidauth0000"
validDenom := "validcoin"
invalidDenom := "1invalid"

testCases := []struct {
name string
denom string
authority string
expectError bool
expectedError string
}{
{
name: "valid case",
denom: validDenom,
authority: validAuthority,
expectError: false,
},
{
name: "invalid authority address",
denom: validDenom,
authority: invalidAuthority,
expectError: true,
expectedError: "decoding bech32 failed: invalid separator index -1",
},
{
name: "invalid denom",
denom: invalidDenom,
authority: validAuthority,
expectError: true,
expectedError: "invalid denom: 1invalid",
},
{
name: "both authority and denom are invalid",
denom: invalidDenom,
authority: invalidAuthority,
expectError: true,
expectedError: "invalid denom: 1invalid",
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
msg := MsgChangeStatusProposalRequest{
Denom: tc.denom,
Authority: tc.authority,
}

err := msg.ValidateBasic()
if tc.expectError {
require.Error(t, err)
require.EqualError(t, err, tc.expectedError, "ValidateBasic error")
} else {
require.NoError(t, err, "ValidateBasic error")
}
})
}
}

0 comments on commit a42c30a

Please sign in to comment.