def create_peer(self, network, peer_id=None, wallet=None, tx_storage=None, unlock_wallet=True, wallet_index=False, capabilities=None): if peer_id is None: peer_id = PeerId() if not wallet: wallet = self._create_test_wallet() if unlock_wallet: wallet.unlock(b'MYPASS') manager = HathorManager( self.clock, peer_id=peer_id, network=network, wallet=wallet, tx_storage=tx_storage, wallet_index=wallet_index, capabilities=capabilities, ) manager.avg_time_between_blocks = 0.0001 manager.test_mode = TestMode.TEST_ALL_WEIGHT manager._full_verification = True manager.start() self.run_to_completion() return manager
def create_peer(self, network, peer_id=None, wallet=None, tx_storage=None, unlock_wallet=True, wallet_index=False, capabilities=None, full_verification=True, enable_sync_v1=None, enable_sync_v2=None, checkpoints=None): if enable_sync_v1 is None: assert hasattr(self, '_enable_sync_v1'), ( '`_enable_sync_v1` has no default by design, either set one on ' 'the test class or pass `enable_sync_v1` by argument') enable_sync_v1 = self._enable_sync_v1 if enable_sync_v2 is None: assert hasattr(self, '_enable_sync_v2'), ( '`_enable_sync_v2` has no default by design, either set one on ' 'the test class or pass `enable_sync_v2` by argument') enable_sync_v2 = self._enable_sync_v2 assert enable_sync_v1 or enable_sync_v2, 'enable at least one sync version' if peer_id is None: peer_id = PeerId() if not wallet: wallet = self._create_test_wallet() if unlock_wallet: wallet.unlock(b'MYPASS') if tx_storage is None: if self.use_memory_storage: from hathor.transaction.storage.memory_storage import TransactionMemoryStorage tx_storage = TransactionMemoryStorage() else: from hathor.transaction.storage.rocksdb_storage import TransactionRocksDBStorage directory = tempfile.mkdtemp() self.tmpdirs.append(directory) tx_storage = TransactionRocksDBStorage(directory) manager = HathorManager( self.clock, peer_id=peer_id, network=network, wallet=wallet, tx_storage=tx_storage, wallet_index=wallet_index, capabilities=capabilities, rng=self.rng, enable_sync_v1=enable_sync_v1, enable_sync_v2=enable_sync_v2, checkpoints=checkpoints, ) # XXX: just making sure that tests set this up correctly if enable_sync_v2: assert SyncVersion.V2 in manager.connections._sync_factories else: assert SyncVersion.V2 not in manager.connections._sync_factories if enable_sync_v1: assert SyncVersion.V1 in manager.connections._sync_factories else: assert SyncVersion.V1 not in manager.connections._sync_factories manager.avg_time_between_blocks = 0.0001 manager._full_verification = full_verification manager.start() self.run_to_completion() return manager