def test_scenario(self, mcd: DssDeployment, our_address: Address, other_address: Address):
        isinstance(mcd, DssDeployment)
        isinstance(our_address, Address)

        prevBalance = mcd.mkr.balance_of(our_address)
        amount = Wad.from_number(1000)
        mint_mkr(mcd.mkr, our_address, amount)
        assert mcd.mkr.balance_of(our_address) == amount + prevBalance

        # Lock MKR in DS-Chief
        assert mcd.mkr.approve(mcd.ds_chief.address).transact(from_address=our_address)
        assert mcd.ds_chief.lock(amount).transact(from_address=our_address)
        assert mcd.mkr.balance_of(our_address) == prevBalance

        # Vote for our address
        assert mcd.ds_chief.vote_yays([our_address.address]).transact(from_address=our_address)
        assert mcd.ds_chief.etch([other_address.address]).transact(from_address=our_address)

        # Confirm that etch(our address) != etch(other address)
        etches = mcd.ds_chief.past_etch(3)
        assert etches[0].slate !=  etches[-1].slate

        assert mcd.ds_chief.get_approvals(our_address.address) == amount

        # Lift hat for our address
        assert mcd.ds_chief.get_hat() != our_address
        assert mcd.ds_chief.lift(our_address).transact(from_address=our_address)
        assert mcd.ds_chief.get_hat() == our_address

        # Now vote for other address
        assert mcd.ds_chief.vote_etch(etches[-1]).transact(from_address=our_address)
        assert mcd.ds_chief.lift(other_address).transact(from_address=our_address)
        assert mcd.ds_chief.get_hat() == other_address
예제 #2
0
def create_flap_auction(mcd: DssDeployment, deployment_address: Address,
                        our_address: Address):
    assert isinstance(mcd, DssDeployment)
    assert isinstance(deployment_address, Address)
    assert isinstance(our_address, Address)

    flapper = mcd.flapper
    print(f"Before Surplus: {mcd.vat.dai(mcd.vow.address)}")
    create_surplus(mcd, flapper, deployment_address)
    print(f"After Surplus: {mcd.vat.dai(mcd.vow.address)}")

    # Kick off the flap auction
    joy = mcd.vat.dai(mcd.vow.address)
    assert joy > mcd.vat.sin(mcd.vow.address) + mcd.vow.bump() + mcd.vow.hump()
    assert (mcd.vat.sin(mcd.vow.address) -
            mcd.vow.sin()) - mcd.vow.ash() == Rad(0)
    assert mcd.vow.flap().transact()
    kick = flapper.kicks()
    assert kick == 1
    assert len(flapper.active_auctions()) == 1

    mint_mkr(mcd.mkr, our_address, Wad.from_number(10))
    flapper.approve(mcd.mkr.address, directly(from_address=our_address))
    bid = Wad.from_number(0.001)
    assert mcd.mkr.balance_of(our_address) > bid
    assert flapper.tend(flapper.kicks(), mcd.vow.bump(),
                        bid).transact(from_address=our_address)
