def test_call_address_reflector_single_name(address_reflector_contract, call):
    with contract_ens_addresses(
        address_reflector_contract,
        [("dennisthepeasant.eth", "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")],
    ):
        result = call(contract=address_reflector_contract,
                      contract_function='reflect',
                      func_args=['dennisthepeasant.eth'])
        assert result == '0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413'
def test_call_address_reflector_single_name(address_reflector_contract, call):
    with contract_ens_addresses(
        address_reflector_contract,
        [("dennisthepeasant.eth", "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")],
    ):
        result = call(contract=address_reflector_contract,
                      contract_function='reflect',
                      func_args=['dennisthepeasant.eth'])
        assert result == '0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413'
def test_init_with_ens_name_arg(w3, WithConstructorAddressArgumentsContract, call):
    with contract_ens_addresses(
        WithConstructorAddressArgumentsContract,
        [("arg-name.eth", "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")],
    ):
        address_contract = deploy(w3, WithConstructorAddressArgumentsContract, args=[
            "arg-name.eth",
        ])

    result = call(contract=address_contract,
                  contract_function='testAddr')
    assert result == "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"
Example #4
0
def test_contract_with_name_address_changing(MathContract, math_addr):
    # Contract address is validated once on creation
    with contract_ens_addresses(MathContract, [('thedao.eth', math_addr)]):
        mc = MathContract(address='thedao.eth')

    caller = mc.web3.eth.coinbase
    assert mc.address == 'thedao.eth'

    # what happens when name returns no address at all
    with contract_ens_addresses(mc, []):
        with pytest.raises(NameNotFound):
            mc.functions.return13().call({'from': caller})

    # what happens when name returns address to different contract
    with contract_ens_addresses(mc, [('thedao.eth', '0x' + '11' * 20)]):
        with pytest.raises(BadFunctionCallOutput):
            mc.functions.return13().call({'from': caller})

    # contract works again when name resolves correctly
    with contract_ens_addresses(mc, [('thedao.eth', math_addr)]):
        assert mc.functions.return13().call({'from': caller}) == 13
def test_init_with_ens_name_arg(web3, WithConstructorAddressArgumentsContract, call):
    with contract_ens_addresses(
        WithConstructorAddressArgumentsContract,
        [("arg-name.eth", "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")],
    ):
        address_contract = deploy(web3, WithConstructorAddressArgumentsContract, args=[
            "arg-name.eth",
        ])

    result = call(contract=address_contract,
                  contract_function='testAddr')
    assert result == "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"
Example #6
0
def test_contract_with_name_address_changing(MathContract, math_addr):
    # Contract address is validated once on creation
    with contract_ens_addresses(MathContract, [('thedao.eth', math_addr)]):
        mc = MathContract(address='thedao.eth')

    caller = mc.web3.eth.coinbase
    assert mc.address == 'thedao.eth'

    # what happen when name returns no address at all
    with contract_ens_addresses(mc, []):
        with pytest.raises(NameNotFound):
            mc.functions.return13().call({'from': caller})

    # what happen when name returns address to different contract
    with contract_ens_addresses(mc, [('thedao.eth', '0x' + '11' * 20)]):
        with pytest.raises(BadFunctionCallOutput):
            mc.functions.return13().call({'from': caller})

    # contract works again when name resolves correctly
    with contract_ens_addresses(mc, [('thedao.eth', math_addr)]):
        assert mc.functions.return13().call({'from': caller}) == 13
def test_call_address_reflector_name_array(address_reflector_contract, call):
    names = [
        'autonomouscollective.eth',
        'wedonthavealord.eth',
    ]
    addresses = [
        '0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413',
        '0xFeC2079e80465cc8C687fFF9EE6386ca447aFec4',
    ]

    with contract_ens_addresses(address_reflector_contract, zip(names, addresses)):
        result = call(contract=address_reflector_contract,
                      contract_function='reflect',
                      func_args=[names])

    assert addresses == result
def test_call_address_reflector_name_array(address_reflector_contract, call):
    names = [
        'autonomouscollective.eth',
        'wedonthavealord.eth',
    ]
    addresses = [
        '0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413',
        '0xFeC2079e80465cc8C687fFF9EE6386ca447aFec4',
    ]

    with contract_ens_addresses(address_reflector_contract, zip(names, addresses)):
        result = call(contract=address_reflector_contract,
                      contract_function='reflect',
                      func_args=[names])

    assert addresses == result
def test_call_reject_invalid_ens_name(address_reflector_contract, call):
    with contract_ens_addresses(address_reflector_contract, []):
        with pytest.raises(ValueError):
            call(contract=address_reflector_contract,
                 contract_function='reflect',
                 func_args=['type0.eth'])
Example #10
0
def test_contract_with_name_address(MathContract, math_addr):
    with contract_ens_addresses(MathContract, [('thedao.eth', math_addr)]):
        mc = MathContract(address='thedao.eth')
        caller = mc.web3.eth.coinbase
        assert mc.address == 'thedao.eth'
        assert mc.functions.return13().call({'from': caller}) == 13
Example #11
0
def test_contract_with_unset_address(MathContract):
    with contract_ens_addresses(MathContract, []):
        with pytest.raises(NameNotFound):
            MathContract(address='unsetname.eth')
def test_call_reject_invalid_ens_name(address_reflector_contract, call):
    with contract_ens_addresses(address_reflector_contract, []):
        with pytest.raises(ValueError):
            call(contract=address_reflector_contract,
                 contract_function='reflect',
                 func_args=['type0.eth'])
Example #13
0
def test_contract_with_name_address(MathContract, math_addr):
    with contract_ens_addresses(MathContract, [('thedao.eth', math_addr)]):
        mc = MathContract(address='thedao.eth')
        caller = mc.web3.eth.coinbase
        assert mc.address == 'thedao.eth'
        assert mc.functions.return13().call({'from': caller}) == 13
Example #14
0
def test_contract_with_unset_address(MathContract):
    with contract_ens_addresses(MathContract, []):
        with pytest.raises(NameNotFound):
            MathContract(address='unsetname.eth')