chainlib-eth

Ethereum implementation of the chainlib interface
Info | Log | Files | Refs | README | LICENSE

test_stat.py (1607B)


      1 # standard imports
      2 import unittest
      3 import datetime
      4 import os
      5 
      6 # external imports
      7 from chainlib.stat import ChainStat
      8 from chainlib.eth.block import Block
      9 
     10 
     11 class TestStat(unittest.TestCase):
     12 
     13     def test_block(self):
     14 
     15         s = ChainStat()
     16  
     17         d = datetime.datetime.utcnow() - datetime.timedelta(seconds=30)
     18         block_a = Block({
     19             'timestamp': d.timestamp(),
     20             'hash': None,
     21             'transactions': [],
     22             'number': 41,
     23             'author': os.urandom(20).hex(),
     24             'gas_used': '0x1234',
     25             'gas_limit': '0x2345',
     26             'parent_hash': None,
     27             })
     28 
     29         d = datetime.datetime.utcnow()
     30         block_b = Block({
     31             'timestamp': d.timestamp(),
     32             'hash': None,
     33             'transactions': [],
     34             'number': 42,
     35             'author': os.urandom(20).hex(),
     36             'gas_used': '0x1234',
     37             'gas_limit': '0x2345',
     38             'parent_hash': None,
     39             })
     40 
     41         s.block_apply(block_a)
     42         s.block_apply(block_b)
     43         self.assertEqual(s.block_average(), 30.0)
     44 
     45         d = datetime.datetime.utcnow() + datetime.timedelta(seconds=10)
     46         block_c = Block({
     47             'timestamp': d.timestamp(),
     48             'hash': None,
     49             'transactions': [],
     50             'number': 43,
     51             'author': os.urandom(20).hex(),
     52             'gas_used': '0x1234',
     53             'gas_limit': '0x2345',
     54             'parent_hash': None,
     55             })
     56 
     57         s.block_apply(block_c)
     58         self.assertEqual(s.block_average(), 20.0)
     59 
     60 
     61 if __name__ == '__main__':
     62     unittest.main()