diff --git a/chain/types/bigint.go b/chain/types/bigint.go index 92294e098..99fb7c0fb 100644 --- a/chain/types/bigint.go +++ b/chain/types/bigint.go @@ -131,7 +131,7 @@ func (bi BigInt) SizeStr() string { den := big.NewRat(1, 1024) var i int - for f, _ := r.Float64(); f >= 1024 && 1 < len(sizeUnits); f, _ = r.Float64() { + for f, _ := r.Float64(); f >= 1024 && i+1 < len(sizeUnits); f, _ = r.Float64() { i++ r = r.Mul(r, den) } diff --git a/chain/types/bigint_test.go b/chain/types/bigint_test.go index 5c86f7875..be77acbde 100644 --- a/chain/types/bigint_test.go +++ b/chain/types/bigint_test.go @@ -2,6 +2,7 @@ package types import ( "bytes" + "math/big" "testing" "github.com/stretchr/testify/assert" @@ -69,3 +70,11 @@ func TestSizeStr(t *testing.T) { assert.Equal(t, c.out, NewInt(c.in).SizeStr(), "input %+v, produced wrong result", c) } } + +func TestSizeStrBig(t *testing.T) { + ZiB := big.NewInt(50000) + ZiB = ZiB.Lsh(ZiB, 70) + + assert.Equal(t, "5e+04 ZiB", BigInt{Int: ZiB}.SizeStr(), "inout %+v, produced wrong result", ZiB) + +}