def testBlock(size): block = BU.generateBlock("me", size) nBlock = BU.jsonToBlock(BU.blockToJson(block)) self.assertEqual(nBlock.miner, block.miner) self.assertEqual(nBlock.prev, block.prev) self.assertEqual(nBlock.height, block.height) self.assertEqual(nBlock.uid, block.uid)
def testBlockToFromData(self): def testBlock(size): block = BU.generateBlock("me", size) nBlock = BU.jsonToBlock(BU.blockToJson(block)) self.assertEqual(nBlock.miner, block.miner) self.assertEqual(nBlock.prev, block.prev) self.assertEqual(nBlock.height, block.height) self.assertEqual(nBlock.uid, block.uid) block = BU.genisisBlock() nBlock = BU.jsonToBlock(BU.blockToJson(block)) self.assertEqual(nBlock.miner, block.miner) self.assertEqual(nBlock.prev, block.prev) self.assertEqual(nBlock.height, block.height) self.assertEqual(nBlock.uid, block.uid) testBlock(5) testBlock(10) testBlock(15) testBlock(16) testBlock(50) testBlock(100)
async def listenForBlocks(self, reader, writer): data = await reader.read(InboxServer.MAXLEN) block = BlockUtils.jsonToBlock(data.decode()) print(block) self.inbox.put(block) writer.close()