コード例 #1
0
    def test_empty_collateral_only(self):
        # given collateral balances before
        collateral_token_balance_before = self.get_collateral_token_balance()
        collateral_safe_engine_balance_before = self.get_collateral_safe_engine_balance(
        )

        # when adding system_coin
        purchase_system_coin(Wad.from_number(79), self.keeper_address)
        assert self.geb.system_coin_adapter.join(
            self.keeper_address,
            Wad.from_number(79)).transact(from_address=self.keeper_address)
        system_coin_token_balance_before = self.get_system_coin_token_balance()
        system_coin_safe_engine_balance_before = self.get_system_coin_safe_engine_balance(
        )
        # and creating and shutting down the keeper
        keeper = self.create_keeper(False, True)
        keeper.shutdown()

        # then ensure system_coin was not emptied
        assert self.get_system_coin_token_balance() == Wad(0)
        assert system_coin_safe_engine_balance_before < self.get_system_coin_safe_engine_balance(
        )
        # and collateral was emptied
        assert collateral_token_balance_before == collateral_token_balance_before + collateral_safe_engine_balance_before
        assert self.get_collateral_safe_engine_balance() == Wad(0)
コード例 #2
0
    def test_do_not_empty(self):
        # given system_coin and collateral in the safe_engine
        keeper = self.create_keeper(False, False)
        purchase_system_coin(Wad.from_number(153), self.keeper_address)
        assert self.get_system_coin_token_balance() >= Wad.from_number(153)
        assert self.geb.system_coin_adapter.join(
            self.keeper_address,
            Wad.from_number(153)).transact(from_address=self.keeper_address)
        wrap_eth(self.geb, self.keeper_address, Wad.from_number(6))
        # and balances before
        system_coin_token_balance_before = self.get_system_coin_token_balance()
        system_coin_safe_engine_balance_before = self.get_system_coin_safe_engine_balance(
        )
        collateral_token_balance_before = self.get_collateral_token_balance()
        collateral_safe_engine_balance_before = self.get_collateral_safe_engine_balance(
        )

        # when creating and shutting down the keeper
        keeper.shutdown()

        # then ensure no balances changed
        assert system_coin_token_balance_before == self.get_system_coin_token_balance(
        )
        assert system_coin_safe_engine_balance_before == self.get_system_coin_safe_engine_balance(
        )
        assert collateral_token_balance_before == self.get_collateral_token_balance(
        )
        assert collateral_safe_engine_balance_before == self.get_collateral_safe_engine_balance(
        )
コード例 #3
0
    def test_join_enough(self, keeper_address):
        # given purchasing some system_coin
        purchase_system_coin(Wad.from_number(237), keeper_address)
        token_balance_before = self.get_system_coin_token_balance()
        assert token_balance_before == Wad.from_number(237)

        # when rebalancing with a smaller amount than we have
        self.create_keeper(153.0)

        # then ensure system_coin was joined to the safe_engine
        assert token_balance_before > self.get_system_coin_token_balance()
        assert self.get_system_coin_safe_engine_balance() == Wad.from_number(
            153)
コード例 #4
0
    def test_balance_added_after_startup(self, mocker):
        try:
            # given collateral balances after starting keeper
            token_balance_before = self.get_system_coin_token_balance()
            self.create_keeper(mocker)
            time.sleep(6)  # wait for keeper to join everything on startup
            safe_engine_balance_before = self.get_system_coin_safe_engine_balance(
            )
            assert self.get_system_coin_token_balance() == Wad(0)
            assert safe_engine_balance_before == Wad(0)

            # when adding SystemCoin
            purchase_system_coin(Wad.from_number(77), self.keeper_address)
            assert self.get_system_coin_token_balance() == Wad.from_number(77)
            # and pretending there's a bid which requires SystemCoin
            reservoir = Reservoir(
                self.keeper.safe_engine.coin_balance(self.keeper_address))
            assert self.keeper.check_bid_cost(id=1,
                                              cost=Rad.from_number(20),
                                              reservoir=reservoir)

            # then ensure all SystemCoin is joined
            assert self.get_system_coin_token_balance() == Wad(0)
            assert self.get_system_coin_safe_engine_balance(
            ) == Wad.from_number(77)

            # when adding more SystemCoin and pretending there's a bid we cannot cover
            purchase_system_coin(Wad.from_number(23), self.keeper_address)
            assert self.get_system_coin_token_balance() == Wad.from_number(23)
            reservoir = Reservoir(
                self.keeper.safe_engine.coin_balance(self.keeper_address))
            assert not self.keeper.check_bid_cost(
                id=2, cost=Rad(Wad.from_number(120)), reservoir=reservoir)

            # then ensure the added SystemCoin was joined anyway
            assert self.get_system_coin_token_balance() == Wad(0)
            assert self.get_system_coin_safe_engine_balance(
            ) == Wad.from_number(100)

        finally:
            self.shutdown_keeper()
            self.give_away_system_coin()
