Пример #1
0
def test_fee_window_record_keeping(localFixture, universe, cash, market, categoricalMarket, scalarMarket):
    feeWindow = localFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())

    # First we'll confirm we get the expected default values for the window record keeping
    assert feeWindow.getNumMarkets() == 0
    assert feeWindow.getNumInvalidMarkets() == 0
    assert feeWindow.getNumIncorrectDesignatedReportMarkets() == 0
    assert feeWindow.getNumDesignatedReportNoShows() == 0

    # Go to designated reporting
    proceedToDesignatedReporting(localFixture, market)

    # Do a report that we'll make incorrect
    assert market.doInitialReport([0, market.getNumTicks()], False)

    # Do a report for a market we'll say is invalid
    assert categoricalMarket.doInitialReport([0, 0, categoricalMarket.getNumTicks()], False)

    # Designated reporter doesn't show up for the third market. Go into initial reporting and do a report by someone else
    reputationToken = localFixture.applySignature('ReputationToken', universe.getReputationToken())
    reputationToken.transfer(tester.a1, 10**6 * 10**18)
    proceedToInitialReporting(localFixture, scalarMarket)
    assert scalarMarket.doInitialReport([0, scalarMarket.getNumTicks()], False, sender=tester.k1)

    # proceed to the window start time
    feeWindow = localFixture.applySignature('FeeWindow', market.getFeeWindow())
    localFixture.contracts["Time"].setTimestamp(feeWindow.getStartTime() + 1)

    # dispute the first market
    chosenPayoutNumerators = [market.getNumTicks(), 0]
    chosenPayoutHash = market.derivePayoutDistributionHash(chosenPayoutNumerators, False)
    amount = 2 * market.getParticipantStake() - 3 * market.getStakeInOutcome(chosenPayoutHash)
    assert market.contribute(chosenPayoutNumerators, False, amount)
    newFeeWindowAddress = market.getFeeWindow()
    assert newFeeWindowAddress != feeWindow

    # dispute the second market with an invalid outcome
    chosenPayoutNumerators = [categoricalMarket.getNumTicks() / 3, categoricalMarket.getNumTicks() / 3, categoricalMarket.getNumTicks() / 3]
    chosenPayoutHash = categoricalMarket.derivePayoutDistributionHash(chosenPayoutNumerators, True)
    amount = 2 * categoricalMarket.getParticipantStake() - 3 * categoricalMarket.getStakeInOutcome(chosenPayoutHash)
    assert categoricalMarket.contribute(chosenPayoutNumerators, True, amount)
    assert categoricalMarket.getFeeWindow() != feeWindow

    # progress time forward
    feeWindow = localFixture.applySignature('FeeWindow', newFeeWindowAddress)
    localFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)

    # finalize the markets
    assert market.finalize()
    assert categoricalMarket.finalize()
    assert scalarMarket.finalize()

    # Now we'll confirm the record keeping was updated
    assert feeWindow.getNumMarkets() == 2
    assert feeWindow.getNumInvalidMarkets() == 1
    assert feeWindow.getNumIncorrectDesignatedReportMarkets() == 2

    feeWindow = localFixture.applySignature('FeeWindow', scalarMarket.getFeeWindow())
    assert feeWindow.getNumMarkets() == 1
    assert feeWindow.getNumDesignatedReportNoShows() == 1
def test_no_show_bond_up(contractsFixture, universe, market):
    noShowBond = universe.getOrCacheDesignatedReportNoShowBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will be absent and we'll do an initial report as another user
    numTicks = market.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market.doInitialReport(payoutNumerators,
                                  "",
                                  0,
                                  sender=contractsFixture.accounts[1])

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond is now doubled in the next dispute window
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    expectedNoShowBond = noShowBond * 2
    noShowBondChangedLog = {
        "universe": universe.address,
        "noShowBond": expectedNoShowBond,
    }
    with AssertLog(contractsFixture, "NoShowBondChanged",
                   noShowBondChangedLog):
        newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == expectedNoShowBond
Пример #3
0
def test_initialReportHappyPath(reportByDesignatedReporter, localFixture,
                                universe, market):
    # proceed to the initial reporting period
    proceedToInitialReporting(localFixture, market)

    # do an initial report as someone other than the designated reporter
    sender = localFixture.accounts[
        0] if reportByDesignatedReporter else localFixture.accounts[1]
    assert market.doInitialReport([0, 0, market.getNumTicks()],
                                  "",
                                  sender=sender)

    # the market is now assigned a dispute window
    newDisputeWindowAddress = market.getDisputeWindow()
    assert newDisputeWindowAddress
    disputeWindow = localFixture.applySignature('DisputeWindow',
                                                newDisputeWindowAddress)

    # Confirm that with the designated report we initially have a different time period than normal to dispute
    assert disputeWindow.duration() == localFixture.contracts[
        "Constants"].INITIAL_DISPUTE_ROUND_DURATION_SECONDS()

    # time marches on and the market can be finalized
    localFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert market.finalize()
