Esempio n. 1
0
def localSnapshot(fixture, controllerSnapshot):
    fixture.resetToSnapshot(controllerSnapshot)
    fixture.upload('solidity_test_helpers/ControllerUser.sol')
    fixture.uploadAugur()
    decentralizedController = fixture.upload('../source/contracts/Controller.sol', 'decentralizedController')
    decentralizedController.switchModeSoOnlyEmergencyStopsAndEscapeHatchesCanBeUsed(sender = tester.k0)
    return fixture.createSnapshot()
Esempio n. 2
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockReputationTokenFactory = fixture.contracts[
        'MockReputationTokenFactory']
    mockFeeWindowFactory = fixture.contracts['MockFeeWindowFactory']
    mockMarketFactory = fixture.contracts['MockMarketFactory']
    mockUniverseFactory = fixture.contracts['MockUniverseFactory']
    controller.registerContract(stringToBytes('MarketFactory'),
                                mockMarketFactory.address, twentyZeros,
                                thirtyTwoZeros)
    controller.registerContract(stringToBytes('ReputationTokenFactory'),
                                mockReputationTokenFactory.address,
                                twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('FeeWindowFactory'),
                                mockFeeWindowFactory.address, twentyZeros,
                                thirtyTwoZeros)
    controller.registerContract(stringToBytes('UniverseFactory'),
                                mockUniverseFactory.address, twentyZeros,
                                thirtyTwoZeros)

    mockReputationToken = fixture.contracts['MockReputationToken']
    mockUniverse = fixture.contracts['MockUniverse']

    universe = fixture.upload('../source/contracts/reporting/Universe.sol',
                              'universe')
    fixture.contracts['populatedUniverse'] = universe
    mockReputationTokenFactory.setCreateReputationTokenValue(
        mockReputationToken.address)
    universe.setController(fixture.contracts['Controller'].address)
    assert universe.initialize(mockUniverse.address, stringToBytes("5"))

    return fixture.createSnapshot()
Esempio n. 3
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockReputationTokenFactory = fixture.contracts[
        'MockReputationTokenFactory']
    mockDisputeWindowFactory = fixture.contracts['MockDisputeWindowFactory']
    mockMarketFactory = fixture.contracts['MockMarketFactory']
    mockUniverseFactory = fixture.contracts['MockUniverseFactory']
    controller.registerContract(stringToBytes('MarketFactory'),
                                mockMarketFactory.address)
    controller.registerContract(stringToBytes('ReputationTokenFactory'),
                                mockReputationTokenFactory.address)
    controller.registerContract(stringToBytes('DisputeWindowFactory'),
                                mockDisputeWindowFactory.address)
    controller.registerContract(stringToBytes('UniverseFactory'),
                                mockUniverseFactory.address)

    mockReputationToken = fixture.contracts['MockReputationToken']
    mockUniverse = fixture.contracts['MockUniverse']
    mockReputationTokenFactory.setCreateReputationTokenValue(
        mockReputationToken.address)

    universe = fixture.upload('../source/contracts/reporting/Universe.sol',
                              'universe',
                              constructorArgs=[
                                  fixture.contracts['Controller'].address,
                                  mockUniverse.address,
                                  stringToBytes("5")
                              ])
    fixture.contracts['populatedUniverse'] = universe

    return fixture.createSnapshot()
Esempio n. 4
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockReportingParticipationTokenFactory = fixture.contracts['MockParticipationTokenFactory']
    mockDisputeBondFactory = fixture.contracts['MockDisputeBondFactory']
    mockCash = fixture.contracts['MockCash']
    mockAugur = fixture.contracts['MockAugur']
    mockShareTokenFactory = fixture.contracts['MockShareTokenFactory']    
    mockShareToken = fixture.contracts['MockShareToken']
    mockFillOrder = fixture.contracts['MockFillOrder']
    mockStakeTokenFactory = fixture.contracts['MockStakeTokenFactory']

    # pre populate share tokens for max of 8 possible outcomes
    for index in range(8):
        item = fixture.upload('solidity_test_helpers/MockShareToken.sol', 'newMockShareToken' + str(index));
        mockShareTokenFactory.pushCreateShareToken(item.address)
    
    controller.registerContract(stringToBytes('Cash'), mockCash.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('ParticipationTokenFactory'), mockReportingParticipationTokenFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('ShareTokenFactory'), mockShareTokenFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('FillOrder'), mockShareTokenFactory.address, twentyZeros, thirtyTwoZeros)    
    controller.registerContract(stringToBytes('StakeTokenFactory'), mockStakeTokenFactory.address, twentyZeros, thirtyTwoZeros)    
    controller.registerContract(stringToBytes('DisputeBondFactory'), mockDisputeBondFactory.address, twentyZeros, thirtyTwoZeros)    
    mockShareTokenFactory.resetCreateShareToken();
    return fixture.createSnapshot()
Esempio n. 5
0
def localSnapshot(fixture, controllerSnapshot):
    fixture.resetToSnapshot(controllerSnapshot)

    # Upload a token
    fixture.uploadAndAddToController(
        "solidity_test_helpers/StandardTokenHelper.sol")

    # Upload Cash
    cash = fixture.uploadAndAddToController(
        "../source/contracts/trading/Cash.sol")
    cash.setController(fixture.contracts['Controller'].address)

    # Upload the mailbox
    name = "Mailbox"
    targetName = "MailboxTarget"
    fixture.uploadAndAddToController(
        "../source/contracts/libraries/Mailbox.sol", targetName, name)
    fixture.uploadAndAddToController(
        "../source/contracts/libraries/Delegator.sol",
        name,
        "delegator",
        constructorArgs=[
            fixture.contracts['Controller'].address,
            stringToBytes(targetName)
        ])
    fixture.contracts[name] = fixture.applySignature(
        name, fixture.contracts[name].address)
    fixture.contracts[name].initialize(tester.a0)
    return fixture.createSnapshot()
Esempio n. 6
0
def localSnapshot(fixture, baseSnapshot):
    fixture.resetToSnapshot(baseSnapshot)
    controller = fixture.upload('../source/contracts/Controller.sol')
    assert fixture.contracts['Controller'].owner() == bytesToHexString(tester.a0)
    fixture.upload('solidity_test_helpers/ControllerUser.sol')
    fixture.uploadAugur()
    return fixture.createSnapshot()
