Add test for addresses index, rcpt

This commit is contained in:
lash
2022-03-01 16:05:00 +00:00
parent 4a8b162cde
commit 50804f4d70
2 changed files with 86 additions and 34 deletions

View File

@@ -39,7 +39,12 @@ class TestCache(EthTesterCase):
super(TestCache, self).setUp()
fp = tempfile.mkdtemp()
self.cache_dir = fp
self.store = FileStore(self.chain_spec, cache_root=self.cache_dir)
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)
@@ -64,7 +69,6 @@ class TestCache(EthTesterCase):
def test_tx(self):
logg.debug('tx {}'.format(self.tx))
self.store.put_tx(self.tx, include_data=True)
j = self.store.get_tx(self.tx.hash)
tx = json.loads(j)
@@ -72,7 +76,6 @@ class TestCache(EthTesterCase):
def test_block(self):
logg.debug('tx {}'.format(self.tx))
self.store.put_block(self.block, include_data=True)
block_hash = strip_0x(self.block.hash)
j = self.store.get_block(block_hash)
@@ -81,6 +84,57 @@ class TestCache(EthTesterCase):
self.assertEqual(retrieved_block_hash, block_hash)
def test_block_number(self):
self.store.put_block(self.block, include_data=True)
block_hash = strip_0x(self.block.hash)
block_number = int(self.block.number)
j = self.store.get_block_number(block_number)
block = json.loads(j)
retrieved_block_hash = strip_0x(block['hash'])
self.assertEqual(retrieved_block_hash, block_hash)
def test_rcpt(self):
self.store.put_tx(self.tx, include_data=True)
j = self.store.get_rcpt(self.tx.hash)
rcpt = json.loads(j)
self.assertTrue(is_same_address(rcpt['transaction_hash'], self.tx.hash))
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)
if __name__ == '__main__':
unittest.main()