Skip to content

Commit

Permalink
fix: added provider chain_id (#2)
Browse files Browse the repository at this point in the history
* fix: added provider chain_id

* fix: provide chain ID value

* fix: self._web3 and #type:ignore for mypy line 28

* fix: comma instead of dot

* fix: updated chain_id to @Property

* chore: upgrade version of ape core; drop support for Python 3.6

* lint: fixup isort

* test: add test to show provider functions and is integrated

Co-authored-by: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com>
  • Loading branch information
sabotagebeats and fubuloubu authored Aug 11, 2021
1 parent fce517e commit 355e24d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand All @@ -63,6 +63,8 @@ jobs:

- name: Run Tests
run: pytest -m "not fuzzing"
env:
WEB3_INFURA_PROJECT_ID: ${{ secrets.WEB3_INFURA_PROJECT_ID }}

# NOTE: uncomment this block after you've marked tests with @pytest.mark.fuzzing
# fuzzing:
Expand Down
7 changes: 5 additions & 2 deletions ape_infura/providers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
from typing import Iterator

from ape.api import ProviderAPI, ReceiptAPI, TransactionAPI
from web3 import HTTPProvider, Web3 # type: ignore
from web3.gas_strategies.rpc import rpc_gas_price_strategy

from ape.api import ProviderAPI, ReceiptAPI, TransactionAPI


class Infura(ProviderAPI):
_web3: Web3 = None # type: ignore
Expand All @@ -24,6 +23,10 @@ def disconnect(self):
def update_settings(self, new_settings: dict):
pass

@property
def chain_id(self) -> int:
return self._web3.eth.chain_id

def estimate_gas_cost(self, txn: TransactionAPI) -> int:
return self._web3.eth.estimate_gas(txn.as_dict()) # type: ignore

Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
url="https://github.com/ApeWorX/ape-infura",
include_package_data=True,
install_requires=[
"eth-ape>=0.1.0a14",
"eth-ape>=0.1.0a21",
"importlib-metadata ; python_version<'3.8'",
], # NOTE: Add 3rd party libraries here
python_requires=">=3.6,<4",
Expand All @@ -79,7 +79,6 @@
"Operating System :: MacOS",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ape import networks

from ape_infura.providers import Infura


def test_provider_works():
with networks.ethereum.mainnet.use_provider("infura") as provider:
assert isinstance(provider, Infura)
assert provider.get_balance("0x0000000000000000000000000000000000000000") > 0

0 comments on commit 355e24d

Please sign in to comment.