Add address index test

This commit is contained in:
lash 2022-03-01 18:54:36 +00:00
parent 06a4852fe5
commit 5f7b23fa00
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 123 additions and 2 deletions

View File

@ -1,4 +1,4 @@
chainlib-eth>=0.1.0b1,<=0.1.0
chainlib-eth>=0.1.0b3,<=0.1.0
chainlib~=0.0.23
chainsyncer~=0.1.0
eth-erc20~=0.1.11

View File

@ -1,6 +1,6 @@
[metadata]
name = eth-monitor
version = 0.1.0a1
version = 0.1.0rc1
description = Monitor and cache transactions using match filters
author = Louis Holbrook
author_email = dev@holbrook.no

View File

@ -0,0 +1,5 @@
eth_tester==0.5.0b3
py-evm==0.3.0a20
rlp==2.0.1
pytest==6.0.1
coverage==5.5

116
tests/test_basic.py Normal file
View File

@ -0,0 +1,116 @@
# standard imports
import tempfile
import shutil
import unittest
import logging
import json
# external imports
from chainlib.chain import ChainSpec
from chainlib.eth.gas import (
Gas,
OverrideGasOracle,
)
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.eth.tx import (
transaction,
receipt,
TxFormat,
Tx,
)
from chainlib.eth.block import (
block_by_hash,
Block,
)
from chainlib.eth.address import is_same_address
from hexathon import strip_0x
from eth_monitor.index import AddressIndex
# local imports
from eth_cache.store.file import FileStore
from eth_cache.rpc import CacheRPC
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
class TestMonitor(EthTesterCase):
def setUp(self):
super(TestMonitor, self).setUp()
fp = tempfile.mkdtemp()
self.cache_dir = fp
class Applier:
def apply_rules_addresses(self, sender, recipient, address):
return True
self.store = FileStore(self.chain_spec, cache_root=self.cache_dir, address_rules=Applier())
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
gas_oracle = OverrideGasOracle(price=100000000000, limit=30000)
c = Gas(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash, o) = c.create(self.accounts[0], self.accounts[1], 1024)
r = self.rpc.do(o)
o = transaction(tx_hash)
tx_src = self.rpc.do(o)
o = receipt(tx_hash)
rcpt_src = self.rpc.do(o)
o = block_by_hash(tx_src['block_hash'])
block_src = self.rpc.do(o)
self.block = Block(block_src)
self.tx = Tx(tx_src, block=self.block, rcpt=rcpt_src)
self.cache_rpc = CacheRPC(None, self.store)
def tearDown(self):
shutil.rmtree(self.cache_dir)
def test_address(self):
nonce_oracle = RPCNonceOracle(self.accounts[2], self.rpc)
gas_oracle = OverrideGasOracle(price=100000000000, limit=30000)
c = Gas(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash, o) = c.create(self.accounts[2], self.accounts[1], 1024)
r = self.rpc.do(o)
o = transaction(tx_hash)
tx_src = self.rpc.do(o)
o = block_by_hash(tx_src['block_hash'])
block_src = self.rpc.do(o)
block = Block(block_src)
tx = Tx(tx_src, block=block)
self.store.put_tx(tx, include_data=True)
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
c = Gas(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash, o) = c.create(self.accounts[1], self.accounts[0], 1024)
r = self.rpc.do(o)
o = transaction(tx_hash)
tx_src = self.rpc.do(o)
o = block_by_hash(tx_src['block_hash'])
block_src = self.rpc.do(o)
block = Block(block_src)
tx = Tx(tx_src, block=block)
self.store.put_tx(tx, include_data=True)
address = strip_0x(self.accounts[1])
txs = self.store.get_address_tx(address)
self.assertEqual(len(txs), 2)
idx = AddressIndex(self.cache_rpc, self.store)
idx.load_address_tx(self.accounts[0])
addrs = idx.get_address(self.accounts[0])
self.assertEqual(len(addrs), 1)
if __name__ == '__main__':
unittest.main()