def test_should_execute_arbitrage_in_one_transaction_if_tx_manager_configured(
            self, deployment: Deployment):
        # given
        tx_manager = TxManager.deploy(deployment.web3)

        # and
        keeper = ArbitrageKeeper(args=args(
            f"--eth-from {deployment.our_address.address}"
            f" --tub-address {deployment.tub.address}"
            f" --tap-address {deployment.tap.address}"
            f" --oasis-address {deployment.otc.address}"
            f" --base-token {deployment.sai.address}"
            f" --min-profit 13.0 --max-engagement 100.0"
            f" --tx-manager {tx_manager.address}"),
                                 web3=deployment.web3)

        # and
        DSValue(web3=deployment.web3,
                address=deployment.tub.pip()).poke_with_int(
                    Wad.from_number(500).value).transact()
        deployment.tub.mold_gap(Wad.from_number(1.05)).transact()
        deployment.tub.join(Wad.from_number(1000)).transact()
        deployment.tap.mold_gap(Wad.from_number(1.05)).transact()

        # and
        deployment.sai.mint(Wad.from_number(1000)).transact()

        # and
        deployment.otc.approve(
            [deployment.gem, deployment.sai, deployment.skr], directly())
        deployment.otc.add_token_pair_whitelist(
            deployment.sai.address, deployment.skr.address).transact()
        deployment.otc.add_token_pair_whitelist(
            deployment.skr.address, deployment.gem.address).transact()
        deployment.otc.add_token_pair_whitelist(
            deployment.gem.address, deployment.sai.address).transact()
        deployment.otc.make(deployment.skr.address,
                            Wad.from_number(105), deployment.sai.address,
                            Wad.from_number(100)).transact()
        deployment.otc.make(deployment.gem.address,
                            Wad.from_number(110), deployment.skr.address,
                            Wad.from_number(105)).transact()
        deployment.otc.make(deployment.sai.address,
                            Wad.from_number(115), deployment.gem.address,
                            Wad.from_number(110)).transact()
        assert len(deployment.otc.get_orders()) == 3

        # when
        keeper.approve()
        block_number_before = deployment.web3.eth.blockNumber
        keeper.process_block()
        block_number_after = deployment.web3.eth.blockNumber

        # then
        assert len(deployment.otc.get_orders()) == 0

        # and
        # [keeper used only one transaction, as TxManager is configured]
        assert (block_number_after - block_number_before) == 1
Exemplo n.º 2
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")
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def setup_method(self):
     self.web3 = Web3(HTTPProvider("http://localhost:8555"))
     self.web3.eth.defaultAccount = self.web3.eth.accounts[0]
     self.our_address = Address(self.web3.eth.defaultAccount)
     self.other_address = Address(self.web3.eth.accounts[1])
     self.tx = TxManager.deploy(self.web3)
     self.token1 = DSToken.deploy(self.web3, 'ABC')
     self.token1.mint(Wad.from_number(1000000)).transact()
     self.token2 = DSToken.deploy(self.web3, 'DEF')
     self.token2.mint(Wad.from_number(1000000)).transact()
Exemplo n.º 5
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)
Exemplo n.º 6
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