Complete test and refactor for generic tx, result, block objects

This commit is contained in:
lash
2022-05-09 18:46:10 +00:00
parent a2168a50e3
commit 972535f1f9
5 changed files with 81 additions and 141 deletions

View File

@@ -1,6 +1,7 @@
# standard imports
import unittest
import datetime
import os
# external imports
from chainlib.stat import ChainStat
@@ -19,6 +20,7 @@ class TestStat(unittest.TestCase):
'hash': None,
'transactions': [],
'number': 41,
'author': os.urandom(20).hex(),
})
d = datetime.datetime.utcnow()
@@ -27,6 +29,7 @@ class TestStat(unittest.TestCase):
'hash': None,
'transactions': [],
'number': 42,
'author': os.urandom(20).hex(),
})
s.block_apply(block_a)
@@ -39,6 +42,7 @@ class TestStat(unittest.TestCase):
'hash': None,
'transactions': [],
'number': 43,
'author': os.urandom(20).hex(),
})
s.block_apply(block_c)

View File

@@ -30,6 +30,7 @@ from chainlib.eth.address import (
from hexathon import (
strip_0x,
add_0x,
same as hex_same,
)
from chainlib.eth.block import Block
@@ -58,6 +59,7 @@ class TxTestCase(EthTesterCase):
self.assertTrue(is_same_address(tx.inputs[0], tx_src['to']))
self.assertEqual(tx.value, tx_src['value'])
self.assertEqual(tx.nonce, tx_src['nonce'])
self.assertTrue(hex_same(tx.payload, tx_src['data']))
def test_tx_reciprocal(self):
@@ -127,6 +129,7 @@ class TxTestCase(EthTesterCase):
'number': 42,
'timestamp': 13241324,
'transactions': [],
'author': os.urandom(20).hex(),
})
with self.assertRaises(AttributeError):
tx = Tx(tx_data, block=block)
@@ -169,7 +172,9 @@ class TxTestCase(EthTesterCase):
'number': 42,
'timestamp': 13241324,
'transactions': [],
'author': os.urandom(20).hex(),
})
block.txs = [add_0x(tx_data['hash'])]
with self.assertRaises(ValueError):
tx = Tx(tx_data, rcpt=rcpt, block=block)