From 0add5bbb8d6f861295d4cab3ec93a42824f4135b Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 14 Oct 2019 16:59:47 +0200 Subject: [PATCH] Fix zero handling in refmt transfrom License: MIT Signed-off-by: Jakub Sztandera --- chain/types/bigint.go | 4 ++++ chain/types/bigint_test.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/chain/types/bigint.go b/chain/types/bigint.go index 329781b9f..1bbe9045e 100644 --- a/chain/types/bigint.go +++ b/chain/types/bigint.go @@ -133,6 +133,10 @@ func (bi *BigInt) cborBytes() []byte { } func fromCborBytes(buf []byte) (BigInt, error) { + if len(buf) == 0 { + return NewInt(0), nil + } + var negative bool switch buf[0] { case 0: diff --git a/chain/types/bigint_test.go b/chain/types/bigint_test.go index 6649aa488..7e2cd71f4 100644 --- a/chain/types/bigint_test.go +++ b/chain/types/bigint_test.go @@ -7,7 +7,7 @@ import ( func TestBigIntSerializationRoundTrip(t *testing.T) { testValues := []string{ - "0", "1", "10", "9999", "12345678901234567891234567890123456789012345678901234567890", + "0", "1", "10", "-10", "9999", "12345678901234567891234567890123456789012345678901234567890", } for _, v := range testValues { @@ -29,5 +29,6 @@ func TestBigIntSerializationRoundTrip(t *testing.T) { if BigCmp(out, bi) != 0 { t.Fatal("failed to round trip BigInt through cbor") } + } }