From 8e085d3ca3a2e760c6d69f84bb78280595f5cceb Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 15 May 2023 18:03:46 +0300 Subject: [PATCH] vm: allow to make stackitem from *Uint160 and *Uint256 Signed-off-by: Anna Shaleva --- pkg/vm/stackitem/item.go | 10 ++++++++++ pkg/vm/stackitem/item_test.go | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/pkg/vm/stackitem/item.go b/pkg/vm/stackitem/item.go index 8e5952a46..7f86879b5 100644 --- a/pkg/vm/stackitem/item.go +++ b/pkg/vm/stackitem/item.go @@ -132,6 +132,16 @@ func Make(v any) Item { return Make(val.BytesBE()) case util.Uint256: return Make(val.BytesBE()) + case *util.Uint160: + if val == nil { + return Null{} + } + return Make(*val) + case *util.Uint256: + if val == nil { + return Null{} + } + return Make(*val) case nil: return Null{} default: diff --git a/pkg/vm/stackitem/item_test.go b/pkg/vm/stackitem/item_test.go index c90763b84..afdfee213 100644 --- a/pkg/vm/stackitem/item_test.go +++ b/pkg/vm/stackitem/item_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -81,6 +82,22 @@ var makeStackItemTestCases = []struct { input: nil, result: Null{}, }, + { + input: &util.Uint160{1, 2, 3}, + result: NewByteArray(util.Uint160{1, 2, 3}.BytesBE()), + }, + { + input: &util.Uint256{1, 2, 3}, + result: NewByteArray(util.Uint256{1, 2, 3}.BytesBE()), + }, + { + input: (*util.Uint160)(nil), + result: Null{}, + }, + { + input: (*util.Uint256)(nil), + result: Null{}, + }, } var makeStackItemErrorCases = []struct {