From ca31d2e17f107eb693ef54d3db7dc716b33d7c5d Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 13 Jun 2023 02:33:52 -0700 Subject: [PATCH] add pytest-pdb hook --- boa/environment.py | 9 +++++++-- boa/test/plugin.py | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/boa/environment.py b/boa/environment.py index e3f769d6..484ab7a1 100644 --- a/boa/environment.py +++ b/boa/environment.py @@ -288,7 +288,8 @@ def __init__(self): def get_gas_price(self): return self._gas_price or 0 - def _restore_journal_state_from_computation(self, computation): + def _restore_journal_state_from_computation(self, computation=None): + computation = computation or self._computation db = self.vm.state._account_db ( ( @@ -577,6 +578,8 @@ def deploy_code( self.vm.state, msg, tx_ctx ) + self._computation = c + if c.is_error: raise c.error @@ -625,7 +628,9 @@ class FakeMessage(Message): # Message object with settable attrs msg._contract = contract # type: ignore origin = sender # XXX: consider making this parametrizable tx_ctx = BaseTransactionContext(origin=origin, gas_price=self.get_gas_price()) - return self.vm.state.computation_class.apply_message(self.vm.state, msg, tx_ctx) + ret = self.vm.state.computation_class.apply_message(self.vm.state, msg, tx_ctx) + self._computation = ret + return ret # function to time travel def time_travel( diff --git a/boa/test/plugin.py b/boa/test/plugin.py index 1a9d679c..42f1338c 100644 --- a/boa/test/plugin.py +++ b/boa/test/plugin.py @@ -72,6 +72,8 @@ def _toggle_profiling(enabled: bool = False) -> Generator: else: yield +def pytest_enter_pdb(config, pdb): + boa.env._restore_journal_state_from_computation() def pytest_sessionfinish(session, exitstatus): if boa.env._cached_call_profiles: