Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SET_COMMUNITY_METADATA event #2341

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,34 @@ describe('ConnectionsManagerService', () => {
'y7yczmugl2tekami7sbdz5pfaemvx7bahwthrdvcbzw5vex2crsr26qd',
'QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSE'
)
const launchCommunityPayload: InitCommunityPayload = {

// Using the factory includes extra properties that affect the assertion
// below
const actualCommunity = {
id: community.id,
peerList: [remotePeer],
}
await localDbService.setCommunity(actualCommunity)
await localDbService.setCurrentCommunityId(community.id)
// TODO: Revisit this when we move the Identity model to the backend, since
// this network data lives in that model.
const network = {
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
certs: {
// @ts-expect-error
certificate: userIdentity.userCertificate,
// @ts-expect-error
key: userIdentity.userCsr?.userKey,
CA: [communityRootCa],
},
peers: [remotePeer],
}
await localDbService.setNetworkInfo(network)

await localDbService.put(LocalDBKeys.COMMUNITY, launchCommunityPayload)
await connectionsManagerService.closeAllServices()

const launchCommunitySpy = jest.spyOn(connectionsManagerService, 'launchCommunity').mockResolvedValue()

await connectionsManagerService.init()

const localPeerAddress = createLibp2pAddress(userIdentity.hiddenService.onionAddress, userIdentity.peerId.id)
const updatedLaunchCommunityPayload = { ...launchCommunityPayload, peers: [localPeerAddress, remotePeer] }
const updatedLaunchCommunityPayload = {
community: { ...actualCommunity, peerList: [localPeerAddress, remotePeer] },
network,
}

expect(launchCommunitySpy).toHaveBeenCalledWith(updatedLaunchCommunityPayload)
})
Expand All @@ -129,20 +134,13 @@ describe('ConnectionsManagerService', () => {
expect(launchCommunitySpy).not.toHaveBeenCalled()
})

// At this moment, that test have to be skipped, because checking statues is called before launchCommunity method
it.skip('community is only launched once', async () => {
const launchCommunityPayload: InitCommunityPayload = {
id: community.id,
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
certs: {
// @ts-expect-error
certificate: userIdentity.userCertificate,
// @ts-expect-error
key: userIdentity.userCsr?.userKey,
CA: [communityRootCa],
it('community is only launched once', async () => {
const launchCommunityPayload = {
community: community,
network: {
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
},
peers: community.peerList,
}

//@ts-ignore
Expand All @@ -157,22 +155,15 @@ describe('ConnectionsManagerService', () => {
})

it('Bug reproduction - Error on startup - Error: TOR: Connection already established - Trigger launchCommunity from backend and state manager', async () => {
const launchCommunityPayload: InitCommunityPayload = {
id: community.id,
await localDbService.setCommunity(community)
await localDbService.setCurrentCommunityId(community.id)
// TODO: Revisit this when we move the Identity model to the backend, since
// this network data lives in that model.
const network = {
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
certs: {
// @ts-expect-error
certificate: userIdentity.userCertificate,
// @ts-expect-error
key: userIdentity.userCsr?.userKey,
CA: [communityRootCa],
},
peers: community.peerList,
}

// await connectionsManager.init()
await localDbService.put(LocalDBKeys.COMMUNITY, launchCommunityPayload)
await localDbService.setNetworkInfo(network)

const peerid = 'QmaEvCkpUG7GxhgvMkk8wxurfi1ehjHhSUNRksWTmXN2ix'
await localDbService.put(LocalDBKeys.PEERS, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,6 @@ describe('Connections manager', () => {
}
const emitSpy = jest.spyOn(libp2pService, 'emit')

const launchCommunityPayload: InitCommunityPayload = {
id: community.id,
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
certs: {
// @ts-expect-error
certificate: userIdentity.userCertificate,
// @ts-expect-error
key: userIdentity.userCsr?.userKey,
CA: [communityRootCa],
},
peers: community.peerList,
}

await localDbService.put(LocalDBKeys.COMMUNITY, launchCommunityPayload)

// Peer connected
await connectionsManagerService.init()
libp2pService.connectedPeers.set(peerId.toString(), DateTime.utc().valueOf())
Expand Down Expand Up @@ -206,19 +190,15 @@ describe('Connections manager', () => {
)
}

const launchCommunityPayload: InitCommunityPayload = {
id: community.id,
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
certs: {
// @ts-expect-error Identity.userCertificate can be null
certificate: userIdentity.userCertificate,
// @ts-expect-error Identity.userCertificate userCsr.userKey can be undefined
key: userIdentity.userCsr?.userKey,
// @ts-expect-error
CA: [community.rootCa],
const launchCommunityPayload = {
community: {
id: community.id,
peerList,
},
network: {
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
},
peers: peerList,
}
await connectionsManagerService.init()
await connectionsManagerService.launchCommunity(launchCommunityPayload)
Expand Down Expand Up @@ -248,19 +228,15 @@ describe('Connections manager', () => {
)
}

const launchCommunityPayload: InitCommunityPayload = {
id: community.id,
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
certs: {
// @ts-expect-error Identity.userCertificate can be null
certificate: userIdentity.userCertificate,
// @ts-expect-error
key: userIdentity.userCsr?.userKey,
// @ts-expect-error
CA: [community.rootCa],
const launchCommunityPayload = {
community: {
id: community.id,
peerList,
},
network: {
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
},
peers: peerList,
}

await connectionsManagerService.launchCommunity(launchCommunityPayload)
Expand Down
Loading
Loading