Esempio n. 7
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)

    universe = kitchenSinkSnapshot['universe']
    market = kitchenSinkSnapshot['yesNoMarket']
    categoricalMarket = kitchenSinkSnapshot['categoricalMarket']
    scalarMarket = kitchenSinkSnapshot['scalarMarket']

    # Skip to Designated Reporting
    fixture.contracts["Time"].setTimestamp(market.getEndTime() + 1)

    # Distribute REP
    reputationToken = fixture.applySignature('ReputationToken',
                                             universe.getReputationToken())
    for testAccount in [
            fixture.accounts[1], fixture.accounts[2], fixture.accounts[3]
    ]:
        reputationToken.transfer(testAccount, 1 * 10**6 * 10**18)

    # Designated Report on the markets
    designatedReportCost = universe.getOrCacheDesignatedReportStake()
    with TokenDelta(
            reputationToken, 0, fixture.accounts[0],
            "Doing the designated report didn't deduct REP correctly or didn't award the no show bond"
    ):
        market.doInitialReport([0, market.getNumTicks(), 0], "", 0)
        categoricalMarket.doInitialReport(
            [0, categoricalMarket.getNumTicks(), 0, 0], "", 0)
        scalarMarket.doInitialReport([0, scalarMarket.getNumTicks(), 0], "", 0)

    return fixture.createSnapshot()
Esempio n. 8
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    augur = fixture.contracts["Augur"]
    kitchenSinkSnapshot['zeroX'] = fixture.upload('solidity_test_helpers/ZeroX/ZeroXPoC.sol', "zeroX", constructorArgs=[augur.address])
    market = ABIContract(fixture.chain, kitchenSinkSnapshot['yesNoMarket'].translator, kitchenSinkSnapshot['yesNoMarket'].address)

    return fixture.createSnapshot()
Esempio n. 9
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockCash = fixture.contracts['MockCash']
    mockAugur = fixture.contracts['MockAugur']
    mockFeeToken = fixture.contracts['MockFeeToken']
    mockFeeTokenFactory = fixture.contracts['MockFeeTokenFactory']
    mockFeeTokenFactory.setCreateFeeToken(mockFeeToken.address)
    mockReputationToken = fixture.contracts['MockReputationToken']
    controller.registerContract(stringToBytes('Cash'), mockCash.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('Augur'), mockAugur.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('FeeTokenFactory'), mockFeeTokenFactory.address, twentyZeros, thirtyTwoZeros)
    feeWindow = fixture.upload('../source/contracts/reporting/FeeWindow.sol', 'feeWindow')
    fixture.contracts["initializedFeeWindow"] = feeWindow
    feeWindow.setController(fixture.contracts["Controller"].address)

    mockUniverse = fixture.contracts['MockUniverse']
    mockUniverse.setReputationToken(mockReputationToken.address)
    mockUniverse.setDisputeRoundDurationInSeconds(5040)
    mockUniverse.setForkingMarket(5040)
    mockUniverse.setForkingMarket(longToHexString(0))
    mockUniverse.setIsForking(False)
    fixture.contracts["Time"].setTimestamp(feeWindowId)
    feeWindow.initialize(mockUniverse.address, feeWindowId)
    return fixture.createSnapshot()
Esempio n. 10
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    augur = fixture.contracts['Augur']
    # TODO registering these mock contracts fails because the real contracts are already registered
    #      but *not* registering the real contracts causes all other tests to fail
    mockReputationTokenFactory = fixture.contracts[
        'MockReputationTokenFactory']
    mockDisputeWindowFactory = fixture.contracts['MockDisputeWindowFactory']
    mockMarketFactory = fixture.contracts['MockMarketFactory']
    mockUniverseFactory = fixture.contracts['MockUniverseFactory']
    augur.registerContract(stringToBytes('MarketFactory'),
                           mockMarketFactory.address)
    augur.registerContract(stringToBytes('ReputationTokenFactory'),
                           mockReputationTokenFactory.address)
    augur.registerContract(stringToBytes('DisputeWindowFactory'),
                           mockDisputeWindowFactory.address)
    augur.registerContract(stringToBytes('UniverseFactory'),
                           mockUniverseFactory.address)

    mockReputationToken = fixture.contracts['MockReputationToken']
    mockUniverse = fixture.contracts['MockUniverse']
    mockReputationTokenFactory.set_mock_createReputationToken_0_address_address_address(
        mockReputationToken.address)

    universe = fixture.upload('../source/contracts/reporting/Universe.sol',
                              'universe',
                              constructorArgs=[
                                  fixture.contracts['Augur'].address,
                                  mockUniverse.address,
                                  stringToBytes("5")
                              ])
    fixture.contracts['populatedUniverse'] = universe

    return fixture.createSnapshot()
Esempio n. 11
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockCash = fixture.contracts['MockCash']
    mockAugur = fixture.contracts['MockAugur']
    mockFeeToken = fixture.contracts['MockFeeToken']
    mockFeeTokenFactory = fixture.contracts['MockFeeTokenFactory']
    mockFeeTokenFactory.setCreateFeeToken(mockFeeToken.address)
    mockReputationToken = fixture.contracts['MockReputationToken']
    controller.registerContract(stringToBytes('Cash'), mockCash.address,
                                twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('Augur'), mockAugur.address,
                                twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('FeeTokenFactory'),
                                mockFeeTokenFactory.address, twentyZeros,
                                thirtyTwoZeros)
    feeWindow = fixture.upload('../source/contracts/reporting/FeeWindow.sol',
                               'feeWindow')
    fixture.contracts["initializedFeeWindow"] = feeWindow
    feeWindow.setController(fixture.contracts["Controller"].address)

    mockUniverse = fixture.contracts['MockUniverse']
    mockUniverse.setReputationToken(mockReputationToken.address)
    mockUniverse.setDisputeRoundDurationInSeconds(5040)
    mockUniverse.setForkingMarket(5040)
    mockUniverse.setForkingMarket(longToHexString(0))
    mockUniverse.setIsForking(False)
    fixture.contracts["Time"].setTimestamp(feeWindowId)
    feeWindow.initialize(mockUniverse.address, feeWindowId)
    return fixture.createSnapshot()
Esempio n. 12
0
def localSnapshot(fixture, controllerSnapshot):
    fixture.resetToSnapshot(controllerSnapshot)
    fixture.upload('solidity_test_helpers/ControllerUser.sol')
    fixture.uploadAugur()
    decentralizedController = fixture.upload(
        '../source/contracts/Controller.sol', 'decentralizedController')
    decentralizedController.switchOffDevMode(sender=tester.k0)
    return fixture.createSnapshot()
Esempio n. 13
0
def localSnapshot(fixture, augurInitializedSnapshot):
    fixture.resetToSnapshot(augurInitializedSnapshot)
    controller = fixture.contracts['Controller']
    mockAugurLite = fixture.uploadAndAddToController(
        "solidity_test_helpers/MockAugurLite.sol", "AugurLite")
    mockToken = fixture.uploadAndAddToController(
        "solidity_test_helpers/MockToken.sol")
    return fixture.createSnapshot()
Esempio n. 14
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockLegacyReputationToken = fixture.contracts['MockLegacyReputationToken']
    controller.registerContract(stringToBytes('LegacyReputationToken'), mockLegacyReputationToken.address)
    mockLegacyReputationToken.setTotalSupply(100)
    mockLegacyReputationToken.setBalanceOfValueFor(tester.a0, 100)
    return fixture.createSnapshot()
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockLegacyReputationToken = fixture.contracts['MockLegacyReputationToken']
    controller.registerContract(stringToBytes('LegacyReputationToken'), mockLegacyReputationToken.address, twentyZeros, thirtyTwoZeros)
    mockLegacyReputationToken.setTotalSupply(100)
    mockLegacyReputationToken.setBalanceOfValueFor(tester.a0, 100)
    return fixture.createSnapshot()
Esempio n. 16
0
def localSnapshot(fixture, baseSnapshot):
    fixture.resetToSnapshot(baseSnapshot)
    controller = fixture.upload('../source/contracts/Controller.sol')
    assert fixture.contracts['Controller'].owner() == bytesToHexString(
        tester.a0)
    fixture.upload('solidity_test_helpers/ControllerUser.sol')
    fixture.uploadAugur()
    return fixture.createSnapshot()
Esempio n. 17
0
def localSnapshot(fixture, baseSnapshot):
    fixture.resetToSnapshot(baseSnapshot)
    fixture.uploadAugur()
    fixture.uploadAndAddToAugur("solidity_test_helpers/DelegatorHelper.sol")
    delegatorHelperFactory = fixture.uploadAndAddToAugur("solidity_test_helpers/DelegatorHelperFactory.sol")
    delegatorHelperAddress = delegatorHelperFactory.createDelegatorHelper(fixture.contracts['Augur'].address)
    fixture.contracts["Clone"] = fixture.applySignature("DelegatorHelper", delegatorHelperAddress)
    return fixture.createSnapshot()
Esempio n. 18
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockLegacyReputationToken = fixture.contracts['MockLegacyReputationToken']
    controller.registerContract(stringToBytes('LegacyReputationToken'),
                                mockLegacyReputationToken.address, twentyZeros,
                                thirtyTwoZeros)
    return fixture.createSnapshot()
Esempio n. 19
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockCash = fixture.contracts['MockCash']
    mockAugur = fixture.contracts['MockAugur']
    mockInitialReporter = fixture.contracts['MockInitialReporter']
    mockDisputeCrowdsourcer = fixture.contracts['MockDisputeCrowdsourcer']
    mockShareTokenFactory = fixture.contracts['MockShareTokenFactory']
    mockInitialReporterFactory = fixture.contracts['MockInitialReporterFactory']
    mockDisputeCrowdsourcerFactory = fixture.contracts['MockDisputeCrowdsourcerFactory']
    mockShareToken = fixture.contracts['MockShareToken']

    # pre populate share tokens for max of 8 possible outcomes
    for index in range(8):
        item = fixture.uploadAndAddToController('solidity_test_helpers/MockShareToken.sol', 'newMockShareToken' + str(index));
        mockShareTokenFactory.pushCreateShareToken(item.address)

    controller.registerContract(stringToBytes('Cash'), mockCash.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('ShareTokenFactory'), mockShareTokenFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('InitialReporterFactory'), mockInitialReporterFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('DisputeCrowdsourcerFactory'), mockDisputeCrowdsourcerFactory.address, twentyZeros, thirtyTwoZeros)
    mockShareTokenFactory.resetCreateShareToken()

    mockReputationToken = fixture.contracts['MockReputationToken']
    mockUniverse = fixture.contracts['MockUniverse']
    mockUniverse.setReputationToken(mockReputationToken.address)

    mockFeeWindow = fixture.contracts['MockFeeWindow']
    mockFeeWindow.setReputationToken(mockReputationToken.address)
    mockFeeWindow.setUniverse(mockUniverse.address)

    mockNextFeeWindow = fixture.upload('solidity_test_helpers/MockFeeWindow.sol', 'mockNextFeeWindow')
    mockNextFeeWindow.setReputationToken(mockReputationToken.address)
    mockNextFeeWindow.setUniverse(mockUniverse.address)

    mockInitialReporterFactory.setInitialReporter(mockInitialReporter.address)
    mockDisputeCrowdsourcerFactory.setDisputeCrowdsourcer(mockDisputeCrowdsourcer.address)

    constants = fixture.contracts['Constants']

    market = fixture.upload('../source/contracts/reporting/Market.sol', 'market')
    fixture.contracts["initializedMarket"] = market
    contractMap = fixture.upload('../source/contracts/libraries/collections/Map.sol', 'Map')
    endTime = fixture.contracts["Time"].getTimestamp() + constants.DESIGNATED_REPORTING_DURATION_SECONDS()
    market.setController(fixture.contracts["Controller"].address)

    mockUniverse.setForkingMarket(longToHexString(0))
    mockUniverse.setOrCacheDesignatedReportNoShowBond(100)
    mockReputationToken.setBalanceOf(100)
    mockUniverse.setOrCacheTargetReporterGasCosts(15)
    mockUniverse.setOrCacheValidityBond(12)
    mockUniverse.setNextFeeWindow(mockNextFeeWindow.address)
    mockFeeWindow.setEndTime(fixture.contracts["Time"].getTimestamp() + constants.DESIGNATED_REPORTING_DURATION_SECONDS())
    mockNextFeeWindow.setEndTime(mockFeeWindow.getEndTime() + constants.DESIGNATED_REPORTING_DURATION_SECONDS())
    assert market.initialize(mockUniverse.address, endTime, 16, mockCash.address, tester.a1, tester.a2, 5, numTicks, value=100)

    return fixture.createSnapshot()
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    augur = fixture.contracts["Augur"]
    kitchenSinkSnapshot['Medianizer'] = fixture.upload('../source/contracts/external/MkrPriceFeed/Medianizer.sol', "Medianizer")
    kitchenSinkSnapshot['FeedFactory'] = fixture.upload('../source/contracts/external/MkrPriceFeed/FeedFactory.sol', "FeedFactory")
    kitchenSinkSnapshot['DSGuardFactory'] = fixture.upload('../source/contracts/external/MkrPriceFeed/DSGuardFactory.sol', "DSGuardFactory")
    kitchenSinkSnapshot['PriceFeed'] = fixture.upload('../source/contracts/external/MkrPriceFeed/PriceFeed.sol', "PriceFeed")

    return fixture.createSnapshot()
Esempio n. 21
0
def localSnapshot(fixture, controllerSnapshot):
    fixture.resetToSnapshot(controllerSnapshot)
    fixture.uploadAugur()
    name = "DelegatorHelper"
    targetName = "DelegatorHelperTarget"
    fixture.uploadAndAddToController("solidity_test_helpers/DelegatorHelper.sol", targetName, name)
    fixture.uploadAndAddToController("../source/contracts/libraries/Delegator.sol", name, "delegator", constructorArgs=[fixture.contracts['Controller'].address, stringToBytes(targetName)])
    fixture.contracts[name] = fixture.applySignature(name, fixture.contracts[name].address)
    return fixture.createSnapshot()
Esempio n. 22
0
def reportingSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    # Give some REP to testers to make things interesting
    universe = ABIContract(fixture.chain, kitchenSinkSnapshot['universe'].translator, kitchenSinkSnapshot['universe'].address)
    reputationToken = fixture.applySignature('ReputationToken', universe.getReputationToken())
    for testAccount in [tester.a1, tester.a2, tester.a3]:
        reputationToken.transfer(testAccount, 1 * 10**6 * 10**18)

    return fixture.createSnapshot()
Esempio n. 23
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain,
                           kitchenSinkSnapshot['universe'].translator,
                           kitchenSinkSnapshot['universe'].address)
    market = ABIContract(fixture.chain,
                         kitchenSinkSnapshot['binaryMarket'].translator,
                         kitchenSinkSnapshot['binaryMarket'].address)
    return initializeReportingFixture(fixture, universe, market)
Esempio n. 24
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockCash = fixture.contracts['MockCash']
    mockAugur = fixture.contracts['MockAugur']
    mockInitialReporter = fixture.contracts['MockInitialReporter']
    mockDisputeCrowdsourcer = fixture.contracts['MockDisputeCrowdsourcer']
    mockShareTokenFactory = fixture.contracts['MockShareTokenFactory']
    mockInitialReporterFactory = fixture.contracts['MockInitialReporterFactory']
    mockDisputeCrowdsourcerFactory = fixture.contracts['MockDisputeCrowdsourcerFactory']
    mockShareToken = fixture.contracts['MockShareToken']

    # pre populate share tokens for max of 8 possible outcomes
    for index in range(8):
        item = fixture.uploadAndAddToController('solidity_test_helpers/MockShareToken.sol', 'newMockShareToken' + str(index));
        mockShareTokenFactory.pushCreateShareToken(item.address)

    controller.registerContract(stringToBytes('Cash'), mockCash.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('ShareTokenFactory'), mockShareTokenFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('InitialReporterFactory'), mockInitialReporterFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('DisputeCrowdsourcerFactory'), mockDisputeCrowdsourcerFactory.address, twentyZeros, thirtyTwoZeros)
    mockShareTokenFactory.resetCreateShareToken()

    mockReputationToken = fixture.contracts['MockReputationToken']
    mockUniverse = fixture.contracts['MockUniverse']
    mockUniverse.setReputationToken(mockReputationToken.address)

    mockFeeWindow = fixture.contracts['MockFeeWindow']
    mockFeeWindow.setReputationToken(mockReputationToken.address)
    mockFeeWindow.setUniverse(mockUniverse.address)

    mockNextFeeWindow = fixture.upload('solidity_test_helpers/MockFeeWindow.sol', 'mockNextFeeWindow')
    mockNextFeeWindow.setReputationToken(mockReputationToken.address)
    mockNextFeeWindow.setUniverse(mockUniverse.address)

    mockInitialReporterFactory.setInitialReporter(mockInitialReporter.address)
    mockDisputeCrowdsourcerFactory.setDisputeCrowdsourcer(mockDisputeCrowdsourcer.address)

    constants = fixture.contracts['Constants']

    market = fixture.upload('../source/contracts/reporting/Market.sol', 'market')
    fixture.contracts["initializedMarket"] = market
    contractMap = fixture.upload('../source/contracts/libraries/collections/Map.sol', 'Map')
    endTime = fixture.contracts["Time"].getTimestamp() + constants.DESIGNATED_REPORTING_DURATION_SECONDS()
    market.setController(fixture.contracts["Controller"].address)

    mockUniverse.setForkingMarket(longToHexString(0))
    mockUniverse.setOrCacheDesignatedReportNoShowBond(100)
    mockReputationToken.setBalanceOf(100)
    mockUniverse.setOrCacheTargetReporterGasCosts(15)
    mockUniverse.setOrCacheValidityBond(12)
    mockUniverse.setNextFeeWindow(mockNextFeeWindow.address)
    mockFeeWindow.setEndTime(fixture.contracts["Time"].getTimestamp() + constants.DESIGNATED_REPORTING_DURATION_SECONDS())
    mockNextFeeWindow.setEndTime(mockFeeWindow.getEndTime() + constants.DESIGNATED_REPORTING_DURATION_SECONDS())
    assert market.initialize(mockUniverse.address, endTime, 16, mockCash.address, tester.a1, tester.a2, 5, numTicks, value=100)

    return fixture.createSnapshot()
Esempio n. 25
0
def localSnapshot(fixture, controllerSnapshot):
    fixture.resetToSnapshot(controllerSnapshot)
    fixture.uploadAugurLite()
    name = "DelegatorHelper"
    targetName = "DelegatorHelperTarget"
    fixture.uploadAndAddToController("solidity_test_helpers/DelegatorHelper.sol", targetName, name)
    fixture.uploadAndAddToController("../source/contracts/libraries/Delegator.sol", name, "delegator", constructorArgs=[fixture.contracts['Controller'].address, stringToBytes(targetName)])
    fixture.contracts[name] = fixture.applySignature(name, fixture.contracts[name].address)
    return fixture.createSnapshot()
Esempio n. 26
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = fixture.applySignature(None, kitchenSinkSnapshot['universe'].address, kitchenSinkSnapshot['universe'].abi)
    market = fixture.applySignature(None, kitchenSinkSnapshot['yesNoMarket'].address, kitchenSinkSnapshot['yesNoMarket'].abi)
    # Give some REP to testers to make things interesting
    reputationToken = fixture.applySignature('ReputationToken', universe.getReputationToken())
    for testAccount in [fixture.accounts[1], fixture.accounts[2], fixture.accounts[3]]:
        reputationToken.transfer(testAccount, 1 * 10**6 * 10**18)

    return fixture.createSnapshot()
Esempio n. 27
0
def localSnapshot(fixture, augurInitializedSnapshot):
    fixture.resetToSnapshot(augurInitializedSnapshot)
    controller = fixture.contracts['Controller']
    mockToken = fixture.uploadAndAddToController(
        "solidity_test_helpers/MockToken.sol")
    mockAugur = fixture.uploadAndAddToController(
        "solidity_test_helpers/MockAugur.sol")
    controller.registerContract(stringToBytes('Augur'), mockAugur.address,
                                twentyZeros, thirtyTwoZeros)
    return fixture.createSnapshot()
Esempio n. 28
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain, kitchenSinkSnapshot['universe'].translator, kitchenSinkSnapshot['universe'].address)

    # Distribute REP
    reputationToken = fixture.applySignature('ReputationToken', universe.getReputationToken())
    for testAccount in [tester.a1, tester.a2, tester.a3]:
        reputationToken.transfer(testAccount, 1 * 10**6 * 10**18)

    return fixture.createSnapshot()
Esempio n. 29
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockReputationTokenFactory = fixture.contracts['MockReputationTokenFactory']
    mockReportingWindowFactory = fixture.contracts['MockReportingWindowFactory']
    mockUniverseFactory = fixture.contracts['MockUniverseFactory']
    controller.registerContract(stringToBytes('ReputationTokenFactory'), mockReputationTokenFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('ReportingWindowFactory'), mockReportingWindowFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('UniverseFactory'), mockUniverseFactory.address, twentyZeros, thirtyTwoZeros)
    return fixture.createSnapshot()
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockReportingParticipationTokenFactory = fixture.contracts['MockParticipationTokenFactory']
    mockCash = fixture.contracts['MockCash']
    mockMarketFactory = fixture.contracts['MockMarketFactory']
    controller.registerContract(stringToBytes('MarketFactory'), mockMarketFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('Cash'), mockCash.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('ParticipationTokenFactory'), mockReportingParticipationTokenFactory.address, twentyZeros, thirtyTwoZeros)
    return fixture.createSnapshot()
Esempio n. 31
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    fixture.contracts['universe'] = ABIContract(
        fixture.chain, kitchenSinkSnapshot['universe'].translator,
        kitchenSinkSnapshot['universe'].address)
    fixture.contracts['market'] = ABIContract(
        fixture.chain, kitchenSinkSnapshot['binaryMarket'].translator,
        kitchenSinkSnapshot['binaryMarket'].address)
    fixture.contracts['cash'] = ABIContract(
        fixture.chain, kitchenSinkSnapshot['cash'].translator,
        kitchenSinkSnapshot['cash'].address)
    return fixture.createSnapshot()
Esempio n. 32
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = kitchenSinkSnapshot['universe']

    # Distribute REP
    reputationToken = fixture.applySignature('ReputationToken',
                                             universe.getReputationToken())
    for testAccount in [
            fixture.accounts[1], fixture.accounts[2], fixture.accounts[3]
    ]:
        reputationToken.transfer(testAccount, 1 * 10**6 * 10**18)

    return fixture.createSnapshot()
Esempio n. 33
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = fixture.applySignature(None, kitchenSinkSnapshot['universe'].address, kitchenSinkSnapshot['universe'].abi)
    fixture.markets = [
        fixture.createReasonableCategoricalMarket(universe, 2),
        fixture.createReasonableCategoricalMarket(universe, 3),
        fixture.createReasonableCategoricalMarket(universe, 4),
        fixture.createReasonableCategoricalMarket(universe, 5),
        fixture.createReasonableCategoricalMarket(universe, 6),
        fixture.createReasonableCategoricalMarket(universe, 7),
    ]

    return fixture.createSnapshot()
Esempio n. 34
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain, kitchenSinkSnapshot['universe'].translator, kitchenSinkSnapshot['universe'].address)
    fixture.markets = [
        fixture.createReasonableCategoricalMarket(universe, 2),
        fixture.createReasonableCategoricalMarket(universe, 3),
        fixture.createReasonableCategoricalMarket(universe, 4),
        fixture.createReasonableCategoricalMarket(universe, 5),
        fixture.createReasonableCategoricalMarket(universe, 6),
        fixture.createReasonableCategoricalMarket(universe, 7),
        fixture.createReasonableCategoricalMarket(universe, 8)
    ]

    return fixture.createSnapshot()
