Esempio n. 1
0
    def test_check_cage(self, mcd: DssDeployment, keeper: CageKeeper,
                        our_address: Address, other_address: Address):
        print_out("test_check_cage")
        keeper.check_cage()
        assert keeper.cageFacilitated == False
        assert mcd.end.live() == 1
        prepare_esm(mcd, our_address)
        fire_esm(mcd)
        assert keeper.confirmations == 0
        for i in range(0, 12):
            time_travel_by(mcd.web3, 1)
            keeper.check_cage()
        assert keeper.confirmations == 12

        keeper.check_cage()  # Facilitate processing period
        assert keeper.cageFacilitated == True

        when = mcd.end.when()
        wait = mcd.end.wait()
        whenInUnix = when.replace(tzinfo=timezone.utc).timestamp()
        blockNumber = mcd.web3.eth.blockNumber
        now = mcd.web3.eth.getBlock(blockNumber).timestamp
        thawedCage = whenInUnix + wait
        assert now >= thawedCage

        time_travel_by(mcd.web3, 1)

        keeper.check_cage()  # Facilitate cooldown (thawing cage)
Esempio n. 2
0
    def test_cage_keeper(self, mcd: DssDeployment, keeper: CageKeeper,
                         our_address: Address, other_address: Address):
        print_out("test_cage_keeper")
        ilks = keeper.get_ilks()
        urns = pytest.global_urns
        auctions = pytest.global_auctions

        for ilk in ilks:
            # Check if cage(ilk) called on all ilks
            assert mcd.end.tag(ilk) > Ray(0)

            # Check if flow(ilk) called on all ilks
            assert mcd.end.fix(ilk) > Ray(0)

        # All underwater urns present before ES have been skimmed
        for i in urns:
            urn = mcd.vat.urn(i.ilk, i.address)
            assert urn.art == Wad(0)

        # All auctions active before cage have been yanked
        for ilk in auctions["flips"].keys():
            for auction in auctions["flips"][ilk]:
                assert mcd.collaterals[ilk].flipper.bids(
                    auction.id).lot == Wad(0)

        for auction in auctions["flaps"]:
            assert mcd.flapper.bids(auction.id).lot == Rad(0)

        for auction in auctions["flops"]:
            assert mcd.flopper.bids(auction.id).lot == Wad(0)

        # Cage has been thawed (thaw() called)
        assert mcd.end.debt() != Rad(0)
Esempio n. 3
0
def keeper(mcd: DssDeployment, keeper_address: Address) -> CageKeeper:
    keeper = CageKeeper(args=args(
        f"--eth-from {keeper_address} --network testnet --vat-deployment-block {1}"
    ),
                        web3=mcd.web3)
    assert isinstance(keeper, CageKeeper)

    return keeper
Esempio n. 4
0
 def test_check_ilks(self, mcd: DssDeployment, keeper: CageKeeper):
     print_out("test_check_ilks")
     ilks = keeper.check_ilks()
     ilkNames = ilkNames = [i.name for i in ilks]
     assert type(ilks) is list
     assert all(isinstance(x, Ilk) for x in ilks)
     deploymentIlkNames = [mcd.collaterals[key].ilk.name for key in mcd.collaterals.keys()]
     assert set(ilkNames) == set(deploymentIlkNames)
Esempio n. 5
0
    def test_get_ilks(self, mcd: DssDeployment, keeper: CageKeeper):
        print_out("test_get_ilks")

        print(f"Dai: {mcd.vat.dai(mcd.vow.address)}")
        print(f"Sin: {mcd.vat.sin(mcd.vow.address)}")
        ilks = keeper.get_ilks()
        assert type(ilks) is list
        assert all(isinstance(x, Ilk) for x in ilks)
        deploymentIlks = [mcd.vat.ilk(key) for key in mcd.collaterals.keys()]
        assert all(elem in deploymentIlks for elem in ilks)
