Beispiel #1
0
    def test_incorrect_hash_transaction_is_rejected(self):
        test = CounterTestContainer()
        self.dc1.add_document_object(test)
        test.testcounter.add(1)

        last_edge = test.history.get_edges_by_end_node(test._clockhash)

        edge1 = AddIntCounter({test._clockhash},
                              last_edge.propertyownerid,
                              last_edge.propertyname, 1,
                              last_edge.propertytype, last_edge.documentid,
                              last_edge.documentclassname, str(uuid.uuid4()))
        edge2 = AddIntCounter({edge1.get_end_node()},
                              last_edge.propertyownerid,
                              last_edge.propertyname, 1,
                              last_edge.propertytype, last_edge.documentid,
                              last_edge.documentclassname, str(uuid.uuid4()))
        edges = [ edge1, edge2 ]

        transaction_hash = hashlib.sha256(','.join([str(edge.get_transaction_info_hash())
            for edge in edges]).encode('utf-8')).hexdigest()
        for i in range(len(edges)):
            edge = edges[i]
            edge.transaction_hash = transaction_hash
            if i > 0:
                edge._start_hashes = [edges[i - 1].get_end_node()]

        test.full_replay(edges)

        self.assertEqual(test.testcounter.get(), 1)
Beispiel #2
0
    def test_success(self):
        test = CounterTestContainer()
        self.dc1.add_document_object(test)
        test.testcounter.add(1)

        last_edge = test.history.get_edges_by_end_node(test._clockhash)

        edge1 = AddIntCounter({test._clockhash},
                              last_edge.propertyownerid,
                              last_edge.propertyname, 1,
                              last_edge.propertytype, last_edge.documentid,
                              last_edge.documentclassname, last_edge.sessionid)
        edge2 = AddIntCounter({edge1.get_end_node()},
                              last_edge.propertyownerid,
                              last_edge.propertyname, 1,
                              last_edge.propertytype, last_edge.documentid,
                              last_edge.documentclassname, last_edge.sessionid)
        edges = [ edge1, edge2 ]

        transaction_hash = get_transaction_hash(edges)
        #print('test_success transaction_hash=', transaction_hash)
        #print('test_success edges.get_transaction_info_hash=', ','.join([edge.get_transaction_info_hash() for edge in edges]))
        for i in range(len(edges)):
            edge = edges[i]
            edge.clear_end_node_cache()
            edge.transaction_hash = transaction_hash
            if i > 0:
                edge._start_hashes = [edges[i - 1].get_end_node()]

        test.full_replay(edges)

        self.assertEqual(test.testcounter.get(), 3)
Beispiel #3
0
    def test_success(self):
        test = CounterTestContainer()
        self.dc1.add_document_object(test)
        test.testcounter.add(1)

        last_edge = test.history.get_edges_by_end_node(test._clockhash)

        edge = AddIntCounter({test._clockhash},
                              last_edge.propertyownerid,
                              last_edge.propertyname, 1,
                              last_edge.propertytype, last_edge.documentid,
                              last_edge.documentclassname, last_edge.sessionid)

        test.full_replay([edge])

        self.assertEqual(test.testcounter.get(), 2)