2021-06-28 07:48:36 +02:00
|
|
|
# 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(),
|
2021-06-28 07:48:36 +02:00
|
|
|
]
|
|
|
|
data = [
|
2021-06-28 09:10:53 +02:00
|
|
|
(b'\xee' * 32).hex(),
|
2021-06-28 07:48:36 +02:00
|
|
|
]
|
|
|
|
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])
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|