示例#1
0
def create_latest_block_uri(w3: Web3, tx_receipt: TxReceipt) -> URI:
    """
    Creates a new block uri from data in w3 and provided tx_receipt.
    """
    chain_id = to_hex(get_genesis_block_hash(w3))
    block_hash = to_hex(tx_receipt.blockHash)
    return create_block_uri(chain_id, block_hash)
示例#2
0
def manifest_with_multiple_matches(w3, tmpdir, safe_math_manifest):
    w3.testing.mine(5)
    genesis_hash = get_genesis_block_hash(w3)
    block = w3.eth.getBlock("latest")
    block_uri = create_block_uri(w3.toHex(genesis_hash), w3.toHex(block.hash))
    w3.testing.mine(1)
    second_block = w3.eth.getBlock("latest")
    second_block_uri = create_block_uri(w3.toHex(genesis_hash),
                                        w3.toHex(second_block.hash))
    manifest = copy.deepcopy(safe_math_manifest)
    manifest["deployments"][block_uri] = {
        "SafeMathLib": {
            "contract_type":
            "SafeMathLib",
            "address":
            "0x8d2c532d7d211816a2807a411f947b211569b68c",
            "transaction":
            "0xaceef751507a79c2dee6aa0e9d8f759aa24aab081f6dcf6835d792770541cb2b",
            "block":
            "0x420cb2b2bd634ef42f9082e1ee87a8d4aeeaf506ea5cdeddaa8ff7cbf911810c",
        }
    }
    manifest["deployments"][second_block_uri] = {
        "SafeMathLib": {
            "contract_type":
            "SafeMathLib",
            "address":
            "0x8d2c532d7d211816a2807a411f947b211569b68c",
            "transaction":
            "0xaceef751507a79c2dee6aa0e9d8f759aa24aab081f6dcf6835d792770541cb2b",
            "block":
            "0x420cb2b2bd634ef42f9082e1ee87a8d4aeeaf506ea5cdeddaa8ff7cbf911810c",
        }
    }
    return manifest
def test_insert_deployment(escrow_deployer):
    w3 = escrow_deployer.package.w3
    escrow_package = escrow_deployer.package
    init_deployment_data = {
        "contract_type": "Escrow",
        "address": "0x",
        "transaction": "0x",
        "block": "0x",
    }
    new_deployment_data = {
        "contract_type": "Escrow",
        "address": "0x123",
        "transaction": "0x123",
        "block": "0x123",
    }
    genesis_hash = to_hex(get_genesis_block_hash(w3))
    w3.testing.mine(1)
    init_block_hash = to_hex(w3.eth.getBlock("latest")["hash"])
    init_block_uri = create_block_uri(genesis_hash, init_block_hash)
    alt_block_uri = init_block_uri[:15] + "yxz123" + init_block_uri[21:]
    init_block_deployment_data = {
        init_block_uri: {
            "Other": {
                "x": "x"
            },
            "Escrow": init_deployment_data
        },
        alt_block_uri: {
            "alt": {
                "x": "x"
            }
        },
    }
    w3.testing.mine(1)
    new_block_hash = to_hex(w3.eth.getBlock("latest")["hash"])
    new_block_uri = create_block_uri(genesis_hash, new_block_hash)
    escrow_package.manifest = assoc(escrow_package.manifest, "deployments",
                                    init_block_deployment_data)
    updated_manifest = insert_deployment(escrow_package, "Escrow",
                                         new_deployment_data, new_block_uri)
    expected_deployments_data = {
        new_block_uri: {
            "Other": {
                "x": "x"
            },
            "Escrow": new_deployment_data
        },
        alt_block_uri: {
            "alt": {
                "x": "x"
            }
        },
    }
    assert updated_manifest["deployments"] == expected_deployments_data
def chain_setup(w3):
    old_chain_id = remove_0x_prefix(to_hex(get_genesis_block_hash(w3)))
    block_hash = remove_0x_prefix(to_hex(w3.eth.getBlock("earliest").hash))
    old_chain_uri = f"blockchain://{old_chain_id}/block/{block_hash}"
    match_data = {
        old_chain_uri: {
            "x": "x"
        },
        f"blockchain://1234/block/{block_hash}": {
            "x": "x"
        },
    }
    no_match_data = {
        f"blockchain://56775ac59d0774e6b603a79c4218efeb5653b99ba0ff14db983bac2662251a8a/block/{block_hash}":
        {  # noqa: E501
            "x": "x"
        }
    }
    return w3, match_data, no_match_data, old_chain_uri