예제 #3
0
    def test_scenario(self, web3, mcd, flapper, our_address, other_address,
                      deployment_address):
        create_surplus(mcd, flapper, deployment_address)

        joy_before = mcd.vat.dai(mcd.vow.address)
        # total surplus > total debt + surplus auction lot size + surplus buffer
        assert joy_before > mcd.vat.sin(
            mcd.vow.address) + mcd.vow.bump() + mcd.vow.hump()
        assert (mcd.vat.sin(mcd.vow.address) -
                mcd.vow.sin()) - mcd.vow.ash() == Rad(0)
        assert mcd.vow.flap().transact()
        kick = flapper.kicks()
        assert kick == 1
        assert len(flapper.active_auctions()) == 1
        check_active_auctions(flapper)
        current_bid = flapper.bids(1)
        assert current_bid.lot > Rad(0)
        log = self.last_log(flapper)
        assert isinstance(log, Flapper.KickLog)
        assert log.id == kick
        assert log.lot == current_bid.lot
        assert log.bid == current_bid.bid

        # Allow the auction to expire, and then resurrect it
        time_travel_by(web3, flapper.tau() + 1)
        assert flapper.tick(kick).transact()

        # Bid on the resurrected auction
        mint_mkr(mcd.mkr, our_address, Wad.from_number(10))
        flapper.approve(mcd.mkr.address, directly(from_address=our_address))
        bid = Wad.from_number(0.001)
        assert mcd.mkr.balance_of(our_address) > bid
        TestFlapper.tend(flapper, kick, our_address, current_bid.lot, bid)
        current_bid = flapper.bids(kick)
        assert current_bid.bid == bid
        assert current_bid.guy == our_address

        # Exercise _deal_ after bid has expired
        time_travel_by(web3, flapper.ttl() + 1)
        now = datetime.now().timestamp()
        assert 0 < current_bid.tic < now or current_bid.end < now
        assert flapper.deal(kick).transact(from_address=our_address)
        joy_after = mcd.vat.dai(mcd.vow.address)
        print(f'joy_before={str(joy_before)}, joy_after={str(joy_after)}')
        assert joy_before - joy_after == mcd.vow.bump()
        log = self.last_log(flapper)
        assert isinstance(log, Flapper.DealLog)
        assert log.usr == our_address
        assert log.id == kick

        # Grab our dai
        mcd.approve_dai(our_address)
        assert mcd.dai_adapter.exit(our_address, Wad(
            current_bid.lot)).transact(from_address=our_address)
        assert mcd.dai.balance_of(our_address) >= Wad(current_bid.lot)
        assert (mcd.vat.sin(mcd.vow.address) -
                mcd.vow.sin()) - mcd.vow.ash() == Rad(0)
예제 #4
0
def mint_approve_lock(mcd: DssDeployment, amount: Wad, address: Address):
    prevBalance = mcd.mkr.balance_of(address)
    mint_mkr(mcd.mkr, address, amount)
    assert mcd.mkr.balance_of(address) == amount + prevBalance

    # Lock MKR in DS-Chief
    assert mcd.mkr.approve(mcd.ds_chief.address).transact(from_address=address)
    assert mcd.ds_chief.lock(amount).transact(from_address=address)
    assert mcd.mkr.balance_of(address) == prevBalance
예제 #5
0
    def test_check_eta_receipt(self, mcd: DssDeployment, keeper: ChiefKeeper,
                               simpledb: SimpleDatabase, our_address: Address):
        print_out("test_check_eta_receipt")

        # clear out anything that came before
        keeper.check_hat()
        keeper.check_eta()

        # Give 1000 MKR to our_address
        amount = Wad.from_number(5000)
        mint_mkr(mcd.mkr, our_address, amount)
        assert mcd.mkr.balance_of(our_address) == amount

        # Lock MKR in DS-Chief
        assert mcd.mkr.approve(
            mcd.ds_chief.address).transact(from_address=our_address)
        assert mcd.ds_chief.lock(amount).transact(from_address=our_address)

        # Deploy spell
        spell = DSSBadSpell.deploy(mcd.web3)

        # Vote 5000 mkr on the spell
        assert mcd.ds_chief.vote_yays([spell.address.address
                                       ]).transact(from_address=our_address)

        keeper.check_hat()

        block = mcd.web3.eth.blockNumber
        simpledb.update_db_etas(block)

        hat = mcd.ds_chief.get_hat()

        etas = keeper.database.db.get(doc_id=3)['upcoming_etas']
        verify([hat.address], etas, 1)

        keeper.check_eta()

        # Confirm that the spell was casted and that the database was updated
        # For the DSSBadSpell, the cast() call in non-conformant.  Usually
        # cast() will flip done to true, but in this broken spell it's modified
        # to not set done to true so we can test this bug and prevent
        # regressions.
        assert DSSBadSpell(mcd.web3, Address(hat)).done() == False
        etas = keeper.database.db.get(doc_id=3)['upcoming_etas']
        verify([], etas, 0)
    def test_join(self, mcd, our_address):
        assert mcd.mkr.approve(mcd.esm.address).transact()

        # This should have no effect yet succeed regardless
        assert mcd.esm.join(Wad(0)).transact()
        assert mcd.esm.sum() == Wad(0)
        assert mcd.esm.sum_of(our_address) == Wad(0)

        # Ensure the appropriate amount of MKR can be joined
        mint_mkr(mcd.mkr, our_address, mcd.esm.min())
        assert mcd.esm.join(mcd.esm.min()).transact()
        assert mcd.esm.sum() == mcd.esm.min()

        # Joining extra MKR should succeed yet have no effect
        mint_mkr(mcd.mkr, our_address, Wad(153))
        assert mcd.esm.join(Wad(153)).transact()
        assert mcd.esm.sum() == mcd.esm.min() + Wad(153)
        assert mcd.esm.sum_of(our_address) == mcd.esm.sum()
