コード例 #1
0
ファイル: test_sha3.py プロジェクト: irchain/webu.py
def test_sha3_raise_if_primitive_and(kwargs):
    # must not set more than one input
    with pytest.raises(TypeError):
        Webu.sha3('', **kwargs)
コード例 #2
0
ファイル: test_sha3.py プロジェクト: irchain/webu.py
def test_sha3_primitive_invalid(primitive, exception):
    with pytest.raises(exception):
        Webu.sha3(primitive)
コード例 #3
0
ファイル: test_sha3.py プロジェクト: irchain/webu.py
def test_sha3_primitive(primitive, digest):
    assert Webu.sha3(primitive) == digest
コード例 #4
0
ファイル: test_sha3.py プロジェクト: irchain/webu.py
def test_sha3_hexstr(hexstr, digest):
    assert Webu.sha3(hexstr=hexstr) == digest
コード例 #5
0
ファイル: test_sha3.py プロジェクト: irchain/webu.py
def test_sha3_text(message, digest):
    assert Webu.sha3(text=message) == digest
コード例 #6
0
ファイル: test_sha3.py プロジェクト: irchain/webu.py
def test_sha3_raise_if_no_args():
    with pytest.raises(TypeError):
        Webu.sha3()
コード例 #7
0
ファイル: test_sha3.py プロジェクト: irchain/webu.py
def test_sha3_raise_if_hexstr_and_text():
    with pytest.raises(TypeError):
        Webu.sha3(hexstr='0x', text='')
コード例 #8
0
def ens_setup():
    w3 = Webu(HappyUCTesterProvider(HappyUCTester()))

    # ** Set up ENS contracts **

    # remove account that creates ENS, so test transactions don't have write access
    accounts = w3.eth.accounts
    ens_key = accounts.pop()

    # create ENS contract
    eth_labelhash = w3.sha3(text='eth')
    eth_namehash = bytes32(0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae)
    resolver_namehash = bytes32(0xfdd5d5de6dd63db72bbc2d487944ba13bf775b50a80805fe6fcaba9b0fba88f5)
    reverse_tld_namehash = bytes32(0xa097f6721ce401e757d1223a763fef49b8b5f90bb18567ddb86fd205dff71d34)  # noqa: E501
    reverser_namehash = bytes32(0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2)
    ens_contract = deploy(w3, ENSFactory, ens_key)

    # create public resolver
    public_resolver = deploy(w3, PublicResolverFactory, ens_key, args=[ens_contract.address])

    # set 'resolver.eth' to resolve to public resolver
    ens_contract.functions.setSubnodeOwner(
        b'\0' * 32,
        eth_labelhash,
        ens_key
    ).transact({'from': ens_key})

    ens_contract.functions.setSubnodeOwner(
        eth_namehash,
        w3.sha3(text='resolver'),
        ens_key
    ).transact({'from': ens_key})

    ens_contract.functions.setResolver(
        resolver_namehash,
        public_resolver.address
    ).transact({'from': ens_key})

    public_resolver.functions.setAddr(
        resolver_namehash,
        public_resolver.address
    ).transact({'from': ens_key})

    # create .eth auction registrar
    eth_registrar = deploy(
        w3,
        ETHRegistrarFactory,
        ens_key,
        args=[ens_contract.address, eth_namehash, 1],
    )

    # set '.eth' to resolve to the registrar
    ens_contract.functions.setResolver(
        eth_namehash,
        public_resolver.address
    ).transact({'from': ens_key})

    public_resolver.functions.setAddr(
        eth_namehash,
        eth_registrar.address
    ).transact({'from': ens_key})

    # create reverse resolver
    reverse_resolver = deploy(w3, DefaultReverseResolver, ens_key, args=[ens_contract.address])

    # create reverse registrar
    reverse_registrar = deploy(
        w3,
        ReverseRegistrar,
        ens_key,
        args=[ens_contract.address, reverse_resolver.address]
    )

    # set 'addr.reverse' to resolve to reverse registrar
    ens_contract.functions.setSubnodeOwner(
        b'\0' * 32,
        w3.sha3(text='reverse'),
        ens_key
    ).transact({'from': ens_key})

    ens_contract.functions.setSubnodeOwner(
        reverse_tld_namehash,
        w3.sha3(text='addr'),
        ens_key
    ).transact({'from': ens_key})

    ens_contract.functions.setResolver(
        reverser_namehash,
        public_resolver.address
    ).transact({'from': ens_key})

    public_resolver.functions.setAddr(
        reverser_namehash,
        reverse_registrar.address
    ).transact({'from': ens_key})

    # set owner of tester.eth to an account controlled by tests
    ens_contract.functions.setSubnodeOwner(
        eth_namehash,
        w3.sha3(text='tester'),
        w3.eth.accounts[2]  # note that this does not have to be the default, only in the list
    ).transact({'from': ens_key})

    # make the registrar the owner of the 'eth' name
    ens_contract.functions.setSubnodeOwner(
        b'\0' * 32,
        eth_labelhash,
        eth_registrar.address
    ).transact({'from': ens_key})

    # make the reverse registrar the owner of the 'addr.reverse' name
    ens_contract.functions.setSubnodeOwner(
        reverse_tld_namehash,
        w3.sha3(text='addr'),
        reverse_registrar.address
    ).transact({'from': ens_key})

    return ENS.fromWebu(w3, ens_contract.address)