rpc: adjust Boolean handling in ExpandArrayIntoScript

Use new PUSHT and PUSHF opcodes for Boolean scparameter.
This commit is contained in:
Anna Shaleva 2022-10-28 12:23:27 +03:00 committed by Anna Shaleva
parent 1250e82c2a
commit 2b140631f4
3 changed files with 8 additions and 12 deletions

View file

@ -73,11 +73,7 @@ func ExpandArrayIntoScript(script *io.BinWriter, slice []Param) error {
if err != nil { if err != nil {
return errors.New("not a bool") return errors.New("not a bool")
} }
if val { emit.Bool(script, val)
emit.Int(script, 1)
} else {
emit.Int(script, 0)
}
case smartcontract.ArrayType: case smartcontract.ArrayType:
val, err := fp.Value.GetArray() val, err := fp.Value.GetArray()
if err != nil { if err != nil {

View file

@ -62,13 +62,13 @@ func TestInvocationScriptCreationGood(t *testing.T) {
script: "ERHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==", script: "ERHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==",
}, { }, {
ps: Params{{RawMessage: []byte(`"a"`)}, {RawMessage: []byte(`[{"type": "Boolean", "value": true}]`)}}, ps: Params{{RawMessage: []byte(`"a"`)}, {RawMessage: []byte(`[{"type": "Boolean", "value": true}]`)}},
script: "ERHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==", script: "CBHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==",
}, { }, {
ps: Params{{RawMessage: []byte(`"a"`)}, {RawMessage: []byte(`[{"type": "Boolean", "value": false}]`)}}, ps: Params{{RawMessage: []byte(`"a"`)}, {RawMessage: []byte(`[{"type": "Boolean", "value": false}]`)}},
script: "EBHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==", script: "CRHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==",
}, { }, {
ps: Params{{RawMessage: []byte(`"a"`)}, {RawMessage: []byte(`[{"type": "Boolean", "value": "blah"}]`)}}, // C# code doesn't use strict type assertions for JSON-ised params ps: Params{{RawMessage: []byte(`"a"`)}, {RawMessage: []byte(`[{"type": "Boolean", "value": "blah"}]`)}}, // C# code doesn't use strict type assertions for JSON-ised params
script: "ERHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==", script: "CBHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==",
}} }}
for i, ps := range paramScripts { for i, ps := range paramScripts {
method, err := ps.ps[0].GetString() method, err := ps.ps[0].GetString()

View file

@ -1438,7 +1438,7 @@ var rpcTestCases = map[string][]rpcTestCase{
res, ok := inv.(*result.Invoke) res, ok := inv.(*result.Invoke)
require.True(t, ok) require.True(t, ok)
expectedInvScript := io.NewBufBinWriter() expectedInvScript := io.NewBufBinWriter()
emit.Int(expectedInvScript.BinWriter, 0) emit.Bool(expectedInvScript.BinWriter, false)
emit.Int(expectedInvScript.BinWriter, int64(4)) emit.Int(expectedInvScript.BinWriter, int64(4))
emit.String(expectedInvScript.BinWriter, "good_string") emit.String(expectedInvScript.BinWriter, "good_string")
require.NoError(t, expectedInvScript.Err) require.NoError(t, expectedInvScript.Err)
@ -1456,7 +1456,7 @@ var rpcTestCases = map[string][]rpcTestCase{
res, ok := inv.(*result.Invoke) res, ok := inv.(*result.Invoke)
require.True(t, ok) require.True(t, ok)
expectedInvScript := io.NewBufBinWriter() expectedInvScript := io.NewBufBinWriter()
emit.Int(expectedInvScript.BinWriter, 0) emit.Bool(expectedInvScript.BinWriter, false)
emit.Int(expectedInvScript.BinWriter, int64(4)) emit.Int(expectedInvScript.BinWriter, int64(4))
emit.String(expectedInvScript.BinWriter, "invalid_string") emit.String(expectedInvScript.BinWriter, "invalid_string")
require.NoError(t, expectedInvScript.Err) require.NoError(t, expectedInvScript.Err)
@ -1556,7 +1556,7 @@ var rpcTestCases = map[string][]rpcTestCase{
res, ok := inv.(*result.Invoke) res, ok := inv.(*result.Invoke)
require.True(t, ok) require.True(t, ok)
expectedInvScript := io.NewBufBinWriter() expectedInvScript := io.NewBufBinWriter()
emit.Int(expectedInvScript.BinWriter, 0) emit.Bool(expectedInvScript.BinWriter, false)
emit.Int(expectedInvScript.BinWriter, int64(4)) emit.Int(expectedInvScript.BinWriter, int64(4))
emit.String(expectedInvScript.BinWriter, "good_string") emit.String(expectedInvScript.BinWriter, "good_string")
require.NoError(t, expectedInvScript.Err) require.NoError(t, expectedInvScript.Err)
@ -1574,7 +1574,7 @@ var rpcTestCases = map[string][]rpcTestCase{
res, ok := inv.(*result.Invoke) res, ok := inv.(*result.Invoke)
require.True(t, ok) require.True(t, ok)
expectedInvScript := io.NewBufBinWriter() expectedInvScript := io.NewBufBinWriter()
emit.Int(expectedInvScript.BinWriter, 0) emit.Bool(expectedInvScript.BinWriter, false)
emit.Int(expectedInvScript.BinWriter, int64(4)) emit.Int(expectedInvScript.BinWriter, int64(4))
emit.String(expectedInvScript.BinWriter, "invalid_string") emit.String(expectedInvScript.BinWriter, "invalid_string")
require.NoError(t, expectedInvScript.Err) require.NoError(t, expectedInvScript.Err)