From fd72f0635e875f08c1ee816b0a78f0a3a9d3895a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 6 May 2020 13:10:32 +0300 Subject: [PATCH 1/2] rpc/server: prevent test panicing in checkErrGetResult() If we expect some resp.Error, then check for it explicitly. --- pkg/rpc/server/server_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 35a1b98e5..59483edf5 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -1091,6 +1091,7 @@ func checkErrGetResult(t *testing.T, body []byte, expectingFail bool) json.RawMe err := json.Unmarshal(body, &resp) require.Nil(t, err) if expectingFail { + require.NotNil(t, resp.Error) assert.NotEqual(t, 0, resp.Error.Code) assert.NotEqual(t, "", resp.Error.Message) } else { From 7287c01bd0576429b33482f142fac9d5485be595 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 6 May 2020 13:11:28 +0300 Subject: [PATCH 2/2] rpc/server: rework submitblock empty test The original intention here was to check for server reaction in presence of validation errors (response.ErrValidationFailed) and it was very easy to make validation fail for block without transactions in Neo 2. But in Neo 3 transactionless blocks are perfectly valid (see 29d321b5e11d2e1f8a88ff169e2c56830e88fba9) which broke this test even though we didn't see it until websocket addition (which required 8cec6694ae9e90f7b279fa5b5d66d5bf07fb9627 to make this test work initially). So make a valid block and then spoil its verification script. --- pkg/rpc/server/server_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 59483edf5..a41961d1f 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -860,8 +860,9 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] t.Run("submit", func(t *testing.T) { rpc := `{"jsonrpc": "2.0", "id": 1, "method": "submitblock", "params": ["%s"]}` - t.Run("empty", func(t *testing.T) { + t.Run("invalid signature", func(t *testing.T) { s := newBlock(t, chain, 1) + s.Script.VerificationScript[8] ^= 0xff body := doRPCCall(fmt.Sprintf(rpc, encodeBlock(t, s)), httpSrv.URL, t) checkErrGetResult(t, body, true) })