rpc.launch(cmd, **cmd_settings)
def _attach_debugger() -> None:
# TODO Implement `ipdb` package functionalities
# This function relies on `ipdb` internal functions
# We could implement all the `ipdb` functionalities ourselves (it is rather small codebase)
if sys.excepthook != BdbQuit_excepthook:
BdbQuit_excepthook.excepthook_ori = sys.excepthook
sys.excepthook = BdbQuit_excepthook
p = _init_pdb(
commands=["import IPython", "alias embed() IPython.embed(colors='neutral')"]
)
p.reset()
p.interaction(None, sys.exc_info()[2])
def _run_core(
fuzz_test: Callable,
index: int,
port: int,
random_seed: bytes,
finished_event: multiprocessing.synchronize.Event,
child_conn: multiprocessing.connection.Connection,
):
print(f"Using seed '{random_seed.hex()}' for process #{index}")
_setup(port)
project = brownie.project.load()
brownie.chain.reset()
args = []
for arg in inspect.getfullargspec(fuzz_test).args:
if arg in {"a", "accounts"}:
args.append(brownie.accounts)
elif arg == "chain":
args.append(brownie.chain)
elif arg == "Contract":
args.append(brownie.Contract)
elif arg == "history":
args.append(brownie.history)
elif arg == "interface":
args.append(project.interface)
elif arg == "rpc":
args.append(brownie.rpc)
elif arg == "web3":
args.append(brownie.web3)
elif arg in project.keys():
args.append(project[arg])
else:
raise ValueError(
f"Unable to set value for '{arg}' argument in '{fuzz_test.__name__}' function."
)
fuzz_test(*args)
child_conn.send(None)
finished_event.set()
def _run(
fuzz_test: Callable,
index: int,
port: int,
random_seed: bytes,
log_file: Path,
tee: bool,
finished_event: multiprocessing.synchronize.Event,
child_conn: multiprocessing.connection.Connection,
):
pickling_support.install()
random.seed(random_seed)
if not tee:
logging.basicConfig(filename=log_file)
try:
if tee:
with closing(Tee(log_file)):
_run_core(
fuzz_test, index, port, random_seed, finished_event, child_conn
)
else:
with log_file.open("w") as f, redirect_stdout(f), redirect_stderr(f):
_run_core(
fuzz_test, index, port, random_seed, finished_event, child_conn
)
except Exception:
child_conn.send(pickle.dumps(sys.exc_info()))
finished_event.set()
try:
attach: bool = child_conn.recv()
if attach:
sys.stdin = os.fdopen(0)
_attach_debugger()
finally:
finished_event.set()
finally:
with log_file.open("a") as f, redirect_stdout(f), redirect_stderr(f):
rpc.kill()
def fuzz(
config: WokeConfig,
fuzz_test: types.FunctionType,
process_count: int,
seeds: Iterable[bytes],
logs_dir: Path,
passive: bool,
):
random_seeds = list(seeds)
if len(random_seeds) < process_count:
for i in range(process_count - len(random_seeds)):