[#505] morph/client: Support boolean invocation argument

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-25 12:24:03 +03:00 committed by Alex Vanin
parent f2778361c8
commit fad477df2a
2 changed files with 26 additions and 1 deletions

View file

@ -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)
}

View file

@ -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)
}
})
}
}