Skip to content

Commit

Permalink
Add e2e test for error result scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Nov 15, 2023
1 parent 6ba6254 commit 20930a8
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,58 @@ func TestE2ETestCachingMdwWithBlockNumberParam_EmptyResult(t *testing.T) {
cleanUpRedis(t, redisClient)
}

func TestE2ETestCachingMdwWithBlockNumberParam_ErrorResult(t *testing.T) {
testRandomAddressHex := "0x6767114FFAA17C6439D7AEA480738B982CE63A02"
testAddress := common.HexToAddress(testRandomAddressHex)

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
}{
{
desc: "test case #1",
method: "eth_getBalance",
params: []interface{}{testAddress, "0x3B9ACA00"}, // block # 1000_000_000, which doesn't exist
keysNum: 0,
},
} {
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)
require.Error(t, err)
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)
require.Error(t, err)
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 20930a8

Please sign in to comment.