Exemplo n.º 1
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()
Exemplo n.º 2
0
def test_delegationTargetInitialMemberValues(localFixture):

    delegatorHelperTarget = localFixture.contracts['DelegatorHelperTarget']
    delegatorHelper = localFixture.contracts['DelegatorHelper']

    # Members set at declaration time on the delegation target are not set/retreivable on the delegator unless declared constant
    assert delegatorHelperTarget.intValue() == -42
    assert delegatorHelper.intValue() == 0
    assert delegatorHelperTarget.name() == stringToBytes("Name")
    assert delegatorHelper.name() == stringToBytes("")
    assert delegatorHelper.constantName() == stringToBytes("ConstantName")
    assert delegatorHelper.constantName() == delegatorHelperTarget.constantName()

    # String values are retrievable, but like ints are not set at declaration time.
    assert delegatorHelperTarget.stringMember() == "StringMember"
    assert delegatorHelperTarget.stringConstant() == "StringConstant"
    assert delegatorHelper.stringMember() == ""
    assert delegatorHelper.stringConstant() == ""
    assert delegatorHelper.setStringMember("StringValue")
    assert delegatorHelper.stringMember() == "StringValue"
    assert delegatorHelper.getStringMember() == "StringValue"

    # Once a non-string member is explicitly set on the delegator it will have the newly provided value
    assert delegatorHelper.setName("NewName")
    assert delegatorHelper.getName() == stringToBytes("NewName")
    assert delegatorHelper.name() == stringToBytes("NewName")
    assert delegatorHelper.name() != delegatorHelperTarget.name()

    assert delegatorHelper.setIntValue(1)
    assert delegatorHelper.getIntValue() == 1
    assert delegatorHelper.intValue() == 1
    assert delegatorHelper.intValue() != delegatorHelperTarget.intValue()
Exemplo n.º 3
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()
Exemplo n.º 4
0
def test_market_finalize_fork(localFixture, initializedMarket, mockUniverse):
    with raises(TransactionFailed, message="current market needs to be forking market"):
        initializedMarket.finalizeFork()

    mockUniverse.setForkingMarket(initializedMarket.address)
    winningUniverse = localFixture.upload('solidity_test_helpers/MockUniverse.sol', 'winningUniverse')
    mockUniverse.setWinningChildUniverse(winningUniverse.address)
    winningUniverse.setParentPayoutDistributionHash(stringToBytes("111"))

    assert initializedMarket.finalizeFork() == True
    assert initializedMarket.getWinningPayoutDistributionHash() == stringToBytes("111")
Exemplo n.º 5
0
def test_one_bid_on_books_buy_excess_order(contractsFixture, cash, market, universe):
    createOrder = contractsFixture.contracts['CreateOrder']
    trade = contractsFixture.contracts['Trade']
    fillOrder = contractsFixture.contracts['FillOrder']
    orders = contractsFixture.contracts['Orders']
    tradeGroupID = "42"

    # create order
    orderID = createOrder.publicCreateOrder(BID, fix(4), 6000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, sender = tester.k1, value=fix('4', '6000'))

    fillOrderID = None

    # fill best order
    orderFilledLog = {
        "filler": bytesToHexString(tester.a2),
        "numCreatorShares": 0,
        "numCreatorTokens": fix('4', '6000'),
        "numFillerShares": 0,
        "numFillerTokens": fix('4', '4000'),
        "marketCreatorFees": 0,
        "reporterFees": 0,
        "shareToken": market.getShareToken(YES),
        "tradeGroupId": stringToBytes("42"),
    }
    orderCreatedLog = {
        "creator": bytesToHexString(tester.a2),
        "shareToken": market.getShareToken(YES),
        "tradeGroupId": stringToBytes("42"),
    }
    with AssertLog(contractsFixture, "OrderFilled", orderFilledLog):
        with AssertLog(contractsFixture, "OrderCreated", orderCreatedLog):
            fillOrderID = trade.publicSell(market.address, YES, fix(5), 6000, "0", "0", tradeGroupID, sender = tester.k2, value=fix('5', '4000'))

    assert orders.getAmount(orderID) == 0
    assert orders.getPrice(orderID) == 0
    assert orders.getOrderCreator(orderID) == longToHexString(0)
    assert orders.getOrderMoneyEscrowed(orderID) == 0
    assert orders.getOrderSharesEscrowed(orderID) == 0
    assert orders.getBetterOrderId(orderID) == longTo32Bytes(0)
    assert orders.getWorseOrderId(orderID) == longTo32Bytes(0)

    assert orders.getAmount(fillOrderID) == fix(1)
    assert orders.getPrice(fillOrderID) == 6000
    assert orders.getOrderCreator(fillOrderID) == bytesToHexString(tester.a2)
    assert orders.getOrderMoneyEscrowed(fillOrderID) == fix('1', '4000')
    assert orders.getOrderSharesEscrowed(fillOrderID) == 0
    assert orders.getBetterOrderId(fillOrderID) == longTo32Bytes(0)
    assert orders.getWorseOrderId(fillOrderID) == longTo32Bytes(0)
Exemplo n.º 6
0
def augurInitializedWithMocksSnapshot(fixture, augurInitializedSnapshot):
    fixture.uploadAndAddToController("solidity_test_helpers/Constants.sol")
    fixture.uploadAllMockContracts()
    controller = fixture.contracts['Controller']
    mockAugur = fixture.contracts['MockAugur']
    controller.registerContract(stringToBytes('Augur'), mockAugur.address, twentyZeros, thirtyTwoZeros)
    return fixture.createSnapshot()
Exemplo n.º 7
0
def test_publicCreateOrder_bid2(contractsFixture, cash, market, universe):
    orders = contractsFixture.contracts['Orders']
    createOrder = contractsFixture.contracts['CreateOrder']

    orderType = BID
    amount = fix(1)
    fxpPrice = 4000
    outcome = 0
    tradeGroupID = "42"

    marketInitialCash = cash.balanceOf(market.address)
    creatorInitialETH = contractsFixture.chain.head_state.get_balance(tester.a1)

    orderID = None
    shareToken = contractsFixture.getShareToken(market, 0)

    orderCreatedLog = {
        'creator': bytesToHexString(tester.a1),
        'shareToken': shareToken.address,
        'tradeGroupId': stringToBytes("42"),
    }

    with AssertLog(contractsFixture, "OrderCreated", orderCreatedLog):
        orderID = createOrder.publicCreateOrder(orderType, amount, fxpPrice, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, sender=tester.k1, value = fix('1', '4000'))
    assert orderID != bytearray(32), "Order ID should be non-zero"

    assert orders.getAmount(orderID) == amount
    assert orders.getPrice(orderID) == fxpPrice
    assert orders.getOrderCreator(orderID) == bytesToHexString(tester.a1)
    assert orders.getOrderMoneyEscrowed(orderID) == fix(1, 4000)
    assert orders.getOrderSharesEscrowed(orderID) == 0
    assert cash.balanceOf(tester.a1) == 0
    assert contractsFixture.chain.head_state.get_balance(tester.a1) == creatorInitialETH - long(4000 * 10**18)
    assert cash.balanceOf(market.address) - marketInitialCash == 4000 * 10**18
