chainlib-eth

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

test_event.py (896B)


      1 # standard imports
      2 import unittest
      3 import logging
      4 
      5 # local imports
      6 from chainlib.eth.unittest.ethtester import EthTesterCase
      7 from chainlib.eth.contract import (
      8         ABIContractLogDecoder,
      9         ABIContractType,
     10         )
     11 
     12 logging.basicConfig(level=logging.DEBUG)
     13 
     14 
     15 class TestContractLog(EthTesterCase):
     16 
     17     def test_log(self):
     18         dec = ABIContractLogDecoder()
     19         dec.topic('TestEventOne')
     20         dec.typ(ABIContractType.UINT256)
     21         dec.typ(ABIContractType.BYTES32)
     22         s = dec.get_signature()
     23         n = 42
     24         topics = [
     25                 s,
     26                 n.to_bytes(32, byteorder='big').hex(),
     27                 ]
     28         data = [
     29             (b'\xee' * 32).hex(),
     30                 ]
     31         dec.apply(topics, data)
     32         o = dec.decode()
     33         self.assertEqual(o[0], 42)
     34         self.assertEqual(o[1], data[0])
     35 
     36 
     37 if __name__ == '__main__':
     38     unittest.main()