def reportingSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    # Give some REP to testers to make things interesting
    universe = ABIContract(fixture.chain, kitchenSinkSnapshot['universe'].translator, kitchenSinkSnapshot['universe'].address)
    reputationToken = fixture.applySignature('ReputationToken', universe.getReputationToken())
    for testAccount in [tester.a1, tester.a2, tester.a3]:
        reputationToken.transfer(testAccount, 1 * 10**6 * 10**18)

    return fixture.createSnapshot()
Ejemplo n.º 2
0
 def getShareToken(self, market, outcome):
     shareTokenAddress = market.getShareToken(outcome)
     assert shareTokenAddress
     shareToken = ABIContract(
         self.chain,
         ContractTranslator(ContractsFixture.signatures['ShareToken']),
         shareTokenAddress)
     return shareToken
Ejemplo n.º 3
0
 def applySignature(self, signatureName, address):
     assert address
     if type(address) is long:
         address = longToHexString(address)
     translator = ContractTranslator(
         ContractsFixture.signatures[signatureName])
     contract = ABIContract(self.chain, translator, address)
     return contract
Ejemplo n.º 4
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain,
                           kitchenSinkSnapshot['universe'].translator,
                           kitchenSinkSnapshot['universe'].address)
    cash = ABIContract(fixture.chain, kitchenSinkSnapshot['cash'].translator,
                       kitchenSinkSnapshot['cash'].address)
    fixture.markets = [
        fixture.createReasonableCategoricalMarket(universe, 2, cash),
        fixture.createReasonableCategoricalMarket(universe, 3, cash),
        fixture.createReasonableCategoricalMarket(universe, 4, cash),
        fixture.createReasonableCategoricalMarket(universe, 5, cash),
        fixture.createReasonableCategoricalMarket(universe, 6, cash),
        fixture.createReasonableCategoricalMarket(universe, 7, cash),
        fixture.createReasonableCategoricalMarket(universe, 8, cash)
    ]

    return fixture.createSnapshot()
Ejemplo n.º 5
0
def uploadSolidityContract(chain, compileResult, name, contractName):
    print compileResult['contracts'][name][contractName]['evm']['bytecode'][
        'object']
    bytecode = bytearray.fromhex(compileResult['contracts'][name][contractName]
                                 ['evm']['bytecode']['object'])
    signature = compileResult['contracts'][name][contractName]['abi']
    address = long(hexlify(chain.contract(bytecode, language='evm')), 16)
    contract = ABIContract(chain, ContractTranslator(signature), address)
    return contract
Ejemplo n.º 6
0
 def resetToSnapshot(self, snapshot):
     if not 'state' in snapshot: raise "snapshot is missing 'state'"
     if not 'contracts' in snapshot: raise "snapshot is missing 'contracts'"
     self.chain = Chain(genesis=snapshot['state'], env=Env(config=config_metropolis))
     if self.coverageMode:
         self.chain.head_state.log_listeners.append(self.writeLogToFile)
     self.contracts = {}
     for contractName in snapshot['contracts']:
         contract = snapshot['contracts'][contractName]
         self.contracts[contractName] = ABIContract(self.chain, contract['translator'], contract['address'])
Ejemplo n.º 7
0
 def getOrCreateChildUniverse(self, parentUniverse, market,
                              payoutDistribution):
     assert payoutDistributionHash
     childUniverseAddress = parentUniverse.getOrCreateChildUniverse(
         payoutDistribution)
     assert childUniverseAddress
     childUniverse = ABIContract(
         self.chain,
         ContractTranslator(ContractsFixture.signatures['Universe']),
         childUniverseAddress)
     return childUniverse
Ejemplo n.º 8
0
 def resetToSnapshot(self, snapshot):
     if not 'state' in snapshot: raise "snapshot is missing 'state'"
     if not 'contracts' in snapshot: raise "snapshot is missing 'contracts'"
     self.chain = Chain(genesis=snapshot['state'],
                        env=Env(config=config_metropolis))
     self.contracts = {}
     for contractName in snapshot['contracts']:
         contract = snapshot['contracts'][contractName]
         self.contracts[contractName] = ABIContract(self.chain,
                                                    contract['translator'],
                                                    contract['address'])
