30
30
HexBytes ,
31
31
)
32
32
33
+ from web3 ._utils .ens import (
34
+ ens_addresses ,
35
+ )
33
36
from web3 .exceptions import (
34
37
BlockNotFound ,
35
38
InvalidAddress ,
39
+ NameNotFound ,
36
40
TransactionNotFound ,
37
41
)
38
42
from web3 .types import ( # noqa: F401
@@ -136,12 +140,35 @@ def test_eth_getBalance_with_block_identifier(self, web3: "Web3") -> None:
136
140
assert is_integer (later_balance )
137
141
assert later_balance > genesis_balance
138
142
143
+ @pytest .mark .parametrize ('address, expect_success' , [
144
+ ('test-address.eth' , True ),
145
+ ('not-an-address.eth' , False )
146
+ ])
147
+ def test_eth_getBalance_with_ens_name (
148
+ self , web3 : "Web3" , address : ChecksumAddress , expect_success : bool
149
+ ) -> None :
150
+ with ens_addresses (web3 , {'test-address.eth' : web3 .eth .accounts [0 ]}):
151
+ if expect_success :
152
+ balance = web3 .eth .getBalance (address )
153
+ assert is_integer (balance )
154
+ assert balance >= 0
155
+ else :
156
+ with pytest .raises (NameNotFound ):
157
+ web3 .eth .getBalance (address )
158
+
139
159
def test_eth_getStorageAt (
140
160
self , web3 : "Web3" , emitter_contract_address : ChecksumAddress
141
161
) -> None :
142
162
storage = web3 .eth .getStorageAt (emitter_contract_address , 0 )
143
163
assert isinstance (storage , HexBytes )
144
164
165
+ def test_eth_getStorageAt_ens_name (
166
+ self , web3 : "Web3" , emitter_contract_address : ChecksumAddress
167
+ ) -> None :
168
+ with ens_addresses (web3 , {'emitter.eth' : emitter_contract_address }):
169
+ storage = web3 .eth .getStorageAt ('emitter.eth' , 0 )
170
+ assert isinstance (storage , HexBytes )
171
+
145
172
def test_eth_getStorageAt_invalid_address (self , web3 : "Web3" ) -> None :
146
173
coinbase = web3 .eth .coinbase
147
174
with pytest .raises (InvalidAddress ):
@@ -154,6 +181,14 @@ def test_eth_getTransactionCount(
154
181
assert is_integer (transaction_count )
155
182
assert transaction_count >= 0
156
183
184
+ def test_eth_getTransactionCount_ens_name (
185
+ self , web3 : "Web3" , unlocked_account_dual_type : ChecksumAddress
186
+ ) -> None :
187
+ with ens_addresses (web3 , {'unlocked-acct-dual-type.eth' : unlocked_account_dual_type }):
188
+ transaction_count = web3 .eth .getTransactionCount ('unlocked-acct-dual-type.eth' )
189
+ assert is_integer (transaction_count )
190
+ assert transaction_count >= 0
191
+
157
192
def test_eth_getTransactionCount_invalid_address (self , web3 : "Web3" ) -> None :
158
193
coinbase = web3 .eth .coinbase
159
194
with pytest .raises (InvalidAddress ):
@@ -208,6 +243,16 @@ def test_eth_getCode(self, web3: "Web3", math_contract_address: ChecksumAddress)
208
243
assert isinstance (code , HexBytes )
209
244
assert len (code ) > 0
210
245
246
+ def test_eth_getCode_ens_address (
247
+ self , web3 : "Web3" , math_contract_address : ChecksumAddress
248
+ ) -> None :
249
+ with ens_addresses (
250
+ web3 , {'mathcontract.eth' : math_contract_address }
251
+ ):
252
+ code = web3 .eth .getCode ('mathcontract.eth' )
253
+ assert isinstance (code , HexBytes )
254
+ assert len (code ) > 0
255
+
211
256
def test_eth_getCode_invalid_address (self , web3 : "Web3" , math_contract : "Contract" ) -> None :
212
257
with pytest .raises (InvalidAddress ):
213
258
web3 .eth .getCode (ChecksumAddress (HexAddress (HexStr (math_contract .address .lower ()))))
@@ -251,6 +296,16 @@ def test_eth_sign(self, web3: "Web3", unlocked_account_dual_type: ChecksumAddres
251
296
)
252
297
assert new_signature != signature
253
298
299
+ def test_eth_sign_ens_names (
300
+ self , web3 : "Web3" , unlocked_account_dual_type : ChecksumAddress
301
+ ) -> None :
302
+ with ens_addresses (web3 , {'unlocked-acct.eth' : unlocked_account_dual_type }):
303
+ signature = web3 .eth .sign (
304
+ 'unlocked-acct.eth' , text = 'Message tö sign. Longer than hash!'
305
+ )
306
+ assert is_bytes (signature )
307
+ assert len (signature ) == 32 + 32 + 1
308
+
254
309
def test_eth_signTypedData (
255
310
self ,
256
311
web3 : "Web3" ,
@@ -374,6 +429,27 @@ def test_eth_signTransaction(self, web3: "Web3", unlocked_account: ChecksumAddre
374
429
assert result ['tx' ]['gasPrice' ] == txn_params ['gasPrice' ]
375
430
assert result ['tx' ]['nonce' ] == txn_params ['nonce' ]
376
431
432
+ def test_eth_signTransaction_ens_names (
433
+ self , web3 : "Web3" , unlocked_account : ChecksumAddress
434
+ ) -> None :
435
+ with ens_addresses (web3 , {'unlocked-account.eth' : unlocked_account }):
436
+ txn_params : TxParams = {
437
+ 'from' : 'unlocked-account.eth' ,
438
+ 'to' : 'unlocked-account.eth' ,
439
+ 'value' : Wei (1 ),
440
+ 'gas' : Wei (21000 ),
441
+ 'gasPrice' : web3 .eth .gasPrice ,
442
+ 'nonce' : Nonce (0 ),
443
+ }
444
+ result = web3 .eth .signTransaction (txn_params )
445
+ signatory_account = web3 .eth .account .recover_transaction (result ['raw' ])
446
+ assert unlocked_account == signatory_account
447
+ assert result ['tx' ]['to' ] == unlocked_account
448
+ assert result ['tx' ]['value' ] == txn_params ['value' ]
449
+ assert result ['tx' ]['gas' ] == txn_params ['gas' ]
450
+ assert result ['tx' ]['gasPrice' ] == txn_params ['gasPrice' ]
451
+ assert result ['tx' ]['nonce' ] == txn_params ['nonce' ]
452
+
377
453
def test_eth_sendTransaction_addr_checksum_required (
378
454
self , web3 : "Web3" , unlocked_account : ChecksumAddress
379
455
) -> None :
0 commit comments