def test_validate_linked_double_pay_fraud(self): db = MockDatabase() (block1, _, _, _) = TestBlocks.setup_validate() # Act db.add_block(block1) db.add_block( TrustChainBlock.create(block1.transaction, db, block1.link_public_key, block1)) block2 = TrustChainBlock.create(block1.transaction, db, block1.link_public_key, block1) result = block2.validate(db) self.assertEqual(result[0], ValidationResult.invalid) self.assertIn("Double countersign fraud", result[1])
def test_validate_linked_mismatch(self): db = MockDatabase() (block1, block2, _, _) = TestBlocks.setup_validate() # Act db.add_block(block1) block3 = TrustChainBlock.create(block2.transaction, db, block2.link_public_key, block1) result = block3.validate(db) self.assertEqual(result[0], ValidationResult.invalid) self.assertIn("Public key mismatch on linked block", result[1])
def test_validate_linked_valid(self): db = MockDatabase() (block1, block2, _, _) = TestBlocks.setup_validate() db.add_block(block2) # Act db.add_block( TrustChainBlock.create(block1.transaction, db, block1.link_public_key, block1)) result = block1.validate(db) self.assertEqual(result[0], ValidationResult.valid)
def test_create_genesis(self): key = ECCrypto().generate_key(u"curve25519") db = MockDatabase() block = TrustChainBlock.create({'id': 42}, db, key.pub().key_to_bin(), link=None) self.assertEqual(block.previous_hash, GENESIS_HASH) self.assertEqual(block.sequence_number, GENESIS_SEQ) self.assertEqual(block.public_key, key.pub().key_to_bin()) self.assertEqual(block.signature, EMPTY_SIG)
def test_create_next(self): db = MockDatabase() prev = TestBlock() prev.sequence_number = GENESIS_SEQ db.add_block(prev) block = TrustChainBlock.create({'id': 42}, db, prev.public_key, link=None) self.assertEqual(block.previous_hash, prev.hash) self.assertEqual(block.sequence_number, 2) self.assertEqual(block.public_key, prev.public_key)
def test_create_link_genesis(self): key = ECCrypto().generate_key(u"curve25519") db = MockDatabase() link = TestBlock() db.add_block(link) block = TrustChainBlock.create({'id': 42}, db, key.pub().key_to_bin(), link=link) self.assertEqual(block.previous_hash, GENESIS_HASH) self.assertEqual(block.sequence_number, GENESIS_SEQ) self.assertEqual(block.public_key, key.pub().key_to_bin()) self.assertEqual(block.link_public_key, link.public_key) self.assertEqual(block.link_sequence_number, link.sequence_number)