Add customizable writers, configs, chain spec in network
This commit is contained in:
@@ -38,7 +38,7 @@ class TestCICBase(unittest.TestCase):
|
||||
|
||||
self.outputs_dir = tempfile.mkdtemp()
|
||||
self.outputs_writer = KVWriter(self.outputs_dir)
|
||||
self.core_processor = Processor(self.token_address, outputs_writer=self.outputs_writer)
|
||||
self.core_processor = Processor(outputs_writer=self.outputs_writer)
|
||||
|
||||
self.resources = {
|
||||
'token': {
|
||||
|
||||
@@ -89,8 +89,8 @@ class TestCICEthBase(EthTesterCase):
|
||||
self.proofs = Proof(proof_dir, attachments=attach)
|
||||
self.proofs.load()
|
||||
|
||||
d = tempfile.mkdtemp()
|
||||
self.outputs_writer = KVWriter(d)
|
||||
self.outputs_dir = tempfile.mkdtemp()
|
||||
self.outputs_writer = KVWriter(self.outputs_dir)
|
||||
|
||||
|
||||
class TestCICEthTokenBase(TestCICEthBase):
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import logging
|
||||
import os
|
||||
|
||||
# local imports
|
||||
from cic.ext.eth import CICEth
|
||||
@@ -18,7 +19,8 @@ class TestCICEthOffline(TestCICEthBase):
|
||||
def setUp(self):
|
||||
super(TestCICEthOffline, self).setUp()
|
||||
self.adapter = CICEth(self.chain_spec, self.resources, self.proofs)
|
||||
self.core_processor = Processor(outputs_writer=self.outputs_writer, extensions=[self.adapter])
|
||||
self.first_proof = self.proofs.get()[0]
|
||||
#self.core_processor = Processor(outputs_writer=self.outputs_writer, extensions=[self.adapter])
|
||||
|
||||
|
||||
def test_offline_token_index(self):
|
||||
@@ -31,11 +33,28 @@ class TestCICEthOffline(TestCICEthBase):
|
||||
def test_offline_address_declarator(self):
|
||||
self.adapter.token_address = self.token_address
|
||||
self.adapter.process_address_declarator()
|
||||
self.assertEqual(self.adapter.outputs[0][0], 'address_declarator')
|
||||
first_proof = self.proofs.get()[0]
|
||||
self.assertEqual(self.adapter.outputs[0][0], 'address_declarator_' + self.first_proof)
|
||||
self.assertEqual(self.adapter.outputs[0][1][:8], 'ae47ece0')
|
||||
self.assertEqual(len(self.adapter.outputs), 3)
|
||||
|
||||
|
||||
def test_offline_writer(self):
|
||||
self.adapter.outputs_writer = self.outputs_writer
|
||||
self.adapter.token_address = self.token_address
|
||||
self.adapter.process_address_declarator()
|
||||
self.assertEqual(self.adapter.outputs[0][0], 'address_declarator_' + self.first_proof)
|
||||
self.assertEqual(self.adapter.outputs[0][1][:8], 'ae47ece0')
|
||||
self.assertEqual(len(self.adapter.outputs), 3)
|
||||
|
||||
proofs = self.proofs.get()
|
||||
for i, v in enumerate(self.adapter.outputs):
|
||||
fp = os.path.join(self.outputs_dir, v[0])
|
||||
f = open(fp, 'rb')
|
||||
r = f.read()
|
||||
f.close()
|
||||
self.assertEqual(r.decode('utf-8'), v[1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -19,7 +19,7 @@ logg = logging.getLogger()
|
||||
class TestCICOutput(TestCICBase):
|
||||
|
||||
def test_output_file(self):
|
||||
self.outputs_writer.write('foo', 'bar')
|
||||
self.outputs_writer.write('foo', b'bar')
|
||||
fp = os.path.join(self.outputs_dir, 'foo')
|
||||
f = open(fp, 'r')
|
||||
v = f.read()
|
||||
|
||||
@@ -9,6 +9,7 @@ from hexathon import strip_0x
|
||||
|
||||
# local imports
|
||||
from cic.processor import Processor
|
||||
from cic.attachment import Attachment
|
||||
from cic.meta import Meta
|
||||
|
||||
# test imports
|
||||
@@ -31,7 +32,7 @@ class MockExt:
|
||||
|
||||
class TestCICProcessor(TestCICBase):
|
||||
|
||||
def test_processor(self):
|
||||
def test_processor_meta(self):
|
||||
fp = os.path.join(test_data_dir, 'proof')
|
||||
m = Meta(fp)
|
||||
m.load()
|
||||
@@ -47,7 +48,20 @@ class TestCICProcessor(TestCICBase):
|
||||
o = json.load(f)
|
||||
f.close()
|
||||
self.assertEqual(m.asdict(), o)
|
||||
|
||||
|
||||
|
||||
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()
|
||||
|
||||
for k in list(m.contents.keys()):
|
||||
fp = os.path.join(self.outputs_dir, k)
|
||||
os.stat(fp)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user