diff --git a/packages/backend/src/nest/connections-manager/connections-manager.service.tor.spec.ts b/packages/backend/src/nest/connections-manager/connections-manager.service.tor.spec.ts index 4e0d85406..369c9d659 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.tor.spec.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.tor.spec.ts @@ -187,7 +187,7 @@ describe('Connections manager', () => { // add 7 random peers to the list for (let pCount = 0; pCount < MANY_PEERS_COUNT; pCount++) { - peerAddress = createLibp2pAddress(generateRandomOnionAddress(56), (await createPeerId()).toString()) + peerAddress = createLibp2pAddress(generateRandomOnionAddress(56), (await createPeerId()).peerId.toString()) logger.info(`pushing peer ${pCount}: ${peerAddress}`) peerList.push(peerAddress) } @@ -203,13 +203,15 @@ describe('Connections manager', () => { localDbService.setCurrentCommunityId(community.id) logger.info('Launching community', community.id, 'with peer list', peerList) await connectionsManagerService.init() - await sleep(5000) - expect(connectionsManagerService.communityState).toBe(ServiceState.LAUNCHED) + await waitForExpect(async () => { + expect(connectionsManagerService.communityState).toBe(ServiceState.LAUNCHED) + }, 20_000) await waitForExpect(async () => { expect(connectionsManagerService.libp2pService.dialedPeers.size).toBe(MANY_PEERS_COUNT) }, 15_000) + await waitForExpect(async () => { // expect to dial all peers except self expect(spyOnDial).toHaveBeenCalledTimes(MANY_PEERS_DIALS) @@ -226,7 +228,7 @@ describe('Connections manager', () => { peerList.push(createLibp2pAddress(userIdentity.hiddenService.onionAddress, userIdentity.peerId.id)) // add 7 random peers to the list for (let pCount = 0; pCount < MANY_PEERS_COUNT; pCount++) { - peerAddress = createLibp2pAddress(generateRandomOnionAddress(56), (await createPeerId()).toString()) + peerAddress = createLibp2pAddress(generateRandomOnionAddress(56), (await createPeerId()).peerId.toString()) logger.info(`pushing peer ${pCount}: ${peerAddress}`) peerList.push(peerAddress) } @@ -240,11 +242,15 @@ describe('Connections manager', () => { expect(connectionsManagerService.communityState).toBe(undefined) // community will launch from storage await connectionsManagerService.init() - expect(connectionsManagerService.communityState).toBe(ServiceState.LAUNCHED) + + await waitForExpect(async () => { + expect(connectionsManagerService.communityState).toBe(ServiceState.LAUNCHED) + }, 20_000) await waitForExpect(async () => { expect(connectionsManagerService.libp2pService.dialedPeers.size).toBe(MANY_PEERS_COUNT) }, 15_000) + await waitForExpect(async () => { // expect to dial all peers except self expect(spyOnDial).toHaveBeenCalledTimes(MANY_PEERS_DIALS) @@ -261,12 +267,12 @@ describe('Connections manager', () => { peerList.push(createLibp2pAddress(userIdentity.hiddenService.onionAddress, userIdentity.peerId.id)) // add 7 random peers to the list for (let pCount = 0; pCount < MANY_PEERS_COUNT; pCount++) { - peerAddress = createLibp2pAddress(generateRandomOnionAddress(56), (await createPeerId()).toString()) + peerAddress = createLibp2pAddress(generateRandomOnionAddress(56), (await createPeerId()).peerId.toString()) logger.info(`pushing peer ${pCount}: ${peerAddress}`) peerList.push(peerAddress) } // add invalid peer address (too short) - peerList.push(createLibp2pAddress(generateRandomOnionAddress(50), (await createPeerId()).toString())) + peerList.push(createLibp2pAddress(generateRandomOnionAddress(50), (await createPeerId()).peerId.toString())) // all addresses are valid expect(peerList.length).toBe(filterValidAddresses(peerList).length + 1) @@ -278,11 +284,14 @@ describe('Connections manager', () => { // community will launch from storage await connectionsManagerService.init() - expect(connectionsManagerService.communityState).toBe(ServiceState.LAUNCHED) + await waitForExpect(async () => { + expect(connectionsManagerService.communityState).toBe(ServiceState.LAUNCHED) + }, 20_000) await waitForExpect(async () => { expect(connectionsManagerService.libp2pService.dialedPeers.size).toBe(MANY_PEERS_COUNT) }, 15_000) + await waitForExpect(async () => { // expect to dial all peers except self expect(spyOnDial).toHaveBeenCalledTimes(MANY_PEERS_DIALS) @@ -303,12 +312,12 @@ describe('Connections manager', () => { peerList.push(createLibp2pAddress(userIdentity.hiddenService.onionAddress, userIdentity.peerId.id)) // add 7 random peers to the list for (let pCount = 0; pCount < MANY_PEERS_COUNT; pCount++) { - peerAddress = createLibp2pAddress(generateRandomOnionAddress(56), (await createPeerId()).toString()) + peerAddress = createLibp2pAddress(generateRandomOnionAddress(56), (await createPeerId()).peerId.toString()) logger.info(`pushing peer ${pCount}: ${peerAddress}`) peerList.push(peerAddress) } // add invalid peer address (too short) - peerList.push(createLibp2pAddress(generateRandomOnionAddress(50), (await createPeerId()).toString())) + peerList.push(createLibp2pAddress(generateRandomOnionAddress(50), (await createPeerId()).peerId.toString())) // all addresses are valid expect(peerList.length).toBe(filterValidAddresses(peerList).length + 1) // update level db store of identity to sim saga registration @@ -319,9 +328,14 @@ describe('Connections manager', () => { localDbService.setCurrentCommunityId(community.id) await connectionsManagerService.init() + await waitForExpect(async () => { + expect(connectionsManagerService.communityState).toBe(ServiceState.LAUNCHED) + }, 20_000) + await waitForExpect(async () => { expect(connectionsManagerService.libp2pService.dialedPeers.size).toBe(MANY_PEERS_COUNT) }, 15_000) + await waitForExpect(async () => { // expect to dial all peers except self expect(spyOnDial).toHaveBeenCalledTimes(MANY_PEERS_DIALS) @@ -335,7 +349,9 @@ describe('Connections manager', () => { const peerList: string[] = [] const peersCount = 8 for (let pCount = 0; pCount < peersCount; pCount++) { - peerList.push(createLibp2pAddress(userIdentity.hiddenService.onionAddress, (await createPeerId()).toString())) + peerList.push( + createLibp2pAddress(userIdentity.hiddenService.onionAddress, (await createPeerId()).peerId.toString()) + ) } await connectionsManagerService.launchCommunity({ ...community, peerList: peerList }) diff --git a/packages/backend/src/nest/connections-manager/connections-manager.service.ts b/packages/backend/src/nest/connections-manager/connections-manager.service.ts index 60d9c30ca..b4e11aee8 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.ts @@ -402,7 +402,6 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI const peerId = await createPeerId() const peerIdJson: QuietPeerId = { id: peerId.peerId.toString(), - pubKey: peerId.peerId.publicKey?.toString(), privKey: uint8ArrayToString(peerId.privKey!.raw, 'base64'), } this.logger.info(`Created network for peer ${peerId.toString()}. Address: ${hiddenService.onionAddress}`) diff --git a/packages/state-manager/src/utils/tests/helpers.ts b/packages/state-manager/src/utils/tests/helpers.ts index 63383dd56..3b0f303a0 100644 --- a/packages/state-manager/src/utils/tests/helpers.ts +++ b/packages/state-manager/src/utils/tests/helpers.ts @@ -13,7 +13,6 @@ const notAfterDate = new Date(Date.UTC(2030, 11, 28, 10, 10, 10)) export const createPeerIdTestHelper = (): PeerId => { return { id: '12D3KooWRga8g1J1oiH7UYnSQ8YMPRDfVuehuiuAd7PMkcXSxRsp', - pubKey: '12D3KooWRga8g1J1oiH7UYnSQ8YMPRDfVuehuiuAd7PMkcXSxRsp', privKey: 'jAXL3ZK13AWR9WcwbX8nM/qgQqdaApPDqWj6dK9IPwHru99WpGniLouugCv2+t7QN4xnYLMoAFPRP40xTUTrCw', } } diff --git a/packages/types/src/identity.ts b/packages/types/src/identity.ts index 4682cba82..7f7ff151e 100644 --- a/packages/types/src/identity.ts +++ b/packages/types/src/identity.ts @@ -17,7 +17,6 @@ export interface HiddenService { export interface PeerId { id: string - pubKey?: string privKey?: string }