예제 #1
0
    def testCheckAllEntriesEntry(self):
        deploy.deploy(_TEST_CONFIG)
        test_key = 'testCheckAllEntriesEntry'
        test_db = ProvedDB(_TEST_CONFIG, 'json')
        for test_case in self.TEST_DATA[test_key]:
            test_db.create(test_case)
        self.assertEqual(test_db.check_all_entries(), True, 'There should pass the checking')

        test_db.delete(list(self.TEST_DATA[test_key][1])[0])
        self.assertEqual(test_db.check_all_entries(), True, 'There should pass the checking')
예제 #2
0
    def testBehaior(self):
        private_node = SubmitAndRecordChainNode(config_path=_TEST_CONFIG,
                                                submit_hash_callback_objs=[],
                                                record_over_callback_objs=[],
                                                wait_time=1)
        private_node.start()
        test_db = ProvedDB(_TEST_CONFIG, 'json')
        # setting key val
        test_db.create({'my_key1': 'key1_data_01'})
        test_db.create({'my_key2': 'key1_data_01'})

        test_db.create({'my_key3': 'key1_data_01'})
        test_db.create({'my_key4': 'key1_data_01'})

        test_db.create({'my_key5': 'key1_data_01'})
        # check all entry
        test_db.check_all_entries()
        val = test_db.retrieve('my_key2')
        self.assertEqual(True, test_db.check_entry('my_key2', val),
                         'should pass')

        gevent.sleep(1)
        # check finalised data
        check_hash = calculate_entry_hash(['my_key3', 'key1_data_01'])
        existed, entries_length = test_db.get_finalised_group_entries_length(
            check_hash)
        self.assertEqual(True, existed, 'should be pass')
        all_check_hash = [
            test_db.get_finalised_group_entry(check_hash, i)
            for i in range(entries_length)
        ]
        self.assertEqual(True, check_hash in all_check_hash, 'should pass')

        check_hash_sum = calculate_submit_hash_from_group(all_check_hash)
        existed, finalised, entries_length = test_db.get_finalise_entries_length(
            check_hash_sum)
        self.assertEqual(True, existed, 'hash does exist')
        self.assertEqual(True, finalised, 'hash doesn finalise')
        self.assertEqual(2, entries_length,
                         'hash entry index should not be zero')

        double_check_hashes = [
            test_db.get_finalise_entry(check_hash_sum, i)
            for i in range(entries_length)
        ]
        self.assertEqual(double_check_hashes, all_check_hash, 'should pass')

        check_hash = calculate_entry_hash(['my_key5', 'key1_data_01'])
        existed, entries_length = test_db.get_finalised_group_entries_length(
            check_hash)
        self.assertEqual(False, existed, 'should be pass')

        # Test again
        test_db.update({'my_key5': 'key1_data_02'})
        gevent.sleep(1)

        check_hash = calculate_entry_hash(['my_key5', 'key1_data_01'])
        existed, entries_length = test_db.get_finalised_group_entries_length(
            check_hash)
        self.assertEqual(True, existed, 'should be pass')

        all_check_hash = [
            test_db.get_finalised_group_entry(check_hash, i)
            for i in range(entries_length)
        ]
        self.assertEqual(True, check_hash in all_check_hash, 'should pass')

        check_hash_sum = calculate_submit_hash_from_group(all_check_hash)
        existed, finalised, entries_length = test_db.get_finalise_entries_length(
            check_hash_sum)
        self.assertEqual(True, existed, 'hash does exist')
        self.assertEqual(True, finalised, 'hash doesn finalise')
        self.assertEqual(2, entries_length,
                         'hash entry index should not be zero')

        double_check_hashes = [
            test_db.get_finalise_entry(check_hash_sum, i)
            for i in range(entries_length)
        ]
        self.assertEqual(double_check_hashes, all_check_hash, 'should pass')

        #        # setting key val again
        test_db.delete('my_key2')
        test_db.create({'my_key6': 'key1_data_01'})
        # Test again
        test_db.update({'my_key6': 'key1_data_02'})

        gevent.sleep(1)
        check_hash = calculate_entry_hash(['my_key6', 'key1_data_01'])
        existed, entries_length = test_db.get_finalised_group_entries_length(
            check_hash)
        self.assertEqual(True, existed, 'should be pass')

        all_check_hash = [
            test_db.get_finalised_group_entry(check_hash, i)
            for i in range(entries_length)
        ]
        self.assertEqual(True, check_hash in all_check_hash, 'should pass')

        check_hash_sum = calculate_submit_hash_from_group(all_check_hash)
        existed, finalised, entries_length = test_db.get_finalise_entries_length(
            check_hash_sum)
        self.assertEqual(True, existed, 'hash does exist')
        self.assertEqual(True, finalised, 'hash doesn finalise')
        self.assertEqual(2, entries_length,
                         'hash entry index should not be zero')

        double_check_hashes = [
            test_db.get_finalise_entry(check_hash_sum, i)
            for i in range(entries_length)
        ]
        self.assertEqual(double_check_hashes, all_check_hash, 'should pass')

        private_node.kill()
예제 #3
0
 def testCheckAllEntriesNoEntry(self):
     deploy.deploy(_TEST_CONFIG)
     test_db = ProvedDB(_TEST_CONFIG, 'json')
     self.assertEqual(test_db.check_all_entries(), True, 'There should no data to check')