Esempio n. 1
0
def test_disavowed_dispute_bond_token_redemption(localFixture, universe, cash, market):
    newMarket = localFixture.createReasonableBinaryMarket(universe, cash)
    reputationToken = localFixture.applySignature("ReputationToken", universe.getReputationToken())

    # We'll do a designated report in the new market
    proceedToDesignatedReporting(localFixture, universe, newMarket, [0,market.getNumTicks()])
    localFixture.designatedReport(newMarket, [0,market.getNumTicks()], tester.k0)

    # Now we'll dispute it
    assert newMarket.disputeDesignatedReport([1,market.getNumTicks()-1], 1, False, sender=tester.k1)

    # We proceed the standard market to the FORKING state
    proceedToForking(localFixture, universe, market, True, 1, 2, 3, [0,market.getNumTicks()], [market.getNumTicks(),0], 2, [market.getNumTicks(),0], [0,market.getNumTicks()], [market.getNumTicks(),0])

    # We'll finalize the forking market
    finalizeForkingMarket(localFixture, universe, market, True, tester.a1, tester.k1, tester.a0, tester.k0, tester.a2, tester.k2, [0,market.getNumTicks()], [market.getNumTicks(),0])

    disputeBond = localFixture.applySignature("DisputeBond", newMarket.getDesignatedReporterDisputeBond())

    # Now we can migrate the market to the winning universe
    assert newMarket.migrateThroughOneFork()

    # Doing this disavows the dispute bond placed against the designated report. We can no longer normally withdraw or withdrawToUniverse but we can call the withdrawDisavowedTokens method
    newUniverseHash = market.derivePayoutDistributionHash([2,market.getNumTicks()-2])
    newUniverse = universe.getOrCreateChildUniverse(newUniverseHash)
    with raises(TransactionFailed):
        disputeBond.withdrawToUniverse(newUniverse, sender=tester.k1)

    with raises(TransactionFailed):
        disputeBond.withdraw(sender=tester.k1)

    with TokenDelta(reputationToken, reputationToken.balanceOf(disputeBond.address), tester.a1, "Redeeming a disavowed dispute bond didn't return the REP balance to the bond holder"):
        assert disputeBond.withdrawDisavowedTokens(sender=tester.k1)
Esempio n. 2
0
def test_stake_token_disavowal(disavowType, localFixture, universe, market):
    newMarket = localFixture.createReasonableBinaryMarket(
        universe, localFixture.contracts['Cash'])

    # We'll do a designated report in the new market based on the makeReport param used for the forking market
    proceedToDesignatedReporting(localFixture, universe, newMarket,
                                 [0, market.getNumTicks()])
    localFixture.designatedReport(newMarket, [0, market.getNumTicks()],
                                  tester.k0)

    # We proceed the standard market to the FORKING state
    proceedToForking(localFixture, universe, market, True, 1, 2, 3,
                     [0, market.getNumTicks()], [market.getNumTicks(), 0], 2,
                     [market.getNumTicks(), 0], [0, market.getNumTicks()],
                     [market.getNumTicks(), 0])

    # The market we created is now awaiting migration
    assert newMarket.getReportingState(
    ) == localFixture.contracts['Constants'].AWAITING_FORK_MIGRATION()

    # If we attempt to migrate now it will not work since the forking market is not finalized
    with raises(
            TransactionFailed,
            message=
            "Migration cannot occur until the forking market is finalized"):
        newMarket.migrateThroughOneFork()

    stakeToken = localFixture.getOrCreateStakeToken(
        newMarket, [0, market.getNumTicks()])
    reputationToken = localFixture.applySignature(
        'ReputationToken', stakeToken.getReputationToken())

    if (disavowType == 0):
        assert newMarket.disavowTokens()
    elif (disavowType == 2):
        finalizeForkingMarket(localFixture, universe, market, True, tester.a1,
                              tester.k1, tester.a0, tester.k0, tester.a2,
                              tester.k2, [0, market.getNumTicks()],
                              [market.getNumTicks(), 0])
        assert newMarket.migrateThroughOneFork()

    # Redeem some disavowed take tokens
    assert stakeToken.balanceOf(tester.a0) > 0
    with TokenDelta(reputationToken, stakeToken.balanceOf(tester.a0),
                    tester.a0,
                    "Rep from disavowed token redemption did not transfer"):
        assert stakeToken.redeemDisavowedTokens(tester.a0)
