Пример #1
0
def _deploy(
    contract_name: str, args: Any, transaction: Dict[str, Any], package: Package
) -> Tuple[Package, Address]:
    # Deploy new instance
    factory = package.get_contract_factory(contract_name)
    if not factory.linked_references and factory.unlinked_references:
        raise LinkerError(
            f"Contract factory: {contract_name} is missing runtime link references, which are "
            "necessary to populate manifest deployments that have a link reference. If using the "
            "builder tool, use `contract_type(..., runtime_bytecode=True)`."
        )
    tx_hash = factory.constructor(*args).transact(transaction)
    tx_receipt = package.w3.eth.waitForTransactionReceipt(tx_hash)
    # Create manifest copy with new deployment instance
    latest_block_uri = create_latest_block_uri(package.w3, 0)
    deployment_data = create_deployment_data(
        contract_name,
        to_checksum_address(tx_receipt.contractAddress),
        tx_receipt,
        factory.linked_references,
    )
    manifest = insert_deployment(
        package, contract_name, deployment_data, latest_block_uri
    )
    logger.info("%s deployed." % contract_name)
    return Package(manifest, package.w3)
Пример #2
0
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",
    }
    w3.testing.mine(1)
    init_block_uri = create_latest_block_uri(w3, 0)
    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_uri = create_latest_block_uri(w3, 0)
    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