Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
erwin-wee committed Jan 31, 2024
1 parent 3a74d1a commit 55e269c
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 201 deletions.
12 changes: 6 additions & 6 deletions chainbench/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ def start(


def validate_clients(ctx: Context, param: Parameter, value: str) -> list[str]:
from chainbench.tools.discovery.rpc import RPCDiscovery
from chainbench.tools.discovery.rpc import RpcDiscovery

if value is not None:
input_client_list = value.split(",")
client_list: list[str] = []
for client in RPCDiscovery.get_clients():
for client in RpcDiscovery.get_clients():
client_list.extend(client.get_cli_argument_names())
for client_name in input_client_list:
if client_name not in client_list:
Expand Down Expand Up @@ -423,9 +423,9 @@ def discover(endpoint: str | None, clients: list[str]) -> None:
click.echo("Target endpoint is required.")
sys.exit(1)

from chainbench.tools.discovery.rpc import RPCDiscovery
from chainbench.tools.discovery.rpc import RpcDiscovery

rpc_discovery = RPCDiscovery(endpoint, clients)
rpc_discovery = RpcDiscovery(endpoint, clients)
click.echo(f"Please wait, discovering methods available on {endpoint}...")

def get_discovery_result(method: str) -> None:
Expand All @@ -445,9 +445,9 @@ def _list() -> None:
help="Lists all available client options for method discovery.",
)
def clients() -> None:
from chainbench.tools.discovery.rpc import RPCDiscovery
from chainbench.tools.discovery.rpc import RpcDiscovery

for client in RPCDiscovery.get_clients():
for client in RpcDiscovery.get_clients():
for unique_client in client.get_name_and_version():
click.echo(unique_client)

Expand Down
26 changes: 13 additions & 13 deletions chainbench/profile/avalanche/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AvalancheProfile(EvmUser):