Esempio n. 3
0
def test_forkMigration(localFixture, makeReport, finalizeByMigration, universe, cash, market):
    newMarket = localFixture.createReasonableBinaryMarket(universe, cash)
    completeSets = localFixture.contracts['CompleteSets']

    # Generate some fees to confirm the market migration also migrates fees
    cost = 10 * newMarket.getNumTicks()
    assert completeSets.publicBuyCompleteSets(newMarket.address, 10, sender=tester.k1, value=cost)
    assert completeSets.publicSellCompleteSets(newMarket.address, 10, sender=tester.k1)
    assert cash.balanceOf(newMarket.getReportingWindow()) > 0

    # We'll do a designated report in the new market based on the makeReport param used for the forking market
    proceedToDesignatedReporting(localFixture, universe, newMarket, [0,market.getNumTicks()])
    if (makeReport):
        localFixture.designatedReport(newMarket, [0,market.getNumTicks()], tester.k0)

    # We proceed the standard market to the FORKING state
    proceedToForking(localFixture, universe, market, makeReport, 1, 2, 3, [0,market.getNumTicks()], [market.getNumTicks(),0], 2, [market.getNumTicks(),0], [0,market.getNumTicks()], [market.getNumTicks(),0])

    # The market we created is now awaiting migration
    assert newMarket.getReportingState() == localFixture.contracts['Constants'].AWAITING_FORK_MIGRATION()

    # If we attempt to migrate now it will not work since the forking market is not finalized
    with raises(TransactionFailed, message="Migration cannot occur until the forking market is finalized"):
        newMarket.migrateThroughOneFork()

    # We'll finalize the forking market
    finalizeForkingMarket(localFixture, universe, market, finalizeByMigration, tester.a1, tester.k1, tester.a0, tester.k0, tester.a2, tester.k2, [0,market.getNumTicks()], [market.getNumTicks(),0])

    # Now we can migrate the market to the winning universe. We also confirm that migration will move fees
    windowCashBalance = cash.balanceOf(newMarket.getReportingWindow())
    with TokenDelta(cash, -windowCashBalance, newMarket.getReportingWindow(), "Fork migration did not trigger window fee migratgion"):
        assert newMarket.migrateThroughOneFork()

    assert cash.balanceOf(newMarket.getReportingWindow()) == windowCashBalance

    # Now that we're on the correct universe we are send back to the DESIGNATED DISPUTE phase, which in the case of no designated reporter means the FIRST Reporting phase
    if (makeReport):
        assert newMarket.getReportingState() == localFixture.contracts['Constants'].DESIGNATED_DISPUTE()
    else:
        assert newMarket.getReportingState() == localFixture.contracts['Constants'].FIRST_REPORTING()
