chainlib-eth/tests/test_event.py

39 lines
903 B
Python
Raw Permalink Normal View History

# standard imports
import unittest
import logging
# local imports
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.eth.contract import (
ABIContractLogDecoder,
ABIContractType,
)
logging.basicConfig(level=logging.DEBUG)
class TestContractLog(EthTesterCase):
def test_log(self):
dec = ABIContractLogDecoder()
dec.topic('TestEventOne')
dec.typ(ABIContractType.UINT256)
dec.typ(ABIContractType.BYTES32)
s = dec.get_method_signature()
n = 42
topics = [
s,
2021-06-28 09:10:53 +02:00
n.to_bytes(32, byteorder='big').hex(),
]
data = [
2021-06-28 09:10:53 +02:00
(b'\xee' * 32).hex(),
]
dec.apply(topics, data)
o = dec.decode()
self.assertEqual(o[0], 42)
2021-06-28 09:10:53 +02:00
self.assertEqual(o[1], data[0])
if __name__ == '__main__':
unittest.main()