-
Notifications
You must be signed in to change notification settings - Fork 1
Update: update etherscan url to v2 from v1 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import importlib | ||
| import os | ||
| import sys | ||
|
|
||
| import pytest | ||
| from web3 import Web3 | ||
|
|
@@ -11,6 +13,32 @@ | |
| ] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def provider_with_etherscan_env(mocker): | ||
| mocker.patch.dict( | ||
| os.environ, | ||
| { | ||
| "ETHERSCAN_URL": "https://{domain}/v2/api?apikey={token}&", | ||
|
||
| "ETHERSCAN_TOKEN": "abc123", | ||
| "ETHERSCAN_DOMAIN": "api.etherscan.io", | ||
| }, | ||
| ) | ||
| sys.modules.pop("ethproto.wrappers", None) | ||
| sys.modules.pop("ethproto.w3wrappers", None) | ||
| wrappers = importlib.import_module("ethproto.wrappers") | ||
| w3wrappers = importlib.import_module("ethproto.w3wrappers") | ||
|
|
||
| w3wrappers.register_w3_provider("w3_test", Web3(Web3.EthereumTesterProvider())) | ||
| provider = wrappers.get_provider("w3_test") | ||
|
|
||
| return provider | ||
|
|
||
|
|
||
| class DummyWrapper: | ||
| address = "0x8e3aab1fc53e8b0f5d987c20b1899a2db3b2f95c" # random generated address | ||
| contract = type("Contract", (), {"address": address})() | ||
|
|
||
|
|
||
| class Counter(wrappers.ETHWrapper): | ||
| eth_contract = "Counter" | ||
| # libraries_required = [] | ||
|
|
@@ -182,3 +210,24 @@ def test_sign_and_send_interact_with_existing_contract(sign_and_send): | |
| assert connected.value() == 1 | ||
|
|
||
| assert counter.value() == 1 # sanity check | ||
|
|
||
|
|
||
| def test_get_etherscan_url_v2_format(provider_with_etherscan_env): | ||
| provider = provider_with_etherscan_env | ||
| assert provider.get_etherscan_url() == "https://api.etherscan.io/v2/api?apikey=abc123&" | ||
|
|
||
|
|
||
| def test_get_first_block_makes_request(provider_with_etherscan_env, requests_mock): | ||
| provider = provider_with_etherscan_env | ||
| address = "0x8e3aab1fc53e8b0f5d987c20b1899a2db3b2f95c" # random generated address | ||
| chain_id = provider.w3.eth.chain_id | ||
|
|
||
| requests_mock.get( | ||
| f"https://api.etherscan.io/v2/api?apikey=abc123&" | ||
| f"chainid={chain_id}&module=account&action=txlist&address={address}&startblock=0&" | ||
| "endblock=99999999&page=1&offset=10&sort=asc", | ||
| json={"status": "1", "message": "OK", "result": [{"blockNumber": "1"}]}, | ||
| ) | ||
|
|
||
| block = provider.get_first_block(DummyWrapper()) | ||
| assert block == 1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ extras = | |
| testing | ||
| deps = | ||
| warrant @ git+https://github.com/gnarvaja/warrant.git#egg=warrant | ||
| requests-mock | ||
|
||
| commands = | ||
| pytest --block-network {posargs} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acá ya tendría que incluir el chainId también. Que
get_etherscan_urllo complete.