Esempio n. 4
0
def test_dispute_bond_token_migration(invalidRep, yesRep, noRep, designatedMigration, firstMigration, lastMigration, finalizeByMigration, localFixture, universe, cash, market):
    reputationToken = localFixture.applySignature("ReputationToken", universe.getReputationToken())
    completeSets = localFixture.contracts['CompleteSets']
    YES_OUTCOME = [market.getNumTicks(),0]
    NO_OUTCOME = [0,market.getNumTicks()]
    INVALID_OUTCOME = [market.getNumTicks() / 2,market.getNumTicks() / 2]
    YES_DISTRIBUTION_HASH = market.derivePayoutDistributionHash(YES_OUTCOME, False)
    NO_DISTRIBUTION_HASH = market.derivePayoutDistributionHash(NO_OUTCOME, False)
    INVALID_DISTRIBUTION_HASH = market.derivePayoutDistributionHash(INVALID_OUTCOME, True)

    # We proceed the standard market to the FORKING state
    proceedToForking(localFixture, universe, market, True, 1, 2, 3, NO_OUTCOME, YES_OUTCOME, 2, YES_OUTCOME, NO_OUTCOME, YES_OUTCOME)

    # We have 3 dispute bonds for the market
    designatedDisputeBond = localFixture.applySignature('DisputeBond', market.getDesignatedReporterDisputeBond())
    firstDisputeBond = localFixture.applySignature('DisputeBond', market.getFirstReportersDisputeBond())
    lastDisputeBond = localFixture.applySignature('DisputeBond', market.getLastReportersDisputeBond())

    # Validate the owners
    assert designatedDisputeBond.getOwner() == bytesToHexString(tester.a1)
    assert firstDisputeBond.getOwner() == bytesToHexString(tester.a2)
    assert lastDisputeBond.getOwner() == bytesToHexString(tester.a0)

    # Validate the disputes outcomes
    assert designatedDisputeBond.getDisputedPayoutDistributionHash() == NO_DISTRIBUTION_HASH
    assert firstDisputeBond.getDisputedPayoutDistributionHash() == YES_DISTRIBUTION_HASH
    assert lastDisputeBond.getDisputedPayoutDistributionHash() == YES_DISTRIBUTION_HASH

    # Get 3 Universe's that may be used as migration targets
    yesUniverse = localFixture.applySignature("Universe", universe.getOrCreateChildUniverse(YES_DISTRIBUTION_HASH))
    noUniverse = localFixture.applySignature("Universe", universe.getOrCreateChildUniverse(NO_DISTRIBUTION_HASH))
    invalidUniverse = localFixture.applySignature("Universe", universe.getOrCreateChildUniverse(INVALID_DISTRIBUTION_HASH))
    universeMap = {0: invalidUniverse, 1:yesUniverse, 2:noUniverse}

    if (invalidRep > 0):
        reputationToken.migrateOut(invalidUniverse.getReputationToken(), tester.a3, invalidRep, sender=tester.k3)
    if (yesRep > 0):
        reputationToken.migrateOut(yesUniverse.getReputationToken(), tester.a3, invalidRep, sender=tester.k3)
    if (noRep > 0):
        reputationToken.migrateOut(noUniverse.getReputationToken(), tester.a3, invalidRep, sender=tester.k3)

    if (designatedMigration[0]):
        destinationUniverse = universeMap[designatedMigration[1]]
        doBondWithdraw(localFixture, designatedDisputeBond, True, market, universe, reputationToken, destinationUniverse, tester.a1, tester.k1)
    if (firstMigration[0]):
        destinationUniverse = universeMap[firstMigration[1]]
        doBondWithdraw(localFixture, firstDisputeBond, True, market, universe, reputationToken, destinationUniverse, tester.a2, tester.k2)
    if (lastMigration[0]):
        destinationUniverse = universeMap[lastMigration[1]]
        doBondWithdraw(localFixture, lastDisputeBond, True, market, universe, reputationToken, destinationUniverse, tester.a0, tester.k0)

    # We'll finalize the forking market. If we finalize by migrating REP we'll get the bonus since dispute bonds have that perk. If we wait till the window is over to finalize though we get no such benefit
    finalizeForkingMarket(localFixture, universe, market, finalizeByMigration, tester.a1, tester.k1, tester.a0, tester.k0, tester.a2, tester.k2, NO_OUTCOME, YES_OUTCOME)

    if (not designatedMigration[0]):
        destinationUniverse = universeMap[designatedMigration[1]]
        doBondWithdraw(localFixture, designatedDisputeBond, finalizeByMigration, market, universe, reputationToken, destinationUniverse, tester.a1, tester.k1)
    if (not firstMigration[0]):
        destinationUniverse = universeMap[firstMigration[1]]
        doBondWithdraw(localFixture, firstDisputeBond, finalizeByMigration, market, universe, reputationToken, destinationUniverse, tester.a2, tester.k2)
    if (not lastMigration[0]):
        destinationUniverse = universeMap[lastMigration[1]]
        doBondWithdraw(localFixture, lastDisputeBond, finalizeByMigration, market, universe, reputationToken, destinationUniverse, tester.a0, tester.k0)
Esempio n. 5
0
def test_forking(localFixture, makeReport, finalizeByMigration, universe, market):
    # Proceed to the FORKING phase
    proceedToForking(localFixture, universe, market, makeReport, 1, 3, 3, [0,market.getNumTicks()], [market.getNumTicks(),0], 2, [market.getNumTicks(),0], [0,market.getNumTicks()], [market.getNumTicks(),0])

    # Finalize the market
    finalizeForkingMarket(localFixture, universe, market, finalizeByMigration, tester.a1, tester.k1, tester.a0, tester.k0, tester.a2, tester.k2, [0,market.getNumTicks()], [market.getNumTicks(),0])