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.eth') ens.setup_name(name, address) assert ens.name(address) == normalized_name # check that the correct namehash is set: node = Web3.toBytes(hexstr=namehash_hex) assert ens.resolver(normalized_name).caller.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_set_address(ens, name, full_name, namehash_hex, TEST_ADDRESS): assert ens.address(name) is None owner = ens.owner('tester.eth') ens.setup_address(name, TEST_ADDRESS) assert is_same_address(ens.address(name), TEST_ADDRESS) namehash = Web3.toBytes(hexstr=namehash_hex) normal_name = ens.nameprep(full_name) assert is_same_address(ens.address(name), TEST_ADDRESS) # check that the correct namehash is set: assert is_same_address( ens.resolver(normal_name).caller.addr(namehash), TEST_ADDRESS) # check that the correct owner is set: assert ens.owner(name) == owner ens.setup_address(name, None) assert ens.address(name) is None
def test_to_bytes_text(val, expected): assert Web3.toBytes(text=val) == expected
def test_to_bytes_hexstr(val, expected): assert Web3.toBytes(hexstr=val) == expected
def test_to_bytes_primitive(val, expected): assert Web3.toBytes(val) == expected