Skip to content

Commit

Permalink
cache fixes for e2e tests (#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj authored Feb 20, 2024
1 parent b70a894 commit 038f6a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions tools/walletextension/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ var cacheableRPCMethods = map[string]time.Duration{
"eth_chainId": longCacheTTL,

// Ethereum JSON-RPC methods that can be cached short time
"eth_blockNumber": shortCacheTTL,
"eth_getCode": shortCacheTTL,
"eth_getBalance": shortCacheTTL,
"eth_blockNumber": shortCacheTTL,
"eth_getCode": shortCacheTTL,
// "eth_getBalance": shortCacheTTL,// excluded for test: gen_cor_059
"eth_getTransactionReceipt": shortCacheTTL,
"eth_call": shortCacheTTL,
"eth_gasPrice": shortCacheTTL,
"eth_getTransactionCount": shortCacheTTL,
"eth_estimateGas": shortCacheTTL,
"eth_feeHistory": shortCacheTTL,
// "eth_getTransactionCount": shortCacheTTL, // excluded for test: gen_cor_009
"eth_estimateGas": shortCacheTTL,
"eth_feeHistory": shortCacheTTL,
}

type Cache interface {
Expand Down
4 changes: 2 additions & 2 deletions tools/walletextension/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func testNonCacheableMethods(t *testing.T) {

// testMethodsWithLatestOrPendingParameter tests if the methods with latest or pending parameter are cacheable
func testMethodsWithLatestOrPendingParameter(t *testing.T) {
methods := []string{"eth_getCode", "eth_getBalance", "eth_getTransactionCount", "eth_estimateGas", "eth_call"}
methods := []string{"eth_getCode", "eth_estimateGas", "eth_call"}
for _, method := range methods {
key := &common.RPCRequest{Method: method, Params: []interface{}{"0x123", "latest"}}
_, _, ttl := IsCacheable(key)
Expand Down Expand Up @@ -110,7 +110,7 @@ func testResultsAreCached(cache Cache, t *testing.T) {

// testCacheTTL tests if the cache TTL is working as expected
func testCacheTTL(cache Cache, t *testing.T) {
req := &common.RPCRequest{Method: "eth_getBalance", Params: []interface{}{"0x123"}}
req := &common.RPCRequest{Method: "eth_blockNumber", Params: []interface{}{"0x123"}}
res := map[string]interface{}{"result": "100"}
isCacheable, key, ttl := IsCacheable(req)

Expand Down
12 changes: 7 additions & 5 deletions tools/walletextension/wallet_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func (w *WalletExtension) Logger() gethlog.Logger {

// ProxyEthRequest proxys an incoming user request to the enclave
func (w *WalletExtension) ProxyEthRequest(request *common.RPCRequest, conn userconn.UserConn, hexUserID string) (map[string]interface{}, error) {
response := map[string]interface{}{}
// all responses must contain the request id. Both successful and unsuccessful.
response[common.JSONKeyRPCVersion] = jsonrpc.Version
response[common.JSONKeyID] = request.ID

// start measuring time for request
requestStartTime := time.Now()

Expand All @@ -111,15 +116,12 @@ func (w *WalletExtension) ProxyEthRequest(request *common.RPCRequest, conn userc
requestEndTime := time.Now()
duration := requestEndTime.Sub(requestStartTime)
w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s, response: %s, duration: %d ", request.Method, request.Params, hexUserID, value, duration.Milliseconds()))
// adjust requestID
value[common.JSONKeyID] = request.ID
return value, nil
}
}

response := map[string]interface{}{}
// all responses must contain the request id. Both successful and unsuccessful.
response[common.JSONKeyRPCVersion] = jsonrpc.Version
response[common.JSONKeyID] = request.ID

// proxyRequest will find the correct client to proxy the request (or try them all if appropriate)
var rpcResp interface{}

Expand Down

0 comments on commit 038f6a6

Please sign in to comment.