def test_no_show_bond_down(contractsFixture, universe, market, cash):
    noShowBond = universe.getOrCacheDesignatedReportNoShowBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will be absent and we'll do an initial report as another user
    numTicks = market.getNumTicks()
    payoutNumerators = [numTicks, 0]
    assert market.doInitialReport(payoutNumerators, False, sender=tester.k1)

    # Move time forward to finalize the market
    feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond is now doubled in the next fee window
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == noShowBond * 2

    # Wait for a fee window with no markets to se the bond decrease
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert universe.getOrCacheDesignatedReportNoShowBond() == noShowBond
def test_no_show_bond_min(contractsFixture, universe, market):
    noShowBond = universe.getOrCacheDesignatedReportNoShowBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will show up
    numTicks = market.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market.doInitialReport(payoutNumerators, "")

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond does not reduce below the original value
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == noShowBond
def test_dr_report_stake_down(contractsFixture, universe, market, cash):
    designatedReportStake = universe.getOrCacheDesignatedReportStake()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will report
    numTicks = market.getNumTicks()
    payoutNumerators = [numTicks, 0]
    assert market.doInitialReport(payoutNumerators, False)

    # Proceed to the next round so we can dispute the DR
    feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getStartTime() + 1)
    payoutNumerators = [0, numTicks]
    chosenPayoutHash = market.derivePayoutDistributionHash(payoutNumerators, False)
    amount = 2 * market.getParticipantStake() - 3 * market.getStakeInOutcome(chosenPayoutHash)
    assert market.contribute(payoutNumerators, False, amount)

    # Move time forward to finalize the market
    feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond is now doubled in the next fee window
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    newDesignatedReportStake = universe.getOrCacheDesignatedReportStake()
    assert newDesignatedReportStake == designatedReportStake * 2

    # Now we'll allow a window to pass with no markets and see the bond decrease
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert universe.getOrCacheDesignatedReportStake() == designatedReportStake
def test_no_show_bond_down(contractsFixture, universe, market, cash):
    noShowBond = universe.getOrCacheDesignatedReportNoShowBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will be absent and we'll do an initial report as another user
    numTicks = market.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market.doInitialReport(payoutNumerators, "", sender=tester.k1)

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond is now doubled in the next dispute window
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == noShowBond * 2

    # Wait for a dispute window with no markets to se the bond decrease
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert universe.getOrCacheDesignatedReportNoShowBond() == noShowBond
def test_dr_report_stake_up(contractsFixture, universe, market):
    designatedReportStake = universe.getOrCacheDesignatedReportStake()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will report
    numTicks = market.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market.doInitialReport(payoutNumerators, "")

    # Proceed to the next round so we can dispute the DR
    disputeWindow = contractsFixture.applySignature('DisputeWindow', market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getStartTime() + 1)
    payoutNumerators = [0, 0, numTicks]
    chosenPayoutHash = market.derivePayoutDistributionHash(payoutNumerators)
    amount = 2 * market.getParticipantStake() - 3 * market.getStakeInOutcome(chosenPayoutHash)
    assert market.contribute(payoutNumerators, amount, "")

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow', market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond is now doubled in the next dispute window
    disputeWindow = contractsFixture.applySignature('DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    newDesignatedReportStake = universe.getOrCacheDesignatedReportStake()
    assert newDesignatedReportStake == designatedReportStake * 2
Пример #9
0
def test_initial_reporter_gas_costs(numReports, gasPrice, reportingFixture, universe, market, categoricalMarket, scalarMarket):
    markets = [market, categoricalMarket, scalarMarket]

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(reportingFixture, market)

    for i in range(0, numReports):
        curMarket = markets[i]
        payoutNumerators = [0] * curMarket.getNumberOfOutcomes()
        payoutNumerators[0] = curMarket.getNumTicks()
        assert curMarket.doInitialReport(payoutNumerators, False, sender=tester.k1, gasprice=gasPrice)

    # The target reporter gas cost is an attempt to charge the market creator for the estimated cost of reporting that may occur for their market. It will use the previous fee window's data to estimate costs if it is available
    feeWindow = reportingFixture.applySignature('FeeWindow', market.getFeeWindow())

    # Now we'll skip ahead in time and finalize the market
    reportingFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    for i in range(0, numReports):
        assert markets[i].finalize()

    actualAvgGasPrice = feeWindow.getAvgReportingGasPrice()
    expectedAvgReportingGasCost = (reportingFixture.contracts['Constants'].DEFAULT_REPORTING_GAS_PRICE() + gasPrice * numReports) / (numReports + 1)
    assert actualAvgGasPrice == expectedAvgReportingGasCost

    # Confirm our estimated gas cost is caluclated as expected
    expectedTargetReporterGasCost = reportingFixture.contracts['Constants'].GAS_TO_REPORT()
    expectedTargetReporterGasCost *= expectedAvgReportingGasCost
    expectedTargetReporterGasCost *= 2
    targetReporterGasCosts = universe.getOrCacheTargetReporterGasCosts()
    assert targetReporterGasCosts == expectedTargetReporterGasCost
Пример #10
0
def test_warp_sync(contractsFixture, augur, universe, reputationToken, warpSync, cash):
    account = contractsFixture.accounts[0]
    time = contractsFixture.contracts["Time"]

    # See that warp sync market does not exist initially
    assert warpSync.markets(universe.address) == nullAddress

    # We can initialize the warp sync market for a universe and be rewarded with REP based on how long since the universe was created
    expectedCreationReward = warpSync.getCreationReward(universe.address)
    with PrintGasUsed(contractsFixture, "WS Market Finalization Cost", 0):
        with TokenDelta(reputationToken, expectedCreationReward, account, "REP reward not minted for initializing universe"):
            warpSync.initializeUniverse(universe.address)

    # The market now exists
    market = contractsFixture.applySignature("Market", warpSync.markets(universe.address))

    # Initially there is no warp sync data for this universe
    assert warpSync.data(universe.address) == [0, 0]

    # Finalize the warp sync market with some value
    proceedToDesignatedReporting(contractsFixture, market)
    numTicks = market.getNumTicks()
    assert warpSync.doInitialReport(universe.address, [0,0,numTicks], "")
    disputeWindow = contractsFixture.applySignature("DisputeWindow", market.getDisputeWindow())

    time.setTimestamp(disputeWindow.getEndTime())

    # Finalizing the warp sync market will award the finalizer REP based on time since it became finalizable
    expectedFinalizationReward = warpSync.getFinalizationReward(market.address)
    WarpSyncDataUpdatedLog = {
        "universe": universe.address,
        "warpSyncHash": numTicks,
        "marketEndTime": market.getEndTime()
    }
    with AssertLog(contractsFixture, "WarpSyncDataUpdated", WarpSyncDataUpdatedLog):
        with PrintGasUsed(contractsFixture, "WS Market Finalization Cost", 0):
            with TokenDelta(reputationToken, expectedFinalizationReward, account, "REP reward not minted for finalizer"):
                assert market.finalize()

    # Check Warp Sync contract for universe and see existing value
    assert warpSync.data(universe.address) == [numTicks, market.getEndTime()]

    # See new warp sync market
    newWarpSyncMarket = contractsFixture.applySignature("Market", warpSync.markets(universe.address))
    assert newWarpSyncMarket.address != market.address

    # Finalize it
    proceedToInitialReporting(contractsFixture, newWarpSyncMarket)
    numTicks = newWarpSyncMarket.getNumTicks()
    assert newWarpSyncMarket.doInitialReport([0,1,numTicks-1], "", 0)
    disputeWindow = contractsFixture.applySignature("DisputeWindow", newWarpSyncMarket.getDisputeWindow())

    time.setTimestamp(disputeWindow.getEndTime())
    assert newWarpSyncMarket.finalize()

    # See new warp sync value
    assert warpSync.data(universe.address) == [numTicks-1, newWarpSyncMarket.getEndTime()]

    # See another new market
    assert newWarpSyncMarket.address != warpSync.markets(universe.address)
Пример #11
0
def test_reports(kitchenSinkFixture, universe, cash, market):
    auditFunds = kitchenSinkFixture.contracts['AuditFunds']

    account = kitchenSinkFixture.accounts[0]

    proceedToInitialReporting(kitchenSinkFixture, market)

    repBond = market.repBond()

    # do an initial report
    assert market.doInitialReport([0, 0, market.getNumTicks()], "", 0)

    # the market is now assigned a dispute window
    newDisputeWindowAddress = market.getDisputeWindow()
    disputeWindow = kitchenSinkFixture.applySignature('DisputeWindow', newDisputeWindowAddress)

    # time marches on and the market can be finalized
    kitchenSinkFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert market.finalize()

    reportResult, done = auditFunds.getAvailableReports(account, 0, 1)
    assert len(reportResult) == 1
    assert done == False
    assert reportResult[0] [0] == market.address
    assert reportResult[0][2] == repBond

    results, done = auditFunds.getAvailableReports(account, 0, 10)
    assert done
    assert results[0][0] == market.address
    assert results[0][2] == repBond
def test_dr_report_stake_min(contractsFixture, universe, market):
    designatedReportStake = universe.getOrCacheDesignatedReportStake()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will report
    numTicks = market.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market.doInitialReport(payoutNumerators, "")

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond doesn't change since it is at the minimum value
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    newDesignatedReportStake = universe.getOrCacheDesignatedReportStake()
    assert newDesignatedReportStake == designatedReportStake
Пример #13
0
def test_no_show_bond_down(contractsFixture, universe, market,
                           categoricalMarket, cash):
    noShowBond = universe.getOrCacheDesignatedReportNoShowBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will be absent and we'll do an initial report as another user
    numTicks = market.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market.doInitialReport(payoutNumerators,
                                  "",
                                  sender=contractsFixture.accounts[1])

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond is now doubled in the next dispute window
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == noShowBond * 2

    # If there is a dispute window with no markets we'll just see the bond remain the same
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert universe.getOrCacheDesignatedReportNoShowBond() == newNoShowBond

    # Now if there is another window with all shows we see the bond decrease
    # The DR will report
    numTicks = categoricalMarket.getNumTicks()
    payoutNumerators = [0, numTicks, 0, 0]
    assert categoricalMarket.doInitialReport(
        payoutNumerators, "", sender=contractsFixture.accounts[0])

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', categoricalMarket.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert categoricalMarket.finalize()

    expectedBond = int(Decimal(newNoShowBond) * 9 / 10)
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', categoricalMarket.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert universe.getOrCacheDesignatedReportNoShowBond() == expectedBond
def test_market_rep_bond(contractsFixture, universe, market, cash):
    noShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    designatedReportStake = universe.getOrCacheDesignatedReportStake()

    assert universe.getOrCacheMarketRepBond() == max(noShowBond,
                                                     designatedReportStake)

    # Increase the no show bond:
    numTicks = market.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    proceedToInitialReporting(contractsFixture, market)
    assert market.doInitialReport(payoutNumerators,
                                  "",
                                  0,
                                  sender=contractsFixture.accounts[1])
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market.finalize()
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == noShowBond * 2

    # The market REP bond is now equal to this higher bond:
    assert universe.getOrCacheMarketRepBond() == newNoShowBond
Пример #15
0
def test_warp_sync_finalization_reward(contractsFixture, augur, universe,
                                       reputationToken, warpSync):
    account = contractsFixture.accounts[0]
    time = contractsFixture.contracts["Time"]

    warpSync.initializeUniverse(universe.address)
    market = contractsFixture.applySignature(
        "Market", warpSync.markets(universe.address))

    proceedToInitialReporting(contractsFixture, market)
    numTicks = market.getNumTicks()
    assert market.doInitialReport([0, 0, numTicks], "", 0)
    disputeWindow = contractsFixture.applySignature("DisputeWindow",
                                                    market.getDisputeWindow())

    time.setTimestamp(disputeWindow.getEndTime())

    # The finalization reward grows as we get further out from the possible finalization time
    finalizationReward = warpSync.getFinalizationReward(market.address)
    # Initially it is 0
    assert finalizationReward == 0

    # After a day it will be about 0.64 REP
    day = 24 * 60 * 60
    time.incrementTimestamp(day)
    expectedFinalizationReward = (day**3) * 1000
    finalizationReward = warpSync.getFinalizationReward(market.address)
    assert finalizationReward == expectedFinalizationReward

    # After a week it will be about 221 REP
    time.incrementTimestamp(6 * day)
    expectedFinalizationReward = ((7 * day)**3) * 1000
    finalizationReward = warpSync.getFinalizationReward(market.address)
    assert finalizationReward == expectedFinalizationReward
Пример #16
0
def test_warp_sync_gets_forked(contractsFixture, augur, universe,
                               reputationToken, warpSync):
    account = contractsFixture.accounts[0]
    time = contractsFixture.contracts["Time"]

    # See warp sync market
    warpSync.initializeUniverse(universe.address)
    market = contractsFixture.applySignature(
        "Market", warpSync.markets(universe.address))

    # Fork warp sync market
    proceedToFork(contractsFixture, market, universe)
    finalize(contractsFixture, market, universe)

    # See that market finalizes but no new warp sync market exists
    assert market.isFinalized()
    assert market.address == warpSync.markets(universe.address)

    # See warp sync markets dont exists for child universes initially until initialization
    shortPayoutNumerators = [0] * market.getNumberOfOutcomes()
    shortPayoutNumerators[1] = market.getNumTicks()
    longPayoutNumerators = [0] * market.getNumberOfOutcomes()
    longPayoutNumerators[2] = market.getNumTicks()
    shortUniverse = contractsFixture.applySignature(
        'Universe', universe.createChildUniverse(shortPayoutNumerators))
    longUniverse = contractsFixture.applySignature(
        'Universe', universe.createChildUniverse(longPayoutNumerators))

    warpSync.initializeUniverse(shortUniverse.address)
    warpSync.initializeUniverse(longUniverse.address)
    shortUniverseMarket = contractsFixture.applySignature(
        "Market", warpSync.markets(shortUniverse.address))
    longUniverseMarket = contractsFixture.applySignature(
        "Market", warpSync.markets(longUniverse.address))

    assert shortUniverseMarket.address != nullAddress
    assert longUniverseMarket.address != nullAddress

    # Initially there is no warp sync data for the child universe
    assert warpSync.data(shortUniverseMarket.address) == [0, 0]

    # Finalize the warp sync market with some value
    proceedToInitialReporting(contractsFixture, shortUniverseMarket)
    numTicks = shortUniverseMarket.getNumTicks()
    assert shortUniverseMarket.doInitialReport([0, 0, numTicks], "", 0)
    disputeWindow = contractsFixture.applySignature(
        "DisputeWindow", shortUniverseMarket.getDisputeWindow())

    time.setTimestamp(disputeWindow.getEndTime())
    assert shortUniverseMarket.finalize()

    # Check Warp Sync contract for universe and see existing value
    assert warpSync.data(
        shortUniverse.address) == [numTicks,
                                   shortUniverseMarket.getEndTime()]

    # See new warp sync market
    newWarpSyncMarket = contractsFixture.applySignature(
        "Market", warpSync.markets(shortUniverse.address))
    assert newWarpSyncMarket.address != shortUniverseMarket.address
def test_validity_bond_up(contractsFixture, universe, market):
    initialValidityBond = universe.getOrCacheValidityBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will admit the market is invalid
    payoutNumerators = [100, 0, 0]
    assert market.doInitialReport(payoutNumerators, "", 0)

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the validity bond is now doubled in the next dispute window
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    expectedValidityBond = initialValidityBond * 2
    validityBondChangedLog = {
        "universe": universe.address,
        "validityBond": expectedValidityBond,
    }
    with AssertLog(contractsFixture, "ValidityBondChanged",
                   validityBondChangedLog):
        newValidityBond = universe.getOrCacheValidityBond()
    assert newValidityBond == expectedValidityBond
Пример #18
0
def test_initialReport_methods(localFixture, universe, market, cash, constants):
    reputationToken = localFixture.applySignature("ReputationToken", universe.getReputationToken())

    # proceed to the initial reporting period
    proceedToInitialReporting(localFixture, market)

    # do an initial report as someone other than the designated reporter
    assert market.doInitialReport([0, market.getNumTicks()], False, sender=tester.k1)

    # the market is now assigned a fee window
    newFeeWindowAddress = market.getFeeWindow()
    assert newFeeWindowAddress
    feeWindow = localFixture.applySignature('FeeWindow', newFeeWindowAddress)

    # time marches on and the market can be finalized
    localFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # We can see that the market reports the designated reporter did not show
    assert not market.designatedReporterShowed()

    # Let's get a reference to the Initial Reporter bond and transfer it to the original designated reporter account
    initialReporter = localFixture.applySignature("InitialReporter", market.getInitialReporter())
    transferLog = {
        "universe": universe.address,
        "market": market.address,
        "from": bytesToHexString(tester.a1),
        "to": initialReporter.getDesignatedReporter(),
    }
    with AssertLog(localFixture, "InitialReporterTransferred", transferLog):
        assert initialReporter.transferOwnership(initialReporter.getDesignatedReporter(), sender=tester.k1)

    # Transfering to the owner is a noop
    assert initialReporter.transferOwnership(initialReporter.getDesignatedReporter())

    # The market still correctly indicates the designated reporter did not show up
    assert not market.designatedReporterShowed()

    # confirm we cannot call protected methods on the initial reporter which only the market may use
    with raises(TransactionFailed):
        initialReporter.report(tester.a0, "", [], False)

    with raises(TransactionFailed):
        initialReporter.resetReportTimestamp()

    with raises(TransactionFailed):
        initialReporter.migrateREP()

    # When we redeem the initialReporter it goes to the correct party as well
    expectedRep = initialReporter.getStake()
    owner = initialReporter.getOwner()

    expectedGasBond = 2 * constants.GAS_TO_REPORT() * constants.DEFAULT_REPORTING_GAS_PRICE()
    with EtherDelta(expectedGasBond, owner, localFixture.chain, "Initial reporter did not get the reporting gas cost bond"):
        with TokenDelta(reputationToken, expectedRep, owner, "Redeeming didn't refund REP"):
            assert initialReporter.redeem(owner)
Пример #19
0
def test_initialReport_methods(localFixture, universe, market, constants):
    reputationToken = localFixture.applySignature("ReputationToken", universe.getReputationToken())

    # proceed to the initial reporting period
    proceedToInitialReporting(localFixture, market)

    # do an initial report as someone other than the designated reporter
    assert market.doInitialReport([0, 0, market.getNumTicks()], "", sender=tester.k1)

    # the market is now assigned a dispute window
    newDisputeWindowAddress = market.getDisputeWindow()
    assert newDisputeWindowAddress
    disputeWindow = localFixture.applySignature('DisputeWindow', newDisputeWindowAddress)

    # time marches on and the market can be finalized
    localFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # We can see that the market reports the designated reporter did not show
    assert not market.designatedReporterShowed()

    # Let's get a reference to the Initial Reporter bond and transfer it to the original designated reporter account
    initialReporter = localFixture.applySignature("InitialReporter", market.getInitialReporter())
    transferLog = {
        "universe": universe.address,
        "market": market.address,
        "from": bytesToHexString(tester.a1),
        "to": initialReporter.getDesignatedReporter(),
    }
    with AssertLog(localFixture, "InitialReporterTransferred", transferLog):
        assert initialReporter.transferOwnership(initialReporter.getDesignatedReporter(), sender=tester.k1)

    # Transfering to the owner is a noop
    assert initialReporter.transferOwnership(initialReporter.getDesignatedReporter())

    # The market still correctly indicates the designated reporter did not show up
    assert not market.designatedReporterShowed()

    # confirm we cannot call protected methods on the initial reporter which only the market may use
    with raises(TransactionFailed):
        initialReporter.report(tester.a0, "", [], False)

    with raises(TransactionFailed):
        initialReporter.returnRepFromDisavow()

    with raises(TransactionFailed):
        initialReporter.migrateToNewUniverse(tester.a0)

    # When we redeem the initialReporter it goes to the correct party as well
    expectedRep = initialReporter.getStake()
    owner = initialReporter.getOwner()

    with TokenDelta(reputationToken, expectedRep, owner, "Redeeming didn't refund REP"):
        assert initialReporter.redeem(owner)
Пример #20
0
def test_initialReport_transfer_ownership(localFixture, universe, market, cash,
                                          constants):
    reputationToken = localFixture.applySignature(
        "ReputationToken", universe.getReputationToken())

    # proceed to the initial reporting period
    proceedToInitialReporting(localFixture, market)

    # do an initial report as someone other than the designated reporter
    assert market.doInitialReport([0, market.getNumTicks()],
                                  False,
                                  sender=tester.k1)

    # the market is now assigned a fee window
    newFeeWindowAddress = market.getFeeWindow()
    assert newFeeWindowAddress
    feeWindow = localFixture.applySignature('FeeWindow', newFeeWindowAddress)

    # time marches on and the market can be finalized
    localFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # We can see that the market reports the designated reporter did not show
    assert not market.designatedReporterShowed()

    # Let's get a reference to the Initial Reporter bond and transfer it to the original designated reporter account
    initialReporter = localFixture.applySignature("InitialReporter",
                                                  market.getInitialReporter())
    transferLog = {
        "universe": universe.address,
        "market": market.address,
        "from": bytesToHexString(tester.a1),
        "to": initialReporter.getDesignatedReporter(),
    }
    with AssertLog(localFixture, "InitialReporterTransfered", transferLog):
        assert initialReporter.transferOwnership(
            initialReporter.getDesignatedReporter(), sender=tester.k1)

    # The market still correctly indicates the designated reporter did not show up
    assert not market.designatedReporterShowed()

    # When we redeem the initialReporter it goes to the correct party as well
    expectedRep = initialReporter.getStake()
    owner = initialReporter.getOwner()

    expectedGasBond = 2 * constants.GAS_TO_REPORT(
    ) * constants.DEFAULT_REPORTING_GAS_PRICE()
    with EtherDelta(
            expectedGasBond, owner, localFixture.chain,
            "Initial reporter did not get the reporting gas cost bond"):
        with TokenDelta(reputationToken, expectedRep, owner,
                        "Redeeming didn't refund REP"):
            assert initialReporter.redeem(owner)
Пример #21
0
def test_dr_report_stake_down(contractsFixture, universe, market, categoricalMarket, cash):
    designatedReportStake = universe.getOrCacheDesignatedReportStake()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will report
    numTicks = market.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market.doInitialReport(payoutNumerators, "")

    # Proceed to the next round so we can dispute the DR
    disputeWindow = contractsFixture.applySignature('DisputeWindow', market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getStartTime() + 1)
    payoutNumerators = [0, 0, numTicks]
    chosenPayoutHash = market.derivePayoutDistributionHash(payoutNumerators)
    amount = 2 * market.getParticipantStake() - 3 * market.getStakeInOutcome(chosenPayoutHash)
    assert market.contribute(payoutNumerators, amount, "")

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow', market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond is now doubled in the next dispute window
    disputeWindow = contractsFixture.applySignature('DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    newDesignatedReportStake = universe.getOrCacheDesignatedReportStake()
    assert newDesignatedReportStake == designatedReportStake * 2

    # Now we'll allow a window to pass with no markets and see the bond stay the same
    disputeWindow = contractsFixture.applySignature('DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert universe.getOrCacheDesignatedReportStake() == newDesignatedReportStake

    # Now if there is another window with all correct we see the bond decrease
    # The DR will report
    numTicks = categoricalMarket.getNumTicks()
    payoutNumerators = [0, numTicks, 0, 0]
    assert categoricalMarket.doInitialReport(payoutNumerators, "", sender=tester.k0)

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow', categoricalMarket.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert categoricalMarket.finalize()

    expectedBond = newDesignatedReportStake * 9 / 10
    disputeWindow = contractsFixture.applySignature('DisputeWindow', categoricalMarket.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    disputeWindow = contractsFixture.applySignature('DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert universe.getOrCacheDesignatedReportStake() == expectedBond
Пример #22
0
def test_reporting(kitchenSinkFixture, augur, cash, market):
    hotLoading = kitchenSinkFixture.contracts[
        "HotLoadingUniversal"] if kitchenSinkFixture.paraAugur else kitchenSinkFixture.contracts[
            "HotLoading"]
    if kitchenSinkFixture.paraAugur:
        augur = kitchenSinkFixture.contracts["ParaAugur"]
    fillOrder = kitchenSinkFixture.contracts["FillOrder"]
    orders = kitchenSinkFixture.contracts["Orders"]
    account = kitchenSinkFixture.accounts[0]

    # Get to Designated Reporting
    proceedToDesignatedReporting(kitchenSinkFixture, market)
    marketData = getMarketData(hotLoading, augur, market, fillOrder, orders)
    assert marketData.reportingState == 1
    assert marketData.disputeRound == 0

    # Get to Open Reporting
    proceedToInitialReporting(kitchenSinkFixture, market)
    marketData = getMarketData(hotLoading, augur, market, fillOrder, orders)
    assert marketData.reportingState == 2
    assert marketData.disputeRound == 0

    # Get to Disputing
    proceedToNextRound(kitchenSinkFixture, market)
    marketData = getMarketData(hotLoading, augur, market, fillOrder, orders)
    assert marketData.reportingState == 3
    assert marketData.disputeRound == 0

    # Proceed to next round
    proceedToNextRound(kitchenSinkFixture, market)
    marketData = getMarketData(hotLoading, augur, market, fillOrder, orders)
    assert marketData.reportingState == 3
    assert marketData.disputeRound == 1

    # Get to Awaiting Next Window
    while not market.getDisputePacingOn():
        proceedToNextRound(kitchenSinkFixture, market, moveTimeForward=False)
    marketData = getMarketData(hotLoading, augur, market, fillOrder, orders)
    assert marketData.reportingState == 4
    assert marketData.disputeRound == 11

    # Get to AwaitingFinalization
    kitchenSinkFixture.contracts["Time"].incrementTimestamp(30 * 24 * 60 * 60)
    marketData = getMarketData(hotLoading, augur, market, fillOrder, orders)
    assert marketData.reportingState == 5

    # get to Finalized
    market.finalize()
    marketData = getMarketData(hotLoading, augur, market, fillOrder, orders)
    assert marketData.reportingState == 6
Пример #23
0
def test_initialReportHappyPath(reportByDesignatedReporter, localFixture, universe, market):
    # proceed to the initial reporting period
    proceedToInitialReporting(localFixture, market)

    # do an initial report as someone other than the designated reporter
    sender = tester.k0 if reportByDesignatedReporter else tester.k1
    assert market.doInitialReport([0, 0, market.getNumTicks()], "", sender=sender)

    # the market is now assigned a dispute window
    newDisputeWindowAddress = market.getDisputeWindow()
    assert newDisputeWindowAddress
    disputeWindow = localFixture.applySignature('DisputeWindow', newDisputeWindowAddress)

    # time marches on and the market can be finalized
    localFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert market.finalize()
Пример #24
0
def test_initialReportHappyPath(reportByDesignatedReporter, localFixture, universe, market):
    # proceed to the initial reporting period
    proceedToInitialReporting(localFixture, market)

    # do an initial report as someone other than the designated reporter
    sender = tester.k0 if reportByDesignatedReporter else tester.k1
    assert market.doInitialReport([0, market.getNumTicks()], False, sender=sender)

    # the market is now assigned a fee window
    newFeeWindowAddress = market.getFeeWindow()
    assert newFeeWindowAddress
    feeWindow = localFixture.applySignature('FeeWindow', newFeeWindowAddress)

    # time marches on and the market can be finalized
    localFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()
def test_validity_bond_down(contractsFixture, universe, market, scalarMarket,
                            cash):
    initialValidityBond = universe.getOrCacheValidityBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will admit the market is invalid
    payoutNumerators = [10000, 0, 0]
    assert market.doInitialReport(payoutNumerators, "")

    # Move time forward into the dispute window and report on the other market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getStartTime() + 1)
    payoutNumerators = [0, 200000, 200000]
    assert scalarMarket.doInitialReport(payoutNumerators, "")

    # And then move time forward further and finalize the first market
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the validity bond is now doubled
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    newValidityBond = universe.getOrCacheValidityBond()
    assert newValidityBond == initialValidityBond * 2

    # Move time forward to finalize the other market
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', scalarMarket.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert scalarMarket.finalize()

    # Confirm that the validity bond is now halved
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    finalValidityBond = universe.getOrCacheValidityBond()
    assert finalValidityBond == newValidityBond / 2
Пример #26
0
def test_initialReportHappyPath(localFixture, universe, market):
    # proceed to the initial reporting period
    proceedToInitialReporting(localFixture, market)

    # do an initial report as someone other than the designated reporter
    assert market.doInitialReport([0, market.getNumTicks()],
                                  False,
                                  sender=tester.k1)

    # the market is now assigned a fee window
    newFeeWindowAddress = market.getFeeWindow()
    assert newFeeWindowAddress
    feeWindow = localFixture.applySignature('FeeWindow', newFeeWindowAddress)

    # time marches on and the market can be finalized
    localFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()
Пример #27
0
def test_validity_bond_min(contractsFixture, universe, market):
    initialValidityBond = universe.getOrCacheValidityBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will report the market had a normal resolution
    payoutNumerators = [0, 0, 10000]
    assert market.doInitialReport(payoutNumerators, "")

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow', market.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the validity bond stayed the same since it is at the minimum value
    disputeWindow = contractsFixture.applySignature('DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)
    newValidityBond = universe.getOrCacheValidityBond()
    assert newValidityBond == initialValidityBond
def test_validity_bond_up(contractsFixture, universe, market):
    initialValidityBond = universe.getOrCacheValidityBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will admit the market is invalid
    payoutNumerators = [5000, 5000]
    assert market.doInitialReport(payoutNumerators, True)

    # Move time forward to finalize the market
    feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the validity bond is now doubled in the next fee window
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    newValidityBond = universe.getOrCacheValidityBond()
    assert newValidityBond == initialValidityBond * 2
def test_validity_bond_min(contractsFixture, universe, market):
    initialValidityBond = universe.getOrCacheValidityBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will report the market had a normal resolution
    payoutNumerators = [0, 10000]
    assert market.doInitialReport(payoutNumerators, False)

    # Move time forward to finalize the market
    feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the validity bond stayed the same since it is at the minimum value
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    newValidityBond = universe.getOrCacheValidityBond()
    assert newValidityBond == initialValidityBond
def test_dr_report_stake_min(contractsFixture, universe, market):
    designatedReportStake = universe.getOrCacheDesignatedReportStake()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will report
    numTicks = market.getNumTicks()
    payoutNumerators = [numTicks, 0]
    assert market.doInitialReport(payoutNumerators, False)

    # Move time forward to finalize the market
    feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond doesn't change since it is at the minimum value
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    newDesignatedReportStake = universe.getOrCacheDesignatedReportStake()
    assert newDesignatedReportStake == designatedReportStake
def test_no_show_bond_min(contractsFixture, universe, market):
    noShowBond = universe.getOrCacheDesignatedReportNoShowBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will show up
    numTicks = market.getNumTicks()
    payoutNumerators = [numTicks, 0]
    assert market.doInitialReport(payoutNumerators, False)

    # Move time forward to finalize the market
    feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the report stake bond does not reduce below the original value
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == noShowBond
def test_validity_bond_down(contractsFixture, universe, market, scalarMarket, cash):
    initialValidityBond = universe.getOrCacheValidityBond()

    # We'll have the markets go to initial reporting
    proceedToInitialReporting(contractsFixture, market)

    # The DR will admit the market is invalid
    payoutNumerators = [5000, 5000]
    assert market.doInitialReport(payoutNumerators, True)

    # Move time forward into the fee window and report on the other market
    feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getStartTime() + 1)
    payoutNumerators = [200000, 200000]
    assert scalarMarket.doInitialReport(payoutNumerators, False)

    # And then move time forward further and finalize the first market
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert market.finalize()

    # Confirm that the validity bond is now doubled
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    newValidityBond = universe.getOrCacheValidityBond()
    assert newValidityBond == initialValidityBond * 2

    # Move time forward to finalize the other market
    feeWindow = contractsFixture.applySignature('FeeWindow', scalarMarket.getFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    assert scalarMarket.finalize()

    # Confirm that the validity bond is now halved
    feeWindow = contractsFixture.applySignature('FeeWindow', universe.getOrCreateCurrentFeeWindow())
    contractsFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)
    finalValidityBond = universe.getOrCacheValidityBond()
    assert finalValidityBond == newValidityBond / 2
Пример #33
0
def test_fee_window_record_keeping(localFixture, universe, cash, market,
                                   categoricalMarket, scalarMarket):
    feeWindow = localFixture.applySignature(
        'FeeWindow', universe.getOrCreateCurrentFeeWindow())

    # First we'll confirm we get the expected default values for the window record keeping
    assert feeWindow.getNumMarkets() == 0
    assert feeWindow.getNumInvalidMarkets() == 0
    assert feeWindow.getNumIncorrectDesignatedReportMarkets() == 0
    assert feeWindow.getNumDesignatedReportNoShows() == 0

    # Go to designated reporting
    proceedToDesignatedReporting(localFixture, market)

    # Do a report that we'll make incorrect
    assert market.doInitialReport([0, market.getNumTicks()], False)

    # Do a report for a market we'll say is invalid
    assert categoricalMarket.doInitialReport(
        [0, 0, categoricalMarket.getNumTicks()], False)

    # Designated reporter doesn't show up for the third market. Go into initial reporting and do a report by someone else
    reputationToken = localFixture.applySignature(
        'ReputationToken', universe.getReputationToken())
    reputationToken.transfer(tester.a1, 10**6 * 10**18)
    proceedToInitialReporting(localFixture, scalarMarket)
    assert scalarMarket.doInitialReport([0, scalarMarket.getNumTicks()],
                                        False,
                                        sender=tester.k1)

    # proceed to the window start time
    feeWindow = localFixture.applySignature('FeeWindow', market.getFeeWindow())
    localFixture.contracts["Time"].setTimestamp(feeWindow.getStartTime() + 1)

    # dispute the first market
    chosenPayoutNumerators = [market.getNumTicks(), 0]
    chosenPayoutHash = market.derivePayoutDistributionHash(
        chosenPayoutNumerators, False)
    amount = 2 * market.getTotalStake() - 3 * market.getStakeInOutcome(
        chosenPayoutHash)
    assert market.contribute(chosenPayoutNumerators, False, amount)
    newFeeWindowAddress = market.getFeeWindow()
    assert newFeeWindowAddress != feeWindow

    # dispute the second market with an invalid outcome
    chosenPayoutNumerators = [
        categoricalMarket.getNumTicks() / 3,
        categoricalMarket.getNumTicks() / 3,
        categoricalMarket.getNumTicks() / 3
    ]
    chosenPayoutHash = categoricalMarket.derivePayoutDistributionHash(
        chosenPayoutNumerators, True)
    amount = 2 * categoricalMarket.getTotalStake(
    ) - 3 * categoricalMarket.getStakeInOutcome(chosenPayoutHash)
    assert categoricalMarket.contribute(chosenPayoutNumerators, True, amount)
    assert categoricalMarket.getFeeWindow() != feeWindow

    # progress time forward
    feeWindow = localFixture.applySignature('FeeWindow', newFeeWindowAddress)
    localFixture.contracts["Time"].setTimestamp(feeWindow.getEndTime() + 1)

    # finalize the markets
    assert market.finalize()
    assert categoricalMarket.finalize()
    assert scalarMarket.finalize()

    # Now we'll confirm the record keeping was updated
    assert feeWindow.getNumMarkets() == 2
    assert feeWindow.getNumInvalidMarkets() == 1
    assert feeWindow.getNumIncorrectDesignatedReportMarkets() == 2

    feeWindow = localFixture.applySignature('FeeWindow',
                                            scalarMarket.getFeeWindow())
    assert feeWindow.getNumMarkets() == 1
    assert feeWindow.getNumDesignatedReportNoShows() == 1
Пример #34
0
def test_fee_window_record_keeping(localFixture, universe, market, categoricalMarket, scalarMarket):
    disputeWindow = localFixture.applySignature('DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))

    noShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    initialReportBond = universe.getOrCacheDesignatedReportStake()
    validityBond = universe.getOrCacheValidityBond()

    # First we'll confirm we get the expected default values for the window record keeping
    assert disputeWindow.invalidMarketsTotal() == 0
    assert disputeWindow.validityBondTotal() == 0
    assert disputeWindow.incorrectDesignatedReportTotal() == 0
    assert disputeWindow.initialReportBondTotal() == 0
    assert disputeWindow.designatedReportNoShowsTotal() == 0
    assert disputeWindow.designatedReporterNoShowBondTotal() == 0

    # Go to designated reporting
    proceedToDesignatedReporting(localFixture, market)

    # Do a report that we'll make incorrect
    assert market.doInitialReport([0, 0, market.getNumTicks()], "", 0)

    # Do a report for a market we'll say is invalid
    assert categoricalMarket.doInitialReport([0, 0, 0, categoricalMarket.getNumTicks()], "", 0)

    # Designated reporter doesn't show up for the third market. Go into initial reporting and do a report by someone else
    reputationToken = localFixture.applySignature('ReputationToken', universe.getReputationToken())
    reputationToken.transfer(localFixture.accounts[1], 10**6 * 10**18)
    proceedToInitialReporting(localFixture, scalarMarket)
    assert scalarMarket.doInitialReport([0, 0, scalarMarket.getNumTicks()], "", 0, sender=localFixture.accounts[1])

    # proceed to the window start time
    disputeWindow = localFixture.applySignature('DisputeWindow', market.getDisputeWindow())
    localFixture.contracts["Time"].setTimestamp(disputeWindow.getStartTime() + 1)

    # dispute the first market
    chosenPayoutNumerators = [0, market.getNumTicks(), 0]
    chosenPayoutHash = market.derivePayoutDistributionHash(chosenPayoutNumerators)
    amount = 2 * market.getParticipantStake() - 3 * market.getStakeInOutcome(chosenPayoutHash)
    assert market.contribute(chosenPayoutNumerators, amount, "")
    newDisputeWindowAddress = market.getDisputeWindow()
    assert newDisputeWindowAddress != disputeWindow

    # dispute the second market with an invalid outcome
    chosenPayoutNumerators = [categoricalMarket.getNumTicks(), 0, 0, 0]
    chosenPayoutHash = categoricalMarket.derivePayoutDistributionHash(chosenPayoutNumerators)
    amount = 2 * categoricalMarket.getParticipantStake() - 3 * categoricalMarket.getStakeInOutcome(chosenPayoutHash)
    assert categoricalMarket.contribute(chosenPayoutNumerators, amount, "")
    assert categoricalMarket.getDisputeWindow() != disputeWindow

    # progress time forward
    disputeWindow = localFixture.applySignature('DisputeWindow', newDisputeWindowAddress)
    localFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1)

    # finalize the markets
    assert market.finalize()
    assert categoricalMarket.finalize()
    assert scalarMarket.finalize()

    # Now we'll confirm the record keeping was updated
    # Dispute Window cadence is different in the subFork Univese tests so we account for that
    assert disputeWindow.invalidMarketsTotal() == validityBond
    assert disputeWindow.validityBondTotal() == 3 * validityBond

    assert disputeWindow.incorrectDesignatedReportTotal() == 2 * initialReportBond
    assert disputeWindow.initialReportBondTotal() == 3 * initialReportBond

    disputeWindow = localFixture.applySignature('DisputeWindow', scalarMarket.getDisputeWindow())
    assert disputeWindow.designatedReportNoShowsTotal() == noShowBond
    assert disputeWindow.designatedReporterNoShowBondTotal() == 3 * noShowBond
def test_bond_weight(contractsFixture, universe, cash):
    initialNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    currentTime = contractsFixture.contracts["Time"].getTimestamp()
    day = 24 * 60 * 60
    finalTime = currentTime + 60 * day

    # create first. ends at final time
    market1 = contractsFixture.createYesNoMarket(universe, finalTime, 10**16,
                                                 4,
                                                 contractsFixture.accounts[0])

    # create second and end as no show
    market2EndTime = contractsFixture.contracts["Time"].getTimestamp() + 1
    market2 = contractsFixture.createYesNoMarket(universe, market2EndTime,
                                                 10**16, 4,
                                                 contractsFixture.accounts[0])
    proceedToInitialReporting(contractsFixture, market2)

    # The DR will be absent and we'll do an initial report as another user
    numTicks = market2.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market2.doInitialReport(payoutNumerators,
                                   "",
                                   0,
                                   sender=contractsFixture.accounts[1])

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market2.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market2.finalize()
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == initialNoShowBond * 2

    # create third. ends at final time
    market3 = contractsFixture.createYesNoMarket(universe, finalTime, 10**16,
                                                 4,
                                                 contractsFixture.accounts[0])

    # create fourth and end as no show
    market4EndTime = contractsFixture.contracts["Time"].getTimestamp() + 1
    market4 = contractsFixture.createYesNoMarket(universe, market4EndTime,
                                                 10**16, 4,
                                                 contractsFixture.accounts[0])
    proceedToInitialReporting(contractsFixture, market4)

    # The DR will be absent and we'll do an initial report as another user
    numTicks = market4.getNumTicks()
    payoutNumerators = [0, numTicks, 0]
    assert market4.doInitialReport(payoutNumerators,
                                   "",
                                   0,
                                   sender=contractsFixture.accounts[1])

    # Move time forward to finalize the market
    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market4.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market4.finalize()
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == initialNoShowBond * 4

    # create fifth.
    market5 = contractsFixture.createYesNoMarket(universe, finalTime, 10**16,
                                                 4,
                                                 contractsFixture.accounts[0])

    # move to final time and finalize market 1, 3, and 5 with 1 as no show, 3 as no show, and 5 as show
    contractsFixture.contracts["Time"].setTimestamp(finalTime + 2 * day)
    assert market1.doInitialReport(payoutNumerators,
                                   "",
                                   0,
                                   sender=contractsFixture.accounts[1])
    assert market3.doInitialReport(payoutNumerators,
                                   "",
                                   0,
                                   sender=contractsFixture.accounts[1])
    assert market5.doInitialReport(payoutNumerators, "", 0)

    disputeWindow = contractsFixture.applySignature('DisputeWindow',
                                                    market5.getDisputeWindow())
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)
    assert market1.finalize()
    assert market3.finalize()
    assert market5.finalize()

    # bond should move with 1/3 bad as input to floating formula
    disputeWindow = contractsFixture.applySignature(
        'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False))
    contractsFixture.contracts["Time"].setTimestamp(
        disputeWindow.getEndTime() + 1)

    previousDisputeWindow = contractsFixture.applySignature(
        'DisputeWindow',
        universe.getOrCreatePreviousPreviousDisputeWindow(False))
    totalNoShowBondsInPreviousWindow = previousDisputeWindow.designatedReporterNoShowBondTotal(
    )
    designatedReportNoShowBondsInPreviousWindow = previousDisputeWindow.designatedReportNoShowsTotal(
    )

    formulas = contractsFixture.contracts["Formulas"]

    oldNoShowBond = newNoShowBond
    newNoShowBond = universe.getOrCacheDesignatedReportNoShowBond()
    assert newNoShowBond == formulas.calculateFloatingValue(
        1, 3, 20, oldNoShowBond, 0)