Пример #1
0
 def test_validate_not_sane_zeroes(self):
     db = MockDatabase()
     block1 = TriblerChainBlock()
     # Act
     block1.transaction = {'up': 0, 'down': 0, 'total_up': 30, 'total_down': 40}
     result = block1.validate(db)
     self.assertEqual(result[0], ValidationResult.invalid)
     self.assertIn("Up and down are zero", result[1])
Пример #2
0
 def test_validate_not_sane_negatives(self):
     db = MockDatabase()
     block1 = TriblerChainBlock()
     # Act
     block1.transaction = {'up': -10, 'down': -10, 'total_up': -20, 'total_down': -10}
     result = block1.validate(db)
     self.assertEqual(result[0], ValidationResult.invalid)
     self.assertIn("Up field is negative", result[1])
     self.assertIn("Down field is negative", result[1])
     self.assertIn("Total up field is negative", result[1])
     self.assertIn("Total down field is negative", result[1])
Пример #3
0
 def test_validate_existing_total_up(self):
     # Arrange
     db = MockDatabase()
     (block1, block2, block3, _) = TestBlocks.setup_validate()
     db.add_block(block1)
     db.add_block(block2)
     db.add_block(block3)
     # Act
     block2 = TriblerChainBlock(block2.pack_db_insert())
     block2.transaction["total_up"] += 10
     block2.sign(db.get(block2.public_key, block2.sequence_number).key)
     result = block2.validate(db)
     # Assert
     self.assertEqual(result[0], ValidationResult.invalid)
     self.assertIn('Total up is higher than expected compared to the next block', result[1])