예제 #7
0
def prepare_esm(mcd: DssDeployment, our_address: Address):
    assert mcd.esm is not None
    assert isinstance(mcd.esm, ShutdownModule)
    assert isinstance(mcd.esm.address, Address)
    assert mcd.esm.sum() == Wad(0)
    assert mcd.esm.min() > Wad(0)
    assert not mcd.esm.fired()

    assert mcd.mkr.approve(mcd.esm.address).transact()

    # This should have no effect yet succeed regardless
    assert mcd.esm.join(Wad(0)).transact()
    assert mcd.esm.sum() == Wad(0)
    assert mcd.esm.sum_of(our_address) == Wad(0)

    # Mint and join a min amount to call esm.fire
    mint_mkr(mcd.mkr, our_address, mcd.esm.min())
    assert mcd.esm.join(mcd.esm.min()).transact()
    assert mcd.esm.sum() == mcd.esm.min()
def create_flap_auction(mcd: DssDeployment, deployment_address: Address,
                        our_address: Address):
    assert isinstance(mcd, DssDeployment)
    assert isinstance(deployment_address, Address)
    assert isinstance(our_address, Address)

    flapper = mcd.flapper
    create_surplus(mcd, flapper, deployment_address)
    joy = mcd.vat.dai(mcd.vow.address)
    assert joy > mcd.vat.sin(mcd.vow.address) + mcd.vow.bump() + mcd.vow.hump()
    assert (mcd.vat.sin(mcd.vow.address) -
            mcd.vow.sin()) - mcd.vow.ash() == Rad(0)
    assert mcd.vow.flap().transact()

    mint_mkr(mcd.mkr, our_address, Wad.from_number(10))
    flapper.approve(mcd.mkr.address, directly(from_address=our_address))
    bid = Wad.from_number(0.001)
    assert mcd.mkr.balance_of(our_address) > bid
    assert flapper.tend(flapper.kicks(), mcd.vow.bump(),
                        bid).transact(from_address=our_address)
예제 #9
0
    def test_setup(self, mcd: DssDeployment, our_address: Address,
                   guy_address: Address):
        print_out("test_setup")

        # Give 1000 MKR to our_address
        amount = Wad.from_number(1000)
        mint_mkr(mcd.mkr, our_address, amount)
        assert mcd.mkr.balance_of(our_address) == amount

        #Give 2000 MKR to guy_address
        guyAmount = Wad.from_number(2000)
        mint_mkr(mcd.mkr, guy_address, guyAmount)
        assert mcd.mkr.balance_of(guy_address) == guyAmount

        # Lock MKR in DS-Chief
        assert mcd.mkr.approve(
            mcd.ds_chief.address).transact(from_address=our_address)
        assert mcd.mkr.approve(
            mcd.ds_chief.address).transact(from_address=guy_address)
        assert mcd.ds_chief.lock(amount).transact(from_address=our_address)
        assert mcd.ds_chief.lock(guyAmount).transact(from_address=guy_address)

        # Deploy spell
        self.spell = DSSSpell.deploy(mcd.web3, mcd.pause.address,
                                     mcd.vat.address)

        # Vote 1000 mkr on our address and guy_address
        # Vote 2000 mkr on global spell address
        assert mcd.ds_chief.vote_yays(
            [our_address.address,
             guy_address.address]).transact(from_address=our_address)
        assert mcd.ds_chief.vote_yays([self.spell.address.address
                                       ]).transact(from_address=guy_address)

        # At this point there are two yays in the chief, one to our_address and the other to the spell address

        pytest.global_spell = self.spell
예제 #10
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
from web3 import Web3, HTTPProvider
import sys

