def test_replacement(self): first_tx = collateral.adapter.join(our_address, Wad(4)) logging.info(f"Submitting first TX with gas price deliberately too low") self._run_future(first_tx.transact_async(gas_price=FixedGasPrice(1000))) time.sleep(2) second_tx = collateral.adapter.join(our_address, Wad(6)) logging.info(f"Replacing first TX with legitimate gas price") second_tx.transact(replace=first_tx, gas_price=FixedGasPrice(2*GWEI)) assert first_tx.replaced
def main(self): self.startup() pending_txes = get_pending_transactions(web3) pprint( list( map(lambda t: f"{t.name()} with gas {t.current_gas}", pending_txes))) if len(pending_txes) > 0: while len(pending_txes) > 0: pending_txes[0].cancel(gas_price=increasing_gas) # After the synchronous cancel, wait to see if subsequent transactions get mined time.sleep(15) pending_txes = get_pending_transactions(web3) else: logging.info( f"No pending transactions were found; submitting {stuck_txes_to_submit}" ) for i in range(1, stuck_txes_to_submit + 1): self._run_future( weth.deposit(Wad(i)).transact_async( gas_price=FixedGasPrice(int(0.4 * i * GWEI)))) time.sleep(2) self.shutdown()
async def test_recover_pending_tx(self, other_address): # given low_gas = FixedGasPrice(1) await self.token.transfer(other_address, Wad(5)).transact_async(gas_price=low_gas) await asyncio.sleep(0.5) # when pending = get_pending_transactions(self.web3) # and assert len(pending) == 1 recovered: RecoveredTransact = pending[0] high_gas = FixedGasPrice(int(1 * FixedGasPrice.GWEI)) recovered.cancel(high_gas) # then assert get_pending_transactions(self.web3) == []
def create_gas_price(arguments) -> GasPrice: if arguments.smart_gas_price: return SmartGasPrice() elif arguments.gas_price_file: return GasPriceFile(arguments.gas_price_file) elif arguments.gas_price: if arguments.gas_price_increase is not None: return IncreasingGasPrice(initial_price=arguments.gas_price, increase_by=arguments.gas_price_increase, every_secs=arguments.gas_price_increase_every, max_price=arguments.gas_price_max) else: return FixedGasPrice(arguments.gas_price) else: return DefaultGasPrice()
def get_gas_price(self, time_elapsed: int) -> Optional[int]: assert(isinstance(time_elapsed, int)) config = self.reloadable_config.get_config() gas_price = config.get('gasPrice', None) gas_price_increase = config.get('gasPriceIncrease', None) gas_price_increase_every = config.get('gasPriceIncreaseEvery', None) gas_price_max = config.get('gasPriceMax', None) if gas_price is not None: if gas_price_increase and gas_price_increase_every: strategy = IncreasingGasPrice(gas_price, gas_price_increase, gas_price_increase_every, gas_price_max) else: strategy = FixedGasPrice(gas_price) else: strategy = DefaultGasPrice() return strategy.get_gas_price(time_elapsed=time_elapsed)