Esempio n. 35
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain,
                           kitchenSinkSnapshot['universe'].translator,
                           kitchenSinkSnapshot['universe'].address)
    market = ABIContract(fixture.chain,
                         kitchenSinkSnapshot['binaryMarket'].translator,
                         kitchenSinkSnapshot['binaryMarket'].address)
    categoricalMarket = ABIContract(
        fixture.chain, kitchenSinkSnapshot['categoricalMarket'].translator,
        kitchenSinkSnapshot['categoricalMarket'].address)
    scalarMarket = ABIContract(fixture.chain,
                               kitchenSinkSnapshot['scalarMarket'].translator,
                               kitchenSinkSnapshot['scalarMarket'].address)
    cash = ABIContract(fixture.chain, kitchenSinkSnapshot['cash'].translator,
                       kitchenSinkSnapshot['cash'].address)
    completeSets = fixture.contracts['CompleteSets']
    mailbox = fixture.applySignature('Mailbox',
                                     market.getMarketCreatorMailbox())

    # Generate the fees in our initial reporting window
    cost = 1000 * market.getNumTicks()
    marketCreatorFees = cost / market.getMarketCreatorSettlementFeeDivisor()
    completeSets.publicBuyCompleteSets(market.address,
                                       1000,
                                       sender=tester.k1,
                                       value=cost)
    with TokenDelta(
            cash, marketCreatorFees, mailbox.address,
            "The market creator mailbox didn't get their share of fees from complete set sale"
    ):
        completeSets.publicSellCompleteSets(market.address,
                                            1000,
                                            sender=tester.k1)
    with EtherDelta(
            marketCreatorFees, market.getOwner(), fixture.chain,
            "The market creator did not get their fees when withdrawing ETH from the mailbox"
    ):
        assert mailbox.withdrawEther()
    fees = cash.balanceOf(market.getReportingWindow())
    reporterFees = cost / universe.getOrCacheReportingFeeDivisor()
    assert fees == reporterFees

    # Distribute REP
    reputationToken = fixture.applySignature('ReputationToken',
                                             universe.getReputationToken())
    for testAccount in [tester.a1, tester.a2, tester.a3, tester.a4, tester.a5]:
        reputationToken.transfer(testAccount, 1 * 10**6 * 10**18)

    return fixture.createSnapshot()
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain, kitchenSinkSnapshot['universe'].translator, kitchenSinkSnapshot['universe'].address)
    cash = ABIContract(fixture.chain, kitchenSinkSnapshot['cash'].translator, kitchenSinkSnapshot['cash'].address)
    fixture.markets = [
        fixture.createReasonableCategoricalMarket(universe, 2, cash),
        fixture.createReasonableCategoricalMarket(universe, 3, cash),
        fixture.createReasonableCategoricalMarket(universe, 4, cash),
        fixture.createReasonableCategoricalMarket(universe, 5, cash),
        fixture.createReasonableCategoricalMarket(universe, 6, cash),
        fixture.createReasonableCategoricalMarket(universe, 7, cash),
        fixture.createReasonableCategoricalMarket(universe, 8, cash)
    ]

    return fixture.createSnapshot()
Esempio n. 37
0
def localSnapshot(fixture, controllerSnapshot):
    fixture.resetToSnapshot(controllerSnapshot)

    fixture.uploadAugur()

    # Upload a token
    fixture.uploadAndAddToController("solidity_test_helpers/StandardTokenHelper.sol")

    # Upload Cash
    cash = fixture.uploadAndAddToController("../source/contracts/trading/Cash.sol")
    cash.setController(fixture.contracts['Controller'].address)

    # Upload the mailbox
    name = "Mailbox"
    targetName = "MailboxTarget"
    fixture.uploadAndAddToController("../source/contracts/reporting/Mailbox.sol", targetName, name)
    fixture.uploadAndAddToController("../source/contracts/libraries/Delegator.sol", name, "delegator", constructorArgs=[fixture.contracts['Controller'].address, stringToBytes(targetName)])
    fixture.contracts[name] = fixture.applySignature(name, fixture.contracts[name].address)
    fixture.contracts[name].initialize(tester.a0)
    return fixture.createSnapshot()
Esempio n. 38
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockReputationTokenFactory = fixture.contracts['MockReputationTokenFactory']
    mockFeeWindowFactory = fixture.contracts['MockFeeWindowFactory']
    mockMarketFactory = fixture.contracts['MockMarketFactory']
    mockUniverseFactory = fixture.contracts['MockUniverseFactory']
    controller.registerContract(stringToBytes('MarketFactory'), mockMarketFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('ReputationTokenFactory'), mockReputationTokenFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('FeeWindowFactory'), mockFeeWindowFactory.address, twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('UniverseFactory'), mockUniverseFactory.address, twentyZeros, thirtyTwoZeros)

    mockReputationToken = fixture.contracts['MockReputationToken']
    mockUniverse = fixture.contracts['MockUniverse']

    universe = fixture.upload('../source/contracts/reporting/Universe.sol', 'universe')
    fixture.contracts['populatedUniverse'] = universe
    mockReputationTokenFactory.setCreateReputationTokenValue(mockReputationToken.address)
    universe.setController(fixture.contracts['Controller'].address)
    assert universe.initialize(mockUniverse.address, stringToBytes("5"))

    return fixture.createSnapshot()
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain, kitchenSinkSnapshot['universe'].translator, kitchenSinkSnapshot['universe'].address)
    market = ABIContract(fixture.chain, kitchenSinkSnapshot['yesNoMarket'].translator, kitchenSinkSnapshot['yesNoMarket'].address)
    categoricalMarket = ABIContract(fixture.chain, kitchenSinkSnapshot['categoricalMarket'].translator, kitchenSinkSnapshot['categoricalMarket'].address)
    scalarMarket = ABIContract(fixture.chain, kitchenSinkSnapshot['scalarMarket'].translator, kitchenSinkSnapshot['scalarMarket'].address)

    # Skip to Designated Reporting
    fixture.contracts["Time"].setTimestamp(market.getEndTime() + 1)

    # Distribute REP
    reputationToken = fixture.applySignature('ReputationToken', universe.getReputationToken())
    for testAccount in [tester.a1, tester.a2, tester.a3]:
        reputationToken.transfer(testAccount, 1 * 10**6 * 10**18)

    # Designated Report on the markets
    designatedReportCost = universe.getOrCacheDesignatedReportStake()
    with TokenDelta(reputationToken, 0, tester.a0, "Doing the designated report didn't deduct REP correctly or didn't award the no show bond"):
        market.doInitialReport([market.getNumTicks(), 0], False)
        categoricalMarket.doInitialReport([categoricalMarket.getNumTicks(), 0, 0], False)
        scalarMarket.doInitialReport([scalarMarket.getNumTicks(), 0], False)

    return fixture.createSnapshot()
Esempio n. 40
0
def localFixture(fixture, localSnapshot):
    fixture.resetToSnapshot(localSnapshot)
    return fixture
def reportingFixture(fixture, reportingSnapshot):
    fixture.resetToSnapshot(reportingSnapshot)
    return fixture
Esempio n. 42
0
def localSnapshot(fixture, augurInitializedSnapshot):
    fixture.resetToSnapshot(augurInitializedSnapshot)
    controller = fixture.contracts['Controller']
    mockAugur = fixture.uploadAndAddToController("solidity_test_helpers/MockAugur.sol", "Augur")
    mockToken = fixture.uploadAndAddToController("solidity_test_helpers/MockToken.sol")
    return fixture.createSnapshot()
def localSnapshot(fixture, baseSnapshot):
    fixture.resetToSnapshot(baseSnapshot)
    fixture.upload('solidity_test_helpers/ContractExistsHelper.sol')
    return fixture.createSnapshot()