Ejemplo n.º 9
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    augur = fixture.contracts["Augur"]
    kitchenSinkSnapshot['zeroX'] = fixture.upload(
        'solidity_test_helpers/ZeroX/ZeroXPoC.sol',
        "zeroX",
        constructorArgs=[augur.address])
    market = ABIContract(fixture.chain,
                         kitchenSinkSnapshot['yesNoMarket'].translator,
                         kitchenSinkSnapshot['yesNoMarket'].address)

    return fixture.createSnapshot()
Ejemplo n.º 10
0
def test_abicontract_interface():
    """ Test for issue #370. """
    tester_state = Chain()

    contract_path = path.join(CONTRACTS_DIR, 'simple_contract.sol')
    contract_name = 'Simple'
    simple_compiled = compile_file(contract_path)
    simple_data = solidity_get_contract_data(
        simple_compiled,
        contract_path,
        contract_name,
    )
    simple_address = tester_state.contract(simple_data['bin'])

    # ABIContract class must accept json_abi
    abi_json = json.dumps(simple_data['abi']).encode('utf-8')

    abi = ABIContract(
        _chain=tester_state,
        _abi=abi_json,
        address=simple_address,
    )

    assert abi.test() == 1  # pylint: disable=no-member
Ejemplo n.º 11
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain,
                           kitchenSinkSnapshot['universe'].translator,
                           kitchenSinkSnapshot['universe'].address)
    fixture.markets = [
        fixture.createReasonableCategoricalMarket(universe, 2),
        fixture.createReasonableCategoricalMarket(universe, 3),
        fixture.createReasonableCategoricalMarket(universe, 4),
        fixture.createReasonableCategoricalMarket(universe, 5),
        fixture.createReasonableCategoricalMarket(universe, 6),
        fixture.createReasonableCategoricalMarket(universe, 7),
    ]

    return fixture.createSnapshot()
Ejemplo n.º 12
0
 def upload(self,
            relativeFilePath,
            lookupKey=None,
            signatureKey=None,
            constructorArgs=[]):
     resolvedPath = resolveRelativePath(relativeFilePath)
     if self.coverageMode:
         resolvedPath = resolvedPath.replace("tests",
                                             "coverageEnv").replace(
                                                 "source/", "coverageEnv/")
     lookupKey = lookupKey if lookupKey else path.splitext(
         path.basename(resolvedPath))[0]
     signatureKey = signatureKey if signatureKey else lookupKey
     if lookupKey in self.contracts:
         return (self.contracts[lookupKey])
     compiledCode = self.getCompiledCode(resolvedPath)
     # abstract contracts have a 0-length array for bytecode
     if len(compiledCode) == 0:
         if ("libraries" in relativeFilePath or lookupKey.startswith("I")
                 or lookupKey.startswith("Base")
                 or lookupKey.startswith("DS")):
             pass  #print "Skipping upload of " + lookupKey + " because it had no bytecode (likely a abstract class/interface)."
         else:
             raise Exception(
                 "Contract: " + lookupKey +
                 " has no bytecode, but this is not expected. It probably doesn't implement all its abstract methods"
             )
         return None
     if signatureKey not in ContractsFixture.signatures:
         ContractsFixture.signatures[signatureKey] = self.generateSignature(
             resolvedPath)
     signature = ContractsFixture.signatures[signatureKey]
     contractTranslator = ContractTranslator(signature)
     if len(constructorArgs) > 0:
         compiledCode += contractTranslator.encode_constructor_arguments(
             constructorArgs)
     contractAddress = bytesToHexString(
         self.chain.contract(compiledCode, language='evm'))
     contract = ABIContract(self.chain, contractTranslator, contractAddress)
     self.contracts[lookupKey] = contract
     return (contract)
