def test_invalid_designated_report(localFixture, universe, cash, market): reportingWindow = localFixture.applySignature('ReportingWindow', market.getReportingWindow()) expectedReportingWindowFeePayout = universe.getOrCacheValidityBond() expectedMarketCreatorFeePayout = universe.getOrCacheTargetReporterGasCosts() # Proceed to the DESIGNATED REPORTING phase proceedToDesignatedReporting(localFixture, universe, market, [long(0.5 * market.getNumTicks()), long(0.5 * market.getNumTicks())]) # To progress into the DESIGNATED DISPUTE phase we do a designated report of invalid initialMarketCreatorETHBalance = localFixture.chain.head_state.get_balance(market.getMarketCreatorMailbox()) assert localFixture.designatedReport(market, [long(0.5 * market.getNumTicks()), long(0.5 * market.getNumTicks())], tester.k0, True) # We're now in the DESIGNATED DISPUTE PHASE assert market.getReportingState() == localFixture.contracts['Constants'].DESIGNATED_DISPUTE() # If time passes and no dispute bond is placed the market can be finalized localFixture.chain.head_state.timestamp = market.getEndTime() + localFixture.contracts['Constants'].DESIGNATED_REPORTING_DURATION_SECONDS() + localFixture.contracts['Constants'].DESIGNATED_REPORTING_DISPUTE_DURATION_SECONDS() + 1 # The market is awaiting finalization now assert market.getReportingState() == localFixture.contracts['Constants'].AWAITING_FINALIZATION() # If we finalize the market it will be recorded as an invalid result initialReportingWindowCashBalance = cash.balanceOf(reportingWindow.address) assert market.tryFinalize() assert not market.isValid() assert reportingWindow.getNumInvalidMarkets() == 1 # Since the market resolved with an invalid outcome the validity bond is paid out to the reporting window increaseInReportingWindowBalance = cash.balanceOf(reportingWindow.address) - initialReportingWindowCashBalance assert increaseInReportingWindowBalance == expectedReportingWindowFeePayout # Since the designated reporter showed up the market creator still gets back the reporter gas cost fee increaseInMarketCreatorBalance = localFixture.chain.head_state.get_balance(market.getMarketCreatorMailbox()) - initialMarketCreatorETHBalance assert increaseInMarketCreatorBalance == expectedMarketCreatorFeePayout
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)
def test_redeemParticipation(localFixture, universe, cash, market, categoricalMarket, scalarMarket): proceedToDesignatedReporting(localFixture, universe, market, [0, 10**18]) assert localFixture.designatedReport(market, [0, 10**18], tester.k0) assert localFixture.designatedReport( categoricalMarket, [0, 0, categoricalMarket.getNumTicks()], tester.k0) assert localFixture.designatedReport(scalarMarket, [0, scalarMarket.getNumTicks()], tester.k0) reportingWindow = localFixture.applySignature('ReportingWindow', market.getReportingWindow()) localFixture.chain.head_state.timestamp = reportingWindow.getEndTime() + 1 assert market.tryFinalize() assert categoricalMarket.tryFinalize() assert scalarMarket.tryFinalize() # We cannot purchase participation tokens yet since the window isn't active participationToken = localFixture.applySignature( "ParticipationToken", reportingWindow.getParticipationToken()) # We'll progress to the start of the window and purchase some participation tokens localFixture.chain.head_state.timestamp = reportingWindow.getStartTime( ) + 1 assert participationToken.buy(1) # Fast forward time until the window is over and we can redeem our winning stake and participation tokens and receive fees localFixture.chain.head_state.timestamp = reportingWindow.getEndTime() + 1 with PrintGasUsed(localFixture, "DisputeBond:withdraw", PARTICIPATION_TOKEN_REDEMPTION): assert participationToken.redeem(False)
def test_redeemDispute(localFixture, universe, cash, market, categoricalMarket, scalarMarket): proceedToDesignatedReporting(localFixture, universe, market, [0, 10**18]) assert localFixture.designatedReport(market, [0, 10**18], tester.k0) assert localFixture.designatedReport( categoricalMarket, [0, 0, categoricalMarket.getNumTicks()], tester.k0) assert localFixture.designatedReport(scalarMarket, [0, scalarMarket.getNumTicks()], tester.k0) assert market.disputeDesignatedReport([10**18, 0], 1, False) reportingWindow = localFixture.applySignature('ReportingWindow', market.getReportingWindow()) localFixture.chain.head_state.timestamp = reportingWindow.getEndTime() + 1 assert market.tryFinalize() assert categoricalMarket.tryFinalize() assert scalarMarket.tryFinalize() disputeBond = localFixture.applySignature( "DisputeBond", market.getDesignatedReporterDisputeBond()) with PrintGasUsed(localFixture, "DisputeBond:withdraw", DISPUTE_BOND_REDEMPTION): assert disputeBond.withdraw()
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)
def test_variable_validity_bond(invalid, contractsFixture, universe, cash): # We can't make a market with less than the minimum required validity bond minimumValidityBond = universe.getOrCacheMarketCreationCost() with raises(TransactionFailed): contractsFixture.createReasonableYesNoMarket( universe, validityBond=minimumValidityBond - 1) # No longer testing a higher validity bond, token transfers are token precisely, no ability to send more than required market = contractsFixture.createReasonableYesNoMarket( universe, validityBond=minimumValidityBond) assert market.getValidityBondAttoEth() == minimumValidityBond # If we resolve the market the bond in it's entirety will go to the fee pool or to the market creator if the resolution was not invalid proceedToDesignatedReporting(contractsFixture, market) if invalid: market.doInitialReport([market.getNumTicks(), 0, 0], "") else: market.doInitialReport([0, 0, market.getNumTicks()], "") # Move time forward so we can finalize and see the bond move disputeWindow = contractsFixture.applySignature('DisputeWindow', market.getDisputeWindow()) assert contractsFixture.contracts["Time"].setTimestamp( disputeWindow.getEndTime() + 1) if invalid: with TokenDelta(cash, minimumValidityBond, universe.getAuction(), "Validity bond did not go to the auction"): market.finalize() else: with TokenDelta(cash, minimumValidityBond, market.getOwner(), "Validity bond did not go to the market creator"): market.finalize()
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_designatedReportHappyPath(localFixture, universe, market): # proceed to the designated reporting period proceedToDesignatedReporting(localFixture, market) # an address that is not the designated reporter cannot report with raises(TransactionFailed): market.doInitialReport([0, 0, market.getNumTicks()], "", 0, sender=localFixture.accounts[1]) # Reporting with an invalid number of outcomes should fail with raises(TransactionFailed): market.doInitialReport([0, 0, 0, 0, market.getNumTicks()], "", 0) # We cannot directly call clearCrowdsourcers setting back reporting with raises(AttributeError): market.clearCrowdsourcers() # do an initial report as the designated reporter disputeWindow = localFixture.applySignature("DisputeWindow", universe.getOrCreateNextDisputeWindow(True)) initialReportLog = { "universe": universe.address, "reporter": localFixture.accounts[0], "market": market.address, "amountStaked": market.repBond(), "isDesignatedReporter": True, "payoutNumerators": [0, 0, market.getNumTicks()], "description": "Obviously I'm right", "nextWindowStartTime": disputeWindow.getStartTime(), "nextWindowEndTime": disputeWindow.getEndTime() } with AssertLog(localFixture, "InitialReportSubmitted", initialReportLog): assert market.doInitialReport([0, 0, market.getNumTicks()], "Obviously I'm right", 0) with raises(TransactionFailed): assert market.doInitialReport([0, 0, market.getNumTicks()], "Obviously I'm right", 0) # the market is now assigned a dispute window newDisputeWindowAddress = market.getDisputeWindow() assert newDisputeWindowAddress disputeWindow = localFixture.applySignature('DisputeWindow', newDisputeWindowAddress) assert disputeWindow.getEndTime() < market.getEndTime() + (24 * 60 * 60 * 2) # Confirm the dispute window time is within 2 days of the market end (1 day DR window + 1 day initial dispute window) # time marches on and the market can be finalized timestamp = disputeWindow.getEndTime() + 1 localFixture.contracts["Time"].setTimestamp(timestamp) marketFinalizedLog = { "universe": universe.address, "market": market.address, "timestamp": timestamp, "winningPayoutNumerators": [0, 0, market.getNumTicks()] } with AssertLog(localFixture, "MarketFinalized", marketFinalizedLog): assert market.finalize() with raises(TransactionFailed): market.finalize()
def test_designatedReportHappyPath(localFixture, universe, market): # proceed to the designated reporting period proceedToDesignatedReporting(localFixture, market) # an address that is not the designated reporter cannot report with raises(TransactionFailed): market.doInitialReport([0, 0, market.getNumTicks()], "", sender=tester.k1) # Reporting with an invalid number of outcomes should fail with raises(TransactionFailed): market.doInitialReport([0, 0, 0, 0, market.getNumTicks()], "") # do an initial report as the designated reporter initialReportLog = { "universe": universe.address, "reporter": bytesToHexString(tester.a0), "market": market.address, "amountStaked": universe.getInitialReportMinValue(), "isDesignatedReporter": True, "payoutNumerators": [0, 0, market.getNumTicks()], "description": "Obviously I'm right", } with AssertLog(localFixture, "InitialReportSubmitted", initialReportLog): assert market.doInitialReport([0, 0, market.getNumTicks()], "Obviously I'm right") with raises(TransactionFailed, message="Cannot initial report twice"): assert market.doInitialReport([0, 0, market.getNumTicks()], "Obviously I'm right") # the market is now assigned a dispute window newDisputeWindowAddress = market.getDisputeWindow() assert newDisputeWindowAddress disputeWindow = localFixture.applySignature('DisputeWindow', newDisputeWindowAddress) assert disputeWindow.getEndTime() < market.getEndTime() + ( 24 * 60 * 60 * 2 ) # Confirm the dispute window time is within 2 days of the market end (1 day DR window + 1 day initial dispute window) # time marches on and the market can be finalized timestamp = disputeWindow.getEndTime() + 1 localFixture.contracts["Time"].setTimestamp(timestamp) marketFinalizedLog = { "universe": universe.address, "market": market.address, "timestamp": timestamp, "winningPayoutNumerators": [0, 0, market.getNumTicks()] } with AssertLog(localFixture, "MarketFinalized", marketFinalizedLog): assert market.finalize() with raises(TransactionFailed, message="Cannot finalize twice"): market.finalize()
def test_disputeDesignated(localFixture, universe, cash, market): proceedToDesignatedReporting(localFixture, universe, market, [0, 10**18]) assert localFixture.designatedReport(market, [0, 10**18], tester.k0) with PrintGasUsed(localFixture, "Market:disputeDesignatedReport", DESIGNATED_DISPUTE): assert market.disputeDesignatedReport([1, market.getNumTicks() - 1], 1, False, sender=tester.k1)
def test_marketFinalization(localFixture, universe, market): proceedToDesignatedReporting(localFixture, universe, market, [0, 10**18]) assert localFixture.designatedReport(market, [0, 10**18], tester.k0) reportingWindow = localFixture.applySignature('ReportingWindow', market.getReportingWindow()) localFixture.chain.head_state.timestamp = reportingWindow.getEndTime() + 1 with PrintGasUsed(localFixture, "Market:tryFinalize", MARKET_FINALIZATION): assert market.tryFinalize()
def test_non_dr_initial_reporter(contractsFixture, universe, reputationToken): account0 = contractsFixture.accounts[0] account1 = contractsFixture.accounts[1] market = contractsFixture.createReasonableYesNoMarket(universe, extraInfo="so extra", designatedReporterAddress=account1) proceedToDesignatedReporting(contractsFixture, market) stake = market.repBond() reputationToken.transfer(account1, stake) with TokenDelta(reputationToken, stake, account0, "Market creator didn't get bond back"): with TokenDelta(reputationToken, -stake, account1, "Designated Reporter did not pay bond"): market.doInitialReport([0, 0, market.getNumTicks()], "", 0, sender=account1)
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
def test_one_market_one_correct_report(localFixture, universe, market): reportingWindow = localFixture.applySignature('ReportingWindow', market.getReportingWindow()) reputationToken = localFixture.applySignature( 'ReputationToken', reportingWindow.getReputationToken()) # Proceed to the DESIGNATED REPORTING phase proceedToDesignatedReporting(localFixture, universe, market, [0, market.getNumTicks()]) # To progress into the DESIGNATED DISPUTE phase we do a designated report initialRepBalance = reputationToken.balanceOf(tester.a0) assert localFixture.designatedReport(market, [0, market.getNumTicks()], tester.k0) # The market owner gets back the no-show REP bond, which cancels out the amount used to pay for the required dispute tokens assert reputationToken.balanceOf( tester.a0 ) == initialRepBalance + universe.getOrCacheDesignatedReportNoShowBond( ) - universe.getOrCacheDesignatedReportStake() initialREPBalance = reputationToken.balanceOf(tester.a0) # We're now in the DESIGNATED DISPUTE PHASE assert market.getReportingState( ) == localFixture.contracts['Constants'].DESIGNATED_DISPUTE() expectedStakeTokenBalance = universe.getOrCacheDesignatedReportStake() # Time passes until the end of the reporting window localFixture.chain.head_state.timestamp = reportingWindow.getEndTime() + 1 # Finalize the market market.tryFinalize() # The designated reporter may redeem their stake tokens which were purchased to make the designated report stakeToken = localFixture.getOrCreateStakeToken( market, [0, market.getNumTicks()]) assert stakeToken.balanceOf(tester.a0) == expectedStakeTokenBalance expectedREPBalance = initialREPBalance # We can see that the designated reporter's balance of REP has returned to the original value since as the market creator the had to pay these REP fees initially assert reputationToken.balanceOf(tester.a0) == expectedREPBalance # We'll redeem the winning tokens we have on the market and confirm we get that amount returned in REP assert stakeToken.redeemWinningTokens() assert reputationToken.balanceOf( tester.a0) == expectedREPBalance + expectedStakeTokenBalance
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)
def test_designatedReportHappyPath(localFixture, universe, market): # proceed to the designated reporting period proceedToDesignatedReporting(localFixture, market) # an address that is not the designated reporter cannot report with raises(TransactionFailed): market.doInitialReport([0, market.getNumTicks()], False, sender=tester.k1) # Reporting with an invalid number of outcomes should fail with raises(TransactionFailed): market.doInitialReport([0, 0, market.getNumTicks()], False) # do an initial report as the designated reporter initialReportLog = { "universe": universe.address, "reporter": bytesToHexString(tester.a0), "market": market.address, "amountStaked": universe.getInitialReportMinValue(), "isDesignatedReporter": True, "payoutNumerators": [0, market.getNumTicks()], "invalid": False } with AssertLog(localFixture, "InitialReportSubmitted", initialReportLog): assert market.doInitialReport([0, market.getNumTicks()], False) with raises(TransactionFailed, message="Cannot initial report twice"): assert market.doInitialReport([0, market.getNumTicks()], False) # 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) marketFinalizedLog = { "universe": universe.address, "market": market.address } with AssertLog(localFixture, "MarketFinalized", marketFinalizedLog): assert market.finalize() with raises(TransactionFailed, message="Cannot finalize twice"): market.finalize()
def test_designatedReportHappyPath(localFixture, universe, market): # proceed to the designated reporting period proceedToDesignatedReporting(localFixture, market) # an address that is not the designated reporter cannot report with raises(TransactionFailed): market.doInitialReport([0, market.getNumTicks()], False, sender=tester.k1) # Reporting with an invalid number of outcomes should fail with raises(TransactionFailed): market.doInitialReport([0, 0, market.getNumTicks()], False) # do an initial report as the designated reporter initialReportLog = { "universe": universe.address, "reporter": bytesToHexString(tester.a0), "market": market.address, "amountStaked": universe.getInitialReportMinValue(), "isDesignatedReporter": True, "payoutNumerators": [0, market.getNumTicks()], "invalid": False } with AssertLog(localFixture, "InitialReportSubmitted", initialReportLog): assert market.doInitialReport([0, market.getNumTicks()], False) with raises(TransactionFailed, message="Cannot initial report twice"): assert market.doInitialReport([0, market.getNumTicks()], False) # 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) marketFinalizedLog = { "universe": universe.address, "market": market.address } with AssertLog(localFixture, "MarketFinalized", marketFinalizedLog): assert market.finalize() with raises(TransactionFailed, message="Cannot finalize twice"): market.finalize()
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()
def test_variable_validity_bond(invalid, contractsFixture, universe, cash): # We can't make a market with less than the minimum required validity bond minimumValidityBond = universe.getOrCacheMarketCreationCost() with raises(TransactionFailed): contractsFixture.createReasonableYesNoMarket( universe, cash, validityBond=minimumValidityBond - 1) # But we can make one with a greater bond higherValidityBond = minimumValidityBond + 1 market = contractsFixture.createReasonableYesNoMarket( universe, cash, validityBond=higherValidityBond) assert market.getValidityBondAttoEth() == higherValidityBond # If we resolve the market the bond in it's entirety will go to the fee pool or to the market creator if the resolution was not invalid proceedToDesignatedReporting(contractsFixture, market) if invalid: market.doInitialReport( [market.getNumTicks() / 2, market.getNumTicks() / 2], True, "") else: market.doInitialReport([0, market.getNumTicks()], False, "") # Move time forward so we can finalize and see the bond move feeWindow = contractsFixture.applySignature('FeeWindow', market.getFeeWindow()) assert contractsFixture.contracts["Time"].setTimestamp( feeWindow.getEndTime() + 1) if invalid: with TokenDelta(cash, higherValidityBond, universe.getAuction(), "Validity bond did not go to the auction"): market.finalize() else: with EtherDelta(higherValidityBond, market.getMarketCreatorMailbox(), contractsFixture.chain, "Validity bond did not go to the market creator"): market.finalize()
def test_redeemStake(localFixture, universe, cash, market, categoricalMarket, scalarMarket): proceedToDesignatedReporting(localFixture, universe, market, [0, 10**18]) assert localFixture.designatedReport(market, [0, 10**18], tester.k0) assert localFixture.designatedReport( categoricalMarket, [0, 0, categoricalMarket.getNumTicks()], tester.k0) assert localFixture.designatedReport(scalarMarket, [0, scalarMarket.getNumTicks()], tester.k0) reportingWindow = localFixture.applySignature('ReportingWindow', market.getReportingWindow()) localFixture.chain.head_state.timestamp = reportingWindow.getEndTime() + 1 assert market.tryFinalize() assert categoricalMarket.tryFinalize() assert scalarMarket.tryFinalize() stakeToken = localFixture.getStakeToken(market, [0, 10**18]) with PrintGasUsed(localFixture, "StakeToken:redeemWinningTokens", STAKE_REDEMPTION): stakeToken.redeemWinningTokens(False)
def test_designatedReportingHappyPath(localFixture, universe, market): # Proceed to the DESIGNATED REPORTING phase proceedToDesignatedReporting(localFixture, universe, market, [0,market.getNumTicks()]) reportingWindow = localFixture.applySignature("ReportingWindow", market.getReportingWindow()) originalNumDesignatedReportNoShows = reportingWindow.getNumDesignatedReportNoShows() # To progress into the DESIGNATED DISPUTE phase we do a designated report logs = [] captureFilteredLogs(localFixture.chain.head_state, localFixture.contracts['Augur'], logs) assert localFixture.designatedReport(market, [0,market.getNumTicks()], tester.k0) # Confirm the designated report logging works assert len(logs) == 4 assert logs[3]['_event_type'] == 'DesignatedReportSubmitted' assert logs[3]['amountStaked'] == localFixture.contracts["Constants"].DEFAULT_DESIGNATED_REPORT_STAKE() assert logs[3]['reporter'] == bytesToHexString(tester.a0) assert logs[3]['stakeToken'] == localFixture.getOrCreateStakeToken(market, [0,market.getNumTicks()]).address assert logs[3]['market'] == market.address assert logs[3]['payoutNumerators'] == [0,market.getNumTicks()] # making a designated report also decremented the no show accounting on the reporting window assert reportingWindow.getNumDesignatedReportNoShows() == originalNumDesignatedReportNoShows - 1 # We're now in the DESIGNATED DISPUTE PHASE assert market.getReportingState() == localFixture.contracts['Constants'].DESIGNATED_DISPUTE() # If time passes and no dispute bond is placed the market can be finalized localFixture.chain.head_state.timestamp = market.getEndTime() + localFixture.contracts['Constants'].DESIGNATED_REPORTING_DURATION_SECONDS() + localFixture.contracts['Constants'].DESIGNATED_REPORTING_DISPUTE_DURATION_SECONDS() + 1 # The market is awaiting finalization now assert market.getReportingState() == localFixture.contracts['Constants'].AWAITING_FINALIZATION() # We can finalize it assert market.tryFinalize() assert market.getReportingState() == localFixture.contracts['Constants'].FINALIZED()
def test_two_markets_two_correct_reports_one_with_no_fees( localFixture, universe, market): cash = localFixture.contracts["Cash"] market2 = localFixture.createReasonableBinaryMarket(universe, cash) reportingWindow = localFixture.applySignature('ReportingWindow', market.getReportingWindow()) reputationToken = localFixture.applySignature( 'ReputationToken', reportingWindow.getReputationToken()) # Proceed to the DESIGNATED REPORTING phase proceedToDesignatedReporting(localFixture, universe, market, [0, 10**18]) # To progress into the DESIGNATED DISPUTE phase we do a designated report initialRepBalance = reputationToken.balanceOf(tester.a0) assert localFixture.designatedReport(market, [0, 10**18], tester.k0) # The market owner gets back the no-show REP bond, which cancels out the amount used to pay for the required dispute tokens assert reputationToken.balanceOf( tester.a0 ) == initialRepBalance + universe.getDesignatedReportNoShowBond( ) - universe.getDesignatedReportStake() initialREPBalance = reputationToken.balanceOf(tester.a0) # We're now in the DESIGNATED DISPUTE PHASE assert market.getReportingState( ) == localFixture.contracts['Constants'].DESIGNATED_DISPUTE() # We'll do the same with the second market proceedToDesignatedReporting(localFixture, universe, market2, [0, 10**18]) initialRepBalance = reputationToken.balanceOf(tester.a0) assert localFixture.designatedReport(market2, [0, 10**18], tester.k0) # The market owner gets back the no-show REP bond, which cancels out the amount used to pay for the required dispute tokens assert reputationToken.balanceOf( tester.a0 ) == initialRepBalance + universe.getDesignatedReportNoShowBond( ) - universe.getDesignatedReportStake() initialREPBalance = reputationToken.balanceOf(tester.a0) assert market2.getReportingState( ) == localFixture.contracts['Constants'].DESIGNATED_DISPUTE() designatedReportStake = universe.getDesignatedReportStake() # Time passes until the end of the reporting window localFixture.chain.head_state.timestamp = reportingWindow.getEndTime() + 1 # Finalize the first market market.tryFinalize() # The market1 designated reporter may redeem their stake tokens which were purchased to make the designated report stakeToken = localFixture.getStakeToken(market, [0, 10**18]) assert stakeToken.balanceOf(tester.a0) == designatedReportStake expectedREPBalance = initialREPBalance # We can see that the designated reporter's balance of REP has returned to the original value since as the market creator the had to pay these REP fees initially assert reputationToken.balanceOf(tester.a0) == expectedREPBalance # If we try to redeem tokens and recieve trading fees now we'll get a failure since not all markets are finalized with raises(TransactionFailed): stakeToken.redeemWinningTokens() # We'll redeem the winning tokens we have on the market and forgo fees and confirm we get that amount returned in REP initialETHBalance = localFixture.chain.head_state.get_balance(tester.a0) assert stakeToken.redeemWinningTokens(True) assert reputationToken.balanceOf( tester.a0) == expectedREPBalance + designatedReportStake assert localFixture.chain.head_state.get_balance( tester.a0) == initialETHBalance # If we redeem the second tester's tokens they'll get ALL of the fees on the reporting window now and their normal share of REP market2.tryFinalize() stakeToken = localFixture.getStakeToken(market2, [0, 10**18]) assert stakeToken.balanceOf(tester.a0) == designatedReportStake initialREPBalance = reputationToken.balanceOf(tester.a0) # We'll redeem the winning tokens we have on the market and confirm we get that amount returned in REP and all the fees in the reporting window expectedETHBalance = localFixture.chain.head_state.get_balance( tester.a0) + cash.balanceOf(reportingWindow.address) assert stakeToken.redeemWinningTokens() assert reputationToken.balanceOf( tester.a0) == initialREPBalance + designatedReportStake assert localFixture.chain.head_state.get_balance( tester.a0) == expectedETHBalance
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
def test_initial_report(localFixture, universe, cash, market): proceedToDesignatedReporting(localFixture, market) with PrintGasUsed(localFixture, "Market:doInitialReport", INITIAL_REPORT): market.doInitialReport([0, market.getNumTicks()], False)
def _test_answer_set(localFixture, controller, universe, realitio_answer_final, realitio_answer_wrong, augur_bool): augarb = controller.lookup("RealitioAugurArbitrator") realitio = controller.lookup("Realitio") cash = controller.lookup("Cash") (a_rep_faucet, k_rep_faucet) = (tester.a0, tester.k0) (a_asker, k_asker) = (tester.a1, tester.k1) (a_market_owner, k_market_owner) = (tester.a2, tester.k2) (a_answerer1, k_answerer1) = (tester.a3, tester.k3) (a_answerer2, k_answerer2) = (tester.a4, tester.k4) (a_reporter, k_reporter) = (tester.a5, tester.k5) (a_arb_requester, k_arb_requester) = (tester.a8, tester.k8) # Params used in the Realitio question template_id = 0 # This is our basic yes/no question type opening_ts = 1000000123 # Any timestamp or 0, we'll use one past for simplicity nonce = 987654321 # Usually 0 timeout = 1 augurarbcon = localFixture.uploadAndAddToController( "../source/contracts/RealitioAugurArbitrator.sol", lookupKey="RealitioAugurArbitrator") augurarbcon.initialize(realitio, template_id, 12345, universe.address, cash) assert augurarbcon.getDisputeFee( "0x0") == 12345 # All question ids are the same assert augurarbcon.latest_universe() == universe.address assert augurarbcon.market_token() == cash assert augurarbcon.template_id() == template_id realitiocon = localFixture.uploadAndAddToController( "../source/contracts/Realitio.sol", lookupKey="Realitio") question_id = realitiocon.askQuestion(template_id, question_text, augurarbcon.address, timeout, opening_ts, nonce, sender=k_asker) answer_hist_hash = [] answer_hist_addr = [] answer_hist_bond = [] answer_hist_answ = [] answer_hist_hash.append(realitiocon.questions(question_id)[8]) realitiocon.submitAnswer(question_id, realitio_answer_final, 0, sender=k_answerer1, value=321) answer_hist_addr.append(a_answerer1) answer_hist_bond.append(321) answer_hist_answ.append(realitio_answer_final) answer_hist_hash.append(realitiocon.questions(question_id)[8]) realitiocon.submitAnswer(question_id, realitio_answer_wrong, 0, sender=k_answerer2, value=642) answer_hist_addr.append(a_answerer2) answer_hist_bond.append(642) answer_hist_answ.append(realitio_answer_wrong) answer_hist_hash.append(realitiocon.questions(question_id)[8]) realitiocon.submitAnswer(question_id, realitio_answer_final, 0, sender=k_answerer1, value=1400) answer_hist_addr.append(a_answerer1) answer_hist_bond.append(1400) answer_hist_answ.append(realitio_answer_final) # Validity bond in ETH valbond = universe.getOrCacheValidityBond() assert valbond > 1 # No show bond in REP noshowbond = universe.getOrCacheDesignatedReportNoShowBond() assert noshowbond > 0 repaddr = universe.getReputationToken() rep = localFixture.applySignature('ReputationToken', repaddr) assert rep.balanceOf(a_rep_faucet) > 0 # Revert if the max_previous is too low with raises(TransactionFailed): augurarbcon.requestArbitration(question_id, 320, value=12345, sender=k_arb_requester) # Revert if you haven't yet requested arbitration with raises(TransactionFailed): augurarbcon.createMarket(question_text, timeout, opening_ts, a_asker, nonce, a_reporter, value=valbond) augurarbcon.requestArbitration(question_id, 0, value=12345, sender=k_arb_requester) # Fail if the contract doesn't yet own sufficient REP with raises(TransactionFailed): augurarbcon.createMarket(question_text, timeout, opening_ts, a_asker, nonce, a_reporter, value=valbond) # Make sure the arbitrator contract has some REP for the validity bond # TODO: Work out how to prevent someone else from spending the REP before you can use it # Either use an intermediate contract owned per-user or do something clever with transferFrom rep.transfer(augurarbcon.address, noshowbond, sender=k_rep_faucet) assert rep.balanceOf(augurarbcon.address) == noshowbond # This will do some checks then call: # IMarket market = universe.createYesNoMarket.value(msg.value)( now+1, 0, market_token, a_reporter, 0x0, question, ""); marketCreatedLog = { "description": question_short, "marketCreationFee": universe.getOrCacheMarketCreationCost(), #"marketCreator": bytesToHexString(augurarbcon.address), } with AssertLog(localFixture, "MarketCreated", marketCreatedLog): augurarbcon.createMarket(question_text, timeout, opening_ts, a_asker, nonce, a_reporter, value=valbond) # You can only do this once per question rep.transfer(augurarbcon.address, noshowbond, sender=k_rep_faucet) with raises(TransactionFailed): augurarbcon.createMarket(question_text, timeout, opening_ts, a_asker, nonce, a_reporter, value=valbond) market_addr = augurarbcon.realitio_questions(question_id)[2] owner_addr = augurarbcon.realitio_questions(question_id)[3] # The following is mostly copied from test_reporting.py # We only cover the happy case, assuming the Augur tests will cover other cases # TODO: Test various different potential final answers, including invalid market = localFixture.applySignature('Market', market_addr) proceedToDesignatedReporting(localFixture, market) reporter_stake = universe.getOrCacheDesignatedReportStake() rep.transfer(a_reporter, reporter_stake, sender=k_rep_faucet) augur_answer_in_realitio = None if augur_bool is None: market.doInitialReport( [market.getNumTicks() / 2, market.getNumTicks() / 2], True, sender=k_reporter) augur_answer_realitio_hex = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" elif augur_bool: market.doInitialReport([0, market.getNumTicks()], False, sender=k_reporter) augur_answer_realitio_hex = "0x0000000000000000000000000000000000000000000000000000000000000001" else: market.doInitialReport([market.getNumTicks(), 0], False, sender=k_reporter) augur_answer_realitio_hex = "0x0000000000000000000000000000000000000000000000000000000000000000" # 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) market.finalize() hash_before_arb_report = realitiocon.questions(question_id)[8] with raises(TransactionFailed, message="answerer mismatch should fail"): augurarbcon.reportAnswer(question_id, answer_hist_hash[-1], realitio_answer_final, 1400, tester.a9, False) assert not realitiocon.isFinalized(question_id) augurarbcon.reportAnswer(question_id, answer_hist_hash[-1], realitio_answer_final, 1400, a_answerer1, False) assert realitiocon.isFinalized(question_id) assert hash_before_arb_report != realitiocon.questions(question_id)[8] with raises(TransactionFailed, message="You can only report an answer once"): augurarbcon.reportAnswer(question_id, answer_hist_hash[-1], realitio_answer_final, 1400, a_answerer1, False) ans = realitiocon.getFinalAnswer(question_id) assert bytes32ToHexString(ans) == augur_answer_realitio_hex claimer = None if (bytes32ToHexString(realitio_answer_final) == augur_answer_realitio_hex ): claimer = a_answerer1 else: claimer = a_arb_requester answer_hist_hash.append(hash_before_arb_report) answer_hist_addr.append(claimer) answer_hist_bond.append(0) answer_hist_answ.append(ans) claimer_start_bal = realitiocon.balanceOf(claimer) realitiocon.claimWinnings(question_id, answer_hist_hash[::-1], answer_hist_addr[::-1], answer_hist_bond[::-1], answer_hist_answ[::-1]) claimer_end_bal = realitiocon.balanceOf(claimer) assert (claimer_end_bal - claimer_start_bal) > 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_designatedReport(localFixture, universe, cash, market): proceedToDesignatedReporting(localFixture, universe, market, [0, 10**18]) with PrintGasUsed(localFixture, "Market:designatedReport", DESIGNATED_REPORT): assert localFixture.designatedReport(market, [0, 10**18], tester.k0)
def test_initial_report(localFixture, universe, cash, market): proceedToDesignatedReporting(localFixture, market) with PrintGasUsed(localFixture, "Market:doInitialReport", INITIAL_REPORT): market.doInitialReport([0, market.getNumTicks()], False)