@@ -605,3 +605,89 @@ def _update_with_gas_estimate_mock(tx: dict) -> dict:
605605
606606 settler .settle ()
607607 assert settler .tx_receipt is not None
608+
609+
610+ def test_gas_estimate_multiplier () -> None :
611+ """Test gas_estimate_multiplier parameter."""
612+
613+ def _tx_builder () -> dict :
614+ return {
615+ "from" : "0x123" ,
616+ "to" : "0x456" ,
617+ "value" : 100 ,
618+ "gas" : 100 ,
619+ }
620+
621+ # Test default multiplier (should be 1.0)
622+ settler = TxSettler (
623+ ledger_api = mock .Mock (
624+ try_get_gas_pricing = lambda ** kwargs : {
625+ "maxFeePerGas" : 100 ,
626+ "maxPriorityFeePerGas" : 100 ,
627+ },
628+ update_with_gas_estimate = lambda tx : {** tx , "gas" : 100 },
629+ ),
630+ crypto = mock .Mock (sign_transaction = lambda transaction : transaction ),
631+ chain_type = ChainType .LOCAL ,
632+ tx_builder = _tx_builder ,
633+ )
634+ assert settler .gas_multiplier == 1.0
635+
636+ # Test custom multiplier
637+ settler_with_multiplier = TxSettler (
638+ ledger_api = mock .Mock (
639+ try_get_gas_pricing = lambda ** kwargs : {
640+ "maxFeePerGas" : 100 ,
641+ "maxPriorityFeePerGas" : 100 ,
642+ },
643+ update_with_gas_estimate = lambda tx : {** tx , "gas" : 100 },
644+ ),
645+ crypto = mock .Mock (sign_transaction = lambda transaction : transaction ),
646+ chain_type = ChainType .LOCAL ,
647+ tx_builder = _tx_builder ,
648+ gas_estimate_multiplier = 1.5 ,
649+ )
650+ assert settler_with_multiplier .gas_multiplier == 1.5
651+
652+ # Test that gas is multiplied correctly in transaction
653+ settler_with_multiplier .transact (dry_run = False )
654+ assert settler_with_multiplier .tx_dict is not None
655+ assert settler_with_multiplier .tx_dict ["gas" ] == 150 # 100 * 1.5
656+
657+ # Test invalid multiplier (must be positive)
658+ with pytest .raises (ValueError , match = "gas_estimate_multiplier.*must be positive" ):
659+ TxSettler (
660+ ledger_api = mock .Mock (),
661+ crypto = mock .Mock (),
662+ chain_type = ChainType .LOCAL ,
663+ tx_builder = _tx_builder ,
664+ gas_estimate_multiplier = 0 ,
665+ )
666+
667+ with pytest .raises (ValueError , match = "gas_estimate_multiplier.*must be positive" ):
668+ TxSettler (
669+ ledger_api = mock .Mock (),
670+ crypto = mock .Mock (),
671+ chain_type = ChainType .LOCAL ,
672+ tx_builder = _tx_builder ,
673+ gas_estimate_multiplier = - 1.0 ,
674+ )
675+
676+
677+ @mock .patch ("autonomy.chain.tx.logger" )
678+ def test_gas_estimate_multiplier_warning (logger : mock .Mock ) -> None :
679+ """Test that gas_estimate_multiplier warns when > 2.5."""
680+
681+ def _tx_builder () -> dict :
682+ return {"from" : "0x123" , "to" : "0x456" , "value" : 100 }
683+
684+ TxSettler (
685+ ledger_api = mock .Mock (),
686+ crypto = mock .Mock (),
687+ chain_type = ChainType .LOCAL ,
688+ tx_builder = _tx_builder ,
689+ gas_estimate_multiplier = 3.0 ,
690+ )
691+
692+ logger .warning .assert_called_once () # type: ignore[attr-defined]
693+ assert "unusually high" in logger .warning .call_args [0 ][0 ] # type: ignore[attr-defined]
0 commit comments