Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache fixes for e2e tests #1803

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading