Esempio n. 1
0
 def test_validate_existing_link_public_key(self):
     # Arrange
     db = MockDatabase()
     (block1, block2, block3, _) = TestBlocks.setup_validate()
     db.add_block(block1)
     db.add_block(block2)
     db.add_block(block3)
     # Act
     block2 = TrustChainBlock(block2.pack_db_insert())
     block2.link_public_key = EMPTY_PK
     block2.sign(db.get(block2.public_key, block2.sequence_number).key)
     result = block2.validate(db)
     # Assert
     self.assertEqual(result[0], ValidationResult.invalid)
     self.assertIn('Linked public key is not valid', result[1])
Esempio n. 2
0
 def test_validate_existing_hash(self):
     # Arrange
     db = MockDatabase()
     (block1, block2, block3, _) = TestBlocks.setup_validate()
     db.add_block(block1)
     db.add_block(block2)
     db.add_block(block3)
     # Act
     block2 = TrustChainBlock(block2.pack_db_insert())
     block2.previous_hash = sha256(str(random.randint(0, 100000))).digest()
     block2.sign(db.get(block2.public_key, block2.sequence_number).key)
     result = block2.validate(db)
     # Assert
     self.assertEqual(result[0], ValidationResult.invalid)
     self.assertIn(
         'Previous hash is not equal to the hash id of the previous block',
         result[1])