chainlib-eth/tests/test_event.py

39 lines
897 B
Python

# 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,
n.to_bytes(32, byteorder='big'),
]
data = [
(b'\xee' * 32),
]
dec.apply(topics, data)
o = dec.decode()
self.assertEqual(o[0], 42)
self.assertEqual(o[1], data[0].hex())
if __name__ == '__main__':
unittest.main()