Closed antazoey closed 10 months ago
OK, it seems like the line endpoints["eth"]["chainId"] = static_return(chain_id)
also updates the global API_ENDPOINTS
dict for some reason
Edit: turns out the issue was because API_ENDPOINTS is not copy-able, it is C stuff i think... so i fixed it by making a method in web3.py to return the api endpoints.
Yeah I think that, due to the functools methods that it uses as values, the dictionary is not deep-copyable and so it really only ever has references to the values. What a funky quirk you found that I've never ran into 😅 .
This would also work:
...
from toolz import merge
endpoints = {**API_ENDPOINTS}
endpoints["eth"] = merge(endpoints["eth"], {"chainId": static_return(chain_id)})
[edited after the correction below]
closing as it doesn't appear to be an issue with the library
endpoints = merge( API_ENDPOINTS, {"eth": {"chainId": static_return(chain_id)}}, )
This isn't quite right (just as FYI)! You lose the rest of eth
:
(Pdb) endpoints["eth"]
{'chainId': <function static_return.<locals>.inner at 0x11f876e60>}
I'll update with the correct code soon.
This is working I think:
def get_endpoints(chain_id: int):
# HACK: Until https://github.com/ethereum/web3.py/issues/3136 resolved.
eth_endpoints = merge(API_ENDPOINTS["eth"], {"chainId": static_return(chain_id)})
return merge(API_ENDPOINTS, {"eth": eth_endpoints})
Thanks @fselmo for your help! Hopefully if someone else encountered this issue, they find this GH issue!
Ah yes, I saw it on my end too. Thought I updated it here. I edited the original just in case anyone stumbles on it. Thanks for the nudge 👍🏼
pip freeze
outputWhat was wrong?
When trying to use multiple instances of web3 with different eth-testers, the API endpoints are not respected in each instance. Here is a simple repro:
notice the chain ID is the same for web3s even though they are separate instances. The API Endoints is not honored
How can it be fixed?
update: I was able to fix the issue by changing the defaults file to be like this:
and in my script, I call the method instead of using the constant, so i get a new object every time. Note: I tried using
copy
anddeepcopy
but those had other issues.Note: We prefer to use issues to track our work. If you think you've encountered a bug in web3py or have a feature request, you're in the right place. If you have implementation or usage questions, please refer to our documentation and/or join the conversation on discord.