Example #1
0
def test_via_tx_manager_approval_should_raise_exception_if_approval_fails():
    # given
    global web3, our_address, second_address, token
    tx = TxManager.deploy(web3)
    tx.execute = MagicMock(return_value=FailingTransact())

    # when
    with pytest.raises(Exception):
        via_tx_manager(tx)(token, second_address, "some-name")
Example #2
0
def test_via_tx_manager_approval():
    # given
    global web3, our_address, second_address, token
    tx = TxManager.deploy(web3)

    # when
    via_tx_manager(tx)(token, second_address, "some-name")

    # then
    assert token.allowance_of(tx.address, second_address) == Wad(2**256 - 1)
Example #3
0
def test_via_tx_manager_approval_should_not_approve_if_already_approved():
    # given
    global web3, our_address, second_address, token
    tx = TxManager.deploy(web3)
    tx.execute([],
               [token.approve(second_address, Wad(2**248 + 19)).invocation()
                ]).transact()

    # when
    via_tx_manager(tx)(token, second_address, "some-name")

    # then
    assert token.allowance_of(tx.address, second_address) == Wad(2**248 + 19)
Example #4
0
def test_via_tx_manager_approval_should_obey_gas_price():
    # given
    global web3, our_address, second_address, token
    tx = TxManager.deploy(web3)

    # when
    via_tx_manager(tx, gas_strategy=FixedGasPrice(15000000000))(token,
                                                                second_address,
                                                                "some-name")

    # then
    assert web3.eth.getBlock(
        'latest',
        full_transactions=True).transactions[0].gasPrice == 15000000000
 def approve(self):
     """Approve all components that need to access our balances"""
     approval_method = via_tx_manager(self.tx_manager, gas_price=self.gas_price()) if self.tx_manager \
         else directly(gas_price=self.gas_price())
     self.tub.approve(approval_method)
     self.otc.approve([self.gem, self.sai, self.skr], approval_method)
     if self.tx_manager:
         self.tx_manager.approve([self.gem, self.sai, self.skr], directly(gas_price=self.gas_price()))
    def approve(self):
        """ Approve all components that need to access our balances

        Approve Oasis to access our tokens from our TxManager
        Approve Uniswap exchanges to access our tokens that they swap from our TxManager
        Approve TxManager to access our tokens from our ETH_FROM address

        """
        approval_method = via_tx_manager(self.tx_manager, gas_price=self.gas_price()) if self.tx_manager \
            else directly(gas_price=self.gas_price())

        self.oasis.approve([self.entry_token, self.arb_token], approval_method)

        if self.uniswap_entry_exchange:
            self.uniswap_entry_exchange.approve([self.entry_token],
                                                approval_method)

        if self.uniswap_arb_exchange:
            self.uniswap_arb_exchange.approve([self.arb_token],
                                              approval_method)

        if self.tx_manager:
            self.tx_manager.approve([self.entry_token, self.arb_token],
                                    directly(gas_price=self.gas_price()))