from pymaker import Address
from pymaker.deployment import DssDeployment
from pymaker.keys import register_keys
from pymaker.numeric import Wad
from tests.test_dss import mint_mkr

web3 = Web3(HTTPProvider(endpoint_uri="http://0.0.0.0:8545"))
web3.eth.defaultAccount = "0x50FF810797f75f6bfbf2227442e0c961a8562F4C"
register_keys(web3, [
    "key_file=../lib/pymaker/tests/config/keys/UnlimitedChain/key1.json,pass_file=/dev/null",
    "key_file=../lib/pymaker/tests/config/keys/UnlimitedChain/key2.json,pass_file=/dev/null",
    "key_file=../lib/pymaker/tests/config/keys/UnlimitedChain/key3.json,pass_file=/dev/null",
    "key_file=../lib/pymaker/tests/config/keys/UnlimitedChain/key4.json,pass_file=/dev/null",
    "key_file=../lib/pymaker/tests/config/keys/UnlimitedChain/key.json,pass_file=/dev/null"
])
mcd = DssDeployment.from_node(web3)

mint_mkr(mcd.mkr, Address(sys.argv[1]), Wad.from_number(sys.argv[2]))
print(
    f"MKR balance for {sys.argv[1]} is {mcd.mkr.balance_of(Address(sys.argv[1]))}"
)
예제 #11
0
    def test_scenario(self, web3, mcd, flapper, our_address, other_address,
                      deployment_address):
        joy = mcd.vat.dai(mcd.vow.address)

        if joy == Rad(0):
            # Create a CDP with surplus
            print('Creating a CDP with surplus')
            collateral = mcd.collaterals['ETH-B']
            assert flapper.kicks() == 0
            wrap_eth(mcd, deployment_address, Wad.from_number(0.1))
            collateral.approve(deployment_address)
            assert collateral.adapter.join(
                deployment_address,
                Wad.from_number(0.1)).transact(from_address=deployment_address)
            frob(mcd,
                 collateral,
                 deployment_address,
                 dink=Wad.from_number(0.1),
                 dart=Wad.from_number(10))
            assert mcd.jug.drip(
                collateral.ilk).transact(from_address=deployment_address)
        else:
            print('Surplus already exists; skipping CDP creation')
        joy_before = mcd.vat.dai(mcd.vow.address)
        # total surplus > total debt + surplus auction lot size + surplus buffer
        assert joy_before > mcd.vat.sin(
            mcd.vow.address) + mcd.vow.bump() + mcd.vow.hump()
        assert (mcd.vat.sin(mcd.vow.address) -
                mcd.vow.sin()) - mcd.vow.ash() == Rad(0)
        assert mcd.vow.flap().transact()
        kick = flapper.kicks()
        assert kick == 1
        assert len(flapper.active_auctions()) == 1
        current_bid = flapper.bids(1)
        assert current_bid.lot > Rad(0)

        # Bid on the surplus
        mint_mkr(mcd.mkr, deployment_address, our_address, Wad.from_number(10))
        flapper.approve(mcd.mkr.address, directly(from_address=our_address))
        bid = Wad.from_number(0.001)
        assert mcd.mkr.balance_of(our_address) > bid
        TestFlapper.tend(flapper, kick, our_address, current_bid.lot, bid)
        current_bid = flapper.bids(kick)
        assert current_bid.bid == bid
        assert current_bid.guy == our_address

        # Exercise _deal_ after bid has expired
        wait(mcd, our_address, flapper.ttl() + 1)
        now = datetime.now().timestamp()
        assert 0 < current_bid.tic < now or current_bid.end < now
        assert flapper.deal(kick).transact(from_address=our_address)
        joy_after = mcd.vat.dai(mcd.vow.address)
        print(f'joy_before={str(joy_before)}, joy_after={str(joy_after)}')
        assert joy_before - joy_after == mcd.vow.bump()

        # Grab our dai
        mcd.approve_dai(our_address)
        assert mcd.dai_adapter.exit(our_address, Wad(
            current_bid.lot)).transact(from_address=our_address)
        assert mcd.dai.balance_of(our_address) >= Wad(current_bid.lot)
        assert (mcd.vat.sin(mcd.vow.address) -
                mcd.vow.sin()) - mcd.vow.ash() == Rad(0)