Exemplo n.º 1
0
def test_build_create2_address_conform_to_EIP1014():
    """
    Tests out two examples given in https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1014.md
    """
    assert (build_create2_address(
        "0x0000000000000000000000000000000000000000",
        "0x00") == "0x4D1A2e2bB4F88F0250f26Ffff098B0b30B26BF38")
    assert (build_create2_address(
        Web3.toChecksumAddress("0x00000000000000000000000000000000deadbeef"),
        "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
        "0x00000000000000000000000000000000000000000000000000000000cafebabe",
    ) == "0x1d8bfDC5D46DC4f61D6b6115972536eBE6A8854C")
Exemplo n.º 2
0
def proxied_identity_contract_with_owner(
    proxy_factory,
    identity_implementation,
    get_proxy_initcode,
    owner,
    signature_of_owner_on_implementation,
    web3,
    contract_assets,
):
    constructor_args = [owner]
    identity_proxy_initcode = get_proxy_initcode(constructor_args)

    proxy_address = build_create2_address(proxy_factory.address,
                                          identity_proxy_initcode)

    proxy_factory.functions.deployProxy(
        identity_proxy_initcode,
        identity_implementation.address,
        signature_of_owner_on_implementation,
    ).transact()

    proxied_identity_contract = web3.eth.contract(
        address=proxy_address,
        abi=contract_assets["Identity"]["abi"],
        bytecode=contract_assets["Identity"]["bytecode"],
    )

    return proxied_identity_contract
Exemplo n.º 3
0
def test_clientlib_calculate_proxy_address(proxy_factory, get_proxy_initcode):
    """Give out some tests values for pre calculating the proxy address in the clientlib tests"""

    owner = "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf"
    identity_proxy_initcode = get_proxy_initcode([owner])

    assert proxy_factory.address == "0x8688966AE53807c273D8B9fCcf667F0A0a91b1d3"

    pre_computed_address = build_create2_address(proxy_factory.address,
                                                 identity_proxy_initcode)
    assert pre_computed_address == "0x7025175Ac3537be29f764bbeAB26d5f89b0F49aC"
Exemplo n.º 4
0
def test_meta_transaction_create_contract(
    each_identity,
    delegate,
    test_contract_initcode,
    test_contract_abi,
    web3,
    operation_type,
):
    deployed_contract_balance = 123
    meta_transaction = MetaTransaction(
        operation_type=operation_type,
        data=test_contract_initcode,
        value=deployed_contract_balance,
    )
    meta_transaction = each_identity.filled_and_signed_meta_transaction(
        meta_transaction)
    # It seems that web3 fails to estimate gas for deployment transactions
    tx_id = delegate.send_signed_meta_transaction(
        meta_transaction, transaction_options={"gas": 1_000_000})

    execution_event = each_identity.contract.events.TransactionExecution.createFilter(
        fromBlock=0).get_all_entries()[0]["args"]

    # assert that the create was successful
    assert get_transaction_status(web3, tx_id)
    assert execution_event["hash"] == meta_transaction.hash
    assert execution_event["status"] is True

    deploy_event = each_identity.contract.events.ContractDeployment.createFilter(
        fromBlock=0).get_all_entries()[0]["args"]
    deployed_contract = web3.eth.contract(deploy_event["deployed"],
                                          abi=test_contract_abi)

    # check that the contract was indeed deployed
    assert deployed_contract.functions.testPublicValue().call() == 123456
    assert web3.eth.getBalance(
        deployed_contract.address) == deployed_contract_balance

    if operation_type == MetaTransaction.OperationType.CREATE2:
        # check that create2 was used and we could pre-compute the deployed address
        create_2_address = build_create2_address(each_identity.address,
                                                 test_contract_initcode)
        assert deployed_contract.address == create_2_address
Exemplo n.º 5
0
def test_deploy_identity_proxy(
    web3,
    proxy_factory,
    identity_implementation,
    signature_of_owner_on_implementation,
    owner,
    get_proxy_initcode,
):
    proxy = deploy_proxied_identity(
        web3,
        proxy_factory.address,
        identity_implementation.address,
        signature_of_owner_on_implementation,
    )

    identity_proxy_initcode = get_proxy_initcode([owner])
    pre_computed_address = build_create2_address(proxy_factory.address,
                                                 identity_proxy_initcode)

    assert proxy.address == pre_computed_address
    assert proxy.functions.implementation().call(
    ) == identity_implementation.address
Exemplo n.º 6
0
def test_deploy_identity_proxy_at_precomputed_address(
    proxy_factory,
    identity_implementation,
    get_proxy_initcode,
    owner,
    signature_of_owner_on_implementation,
):
    """Test that we can deploy the proxy at a pre-computed address"""
    identity_proxy_initcode = get_proxy_initcode([owner])

    pre_computed_address = build_create2_address(proxy_factory.address,
                                                 identity_proxy_initcode)

    proxy_factory.functions.deployProxy(
        identity_proxy_initcode,
        identity_implementation.address,
        signature_of_owner_on_implementation,
    ).transact()

    deployement_event = proxy_factory.events.ProxyDeployment.getLogs()[0]
    identity_proxy_address = deployement_event["args"]["proxyAddress"]

    assert identity_proxy_address == pre_computed_address