def bytes32(val): if isinstance(val, int): result = Web3.toBytes(val) else: raise TypeError('val %r could not be converted to bytes') if len(result) < 32: return result.rjust(32, b'\0') else: return result
def test_setup_name(ens, name, normalized_name, namehash_hex): address = ens.web3.eth.accounts[3] assert not ens.name(address) owner = ens.owner('tester') ens.setup_name(name, address) assert ens.name(address) == normalized_name # check that .eth is only appended if guess_tld is True if ens.nameprep(name) != normalized_name: assert ens.address(name, guess_tld=False) is None # check that the correct namehash is set: node = Web3.toBytes(hexstr=namehash_hex) assert ens.resolver(normalized_name).addr(node) == address # check that the correct owner is set: assert ens.owner(name) == owner ens.setup_name(None, address) ens.setup_address(name, None) assert not ens.name(address) assert not ens.address(name)
def test_to_bytes_hexstr(val, expected): assert Web3.toBytes(hexstr=val) == expected
def test_to_bytes_text(val, expected): assert Web3.toBytes(text=val) == expected
def test_to_bytes_primitive(val, expected): assert Web3.toBytes(val) == expected