From d6c3f74e3c6b63c57d62ca1d1e99f688a2848f2e Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 12 Aug 2019 17:53:19 +0300 Subject: [PATCH] pkg/vm/stack: make some use of testReadInt64() GolangCI complains: testReadInt64 is unused (from deadcode) Fix it to always provide correctly-sized buffer for the binary.Read(). --- pkg/vm/stack/int_test.go | 2 ++ pkg/vm/stack/test_helper.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/vm/stack/int_test.go b/pkg/vm/stack/int_test.go index 25d360183..46a2c302e 100644 --- a/pkg/vm/stack/int_test.go +++ b/pkg/vm/stack/int_test.go @@ -64,6 +64,8 @@ func TestByteArrConversion(t *testing.T) { ba, err := a.ByteArray() assert.Nil(t, err) + assert.Equal(t, num, testReadInt64(ba.val)) + have, err := ba.Integer() assert.Nil(t, err) diff --git a/pkg/vm/stack/test_helper.go b/pkg/vm/stack/test_helper.go index d12bea71f..56a5ff89d 100644 --- a/pkg/vm/stack/test_helper.go +++ b/pkg/vm/stack/test_helper.go @@ -38,7 +38,11 @@ func testMakeStackInt(t *testing.T, num int64) *Int { func testReadInt64(data []byte) int64 { var ret int64 - buf := bytes.NewBuffer(data) + var arr [8]byte + + // expands or shrinks data automatically + copy(arr[:], data) + buf := bytes.NewBuffer(arr[:]) binary.Read(buf, binary.LittleEndian, &ret) return ret }