Esempio n. 44
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    return fixture.createSnapshot()
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    fixture.contracts['universe'] = ABIContract(fixture.chain, kitchenSinkSnapshot['universe'].translator, kitchenSinkSnapshot['universe'].address)
    fixture.contracts['market'] = ABIContract(fixture.chain, kitchenSinkSnapshot['yesNoMarket'].translator, kitchenSinkSnapshot['yesNoMarket'].address)
    fixture.contracts['cash'] = ABIContract(fixture.chain, kitchenSinkSnapshot['cash'].translator, kitchenSinkSnapshot['cash'].address)
    return fixture.createSnapshot()
Esempio n. 46
0
def execute(fixture, snapshot, universe, market, orderType, orderSize, orderPrice, orderOutcome, creatorLongShares, creatorShortShares, creatorTokens, fillerLongShares, fillerShortShares, fillerTokens, expectedMakerLongShares, expectedMakerShortShares, expectedMakerTokens, expectedFillerLongShares, expectedFillerShortShares, expectedFillerTokens, numTicks):
    def acquireLongShares(outcome, amount, approvalAddress, sender):
        if amount == 0: return

        shareToken = fixture.applySignature('ShareToken', market.getShareToken(outcome))
        completeSets = fixture.contracts['CompleteSets']
        createOrder = fixture.contracts['CreateOrder']
        fillOrder = fixture.contracts['FillOrder']

        ethRequired = amount * numTicks
        assert completeSets.publicBuyCompleteSets(market.address, amount, sender = sender, value = ethRequired)
        for otherOutcome in range(0, market.getNumberOfOutcomes()):
            if otherOutcome == outcome: continue
            otherShareToken = fixture.applySignature('ShareToken', market.getShareToken(otherOutcome))
            assert otherShareToken.transfer(0, amount, sender = sender)

    def acquireShortShareSet(outcome, amount, approvalAddress, sender):
        if amount == 0: return

        shareToken = fixture.applySignature('ShareToken', market.getShareToken(outcome))
        completeSets = fixture.contracts['CompleteSets']
        createOrder = fixture.contracts['CreateOrder']
        fillOrder = fixture.contracts['FillOrder']

        ethRequired = amount * numTicks
        assert completeSets.publicBuyCompleteSets(market.address, amount, sender = sender, value = ethRequired)
        assert shareToken.transfer(0, amount, sender = sender)
        for otherOutcome in range(0, market.getNumberOfOutcomes()):
            if otherOutcome == outcome: continue
            otherShareToken = fixture.applySignature('ShareToken', market.getShareToken(otherOutcome))

    fixture.resetToSnapshot(snapshot)

    legacyReputationToken = fixture.contracts['LegacyReputationToken']
    legacyReputationToken.faucet(long(11 * 10**6 * 10**18))
    fixture.chain.head_state.timestamp += 15000

    orders = fixture.contracts['Orders']
    createOrder = fixture.contracts['CreateOrder']
    fillOrder = fixture.contracts['FillOrder']
    completeSets = fixture.contracts['CompleteSets']

    creatorAddress = tester.a1
    fillerAddress = tester.a2
    creatorKey = tester.k1
    fillerKey = tester.k2

    # Set creator/filler balances
    creatorBalance = fixture.chain.head_state.get_balance(creatorAddress)
    fillerBalance = fixture.chain.head_state.get_balance(fillerAddress)

    # Acquire shares for creator
    creatorEthRequiredLong = 0 if creatorLongShares == 0 else creatorLongShares * numTicks
    creatorEthRequiredShort = 0 if creatorShortShares == 0 else creatorShortShares * numTicks
    acquireLongShares(orderOutcome, creatorLongShares, createOrder.address, sender = creatorKey)
    acquireShortShareSet(orderOutcome, creatorShortShares, createOrder.address, sender = creatorKey)
    assert fixture.chain.head_state.get_balance(creatorAddress) == creatorBalance - creatorEthRequiredLong - creatorEthRequiredShort
    assert fixture.chain.head_state.get_balance(fillerAddress) == fillerBalance

    creatorBalance = fixture.chain.head_state.get_balance(creatorAddress)
    fillerBalance = fixture.chain.head_state.get_balance(fillerAddress)

    # Create order
    orderId = createOrder.publicCreateOrder(orderType, orderSize, orderPrice, market.address, orderOutcome, longTo32Bytes(0), longTo32Bytes(0), "42", sender = creatorKey, value = creatorTokens)
    assert fixture.chain.head_state.get_balance(creatorAddress) == creatorBalance - creatorTokens
    assert fixture.chain.head_state.get_balance(fillerAddress) == fillerBalance

    creatorBalance = fixture.chain.head_state.get_balance(creatorAddress)
    fillerBalance = fixture.chain.head_state.get_balance(fillerAddress)

    # Validate order
    assert orders.getAmount(orderId) == orderSize
    assert orders.getPrice(orderId) == orderPrice
    assert orders.getOrderCreator(orderId) == bytesToHexString(creatorAddress)
    assert orders.getOrderMoneyEscrowed(orderId) == creatorTokens
    assert orders.getOrderSharesEscrowed(orderId) == creatorLongShares or creatorShortShares

    # Acquire shares for filler
    fillerEthRequiredLong = 0 if fillerLongShares == 0 else fillerLongShares * numTicks
    fillerEthRequiredShort = 0 if fillerShortShares == 0 else fillerShortShares * numTicks
    acquireLongShares(orderOutcome, fillerLongShares, fillOrder.address, sender = fillerKey)
    acquireShortShareSet(orderOutcome, fillerShortShares, fillOrder.address, sender = fillerKey)
    assert fixture.chain.head_state.get_balance(creatorAddress) == creatorBalance
    assert fixture.chain.head_state.get_balance(fillerAddress) == fillerBalance - fillerEthRequiredLong - fillerEthRequiredShort

    creatorBalance = fixture.chain.head_state.get_balance(creatorAddress)
    fillerBalance = fixture.chain.head_state.get_balance(fillerAddress)

    # Fill order
    remaining = fillOrder.publicFillOrder(orderId, orderSize, "42", sender = fillerKey, value = fillerTokens)
    assert not remaining

    # Assert final state
    assert fixture.chain.head_state.get_balance(creatorAddress) == creatorBalance + expectedMakerTokens
    assert fixture.chain.head_state.get_balance(fillerAddress) == fillerBalance - fillerTokens + expectedFillerTokens
    for outcome in range(0, market.getNumberOfOutcomes()):
        shareToken = fixture.applySignature('ShareToken', market.getShareToken(outcome))
        if outcome == orderOutcome:
            assert shareToken.balanceOf(creatorAddress) == expectedMakerLongShares
            assert shareToken.balanceOf(fillerAddress) == expectedFillerLongShares
        else:
            assert shareToken.balanceOf(creatorAddress) == expectedMakerShortShares
            assert shareToken.balanceOf(fillerAddress) == expectedFillerShortShares