コード例 #5
0
    def test_fixed_system_coin_target(self, mocker):
        try:
            # given a keeper configured to maintained a fixed amount of SystemCoin
            target = Wad.from_number(100)
            purchase_system_coin(target * 2, self.keeper_address)
            assert self.get_system_coin_token_balance() == Wad.from_number(200)

            self.create_keeper(mocker, target)
            time.sleep(6)  # wait for keeper to join 100 on startup
            safe_engine_balance_before = self.get_system_coin_safe_engine_balance(
            )
            assert safe_engine_balance_before == target

            # when spending SystemCoin
            assert self.keeper.system_coin_join.exit(
                self.keeper_address, Wad.from_number(22)).transact()
            assert self.get_system_coin_safe_engine_balance(
            ) == Wad.from_number(78)
            # and pretending there's a bid which requires more SystemCoin
            reservoir = Reservoir(
                self.keeper.safe_engine.coin_balance(self.keeper_address))
            assert self.keeper.check_bid_cost(id=3,
                                              cost=Rad.from_number(79),
                                              reservoir=reservoir)

            # then ensure SystemCoin was joined up to the target
            assert self.get_system_coin_safe_engine_balance() == target

            # when pretending there's a bid which we have plenty of SystemCoin to cover
            reservoir = Reservoir(
                self.keeper.safe_engine.coin_balance(self.keeper_address))
            assert self.keeper.check_bid_cost(id=4,
                                              cost=Rad(Wad.from_number(1)),
                                              reservoir=reservoir)

            # then ensure SystemCoin levels haven't changed
            assert self.get_system_coin_safe_engine_balance() == target

        finally:
            self.shutdown_keeper()
コード例 #6
0
    def test_liquidation_and_collateral_auction(
            self, web3, geb, auction_income_recipient_address, keeper_address):
        # given
        c = geb.collaterals['ETH-A']
        set_collateral_price(geb, c, Wad.from_number(500))
        keeper = AuctionKeeper(args=args(
            f"--eth-from {keeper_address} "
            f"--type collateral "
            f"--from-block 1 "
            f"--collateral-type {c.collateral_type.name} "
            f"--model ./bogus-model.sh"),
                               web3=geb.web3)
        keeper.approve()
        unsafe_safe = create_critical_safe(geb, c, Wad.from_number(1.2),
                                           auction_income_recipient_address)
        assert len(geb.active_auctions()["collateral_auctions"][
            c.collateral_type.name]) == 0

        # Keeper won't bid with a 0 system coin balance
        purchase_system_coin(Wad.from_number(20), keeper_address)
        assert geb.system_coin_adapter.join(
            keeper_address,
            Wad.from_number(20)).transact(from_address=keeper_address)

        # when
        keeper.check_safes()
        wait_for_other_threads()

        # then
        assert len(geb.liquidation_engine.past_liquidations(10)) > 0
        safe = geb.safe_engine.safe(unsafe_safe.collateral_type,
                                    unsafe_safe.address)
        assert safe.generated_debt == Wad(0)  # unsafe safe has been liquidated
        assert safe.locked_collateral == Wad(0)  # unsafe safe is now safe ...
        assert c.collateral_auction_house.auctions_started(
        ) == 1  # One auction started