def cancel_offers(self, offers): """Cancel offers asynchronously.""" synchronize([ self.otc.kill( offer.offer_id).transact_async(gas_price=self.gas_price) for offer in offers ])
def create_new_offers(self, active_offers: list, target_price: Wad): """Asynchronously create new buy and sell offers if necessary.""" synchronize([ transact.transact_async(gas_price=self.gas_price) for transact in chain( self.new_buy_offer(active_offers, target_price), self.new_sell_offer(active_offers, target_price)) ])
def test_transfer_async(self): # when synchronize([ self.token.transfer(self.second_address, Wad(750)).transact_async() ]) # then assert self.token.balance_of(self.our_address) == Wad(999250) assert self.token.balance_of(self.second_address) == Wad(750)
def test_transfer_out_of_gas_async(self): # when receipt = synchronize([ self.token.transfer(self.second_address, Wad(500)).transact_async(gas=15000) ])[0] # then assert receipt is None assert self.token.balance_of(self.our_address) == Wad(1000000) assert self.token.balance_of(self.second_address) == Wad(0)
def transact(self, **kwargs) -> Optional[Receipt]: """Executes the Ethereum transaction synchronously. Executes the Ethereum transaction synchronously. The method will block until the transaction gets mined i.e. it will return when either the transaction execution succeeded or failed. In case of the former, a :py:class:`keeper.api.Receipt` object will be returned. Out-of-gas exceptions are automatically recognized as transaction failures. Allowed keyword arguments are: `gas`, `gas_buffer`, `gas_price`. `gas_price` needs to be an instance of a class inheriting from :py:class:`keeper.api.gas.GasPrice`. Returns: A :py:class:`keeper.api.Receipt` object if the transaction invocation was successful. `None` otherwise. """ return synchronize([self.transact_async(**kwargs)])[0]
def test_synchronize_should_pass_exceptions(): with pytest.raises(Exception): synchronize([async_return(1), async_exception(), async_return(3)])
def test_synchronize_should_return_results_of_all_async_calls(): assert synchronize([async_return(1)]) == [1] assert synchronize([async_return(1), async_return(2)]) == [1, 2] assert synchronize([async_return(1), async_return(2), async_return(3)]) == [1, 2, 3]
def test_synchronize_should_return_empty_list_for_no_futures(): assert synchronize([]) == []
def transact(self, options=None) -> Optional[Receipt]: return synchronize([self.transact_async(options)])[0]
def create_new_offers(self, active_offers: list): """Asynchronously create new buy and sell offers if necessary.""" synchronize([transact.transact_async(self.default_options()) for transact in chain(self.new_buy_offer(active_offers), self.new_sell_offer(active_offers))])
def cancel_offers(self, offers): """Cancel offers asynchronously.""" synchronize([self.otc.kill(offer.offer_id).transact_async(self.default_options()) for offer in offers])