def test_gas_and_gas_buffer_not_allowed_at_the_same_time_async(self): # expect with pytest.raises(Exception): synchronize([ self.token.transfer(self.second_address, Wad(500)).transact_async( gas=129995, gas_buffer=3000000) ])
def test_transfer_out_of_gas_async(self): # when with pytest.raises(Exception): synchronize([ self.token.transfer(self.second_address, Wad(500)).transact_async(gas=26000) ])[0] # then assert self.token.balance_of(self.our_address) == Wad(1000000) assert self.token.balance_of(self.second_address) == Wad(0)
def test_should_raise_exception_on_unknown_kwarg(self): # expect with pytest.raises(Exception): self.token.transfer(self.second_address, Wad(123)).transact(unknown_kwarg="some_value") # expect with pytest.raises(Exception): synchronize([ self.token.transfer( self.second_address, Wad(123)).transact_async(unknown_kwarg="some_value") ])
def test_custom_gas_price_async(self): # given gas_price = FixedGasPrice(25000000200) # when synchronize([ self.token.transfer(self.second_address, Wad(500)).transact_async(gas_price=gas_price) ]) # then assert self.web3.eth.getBlock( 'latest', full_transactions=True ).transactions[0].gasPrice == gas_price.gas_price
def test_default_gas_async(self): # when receipt = synchronize([ self.token.transfer(self.second_address, Wad(500)).transact_async() ])[0] # then assert 100000 <= self.web3.eth.getTransaction( receipt.transaction_hash)['gas'] <= 1200000
def test_custom_gas_async(self): # when receipt = synchronize([ self.token.transfer(self.second_address, Wad(500)).transact_async(gas=129995) ])[0] # then assert self.web3.eth.getTransaction( receipt.transaction_hash)['gas'] == 129995
def test_transfer_async(self): # when receipt = synchronize([ self.token.transfer(self.second_address, Wad(750)).transact_async() ]) # then assert receipt is not None assert self.token.balance_of(self.our_address) == Wad(999250) assert self.token.balance_of(self.second_address) == Wad(750)
def test_transfer_failed_async(self): # when receipt = synchronize([ self.token.transfer(self.second_address, Wad(5000000)).transact_async() ])[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:`pyflex.Receipt` object will be returned. Out-of-gas exceptions are automatically recognized as transaction failures. Allowed keyword arguments are: `from_address`, `replace`, `gas`, `gas_buffer`, `gas_price`. `gas_price` needs to be an instance of a class inheriting from :py:class:`pyflex.gas.GasPrice`. `from_address` needs to be an instance of :py:class:`pyflex.Address`. The `gas` keyword argument is the gas limit for the transaction, whereas `gas_buffer` specifies how much gas should be added to the estimate. They can not be present at the same time. If none of them are present, a default buffer is added to the estimate. Returns: A :py:class:`pyflex.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 cancel(self, gas_price: GasPrice): return synchronize([self.cancel_async(gas_price)])[0]