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 dc26c1e commit b8d480e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
20 changes: 20 additions & 0 deletions x/marker/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,23 @@ func (msg MsgSetAdministratorProposalRequest) ValidateBasic() error {
}
return nil
}

func NewMsgRemoveAdministratorProposalRequest(denom string, removedAddress []string) *MsgRemoveAdministratorProposalRequest {
return &MsgRemoveAdministratorProposalRequest{
Denom: denom,
RemovedAddress: removedAddress,
}
}

func (msg MsgRemoveAdministratorProposalRequest) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Authority)
if err != nil {
return err
}
for _, ra := range msg.RemovedAddress {
if _, err := sdk.AccAddressFromBech32(ra); err != nil {
return fmt.Errorf("administrator account address is invalid: %w", err)
}
}
return nil
}
64 changes: 63 additions & 1 deletion x/marker/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ func TestMsgSetAdministratorProposalRequestValidateBasic(t *testing.T) {
}

for _, tc := range testCases {
tc := tc // capture range variable
tc := tc
t.Run(tc.name, func(t *testing.T) {
msg := NewMsgSetAdministratorProposalRequest(tc.denom, tc.accessGrant, tc.authority)

Expand All @@ -1004,3 +1004,65 @@ func TestMsgSetAdministratorProposalRequestValidateBasic(t *testing.T) {
})
}
}

func TestMsgRemoveAdministratorProposalRequestValidateBasic(t *testing.T) {
validAuthority := "cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck"
invalidAuthority := "invalidauth0000"

validRemovedAddress := "cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl"
invalidRemovedAddress := "invalidremoved000"

testCases := []struct {
name string
authority string
removedAddress []string
expectError bool
expectedError string
}{
{
name: "valid case",
authority: validAuthority,
removedAddress: []string{validRemovedAddress},
expectError: false,
},
{
name: "invalid authority address",
authority: invalidAuthority,
removedAddress: []string{validRemovedAddress},
expectError: true,
expectedError: "decoding bech32 failed: invalid separator index -1",
},
{
name: "invalid removed address",
authority: validAuthority,
removedAddress: []string{invalidRemovedAddress},
expectError: true,
expectedError: "administrator account address is invalid: decoding bech32 failed: invalid separator index -1",
},
{
name: "multiple removed addresses with an invalid one",
authority: validAuthority,
removedAddress: []string{validRemovedAddress, invalidRemovedAddress},
expectError: true,
expectedError: "administrator account address is invalid: decoding bech32 failed: invalid separator index -1",
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
msg := MsgRemoveAdministratorProposalRequest{
Authority: tc.authority,
RemovedAddress: tc.removedAddress,
}

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 b8d480e

Please sign in to comment.