def func_wrapper(): from dokuztas.blockchain import Blockchain node = NodeComponent() node.chain = Blockchain(difficulty=difficulty) node.miner = True node.create_genesis_chain() for x in range(0, txs_count): node.add_transaction(str(x)) func(node)
def test_if_first_pendingblock_is_just_created_then_mining_should_be_started_once(): node = NodeComponent(miner=True) node.create_genesis_chain() patcher = patch('dokuztas.node.NodeComponent.mine') mock = patcher.start() for x in range(0, 200): node.add_transaction(x) patcher.stop() mock.assert_called_once()
def func_wrapper(): patcher = patch('dokuztas.node.NodeComponent.mine') patcher.start() node = NodeComponent() node.miner = True node.create_genesis_chain() for x in range(0, txs_count): node.add_transaction(str(x)) patcher.stop() func(node)
def test_after_first_block_is_mined_then_pending_txs_should_be_mined(): from dokuztas.blockchain import Blockchain node = NodeComponent() node.miner = True node.chain = Blockchain(difficulty=1) node.chain._generate_genesis() def sync_mine(**kwargs): node.chain.mine(kwargs['args'][0], kwargs['args'][1], kwargs['args'][2]) thread_patcher = patch('dokuztas.node.NodeComponent._internal_mine', side_effect=sync_mine) thread_patcher.start() for x in range(0, 22): node.add_transaction(str(x)) thread_patcher.stop() assert len(node.chain.blocks) == 3