Ejemplo n.º 13
0
 def upload(self, relativeFilePath, lookupKey = None, signatureKey = None, constructorArgs=[]):
     resolvedPath = resolveRelativePath(relativeFilePath)
     lookupKey = lookupKey if lookupKey else path.splitext(path.basename(resolvedPath))[0]
     signatureKey = signatureKey if signatureKey else lookupKey
     if lookupKey in self.contracts:
         return(self.contracts[lookupKey])
     compiledCode = ContractsFixture.getCompiledCode(resolvedPath)
     # abstract contracts have a 0-length array for bytecode
     if len(compiledCode) == 0:
         print "Skipping upload of " + lookupKey + " because it had no bytecode (likely a abstract class/interface)."
         return None
     if signatureKey not in ContractsFixture.signatures:
         ContractsFixture.signatures[signatureKey] = ContractsFixture.generateSignature(resolvedPath)
     signature = ContractsFixture.signatures[signatureKey]
     contractTranslator = ContractTranslator(signature)
     if len(constructorArgs) > 0:
         compiledCode += contractTranslator.encode_constructor_arguments(constructorArgs)
     contractAddress = bytesToHexString(self.chain.contract(compiledCode, language='evm', startgas=long(6.7 * 10**6)))
     contract = ABIContract(self.chain, contractTranslator, contractAddress)
     self.contracts[lookupKey] = contract
     return(contract)
Ejemplo n.º 14
0
 def createYesNoMarket(self,
                       universe,
                       endTime,
                       feeDivisor,
                       denominationToken,
                       oracle,
                       sender=tester.k0,
                       topic="",
                       description="description",
                       extraInfo=""):
     marketAddress = universe.createYesNoMarket(endTime,
                                                feeDivisor,
                                                denominationToken.address,
                                                oracle,
                                                topic,
                                                description,
                                                extraInfo,
                                                sender=sender)
     assert marketAddress
     market = ABIContract(
         self.chain,
         ContractTranslator(ContractsFixture.signatures['Market']),
         marketAddress)
     return market
Ejemplo n.º 15
0
def reputationToken(kitchenSinkFixture, kitchenSinkSnapshot):
    return ABIContract(kitchenSinkFixture.chain, kitchenSinkSnapshot['reputationToken'].translator, kitchenSinkSnapshot['reputationToken'].address)
Ejemplo n.º 16
0
def auction(kitchenSinkFixture, kitchenSinkSnapshot):
    return ABIContract(kitchenSinkFixture.chain, kitchenSinkSnapshot['auction'].translator, kitchenSinkSnapshot['auction'].address)
Ejemplo n.º 17
0
def scalarMarket(kitchenSinkFixture, kitchenSinkSnapshot):
    return ABIContract(kitchenSinkFixture.chain, kitchenSinkSnapshot['scalarMarket'].translator, kitchenSinkSnapshot['scalarMarket'].address)
Ejemplo n.º 18
0
def testNetDenominationToken(kitchenSinkFixture, kitchenSinkSnapshot):
    return ABIContract(
        kitchenSinkFixture.chain,
        kitchenSinkSnapshot['testNetDenominationToken'].translator,
        kitchenSinkSnapshot['testNetDenominationToken'].address)
Ejemplo n.º 19
0
def market(localFixture, kitchenSinkSnapshot):
    return ABIContract(localFixture.chain,
                       kitchenSinkSnapshot['yesNoMarket'].translator,
                       kitchenSinkSnapshot['yesNoMarket'].address)
Ejemplo n.º 20
0
def universe(localFixture, kitchenSinkSnapshot):
    return ABIContract(localFixture.chain,
                       kitchenSinkSnapshot['universe'].translator,
                       kitchenSinkSnapshot['universe'].address)
def guardFactory(localFixture, kitchenSinkSnapshot):
    return ABIContract(localFixture.chain, kitchenSinkSnapshot['DSGuardFactory'].translator, kitchenSinkSnapshot['DSGuardFactory'].address)
def medianizer(localFixture, kitchenSinkSnapshot):
    return ABIContract(localFixture.chain, kitchenSinkSnapshot['Medianizer'].translator, kitchenSinkSnapshot['Medianizer'].address)
