Example #1
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
Example #2
0
def package_with_multiple_matches(w3, tmpdir, valid_package):
    w3.testing.mine(5)
    chain_id = get_chain_id(w3)
    block = w3.eth.getBlock("latest")
    block_uri = create_block_uri(w3.toHex(chain_id), w3.toHex(block.hash))
    w3.testing.mine(1)
    second_block = w3.eth.getBlock("latest")
    second_block_uri = create_block_uri(w3.toHex(chain_id),
                                        w3.toHex(second_block.hash))
    package = copy.deepcopy(valid_package)
    package['deployments'][block_uri] = {
        "SafeMathLib": {
            "contract_type":
            "SafeMathLib",
            "address":
            "0x8d2c532d7d211816a2807a411f947b211569b68c",
            "transaction":
            "0xaceef751507a79c2dee6aa0e9d8f759aa24aab081f6dcf6835d792770541cb2b",
            "block":
            "0x420cb2b2bd634ef42f9082e1ee87a8d4aeeaf506ea5cdeddaa8ff7cbf911810c"
        }
    }
    package['deployments'][second_block_uri] = {
        "SafeMathLib": {
            "contract_type":
            "SafeMathLib",
            "address":
            "0x8d2c532d7d211816a2807a411f947b211569b68c",
            "transaction":
            "0xaceef751507a79c2dee6aa0e9d8f759aa24aab081f6dcf6835d792770541cb2b",
            "block":
            "0x420cb2b2bd634ef42f9082e1ee87a8d4aeeaf506ea5cdeddaa8ff7cbf911810c"
        }
    }
    return package
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
Example #4
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)
Example #5
0
def lockfile_with_multiple_matches(w3, tmpdir):
    w3.testing.mine(5)
    chain_id = get_chain_id(w3)
    block = w3.eth.getBlock("latest")
    block_uri = create_block_uri(w3.toHex(chain_id), w3.toHex(block.hash))
    w3.testing.mine(1)
    second_block = w3.eth.getBlock("latest")
    second_block_uri = create_block_uri(w3.toHex(chain_id),
                                        w3.toHex(second_block.hash))
    lockfile = copy.deepcopy(LOCKFILE)
    lockfile['deployments'][block_uri] = {
        "SafeMathLib": {
            "contract_type":
            "SafeMathLib",
            "address":
            "0x8d2c532d7d211816a2807a411f947b211569b68c",
            "transaction":
            "0xaceef751507a79c2dee6aa0e9d8f759aa24aab081f6dcf6835d792770541cb2b",
            "block":
            "0x420cb2b2bd634ef42f9082e1ee87a8d4aeeaf506ea5cdeddaa8ff7cbf911810c"
        }
    }
    lockfile['deployments'][second_block_uri] = {
        "SafeMathLib": {
            "contract_type":
            "SafeMathLib",
            "address":
            "0x8d2c532d7d211816a2807a411f947b211569b68c",
            "transaction":
            "0xaceef751507a79c2dee6aa0e9d8f759aa24aab081f6dcf6835d792770541cb2b",
            "block":
            "0x420cb2b2bd634ef42f9082e1ee87a8d4aeeaf506ea5cdeddaa8ff7cbf911810c"
        }
    }
    f = tmpdir.join("lockfile.json")
    f.write(json.dumps(lockfile))
    return str(f)
Example #6
0
def manifest_with_no_matching_deployments(w3, tmpdir, safe_math_manifest):
    w3.testing.mine(5)
    incorrect_chain_id = (b'\x00' * 31 + b'\x01')
    block = w3.eth.getBlock("earliest")
    block_uri = create_block_uri(w3.toHex(incorrect_chain_id), w3.toHex(block.hash))
    manifest = copy.deepcopy(safe_math_manifest)
    manifest["deployments"][block_uri] = {
      "SafeMathLib": {
        "contract_type": "SafeMathLib",
        "address": "0x8d2c532d7d211816a2807a411f947b211569b68c",
        "transaction": "0xaceef751507a79c2dee6aa0e9d8f759aa24aab081f6dcf6835d792770541cb2b",
        "block": "0x420cb2b2bd634ef42f9082e1ee87a8d4aeeaf506ea5cdeddaa8ff7cbf911810c"
      }
    }
    return manifest