def test_4_wrong_previous_block(self): self.blocks[0].previous_block_rev = BlockRev.from_id(double_sha(b'something')) self.blocks[0].mine() sign_object(self.public_key, self.private_key, self.blocks[0]) with self.assertRaisesRegex(Block.ChainError, "previous_block_rev does not exist"): self.blocks[0].verify()
def mint_block(): if len(ops) >= MIN_OPS_IN_BLOCK: print("Preparing block with {} operations.".format(len(ops))) blockchain = pmpi.core.get_blockchain() rev = BlockRev.from_id(blockchain.head) if blockchain.max_depth > 0 else BlockRev() block = Block.from_operations_list(rev, int(time.time()), ops) block.difficulty = 10 # TODO difficulty! block.mine() self.user.sign_object(block) block.verify() print("Block minted. Sending.") self.transport.write(b'BL' + block.raw_with_operations()) else: print("There are not enough operations to mint a block") for op in ops: asyncio.ensure_future(operation_queue.put(op))