Ejemplo n.º 23
0
def localSnapshot(fixture, kitchenSinkSnapshot):
    fixture.resetToSnapshot(kitchenSinkSnapshot)
    universe = ABIContract(fixture.chain,
                           kitchenSinkSnapshot['universe'].translator,
                           kitchenSinkSnapshot['universe'].address)
    market = ABIContract(fixture.chain,
                         kitchenSinkSnapshot['binaryMarket'].translator,
                         kitchenSinkSnapshot['binaryMarket'].address)
    categoricalMarket = ABIContract(
        fixture.chain, kitchenSinkSnapshot['categoricalMarket'].translator,
        kitchenSinkSnapshot['categoricalMarket'].address)
    scalarMarket = ABIContract(fixture.chain,
                               kitchenSinkSnapshot['scalarMarket'].translator,
                               kitchenSinkSnapshot['scalarMarket'].address)

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

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

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

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

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

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

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

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

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

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

    return fixture.createSnapshot()
Ejemplo n.º 27
0
def categoricalMarket(localFixture, kitchenSinkSnapshot):
    return ABIContract(localFixture.chain,
                       kitchenSinkSnapshot['categoricalMarket'].translator,
                       kitchenSinkSnapshot['categoricalMarket'].address)
Ejemplo n.º 28
0
def localFixture(fixture, localSnapshot, kitchenSinkSnapshot):
    fixture.resetToSnapshot(localSnapshot)

    market = ABIContract(fixture.chain,
                         kitchenSinkSnapshot['binaryMarket'].translator,
                         kitchenSinkSnapshot['binaryMarket'].address)
    categoricalMarket = ABIContract(
        fixture.chain, kitchenSinkSnapshot['categoricalMarket'].translator,
        kitchenSinkSnapshot['categoricalMarket'].address)
    scalarMarket = ABIContract(fixture.chain,
                               kitchenSinkSnapshot['scalarMarket'].translator,
                               kitchenSinkSnapshot['scalarMarket'].address)
    universe = ABIContract(fixture.chain,
                           kitchenSinkSnapshot['universe'].translator,
                           kitchenSinkSnapshot['universe'].address)
    reputationToken = fixture.applySignature('ReputationToken',
                                             universe.getReputationToken())
    reportingWindow = fixture.applySignature('ReportingWindow',
                                             market.getReportingWindow())

    # Skip to Designated Reporting
    fixture.chain.head_state.timestamp = market.getEndTime() + 1

    # Designated Report on each market
    designatedReportCost = universe.getOrCacheDesignatedReportStake()
    totalDesignatedReportCostInWindow = designatedReportCost * 3
    with TokenDelta(
            reputationToken, 0, tester.a0,
            "Doing the designated report didn't deduct REP correctly or didn't award the no show bond"
    ):
        with StakeDelta(
                designatedReportCost, totalDesignatedReportCostInWindow, 0,
                market, reportingWindow,
                "Doing the designated report din't adjust stake accounting correctly"
        ):
            fixture.designatedReport(market, [0, market.getNumTicks()],
                                     tester.k0)
            fixture.designatedReport(
                categoricalMarket,
                [0, 0, categoricalMarket.getNumTicks()], tester.k0)
            fixture.designatedReport(scalarMarket,
                                     [0, scalarMarket.getNumTicks()],
                                     tester.k0)

    return fixture
Ejemplo n.º 29
0
def zeroX(localFixture, kitchenSinkSnapshot):
    return ABIContract(localFixture.chain,
                       kitchenSinkSnapshot['zeroX'].translator,
                       kitchenSinkSnapshot['zeroX'].address)
def universe(localFixture, localSnapshot):
    return ABIContract(localFixture.chain,
                       localSnapshot['universe'].translator,
                       localSnapshot['universe'].address)
Ejemplo n.º 31
0
def cash(localFixture, kitchenSinkSnapshot):
    return ABIContract(localFixture.chain,
                       kitchenSinkSnapshot['cash'].translator,
                       kitchenSinkSnapshot['cash'].address)
def market(localFixture, localSnapshot):
    return ABIContract(localFixture.chain, localSnapshot['market'].translator,
                       localSnapshot['market'].address)