test_interface.py (1420B)
1 # standard imports 2 import unittest 3 import logging 4 import os 5 6 # test imports 7 from tests.base import TestBase 8 from taint.store.file import FileStore 9 from taint.taint import Tainter 10 11 12 class TestInterface(TestBase): 13 14 def test_store(self): 15 self.store = FileStore(self.session_data_dir) 16 c = Tainter(self.chain_spec, self.bits_size, store=self.store) 17 c.add_subject(self.alice) 18 c.add_subject(self.bob) 19 block_height = 42 20 tx_index = 13 21 c.add_tx(self.alice.account, self.bob.account, block_height, tx_index) 22 c.save() 23 24 stored = os.listdir(self.session_data_dir) 25 self.assertEqual(len(stored), 3) 26 self.assertIn(self.alice.account.hex(), stored) 27 self.assertIn(self.bob.account.hex(), stored) 28 self.assertIn(c.root_key().hex(), stored) 29 30 c = Tainter(self.chain_spec, self.bits_size, store=self.store) 31 r = c.load_subject(self.alice.account) 32 self.assertTrue(r) 33 r = c.load_object(self.bob.account) 34 self.assertTrue(r) 35 36 self.assertTrue(self.alice.is_same(c.subjects[self.alice.account])) 37 self.assertTrue(self.bob.is_same(c.objects[self.bob.account])) 38 self.assertFalse(c.have(block_height, tx_index)) 39 40 c = Tainter.load(self.store, self.chain_spec) 41 self.assertTrue(c.have(block_height, tx_index)) 42 43 44 if __name__ == '__main__': 45 unittest.main()