Skip to content

Commit

Permalink
Fix : Mock HasTTL() to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OBlackmon3 committed Sep 13, 2024
1 parent b637ab7 commit 7709b48
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions erpc/evm_json_rpc_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":{"hash":"0xabc","blockNumber":"0x2"}}`))

mockConnector.On("Set", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)

err := cache.Set(context.Background(), req, resp)

Expand All @@ -95,6 +96,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":{"hash":"0xabc","number":"0x2"}}`))

mockConnector.On("Set", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)

err := cache.Set(context.Background(), req, resp)

Expand Down Expand Up @@ -147,6 +149,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
resp := common.NewNormalizedResponse().WithBody([]byte(tc.result))

mockConnector.On("Set", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)

err := cache.Set(context.Background(), req, resp)

Expand All @@ -166,6 +169,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":{"number":"0x1","hash":"0xabc"}}`))

mockConnector.On("Set", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)

err := cache.Set(context.Background(), req, resp)

Expand All @@ -179,6 +183,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
req := common.NewNormalizedRequest([]byte(`{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x399",false],"id":1}`))
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":{"number":"0x399","hash":"0xdef"}}`))

mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)
err := cache.Set(context.Background(), req, resp)

assert.NoError(t, err)
Expand All @@ -192,6 +197,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
req.SetNetwork(mockNetwork)
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":"0x0"}`))

mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)
err := cache.Set(context.Background(), req, resp)

assert.NoError(t, err)
Expand All @@ -205,6 +211,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
req.SetNetwork(mockNetwork)
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":"0x0"}`))

mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)
err := cache.Set(context.Background(), req, resp)

assert.NoError(t, err)
Expand All @@ -218,6 +225,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
req.SetNetwork(mockNetwork)
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":"0x0"}`))

mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)
err := cache.Set(context.Background(), req, resp)

assert.NoError(t, err)
Expand All @@ -231,6 +239,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
req.SetNetwork(mockNetwork)
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":"0x0"}`))

mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)
err := cache.Set(context.Background(), req, resp)

assert.NoError(t, err)
Expand All @@ -245,6 +254,7 @@ func TestEvmJsonRpcCache_Set(t *testing.T) {
resp := common.NewNormalizedResponse().WithBody([]byte(`{"result":"0x0"}`))

mockConnector.On("Set", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)

err := cache.Set(context.Background(), req, resp)

Expand All @@ -262,6 +272,7 @@ func TestEvmJsonRpcCache_Get(t *testing.T) {

cachedResponse := `{"number":"0x1","hash":"0xabc"}`
mockConnector.On("Get", mock.Anything, mock.Anything, "evm:123:1", mock.Anything).Return(cachedResponse, nil)
mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)

resp, err := cache.Get(context.Background(), req)

Expand All @@ -278,6 +289,7 @@ func TestEvmJsonRpcCache_Get(t *testing.T) {

req := common.NewNormalizedRequest([]byte(`{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x32345",false],"id":1}`))
req.SetNetwork(mockNetwork)
mockConnector.On("HasTTL", mock.AnythingOfType("string")).Return(false)
resp, err := cache.Get(context.Background(), req)

assert.NoError(t, err)
Expand Down

0 comments on commit 7709b48

Please sign in to comment.