From 09e197eaf3ec8e5e71395cd0ddc69a49f117dc43 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 12 Sep 2019 11:42:27 +0300 Subject: [PATCH] vm: make PUSH0 create empty bytearray Also make tests expect []byte{} instead of 0. --- pkg/vm/tests/binary_expr_test.go | 10 +++++----- pkg/vm/tests/for_test.go | 2 +- pkg/vm/tests/function_call_test.go | 2 +- pkg/vm/tests/if_test.go | 6 +++--- pkg/vm/tests/import_test.go | 2 +- pkg/vm/tests/struct_test.go | 4 ++-- pkg/vm/vm.go | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/vm/tests/binary_expr_test.go b/pkg/vm/tests/binary_expr_test.go index 16e7509fb..fd24c2e37 100644 --- a/pkg/vm/tests/binary_expr_test.go +++ b/pkg/vm/tests/binary_expr_test.go @@ -26,7 +26,7 @@ var binaryExprTestCases = []testCase{ return x } `, - big.NewInt(0), + []byte{}, }, { "simple div", @@ -86,7 +86,7 @@ var binaryExprTestCases = []testCase{ return 0 } `, - big.NewInt(0), + []byte{}, }, { "compare equal strings with eql", @@ -128,7 +128,7 @@ var binaryExprTestCases = []testCase{ return 0 } `, - big.NewInt(0), + []byte{}, }, { "compare equal ints with eql", @@ -156,7 +156,7 @@ var binaryExprTestCases = []testCase{ return 0 } `, - big.NewInt(0), + []byte{}, }, { "compare not equal ints with eql", @@ -170,7 +170,7 @@ var binaryExprTestCases = []testCase{ return 0 } `, - big.NewInt(0), + []byte{}, }, { "compare not equal ints with neq", diff --git a/pkg/vm/tests/for_test.go b/pkg/vm/tests/for_test.go index 70b063ffe..2e3c15288 100644 --- a/pkg/vm/tests/for_test.go +++ b/pkg/vm/tests/for_test.go @@ -275,7 +275,7 @@ func TestIfUnaryInvert(t *testing.T) { return 0 } ` - eval(t, src, big.NewInt(0)) + eval(t, src, []byte{}) } func TestAppendByte(t *testing.T) { diff --git a/pkg/vm/tests/function_call_test.go b/pkg/vm/tests/function_call_test.go index 442d703b4..1ac71b011 100644 --- a/pkg/vm/tests/function_call_test.go +++ b/pkg/vm/tests/function_call_test.go @@ -35,7 +35,7 @@ func TestNotAssignedFunctionCall(t *testing.T) { return 0 } ` - eval(t, src, big.NewInt(0)) + eval(t, src, []byte{}) } func TestMultipleFunctionCalls(t *testing.T) { diff --git a/pkg/vm/tests/if_test.go b/pkg/vm/tests/if_test.go index 6e39d0ab6..c4483309e 100644 --- a/pkg/vm/tests/if_test.go +++ b/pkg/vm/tests/if_test.go @@ -30,7 +30,7 @@ func TestGT(t *testing.T) { return 0 } ` - eval(t, src, big.NewInt(0)) + eval(t, src, []byte{}) } func TestGTE(t *testing.T) { @@ -44,7 +44,7 @@ func TestGTE(t *testing.T) { return 0 } ` - eval(t, src, big.NewInt(0)) + eval(t, src, []byte{}) } func TestLAND(t *testing.T) { @@ -89,5 +89,5 @@ func TestNestedIF(t *testing.T) { return 0 } ` - eval(t, src, big.NewInt(0)) + eval(t, src, []byte{}) } diff --git a/pkg/vm/tests/import_test.go b/pkg/vm/tests/import_test.go index c969ba71f..fb831fcef 100644 --- a/pkg/vm/tests/import_test.go +++ b/pkg/vm/tests/import_test.go @@ -32,7 +32,7 @@ func TestImportStruct(t *testing.T) { return b.Y } ` - eval(t, src, big.NewInt(0)) + eval(t, src, []byte{}) } func TestMultipleDirFileImport(t *testing.T) { diff --git a/pkg/vm/tests/struct_test.go b/pkg/vm/tests/struct_test.go index 759396889..e3de28f91 100644 --- a/pkg/vm/tests/struct_test.go +++ b/pkg/vm/tests/struct_test.go @@ -179,7 +179,7 @@ var structTestCases = []testCase{ return t.y } `, - big.NewInt(0), + []byte{}, }, { "test return struct from func", @@ -209,7 +209,7 @@ var structTestCases = []testCase{ vm.NewBigIntegerItem(1), vm.NewBigIntegerItem(2), vm.NewByteArrayItem([]byte("hello")), - vm.NewBigIntegerItem(0), + vm.NewByteArrayItem([]byte{}), }, }, { diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 0587a6929..7e9c7bd05 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -257,7 +257,7 @@ func (v *VM) execute(ctx *Context, op Instruction) { v.estack.PushVal(val) case PUSH0: - v.estack.PushVal(0) + v.estack.PushVal([]byte{}) case PUSHDATA1: n := ctx.readByte()