From fad477df2aaa0501a8951171ee2972ea2d226090 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 25 May 2021 12:24:03 +0300 Subject: [PATCH] [#505] morph/client: Support boolean invocation argument Signed-off-by: Leonard Lyubich --- pkg/morph/client/client.go | 10 ++++++++++ pkg/morph/client/client_test.go | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index e97f63e25..c8a13a0c2 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -289,6 +289,16 @@ func toStackParameter(value interface{}) (sc.Parameter, error) { } return toStackParameter(arr) + case bool: + // FIXME: there are some problems with BoolType in neo-go, + // so we use compatible type + result.Type = sc.IntegerType + + if v { + result.Value = int64(1) + } else { + result.Value = int64(0) + } default: return result, fmt.Errorf("chain/client: unsupported parameter %v", value) } diff --git a/pkg/morph/client/client_test.go b/pkg/morph/client/client_test.go index f1b1f6bb3..321811a88 100644 --- a/pkg/morph/client/client_test.go +++ b/pkg/morph/client/client_test.go @@ -11,6 +11,7 @@ func TestToStackParameter(t *testing.T) { items := []struct { value interface{} expType sc.ParamType + expVal interface{} }{ { value: []byte{1, 2, 3}, @@ -24,6 +25,16 @@ func TestToStackParameter(t *testing.T) { value: "hello world", expType: sc.StringType, }, + { + value: false, + expType: sc.IntegerType, + expVal: int64(0), + }, + { + value: true, + expType: sc.IntegerType, + expVal: int64(1), + }, } for _, item := range items { @@ -31,7 +42,11 @@ func TestToStackParameter(t *testing.T) { res, err := toStackParameter(item.value) require.NoError(t, err) require.Equal(t, item.expType, res.Type) - require.Equal(t, item.value, res.Value) + if item.expVal != nil { + require.Equal(t, item.expVal, res.Value) + } else { + require.Equal(t, item.value, res.Value) + } }) } }