kaspad/cmd/kaspawallet/utils/validate_amount_test.go
2023-09-22 08:45:26 -06:00

40 lines
619 B
Go

package utils
import (
"testing"
)
func TestValidateAmountFormat(t *testing.T) {
validCases := []string{
"0",
"1",
"1.0",
"0.1",
"0.12345678",
}
for _, testCase := range validCases {
err := ValidateAmountFormat(testCase)
if err != nil {
t.Error(err)
}
}
invalidCases := []string{
"",
"a",
"-1",
"0.123456789", // 9 decimal digits
".1", // decimal but no integer component
}
for _, testCase := range invalidCases {
err := ValidateAmountFormat(testCase)
if err == nil {
t.Errorf("Expected an error but succeeded validation for test case %s", testCase)
}
}
}