def test_sync_state_change_synced(self): chain_manager = Mock() chain_manager.height = 0 chain_manager.get_block = MagicMock(return_value=GenesisBlock()) chain_manager.last_block = GenesisBlock() chain_manager.tx_pool = Mock() chain_manager.tx_pool.transaction_pool = [] get_block_metadata_response = Mock() get_block_metadata_response.block_difficulty = StringToUInt256('2') chain_manager.state.get_block_metadata = MagicMock(return_value=get_block_metadata_response) alice_xmss = get_alice_xmss() chain_manager.state.get_address = MagicMock(return_value=AddressState.get_default(alice_xmss.address)) chain_manager.state.get_measurement = MagicMock(return_value=60) p2p_factory = Mock() sync_state = Mock() time_provider = Mock() node = POW(chain_manager=chain_manager, p2p_factory=p2p_factory, sync_state=sync_state, time_provider=time_provider, slaves=get_random_master(), mining_thread_count=0) self.assertIsNotNone(node) node.update_node_state(ESyncState.synced)
def test_sync_state_change_synced(self): chain_manager = Mock() chain_manager.height = 0 chain_manager.get_block = MagicMock(return_value=GenesisBlock()) chain_manager.last_block = GenesisBlock() chain_manager.tx_pool = Mock() chain_manager.tx_pool.transaction_pool = [] chain_manager.tx_pool.transactions = chain_manager.tx_pool.transaction_pool get_block_metadata_response = Mock() get_block_metadata_response.block_difficulty = StringToUInt256('2') chain_manager.state.get_block_metadata = MagicMock( return_value=get_block_metadata_response) alice_xmss = get_alice_xmss() chain_manager.state.get_address = MagicMock( return_value=AddressState.get_default(alice_xmss.address)) chain_manager.state.get_measurement = MagicMock(return_value=60) p2p_factory = Mock() sync_state = Mock() time_provider = Mock() # Setting mining enabled False, when update_note_state set to synced, # starts miner which is not exited properly by unit test with set_mining_enabled(False): node = POW(chain_manager=chain_manager, p2p_factory=p2p_factory, sync_state=sync_state, time_provider=time_provider, mining_credit_wallet=get_random_xmss().address, mining_thread_count=0) self.assertIsNotNone(node) node.update_node_state(ESyncState.synced)
def start_pow(self, mining_thread_count): self._pow = POW(chain_manager=self._chain_manager, p2p_factory=self._p2pfactory, sync_state=self._sync_state, time_provider=ntp, mining_address=self.mining_address, mining_thread_count=mining_thread_count) self._pow.start()
def start_pow(self, mining_thread_count): # FIXME: This seems an unexpected side effect. It should be refactored self._pow = POW(chain_manager=self._chain_manager, p2p_factory=self._p2pfactory, sync_state=self._sync_state, time_provider=ntp, mining_credit_wallet=self.mining_credit_wallet, mining_thread_count=mining_thread_count) self._pow.start()
def test_create(self): chain_manager = Mock() p2p_factory = Mock() sync_state = Mock() time_provider = Mock() node = POW(chain_manager=chain_manager, p2p_factory=p2p_factory, sync_state=sync_state, time_provider=time_provider, slaves=get_slaves(0, 0), mining_thread_count=0) self.assertIsNotNone(node)
def test_create(self): chain_manager = Mock() p2p_factory = Mock() sync_state = Mock() time_provider = Mock() node = POW(chain_manager=chain_manager, p2p_factory=p2p_factory, sync_state=sync_state, time_provider=time_provider, mining_credit_wallet=get_random_xmss().address, mining_thread_count=0) self.assertIsNotNone(node)
def test_sync_state_change_unsynced(self): chain_manager = Mock() p2p_factory = Mock() sync_state = Mock() time_provider = Mock() node = POW(chain_manager=chain_manager, p2p_factory=p2p_factory, sync_state=sync_state, time_provider=time_provider, slaves=get_slaves(0, 0), mining_thread_count=0) self.assertIsNotNone(node) node.update_node_state(ESyncState.unsynced)
def test_sync_state_change_syncing(self): chain_manager = Mock() p2p_factory = Mock() sync_state = Mock() time_provider = Mock() node = POW(chain_manager=chain_manager, p2p_factory=p2p_factory, sync_state=sync_state, time_provider=time_provider, mining_address=get_random_xmss().address, mining_thread_count=0) self.assertIsNotNone(node) node.update_node_state(ESyncState.syncing)