Skip to content

Commit

Permalink
test: repricing bad tx
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Jan 19, 2024
1 parent aeebd97 commit 9d33586
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_autonomy/test_chain/test_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,46 @@ def _reprice(old_price: Any, **kwargs: Any) -> Any:
assert "Repricing the transaction..." in captured.out


def test_repricing_bad_tx(capsys: Any) -> None:
"""Test retriable exception."""

class _repricable_method:
retries = 0

def __call__(self, *args: Any, **kwargs: Any) -> Any:
if self.retries == 0:
self.retries += 1
return {
"maxFeePerGas": 100,
}
return {
"maxFeePerGas": 100,
"maxPriorityFeePerGas": 100,
}

def _raise_fee_too_low(tx_signed: Any, **kwargs: Any) -> None:
if tx_signed["maxFeePerGas"] == 110:
return
raise Exception("FeeTooLow")

def _reprice(old_price: Any, **kwargs: Any) -> Any:
return {"maxFeePerGas": 110, "maxPriorityFeePerGas": 110}

settler = TxSettler(
ledger_api=mock.Mock(
send_signed_transaction=_raise_fee_too_low,
try_get_gas_pricing=_reprice,
),
crypto=mock.Mock(
sign_transaction=lambda transaction: transaction,
),
chain_type=ChainType.LOCAL,
)
settler.transact(_repricable_method(), contract="service_registry", kwargs={}) # type: ignore
captured = capsys.readouterr()
assert "Repricing the transaction..." in captured.out


def test_tx_not_found(capsys: Any) -> None:
"""Test retriable exception."""

Expand Down

0 comments on commit 9d33586

Please sign in to comment.