fix: allow any address in ValidatePromptAddress (#16312)
This commit is contained in:
@@ -29,11 +29,22 @@ func ValidatePromptURL(input string) error {
|
||||
|
||||
// ValidatePromptAddress validates that the input is a valid Bech32 address.
|
||||
func ValidatePromptAddress(input string) error {
|
||||
if _, err := sdk.AccAddressFromBech32(input); err != nil {
|
||||
return fmt.Errorf("invalid address: %w", err)
|
||||
_, err := sdk.AccAddressFromBech32(input)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
_, err = sdk.ValAddressFromBech32(input)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = sdk.ConsAddressFromBech32(input)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid address: %w", err)
|
||||
}
|
||||
|
||||
// ValidatePromptYesNo validates that the input is valid sdk.COins
|
||||
@@ -0,0 +1,38 @@
|
||||
package client_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestValidatePromptNotEmpty(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
require.NoError(client.ValidatePromptNotEmpty("foo"))
|
||||
require.ErrorContains(client.ValidatePromptNotEmpty(""), "input cannot be empty")
|
||||
}
|
||||
|
||||
func TestValidatePromptURL(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
require.NoError(client.ValidatePromptURL("https://example.com"))
|
||||
require.ErrorContains(client.ValidatePromptURL("foo"), "invalid URL")
|
||||
}
|
||||
|
||||
func TestValidatePromptAddress(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
require.NoError(client.ValidatePromptAddress("cosmos1huydeevpz37sd9snkgul6070mstupukw00xkw9"))
|
||||
require.NoError(client.ValidatePromptAddress("cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0"))
|
||||
require.NoError(client.ValidatePromptAddress("cosmosvalcons1ntk8eualewuprz0gamh8hnvcem2nrcdsgz563h"))
|
||||
require.ErrorContains(client.ValidatePromptAddress("foo"), "invalid address")
|
||||
}
|
||||
|
||||
func TestValidatePromptCoins(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
require.NoError(client.ValidatePromptCoins("100stake"))
|
||||
require.ErrorContains(client.ValidatePromptCoins("foo"), "invalid coins")
|
||||
}
|
||||
Reference in New Issue
Block a user