示例#1
0
    def test_should_cancel_orders_on_shutdown_and_withdraw_if_asked_to_do_so(
            self, deployment: Deployment, tmpdir: py.path.local):
        # given
        config_file = BandConfig.sample_config(tmpdir)

        # and
        keeper = EtherDeltaMarketMakerKeeper(args=args(
            f"--eth-from {deployment.our_address} --config {config_file}"
            f" --tub-address {deployment.tub.address}"
            f" --etherdelta-address {deployment.etherdelta.address}"
            f" --etherdelta-socket https://127.0.0.1:99999/"
            f" --order-age 3600 --eth-reserve 10"
            f" --min-eth-deposit 1 --min-sai-deposit 400"
            f" --cancel-on-shutdown --withdraw-on-shutdown"),
                                             web3=deployment.web3)
        keeper.lifecycle = Web3Lifecycle(web3=keeper.web3)
        keeper.etherdelta_api.publish_order = MagicMock()

        # and
        self.mint_tokens(deployment)
        self.set_price(deployment, Wad.from_number(100))

        # and
        keeper.approve()
        keeper.synchronize_orders(
        )  # ... first call is so it can made deposits
        keeper.synchronize_orders(
        )  # ... second call is so the actual orders can get placed
        assert len(self.orders(keeper)) == 2

        # when
        keeper.shutdown()

        # then
        assert len(self.orders(keeper)) == 0

        # and
        assert deployment.etherdelta.balance_of(
            deployment.our_address) == Wad(0)
        assert deployment.etherdelta.balance_of_token(
            deployment.sai.address, deployment.our_address) == Wad(0)
示例#2
0
    def test_should_use_specified_gas_price_for_all_transactions(
            self, deployment: Deployment, tmpdir: py.path.local):
        # given
        config_file = BandConfig.sample_config(tmpdir)

        # and
        keeper = EtherDeltaMarketMakerKeeper(args=args(
            f"--eth-from {deployment.our_address} --config {config_file}"
            f" --tub-address {deployment.tub.address}"
            f" --etherdelta-address {deployment.etherdelta.address}"
            f" --etherdelta-socket https://127.0.0.1:99999/"
            f" --order-age 3600 --eth-reserve 10"
            f" --min-eth-deposit 1 --min-sai-deposit 400"
            f" --cancel-on-shutdown"
            f" --gas-price 69000000000"),
                                             web3=deployment.web3)
        keeper.lifecycle = Web3Lifecycle(web3=keeper.web3)
        keeper.etherdelta_api.publish_order = MagicMock()

        # and
        self.mint_tokens(deployment)
        self.set_price(deployment, Wad.from_number(100))

        # and
        start_block_number = deployment.web3.eth.blockNumber

        # when
        keeper.approve()
        keeper.synchronize_orders(
        )  # ... first call is so it can made deposits
        keeper.synchronize_orders(
        )  # ... second call is so the actual orders can get placed
        keeper.shutdown()

        # then
        for block_number in range(start_block_number + 1,
                                  deployment.web3.eth.blockNumber + 1):
            for transaction in deployment.web3.eth.getBlock(
                    block_number, full_transactions=True).transactions:
                assert transaction.gasPrice == 69000000000