コード例 #1
0
    def test_get_last_block(self):

        blockchain = Blockchain()
        g_block = blockchain.get_last_block()
        test_block = None

        while not test_block:
            test_block = blockchain.mine_block(data="Test", node_addr="8367")

        self.assertEqual(test_block, blockchain.get_last_block())
        self.assertNotEqual(g_block, blockchain.get_last_block())
コード例 #2
0
    def test_mine_block(self):

        blockchain = Blockchain()
        test_block = None

        while not test_block:
            test_block = blockchain.mine_block(data="Test", node_addr="8367")

        self.assertIsNotNone(test_block)
        self.assertTrue(blockchain.verify_block(test_block))
        self.assertEqual(blockchain.get_last_block(), test_block)
コード例 #3
0
    def test_verify_block(self):

        blockchain = Blockchain()

        # A block that was not mined on the chain cannot be verified:
        wrong_block = Block(data="Wrong block", user_addr="Bad person")

        correct_block = blockchain.mine_block(data="Correct block",
                                              node_addr="Good person")

        self.assertFalse(blockchain.verify_block(wrong_block))
        self.assertTrue(blockchain.verify_block(correct_block))
コード例 #4
0
    def test_get_ledger(self):

        blockchain = Blockchain()
        g_block_hash = blockchain.get_last_block().get_block_hash()

        test_block = None

        while not test_block:
            test_block = blockchain.mine_block(data="Test", node_addr="8367")

        ledger = blockchain.get_ledger()

        self.assertIsNotNone(ledger[g_block_hash])