From c8ddc790d9fc1af7f64db24ec6bffcca72cf4b27 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 25 May 2021 11:24:28 +0300 Subject: [PATCH] rpc/request: handle bool parameters correctly --- pkg/rpc/request/txBuilder.go | 13 +++++-------- pkg/rpc/request/tx_builder_test.go | 4 ++-- pkg/rpc/server/server_test.go | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index e02ffbc77..f56803428 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -70,17 +70,14 @@ func ExpandArrayIntoScript(script *io.BinWriter, slice []Param) error { } emit.Int(script, int64(val)) case smartcontract.BoolType: - str, err := fp.Value.GetString() - if err != nil { - return err + val, ok := fp.Value.Value.(bool) + if !ok { + return errors.New("not a bool") } - switch str { - case "true": + if val { emit.Int(script, 1) - case "false": + } else { emit.Int(script, 0) - default: - return errors.New("wrong boolean value") } case smartcontract.ArrayType: val, err := fp.Value.GetArray() diff --git a/pkg/rpc/request/tx_builder_test.go b/pkg/rpc/request/tx_builder_test.go index ad445898d..c8e6b69ab 100644 --- a/pkg/rpc/request/tx_builder_test.go +++ b/pkg/rpc/request/tx_builder_test.go @@ -54,10 +54,10 @@ func TestInvocationScriptCreationGood(t *testing.T) { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.IntegerType, Value: Param{Type: NumberT, Value: 42}}}}}}, script: "002a11c01f0c01610c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52", }, { - ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.BoolType, Value: Param{Type: StringT, Value: "true"}}}}}}, + ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.BoolType, Value: Param{Type: BooleanT, Value: true}}}}}}, script: "1111c01f0c01610c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52", }, { - ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.BoolType, Value: Param{Type: StringT, Value: "false"}}}}}}, + ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.BoolType, Value: Param{Type: BooleanT, Value: false}}}}}}, script: "1011c01f0c01610c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52", }} for _, ps := range paramScripts { diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 27d8be5a8..454733a1a 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -859,7 +859,7 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { name: "positive, with arguments, result=true", - params: fmt.Sprintf(`["%s", [{"type": "String", "value": "good_string"}, {"type": "Integer", "value": "4"}, {"type":"Boolean", "value": "false"}]]`, verifyWithArgsContractHash), + params: fmt.Sprintf(`["%s", [{"type": "String", "value": "good_string"}, {"type": "Integer", "value": "4"}, {"type":"Boolean", "value": false}]]`, verifyWithArgsContractHash), result: func(e *executor) interface{} { return &result.Invoke{} }, check: func(t *testing.T, e *executor, inv interface{}) { res, ok := inv.(*result.Invoke) @@ -877,7 +877,7 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { name: "positive, with arguments, result=false", - params: fmt.Sprintf(`["%s", [{"type": "String", "value": "invalid_string"}, {"type": "Integer", "value": "4"}, {"type":"Boolean", "value": "false"}]]`, verifyWithArgsContractHash), + params: fmt.Sprintf(`["%s", [{"type": "String", "value": "invalid_string"}, {"type": "Integer", "value": "4"}, {"type":"Boolean", "value": false}]]`, verifyWithArgsContractHash), result: func(e *executor) interface{} { return &result.Invoke{} }, check: func(t *testing.T, e *executor, inv interface{}) { res, ok := inv.(*result.Invoke)