From a42c30afcadb57a6759f39809aa42f1fec6744ab Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Tue, 30 Apr 2024 14:25:52 -0600 Subject: [PATCH] add validate basic for MsgChangeStatusProposalRequest --- x/marker/types/msg.go | 16 ++++++++++ x/marker/types/msg_test.go | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/x/marker/types/msg.go b/x/marker/types/msg.go index 913ab9a2ea..7f9d01c2de 100644 --- a/x/marker/types/msg.go +++ b/x/marker/types/msg.go @@ -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 +} diff --git a/x/marker/types/msg_test.go b/x/marker/types/msg_test.go index 2b18561938..b3e834578e 100644 --- a/x/marker/types/msg_test.go +++ b/x/marker/types/msg_test.go @@ -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") + } + }) + } +}