From 7986edeb267f05eb825fab55fd43a7a2edae5327 Mon Sep 17 00:00:00 2001 From: Felipe Andrade Date: Thu, 19 Oct 2023 11:46:24 -0700 Subject: [PATCH] betterer tests --- .../proxyd/integration_tests/caching_test.go | 25 +++++++++++++++++++ .../integration_tests/mock_backend_test.go | 1 + .../integration_tests/testdata/caching.toml | 1 + 3 files changed, 27 insertions(+) diff --git a/proxyd/proxyd/integration_tests/caching_test.go b/proxyd/proxyd/integration_tests/caching_test.go index e4a64d9..e74b85b 100644 --- a/proxyd/proxyd/integration_tests/caching_test.go +++ b/proxyd/proxyd/integration_tests/caching_test.go @@ -27,6 +27,7 @@ func TestCaching(t *testing.T) { hdlr.SetRoute("eth_getTransactionByBlockHashAndIndex", "999", "eth_getTransactionByBlockHashAndIndex") hdlr.SetRoute("eth_getUncleByBlockHashAndIndex", "999", "eth_getUncleByBlockHashAndIndex") hdlr.SetRoute("eth_getTransactionReceipt", "999", "eth_getTransactionReceipt") + hdlr.SetRoute("debug_getRawReceipts", "999", "debug_getRawReceipts") /* not cacheable */ hdlr.SetRoute("eth_getBlockByNumber", "999", "eth_getBlockByNumber") hdlr.SetRoute("eth_blockNumber", "999", "eth_blockNumber") @@ -180,6 +181,30 @@ func TestCaching(t *testing.T) { RequireEqualJSON(t, resRaw, resCache) require.Equal(t, 2, countRequests(backend, "eth_getBlockByHash")) }) + + t.Run("debug_getRawReceipts with 0 receipts should not be cached", func(t *testing.T) { + backend.Reset() + hdlr.SetRoute("debug_getRawReceipts", "999", []string{}) + resRaw, _, err := client.SendRPC("debug_getRawReceipts", []interface{}{"0x88420081ab9c6d50dc57af36b541c6b8a7b3e9c0d837b0414512c4c5883560ff"}) + require.NoError(t, err) + resCache, _, err := client.SendRPC("debug_getRawReceipts", []interface{}{"0x88420081ab9c6d50dc57af36b541c6b8a7b3e9c0d837b0414512c4c5883560ff"}) + require.NoError(t, err) + RequireEqualJSON(t, []byte("{\"id\":999,\"jsonrpc\":\"2.0\",\"result\":[]}"), resRaw) + RequireEqualJSON(t, resRaw, resCache) + require.Equal(t, 2, countRequests(backend, "debug_getRawReceipts")) + }) + + t.Run("debug_getRawReceipts with more than 0 receipts should be cached", func(t *testing.T) { + backend.Reset() + hdlr.SetRoute("debug_getRawReceipts", "999", []string{"a"}) + resRaw, _, err := client.SendRPC("debug_getRawReceipts", []interface{}{"0x88420081ab9c6d50dc57af36b541c6b8a7b3e9c0d837b0414512c4c5883560bb"}) + require.NoError(t, err) + resCache, _, err := client.SendRPC("debug_getRawReceipts", []interface{}{"0x88420081ab9c6d50dc57af36b541c6b8a7b3e9c0d837b0414512c4c5883560bb"}) + require.NoError(t, err) + RequireEqualJSON(t, []byte("{\"id\":999,\"jsonrpc\":\"2.0\",\"result\":[\"a\"]}"), resRaw) + RequireEqualJSON(t, resRaw, resCache) + require.Equal(t, 1, countRequests(backend, "debug_getRawReceipts")) + }) } func TestBatchCaching(t *testing.T) { diff --git a/proxyd/proxyd/integration_tests/mock_backend_test.go b/proxyd/proxyd/integration_tests/mock_backend_test.go index ade879c..bf45d03 100644 --- a/proxyd/proxyd/integration_tests/mock_backend_test.go +++ b/proxyd/proxyd/integration_tests/mock_backend_test.go @@ -77,6 +77,7 @@ func (h *BatchRPCResponseRouter) SetRoute(method string, id string, result inter switch result.(type) { case string: + case []string: case nil: break default: diff --git a/proxyd/proxyd/integration_tests/testdata/caching.toml b/proxyd/proxyd/integration_tests/testdata/caching.toml index f3c1327..41bc65b 100644 --- a/proxyd/proxyd/integration_tests/testdata/caching.toml +++ b/proxyd/proxyd/integration_tests/testdata/caching.toml @@ -33,3 +33,4 @@ eth_getTransactionByHash = "main" eth_getTransactionByBlockHashAndIndex = "main" eth_getUncleByBlockHashAndIndex = "main" eth_getTransactionReceipt = "main" +debug_getRawReceipts = "main"