Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional testing for tracker and tx modules - mostly around serialization/deserialization #30

Merged
merged 70 commits into from
Mar 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
73e3e0e
AsyncTxStrategy should do one of the following during execute: raise …
derekpierre Mar 1, 2024
013279c
Adjust strategies to accomodate latest paradigm for execute i.e. retu…
derekpierre Mar 1, 2024
9c2ec6e
Adjust existing strategy tests since None can now be returned from ex…
derekpierre Mar 1, 2024
39b4b36
Update timeout strategy logging.
derekpierre Mar 3, 2024
cf88810
Update speedup strategy calcs to use math.ceil instead of round
derekpierre Mar 3, 2024
1c01980
Move from a fixed max tip to a max tip factor based on the current su…
derekpierre Mar 4, 2024
352f74a
Simplify legacy transaction speedup logic.
derekpierre Mar 4, 2024
0be4f52
Add tests for constructor parameters and legacy tx speed up functiona…
derekpierre Mar 4, 2024
c023dea
Update logging of gas conditions.
derekpierre Mar 4, 2024
979f3f9
Better annotations about what the strategy is doing.
derekpierre Mar 4, 2024
9589151
Don't modify tx nonce as part of strategy.
derekpierre Mar 4, 2024
b66f5af
Fix outdated comment about value of warn factor.
derekpierre Mar 4, 2024
bf13194
Clean up logging logic since old_tip, old_max_fee may or may not be p…
derekpierre Mar 4, 2024
f7bd316
Add tests for eip1559 transaction speedup.
derekpierre Mar 4, 2024
699d38f
Rename speed up strategy; while the rate value is fixed the updates a…
derekpierre Mar 4, 2024
3755667
Use constant instead of "maxPriorityFeePerGas".
derekpierre Mar 4, 2024
16c2ed3
Use constant for minimum required speedup increase percentage.
derekpierre Mar 4, 2024
1c67055
Use a max between a low default value and warn factor calc in case ti…
derekpierre Mar 4, 2024
f8cf36b
Add todo about best way of setting a cap on the speedup strategy.
derekpierre Mar 4, 2024
1f1fb28
Use reactor to determine when hook is called instead of repeatedly ca…
derekpierre Mar 4, 2024
abb8555
Add TODO to determine whether strategies can be overriden.
derekpierre Mar 4, 2024
5491a6e
Update logging category for monitor when no longer tracking tx.
derekpierre Mar 5, 2024
2a9c0b5
Use enable/disabling of auto mining for better testing.
derekpierre Mar 5, 2024
436ce64
Fix nonce logging message for strategies.
derekpierre Mar 5, 2024
c7851ae
Add the ability to update the tracker's active pending tx after a retry.
derekpierre Mar 5, 2024
7e647c0
Ensure that "from" value in tx params matches/equals signer.
derekpierre Mar 5, 2024
283ba70
Make __fire reusable by both broadcast and strategize - it is now lim…
derekpierre Mar 5, 2024
bd27cbf
Add tests to ensure that strategies are employed when a tx hasn't alr…
derekpierre Mar 5, 2024
25ad0b5
Add testing for "from" tx parameter handling when a tx is being queued.
derekpierre Mar 6, 2024
adac77d
Add test for strategies which do not make updates to parameters.
derekpierre Mar 6, 2024
dc6cda3
Add testing statements to ensure that the broadcast hook is also call…
derekpierre Mar 6, 2024
28f67f4
txhash is not optionally returned from __fire - either it is or an ex…
derekpierre Mar 6, 2024
a7eff18
Potential specialized handling of error cases when firing a tx; this …
derekpierre Mar 6, 2024
9ea695c
Commonize check for recoverable type of error after calling sendRawTr…
derekpierre Mar 6, 2024
f42264d
Insufficient funds is really a special case and its own exception, no…
derekpierre Mar 6, 2024
9013c0d
Fix firing of hook with only ordered args.
derekpierre Mar 6, 2024
f5ecc5a
Add test for unrecoverable errors encoutered when trying to broadcast…
derekpierre Mar 6, 2024
4905e07
Add test for recoverable errors encoutered when trying to broadcast a…
derekpierre Mar 7, 2024
d695078
Add test for unrecoverable errors encoutered when trying to retry a tx.
derekpierre Mar 7, 2024
e000b64
Retry failures should be treated differently than broadcast failures.…
derekpierre Mar 7, 2024
b744a93
Make methods on TxTracker public instead of protected.
derekpierre Mar 7, 2024
431462e
Use a counter for tracking number of requeue attempts for failed txs …
derekpierre Mar 7, 2024
290fd65
Use a counter for tracking number of failed retry attempts when using…
derekpierre Mar 7, 2024
5c42f80
Update existing tests given limits on requeue/retry (redo) attempts.
derekpierre Mar 7, 2024
189b2dd
Add test for exceeding retries when encountering a broadcast error.
derekpierre Mar 7, 2024
f4670ac
Add additional assertions for the requeue counter in existing tests.
derekpierre Mar 7, 2024
c370dea
Existing retry test cleanup.
derekpierre Mar 7, 2024
f59aa74
Add test for exceeding retries when encountering retry errors.
derekpierre Mar 7, 2024
86734c3
Ensure that retry_failure_counter is cleared for all exit cases fault…
derekpierre Mar 7, 2024
190ed94
Rename constant to _MAX_REDO_ATTEMPTS.
derekpierre Mar 7, 2024
f820474
Add TODO.
derekpierre Mar 7, 2024
a2ea01c
Track num requeues and num retries directly on FutureTx and PendingTx…
derekpierre Mar 7, 2024
6f0e150
Strategies must be explicitly provided by the user, if not, no strate…
derekpierre Mar 7, 2024
008c308
There will always be one TimeoutStrategy used by the machine. The tim…
derekpierre Mar 7, 2024
b76111f
Update error messages when non-active tx provided for retry update/fa…
derekpierre Mar 8, 2024
3f52121
Get hook after ensuring active tx is set.
derekpierre Mar 8, 2024
7d5b060
Inital tests for tracker.
derekpierre Mar 8, 2024
b017820
Set retries value of copy instead of incrementing it - just safer.
derekpierre Mar 8, 2024
153161f
Rename handle retry failure parameter for clarity.
derekpierre Mar 8, 2024
e8e704c
Ensure that hook is given time to be called by using a deferred with …
derekpierre Mar 8, 2024
f36fb9d
Don't forget to pop the tx before morphing in tests.
derekpierre Mar 8, 2024
018b0e2
Remove the storage of txdata from PendingTx; it isn't used at all.
derekpierre Mar 8, 2024
a0f2c74
Fix bug in restoring queue values for _TxTracker.
derekpierre Mar 8, 2024
1914e6b
Move params out of AsyncTx and into FutureTx and PendingTx, the other…
derekpierre Mar 8, 2024
7185531
TxParams which has Union data types can take different forms so to en…
derekpierre Mar 8, 2024
faa51ed
Fix tests that used hook to wait using reactor, and enable inlineCall…
derekpierre Mar 8, 2024
084e1e2
Add tests for commit/restore functionality for _TxTracker.
derekpierre Mar 8, 2024
2b52a48
Ensure that hash comparisons of txs are also made as part of tests.
derekpierre Mar 8, 2024
e1f312e
Add serialization/deserialization test for FaultedTx. May/may not rea…
derekpierre Mar 8, 2024
3245c0f
Add test about trying to perform finalize when there isn't an existin…
derekpierre Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for unrecoverable errors encoutered when trying to retry a tx.
derekpierre committed Mar 7, 2024
commit d6950787f3b282b46b6b2f4ad3afe93004eeb3ae
90 changes: 86 additions & 4 deletions tests/test_machine.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
Web3Exception,
)

