From 2b140631f47f1f6dce8c1f0cc780b3ca18661d77 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 28 Oct 2022 12:23:27 +0300 Subject: [PATCH] rpc: adjust Boolean handling in ExpandArrayIntoScript Use new PUSHT and PUSHF opcodes for Boolean scparameter. --- pkg/services/rpcsrv/params/txBuilder.go | 6 +----- pkg/services/rpcsrv/params/tx_builder_test.go | 6 +++--- pkg/services/rpcsrv/server_test.go | 8 ++++---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pkg/services/rpcsrv/params/txBuilder.go b/pkg/services/rpcsrv/params/txBuilder.go index 2c8272739..9872c7cc6 100644 --- a/pkg/services/rpcsrv/params/txBuilder.go +++ b/pkg/services/rpcsrv/params/txBuilder.go @@ -73,11 +73,7 @@ func ExpandArrayIntoScript(script *io.BinWriter, slice []Param) error { if err != nil { return errors.New("not a bool") } - if val { - emit.Int(script, 1) - } else { - emit.Int(script, 0) - } + emit.Bool(script, val) case smartcontract.ArrayType: val, err := fp.Value.GetArray() if err != nil { diff --git a/pkg/services/rpcsrv/params/tx_builder_test.go b/pkg/services/rpcsrv/params/tx_builder_test.go index 983e31abb..ed495b21b 100644 --- a/pkg/services/rpcsrv/params/tx_builder_test.go +++ b/pkg/services/rpcsrv/params/tx_builder_test.go @@ -62,13 +62,13 @@ func TestInvocationScriptCreationGood(t *testing.T) { script: "ERHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==", }, { 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}]`)}}, - 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 - script: "ERHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==", + script: "CBHAHwwBYQwUb0WRYs7rJIsHHsFX2eT2/Sb9vlBBYn1bUg==", }} for i, ps := range paramScripts { method, err := ps.ps[0].GetString() diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index 764af4756..8f1ee23cd 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -1438,7 +1438,7 @@ var rpcTestCases = map[string][]rpcTestCase{ res, ok := inv.(*result.Invoke) require.True(t, ok) expectedInvScript := io.NewBufBinWriter() - emit.Int(expectedInvScript.BinWriter, 0) + emit.Bool(expectedInvScript.BinWriter, false) emit.Int(expectedInvScript.BinWriter, int64(4)) emit.String(expectedInvScript.BinWriter, "good_string") require.NoError(t, expectedInvScript.Err) @@ -1456,7 +1456,7 @@ var rpcTestCases = map[string][]rpcTestCase{ res, ok := inv.(*result.Invoke) require.True(t, ok) expectedInvScript := io.NewBufBinWriter() - emit.Int(expectedInvScript.BinWriter, 0) + emit.Bool(expectedInvScript.BinWriter, false) emit.Int(expectedInvScript.BinWriter, int64(4)) emit.String(expectedInvScript.BinWriter, "invalid_string") require.NoError(t, expectedInvScript.Err) @@ -1556,7 +1556,7 @@ var rpcTestCases = map[string][]rpcTestCase{ res, ok := inv.(*result.Invoke) require.True(t, ok) expectedInvScript := io.NewBufBinWriter() - emit.Int(expectedInvScript.BinWriter, 0) + emit.Bool(expectedInvScript.BinWriter, false) emit.Int(expectedInvScript.BinWriter, int64(4)) emit.String(expectedInvScript.BinWriter, "good_string") require.NoError(t, expectedInvScript.Err) @@ -1574,7 +1574,7 @@ var rpcTestCases = map[string][]rpcTestCase{ res, ok := inv.(*result.Invoke) require.True(t, ok) expectedInvScript := io.NewBufBinWriter() - emit.Int(expectedInvScript.BinWriter, 0) + emit.Bool(expectedInvScript.BinWriter, false) emit.Int(expectedInvScript.BinWriter, int64(4)) emit.String(expectedInvScript.BinWriter, "invalid_string") require.NoError(t, expectedInvScript.Err)