Exemplo n.º 8
0
def test_ask_withPartialShares(contractsFixture, universe, cash, market):
    orders = contractsFixture.contracts['Orders']
    createOrder = contractsFixture.contracts['CreateOrder']
    fillOrder = contractsFixture.contracts['FillOrder']
    completeSets = contractsFixture.contracts['CompleteSets']
    yesShareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(YES))
    noShareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(NO))

    # buy fix(2) complete sets
    assert completeSets.publicBuyCompleteSets(market.address, fix(2), sender = tester.k1, value= fix(2, market.getNumTicks()))
    assert cash.balanceOf(tester.a1) == fix('0')
    assert yesShareToken.balanceOf(tester.a1) == fix(2)
    assert noShareToken.balanceOf(tester.a1) == fix(2)

    orderID = None

    orderCreatedLog = {
        'creator': bytesToHexString(tester.a1),
        'shareToken': yesShareToken.address,
        'tradeGroupId': stringToBytes("42"),
    }
    with AssertLog(contractsFixture, "OrderCreated", orderCreatedLog):
        orderID = createOrder.publicCreateOrder(ASK, fix(3), 4000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), "42", sender=tester.k1, value=fix('6000'))
    assert cash.balanceOf(tester.a1) == fix('0')
    assert yesShareToken.balanceOf(tester.a1) == 0
    assert noShareToken.balanceOf(tester.a1) == fix(2)

    # validate the order contains expected results
    assert orderID != bytearray(32), "Order ID should be non-zero"
    assert orders.getAmount(orderID) == fix(3)
    assert orders.getPrice(orderID) == 4000
    assert orders.getOrderCreator(orderID) == bytesToHexString(tester.a1)
    assert orders.getOrderMoneyEscrowed(orderID) == fix('6000')
    assert orders.getOrderSharesEscrowed(orderID) == fix(2)
Exemplo n.º 9
0
def test_universe_reporting_fee_divisor(localFixture, chain, populatedUniverse, mockReputationToken, mockFeeWindow, mockFeeWindowFactory):
    timestamp = localFixture.contracts["Time"].getTimestamp()
    controller = localFixture.contracts['Controller']
    constants = localFixture.contracts['Constants']
    repPriceOracle = localFixture.uploadAndAddToController("../source/contracts/reporting/RepPriceOracle.sol", 'repPriceOracle')
    controller.registerContract(stringToBytes('RepPriceOracle'), repPriceOracle.address, twentyZeros, thirtyTwoZeros)

    previousFeeWindow = localFixture.upload('solidity_test_helpers/MockFeeWindow.sol', 'previousFeeWindow')

    # set current fee window
    mockFeeWindowFactory.setCreateFeeWindowValue(mockFeeWindow.address)
    assert populatedUniverse.getOrCreateCurrentFeeWindow() == mockFeeWindow.address

    # set previous fee window
    mockFeeWindowFactory.setCreateFeeWindowValue(previousFeeWindow.address)
    assert populatedUniverse.getOrCreatePreviousFeeWindow() == previousFeeWindow.address

    multiplier = localFixture.contracts['Constants'].TARGET_REP_MARKET_CAP_MULTIPLIER() / float(localFixture.contracts['Constants'].TARGET_REP_MARKET_CAP_DIVISOR())
    # default value
    defaultValue = 100
    assert populatedUniverse.getRepMarketCapInAttoeth() == 0
    assert populatedUniverse.getOrCacheReportingFeeDivisor() == defaultValue

    # push fee window forward
    localFixture.contracts["Time"].incrementTimestamp(populatedUniverse.getDisputeRoundDurationInSeconds())

    # check getRepMarketCapInAttoeth() == 0
    assert populatedUniverse.getRepMarketCapInAttoeth() == 0
    assert populatedUniverse.getTargetRepMarketCapInAttoeth() == 0
    assert populatedUniverse.getOrCacheReportingFeeDivisor() == defaultValue

    # push fee window forward
    localFixture.contracts["Time"].incrementTimestamp(populatedUniverse.getDisputeRoundDurationInSeconds())

    # check previousDivisor > 0 and getRepMarketCapInAttoeth == 0
    assert populatedUniverse.getOrCacheReportingFeeDivisor() == defaultValue

    # _currentFeeDivisor > 0
    mockReputationToken.setTotalSupply(0)
    assert repPriceOracle.setRepPriceInAttoEth(0)
    populatedUniverse.incrementOpenInterest(10)
    assert populatedUniverse.getRepMarketCapInAttoeth() == 0
    assert populatedUniverse.getTargetRepMarketCapInAttoeth() == 10 * multiplier
    assert populatedUniverse.getOpenInterestInAttoEth() == 10
    assert populatedUniverse.getOrCacheReportingFeeDivisor() == defaultValue
    # value is cached for reach fee window
    assert populatedUniverse.getOrCacheReportingFeeDivisor() == defaultValue

    # push fee window forward
    localFixture.contracts["Time"].incrementTimestamp(populatedUniverse.getDisputeRoundDurationInSeconds())

    mockReputationToken.setTotalSupply(105)
    assert repPriceOracle.setRepPriceInAttoEth(10)
    populatedUniverse.incrementOpenInterest(10)
    assert populatedUniverse.getRepMarketCapInAttoeth() == 105 * 10
    assert populatedUniverse.getTargetRepMarketCapInAttoeth() == 20 * multiplier
    assert populatedUniverse.getOpenInterestInAttoEth() == 20
    # default because calculation is greater than 10000
    assert populatedUniverse.getOrCacheReportingFeeDivisor() == defaultValue
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
def test_init(contractsFixture, market):
    shareToken = contractsFixture.applySignature('ShareToken', market.getShareToken())

    assert shareToken.name() == "Shares", "currency name"
    assert shareToken.decimals() == 0, "number of decimals"
    assert shareToken.symbol() == "SHARE", "currency symbol"

    assert shareToken.getTypeName() == stringToBytes("ShareToken")
Exemplo n.º 12
0
def test_reputation_token_creation(localFixture, mockUniverse):
    reputationToken = localFixture.upload('../source/contracts/reporting/ReputationToken.sol', 'reputationToken')
    reputationToken.setController(localFixture.contracts['Controller'].address)
    with raises(TransactionFailed, message="universe has to have address"):
        reputationToken.initialize(longToHexString(0))

    assert reputationToken.initialize(mockUniverse.address)
    assert reputationToken.getTypeName() == stringToBytes('ReputationToken')
    assert reputationToken.getUniverse() == mockUniverse.address
Exemplo n.º 13
0
def test_reputation_token_creation(localFixture, mockUniverse):
    reputationToken = localFixture.upload('../source/contracts/reporting/ReputationToken.sol', 'reputationToken')
    reputationToken.setController(localFixture.contracts['Controller'].address)
    with raises(TransactionFailed, message="universe has to have address"):
        reputationToken.initialize(longToHexString(0))

    assert reputationToken.initialize(mockUniverse.address)
    assert reputationToken.getTypeName() == stringToBytes('ReputationToken')
    assert reputationToken.getUniverse() == mockUniverse.address
Exemplo n.º 14
0
def test_init(contractsFixture, market):
    shareToken = contractsFixture.applySignature('ShareToken',
                                                 market.getShareToken())

    assert shareToken.name() == "Shares", "currency name"
    assert shareToken.decimals() == 0, "number of decimals"
    assert shareToken.symbol() == "SHARE", "currency symbol"

    assert shareToken.getTypeName() == stringToBytes("ShareToken")
Exemplo n.º 15
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockMarketFactory = fixture.contracts['MockMarketFactory']
    mockUniverseFactory = fixture.contracts['MockUniverseFactory']
    controller.registerContract(stringToBytes('MarketFactory'),
                                mockMarketFactory.address, twentyZeros,
                                thirtyTwoZeros)
    controller.registerContract(stringToBytes('UniverseFactory'),
                                mockUniverseFactory.address, twentyZeros,
                                thirtyTwoZeros)
    mockUniverse = fixture.contracts['MockUniverse']

    universe = fixture.upload('../source/contracts/Universe.sol', 'universe')
    fixture.contracts['populatedUniverse'] = universe
    universe.setController(fixture.contracts['Controller'].address)

    return fixture.createSnapshot()
Exemplo n.º 16
0
def test_getContractDetails(controller):
    key = stringToBytes('lookup key')
    address = garbageAddress
    commitHash = garbageBytes20
    fileHash = garbageBytes32

    assert controller.getContractDetails(key, sender = tester.k2) == [ longToHexString(0), twentyZeros, thirtyTwoZeros ]
    assert controller.registerContract(key, address, commitHash, fileHash, sender = tester.k0)
    assert controller.getContractDetails(key, sender = tester.k2) == [ address, commitHash, fileHash ]