from atxm.exceptions import Fault
from atxm.strategies import AsyncTxStrategy, TimeoutStrategy
from atxm.tx import FutureTx, PendingTx
from atxm.utils import _is_recoverable_send_tx_error
@@ -774,10 +775,8 @@ def test_use_strategies_that_dont_make_updates(
# params remained unchanged since strategies don't make updates
assert atx.params == original_params, "params remain unchanged"

s1_call_count = strategy_1.execute.call_count
assert s1_call_count > 0, "strategy #1 was called"
s2_call_count = strategy_2.execute.call_count
assert s2_call_count > 0, "strategy #2 was called"
assert strategy_1.execute.call_count > 0, "strategy #1 was called"
assert strategy_2.execute.call_count > 0, "strategy #2 was called"

assert atx.params == original_params, "params remain unchanged"
assert update_spy.call_count == 0, "update never called because no retry"
@@ -804,6 +803,89 @@ def test_use_strategies_that_dont_make_updates(
machine.stop()


@pytest_twisted.inlineCallbacks
@pytest.mark.usefixtures("disable_auto_mining")
@pytest.mark.parametrize(
"non_recoverable_error", [ValidationError, ValueError, Web3Exception]
)
def test_retry_non_recoverable(
non_recoverable_error,
ethereum_tester,
w3,
machine,
state_observer,
clock,
eip1559_transaction,
account,
mocker,
mock_wake_sleep,
):
# TODO consider whether this should just be provided to constructor - #23
machine._strategies.clear()

# strategies that don't make updates
strategy_1 = mocker.Mock(spec=AsyncTxStrategy)
strategy_1.name = "mock_strategy"
# return non-None so retry is attempted
strategy_1.execute.return_value = dict(eip1559_transaction)

machine._strategies = [strategy_1]

update_spy = mocker.spy(machine._tx_tracker, "update_after_retry")

machine.start()
assert machine.current_state == machine._IDLE

fault_hook = mocker.Mock()
atx = machine.queue_transaction(
params=eip1559_transaction, signer=account, on_fault=fault_hook
)

# advance to broadcast the transaction
while machine.pending is None:
yield clock.advance(1)

# ensure that hook is called
assert machine.current_state == machine._BUSY

# make firing of transaction fail with non-recoverable error
error = non_recoverable_error("non-recoverable error")
assert not _is_recoverable_send_tx_error(error)
mocker.patch.object(w3.eth, "send_raw_transaction", side_effect=error)

# run a cycle while tx unmined for strategies to kick in
yield clock.advance(1)

assert strategy_1.execute.call_count > 0, "strategy #1 was called"

# however retry failed, so params shouldn't have been updated
assert update_spy.call_count == 0, "update never called because no retry"

# ensure that hook is called
yield deferLater(reactor, 0.2, lambda: None)
assert fault_hook.call_count == 1
fault_hook.assert_called_with(atx)
assert atx.fault == Fault.ERROR
assert atx.error == "non-recoverable error"

# ensure switch back to IDLE
yield clock.advance(1)

assert len(machine.queued) == 0
assert machine.pending is None

assert not machine.busy
assert not atx.final

assert machine.current_state == machine._IDLE

assert len(state_observer.transitions) == 2
assert state_observer.transitions[0] == (machine._IDLE, machine._BUSY)
assert state_observer.transitions[1] == (machine._BUSY, machine._IDLE)

machine.stop()


@pytest_twisted.inlineCallbacks
def test_pause_when_idle(clock, machine, mocker):
machine.start()