From dcaa82b32b6a54ccf3fb292d111e281a69e2d0e2 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 8 Jun 2020 16:38:44 +0300 Subject: [PATCH] rpc: convert `null` value to a defaultT Right now we convert it is unmarshaler into a float64(0) so an error is supressed. --- pkg/rpc/request/param.go | 5 +++++ pkg/rpc/request/param_test.go | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/rpc/request/param.go b/pkg/rpc/request/param.go index de1e3dcb9..205a2a93e 100644 --- a/pkg/rpc/request/param.go +++ b/pkg/rpc/request/param.go @@ -192,6 +192,11 @@ func (p *Param) UnmarshalJSON(data []byte) error { {ArrayT, &[]Param{}}, } + if bytes.Equal(data, []byte("null")) { + p.Type = defaultT + return nil + } + for _, cur := range attempts { r := bytes.NewReader(data) jd := json.NewDecoder(r) diff --git a/pkg/rpc/request/param_test.go b/pkg/rpc/request/param_test.go index da04ea540..7bf2ae22d 100644 --- a/pkg/rpc/request/param_test.go +++ b/pkg/rpc/request/param_test.go @@ -14,7 +14,7 @@ import ( ) func TestParam_UnmarshalJSON(t *testing.T) { - msg := `["str1", 123, ["str2", 3], [{"type": "String", "value": "jajaja"}], + msg := `["str1", 123, null, ["str2", 3], [{"type": "String", "value": "jajaja"}], {"type": "MinerTransaction"}, {"contract": "f84d6a337fbc3d3a201d41da99e86b479e7a2554"}, {"state": "HALT"}]` @@ -29,6 +29,9 @@ func TestParam_UnmarshalJSON(t *testing.T) { Type: NumberT, Value: 123, }, + { + Type: defaultT, + }, { Type: ArrayT, Value: []Param{