示例#1
0
    def test_should_both_wipe_and_top_up_if_collateralization_too_low(
            self, deployment: Deployment):
        # given
        self.open_cdp(deployment, eth_amount=40, sai_amount=5000)
        self.sai_balance(deployment, balance=3500)

        # and
        keeper = CdpKeeper(args=args(
            f"--eth-from {deployment.web3.eth.defaultAccount} "
            f"--tub-address {deployment.tub.address} "
            f"--min-margin 0.2 --top-up-margin 0.45 --max-sai 3000 --avg-sai 2000"
        ),
                           web3=deployment.web3)
        keeper.approve()

        # when
        self.set_price(deployment, 276)
        # and
        keeper.check_all_cups()
        # then
        assert deployment.tub.ink(1) == Wad.from_number(40)
        assert deployment.tub.tab(1) == Wad.from_number(5000)
        assert deployment.sai.balance_of(
            deployment.our_address) == Wad.from_number(3500)

        # when
        self.set_price(deployment, 120)
        # and
        keeper.check_all_cups()
        # then
        assert deployment.tub.ink(1) == Wad(71458333333333333000)
        assert deployment.tub.tab(1) == Wad.from_number(3500)
        assert deployment.sai.balance_of(
            deployment.our_address) == Wad.from_number(2000)
示例#2
0
    def test_should_not_start_without_eth_from_argument(
            self, deployment: Deployment):
        # when
        with captured_output() as (out, err):
            with pytest.raises(SystemExit):
                CdpKeeper(args=args(f""), web3=deployment.web3)

        # then
        assert "error: the following arguments are required: --eth-from" in err.getvalue(
        )
示例#3
0
    def test_should_not_start_without_tub_address_argument(
            self, deployment: Deployment):
        # when
        with captured_output() as (out, err):
            with pytest.raises(SystemExit):
                CdpKeeper(args=args(
                    f"--eth-from {deployment.web3.eth.defaultAccount}"),
                          web3=deployment.web3)

        # then
        assert "error: the following arguments are required: --tub-address" in err.getvalue(
        )
示例#4
0
    def test_should_not_crash_on_empty_cdps(self, deployment: Deployment):
        # given
        deployment.tub.open().transact()

        # and
        keeper = CdpKeeper(args=args(
            f"--eth-from {deployment.web3.eth.defaultAccount} "
            f"--tub-address {deployment.tub.address} "
            f"--min-margin 0.2 --top-up-margin 0.45 --max-sai 3000 --avg-sai 2000"
        ),
                           web3=deployment.web3)
        keeper.approve()

        # when
        self.set_price(deployment, 276)
        # and
        keeper.check_all_cups()