def test_serialize_deserialize(self): block_data = build_valid_block_data() hash = BlockStorageDriver.compute_block_hash(block_data) req = BlockMetaData.create( hash=hash, merkle_root=block_data['merkle_root'], merkle_leaves=block_data['merkle_leaves'], prev_block_hash=block_data['prev_block_hash'], timestamp=block_data['timestamp'], masternode_signature=block_data['masternode_signature'], masternode_vk=block_data['masternode_vk'], block_contender=block_data['block_contender']) clone = BlockMetaData.from_bytes(req.serialize()) self.assertEqual(clone, req)
def test_validate_timestamp_fail(self, block_data, hash): return BlockMetaData.create( hash=hash, merkle_root=block_data['merkle_root'], merkle_leaves=block_data['merkle_leaves'], prev_block_hash=block_data['prev_block_hash'], timestamp=1234, masternode_signature=block_data['masternode_signature'], masternode_vk=block_data['masternode_vk'], block_contender=block_data['block_contender'])
def test_validate_block_contender_fail(self, block_data, hash): new_block = build_valid_block_data() with self.assertRaises(Exception) as e: bmd = BlockMetaData.create( hash=hash, merkle_root=block_data['merkle_root'], merkle_leaves=block_data['merkle_leaves'], prev_block_hash=block_data['prev_block_hash'], timestamp=block_data['timestamp'], masternode_signature=block_data['masternode_signature'], masternode_vk=block_data['masternode_vk'], block_contender=new_block['block_contender'])
def _bad_block(self): block_data = build_valid_block_data() hash = BlockStorageDriver.compute_block_hash(block_data) bmd = BlockMetaData.create( hash=hash, merkle_root=block_data['merkle_root'], merkle_leaves=block_data['merkle_leaves'], prev_block_hash=block_data['prev_block_hash'], timestamp=block_data['timestamp'], masternode_signature=block_data['masternode_signature'], masternode_vk=block_data['masternode_vk'], block_contender=block_data['block_contender']) return bmd
def setUpClass(cls): cls.block_metas = [] for i in range(5): block_data = build_valid_block_data() hash = BlockStorageDriver.compute_block_hash(block_data) bmd = BlockMetaData.create( hash=hash, merkle_root=block_data['merkle_root'], merkle_leaves=block_data['merkle_leaves'], prev_block_hash=block_data['prev_block_hash'], timestamp=block_data['timestamp'], masternode_signature=block_data['masternode_signature'], masternode_vk=block_data['masternode_vk'], block_contender=block_data['block_contender']) cls.block_metas.append(bmd)
def test_create(self, block_data, hash): bmd = BlockMetaData.create( hash=hash, merkle_root=block_data['merkle_root'], merkle_leaves=block_data['merkle_leaves'], prev_block_hash=block_data['prev_block_hash'], timestamp=block_data['timestamp'], masternode_signature=block_data['masternode_signature'], masternode_vk=block_data['masternode_vk'], block_contender=block_data['block_contender']) self.assertEqual(block_data['merkle_root'], bmd.merkle_root) self.assertEqual(block_data['merkle_leaves'], ''.join(bmd.merkle_leaves)) self.assertEqual(block_data['prev_block_hash'], bmd.prev_block_hash) self.assertEqual(block_data['timestamp'], bmd.timestamp) self.assertEqual(block_data['masternode_signature'], bmd.masternode_signature) self.assertEqual(block_data['masternode_vk'], bmd.masternode_vk) self.assertEqual(block_data['block_contender'], bmd.block_contender)
def _build_block_meta(self, *args, **kwargs): b_data = self._build_block_data_with_hash(*args, **kwargs) return BlockMetaData.create(**b_data)