Add tests for merged and unmerged processing including proofs

This commit is contained in:
nolash 2021-10-11 19:13:21 +02:00
parent 09fa8f2a4c
commit 1fce3245d8
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 45 additions and 8 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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()

View File

@ -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):