def test_get_contract_factory_with_no_dependencies(chain):
    provider = chain.provider

    MATH = chain.project.compiled_contract_data['Math']
    Math = provider.get_contract_factory('Math')

    assert hexbytes_to_hexstr(Math.bytecode) == MATH['bytecode']
    assert hexbytes_to_hexstr(Math.bytecode_runtime) == MATH['bytecode_runtime']
Exemple #2
0
def check_if_chain_matches_chain_uri(web3, blockchain_uri):
    chain_id, resource_type, resource_hash = parse_BIP122_uri(blockchain_uri)
    genesis_block = web3.eth.getBlock('earliest')
    if hexbytes_to_hexstr(genesis_block['hash']) != chain_id:
        return False

    if resource_type == BLOCK:
        resource = web3.eth.getBlock(resource_hash)
    elif resource_type == TRANSACTION:
        resource = web3.eth.getTransaction(resource_hash)
    else:
        raise ValueError(
            "Unsupported resource type: {0}".format(resource_type))

    if hexbytes_to_hexstr(resource['hash']) == resource_hash:
        return True
    else:
        return False
def test_it_uses_existing_library_dependencies(chain, library_13):
    provider = chain.provider
    registrar = chain.registrar

    registrar.set_contract_address('Library13', library_13.address)

    multiply_13, deploy_txn = provider.get_or_deploy_contract('Multiply13')
    assert multiply_13.functions.multiply13(3).call() == 39
    assert deploy_txn is not None

    chain_bytecode = chain.web3.eth.getCode(multiply_13.address)
    assert library_13.address[2:].lower() in hexbytes_to_hexstr(chain_bytecode)
def test_get_contract_factory_with_dependency(chain,
                                              library_13):
    provider = chain.provider
    registrar = chain.registrar

    registrar.set_contract_address('Library13', library_13.address)

    MULTIPLY_13 = chain.project.compiled_contract_data['Multiply13']
    Multiply13 = provider.get_contract_factory('Multiply13')

    expected_bytecode = link_bytecode_by_name(
        MULTIPLY_13['bytecode'],
        MULTIPLY_13['linkrefs'],
        Library13=library_13.address,
    )
    expected_runtime = link_bytecode_by_name(
        MULTIPLY_13['bytecode_runtime'],
        MULTIPLY_13['linkrefs_runtime'],
        Library13=library_13.address,
    )
    assert hexbytes_to_hexstr(Multiply13.bytecode) == expected_bytecode
    assert hexbytes_to_hexstr(Multiply13.bytecode_runtime) == expected_runtime
Exemple #5
0
def get_chain_definition(web3, min_block_number=0, num_confirmations=0):
    """
    Return the blockchain URI that
    """
    chain_id = get_chain_id(web3)
    latest_block = web3.eth.getBlock('latest')
    latest_block_number = latest_block['number']

    target_block_number = latest_block_number - num_confirmations
    if target_block_number < min_block_number:
        raise ValueError(
            "Cannot generate chain definition matching given constraints")

    block_for_definition = web3.eth.getBlock(target_block_number)
    block_hash_for_definition = hexbytes_to_hexstr(
        block_for_definition['hash'])

    return create_block_uri(chain_id, block_hash_for_definition)
Exemple #6
0
def get_chain_id(web3):
    return hexbytes_to_hexstr(web3.eth.getBlock(0)['hash'])
def test_getting_contract_data(chain, math):
    provider = chain.provider

    contract_data = provider.get_contract_data('Math')
    assert hexbytes_to_hexstr(math.bytecode) == contract_data['bytecode']