init: block filter

This commit is contained in:
Mohamed Sohail 2022-12-20 20:05:03 +03:00
commit 0f7937d9b1
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
9 changed files with 69 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
dist
__pycache__
*.egg-info
*.pyc
*.d/
.venv

View File

@ -0,0 +1,2 @@
from .block_dialect_filter import CeloBlockDialectFilter
from .util import CeloUtil

View File

@ -0,0 +1,7 @@
from chainlib.dialect import DialectFilter as BaseDialectFilter
class CeloBlockDialectFilter(BaseDialectFilter):
def apply_src(self, src):
src['gas_limit'] = '0x0'
return src

View File

@ -0,0 +1,5 @@
from enum import Enum
class CeloUtil(Enum):
CHAIN_SPEC = 'evm:flan:44787:celo'

4
pytest.ini Normal file
View File

@ -0,0 +1,4 @@
[pytest]
log_cli = 1
log_cli_level = DEBUG
filterwarnings = ignore::DeprecationWarning

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
chainlib>=0.4.4
chainlib-eth>=0.4.8

1
test_requirements.txt Normal file
View File

@ -0,0 +1 @@
pytest~=7.2.0

8
tests/conftest.py Normal file
View File

@ -0,0 +1,8 @@
import pytest
from chainlib.eth.connection import (
EthHTTPConnection
)
from chainlib_eth_celo import CeloUtil
def pytest_configure():
pytest.conn = EthHTTPConnection(url='https://rpc.celo.grassecon.net', chain_spec=CeloUtil.CHAIN_SPEC)

34
tests/test_e2e.py Normal file
View File

@ -0,0 +1,34 @@
import logging
import pytest
from chainlib.eth.tx import (
transaction,
receipt,
Tx
)
from chainlib.eth.block import (
block_by_number,
Block
)
from chainlib_eth_celo import CeloBlockDialectFilter
logg = logging.getLogger(__name__)
def test_fetch_tx():
block = 15_237_555
hash = '0xd50cff848bc7ee304bab4763d3dcc00e6c900e1bdb955bfa836ad1ba2d74dde2'
block_query = block_by_number(block, include_tx=True)
block_resp = pytest.conn.do(block_query)
parsed_block = Block(block_resp, dialect_filter=CeloBlockDialectFilter())
tx_query = transaction(hash)
tx_resp = pytest.conn.do(tx_query)
receipt_query = receipt(hash)
tx_receipt_resp = pytest.conn.do(receipt_query)
full_parsed_tx = Tx(tx_resp, rcpt=tx_receipt_resp, block=parsed_block)
logg.debug('full_parsed_tx: \n{}'.format(full_parsed_tx.to_human()))
assert full_parsed_tx != None