Exemplo n.º 17
0
def test_universe_creation(localFixture, mockReputationToken, mockReputationTokenFactory, mockUniverse, mockUniverseFactory, mockAugur):
    universe = localFixture.upload('../source/contracts/reporting/Universe.sol', 'newUniverse')

    with raises(TransactionFailed, message="reputation token can not be address 0"):
        universe.initialize(mockUniverse.address, stringToBytes("5"))

    mockReputationTokenFactory.setCreateReputationTokenValue(mockReputationToken.address)

    universe.setController(localFixture.contracts['Controller'].address)
    assert universe.initialize(mockUniverse.address, stringToBytes("5"))
    assert universe.getReputationToken() == mockReputationToken.address
    assert universe.getParentUniverse() == mockUniverse.address
    assert universe.getParentPayoutDistributionHash() == stringToBytes("5")
    assert universe.getForkingMarket() == longToHexString(0)
    assert universe.getForkEndTime() == 0
    assert universe.getTypeName() == stringToBytes('Universe')
    assert universe.getForkEndTime() == 0
    assert universe.getChildUniverse("5") == longToHexString(0)
Exemplo n.º 18
0
def test_getContractDetails(controller):
    key = stringToBytes('lookup key')
    address = garbageAddress
    commitHash = garbageBytes20
    fileHash = garbageBytes32

    assert controller.getContractDetails(key, sender = tester.k2) == [ longToHexString(0), twentyZeros, thirtyTwoZeros ]
    assert controller.registerContract(key, address, commitHash, fileHash, sender = tester.k0)
    assert controller.getContractDetails(key, sender = tester.k2) == [ address, commitHash, fileHash ]
Exemplo n.º 19
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()
Exemplo n.º 20
0
def test_universe_creation(localFixture, mockReputationToken, mockReputationTokenFactory, mockUniverse, mockUniverseFactory, mockAugur):
    universe = localFixture.upload('../source/contracts/reporting/Universe.sol', 'newUniverse')

    with raises(TransactionFailed, message="reputation token can not be address 0"):
        universe.initialize(mockUniverse.address, stringToBytes("5"))

    mockReputationTokenFactory.setCreateReputationTokenValue(mockReputationToken.address)

    universe.setController(localFixture.contracts['Controller'].address)
    assert universe.initialize(mockUniverse.address, stringToBytes("5"))
    assert universe.getReputationToken() == mockReputationToken.address
    assert universe.getParentUniverse() == mockUniverse.address
    assert universe.getParentPayoutDistributionHash() == stringToBytes("5")
    assert universe.getForkingMarket() == longToHexString(0)
    assert universe.getForkEndTime() == 0
    assert universe.getTypeName() == stringToBytes('Universe')
    assert universe.getForkEndTime() == 0
    assert universe.getChildUniverse("5") == longToHexString(0)
Exemplo n.º 21
0
def test_one_ask_on_books_buy_partial_order(contractsFixture, cash, market,
                                            universe):
    createOrder = contractsFixture.contracts['CreateOrder']
    trade = contractsFixture.contracts['Trade']
    fillOrder = contractsFixture.contracts['FillOrder']
    orders = contractsFixture.contracts['Orders']
    tradeGroupID = "42"
    logs = []

    # create order
    orderID = createOrder.publicCreateOrder(ASK,
                                            fix(12),
                                            6000,
                                            market.address,
                                            YES,
                                            longTo32Bytes(0),
                                            longTo32Bytes(0),
                                            tradeGroupID,
                                            sender=tester.k1,
                                            value=fix('12', '4000'))

    # fill best order
    captureFilteredLogs(contractsFixture.chain.head_state, orders, logs)
    captureFilteredLogs(contractsFixture.chain.head_state,
                        contractsFixture.contracts['Augur'], logs)
    fillOrderID = trade.publicBuy(market.address,
                                  YES,
                                  fix(7),
                                  6000,
                                  tradeGroupID,
                                  sender=tester.k2,
                                  value=fix('7', '6000'))

    assert len(logs) == 5
    log1 = logs[4]

    assert log1["_event_type"] == "OrderFilled"
    assert log1["filler"] == bytesToHexString(tester.a2)
    assert log1["numCreatorShares"] == 0
    assert log1["numCreatorTokens"] == fix('7', '4000')
    assert log1["numFillerShares"] == 0
    assert log1["numFillerTokens"] == fix('7', '6000')
    assert log1["marketCreatorFees"] == 0
    assert log1["reporterFees"] == 0
    assert log1["shareToken"] == market.getShareToken(YES)
    assert log1["tradeGroupId"] == stringToBytes("42")

    assert orders.getAmount(orderID) == fix(5)
    assert orders.getPrice(orderID) == 6000
    assert orders.getOrderCreator(orderID) == bytesToHexString(tester.a1)
    assert orders.getOrderMoneyEscrowed(orderID) == fix('5', '4000')
    assert orders.getOrderSharesEscrowed(orderID) == 0
    assert orders.getBetterOrderId(orderID) == longTo32Bytes(0)
    assert orders.getWorseOrderId(orderID) == longTo32Bytes(0)

    assert fillOrderID == longTo32Bytes(1)
Exemplo n.º 22
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()
Exemplo n.º 23
0
def test_trade_with_self(contractsFixture, cash, market, universe):
    createOrder = contractsFixture.contracts['CreateOrder']
    trade = contractsFixture.contracts['Trade']
    fillOrder = contractsFixture.contracts['FillOrder']
    orders = contractsFixture.contracts['Orders']
    tradeGroupID = longTo32Bytes(42)

    orderID = None
    # create order
    with BuyWithCash(cash, fix('4', '6000'), tester.k1, "create order"):
        orderID = createOrder.publicCreateOrder(BID, fix(4), 6000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, False, nullAddress, sender = tester.k1)

    # fill best order
    orderFilledLog = {
        "filler": bytesToHexString(tester.a1),
        "marketCreatorFees": 0,
        "reporterFees": 0,
        "tradeGroupId": stringToBytes(longTo32Bytes(42)),
    }
    orderCreatedLog = {
        "creator": bytesToHexString(tester.a1),
        "tradeGroupId": stringToBytes(longTo32Bytes(42)),
    }
    with BuyWithCash(cash, fix('5', '4000'), tester.k1, "trade"):
        with AssertLog(contractsFixture, "OrderFilled", orderFilledLog):
            with AssertLog(contractsFixture, "OrderCreated", orderCreatedLog):
                fillOrderID = trade.publicTrade(SHORT,market.address, YES, fix(5), 6000, "0", "0", tradeGroupID, 6, False, nullAddress, nullAddress, sender = tester.k1)

    assert orders.getAmount(orderID) == 0
    assert orders.getPrice(orderID) == 0
    assert orders.getOrderCreator(orderID) == longToHexString(0)
    assert orders.getOrderMoneyEscrowed(orderID) == 0
    assert orders.getOrderSharesEscrowed(orderID) == 0
    assert orders.getBetterOrderId(orderID) == longTo32Bytes(0)
    assert orders.getWorseOrderId(orderID) == longTo32Bytes(0)

    assert orders.getAmount(fillOrderID) == fix(1)
    assert orders.getPrice(fillOrderID) == 6000
    assert orders.getOrderCreator(fillOrderID) == bytesToHexString(tester.a1)
    assert orders.getOrderMoneyEscrowed(fillOrderID) == fix(1, 4000)
    assert orders.getOrderSharesEscrowed(fillOrderID) == 0
    assert orders.getBetterOrderId(fillOrderID) == longTo32Bytes(0)
    assert orders.getWorseOrderId(fillOrderID) == longTo32Bytes(0)
Exemplo n.º 24
0
def test_logs(localFixture, augur):
    RegisterContractLog = {
        "contractAddress": augur.address,
        "key": stringToBytes("Testing")
    }
    with AssertLog(localFixture, "RegisterContract", RegisterContractLog):
        augur.registerContract("Testing", augur.address)

    with AssertLog(localFixture, "FinishDeployment", {}):
        augur.finishDeployment()
Exemplo n.º 25
0
def test_delegationExternalContractCalls(localFixture):
    clone = localFixture.contracts['Clone']
    cloneTarget = localFixture.contracts['DelegatorHelper']

    # We can make external calls in a function of a delegated contract and recieve back values correctly
    assert clone.setOtherContract(cloneTarget.address)
    assert clone.getOtherName() == stringToBytes("Name")

    assert clone.addToOtherMap(1, 2)
    assert clone.getOtherMapValue(1) == 2
Exemplo n.º 26
0
def test_publicFillOrder_bid(contractsFixture, cash, market, universe):
    createOrder = contractsFixture.contracts['CreateOrder']
    fillOrder = contractsFixture.contracts['FillOrder']
    orders = contractsFixture.contracts['Orders']
    tradeGroupID = "42"

    initialMakerETH = contractsFixture.chain.head_state.get_balance(tester.a1)
    initialFillerETH = contractsFixture.chain.head_state.get_balance(tester.a2)
    creatorCost = fix('2', '6000')
    fillerCost = fix('2', '4000')

    # create order
    orderID = createOrder.publicCreateOrder(BID,
                                            fix(2),
                                            6000,
                                            market.address,
                                            YES,
                                            longTo32Bytes(0),
                                            longTo32Bytes(0),
                                            tradeGroupID,
                                            sender=tester.k1,
                                            value=creatorCost)

    # fill best order
    orderFilledLog = {
        "filler": bytesToHexString(tester.a2),
        "numCreatorShares": 0,
        "numCreatorTokens": creatorCost,
        "numFillerShares": 0,
        "numFillerTokens": fillerCost,
        "marketCreatorFees": 0,
        "reporterFees": 0,
        "shareToken": market.getShareToken(YES),
        "tradeGroupId": stringToBytes("42"),
        "amountFilled": fix(2),
    }
    with AssertLog(contractsFixture, "OrderFilled", orderFilledLog):
        fillOrderID = fillOrder.publicFillOrder(orderID,
                                                fix(2),
                                                tradeGroupID,
                                                sender=tester.k2,
                                                value=fillerCost)
        assert fillOrderID == 0

    assert contractsFixture.chain.head_state.get_balance(
        tester.a1) == initialMakerETH - creatorCost
    assert contractsFixture.chain.head_state.get_balance(
        tester.a2) == initialFillerETH - fillerCost
    assert orders.getAmount(orderID) == 0
    assert orders.getPrice(orderID) == 0
    assert orders.getOrderCreator(orderID) == longToHexString(0)
    assert orders.getOrderMoneyEscrowed(orderID) == 0
    assert orders.getOrderSharesEscrowed(orderID) == 0
    assert orders.getBetterOrderId(orderID) == longTo32Bytes(0)
    assert orders.getWorseOrderId(orderID) == longTo32Bytes(0)
Exemplo n.º 27
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    augur = fixture.contracts['Augur']
    mockCash = fixture.contracts['MockCash']
    mockAugur = fixture.contracts['MockAugur']
    mockReputationToken = fixture.contracts['MockReputationToken']
    augur.registerContract(stringToBytes('Cash'), mockCash.address)
    augur.registerContract(stringToBytes('Augur'), mockAugur.address)
    disputeWindow = fixture.upload('../source/contracts/reporting/DisputeWindow.sol', 'disputeWindow')
    fixture.contracts["initializedDisputeWindow"] = disputeWindow

    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(disputeWindowId)
    disputeWindow.initialize(mockUniverse.address, disputeWindowId)
    return fixture.createSnapshot()
Exemplo n.º 28
0
def test_reputation_token_creation(localFixture, mockUniverse):
    reputationToken = localFixture.upload(
        '../source/contracts/reporting/ReputationToken.sol',
        'reputationToken',
        constructorArgs=[
            localFixture.contracts['Augur'].address, mockUniverse.address,
            mockUniverse.address
        ])

    assert reputationToken.getTypeName() == stringToBytes('ReputationToken')
    assert reputationToken.getUniverse() == mockUniverse.address
Exemplo n.º 29
0
def test_delegationExternalContractCalls(localFixture):

    delegatorHelperTarget = localFixture.contracts['DelegatorHelperTarget']
    delegatorHelper = localFixture.contracts['DelegatorHelper']

    # We can make external calls in a function of a delegated contract and recieve back values correctly
    assert delegatorHelper.setOtherContract(delegatorHelperTarget.address)
    assert delegatorHelper.getOtherName() == stringToBytes("Name")

    assert delegatorHelper.addToOtherMap(1, 2)
    assert delegatorHelper.getOtherMapValue(1) == 2
Exemplo n.º 30
0
def test_universe_rep_price_oracle(localFixture, populatedUniverse, mockReputationToken, mockShareToken, mockStakeToken):
    controller = localFixture.contracts['Controller']
    repPriceOracle = localFixture.uploadAndAddToController("../source/contracts/reporting/RepPriceOracle.sol", 'repPriceOracle')
    controller.registerContract(stringToBytes('RepPriceOracle'), repPriceOracle.address, twentyZeros, thirtyTwoZeros)
    mockReputationToken.setTotalSupply(0)
    assert populatedUniverse.getRepMarketCapInAttoeth() == 0
    mockReputationToken.setTotalSupply(1)
    repPriceOracle.setRepPriceInAttoEth(100)
    assert populatedUniverse.getRepMarketCapInAttoeth() == 100
    mockReputationToken.setTotalSupply(12)
    assert populatedUniverse.getRepMarketCapInAttoeth() == 1200
Exemplo n.º 31
0
def mockMarket(localFixture, mockUniverse):
    # wire up mock market
    mockMarket = localFixture.contracts['MockMarket']
    mockMarket.setDesignatedReporter(bytesToHexString(tester.a0))
    mockMarket.setUniverse(mockUniverse.address)
    mockMarket.setIsContainerForStakeToken(True)
    mockMarket.setMigrateDueToNoReports(True)
    mockMarket.setMigrateDueToNoReportsNextState(localFixture.contracts['Constants'].FIRST_REPORTING())
    mockMarket.setFirstReporterCompensationCheck(0)
    mockMarket.setDerivePayoutDistributionHash(stringToBytes("1"))
    mockMarket.setTotalWinningDisputeBondStake(100)
    return mockMarket
Exemplo n.º 32
0
def test_market_hot_loading_basic(kitchenSinkFixture, augur, cash, market,
                                  categoricalMarket, scalarMarket):
    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 the market hot load data
    marketData = getMarketData(hotLoading, augur, market, fillOrder, orders)

    assert marketData.extraInfo == '{description: "description", categories: ["", "", ""]}'
    assert marketData.marketCreator == account
    assert marketData.owner == account
    assert marketData.outcomes == []
    assert marketData.marketType == 0  # YES_NO
    assert marketData.displayPrices == []
    assert marketData.designatedReporter == account
    assert marketData.reportingState == 0  # PRE_REPORTING
    assert marketData.disputeRound == 0
    assert marketData.winningPayout == []
    assert marketData.volume == 0
    assert marketData.openInterest == 0
    assert marketData.lastTradedPrices == [0, 0, 0]
    assert marketData.universe == market.getUniverse()
    assert marketData.numTicks == market.getNumTicks()
    assert marketData.feeDivisor == market.getMarketCreatorSettlementFeeDivisor(
    )
    assert marketData.affiliateFeeDivisor == market.affiliateFeeDivisor()
    assert marketData.endTime == market.getEndTime()
    assert marketData.numOutcomes == 3
    universeContract = kitchenSinkFixture.applySignature(
        "Universe", marketData.universe)
    assert marketData.validityBond == universeContract.getOrCacheValidityBond()
    assert marketData.reportingFeeDivisor == universeContract.getReportingFeeDivisor(
    )

    # Try the other markets
    marketData = getMarketData(hotLoading, augur, categoricalMarket, fillOrder,
                               orders)
    assert marketData.marketType == 1  # CATEGORICAL
    assert marketData.numOutcomes == 4
    outcomeLabel = stringToBytes(" ")
    assert marketData.outcomes == [outcomeLabel, outcomeLabel, outcomeLabel]

    marketData = getMarketData(hotLoading, augur, scalarMarket, fillOrder,
                               orders)
    assert marketData.marketType == 2  # SCALAR
    assert marketData.numTicks == 400000
    assert marketData.displayPrices == [-10 * 10**18, 30 * 10**18]
