Beispiel #1
0
    def test_serialized_solution_none_if_not_adequate_consensus(self):
        con = contender.SubBlockContender(input_hash='a' * 64, index=0, total_contacts=2, required_consensus=0.66)
        con.total_contacts = 100

        con.best_solution = contender.PotentialSolution(struct={})
        con.best_solution.signatures = ['a', 'b', 'c']

        self.assertIsNone(con.serialized_solution)
Beispiel #2
0
    def test_has_adequate_consensus_true_if_enough_votes(self):
        con = contender.SubBlockContender(input_hash='a' * 64, index=0, total_contacts=2, required_consensus=0.66)
        con.total_contacts = 3

        con.best_solution = contender.PotentialSolution(struct={})
        con.best_solution.signatures = ['a', 'b', 'c']

        self.assertTrue(con.has_adequate_consensus)
Beispiel #3
0
    def test_has_adequate_consensus_false_if_no_votes_on_any_solution(self):
        con = contender.SubBlockContender(input_hash='a' * 64, index=0, total_contacts=2, required_consensus=0.66)
        con.total_contacts = 100

        con.best_solution = contender.PotentialSolution(struct={})
        con.best_solution.signatures = ['a', 'b', 'c']

        self.assertFalse(con.has_adequate_consensus)
Beispiel #4
0
    def test_serialized_solution_returns_best_solution_as_dict(self):
        con = contender.SubBlockContender(input_hash='a' * 64, index=0, total_contacts=2, required_consensus=0.66)
        con.add_potential_solution(subblock)

        #p.signatures.append(('b', 'x'))
        #p.signatures.append(('x', 'b'))

        expected = {
            'input_hash': 'a',
            'transactions': [],
            'merkle_leaves': ['a', 'b', 'c'],
            'subblock': 0,
            'previous': 'b',
            'signatures': [
                {
                    'signature': 'x',
                    'signer': 'b'
                },
                {
                    'signature': 'b',
                    'signer': 'x'
                },
            ]
        }
Beispiel #5
0
    def test_serialized_solution_none_if_failed(self):
        con = contender.SubBlockContender(input_hash='a' * 64, index=0, total_contacts=2, required_consensus=0.66)
        con.total_responses = 10

        self.assertIsNone(con.serialized_solution)
Beispiel #6
0
 def test_failed_if_enough_responses_but_no_consensus(self):
     con = contender.SubBlockContender(input_hash='a' * 64, index=0, total_contacts=2, required_consensus=0.66)
     con.total_responses = 10
     self.assertTrue(con.failed)
Beispiel #7
0
 def test_not_failed_if_no_responses_yet(self):
     con = contender.SubBlockContender(input_hash='a' * 64, index=0, total_contacts=2, required_consensus=0.66)
     self.assertFalse(con.failed)
Beispiel #8
0
 def test_has_adequate_consensus_false_if_best_solution_none(self):
     con = contender.SubBlockContender(input_hash='a' * 64, index=0, total_contacts=2, required_consensus=0.66)
     self.assertFalse(con.has_adequate_consensus)