def test_publicSellCompleteSets(contractsFixture, universe, cash, market): completeSets = contractsFixture.contracts['CompleteSets'] orders = contractsFixture.contracts['Orders'] yesShareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(YES)) noShareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(NO)) assert not cash.balanceOf(tester.a0) assert not cash.balanceOf(tester.a1) assert cash.balanceOf(market.address) == universe.getOrCacheValidityBond() assert not yesShareToken.totalSupply() assert not noShareToken.totalSupply() cost = 10 * market.getNumTicks() print cash.faucet(cost, sender=tester.k1) assert universe.getOpenInterestInAttoCash() == 0 completeSets.publicBuyCompleteSets(market.address, 10, sender=tester.k1) assert universe.getOpenInterestInAttoCash() == 10 * market.getNumTicks() initialTester1ETH = contractsFixture.chain.head_state.get_balance( tester.a1) initialTester0ETH = contractsFixture.chain.head_state.get_balance( tester.a0) completeSetsSoldLog = { "universe": universe.address, "market": market.address, "account": bytesToHexString(tester.a1), "numCompleteSets": 9, "marketOI": market.getNumTicks(), "fees": 9 + 9, } with AssertLog(contractsFixture, "CompleteSetsSold", completeSetsSoldLog): result = completeSets.publicSellCompleteSets(market.address, 9, sender=tester.k1) assert universe.getOpenInterestInAttoCash() == 1 * market.getNumTicks() assert yesShareToken.balanceOf( tester.a1) == 1, "Should have 1 share of outcome yes" assert noShareToken.balanceOf( tester.a1) == 1, "Should have 1 share of outcome no" assert yesShareToken.totalSupply() == 1 assert noShareToken.totalSupply() == 1 assert contractsFixture.chain.head_state.get_balance( tester.a1) == initialTester1ETH assert cash.balanceOf(tester.a1) == 882 assert cash.balanceOf( market.address) == universe.getOrCacheValidityBond() + 100 + 9 assert market.marketCreatorFeesAttoCash() == 9
def test_fee_window_logging(contractsFixture, market, categoricalMarket, scalarMarket, universe): feeWindow = contractsFixture.applySignature( 'FeeWindow', universe.getOrCreateCurrentFeeWindow()) contractsFixture.contracts["Time"].setTimestamp(feeWindow.getStartTime() + 1) assert feeWindow.buy(100) tokensTransferredLog = { 'from': bytesToHexString(tester.a0), 'to': bytesToHexString(tester.a1), 'token': feeWindow.address, 'universe': universe.address, 'tokenType': 3, 'value': 8 } with AssertLog(contractsFixture, "TokensTransferred", tokensTransferredLog): assert feeWindow.transfer(tester.a1, 8) assert feeWindow.approve(tester.a2, 12) tokensTransferredLog = { 'from': bytesToHexString(tester.a0), 'to': bytesToHexString(tester.a1), 'token': feeWindow.address, 'universe': universe.address, 'tokenType': 3, 'value': 12 } with AssertLog(contractsFixture, "TokensTransferred", tokensTransferredLog): assert feeWindow.transferFrom(tester.a0, tester.a1, 12, sender=tester.k2)
def test_approve(contractsFixture, market, cash): shareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(0)) completeSets = contractsFixture.contracts['CompleteSets'] with BuyWithCash(cash, 7 * market.getNumTicks(), tester.k0, "complete set buy"): completeSets.publicBuyCompleteSets(market.address, 7) assert(shareToken.allowance(tester.a0, tester.a1) == 0), "initial allowance is 0" approvalLog = { "owner": bytesToHexString(tester.a0), "spender": bytesToHexString(tester.a1), "value": 10 } with AssertLog(contractsFixture, "Approval", approvalLog, contract=shareToken): assert shareToken.approve(tester.a1, 10, sender=tester.k0) assert(shareToken.allowance(tester.a0, tester.a1) == 10), "allowance is 10 after approval" transferLog = { "from": bytesToHexString(tester.a0), "to": bytesToHexString(tester.a1), "value": 7 } tokensTransferredLog = { "token": shareToken.address, "from": bytesToHexString(tester.a0), "to": bytesToHexString(tester.a1), "universe": market.getUniverse(), "tokenType": 1, "market": market.address, "value": 7 } with AssertLog(contractsFixture, "Transfer", transferLog, contract=shareToken): with AssertLog(contractsFixture, "TokensTransferred", tokensTransferredLog): assert shareToken.transferFrom(tester.a0, tester.a1, 7, sender=tester.k1)
def test_roundsOfReporting(rounds, localFixture, market, universe): disputeWindow = universe.getOrCreateCurrentDisputeWindow() # Do the initial report proceedToNextRound(localFixture, market, moveTimeForward = False) # Do the first round outside of the loop and test logging crowdsourcerCreatedLog = { "universe": universe.address, "market": market.address, "size": universe.getInitialReportMinValue() * 2, "payoutNumerators": [0, 0, market.getNumTicks()], } crowdsourcerContributionLog = { "universe": universe.address, "reporter": bytesToHexString(tester.a0), "market": market.address, "amountStaked": universe.getInitialReportMinValue() * 2, "description": "Clearly incorrect", } crowdsourcerCompletedLog = { "universe": universe.address, "market": market.address } with AssertLog(localFixture, "DisputeCrowdsourcerCreated", crowdsourcerCreatedLog): with AssertLog(localFixture, "DisputeCrowdsourcerContribution", crowdsourcerContributionLog): with AssertLog(localFixture, "DisputeCrowdsourcerCompleted", crowdsourcerCompletedLog): proceedToNextRound(localFixture, market, description="Clearly incorrect") # proceed through several rounds of disputing for i in range(rounds - 2): proceedToNextRound(localFixture, market) assert disputeWindow != market.getDisputeWindow() disputeWindow = market.getDisputeWindow() assert disputeWindow == universe.getCurrentDisputeWindow()
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)
def test_publicSellCompleteSets(contractsFixture, universe, cash, market): completeSets = contractsFixture.contracts['CompleteSets'] orders = contractsFixture.contracts['Orders'] yesShareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(YES)) noShareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(NO)) cash.transfer(0, cash.balanceOf(tester.a9), sender=tester.k9) assert not cash.balanceOf(tester.a0) assert not cash.balanceOf(tester.a1) assert not cash.balanceOf(market.address) assert not yesShareToken.totalSupply() assert not noShareToken.totalSupply() cost = 10 * market.getNumTicks() assert universe.getOpenInterestInAttoEth() == 0 completeSets.publicBuyCompleteSets(market.address, 10, sender=tester.k1, value=cost) assert universe.getOpenInterestInAttoEth() == 10 * market.getNumTicks() initialTester1ETH = contractsFixture.chain.head_state.get_balance( tester.a1) initialTester0ETH = contractsFixture.chain.head_state.get_balance( tester.a0) completeSetsSoldLog = { "universe": universe.address, "market": market.address, "account": bytesToHexString(tester.a1), "numCompleteSets": 9 } with AssertLog(contractsFixture, "CompleteSetsSold", completeSetsSoldLog): result = completeSets.publicSellCompleteSets(market.address, 9, sender=tester.k1) assert universe.getOpenInterestInAttoEth() == 1 * market.getNumTicks() assert yesShareToken.balanceOf( tester.a1) == 1, "Should have 1 share of outcome yes" assert noShareToken.balanceOf( tester.a1) == 1, "Should have 1 share of outcome no" assert yesShareToken.totalSupply() == 1 assert noShareToken.totalSupply() == 1 assert contractsFixture.chain.head_state.get_balance( tester.a1) == initialTester1ETH + 88200 assert cash.balanceOf(market.address) == 10000 assert cash.balanceOf(market.getMarketCreatorMailbox()) == 900
def test_redeem_shares_in_yesNo_market(kitchenSinkFixture, universe, cash, market): claimTradingProceeds = kitchenSinkFixture.contracts['ClaimTradingProceeds'] yesShareToken = kitchenSinkFixture.applySignature('ShareToken', market.getShareToken(YES)) noShareToken = kitchenSinkFixture.applySignature('ShareToken', market.getShareToken(NO)) expectedValue = 1 * market.getNumTicks() expectedReporterFees = expectedValue / universe.getOrCacheReportingFeeDivisor() expectedMarketCreatorFees = expectedValue / market.getMarketCreatorSettlementFeeDivisor() expectedSettlementFees = expectedReporterFees + expectedMarketCreatorFees expectedPayout = long(expectedValue - expectedSettlementFees) assert universe.getOpenInterestInAttoCash() == 0 # get YES shares with a1 acquireLongShares(kitchenSinkFixture, cash, market, YES, 1, claimTradingProceeds.address, sender = tester.k1) assert universe.getOpenInterestInAttoCash() == 1 * market.getNumTicks() # get NO shares with a2 acquireShortShareSet(kitchenSinkFixture, cash, market, YES, 1, claimTradingProceeds.address, sender = tester.k2) assert universe.getOpenInterestInAttoCash() == 2 * market.getNumTicks() finalizeMarket(kitchenSinkFixture, market, [0, 0, 10**4]) initialLongHolderETH = kitchenSinkFixture.chain.head_state.get_balance(tester.a1) initialShortHolderETH = kitchenSinkFixture.chain.head_state.get_balance(tester.a2) tradingProceedsClaimedLog = { 'market': market.address, 'shareToken': yesShareToken.address, 'numPayoutTokens': expectedPayout, 'numShares': 1, 'sender': bytesToHexString(tester.a1), 'finalTokenBalance': initialLongHolderETH + expectedPayout, 'marketCreatorFees': 100, 'reporterFees': 100, } with TokenDelta(cash, expectedMarketCreatorFees, market.getOwner(), "market creator fees not paid"): with TokenDelta(cash, expectedReporterFees, universe.getOrCreateNextDisputeWindow(False), "Reporter fees not paid"): # redeem shares with a1 with AssertLog(kitchenSinkFixture, "TradingProceedsClaimed", tradingProceedsClaimedLog): claimTradingProceeds.claimTradingProceeds(market.address, tester.a1) # redeem shares with a2 claimTradingProceeds.claimTradingProceeds(market.address, tester.a2) # assert a1 ends up with cash (minus fees) and a2 does not assert kitchenSinkFixture.chain.head_state.get_balance(tester.a1) == initialLongHolderETH assert cash.balanceOf(tester.a1) == expectedPayout assert kitchenSinkFixture.chain.head_state.get_balance(tester.a2) == initialShortHolderETH assert yesShareToken.balanceOf(tester.a1) == 0 assert yesShareToken.balanceOf(tester.a2) == 0 assert noShareToken.balanceOf(tester.a1) == 0 assert noShareToken.balanceOf(tester.a2) == 0
def test_redeem_shares_in_yesNo_market(kitchenSinkFixture, universe, cash, market): shareToken = kitchenSinkFixture.contracts["ShareToken"] expectedValue = 100 * market.getNumTicks() expectedReporterFees = expectedValue / universe.getOrCacheReportingFeeDivisor() expectedMarketCreatorFees = expectedValue / market.getMarketCreatorSettlementFeeDivisor() expectedSettlementFees = expectedReporterFees + expectedMarketCreatorFees expectedPayout = expectedValue - expectedSettlementFees assert universe.getOpenInterestInAttoCash() == 0 # get YES shares with a1 acquireLongShares(kitchenSinkFixture, cash, market, YES, 100, shareToken.address, sender = kitchenSinkFixture.accounts[1]) assert universe.getOpenInterestInAttoCash() == 100 * market.getNumTicks() # get NO shares with a2 acquireShortShareSet(kitchenSinkFixture, cash, market, YES, 100, shareToken.address, sender = kitchenSinkFixture.accounts[2]) assert universe.getOpenInterestInAttoCash() == 200 * market.getNumTicks() finalizeMarket(kitchenSinkFixture, market, [0, 0, 10**2]) tradingProceedsClaimedLog = { 'market': market.address, 'numPayoutTokens': expectedPayout, 'numShares': 100, 'sender': kitchenSinkFixture.accounts[1], 'fees': 101, } daiVat = kitchenSinkFixture.contracts['DaiVat'] disputeWindow = universe.getOrCreateNextDisputeWindow(False) originalDisputeWindowBalance = cash.balanceOf(disputeWindow) originalMarketCreatorBalance = cash.balanceOf(market.getOwner()) # redeem shares with a1 with AssertLog(kitchenSinkFixture, "TradingProceedsClaimed", tradingProceedsClaimedLog): shareToken.claimTradingProceeds(market.address, kitchenSinkFixture.accounts[1], longTo32Bytes(11)) # redeem shares with a2 shareToken.claimTradingProceeds(market.address, kitchenSinkFixture.accounts[2], longTo32Bytes(11)) newDisputeWindowBalance = cash.balanceOf(disputeWindow) + daiVat.dai(disputeWindow) / 10**27 assert newDisputeWindowBalance == expectedReporterFees + originalDisputeWindowBalance newMarketCreatorBalanceFromFees = cash.balanceOf(market.getOwner()) assert newMarketCreatorBalanceFromFees == int(expectedMarketCreatorFees) + originalMarketCreatorBalance # assert a1 ends up with cash (minus fees) and a2 does not assert cash.balanceOf(kitchenSinkFixture.accounts[1]) == expectedPayout assert shareToken.balanceOfMarketOutcome(market.address, YES, kitchenSinkFixture.accounts[1]) == 0 assert shareToken.balanceOfMarketOutcome(market.address, YES, kitchenSinkFixture.accounts[2]) == 0 assert shareToken.balanceOfMarketOutcome(market.address, NO, kitchenSinkFixture.accounts[1]) == 0 assert shareToken.balanceOfMarketOutcome(market.address, NO, kitchenSinkFixture.accounts[2]) == 0
def test_whitelists(localFixture, controller): assert controller.assertIsWhitelisted(tester.a0, sender = tester.k2) with raises(TransactionFailed): controller.addToWhitelist(tester.a1, sender = tester.k1) with raises(TransactionFailed): controller.addToWhitelist(tester.a1, sender = tester.k2) whitelistAdditionLog = {"addition": bytesToHexString(tester.a1)} with AssertLog(localFixture, "WhitelistAddition", whitelistAdditionLog): assert controller.addToWhitelist(tester.a1, sender = tester.k0) assert controller.assertIsWhitelisted(tester.a1, sender = tester.k2) with raises(TransactionFailed): controller.assertIsWhitelisted(tester.a2, sender = tester.k2) with raises(TransactionFailed): controller.removeFromWhitelist(tester.a1, sender = tester.k2) assert controller.removeFromWhitelist(tester.a1, sender = tester.k1) with raises(TransactionFailed): controller.assertIsWhitelisted(tester.a1, sender = tester.k0)
def test_create_bid_with_shares_fill_with_shares(contractsFixture, cash, market, universe): shareToken = contractsFixture.contracts['ShareToken'] createOrder = contractsFixture.contracts['CreateOrder'] fillOrder = contractsFixture.contracts['FillOrder'] shareToken = contractsFixture.contracts["ShareToken"] totalProceeds = fix('12', market.getNumTicks()) marketCreatorFee = totalProceeds / market.getMarketCreatorSettlementFeeDivisor() reporterFee = totalProceeds / universe.getOrCacheReportingFeeDivisor() completeSetFees = marketCreatorFee + reporterFee # 1. buy complete sets with both accounts with BuyWithCash(cash, fix('12', market.getNumTicks()), contractsFixture.accounts[1], "buy complete set"): assert shareToken.publicBuyCompleteSets(market.address, fix(12), sender = contractsFixture.accounts[1]) with BuyWithCash(cash, fix('12', market.getNumTicks()), contractsFixture.accounts[2], "buy complete set"): assert shareToken.publicBuyCompleteSets(market.address, fix(12), sender = contractsFixture.accounts[2]) assert cash.balanceOf(contractsFixture.accounts[1]) == fix('0') assert cash.balanceOf(contractsFixture.accounts[2]) == fix('0') assert shareToken.balanceOfMarketOutcome(market.address, YES, contractsFixture.accounts[2]) == fix(12) assert shareToken.balanceOfMarketOutcome(market.address, YES, contractsFixture.accounts[1]) == fix(12) assert shareToken.balanceOfMarketOutcome(market.address, NO, contractsFixture.accounts[1]) == fix(12) assert shareToken.balanceOfMarketOutcome(market.address, NO, contractsFixture.accounts[2]) == fix(12) # 2. create BID order for YES with NO shares escrowed orderID = createOrder.publicCreateOrder(BID, fix(12), 60, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), longTo32Bytes(42), nullAddress, sender = contractsFixture.accounts[1]) assert orderID assert cash.balanceOf(contractsFixture.accounts[1]) == fix('0') assert shareToken.balanceOfMarketOutcome(market.address, YES, contractsFixture.accounts[1]) == fix(12) assert shareToken.balanceOfMarketOutcome(market.address, NO, contractsFixture.accounts[1]) == 0 # 3. fill BID order for YES with shares of YES orderFilledEventLog = { "eventType": 2, "addressData": [contractsFixture.accounts[1] , contractsFixture.accounts[2]], "uint256Data": [60, 0, YES, 0, 0, completeSetFees, fix(12), contractsFixture.contracts['Time'].getTimestamp(), 0, 0], } with AssertLog(contractsFixture, 'OrderEvent', orderFilledEventLog): leftoverInOrder = fillOrder.publicFillOrder(orderID, fix(12), longTo32Bytes(42), longTo32Bytes(11), sender = contractsFixture.accounts[2]) assert leftoverInOrder == 0 creatorFee = completeSetFees * 2 / 5 fillerFee = completeSetFees * 3 / 5 creatorPayment = fix('12', '40') - creatorFee fillerPayment = fix('12', '60') - fillerFee assert cash.balanceOf(contractsFixture.accounts[1]) == creatorPayment assert cash.balanceOf(contractsFixture.accounts[2]) == fillerPayment assert shareToken.balanceOfMarketOutcome(market.address, YES, contractsFixture.accounts[1]) == fix(12) assert shareToken.balanceOfMarketOutcome(market.address, YES, contractsFixture.accounts[2]) == 0 assert shareToken.balanceOfMarketOutcome(market.address, NO, contractsFixture.accounts[1]) == 0 assert shareToken.balanceOfMarketOutcome(market.address, NO, contractsFixture.accounts[2]) == fix(12)
def test_transfering_ownership(contractsFixture, universe, market): account0 = contractsFixture.accounts[0] account1 = contractsFixture.accounts[1] transferLog = { "universe": universe.address, "market": market.address, "from": account0, "to": account1, } with AssertLog(contractsFixture, "MarketTransferred", transferLog): assert market.transferOwnership(account1) transferLog = { "universe": universe.address, "market": market.address, "from": account0, "to": account1, } with AssertLog(contractsFixture, "MarketRepBondTransferred", transferLog): assert market.transferRepBondOwnership(account1) assert market.repBondOwner() == account1
def test_share_transfer(contractsFixture, cash, market, universe): createOrder = contractsFixture.contracts["CreateOrder"] fillOrder = contractsFixture.contracts["FillOrder"] profitLoss = contractsFixture.contracts["ProfitLoss"] # Buy shares for .5 amount = fix(1) price = 50 cost = amount * price assert cash.faucet(cost) orderID = createOrder.publicCreateOrder(BID, amount, price, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), longTo32Bytes(42), nullAddress) assert cash.faucet(cost, sender = contractsFixture.accounts[1]) fillOrder.publicFillOrder(orderID, amount, longTo32Bytes(42), nullAddress, sender = contractsFixture.accounts[1]) yesShares = contractsFixture.applySignature('ShareToken', market.getShareToken(YES)) assert yesShares.balanceOf(contractsFixture.accounts[0]) == fix(1) # Transfer shares and confirm its as if sender sold for 0 and receiver bought for 0 profitLossChangedLogSender = { "account": contractsFixture.accounts[0], "outcome": YES, "netPosition": fix(1) - 100, "avgPrice": 50, "realizedProfit": -5000, } profitLossChangedLogReceiver = { "account": contractsFixture.accounts[2], "outcome": YES, "netPosition": 100, "avgPrice": 0, "realizedProfit": 0, } with AssertLog(contractsFixture, "ProfitLossChanged", profitLossChangedLogSender): with AssertLog(contractsFixture, "ProfitLossChanged", profitLossChangedLogReceiver, skip=1): assert yesShares.transfer(contractsFixture.accounts[2], 100)
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)
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
def test_basic_token_emit(testStandardTokenFixture): standardToken = testStandardTokenFixture.contracts['StandardTokenHelper'] assert standardToken.faucet(101, sender=testStandardTokenFixture.accounts[1]) transferLog = {'value': 101} with AssertLog(testStandardTokenFixture, "Transfer", transferLog, contract=standardToken): assert standardToken.transfer( testStandardTokenFixture.accounts[2], 101, sender=testStandardTokenFixture.accounts[1]) assert standardToken.balanceOf(testStandardTokenFixture.accounts[2]) == 101
def test_publicCreateOrder_bid2(contractsFixture, cash, market, universe): orders = contractsFixture.contracts['Orders'] createOrder = contractsFixture.contracts['CreateOrder'] shareToken = contractsFixture.contracts["ShareToken"] orderType = BID amount = fix(1) fxpPrice = 40 outcome = 0 tradeGroupID = longTo32Bytes(42) orderID = None orderCreatedEventLog = { "eventType": 0, "addressData": [nullAddress, contractsFixture.accounts[1], nullAddress], "uint256Data": [ fxpPrice, amount, outcome, 0, 0, 0, 0, contractsFixture.contracts['Time'].getTimestamp(), 0, fix(1, 40) ], } with BuyWithCash(cash, fix('1', '40'), contractsFixture.accounts[1], "create order"): with AssertLog(contractsFixture, "OrderEvent", orderCreatedEventLog): orderID = createOrder.publicCreateOrder( orderType, amount, fxpPrice, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, nullAddress, sender=contractsFixture.accounts[1]) assert orderID != bytearray(32), "Order ID should be non-zero" assert orders.getAmount(orderID) == amount assert orders.getPrice(orderID) == fxpPrice assert orders.getOrderCreator(orderID) == contractsFixture.accounts[1] assert orders.getOrderMoneyEscrowed(orderID) == fix(1, 40) assert orders.getOrderSharesEscrowed(orderID) == 0 assert cash.balanceOf(contractsFixture.accounts[1]) == 0 assert orders.getTotalEscrowed(market.address) == 40 * 10**18
def test_publicCreateOrder_bid2(contractsFixture, cash, market): orders = contractsFixture.contracts['Orders'] createOrder = contractsFixture.contracts['CreateOrder'] orderType = BID amount = fix(1) fxpPrice = 40 outcome = 0 tradeGroupID = longTo32Bytes(42) marketInitialCash = cash.balanceOf(market.address) orderID = None shareToken = contractsFixture.getShareToken(market, 0) orderCreatedEventLog = { "eventType": 0, "addressData": [nullAddress, bytesToHexString(tester.a1), nullAddress], "uint256Data": [ fxpPrice, amount, outcome, 0, 0, 0, 0, contractsFixture.contracts['Time'].getTimestamp() ], } with BuyWithCash(cash, fix('1', '40'), tester.k1, "create order"): with AssertLog(contractsFixture, "OrderEvent", orderCreatedEventLog): orderID = createOrder.publicCreateOrder(orderType, amount, fxpPrice, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, False, nullAddress, sender=tester.k1) 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, 40) assert orders.getOrderSharesEscrowed(orderID) == 0 assert cash.balanceOf(tester.a1) == 0 assert cash.balanceOf(market.address) - marketInitialCash == 40 * 10**18
def test_gnosis_safe_registry(contractsFixture, augur, universe, cash, gnosisSafeRegistry, gnosisSafeMaster, proxyFactory): createOrder = contractsFixture.contracts["CreateOrder"] fillOrder = contractsFixture.contracts["FillOrder"] zeroXTrade = contractsFixture.contracts["ZeroXTrade"] shareToken = contractsFixture.contracts["ShareToken"] affiliates = contractsFixture.contracts["Affiliates"] account = contractsFixture.accounts[0] assert gnosisSafeRegistry.getSafe(account) == nullAddress assert gnosisSafeRegistry.address assert gnosisSafeMaster.address assert proxyFactory.address saltNonce = 42 gnosisSafeRegistryData = gnosisSafeRegistry.setupForAugur_encode( augur.address, createOrder.address, fillOrder.address, zeroXTrade.address, cash.address, shareToken.address, affiliates.address, longTo32Bytes(11), nullAddress) gnosisSafeData = gnosisSafeMaster.setup_encode([account], 1, gnosisSafeRegistry.address, gnosisSafeRegistryData, nullAddress, nullAddress, 0, nullAddress) GnosisSafeRegisteredLog = { "owner": account, } with AssertLog(contractsFixture, "GnosisSafeRegistered", GnosisSafeRegisteredLog): gnosisSafeAddress = proxyFactory.createProxyWithCallback( gnosisSafeMaster.address, gnosisSafeData, saltNonce, gnosisSafeRegistry.address) gnosisSafe = contractsFixture.applySignature("GnosisSafe", gnosisSafeAddress) assert gnosisSafe.getOwners() == [account] assert gnosisSafe.getThreshold() == 1 assert gnosisSafeRegistry.getSafe(account) == gnosisSafe.address assert cash.allowance(gnosisSafe.address, augur.address, 2**256 - 1)
def test_registry(localFixture, controller, decentralizedController): key1 = 'abc'.ljust(32, '\x00') key2 = 'foo'.ljust(32, '\x00') with raises(TransactionFailed): controller.registerContract(key1, 123, garbageBytes20, garbageBytes32, sender=tester.k2) assert controller.lookup(key1, sender=tester.k2) == longToHexString(0) assert controller.addToWhitelist(tester.a1, sender=tester.k0) registryAdditionLog = { "key": key1, "addition": longToHexString(123), "commitHash": garbageBytes20, "bytecodeHash": garbageBytes32 } with AssertLog(localFixture, "RegistryAddition", registryAdditionLog): assert controller.registerContract(key1, 123, garbageBytes20, garbageBytes32, sender=tester.k0) assert controller.lookup(key1, sender=tester.k2) == longToHexString(123) with raises(TransactionFailed): controller.assertOnlySpecifiedCaller(tester.a1, key2, sender=tester.k2) assert controller.registerContract(key2, tester.a1, garbageBytes20, garbageBytes32, sender=tester.k0) assert controller.assertOnlySpecifiedCaller(tester.a1, key2, sender=tester.k2) # dev mode special assert controller.assertOnlySpecifiedCaller(tester.a1, key2, sender=tester.k0) with raises(TransactionFailed): decentralizedController.assertOnlySpecifiedCaller(tester.a2, key2, sender=tester.k0) with raises(TransactionFailed): controller.assertOnlySpecifiedCaller(tester.a2, key2, sender=tester.k2)
def process_trades(contractsFixture, trade_data, cash, market, zeroXTrade, profitLoss, taker, minPrice = 0, displayRange = 1): for trade in trade_data: quantity = trade['quantity'] * 10**18 onChainLongPrice = int(round((trade['price'] - minPrice) * market.getNumTicks() / displayRange)) onChainShortPrice = int(round(market.getNumTicks() - onChainLongPrice)) direction = BID if trade['direction'] == SHORT else ASK direction = direction if taker else ASK if trade['direction'] == SHORT else BID longCost = quantity * onChainLongPrice shortCost = quantity * onChainShortPrice creatorCost = longCost if direction == BID else shortCost fillerCost = longCost if direction == ASK else shortCost expirationTime = contractsFixture.contracts["Time"].getTimestamp() + 1000000 salt = 42 assert cash.faucet(creatorCost, sender = contractsFixture.accounts[1]) rawZeroXOrderData, orderHash = zeroXTrade.createZeroXOrder(direction, quantity, onChainLongPrice, market.address, trade['outcome'], expirationTime, salt, sender = contractsFixture.accounts[1]) signature = signOrder(orderHash, contractsFixture.privateKeys[1]) timestamp = contractsFixture.contracts["Augur"].getTimestamp() profitLossChangedLog = { "outcome": trade['outcome'], "timestamp": timestamp, } fingerprint = longTo32Bytes(11) tradeGroupId = longTo32Bytes(42) orders = [rawZeroXOrderData] signatures = [signature] assert cash.faucet(fillerCost, sender = contractsFixture.accounts[2]) skip = 0 if direction == BID else 1 skip = skip if taker else (1 if direction == BID else 0) with AssertLog(contractsFixture, "ProfitLossChanged", profitLossChangedLog, skip = skip): zeroXTrade.trade(quantity, fingerprint, tradeGroupId, 0, 10, orders, signatures, sender=contractsFixture.accounts[2], value=150000) avgPrice = (trade['avgPrice'] - minPrice) * market.getNumTicks() / displayRange * 10**18 realizedProfit = trade['realizedPL'] * market.getNumTicks() / displayRange * 10**36 frozenFunds = trade['frozenFunds'] * market.getNumTicks() / displayRange * 10**36 account = contractsFixture.accounts[2] if taker else contractsFixture.accounts[1] assert profitLoss.getNetPosition(market.address, account, trade['outcome']) == trade['position'] * 10**18 assert roughlyEqual(profitLoss.getAvgPrice(market.address, account, trade['outcome']), avgPrice, 10**6) assert roughlyEqual(profitLoss.getRealizedProfit(market.address, account, trade['outcome']), realizedProfit) assert roughlyEqual(profitLoss.getFrozenFunds(market.address, account, trade['outcome']), frozenFunds)
def test_publicCreateOrder_bid2(contractsFixture, cash, market): orders = contractsFixture.contracts['Orders'] createOrder = contractsFixture.contracts['CreateOrder'] orderType = BID amount = fix(1) fxpPrice = 4000 outcome = 0 tradeGroupID = longTo32Bytes(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(longTo32Bytes(42)), } with BuyWithCash(cash, fix('1', '4000'), tester.k1, "create order"): with AssertLog(contractsFixture, "OrderCreated", orderCreatedLog): orderID = createOrder.publicCreateOrder(orderType, amount, fxpPrice, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, False, sender=tester.k1) 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
def test_publicBuyCompleteSets(contractsFixture, universe, cash, market): completeSets = contractsFixture.contracts['CompleteSets'] orders = contractsFixture.contracts['Orders'] yesShareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(YES)) noShareToken = contractsFixture.applySignature('ShareToken', market.getShareToken(NO)) assert not cash.balanceOf(tester.a1) assert cash.balanceOf(market.address) == universe.getOrCacheValidityBond() assert not yesShareToken.totalSupply() assert not noShareToken.totalSupply() assert universe.getOpenInterestInAttoEth() == 0 cost = 10 * market.getNumTicks() print cash.depositEther(sender=tester.k1, value=cost) completeSetsPurchasedLog = { "universe": universe.address, "market": market.address, "account": bytesToHexString(tester.a1), "numCompleteSets": 10, "marketOI": cost } with AssertLog(contractsFixture, "CompleteSetsPurchased", completeSetsPurchasedLog): assert completeSets.publicBuyCompleteSets(market.address, 10, sender=tester.k1) assert yesShareToken.balanceOf( tester.a1) == 10, "Should have 10 shares of outcome 1" assert noShareToken.balanceOf( tester.a1) == 10, "Should have 10 shares of outcome 2" assert cash.balanceOf(tester.a1) == 0, "Sender's cash balance should be 0" assert cash.balanceOf( market.address ) == cost + universe.getOrCacheValidityBond( ), "Increase in market's cash should equal the cost to purchase the complete set" assert yesShareToken.totalSupply( ) == 10, "Increase in yes shares purchased for this market should be 10" assert noShareToken.totalSupply( ) == 10, "Increase in yes shares purchased for this market should be 10" assert universe.getOpenInterestInAttoEth( ) == cost, "Open interest in the universe increases by the cost in ETH of the sets purchased"
def test_one_round_crowdsourcer(localFixture, universe, market, cash, reputationToken): disputeWindow = localFixture.applySignature('DisputeWindow', market.getDisputeWindow()) constants = localFixture.contracts["Constants"] # We'll make the window active localFixture.contracts["Time"].setTimestamp(disputeWindow.getStartTime() + 1) # We'll have testers push markets into the next round by funding dispute crowdsourcers amount = 2 * market.getParticipantStake() with TokenDelta(reputationToken, -amount, tester.a1, "Disputing did not reduce REP balance correctly"): assert market.contribute([0, 0, market.getNumTicks()], amount, "", sender=tester.k1) newDisputeWindowAddress = market.getDisputeWindow() assert newDisputeWindowAddress != disputeWindow.address # fast forward time to the fee new window disputeWindow = localFixture.applySignature('DisputeWindow', newDisputeWindowAddress) localFixture.contracts["Time"].setTimestamp(disputeWindow.getStartTime() + 1) # Fast forward time until the new dispute window is over and we can redeem our winning stake, and dispute bond tokens localFixture.contracts["Time"].setTimestamp(disputeWindow.getEndTime() + 1) assert market.finalize() initialReporter = localFixture.applySignature('InitialReporter', market.getReportingParticipant(0)) marketDisputeCrowdsourcer = localFixture.applySignature('DisputeCrowdsourcer', market.getReportingParticipant(1)) expectedRep = market.getParticipantStake() assert expectedRep == long(marketDisputeCrowdsourcer.getStake() + marketDisputeCrowdsourcer.getStake() / 2) disputeCrowdsourcerRedeemedLog = { "reporter": bytesToHexString(tester.a1), "disputeCrowdsourcer": marketDisputeCrowdsourcer.address, "amountRedeemed": marketDisputeCrowdsourcer.getStake(), "repReceived": expectedRep, "payoutNumerators": [0, 0, market.getNumTicks()], "universe": universe.address, "market": market.address } with AssertLog(localFixture, "DisputeCrowdsourcerRedeemed", disputeCrowdsourcerRedeemedLog): with TokenDelta(reputationToken, expectedRep, tester.a1, "Redeeming didn't refund REP"): assert marketDisputeCrowdsourcer.redeem(tester.a1, sender=tester.k1) # The initial reporter does not get their REP back with TokenDelta(reputationToken, 0, tester.a0, "Redeeming didn't refund REP"): assert initialReporter.redeem(tester.a0)
def test_cancelBid(contractsFixture, cash, market, universe): createOrder = contractsFixture.contracts['CreateOrder'] cancelOrder = contractsFixture.contracts['CancelOrder'] orders = contractsFixture.contracts['Orders'] shareToken = contractsFixture.getShareToken() orderType = BID amount = fix(1) fxpPrice = 60 outcomeID = YES tradeGroupID = longTo32Bytes(42) creatorInitialShares = shareToken.balanceOfMarketOutcome(market.address, YES, contractsFixture.accounts[1]) marketInitialCash = cash.balanceOf(market.address) marketInitialYesShares = shareToken.totalSupplyForMarketOutcome(market.address, YES) marketInitialNoShares = shareToken.totalSupplyForMarketOutcome(market.address, NO) with BuyWithCash(cash, fix(fxpPrice), contractsFixture.accounts[1], "The sender didn't get cost deducted for create order"): orderID = createOrder.publicCreateOrder(orderType, amount, fxpPrice, market.address, outcomeID, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, nullAddress, sender=contractsFixture.accounts[1]) assert orderID, "Order ID should be non-zero" assert orders.getOrderCreator(orderID), "Order should have an owner" orderEventLog = { "universe": universe.address, "market": market.address, "eventType": 1, "addressData": [contractsFixture.accounts[1], nullAddress], "uint256Data": [0, 0, 0, fix('1', '60'), 0, 0, 0, contractsFixture.contracts['Time'].getTimestamp(), 0, 0], } with AssertLog(contractsFixture, 'OrderEvent', orderEventLog): assert(cancelOrder.cancelOrder(orderID, sender=contractsFixture.accounts[1]) == 1), "cancelOrder should succeed" 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(cash.balanceOf(contractsFixture.accounts[1]) == fix('60')), "Maker's cash balance should be order size" assert(marketInitialCash == cash.balanceOf(market.address)), "Market's cash balance should be the same as before the order was placed" assert(creatorInitialShares == shareToken.balanceOfMarketOutcome(market.address, YES, contractsFixture.accounts[1])), "Maker's shares should be unchanged" assert(marketInitialYesShares == shareToken.totalSupplyForMarketOutcome(market.address, YES)), "Market's yes shares should be unchanged" assert marketInitialNoShares == shareToken.totalSupplyForMarketOutcome(market.address, NO), "Market's no shares should be unchanged"
def test_crowdsourcer_transfer(contractsFixture, market, universe): proceedToNextRound(contractsFixture, market) proceedToNextRound(contractsFixture, market) proceedToNextRound(contractsFixture, market) crowdsourcer = contractsFixture.applySignature( "DisputeCrowdsourcer", market.getWinningReportingParticipant()) crowdsourcerTokenTransferLog = { 'from': bytesToHexString(tester.a0), 'to': bytesToHexString(tester.a1), 'token': crowdsourcer.address, 'universe': universe.address, 'tokenType': 2, 'value': 0, } with AssertLog(contractsFixture, "TokensTransferred", crowdsourcerTokenTransferLog): assert crowdsourcer.transfer(tester.a1, 0)
def test_dr_report_stake_up(contractsFixture, universe, market): designatedReportStake = universe.getOrCacheDesignatedReportStake() # We'll have the markets go to initial reporting proceedToInitialReporting(contractsFixture, market) # The DR will report numTicks = market.getNumTicks() payoutNumerators = [0, numTicks, 0] assert market.doInitialReport(payoutNumerators, "", 0) # Proceed to the next round so we can dispute the DR disputeWindow = contractsFixture.applySignature('DisputeWindow', market.getDisputeWindow()) contractsFixture.contracts["Time"].setTimestamp( disputeWindow.getStartTime() + 1) payoutNumerators = [0, 0, numTicks] chosenPayoutHash = market.derivePayoutDistributionHash(payoutNumerators) amount = 2 * market.getParticipantStake() - 3 * market.getStakeInOutcome( chosenPayoutHash) assert market.contribute(payoutNumerators, amount, "") # Move time forward to finalize the market disputeWindow = contractsFixture.applySignature('DisputeWindow', market.getDisputeWindow()) contractsFixture.contracts["Time"].setTimestamp( disputeWindow.getEndTime() + 1) assert market.finalize() # Confirm that the report stake bond is now doubled in the next dispute window disputeWindow = contractsFixture.applySignature( 'DisputeWindow', universe.getOrCreateCurrentDisputeWindow(False)) contractsFixture.contracts["Time"].setTimestamp( disputeWindow.getEndTime() + 1) expectedDesignatedReportStake = designatedReportStake * 2 designatedReportStakeChangedLog = { "universe": universe.address, "designatedReportStake": expectedDesignatedReportStake, } with AssertLog(contractsFixture, "DesignatedReportStakeChanged", designatedReportStakeChangedLog): newDesignatedReportStake = universe.getOrCacheDesignatedReportStake() assert newDesignatedReportStake == expectedDesignatedReportStake
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 with BuyWithCash(cash, creatorCost, tester.k1, "complete set buy"): orderID = createOrder.publicCreateOrder(BID, fix(2), 6000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, sender = tester.k1) # 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 BuyWithCash(cash, fillerCost, tester.k2, "filling order"): with AssertLog(contractsFixture, "OrderFilled", orderFilledLog): fillOrderID = fillOrder.publicFillOrder(orderID, fix(2), tradeGroupID, sender = tester.k2) 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)
def test_redeem_shares_in_yesNo_market(kitchenSinkFixture, universe, cash, market): shareToken = kitchenSinkFixture.contracts["ShareToken"] expectedValue = 1 * market.getNumTicks() expectedReporterFees = expectedValue / universe.getOrCacheReportingFeeDivisor() expectedMarketCreatorFees = expectedValue / market.getMarketCreatorSettlementFeeDivisor() expectedSettlementFees = expectedReporterFees + expectedMarketCreatorFees expectedPayout = expectedValue - expectedSettlementFees assert universe.getOpenInterestInAttoCash() == 0 # get YES shares with a1 acquireLongShares(kitchenSinkFixture, cash, market, YES, 1, shareToken.address, sender = kitchenSinkFixture.accounts[1]) assert universe.getOpenInterestInAttoCash() == 1 * market.getNumTicks() # get NO shares with a2 acquireShortShareSet(kitchenSinkFixture, cash, market, YES, 1, shareToken.address, sender = kitchenSinkFixture.accounts[2]) assert universe.getOpenInterestInAttoCash() == 2 * market.getNumTicks() finalizeMarket(kitchenSinkFixture, market, [0, 0, 10**2]) tradingProceedsClaimedLog = { 'market': market.address, 'numPayoutTokens': expectedPayout, 'numShares': 1, 'sender': kitchenSinkFixture.accounts[1], 'fees': 2, } with TokenDelta(cash, expectedMarketCreatorFees, market.getOwner(), "market creator fees not paid"): with TokenDelta(cash, expectedReporterFees, universe.getOrCreateNextDisputeWindow(False), "Reporter fees not paid"): # redeem shares with a1 with AssertLog(kitchenSinkFixture, "TradingProceedsClaimed", tradingProceedsClaimedLog): shareToken.claimTradingProceeds(market.address, kitchenSinkFixture.accounts[1], longTo32Bytes(11)) # redeem shares with a2 shareToken.claimTradingProceeds(market.address, kitchenSinkFixture.accounts[2], longTo32Bytes(11)) # assert a1 ends up with cash (minus fees) and a2 does not assert cash.balanceOf(kitchenSinkFixture.accounts[1]) == expectedPayout assert shareToken.balanceOfMarketOutcome(market.address, YES, kitchenSinkFixture.accounts[1]) == 0 assert shareToken.balanceOfMarketOutcome(market.address, YES, kitchenSinkFixture.accounts[2]) == 0 assert shareToken.balanceOfMarketOutcome(market.address, NO, kitchenSinkFixture.accounts[1]) == 0 assert shareToken.balanceOfMarketOutcome(market.address, NO, kitchenSinkFixture.accounts[2]) == 0
def test_market_creation(contractsFixture, universe, testNetDenominationToken, market): numTicks = market.getNumTicks() market = None marketCreatedLog = { "extraInfo": 'so extra', "marketCreator": bytesToHexString(tester.a0), } with AssertLog(contractsFixture, "MarketCreated", marketCreatedLog): market = contractsFixture.createReasonableYesNoMarket(universe, testNetDenominationToken, extraInfo="so extra") assert market.getUniverse() == universe.address assert market.getNumberOfOutcomes() == 2 assert numTicks == 10000 assert market.isResolved() == False assert market.getInitialized() feeDivisor = 100 with raises(TransactionFailed, message="Cannot create a market with an end date in the past"): contractsFixture.createYesNoMarket(universe, 0, feeDivisor, testNetDenominationToken, tester.a0)
def test_market_creation(afterMkrShutdown, contractsFixture, augur, universe, market): marketFactory = contractsFixture.contracts["MarketFactory"] account0 = contractsFixture.accounts[0] numTicks = market.getNumTicks() market = None endTime = contractsFixture.contracts["Time"].getTimestamp() + timedelta( days=1).total_seconds() if (afterMkrShutdown): contractsFixture.MKRShutdown() marketCreatedLog = { "extraInfo": 'so extra', "endTime": endTime, "marketCreator": account0, "designatedReporter": account0, "noShowBond": universe.getOrCacheMarketRepBond(), } with raises(TransactionFailed): market = marketFactory.createMarket(augur.address, endTime, 0, nullAddress, 0, account0, account0, 3, 100) with AssertLog(contractsFixture, "MarketCreated", marketCreatedLog): market = contractsFixture.createReasonableYesNoMarket( universe, extraInfo="so extra") assert market.getUniverse() == universe.address assert market.getNumberOfOutcomes() == 3 assert numTicks == 100 assert market.getReputationToken() == universe.getReputationToken() assert market.getWinningPayoutDistributionHash() == stringToBytes("") assert market.getInitialized() endTime = 0 with raises(TransactionFailed): contractsFixture.createYesNoMarket(universe, endTime, 1, 0, account0)