Commit 2645aa41 authored by Felipe Andrade's avatar Felipe Andrade

betterer tests

parent 23f0ea39
...@@ -27,6 +27,7 @@ func TestCaching(t *testing.T) { ...@@ -27,6 +27,7 @@ func TestCaching(t *testing.T) {
hdlr.SetRoute("eth_getTransactionByBlockHashAndIndex", "999", "eth_getTransactionByBlockHashAndIndex") hdlr.SetRoute("eth_getTransactionByBlockHashAndIndex", "999", "eth_getTransactionByBlockHashAndIndex")
hdlr.SetRoute("eth_getUncleByBlockHashAndIndex", "999", "eth_getUncleByBlockHashAndIndex") hdlr.SetRoute("eth_getUncleByBlockHashAndIndex", "999", "eth_getUncleByBlockHashAndIndex")
hdlr.SetRoute("eth_getTransactionReceipt", "999", "eth_getTransactionReceipt") hdlr.SetRoute("eth_getTransactionReceipt", "999", "eth_getTransactionReceipt")
hdlr.SetRoute("debug_getRawReceipts", "999", "debug_getRawReceipts")
/* not cacheable */ /* not cacheable */
hdlr.SetRoute("eth_getBlockByNumber", "999", "eth_getBlockByNumber") hdlr.SetRoute("eth_getBlockByNumber", "999", "eth_getBlockByNumber")
hdlr.SetRoute("eth_blockNumber", "999", "eth_blockNumber") hdlr.SetRoute("eth_blockNumber", "999", "eth_blockNumber")
...@@ -180,6 +181,30 @@ func TestCaching(t *testing.T) { ...@@ -180,6 +181,30 @@ func TestCaching(t *testing.T) {
RequireEqualJSON(t, resRaw, resCache) RequireEqualJSON(t, resRaw, resCache)
require.Equal(t, 2, countRequests(backend, "eth_getBlockByHash")) 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) { func TestBatchCaching(t *testing.T) {
......
...@@ -77,6 +77,7 @@ func (h *BatchRPCResponseRouter) SetRoute(method string, id string, result inter ...@@ -77,6 +77,7 @@ func (h *BatchRPCResponseRouter) SetRoute(method string, id string, result inter
switch result.(type) { switch result.(type) {
case string: case string:
case []string:
case nil: case nil:
break break
default: default:
......
...@@ -33,3 +33,4 @@ eth_getTransactionByHash = "main" ...@@ -33,3 +33,4 @@ eth_getTransactionByHash = "main"
eth_getTransactionByBlockHashAndIndex = "main" eth_getTransactionByBlockHashAndIndex = "main"
eth_getUncleByBlockHashAndIndex = "main" eth_getUncleByBlockHashAndIndex = "main"
eth_getTransactionReceipt = "main" eth_getTransactionReceipt = "main"
debug_getRawReceipts = "main"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment