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 _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) address = to_canonical_address(tx_receipt.contractAddress) # Create manifest copy with new deployment instance latest_block_uri = create_latest_block_uri(package.w3, tx_receipt) deployment_data = create_deployment_data(contract_name, address, 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)