Skip to content

Commit

Permalink
Add e2e tests for unexisting block hashes scenario (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina authored Nov 17, 2023
1 parent 8ec9aca commit 5df4cda
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,93 @@ func TestE2ETestCachingMdwWithBlockNumberParam_FutureBlocks(t *testing.T) {
cleanUpRedis(t, redisClient)
}

func TestE2ETestCachingMdwWithBlockHashParam_UnexistingBlockHashes(t *testing.T) {
unexistingBlockHash := "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"

redisClient := redis.NewClient(&redis.Options{
Addr: redisURL,
Password: redisPassword,
DB: 0,
})
cleanUpRedis(t, redisClient)
expectKeysNum(t, redisClient, 0)

for _, tc := range []struct {
desc string
method string
params []interface{}
keysNum int
errorMsg string
}{
{
desc: "test case #1",
method: "eth_getBlockTransactionCountByHash",
params: []interface{}{unexistingBlockHash},
keysNum: 0,
errorMsg: "",
},
{
desc: "test case #2",
method: "eth_getUncleCountByBlockHash",
params: []interface{}{unexistingBlockHash},
keysNum: 0,
errorMsg: "",
},
{
desc: "test case #3",
method: "eth_getBlockByHash",
params: []interface{}{unexistingBlockHash, false},
keysNum: 0,
errorMsg: "",
},
{
desc: "test case #4",
method: "eth_getUncleByBlockHashAndIndex",
params: []interface{}{unexistingBlockHash, "0x0"},
keysNum: 0,
errorMsg: "",
},
{
desc: "test case #5",
method: "eth_getTransactionByBlockHashAndIndex",
params: []interface{}{unexistingBlockHash, "0x0"},
keysNum: 0,
errorMsg: "",
},
} {
t.Run(tc.desc, func(t *testing.T) {
// both calls should lead to cache MISS scenario, because error results aren't cached
// check corresponding values in cachemdw.CacheHeaderKey HTTP header
//
// cache MISS
resp1 := mkJsonRpcRequest(t, proxyServiceURL, 1, tc.method, tc.params)
require.Equal(t, cachemdw.CacheMissHeaderValue, resp1.Header[cachemdw.CacheHeaderKey][0])
body1, err := io.ReadAll(resp1.Body)
require.NoError(t, err)
err = checkJsonRpcErr(body1)
if tc.errorMsg != "" {
require.Error(t, err)
require.Contains(t, err.Error(), tc.errorMsg)
}
expectKeysNum(t, redisClient, tc.keysNum)

// cache MISS again (error results aren't cached)
resp2 := mkJsonRpcRequest(t, proxyServiceURL, 1, tc.method, tc.params)
require.Equal(t, cachemdw.CacheMissHeaderValue, resp2.Header[cachemdw.CacheHeaderKey][0])
body2, err := io.ReadAll(resp2.Body)
require.NoError(t, err)
err = checkJsonRpcErr(body2)
if tc.errorMsg != "" {
require.Error(t, err)
require.Contains(t, err.Error(), tc.errorMsg)
}
expectKeysNum(t, redisClient, tc.keysNum)
})
}

cleanUpRedis(t, redisClient)
}

func TestE2ETestCachingMdwWithBlockNumberParam_DiffJsonRpcReqIDs(t *testing.T) {
redisClient := redis.NewClient(&redis.Options{
Addr: redisURL,
Expand Down

0 comments on commit 5df4cda

Please sign in to comment.