Skip to content

Commit

Permalink
Minor refactoring and bugfixes (#41)
Browse files Browse the repository at this point in the history
- BlockchainDataSize namedtuple to frozen dataclass
- set Sizes class as frozen dataclass
- fix HTTP errors to display properly in report
- fix monitor logger name
- fix __initi__ files
- fix wrong test data sizes
- make estimate gas fee params factory use randomized "to" param
  • Loading branch information
erwin-wee authored Dec 14, 2023
1 parent 5149a52 commit b8b255b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions chainbench/test_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from .dummy import DummyTestData
from .evm import EVMTestData
from .solana import SolanaTestData
from .starknet import StarkNetTestData

__all__ = [
"BaseTestData",
"DummyTestData",
"EVMTestData",
"SolanaTestData",
"StarkNetTestData",
]
17 changes: 10 additions & 7 deletions chainbench/test_data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import typing as t
from argparse import Namespace
from collections import namedtuple
from dataclasses import dataclass, field
from secrets import token_hex

Expand All @@ -24,25 +23,29 @@
Blocks = list[tuple[BlockNumber, BlockHash]]


BlockchainDataSize = namedtuple("BlockchainDataSize", ["blocks", "txs", "accounts"])
@dataclass(frozen=True)
class BlockchainDataSize:
blocks: int
txs: int
accounts: int


@dataclass
@dataclass(frozen=True)
class Sizes:
S = BlockchainDataSize(10, 100, 100)
M = BlockchainDataSize(100, 1000, 1000)
L = BlockchainDataSize(1000, 10000, 100000)
XL = BlockchainDataSize(10000, 100000, 1000000)
L = BlockchainDataSize(1000, 10000, 10000)
XL = BlockchainDataSize(10000, 100000, 100000)

@classmethod
def get_size(cls, size: str):
def get_size(cls, size: str) -> BlockchainDataSize:
try:
return getattr(cls, size.upper())
except AttributeError:
raise ValueError(f"Invalid size: '{size}'. Valid Sizes are S, M, L, XL")

@classmethod
def get_custom_size(cls, blocks: int, txs: int, accounts: int):
def get_custom_size(cls, blocks: int, txs: int, accounts: int) -> BlockchainDataSize:
return BlockchainDataSize(blocks, txs, accounts)


Expand Down
6 changes: 4 additions & 2 deletions chainbench/user/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ def check_response(self, response: RestResponseContextManager, name: str):
"""Check the response for errors."""
if response.status_code != 200:
self.logger.info(f"Request failed with {response.status_code} code")
self.logger.debug(f"Request to {response.url} failed with {response.status_code} code: {response.text}")
self.logger.debug(
f"Request to {response.url} failed with HTTP Error {response.status_code} code: {response.text}"
)
self.check_fatal(response)
response.failure(f"Request failed with {response.status_code} code")
response.raise_for_status()
return

if response_json is None:
self.logger.error(f"Response for {name} is not a JSON: {response.text}")
Expand Down
2 changes: 1 addition & 1 deletion chainbench/user/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ def _eth_estimate_gas_params_factory(self, rng: RNG):
return [
{
"from": self.test_data.get_random_account(rng),
"to": "0x18318221d811Da0fe45412394eAf2C42A10BC678",
"to": self.test_data.get_random_account(rng),
}
]
2 changes: 1 addition & 1 deletion chainbench/user/starknet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from chainbench.test_data.starknet import StarkNetTestData
from chainbench.test_data import StarkNetTestData
from chainbench.user.base import BaseBenchUser
from chainbench.util.rng import RNG

Expand Down
2 changes: 1 addition & 1 deletion chainbench/util/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import httpx
from locust.util.timespan import parse_timespan

logger = logging.getLogger()
logger = logging.getLogger(__name__)


def calculate_lag(current_timestamp, block_timestamp):
Expand Down

0 comments on commit b8b255b

Please sign in to comment.