import logging import unittest from unittest.mock import Mock from aucoin.blockchain import Blockchain, Mempool from aucoin.miner import Miner, find_best_transactions from aucoin.transactions import Transaction, Input, Output from aucoin.wallet import Wallet logging.basicConfig(level=logging.DEBUG) class TestMiner(unittest.TestCase): def setUp(self): self.wallet = Wallet() self.blockchain = Blockchain() self.mempool = Mempool() # start miner callback_mock = Mock() miner = Miner(self.wallet.address, self.blockchain, self.mempool, callback_mock) # wait until callback has been called by the miner (until a block has been found) while not callback_mock.called: pass # stop miner miner.stop() # the arguments that the callback_mock was last called with: self.found_block = callback_mock.call_args[0][0] @unittest.skip def test_mined_blocks_are_valid(self): self.assertTrue(self.found_block.validate()) # TODO def test_correct_coinbase_address(self): coinbase_tx = self.found_block.transactions[0] self.assertEqual(coinbase_tx.outputs[0].address, self.wallet.address) if __name__ == '__main__': unittest.main()