Make callback filter test pass

This commit is contained in:
lash 2022-04-21 06:40:53 +00:00
parent 0ce75da8fd
commit b4c53d41a9
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 36 additions and 9 deletions

View File

@ -1 +1 @@
from .filter import *

View File

@ -17,16 +17,15 @@ from hexathon import (
)
from eth_erc20 import ERC20
from erc20_faucet import Faucet
from chainsyncer.filter import SyncFilter
from cic_eth.eth.meta import ExtendedTx
# local imports
#from cic_eth.eth.meta import ExtendedTx
#from cic_eth.encode import tx_normalize
from cic_sync_filter.parse import (
parse_transfer,
parse_transferfrom,
parse_giftto,
)
from cic_sync_filter import SyncFilter
logg = logging.getLogger(__name__)
@ -89,8 +88,8 @@ class CallbackFilter(SyncFilter):
return (transfer_type, transfer_data)
def filter(self, conn, block, tx, db_session=None):
super(CallbackFilter, self).filter(conn, block, tx, db_session)
def filter(self, conn, block, tx):
super(CallbackFilter, self).filter(conn, block, tx)
transfer_data = None
transfer_type = None
try:

21
cic_sync_filter/filter.py Normal file
View File

@ -0,0 +1,21 @@
# external imports
from chainsyncer.filter import SyncFilter as BaseSyncFilter
class SyncFilter(BaseSyncFilter):
def __init__(self):
self.exec_count = 0
self.match_count = 0
def filter(self, conn, block, tx):
self.exec_count += 1
def register_match(self):
self.match_count += 1
def to_logline(self, block, tx, v):
return '{} exec {} match {} block {} tx {}: {}'.format(self, self.exec_count, self.match_count, block.number, tx.index, v)

View File

@ -1,4 +1,12 @@
# external imports
from eth_erc20 import ERC20
from erc20_faucet import Faucet
from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.encode import TxHexNormalizer
from hexathon import add_0x
tx_normalize = TxHexNormalizer()
def parse_transfer(tx, conn, chain_spec, caller_address=ZERO_ADDRESS):
if not tx.payload:

View File

@ -1,9 +1,8 @@
#from chainlib.eth.pytest import *
#from cic_eth_registry.pytest import *
from cic_eth_registry.pytest.fixtures_tokens import *
#from pytest_cic.fixtures_database import *
from cic_eth.pytest.fixtures_database import *
from cic_eth.pytest.fixtures_contract import *
from cic_eth.pytest.fixtures_config import *
from cic_eth.pytest.fixtures_token import *
from chainlib.eth.pytest import *

View File

@ -229,7 +229,7 @@ def test_callback_filter_filter(
mock = CallbackMock()
fltr.call_back = mock.call_back
fltr.filter(eth_rpc, mockblock, tx, init_database)
fltr.filter(eth_rpc, mockblock, tx) #, init_database)
assert mock.results.get('transfer') != None
assert mock.results['transfer']['destination_token'] == strip_0x(foo_token)