Skip to content

Commit

Permalink
Update tests to reflect that failure callbacks must be provided when …
Browse files Browse the repository at this point in the history
…queueing a transaction.

Update tests to reflect that txs are no longer requeued because of failure, but instead remain at the front of the queue unless the user takes more aggressive action to remove the tx from the queue.
  • Loading branch information
derekpierre committed Apr 4, 2024
1 parent d383fcf commit 08b0031
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 147 deletions.
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ def machine(w3, strategies):
_machine.stop()


@pytest.fixture
def broadcast_failure_hook(mocker):
return mocker.Mock()


@pytest.fixture
def fault_hook(mocker):
return mocker.Mock()


@pytest.fixture
def clock(machine):
return machine._task.clock
Expand Down
4 changes: 4 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ def test_machine(
machine,
clock,
mock_wake_sleep,
broadcast_failure_hook,
fault_hook,
):
assert not machine.busy
async_txs = machine.queue_transactions(
params=[legacy_transaction, eip1559_transaction],
signer=account,
info={"message": "something wonderful is happening..."},
on_broadcast_failure=broadcast_failure_hook,
on_fault=fault_hook,
)

assert len(async_txs) == 2
Expand Down
44 changes: 35 additions & 9 deletions tests/test_faults.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
from atxm.utils import _get_receipt_from_txhash


def _broadcast_tx(machine, eip1559_transaction, account, mocker):
fault_hook = mocker.Mock()

def _broadcast_tx(
machine, eip1559_transaction, account, broadcast_failure_hook, fault_hook
):
atx = machine.queue_transaction(
params=eip1559_transaction,
signer=account,
on_broadcast_failure=broadcast_failure_hook,
on_fault=fault_hook,
)

Expand All @@ -26,7 +27,7 @@ def _broadcast_tx(machine, eip1559_transaction, account, mocker):
assert atx.final is False
assert atx.fault is None

return atx, fault_hook
return atx


@pytest_twisted.inlineCallbacks
Expand Down Expand Up @@ -58,9 +59,13 @@ def test_revert(
account,
interval,
mock_wake_sleep,
broadcast_failure_hook,
fault_hook,
mocker,
):
atx, fault_hook = _broadcast_tx(machine, eip1559_transaction, account, mocker)
atx = _broadcast_tx(
machine, eip1559_transaction, account, broadcast_failure_hook, fault_hook
)

assert machine.pending

Expand All @@ -78,14 +83,25 @@ def test_revert(

@pytest.mark.usefixtures("disable_auto_mining")
def test_strategy_fault(
w3, machine, clock, eip1559_transaction, account, interval, mock_wake_sleep, mocker
w3,
machine,
clock,
eip1559_transaction,
account,
interval,
mock_wake_sleep,
broadcast_failure_hook,
fault_hook,
mocker,
):
faulty_strategy = mocker.Mock(spec=AsyncTxStrategy)

# TODO: consider whether strategies should just be overridden through the constructor
machine._strategies.insert(0, faulty_strategy) # add first

atx, fault_hook = _broadcast_tx(machine, eip1559_transaction, account, mocker)
atx = _broadcast_tx(
machine, eip1559_transaction, account, broadcast_failure_hook, fault_hook
)

faulty_message = "mocked fault"
faulty_strategy.execute.side_effect = TransactionFaulted(
Expand All @@ -99,9 +115,19 @@ def test_strategy_fault(

@pytest.mark.usefixtures("disable_auto_mining")
def test_timeout_strategy_fault(
w3, machine, clock, eip1559_transaction, account, interval, mock_wake_sleep, mocker
w3,
machine,
clock,
eip1559_transaction,
account,
interval,
mock_wake_sleep,
broadcast_failure_hook,
fault_hook,
):
atx, fault_hook = _broadcast_tx(machine, eip1559_transaction, account, mocker)
atx = _broadcast_tx(
machine, eip1559_transaction, account, broadcast_failure_hook, fault_hook
)

atx.created -= 9999999999

Expand Down
Loading

0 comments on commit 08b0031

Please sign in to comment.