def test_eth_getCode_ens_address( self, web3: "Web3", math_contract_address: ChecksumAddress) -> None: with ens_addresses(web3, {'mathcontract.eth': math_contract_address}): code = web3.eth.getCode('mathcontract.eth') assert isinstance(code, HexBytes) assert len(code) > 0
def test_eth_getTransactionCount_ens_name( self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: with ens_addresses(web3, {'unlocked-acct-dual-type.eth': unlocked_account_dual_type}): transaction_count = web3.eth.getTransactionCount('unlocked-acct-dual-type.eth') assert is_integer(transaction_count) assert transaction_count >= 0
def test_eth_sign_ens_names( self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress) -> None: with ens_addresses(web3, {'unlocked-acct.eth': unlocked_account_dual_type}): signature = web3.eth.sign( 'unlocked-acct.eth', text='Message tö sign. Longer than hash!') assert is_bytes(signature) assert len(signature) == 32 + 32 + 1
def test_eth_getBalance_with_ens_name(self, web3: "Web3", address: ChecksumAddress, expect_success: bool) -> None: with ens_addresses(web3, {'test-address.eth': web3.eth.accounts[0]}): if expect_success: balance = web3.eth.getBalance(address) assert is_integer(balance) assert balance >= 0 else: with pytest.raises(NameNotFound): web3.eth.getBalance(address)
def test_send_transaction_with_invalid_ens_names(web3, to, _from): with ens_addresses(web3, [ ('registered-name-1.eth', web3.eth.accounts[1]), ]): transaction = { 'to': to, 'chainId': web3.eth.chainId, 'from': _from, } with pytest.raises(NameNotFound): web3.eth.sendTransaction(transaction)
def test_solidityKeccak_ens(self, web3, types, values, expected): with ens_addresses( web3, { 'one.eth': "0x49EdDD3769c0712032808D86597B84ac5c2F5614", 'two.eth': "0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5", }): # when called as class method, any name lookup attempt will fail with pytest.raises(InvalidAddress): Web3.solidityKeccak(types, values) # when called as instance method, ens lookups can succeed actual = web3.solidityKeccak(types, values) assert actual == expected
def test_send_transaction_with_ens_names(w3): with ens_addresses(w3, [('registered-name-1.eth', w3.eth.accounts[1]), ('registered-name-2.eth', w3.eth.accounts[0])]): transaction = { 'to': 'registered-name-1.eth', 'chainId': w3.eth.chain_id, 'from': 'registered-name-2.eth', } txn_hash = w3.eth.send_transaction(transaction) receipt = w3.eth.wait_for_transaction_receipt(txn_hash, timeout=RECEIPT_TIMEOUT) assert receipt.get('blockNumber') is not None
def test_contract_with_name_address_from_eth_contract( web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, math_addr, ): with ens_addresses(web3, [('thedao.eth', math_addr)]): mc = web3.eth.contract( address='thedao.eth', abi=MATH_ABI, bytecode=MATH_CODE, bytecode_runtime=MATH_RUNTIME, ) caller = mc.web3.eth.coinbase assert mc.address == 'thedao.eth' assert mc.functions.return13().call({'from': caller}) == 13
def test_solidityKeccak_ens( self, web3: "Web3", types: Sequence[TypeStr], values: Sequence[str], expected: HexBytes ) -> None: with ens_addresses(web3, { 'one.eth': ChecksumAddress( HexAddress(HexStr("0x49EdDD3769c0712032808D86597B84ac5c2F5614")) ), 'two.eth': ChecksumAddress( HexAddress(HexStr("0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5")) ), }): # when called as class method, any name lookup attempt will fail with pytest.raises(InvalidAddress): Web3.solidityKeccak(types, values) # when called as instance method, ens lookups can succeed actual = web3.solidityKeccak(types, values) assert actual == expected
def test_eth_signTransaction_ens_names( self, web3: "Web3", unlocked_account: ChecksumAddress) -> None: with ens_addresses(web3, {'unlocked-account.eth': unlocked_account}): txn_params: TxParams = { 'from': 'unlocked-account.eth', 'to': 'unlocked-account.eth', 'value': Wei(1), 'gas': Wei(21000), 'gasPrice': web3.eth.gasPrice, 'nonce': Nonce(0), } result = web3.eth.signTransaction(txn_params) signatory_account = web3.eth.account.recover_transaction( result['raw']) assert unlocked_account == signatory_account assert result['tx']['to'] == unlocked_account assert result['tx']['value'] == txn_params['value'] assert result['tx']['gas'] == txn_params['gas'] assert result['tx']['gasPrice'] == txn_params['gasPrice'] assert result['tx']['nonce'] == txn_params['nonce']
def test_eth_getStorageAt_ens_name( self, web3: "Web3", emitter_contract_address: ChecksumAddress) -> None: with ens_addresses(web3, {'emitter.eth': emitter_contract_address}): storage = web3.eth.getStorageAt('emitter.eth', 0) assert isinstance(storage, HexBytes)