@task(100)
def call_task(self):
self.make_call(
self.make_rpc_call(
name="call",
method="eth_call",
params=[
Expand All @@ -41,53 +41,53 @@ def call_task(self):

@task(50)
def get_block_by_number_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_number",
method="eth_getBlockByNumber",
params=self._block_params_factory(),
),

@task(17)
def get_transaction_receipt_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_receipt",
method="eth_getTransactionReceipt",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(15)
def chain_id_task(self):
self.make_call(
self.make_rpc_call(
name="chain_id",
method="eth_chainId",
),

@task(15)
def block_number_task(self):
self.make_call(
self.make_rpc_call(
name="block_number",
method="eth_blockNumber",
),

@task(11)
def get_balance_task(self):
self.make_call(
self.make_rpc_call(
name="get_balance",
method="eth_getBalance",
params=self._get_account_and_block_number_params_factory_latest(get_rng()),
),

@task(10)
def get_transaction_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_by_hash",
method="eth_getTransactionByHash",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(5)
def estimate_gas_task(self):
self.make_call(
self.make_rpc_call(
name="estimate_gas",
method="eth_estimateGas",
params=[
Expand All @@ -101,29 +101,29 @@ def estimate_gas_task(self):

@task(4)
def client_version_task(self):
self.make_call(
self.make_rpc_call(
name="client_version",
method="web3_clientVersion",
),

@task(3)
def get_block_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_hash",
method="eth_getBlockByHash",
params=self._block_by_hash_params_factory(get_rng()),
),

@task(3)
def gas_price_task(self):
self.make_call(
self.make_rpc_call(
name="gas_price",
method="eth_gasPrice",
),

@task(3)
def max_priority_fee_per_gas_task(self):
self.make_call(
self.make_rpc_call(
name="max_priority_fee_per_gas",
method="eth_maxPriorityFeePerGas",
),
Expand All @@ -136,7 +136,7 @@ class AvalancheGetLogsProfile(EvmUser):
@tag("get-logs")
@task
def get_logs_task(self):
self.make_call(
self.make_rpc_call(
name="get_logs",
method="eth_getLogs",
params=self._get_logs_params_factory(get_rng()),
Expand Down
18 changes: 9 additions & 9 deletions chainbench/profile/bsc/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BscProfile(EvmUser):

@task(100)
def call_task(self):
self.make_call(
self.make_rpc_call(
name="call",
method="eth_call",
params=[
Expand All @@ -40,53 +40,53 @@ def call_task(self):

@task(93)
def get_transaction_receipt_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_receipt",
method="eth_getTransactionReceipt",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(28)
def block_number_task(self):
self.make_call(
self.make_rpc_call(
name="block_number",
method="eth_blockNumber",
),

@task(18)
def chain_id_task(self):
self.make_call(
self.make_rpc_call(
name="chain_id",
method="eth_chainId",
),

@task(13)
def get_block_by_number_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_number",
method="eth_getBlockByNumber",
params=self._block_params_factory(),
),

@task(9)
def get_transaction_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_by_hash",
method="eth_getTransactionByHash",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(5)
def get_balance_task(self):
self.make_call(
self.make_rpc_call(
name="get_balance",
method="eth_getBalance",
params=self._get_account_and_block_number_params_factory_latest(get_rng()),
),

@task(3)
def get_block_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_hash",
method="eth_getBlockByHash",
params=self._block_by_hash_params_factory(get_rng()),
Expand All @@ -100,7 +100,7 @@ class BscGetLogsProfile(EvmUser):
@tag("get-logs")
@task
def get_logs_task(self):
self.make_call(
self.make_rpc_call(
name="get_logs",
method="eth_getLogs",
params=self._get_logs_params_factory(get_rng()),
Expand Down
20 changes: 10 additions & 10 deletions chainbench/profile/ethereum/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,53 @@ class EthereumProfile(EvmUser):

@task(100)
def call_task(self):
self.make_call(
self.make_rpc_call(
name="call",
method="eth_call",
params=self._erc20_eth_call_params_factory(get_rng()),
),

@task(24)
def get_transaction_receipt_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_receipt",
method="eth_getTransactionReceipt",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(19)
def block_number_task(self):
self.make_call(
self.make_rpc_call(
name="block_number",
method="eth_blockNumber",
),

@task(12)
def get_balance_task(self):
self.make_call(
self.make_rpc_call(
name="get_balance",
method="eth_getBalance",
params=self._get_account_and_block_number_params_factory_latest(get_rng()),
),

@task(11)
def chain_id_task(self):
self.make_call(
self.make_rpc_call(
name="chain_id",
method="eth_chainId",
),

@task(9)
def get_block_by_number_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_number",
method="eth_getBlockByNumber",
params=self._block_params_factory(),
),

@task(8)
def get_transaction_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_by_hash",
method="eth_getTransactionByHash",
params=self._transaction_by_hash_params_factory(get_rng()),
Expand All @@ -82,14 +82,14 @@ def get_transaction_by_hash_task(self):
@tag("debug")
@task(3)
def trace_transaction_task(self):
self.make_call(
self.make_rpc_call(
name="trace_transaction",
method="debug_traceTransaction",
),

@task(2)
def client_version_task(self):
self.make_call(
self.make_rpc_call(
name="client_version",
method="web3_clientVersion",
),
Expand All @@ -102,7 +102,7 @@ class EthGetLogsProfile(EvmUser):
@tag("get-logs")
@task
def get_logs_task(self):
self.make_call(
self.make_rpc_call(
name="get_logs",
method="eth_getLogs",
params=self._get_logs_params_factory(get_rng()),
Expand Down
8 changes: 4 additions & 4 deletions chainbench/profile/evm/debug_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ class EvmDebugTraceProfile(EvmUser):

@task(324)
def debug_trace_transaction_task(self):
self.make_call(
self.make_rpc_call(
name="debug_trace_transaction",
method="debug_traceTransaction",
params=self._debug_trace_transaction_params_factory(get_rng()),
),

@task(41)
def debug_trace_call_task(self):
self.make_call(
self.make_rpc_call(
name="debug_trace_call",
method="debug_traceCall",
params=self._debug_trace_call_params_factory(get_rng()),
),

@task(36)
def debug_trace_block_by_number_task(self):
self.make_call(
self.make_rpc_call(
name="debug_trace_block_by_number",
method="debug_traceBlockByNumber",
params=self._debug_trace_block_by_number_params_factory(),
),

@task(1)
def debug_trace_block_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="debug_trace_block_by_hash",
method="debug_traceBlockByHash",
params=self._debug_trace_block_by_hash_params_factory(get_rng()),
Expand Down
2 changes: 1 addition & 1 deletion chainbench/profile/evm/get_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EvmGetLogsProfile(EvmUser):

@task
def get_logs_task(self):
self.make_call(
self.make_rpc_call(
name="get_logs",
method="eth_getLogs",
params=self._get_logs_params_factory(get_rng()),
Expand Down
Loading

0 comments on commit 55e269c

Please sign in to comment.