def test_deploy_contract_operation_with_arguments(web3, chain,
                                                  WITH_CONSTRUCTOR_ARGUMENTS):
    deploy_contract_operation = DeployContract(
        'WithConstructorArguments',
        timeout=30,
        arguments=[12345, 'a-string-argument-thats-32-bytes'],
    )

    operation_receipt = deploy_contract_operation.execute(
        chain=chain,
        compiled_contracts={
            'WithConstructorArguments': WITH_CONSTRUCTOR_ARGUMENTS
        },
    )
    deploy_txn_hash = operation_receipt['deploy-transaction-hash']
    contract_address = chain.wait.for_contract_address(deploy_txn_hash,
                                                       timeout=30)

    code = web3.eth.getCode(contract_address)

    assert code == WITH_CONSTRUCTOR_ARGUMENTS['code_runtime']

    ContractFactory = web3.eth.contract(**WITH_CONSTRUCTOR_ARGUMENTS)
    contract = ContractFactory(address=contract_address)

    assert contract.call().data_a() == 12345
    assert contract.call().data_b() == 'a-string-argument-thats-32-bytes'
def test_deploy_contract_failure_during_deployment(web3, chain, THROWER):
    deploy_contract_operation = DeployContract(
        'Thrower',
        timeout=30,
        arguments=[True],
    )

    with pytest.raises(TransactionFailed):
        deploy_contract_operation.execute(
            chain=chain,
            compiled_contracts={'Thrower': THROWER},
        )
def test_deploy_contract_failure_during_deployment(web3, chain, THROWER):
    deploy_contract_operation = DeployContract(
        'Thrower',
        timeout=30,
        arguments=[True],
    )

    with pytest.raises(ValueError):
        deploy_contract_operation.execute(
            chain=chain,
            compiled_contracts={'Thrower': THROWER},
        )
def test_deploy_contract_operation_on_math_contract(web3, chain, MATH):
    deploy_contract_operation = DeployContract('Math', timeout=30)

    operation_receipt = deploy_contract_operation.execute(
        chain=chain,
        compiled_contracts={'Math': MATH},
    )
    deploy_txn_hash = operation_receipt['deploy-transaction-hash']
    contract_address = chain.wait.for_contract_address(deploy_txn_hash, timeout=30)

    code = web3.eth.getCode(contract_address)

    assert code == MATH['code_runtime']
def test_deploy_contract_operation_on_math_contract(web3, chain, MATH):
    deploy_contract_operation = DeployContract('Math', timeout=30)

    operation_receipt = deploy_contract_operation.execute(
        chain=chain,
        compiled_contracts={'Math': MATH},
    )
    deploy_txn_hash = operation_receipt['deploy-transaction-hash']
    contract_address = chain.wait.for_contract_address(deploy_txn_hash,
                                                       timeout=30)

    code = web3.eth.getCode(contract_address)

    assert code == MATH['code_runtime']
예제 #6
0
 class Migration0001(Migration):
     migration_id = '0001_deploy_v1_math'
     dependencies = []
     operations = [
         DeployContract('Math'),
     ]
     compiled_contracts = {
         'Math': MATH,
     }
예제 #7
0
 class Migration0003(Migration):
     migration_id = '0003_deploy_alternate_math'
     dependencies = ['0002_deploy_v2_math']
     operations = [
         DeployContract('Math', contract_registrar_name='FancyMath'),
     ]
     compiled_contracts = {
         'Math': MATH,
     }
예제 #8
0
def test_deployment_linking_with_provided_address(library_13,
                                                  verify_multiply_13_linked):
    deploy_operation = DeployContract(
        'Multiply13',
        timeout=30,
        libraries={
            'Library13': library_13.address,
        },
    )

    verify_multiply_13_linked(deploy_operation)
    class TestMigration(Migration):
        migration_id = '0001_initial'
        dependencies = []

        operations = [
            DeployContract('Math'),
        ]

        compiled_contracts = {
            'Math': {
                'code': MATH['code'],
                'code_runtime': MATH['code_runtime'],
                'abi': MATH['abi'],
            },
        }
def test_deploy_contract_operation_with_arguments(web3, chain,
                                                  WITH_CONSTRUCTOR_ARGUMENTS):
    deploy_contract_operation = DeployContract(
        'WithConstructorArguments',
        timeout=30,
        arguments=[12345, 'a-string-argument-thats-32-bytes'],
    )

    operation_receipt = deploy_contract_operation.execute(
        chain=chain,
        compiled_contracts={'WithConstructorArguments': WITH_CONSTRUCTOR_ARGUMENTS},
    )
    deploy_txn_hash = operation_receipt['deploy-transaction-hash']
    contract_address = chain.wait.for_contract_address(deploy_txn_hash, timeout=30)

    code = web3.eth.getCode(contract_address)

    assert code == WITH_CONSTRUCTOR_ARGUMENTS['code_runtime']

    ContractFactory = web3.eth.contract(**WITH_CONSTRUCTOR_ARGUMENTS)
    contract = ContractFactory(address=contract_address)

    assert contract.call().data_a() == 12345
    assert contract.call().data_b() == 'a-string-argument-thats-32-bytes'
예제 #11
0
def test_deployment_linking_with_auto_lookup_from_registrar(
        deploy_chain, library_13, verify_multiply_13_linked):
    chain = deploy_chain
    web3 = chain.web3
    registrar = chain.registrar

    set_library_addr_txn_hash = registrar.transact().setAddress(
        'contract/Library13',
        library_13.address,
    )
    chain.wait.for_receipt(set_library_addr_txn_hash, timeout=30)

    deploy_operation = DeployContract(
        'Multiply13',
        timeout=30,
    )

    verify_multiply_13_linked(deploy_operation)
예제 #12
0
def test_deployment_linking_with_provided_registrar_value(
        deploy_chain, library_13, verify_multiply_13_linked):
    chain = deploy_chain
    web3 = chain.web3
    registrar = chain.registrar

    set_library_addr_txn_hash = registrar.transact().setAddress(
        'a-custom-key',
        library_13.address,
    )
    chain.wait.for_receipt(set_library_addr_txn_hash, timeout=30)

    deploy_operation = DeployContract(
        'Multiply13',
        timeout=30,
        libraries={
            'Library13': Address.defer(key='a-custom-key'),
        },
    )

    verify_multiply_13_linked(deploy_operation)