From b23d1a861ceda80c3827bcf94ae99ed859d38e0f Mon Sep 17 00:00:00 2001 From: Karim TAAM Date: Fri, 3 Nov 2023 10:43:19 +0100 Subject: [PATCH] add debug trace transaction test --- .../object_generators/call_generators.py | 27 ++++++++++++++++ flood/generators/test_generators/__init__.py | 1 + .../test_generators/debug_test_generators.py | 31 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 flood/generators/test_generators/debug_test_generators.py diff --git a/flood/generators/object_generators/call_generators.py b/flood/generators/object_generators/call_generators.py index c8b5dda..df1b5bb 100644 --- a/flood/generators/object_generators/call_generators.py +++ b/flood/generators/object_generators/call_generators.py @@ -575,6 +575,33 @@ def generate_calls_trace_replay_transaction( ] +def generate_calls_debug_trace_transaction( + n_calls: int | None = None, + *, + transaction_hashes: typing.Sequence[str] | None = None, + network: str | None = None, + random_seed: flood.RandomSeed | None = None, +) -> typing.Sequence[flood.Call]: + import ctc.rpc + + if transaction_hashes is None: + if n_calls is None: + raise Exception('must floodify more parameters') + if network is None: + raise Exception('must floodify network') + transaction_hashes = transaction_generators.generate_transaction_hashes( + n=n_calls, + random_seed=random_seed, + network=network, + ) + return [ + ctc.rpc.construct_debug_trace_transaction( + transaction_hash + ) + for transaction_hash in transaction_hashes + ] + + def generate_calls_trace_replay_transaction_state_diff( n_calls: int | None = None, *, diff --git a/flood/generators/test_generators/__init__.py b/flood/generators/test_generators/__init__.py index 0359bf3..867d227 100644 --- a/flood/generators/test_generators/__init__.py +++ b/flood/generators/test_generators/__init__.py @@ -6,3 +6,4 @@ from .multi_test_generators import * from .transaction_test_generators import * from .trace_test_generators import * +from .debug_test_generators import * diff --git a/flood/generators/test_generators/debug_test_generators.py b/flood/generators/test_generators/debug_test_generators.py new file mode 100644 index 0000000..c10281e --- /dev/null +++ b/flood/generators/test_generators/debug_test_generators.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +import typing + +import flood +from flood.tests import load_tests + +def generate_test_debug_trace_transaction( + *, + network: str, + rates: typing.Sequence[int], + duration: int | None = None, + durations: typing.Sequence[int] | None = None, + vegeta_args: flood.VegetaArgsShorthand | None = None, + random_seed: flood.RandomSeed | None = None, +) -> typing.Sequence[flood.VegetaAttack]: + n_calls = load_tests.estimate_call_count( + rates=rates, duration=duration, durations=durations + ) + calls = flood.generators.generate_calls_debug_trace_transaction( + n_calls=n_calls, + network=network, + random_seed=random_seed, + ) + return load_tests.create_load_test( + calls=calls, + rates=rates, + duration=duration, + durations=durations, + vegeta_args=vegeta_args, + )