Exemplo n.º 33
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()
Exemplo n.º 34
0
def test_universe_creation(localFixture, mockReputationToken,
                           mockReputationTokenFactory, mockUniverse,
                           mockUniverseFactory, mockAugur):
    mockReputationTokenFactory.set_mock_createReputationToken_0_address_address_address(
        mockReputationToken.address)

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

    assert universe.getReputationToken() == mockReputationToken.address
    assert universe.getParentUniverse() == mockUniverse.address
    assert universe.getParentPayoutDistributionHash() == stringToBytes("5")
    assert universe.getForkingMarket() == longToHexString(0)
    assert universe.getForkEndTime() == 0
    assert universe.getTypeName() == stringToBytes('Universe')
    assert universe.getForkEndTime() == 0
    assert universe.getChildUniverse("5") == longToHexString(0)
Exemplo n.º 35
0
def test_real_time(localFixture, controller):
    # Let's test a real Time provider implementation
    time = localFixture.uploadAndAddToController("../source/contracts/Time.sol", lookupKey="RealTime")

    # We can verify that it is the controller version of time
    assert controller.lookup("RealTime") == time.address

    assert time.getTypeName() == stringToBytes("Time")

    # If we change the block timestamp it will be reflected in the new time
    localFixture.chain.head_state.timestamp = 500

    assert time.getTimestamp() == 500
Exemplo n.º 36
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()
Exemplo n.º 37
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()
Exemplo n.º 38
0
def test_universe_rep_price_oracle(localFixture, populatedUniverse, mockReputationToken, mockShareToken):
    controller = localFixture.contracts['Controller']
    repPriceOracle = localFixture.uploadAndAddToController("../source/contracts/reporting/RepPriceOracle.sol", 'repPriceOracle')
    controller.registerContract(stringToBytes('RepPriceOracle'), repPriceOracle.address, twentyZeros, thirtyTwoZeros)
    mockReputationToken.setTotalSupply(0)
    assert populatedUniverse.getRepMarketCapInAttoeth() == 0
    mockReputationToken.setTotalSupply(1)
    assert repPriceOracle.setRepPriceInAttoEth(100)
    assert populatedUniverse.getRepMarketCapInAttoeth() == 100
    mockReputationToken.setTotalSupply(12)
    assert populatedUniverse.getRepMarketCapInAttoeth() == 1200
    assert repPriceOracle.transferOwnership(tester.a1)
    assert repPriceOracle.getOwner() == bytesToHexString(tester.a1)
Exemplo n.º 39
0
def test_real_time(localFixture, augur):
    # Let's test a real Time provider implementation
    time = localFixture.uploadAndAddToAugur("../source/contracts/Time.sol", lookupKey="RealTime")

    # We can verify that it is the augur version of time
    assert augur.lookup("RealTime") == time.address

    assert time.getTypeName() == stringToBytes("Time")

    # If we change the block timestamp it will be reflected in the new time
    localFixture.chain.head_state.timestamp = 500

    assert time.getTimestamp() == 500
Exemplo n.º 40
0
def test_universe_fork_market(localFixture, populatedUniverse, mockUniverse, mockUniverseFactory, mockMarket, mockReportingWindow, chain, mockReportingWindowFactory, mockAugur):
    with raises(TransactionFailed, message="must be called from market"):
        populatedUniverse.fork()

    with raises(TransactionFailed, message="forking market has to be in universe"):
        mockMarket.callForkOnUniverse(populatedUniverse.address)

    timestamp = chain.head_state.timestamp
    mockReportingWindowFactory.setCreateReportingWindowValue(mockReportingWindow.address)
    reportingWindowId = populatedUniverse.getReportingWindowByTimestamp(timestamp)
    mockReportingWindow.setStartTime(timestamp)

    mockReportingWindow.setIsContainerForMarket(True)
    mockMarket.setReportingWindow(mockReportingWindow.address)
    assert populatedUniverse.getForkingMarket() == longToHexString(0)
    assert populatedUniverse.isContainerForMarket(mockMarket.address)

    assert mockMarket.callForkOnUniverse(populatedUniverse.address)
    assert mockAugur.logUniverseForkedCalled() == True
    assert populatedUniverse.getForkingMarket() == mockMarket.address
    assert populatedUniverse.getForkEndTime() == timestamp + localFixture.contracts['Constants'].FORK_DURATION_SECONDS()

    # child universe
    mockUniverseFactory.setCreateUniverseUniverseValue(mockUniverse.address)
    mockUniverse.setParentPayoutDistributionHash(stringToBytes("101"))
    assert populatedUniverse.getOrCreateChildUniverse(stringToBytes("101")) == mockUniverse.address
    assert mockAugur.logUniverseCreatedCalled() == True
    assert mockUniverseFactory.getCreateUniverseParentUniverseValue() == populatedUniverse.address
    assert mockUniverseFactory.getCreateUniverseParentPayoutDistributionHashValue() == stringToBytes("101")
    assert populatedUniverse.getChildUniverse(stringToBytes("101")) == mockUniverse.address
    assert populatedUniverse.isParentOf(mockUniverse.address)
    strangerUniverse = localFixture.upload('../source/contracts/reporting/Universe.sol', 'strangerUniverse')
    assert populatedUniverse.isParentOf(strangerUniverse.address) == False

    assert populatedUniverse.getReportingWindowForForkEndTime() == mockReportingWindow.address

    with raises(TransactionFailed, message="forking market is already set"):
        mockMarket.callForkOnUniverse()
Exemplo n.º 41
0
def test_one_bid_on_books_buy_full_order(contractsFixture, cash, market,
                                         universe):
    createOrder = contractsFixture.contracts['CreateOrder']
    trade = contractsFixture.contracts['Trade']
    fillOrder = contractsFixture.contracts['FillOrder']
    orders = contractsFixture.contracts['Orders']
    tradeGroupID = "42"

    # create order
    orderID = createOrder.publicCreateOrder(BID,
                                            fix(2),
                                            6000,
                                            market.address,
                                            YES,
                                            longTo32Bytes(0),
                                            longTo32Bytes(0),
                                            tradeGroupID,
                                            sender=tester.k1,
                                            value=fix('2', '6000'))

    # fill best order
    orderFilledLog = {
        "filler": bytesToHexString(tester.a2),
        "numCreatorShares": 0,
        "numCreatorTokens": fix('2', '6000'),
        "numFillerShares": 0,
        "numFillerTokens": fix('2', '4000'),
        "marketCreatorFees": 0,
        "reporterFees": 0,
        "shareToken": market.getShareToken(YES),
        "tradeGroupId": stringToBytes("42"),
    }
    with AssertLog(contractsFixture, "OrderFilled", orderFilledLog):
        assert trade.publicSell(market.address,
                                YES,
                                fix(2),
                                6000,
                                "0",
                                "0",
                                tradeGroupID,
                                sender=tester.k2,
                                value=fix('2', '4000'))

    assert orders.getAmount(orderID) == 0
    assert orders.getPrice(orderID) == 0
    assert orders.getOrderCreator(orderID) == longToHexString(0)
    assert orders.getOrderMoneyEscrowed(orderID) == 0
    assert orders.getOrderSharesEscrowed(orderID) == 0
    assert orders.getBetterOrderId(orderID) == longTo32Bytes(0)
    assert orders.getWorseOrderId(orderID) == longTo32Bytes(0)
Exemplo n.º 42
0
def test_delegationTargetInitialMemberValues(localFixture):

    delegatorHelperTarget = localFixture.contracts['DelegatorHelperTarget']
    delegatorHelper = localFixture.contracts['DelegatorHelper']

    # Members set at declaration time on the delegation target are not set/retreivable on the delegator unless declared constant
    assert delegatorHelperTarget.intValue() == -42
    assert delegatorHelper.intValue() == 0
    assert delegatorHelperTarget.name() == stringToBytes("Name")
    assert delegatorHelper.name() == stringToBytes("")
    assert delegatorHelper.constantName() == stringToBytes("ConstantName")
    assert delegatorHelper.constantName(
    ) == delegatorHelperTarget.constantName()

    # Constant string values however are not retrievable. In fact, string values will not work at all with delegated contract storage. See: https://github.com/ethereum/solidity/issues/164#issuecomment-149846605
    assert delegatorHelperTarget.stringMember() == "StringMember"
    assert delegatorHelperTarget.stringConstant() == "StringConstant"
    assert delegatorHelper.stringMember() == ""
    assert delegatorHelper.stringConstant() == ""
    assert delegatorHelper.setStringMember("StringValue")
    assert delegatorHelper.stringMember() == ""
    assert delegatorHelper.getStringMember() == ""

    # Note that even if we do not attempt to pass in the string value and let the contract set the value itself we will not be able to retrieve the value
    assert delegatorHelper.populateStringMember()
    assert delegatorHelper.getStringMember() == ""

    # Once a non-string member is explicitly set on the delegator it will have the newly provided value
    assert delegatorHelper.setName("NewName")
    assert delegatorHelper.getName() == stringToBytes("NewName")
    assert delegatorHelper.name() == stringToBytes("NewName")
    assert delegatorHelper.name() != delegatorHelperTarget.name()

    assert delegatorHelper.setIntValue(1)
    assert delegatorHelper.getIntValue() == 1
    assert delegatorHelper.intValue() == 1
    assert delegatorHelper.intValue() != delegatorHelperTarget.intValue()
Exemplo n.º 43
0
def localSnapshot(fixture, augurInitializedWithMocksSnapshot):
    fixture.resetToSnapshot(augurInitializedWithMocksSnapshot)
    controller = fixture.contracts['Controller']
    mockTestNetDenominationToken = fixture.contracts[
        'MockTestNetDenominationToken']
    mockAugurLite = fixture.contracts['MockAugurLite']
    mockShareTokenFactory = fixture.contracts['MockShareTokenFactory']
    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('MockTestNetDenominationToken'),
                                mockTestNetDenominationToken.address,
                                twentyZeros, thirtyTwoZeros)
    controller.registerContract(stringToBytes('ShareTokenFactory'),
                                mockShareTokenFactory.address, twentyZeros,
                                thirtyTwoZeros)
    mockShareTokenFactory.resetCreateShareToken()

    mockUniverse = fixture.contracts['MockUniverse']
    mockUniverse.setDenominationToken(mockTestNetDenominationToken.address)

    market = fixture.upload('../source/contracts/Market.sol', 'market')
    fixture.contracts["initializedMarket"] = market
    endTime = fixture.contracts["Time"].getTimestamp() + 259200
    market.setController(fixture.contracts["Controller"].address)

    assert market.initialize(mockUniverse.address, endTime, 16,
                             mockTestNetDenominationToken.address, tester.a1,
                             tester.a2, 5, numTicks)

    return fixture.createSnapshot()
Exemplo n.º 44
0
def on_new_client(conn, addr):
    i = 0
    num_iters = 3  # int(input("Enter the number of iterations."))
    json_msg = {"quit": False}
    json_msg["gen"] = True
    json_msg["seed"] = random.randint(0, 100000)
    json_msg["iter"] = 0
    json_msg["weights"] = None
    message = json.dumps(json_msg)
    conn.send(utils.stringToBytes(message))
    data = ""
    while True:
        raw = conn.recv(2048)
        data += utils.stringFromBytes(raw)
        if data != None and data != "":
            if data[-1] == "}":
                if True:  # later: if have x% of clients
                    i += 1
                client_data = json.loads(data)
                data = ""
                display = client_data.copy()
                display["weights"] = "weights"
                print("Server received data:", display)
                json_msg = {"quit": False}
                json_msg["gen"] = True
                json_msg["seed"] = random.randint(0, 100000)
                json_msg["iter"] = i
                fitnesses.append(client_data["fitness"])
                best_weights = client_data["weights"]
                json_msg["weights"] = best_weights
                if i > num_iters:
                    json_msg["quit"] = True
                message = json.dumps(json_msg)

                conn.send(utils.stringToBytes(message))
                if i > num_iters:
                    break
Exemplo n.º 45
0
def test_ask_withPartialShares(contractsFixture, universe, cash, market):
    orders = contractsFixture.contracts['Orders']
    createOrder = contractsFixture.contracts['CreateOrder']
    completeSets = contractsFixture.contracts['CompleteSets']
    yesShareToken = contractsFixture.applySignature('ShareToken',
                                                    market.getShareToken(YES))
    noShareToken = contractsFixture.applySignature('ShareToken',
                                                   market.getShareToken(NO))

    # buy fix(2) complete sets
    with BuyWithCash(cash, fix(2, market.getNumTicks()), tester.k1,
                     "buy complete set"):
        assert completeSets.publicBuyCompleteSets(market.address,
                                                  fix(2),
                                                  sender=tester.k1)
    assert cash.balanceOf(tester.a1) == fix('0')
    assert yesShareToken.balanceOf(tester.a1) == fix(2)
    assert noShareToken.balanceOf(tester.a1) == fix(2)

    orderID = None

    orderCreatedLog = {
        'creator': bytesToHexString(tester.a1),
        'tradeGroupId': stringToBytes(longTo32Bytes(42)),
    }
    with BuyWithCash(cash, fix('6000'), tester.k1, "buy complete set"):
        with AssertLog(contractsFixture, "OrderCreated", orderCreatedLog):
            orderID = createOrder.publicCreateOrder(ASK,
                                                    fix(3),
                                                    4000,
                                                    market.address,
                                                    YES,
                                                    longTo32Bytes(0),
                                                    longTo32Bytes(0),
                                                    longTo32Bytes(42),
                                                    False,
                                                    nullAddress,
                                                    sender=tester.k1)
    assert cash.balanceOf(tester.a1) == fix('0')
    assert yesShareToken.balanceOf(tester.a1) == 0
    assert noShareToken.balanceOf(tester.a1) == fix(2)

    # validate the order contains expected results
    assert orderID != bytearray(32), "Order ID should be non-zero"
    assert orders.getAmount(orderID) == fix(3)
    assert orders.getPrice(orderID) == 4000
    assert orders.getOrderCreator(orderID) == bytesToHexString(tester.a1)
    assert orders.getOrderMoneyEscrowed(orderID) == fix('6000')
    assert orders.getOrderSharesEscrowed(orderID) == fix(2)
Exemplo n.º 46
0
def test_reporting_window_update_fin_market_calculations(localFixture, mockMarket, populatedReportingWindow):
    mockMarket.setFinalPayoutDistributionHash(stringToBytes("101"))
    mockMarket.setDesignatedReportPayoutHash(stringToBytes("10"))
    mockMarket.setIsValid(True)
    finializeMarket(localFixture, mockMarket, populatedReportingWindow, 99, 15)
    # 99 + 15
    assert populatedReportingWindow.getTotalWinningStake() == 114
    assert populatedReportingWindow.getNumIncorrectDesignatedReportMarkets() == 1

    # add new market to finialize
    parentUniverse = localFixture.upload('solidity_test_helpers/MockUniverse.sol', 'parentUniverse')
    parentUniverse.setIsContainerForReportingWindow(True)
    newMockMarket = localFixture.upload('solidity_test_helpers/MockMarket.sol', 'newMockMarket')
    newMockMarket.setUniverse(parentUniverse.address)
    newWindow = localFixture.upload('solidity_test_helpers/MockReportingWindow.sol', 'newWindow')
    newWindow.setIsContainerForMarket(True)
    newMockMarket.setFinalPayoutDistributionHash(stringToBytes("101"))
    newMockMarket.setDesignatedReportPayoutHash(stringToBytes("10"))
    newMockMarket.setReportingWindow(newWindow.address)
    assert newMockMarket.callReportingWindowMigrateMarketInFromSibling(populatedReportingWindow.address)
    finializeMarket(localFixture, newMockMarket, populatedReportingWindow, 19, 12)
    # 19 + 12 + existing 114  = 114 + 31 = 145
    assert populatedReportingWindow.getTotalWinningStake() == 145
    assert populatedReportingWindow.getNumIncorrectDesignatedReportMarkets() == 2
Exemplo n.º 47
0
def test_stake_token_getters(localFixture, mockMarket, mockUniverse, mockReportingWindow, mockReputationToken):
    numTicks = 3 * 10 ** 17
    stakeToken = localFixture.upload('../source/contracts/reporting/StakeToken.sol', 'stakeToken')
    stakeToken.setController(localFixture.contracts["Controller"].address)
    mockMarket.setNumTicks(numTicks)
    mockMarket.setNumberOfOutcomes(3)

    assert stakeToken.initialize(mockMarket.address, [0, 1, numTicks - 1], False)
    assert stakeToken.getTypeName() == stringToBytes("StakeToken")
    assert stakeToken.getUniverse() == mockUniverse.address
    assert stakeToken.getMarket() == mockMarket.address
    assert stakeToken.getPayoutDistributionHash() == mockMarket.derivePayoutDistributionHash([0, 1, numTicks - 1], False)
    assert stakeToken.getReportingWindow() == mockMarket.getReportingWindow()
    assert stakeToken.getReputationToken() == mockReportingWindow.getReputationToken()
    assert stakeToken.isValid()
Exemplo n.º 48
0
def test_stake_token_buy_designated_reporter_state(localFixture, mockMarket, mockUniverse, mockReputationToken, mockReportingWindow):
    numTicks = 3 * 10 ** 17
    mockMarket.setNumTicks(numTicks)
    mockMarket.setNumberOfOutcomes(3)
    mockMarket.setIsContainerForStakeToken(True)
    mockMarket.setDerivePayoutDistributionHash(stringToBytes("1"))
    mockMarket.setDesignatedReport(True)
    mockReportingWindow.setNoteReportingGasPrice(True)

    stakeToken = localFixture.upload('../source/contracts/reporting/StakeToken.sol', 'stakeToken')
    stakeToken.setController(localFixture.contracts["Controller"].address)
    assert stakeToken.initialize(mockMarket.address, [numTicks/3, numTicks/3, numTicks/3], False)
    designatedReporterStake = 100
    mockUniverse.setDesignatedReportStake(designatedReporterStake)

    mockMarket.setReportingState(localFixture.contracts['Constants'].DESIGNATED_REPORTING())
    with raises(TransactionFailed, message="Designated reporter needs to buy DESIGNATED REPORTER bond not more"):
        stakeToken.buy(designatedReporterStake + 1)

    mockMarket.setReportingState(localFixture.contracts['Constants'].DESIGNATED_REPORTING())
    with raises(TransactionFailed, message="Designated reporter needs to buy DESIGNATED REPORTER bond not less"):
        stakeToken.buy(designatedReporterStake - 1)

    mockMarket.setReportingState(localFixture.contracts['Constants'].DESIGNATED_REPORTING())
    with raises(TransactionFailed, message="Only Designated reporter can buy stake during designated reporting window"):
        stakeToken.buy(designatedReporterStake, sender=tester.k8)

    mockMarket.setReportingState(localFixture.contracts['Constants'].DESIGNATED_REPORTING())
    mockUniverse.setIsContainerForStakeToken(True)
    assert stakeToken.buy(designatedReporterStake)

    # call tests
    assert mockMarket.getUpdateDerivePayoutDistributionHashValue() == stringToBytes("1")
    assert mockReputationToken.getTrustedTransferSourceValue() == bytesToHexString(tester.a0)
    assert mockReputationToken.getTrustedTransferDestinationValue() == stakeToken.address
    assert mockReputationToken.getTrustedTransferAttotokensValue() == designatedReporterStake
Exemplo n.º 49
0
def test_fee_window_creation(localFixture, initializedFeeWindow, mockReputationToken, mockUniverse, constants, mockFeeToken, mockFeeTokenFactory, Time):
    assert initializedFeeWindow.getTypeName() == stringToBytes("FeeWindow")
    assert initializedFeeWindow.getReputationToken() == mockReputationToken.address
    assert initializedFeeWindow.getStartTime() == feeWindowId * mockUniverse.getDisputeRoundDurationInSeconds()
    assert initializedFeeWindow.getUniverse() == mockUniverse.address
    assert initializedFeeWindow.getEndTime() == feeWindowId * mockUniverse.getDisputeRoundDurationInSeconds() + constants.DISPUTE_ROUND_DURATION_SECONDS()
    assert initializedFeeWindow.getFeeToken() == mockFeeToken.address
    assert initializedFeeWindow.getNumInvalidMarkets() == 0
    assert initializedFeeWindow.getNumIncorrectDesignatedReportMarkets() == 0
    assert initializedFeeWindow.getNumDesignatedReportNoShows() == 0
    assert initializedFeeWindow.isActive() == False
    assert initializedFeeWindow.isOver() == False
    assert mockFeeTokenFactory.getCreateFeeTokenFeeWindowValue() == initializedFeeWindow.address
    Time.setTimestamp(feeWindowId * mockUniverse.getDisputeRoundDurationInSeconds() + 1)
    assert initializedFeeWindow.isActive() == True
    Time.setTimestamp(feeWindowId * mockUniverse.getDisputeRoundDurationInSeconds() + constants.DISPUTE_ROUND_DURATION_SECONDS())
    assert initializedFeeWindow.isActive() == False
    assert initializedFeeWindow.isOver() == True
Exemplo n.º 50
0
def test_publicFillOrder_bid(contractsFixture, cash, market, universe):
    createOrder = contractsFixture.contracts['CreateOrder']
    fillOrder = contractsFixture.contracts['FillOrder']
    orders = contractsFixture.contracts['Orders']
    tradeGroupID = "42"

    initialMakerETH = contractsFixture.chain.head_state.get_balance(tester.a1)
    initialFillerETH = contractsFixture.chain.head_state.get_balance(tester.a2)
    creatorCost = fix('2', '6000')
    fillerCost = fix('2', '4000')

    # create order
    orderID = createOrder.publicCreateOrder(BID, fix(2), 6000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, sender = tester.k1, value=creatorCost)

    # fill best order
    orderFilledLog = {
        "filler": bytesToHexString(tester.a2),
        "numCreatorShares": 0,
        "numCreatorTokens": creatorCost,
        "numFillerShares": 0,
        "numFillerTokens": fillerCost,
        "marketCreatorFees": 0,
        "reporterFees": 0,
        "shareToken": market.getShareToken(YES),
        "tradeGroupId": stringToBytes("42"),
        "amountFilled": fix(2),
    }
    with AssertLog(contractsFixture, "OrderFilled", orderFilledLog):
        fillOrderID = fillOrder.publicFillOrder(orderID, fix(2), tradeGroupID, sender = tester.k2, value=fillerCost)
        assert fillOrderID == 0

    assert contractsFixture.chain.head_state.get_balance(tester.a1) == initialMakerETH - creatorCost
    assert contractsFixture.chain.head_state.get_balance(tester.a2) == initialFillerETH - fillerCost
    assert orders.getAmount(orderID) == 0
    assert orders.getPrice(orderID) == 0
    assert orders.getOrderCreator(orderID) == longToHexString(0)
    assert orders.getOrderMoneyEscrowed(orderID) == 0
    assert orders.getOrderSharesEscrowed(orderID) == 0
    assert orders.getBetterOrderId(orderID) == longTo32Bytes(0)
    assert orders.getWorseOrderId(orderID) == longTo32Bytes(0)
