2021-10-11 15:28:09 +02:00
|
|
|
# standard imports
|
|
|
|
import unittest
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import json
|
2021-10-15 12:48:14 +02:00
|
|
|
import sys
|
2021-10-11 15:28:09 +02:00
|
|
|
|
|
|
|
# external imports
|
|
|
|
from hexathon import strip_0x
|
|
|
|
|
|
|
|
# local imports
|
2021-10-11 19:13:21 +02:00
|
|
|
from cic import Proof
|
2021-10-11 15:28:09 +02:00
|
|
|
from cic.processor import Processor
|
2021-10-11 17:39:01 +02:00
|
|
|
from cic.attachment import Attachment
|
2021-10-11 15:28:09 +02:00
|
|
|
from cic.meta import Meta
|
2021-10-15 12:48:14 +02:00
|
|
|
from cic.output import KVWriter
|
2021-10-11 15:28:09 +02:00
|
|
|
|
|
|
|
# test imports
|
|
|
|
from tests.base_cic import (
|
|
|
|
TestCICBase,
|
|
|
|
test_data_dir,
|
2021-10-11 19:13:21 +02:00
|
|
|
root_merged_hash,
|
|
|
|
root_unmerged_hash,
|
2021-10-11 15:28:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
logg = logging.getLogger()
|
2021-10-15 12:48:14 +02:00
|
|
|
logg.setLevel(logging.DEBUG)
|
|
|
|
|
2021-10-11 15:28:09 +02:00
|
|
|
|
|
|
|
class MockExt:
|
|
|
|
|
|
|
|
def __init__(self, address):
|
|
|
|
self.address = address
|
|
|
|
|
|
|
|
def process(self):
|
|
|
|
return self.address
|
|
|
|
|
|
|
|
|
|
|
|
class TestCICProcessor(TestCICBase):
|
|
|
|
|
2021-10-11 17:39:01 +02:00
|
|
|
def test_processor_meta(self):
|
2021-10-11 15:28:09 +02:00
|
|
|
fp = os.path.join(test_data_dir, 'proof')
|
|
|
|
m = Meta(fp)
|
|
|
|
m.load()
|
|
|
|
|
|
|
|
mock_ext = MockExt(self.token_address)
|
|
|
|
p = Processor(metadata=m, outputs_writer=self.outputs_writer, extensions=[mock_ext])
|
2021-10-15 12:48:14 +02:00
|
|
|
p.token_address = self.token_address
|
2021-10-11 15:28:09 +02:00
|
|
|
p.process()
|
|
|
|
|
|
|
|
meta_reference = m.reference(self.token_address)
|
|
|
|
|
|
|
|
fp = os.path.join(self.outputs_dir, meta_reference)
|
|
|
|
f = open(fp, 'r')
|
|
|
|
o = json.load(f)
|
|
|
|
f.close()
|
|
|
|
self.assertEqual(m.asdict(), o)
|
2021-10-11 17:39:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_processor_attachment(self):
|
|
|
|
fp = os.path.join(test_data_dir, 'proof')
|
|
|
|
m = Attachment(fp)
|
|
|
|
m.load()
|
|
|
|
|
|
|
|
mock_ext = MockExt(self.token_address)
|
|
|
|
p = Processor(attachment=m, outputs_writer=self.outputs_writer, extensions=[mock_ext])
|
|
|
|
p.process()
|
|
|
|
|
2021-10-15 12:48:14 +02:00
|
|
|
|
2021-10-11 17:39:01 +02:00
|
|
|
for k in list(m.contents.keys()):
|
|
|
|
os.stat(fp)
|
2021-10-11 15:28:09 +02:00
|
|
|
|
2021-10-11 19:13:21 +02:00
|
|
|
|
|
|
|
def test_processor_proof_noattachment(self):
|
|
|
|
fp = os.path.join(test_data_dir, 'proof')
|
|
|
|
m = Proof(fp)
|
|
|
|
m.load()
|
|
|
|
|
|
|
|
mock_ext = MockExt(self.token_address)
|
|
|
|
p = Processor(proof=m, outputs_writer=self.outputs_writer, extensions=[mock_ext])
|
|
|
|
p.process()
|
|
|
|
|
|
|
|
self.assertEqual(p.outputs[0], root_unmerged_hash)
|
|
|
|
|
|
|
|
|
|
|
|
def test_processor_proof_attachment(self):
|
|
|
|
fp = os.path.join(test_data_dir, 'proof')
|
|
|
|
|
|
|
|
ma = Attachment(fp)
|
|
|
|
ma.load()
|
|
|
|
|
|
|
|
mp = Proof(fp, attachments=ma)
|
|
|
|
mp.load()
|
|
|
|
|
|
|
|
mock_ext = MockExt(self.token_address)
|
|
|
|
p = Processor(proof=mp, outputs_writer=self.outputs_writer, extensions=[mock_ext])
|
|
|
|
p.process()
|
|
|
|
|
|
|
|
self.assertEqual(p.outputs[0], root_merged_hash)
|
|
|
|
|
|
|
|
|
2021-10-11 15:28:09 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|