Esempio n. 6
0
    def test_get_ilks(self, mcd: DssDeployment, keeper: CageKeeper):
        print_out("test_get_ilks")

        ilks = keeper.get_ilks()
        assert type(ilks) is list
        assert all(isinstance(x, Ilk) for x in ilks)
        deploymentIlks = [mcd.vat.ilk(key) for key in mcd.collaterals.keys()]

        empty_deploymentIlks = list(
            filter(lambda l: mcd.vat.ilk(l.name).art == Wad(0),
                   deploymentIlks))

        assert all(elem not in empty_deploymentIlks for elem in ilks)
Esempio n. 7
0
    def test_get_underwater_urns(self, mcd: DssDeployment, keeper: CageKeeper,
                                 guy_address: Address, our_address: Address):
        print_out("test_get_underwater_urns")

        previous_eth_price = open_underwater_urn(mcd, mcd.collaterals['ETH-A'],
                                                 guy_address)
        open_vault(mcd, mcd.collaterals['ETH-C'], our_address)

        ilks = keeper.get_ilks()

        urns = keeper.get_underwater_urns(ilks)
        assert type(urns) is list
        assert all(isinstance(x, Urn) for x in urns)
        assert len(urns) == 1
        assert urns[0].address.address == guy_address.address

        ## We've multiplied by a small Ray amount to counteract
        ## the residual dust (or lack thereof) in this step that causes
        ## create_flop_auction fail
        set_collateral_price(mcd, mcd.collaterals['ETH-A'],
                             Wad(previous_eth_price * Ray.from_number(1.0001)))

        pytest.global_urns = urns
Esempio n. 8
0
    def test_get_underwater_urns(self, mcd: DssDeployment, keeper: CageKeeper, guy_address: Address, our_address: Address):
        print_out("test_get_underwater_urns")

        previous_eth_price = open_underwater_urn(mcd, mcd.collaterals['ETH-A'], guy_address)
        open_cdp(mcd, mcd.collaterals['ETH-C'], our_address)


        urns = keeper.get_underwater_urns()
        assert type(urns) is list
        assert all(isinstance(x, Urn) for x in urns)
        assert len(urns) == 1
        assert urns[0].address.address == guy_address.address

        set_collateral_price(mcd, mcd.collaterals['ETH-A'], Wad(previous_eth_price))

        pytest.global_urns = urns
Esempio n. 9
0
    def test_active_auctions(self, mcd: DssDeployment, keeper: CageKeeper,
                             our_address: Address, other_address: Address,
                             deployment_address: Address):
        print_out("test_active_auctions")
        print(f"Sin: {mcd.vat.sin(mcd.vow.address)}")
        print(f"Dai: {mcd.vat.dai(mcd.vow.address)}")

        create_flap_auction(mcd, deployment_address, our_address)
        create_flop_auction(mcd, deployment_address, other_address)
        # this flip auction sets the collateral back to a price that makes the guy's vault underwater again.
        # 49 to make it underwater, and create_flip_auction sets it to 33
        create_flip_auction(mcd, deployment_address, our_address)

        auctions = keeper.all_active_auctions()
        assert "flips" in auctions
        assert "flops" in auctions
        assert "flaps" in auctions

        nobody = Address("0x0000000000000000000000000000000000000000")

        # All auctions active before cage have been yanked
        for ilk in auctions["flips"].keys():
            for auction in auctions["flips"][ilk]:
                assert len(auctions["flips"][ilk]) == 1
                assert auction.id > 0
                assert auction.bid < auction.tab
                assert auction.guy != nobody
                assert auction.guy == our_address

        assert len(auctions["flaps"]) == 1
        for auction in auctions["flaps"]:
            assert auction.id > 0
            assert auction.guy != nobody
            assert auction.guy == our_address

        assert len(auctions["flops"]) == 1
        for auction in auctions["flops"]:
            assert auction.id > 0
            assert auction.guy != nobody
            assert auction.guy == other_address

        pytest.global_auctions = auctions
Esempio n. 10
0
 def test_check_deployment(self, mcd: DssDeployment, keeper: CageKeeper):
     print_out("test_check_deployment")
     keeper.check_deployment()