def test_validate_existing_fraud(self): # Arrange db = MockDatabase() (block1, block2, _, _) = TestBlocks.setup_validate() db.add_block(block1) db.add_block(block2) # Act block3 = TrustChainBlock(block2.pack_db_insert()) block3.previous_hash = sha256(str(random.randint(0, 100000))).digest() block3.sign(block2.key) result = block3.validate(db) # Assert self.assertEqual(result[0], ValidationResult.invalid) self.assertIn("Double sign fraud", result[1])
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])
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])