CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-web3

A Python library for interacting with Ethereum blockchain

Overall
score

88%

Evaluation88%

1.01x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-6/

Request Logging Middleware

Goal { .goal }

Implement a request logging system for Ethereum JSON-RPC calls that tracks all requests and responses through a custom middleware component.

Requirements { .requirements }

Create a middleware component that:

  1. Logs all JSON-RPC method calls with their parameters before they are sent
  2. Logs the responses received from the Ethereum node
  3. Tracks the total number of requests made during the session
  4. Provides a method to retrieve the call history

The middleware should capture:

  • The JSON-RPC method name
  • Request parameters (if any)
  • Response data
  • Timestamp of each request

Implement a RequestLogger class with:

  • A method get_middleware() that returns the middleware function
  • A method get_request_count() that returns the total number of requests made
  • A method get_call_history() that returns a list of all logged calls

Each entry in the call history should be a dictionary containing:

  • method: the JSON-RPC method name
  • params: the request parameters
  • response: the response data
  • timestamp: ISO format timestamp string

Test Cases { .test-cases }

Test 1: Middleware logs requests { .test-case @test }

Setup:

  • Create a Web3 instance connected to a test provider
  • Attach the request logger middleware
  • Make a request to get the latest block number

Expected:

  • The request count should be 1
  • The call history should contain one entry with method name and response

Test 2: Multiple requests are tracked { .test-case @test }

Setup:

  • Create a Web3 instance with the request logger middleware
  • Make three different requests (e.g., get block number, get chain ID, get gas price)

Expected:

  • The request count should be 3
  • The call history should contain three entries in chronological order
  • Each entry should have the correct method name and valid timestamp

Test 3: Request parameters are captured { .test-case @test }

Setup:

  • Create a Web3 instance with the request logger middleware
  • Make a request that requires parameters (e.g., get block by number)

Expected:

  • The call history entry should contain the parameters passed to the request
  • The response data should match the expected block information

Dependencies { .dependencies }

web3 { .dependency }

A Python library for interacting with Ethereum blockchain, providing middleware support for request pipeline customization.

Implementation { .implementation }

Create the following files:

request_logger.py { .implementation-file }

Implement the RequestLogger class with the required methods.

test_request_logger.py { .implementation-file @test }

Implement the test cases to verify the middleware functionality.

Install with Tessl CLI

npx tessl i tessl/pypi-web3

tile.json