def mineLoop(self):
     try:
         while (True):
             # simulate mining by rolling dice till 0
             if (random.randint(0, self.difficulty) == 0):
                 self.chain = BlockUtils.mineNewBlock(self.chain, self.name)
                 self.broadcastNewBlock()
             self.checkForNewBlocks()
     except KeyboardInterrupt:
         self.inboxServer.shutDown()
 def testMineNewBlock(self):
     chain = BU.generateChain("me", 5)
     newChain = BU.mineNewBlock(chain, "me")
     self.assertEqual(BU.isValidChain(newChain), True)
     self.assertEqual(len(newChain.orphans), 0)