eth-cache

Ethereum chain data caching tools
Log | Files | Refs | LICENSE

commit 182e7e2bb244a98b8bb92f8057b1070e46d82189
parent 3671d458a857eb552c91b2cef7db06608eccdc02
Author: lash <dev@holbrook.no>
Date:   Tue, 18 Jun 2024 02:52:14 +0100

Add lmdb cacherpc lmdb test

Diffstat:
Mtests/test_lmdb.py | 34++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+), 0 deletions(-)

diff --git a/tests/test_lmdb.py b/tests/test_lmdb.py @@ -5,9 +5,18 @@ import json # external imports from chainlib.eth.address import is_same_address from hexathon import strip_0x +from chainlib.eth.block import ( + block_by_hash, + block_by_number, + ) +from chainlib.eth.tx import ( + transaction, + ) + # local imports from eth_cache.store.lmdb import LmdbStore +from eth_cache.rpc import CacheRPC from tests.util import TestCache @@ -43,5 +52,30 @@ class TestCacheBasic(TestCache): self.assertEqual(retrieved_block_hash, block_hash) + def test_block(self): + self.store.put_block(self.block, include_data=True) + block_hash = strip_0x(self.block.hash) + j = self.store.get_block(block_hash) + block = json.loads(j) + retrieved_block_hash = strip_0x(block['hash']) + self.assertEqual(retrieved_block_hash, block_hash) + + + def test_cache_rpc(self): + rpc = CacheRPC(None, self.store) + + o = block_by_hash(self.block.hash) + block_src = self.rpc.do(o) + self.assertEqual(block_src['hash'], self.block.hash) + + o = block_by_number(self.block.number) + block_src = self.rpc.do(o) + self.assertEqual(block_src['hash'], self.block.hash) + + o = transaction(self.tx.hash) + tx_src = self.rpc.do(o) + self.assertTrue(is_same_address(tx_src['hash'], self.tx.hash)) + + if __name__ == '__main__': unittest.main()