Exemplo n.º 51
0
def test_market_creation(contractsFixture, universe, cash, market):
    numTicks = market.getNumTicks()

    market = None

    marketCreatedLog = {
        "extraInfo": 'so extra',
        "marketCreationFee": universe.getOrCacheMarketCreationCost(),
        "marketCreator": bytesToHexString(tester.a0),
    }
    with AssertLog(contractsFixture, "MarketCreated", marketCreatedLog):
        market = contractsFixture.createReasonableBinaryMarket(universe, cash, extraInfo="so extra")

    assert market.getUniverse() == universe.address
    assert market.getNumberOfOutcomes() == 2
    assert numTicks == 10000
    assert market.getReputationToken() == universe.getReputationToken()
    assert market.getWinningPayoutDistributionHash() == stringToBytes("")
    assert market.getInitialized()

    with raises(TransactionFailed, message="Cannot create a market with an end date in the past"):
        contractsFixture.createBinaryMarket(universe, 0, 1, cash, tester.a0)
Exemplo n.º 52
0
def test_default_controlled_time(localFixture, controller, time):
    # By default in testing we upload a controlled version of time to the controller which we control
    assert time.getTimestamp() == controller.getTimestamp() > 0

    # We can verify that it is the controller version of time
    assert controller.lookup("Time") == time.address

    assert time.getTypeName() == stringToBytes("TimeControlled")

    # The owner of the uploaded Time contract can change this time at will
    newTime = time.getTimestamp() + 1
    with AssertLog(localFixture, "TimestampSet", {"newTimestamp": newTime}):
        assert time.setTimestamp(newTime)
    assert time.getTimestamp() == controller.getTimestamp() == newTime

    # Other users cannot
    with raises(TransactionFailed):
        time.setTimestamp(newTime + 1, sender=tester.k1)

    # We can also increment the time
    with AssertLog(localFixture, "TimestampSet", {"newTimestamp": newTime + 1}):
        assert time.incrementTimestamp(1)
    assert time.getTimestamp() == controller.getTimestamp() == newTime + 1
Exemplo n.º 53
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()
Exemplo n.º 54
0
def test_init(cash):
    assert cash.name() == 'Cash'
    assert cash.decimals() == 18
    assert cash.symbol() == 'CASH'

    assert cash.getTypeName() == stringToBytes('Cash')
Exemplo n.º 55
0
def test_market_creation(localFixture, mockUniverse, mockFeeWindow, mockCash, chain, constants, mockMarket, mockReputationToken, mockShareToken, mockShareTokenFactory):
    fee = 16
    oneEther = 10 ** 18
    endTime = localFixture.contracts["Time"].getTimestamp() + constants.DESIGNATED_REPORTING_DURATION_SECONDS()
    market = localFixture.upload('../source/contracts/reporting/Market.sol', 'newMarket')
    market.setController(localFixture.contracts["Controller"].address)

    with raises(TransactionFailed, message="outcomes has to be greater than 1"):
        market.initialize(mockUniverse.address, endTime, fee, mockCash.address, tester.a1, tester.a1, 1, numTicks)

    with raises(TransactionFailed, message="outcomes has to be less than 9"):
        market.initialize(mockUniverse.address, endTime, fee, mockCash.address, tester.a1, tester.a1, 9, numTicks)

    with raises(TransactionFailed, message="numTicks needs to be divisable by outcomes"):
        market.initialize(mockUniverse.address, endTime, fee, mockCash.address, tester.a1, tester.a1, 7, numTicks)

    with raises(TransactionFailed, message="fee per eth can not be greater than max fee per eth in attoEth"):
        market.initialize(mockUniverse.address, endTime, oneEther / 2 + 1, mockCash.address, tester.a1, tester.a1, 5, numTicks)

    with raises(TransactionFailed, message="creator address can not be 0"):
        market.initialize(mockUniverse.address, endTime, fee, mockCash.address, longToHexString(0), tester.a1, 5, numTicks)

    with raises(TransactionFailed, message="designated reporter address can not be 0"):
        market.initialize(mockUniverse.address, endTime, fee, mockCash.address, tester.a1, longToHexString(0), 5, numTicks)

    mockUniverse.setForkingMarket(mockMarket.address)
    with raises(TransactionFailed, message="forking market address has to be 0"):
        market.initialize(mockUniverse.address, endTime, fee, mockCash.address, tester.a1, tester.a1, 5, numTicks)

    mockUniverse.setForkingMarket(longToHexString(0))
    mockReputationToken.setBalanceOf(0)
    mockUniverse.setOrCacheDesignatedReportNoShowBond(100)
    with raises(TransactionFailed, message="reporting window reputation token does not have enough balance"):
        market.initialize(mockUniverse.address, endTime, fee, mockCash.address, tester.a1, tester.a1, 5, numTicks)

    badCash = localFixture.upload('../source/contracts/trading/Cash.sol', 'uncontrolledCash')
    with raises(TransactionFailed, message="the denomination token must be a valid cash implementation"):
        market.initialize(mockUniverse.address, endTime, fee, badCash.address, tester.a1, tester.a1, 5, numTicks, value=100)

    mockReputationToken.setBalanceOf(100)
    mockUniverse.setOrCacheTargetReporterGasCosts(15)
    mockUniverse.setOrCacheValidityBond(12)
    with raises(TransactionFailed, message="refund is not over 0"):
        market.initialize(mockUniverse.address, endTime, fee, mockCash.address, tester.a1, tester.a1, 5, numTicks, value=0)

    mockShareTokenFactory.resetCreateShareToken()
    assert market.initialize(mockUniverse.address, endTime, fee, mockCash.address, tester.a1, tester.a1, 5, numTicks, value=100)
    assert mockShareTokenFactory.getCreateShareTokenMarketValue() == market.address
    assert mockShareTokenFactory.getCreateShareTokenOutcomeValue() == 5 - 1 # mock logs the last outcome
    assert market.getTypeName() == stringToBytes("Market")
    assert market.getUniverse() == mockUniverse.address
    assert market.getUniverse() == mockUniverse.address
    assert market.getDesignatedReporter() == bytesToHexString(tester.a1)
    assert market.getNumberOfOutcomes() == 5
    assert market.getEndTime() == endTime
    assert market.getNumTicks() == numTicks
    assert market.getDenominationToken() == mockCash.address
    assert market.getMarketCreatorSettlementFeeDivisor() == oneEther / 16
    assert mockShareTokenFactory.getCreateShareTokenCounter() == 5
    assert mockShareTokenFactory.getCreateShareToken(0) == market.getShareToken(0)
    assert mockShareTokenFactory.getCreateShareToken(1) == market.getShareToken(1)
    assert mockShareTokenFactory.getCreateShareToken(2) == market.getShareToken(2)
    assert mockShareTokenFactory.getCreateShareToken(3) == market.getShareToken(3)
    assert mockShareTokenFactory.getCreateShareToken(4) == market.getShareToken(4)
    assert mockUniverse.getOrCacheValidityBondWallCalled() == True
Exemplo n.º 56
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()
Exemplo n.º 57
0
 def createUniverse(self):
     universeAddress = self.contracts['Augur'].createGenesisUniverse()
     universe = self.applySignature('Universe', universeAddress)
     assert universe.getTypeName() == stringToBytes('Universe')
     return universe