From 1fce3245d8e74794e8df5e4788c2cd9452dd0576 Mon Sep 17 00:00:00 2001 From: nolash Date: Mon, 11 Oct 2021 19:13:21 +0200 Subject: [PATCH] Add tests for merged and unmerged processing including proofs --- cic/processor.py | 7 +++++-- tests/base_cic.py | 6 ++++++ tests/test_processor.py | 32 ++++++++++++++++++++++++++++++++ tests/test_proof.py | 8 ++------ 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/cic/processor.py b/cic/processor.py index bac2a46..a2ecb62 100644 --- a/cic/processor.py +++ b/cic/processor.py @@ -6,12 +6,13 @@ logg = logging.getLogger(__name__) class Processor: - def __init__(self, outputs_writer=None, metadata=None, attachment=None, extensions=[]): + def __init__(self, proof=None, attachment=None, metadata=None, outputs_writer=None, extensions=[]): self.token_address = None self.extensions = extensions self.cores = { 'metadata': metadata, 'attachment': attachment, + 'proof': proof, } self.outputs = [] self.__outputs_writer = outputs_writer @@ -31,8 +32,9 @@ class Processor: def process(self): tasks = [ - 'metadata', + 'proof', 'attachment', + 'metadata', ] for ext in self.extensions: @@ -45,3 +47,4 @@ class Processor: continue v = a.process(token_address=token_address, writer=self.__outputs_writer) self.outputs.append(v) + diff --git a/tests/base_cic.py b/tests/base_cic.py index 2630639..1e7d7aa 100644 --- a/tests/base_cic.py +++ b/tests/base_cic.py @@ -19,6 +19,12 @@ logg = logging.getLogger(__name__) test_base_dir = os.path.dirname(os.path.realpath(__file__)) test_data_dir = os.path.join(test_base_dir, 'testdata') +proof_hash = '0f6fc017f29caf512c0feaaf83bc10614b488311cace2973dc248dc24b01e04f' +foo_hash = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' +bar_hash = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9' +root_merged_hash = '1b38b0e9a2cc0895c72e5f460a613bb0f3d88c4a87c1ee2b39a41c64f1dbcd1e' +root_unmerged_hash = '86d0091b98635a45da472388a1204104d7d10ea1199c1bd9c1d235de73a2c285' + class TestCICBase(unittest.TestCase): diff --git a/tests/test_processor.py b/tests/test_processor.py index 3fbd8b2..b3e6ddf 100644 --- a/tests/test_processor.py +++ b/tests/test_processor.py @@ -8,6 +8,7 @@ import json from hexathon import strip_0x # local imports +from cic import Proof from cic.processor import Processor from cic.attachment import Attachment from cic.meta import Meta @@ -16,6 +17,8 @@ from cic.meta import Meta from tests.base_cic import ( TestCICBase, test_data_dir, + root_merged_hash, + root_unmerged_hash, ) logging.basicConfig(level=logging.DEBUG) @@ -63,5 +66,34 @@ class TestCICProcessor(TestCICBase): fp = os.path.join(self.outputs_dir, k) os.stat(fp) + + 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) + + if __name__ == '__main__': unittest.main() diff --git a/tests/test_proof.py b/tests/test_proof.py index 689b9f4..8e28179 100644 --- a/tests/test_proof.py +++ b/tests/test_proof.py @@ -11,17 +11,13 @@ from cic.attachment import Attachment from tests.base_cic import ( test_data_dir, TestCICBase, + root_merged_hash, + root_unmerged_hash, ) logging.basicConfig(level=logging.DEBUG) logg = logging.getLogger() -proof_hash = '0f6fc017f29caf512c0feaaf83bc10614b488311cace2973dc248dc24b01e04f' -foo_hash = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' -bar_hash = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9' -root_merged_hash = '1b38b0e9a2cc0895c72e5f460a613bb0f3d88c4a87c1ee2b39a41c64f1dbcd1e' -root_unmerged_hash = '86d0091b98635a45da472388a1204104d7d10ea1199c1bd9c1d235de73a2c285' - class TestProof(TestCICBase): def test_proof_serialize(self):