Esempio n. 47
0
def test_randomSorting(market, orderType, numOrders, withBoundingOrders, deadOrderProbability, fixture, kitchenSinkSnapshot):
    print("Order sorting tests (orderType=" + str(orderType) + ", numOrders=" + str(numOrders) + ", withBoundingOrders=" + str(withBoundingOrders) + ", deadOrderProbability=" + str(deadOrderProbability) + ")")
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    orders = fixture.contracts['Orders']
    outcomeId = 1
    orderIds = np.arange(1, numOrders + 1)
    # Generate random prices on [0, 1) and rank them (smallest price @ rank 0)
    fxpPrices = np.vectorize(fix)(np.random.rand(numOrders))
    orderIdsToPriceMapping = {}
    priceRanks = np.argsort(np.argsort(fxpPrices))
    logs = []
    assert orderType == BID or orderType == ASK
    if orderType == BID:
        bestOrderId = orderIds[np.argmax(priceRanks)]
        worstOrderId = orderIds[np.argmin(priceRanks)]
    if orderType == ASK:
        bestOrderId = orderIds[np.argmin(priceRanks)]
        worstOrderId = orderIds[np.argmax(priceRanks)]
    betterOrderIds = np.zeros(numOrders, dtype=np.int)
    worseOrderIds = np.zeros(numOrders, dtype=np.int)
    deadOrders = np.random.rand(numOrders, 2) < deadOrderProbability
    for i, priceRank in enumerate(priceRanks):
        if withBoundingOrders:
            if orderType == BID:
                betterOrders = np.flatnonzero(priceRank < priceRanks)
                worseOrders = np.flatnonzero(priceRank > priceRanks)
            else:
                betterOrders = np.flatnonzero(priceRank > priceRanks)
                worseOrders = np.flatnonzero(priceRank < priceRanks)
            if len(betterOrders): betterOrderIds[i] = orderIds[np.random.choice(betterOrders)]
            if len(worseOrders): worseOrderIds[i] = orderIds[np.random.choice(worseOrders)]
    print(np.c_[orderIds, fxpPrices, priceRanks, betterOrderIds, worseOrderIds, deadOrders])
    orderIdsToBytesMapping = {}
    bytesToOrderIdsMapping = {}
    for i, orderId in enumerate(orderIds):
        betterOrderId = betterOrderIds[i]
        worseOrderId = worseOrderIds[i]
        if withBoundingOrders:
            if orderType == BID:
                assert((orderId == bestOrderId and betterOrderId == 0) or fxpPrices[i] < fxpPrices[betterOrderId - 1]), "Input price is < better order price, or this is the best order so better order Id is zero"
                assert((orderId == worstOrderId and worseOrderId == 0) or fxpPrices[i] > fxpPrices[worseOrderId - 1]), "Input price is > worse order price, or this is the worst order so worse order Id is zero"
            else:
                assert((orderId == bestOrderId and betterOrderId == 0) or fxpPrices[i] > fxpPrices[betterOrderId - 1]), "Input price is > better order price, or this is the best order so better order Id is zero"
                assert((orderId == worstOrderId and worseOrderId == 0) or fxpPrices[i] < fxpPrices[worseOrderId - 1]), "Input price is < worse order price, or this is the worst order so worse order Id is zero"
            if deadOrders[i, 0]: betterOrderId = numOrders + 1
            if deadOrders[i, 1]: worseOrderId = numOrders + 1
        actualOrderId = orders.saveOrder(orderType, market.address, 1, fxpPrices[i], tester.a1, outcomeId, 0, 0, longTo32Bytes(betterOrderId), longTo32Bytes(worseOrderId), "0")
        assert(actualOrderId != bytearray(32)), "Insert order into list"
        orderIdsToPriceMapping[orderId] = fxpPrices[i]
        orderIdsToBytesMapping[orderId] = actualOrderId
        bytesToOrderIdsMapping[actualOrderId] =  orderId
    assert(orderIdsToBytesMapping[bestOrderId] == orders.getBestOrderId(orderType, market.address, outcomeId)), "Verify best order Id"
    assert(orderIdsToBytesMapping[worstOrderId] == orders.getWorstOrderId(orderType, market.address, outcomeId)), "Verify worst order Id"
    for orderId in orderIds:
        orderPrice = orderIdsToPriceMapping[orderId]
        betterOrderIdAsBytes = orders.getBetterOrderId(orderIdsToBytesMapping[orderId])
        worseOrderIdAsBytes = orders.getWorseOrderId(orderIdsToBytesMapping[orderId])
        betterOrderId = 0 if betterOrderIdAsBytes == longTo32Bytes(0) else bytesToOrderIdsMapping[betterOrderIdAsBytes]
        worseOrderId = 0 if worseOrderIdAsBytes == longTo32Bytes(0) else bytesToOrderIdsMapping[worseOrderIdAsBytes]
        betterOrderPrice = 0 if betterOrderId == 0 else orderIdsToPriceMapping[betterOrderId]
        worseOrderPrice = 0 if worseOrderId == 0 else orderIdsToPriceMapping[worseOrderId]
        if orderType == BID:
            if betterOrderPrice: assert(orderPrice <= betterOrderPrice), "Order price <= better order price"
            if worseOrderPrice: assert(orderPrice >= worseOrderPrice), "Order price >= worse order price"
        else:
            if betterOrderPrice: assert(orderPrice >= betterOrderPrice), "Order price >= better order price"
            if worseOrderPrice: assert(orderPrice <= worseOrderPrice), "Order price <= worse order price"
        if betterOrderId:
            assert(orders.getWorseOrderId(betterOrderIdAsBytes) == orderIdsToBytesMapping[orderId]), "Better order's worseOrderId should equal orderId"
        else:
            assert(orderId == bestOrderId), "Should be the best order Id"
        if worseOrderId:
            assert(orders.getBetterOrderId(worseOrderIdAsBytes) == orderIdsToBytesMapping[orderId]), "Worse order's betterOrderId should equal orderId"
        else:
            assert(orderId == worstOrderId), "Should be the worst order Id"
    for orderId in orderIds:
        assert(orders.removeOrder(orderIdsToBytesMapping[orderId]) == 1), "Remove order from list"