From a3602d4fcf31a49ccf6069b34b7931b5456d41a7 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 9 Jul 2020 17:26:06 -0700 Subject: [PATCH] fix tests, handle parsing with suffixes properly --- chain/types/bigint_test.go | 2 +- chain/types/fil.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/chain/types/bigint_test.go b/chain/types/bigint_test.go index 43e5633b2..60130277e 100644 --- a/chain/types/bigint_test.go +++ b/chain/types/bigint_test.go @@ -43,7 +43,7 @@ func TestBigIntSerializationRoundTrip(t *testing.T) { func TestFilRoundTrip(t *testing.T) { testValues := []string{ - "0", "1", "1.001", "100.10001", "101100", "5000.01", "5000", + "0 FIL", "1 FIL", "1.001 FIL", "100.10001 FIL", "101100 FIL", "5000.01 FIL", "5000 FIL", } for _, v := range testValues { diff --git a/chain/types/fil.go b/chain/types/fil.go index 941cfbaa9..1d912d9c0 100644 --- a/chain/types/fil.go +++ b/chain/types/fil.go @@ -13,7 +13,7 @@ type FIL BigInt func (f FIL) String() string { r := new(big.Rat).SetFrac(f.Int, big.NewInt(int64(build.FilecoinPrecision))) if r.Sign() == 0 { - return "0" + return "0 FIL" } return strings.TrimRight(strings.TrimRight(r.FloatString(18), "0"), ".") + " FIL" } @@ -29,6 +29,7 @@ func (f FIL) Format(s fmt.State, ch rune) { func ParseFIL(s string) (FIL, error) { suffix := strings.TrimLeft(s, ".1234567890") + s = s[:len(s)-len(suffix)] var attofil bool if suffix != "" { norm := strings.ToLower(strings.TrimSpace(suffix))