diff --git a/packages/integration-tests/lib/communities.test.js b/packages/integration-tests/lib/communities.test.js deleted file mode 100644 index c25dcc1c6d..0000000000 --- a/packages/integration-tests/lib/communities.test.js +++ /dev/null @@ -1,205 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const webcrypto_1 = require("@peculiar/webcrypto"); -const communitiesTestUtils_1 = require("./communitiesTestUtils"); -const identity_1 = require("@zbayapp/identity"); -const nectar_1 = require("@zbayapp/nectar"); -const nectar_2 = require("@zbayapp/nectar"); -const identity_2 = __importDefault(require("@zbayapp/identity")); -const utils_1 = require("./utils"); -const nectar_3 = require("@zbayapp/nectar"); -const nectar_4 = require("@zbayapp/nectar"); -const nectar_5 = require("@zbayapp/nectar"); -const nectar_6 = require("@zbayapp/nectar"); -const nectar_7 = require("@zbayapp/nectar"); -jest.setTimeout(600000); -const crypto = new webcrypto_1.Crypto(); -global.crypto = crypto; -describe('communities - with tor', () => { - let owner; - let userOne; - let userTwo; - beforeAll(async () => { - owner = await (0, utils_1.createApp)(); - userOne = await (0, utils_1.createApp)(); - userTwo = await (0, utils_1.createApp)(); - }); - afterAll(async () => { - await owner.manager.closeAllServices(); - await userOne.manager.closeAllServices(); - await userTwo.manager.closeAllServices(); - }); - test('Owner creates community', async () => { - await (0, communitiesTestUtils_1.createCommunity)({ userName: 'Owner', store: owner.store }); - }); - test('Two users join community', async () => { - const ownerData = (0, communitiesTestUtils_1.getCommunityOwnerData)(owner.store); - await (0, communitiesTestUtils_1.joinCommunity)(Object.assign(Object.assign({}, ownerData), { store: userOne.store, userName: 'username1', expectedPeersCount: 2 })); - await (0, communitiesTestUtils_1.joinCommunity)(Object.assign(Object.assign({}, ownerData), { store: userTwo.store, userName: 'username2', expectedPeersCount: 3 })); - }); - test('Owner and users received certificates', async () => { - await (0, communitiesTestUtils_1.assertReceivedCertificates)('owner', 3, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedCertificates)('userOne', 3, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedCertificates)('userTwo', 3, 120000, userTwo.store); - }); - test('Users replicated channel and subscribed to it', async () => { - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)('owner', 1, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)('userTwo', 1, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)('userTwo', 1, 120000, userTwo.store); - }); - let ownerMessageData; - let userOneMessageData; - let userTwoMessageData; - test('Every user sends one message to general channel', async () => { - ownerMessageData = await (0, communitiesTestUtils_1.sendMessage)('owner says hi', owner.store); - userOneMessageData = await (0, communitiesTestUtils_1.sendMessage)('userOne says hi', userOne.store); - userTwoMessageData = await (0, communitiesTestUtils_1.sendMessage)('userTwo says hi', userTwo.store); - }); - test('Every user replicated all messages', async () => { - await (0, communitiesTestUtils_1.assertReceivedMessages)('owner', 3, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessages)('userOne', 3, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedMessages)('userTwo', 3, 120000, userTwo.store); - }); - test('Replicated messages are valid', async () => { - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)('owner', [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)('userOne', [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)('userTwo', [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - }); -}); -describe('communities - without tor', () => { - let owner; - let userOne; - let userTwo; - beforeAll(async () => { - owner = await (0, utils_1.createAppWithoutTor)(); - userOne = await (0, utils_1.createAppWithoutTor)(); - userTwo = await (0, utils_1.createAppWithoutTor)(); - }); - afterAll(async () => { - await owner.manager.closeAllServices(); - await userOne.manager.closeAllServices(); - await userTwo.manager.closeAllServices(); - }); - test('Owner creates community', async () => { - await (0, communitiesTestUtils_1.createCommunity)({ userName: 'Owner', store: owner.store }); - }); - test('Two users join community', async () => { - const ownerData = (0, communitiesTestUtils_1.getCommunityOwnerData)(owner.store); - await (0, communitiesTestUtils_1.joinCommunity)(Object.assign(Object.assign({}, ownerData), { store: userOne.store, userName: 'username1', expectedPeersCount: 2 })); - await (0, communitiesTestUtils_1.joinCommunity)(Object.assign(Object.assign({}, ownerData), { store: userTwo.store, userName: 'username2', expectedPeersCount: 3 })); - }); - test('Owner and users received certificates', async () => { - await (0, communitiesTestUtils_1.assertReceivedCertificates)('owner', 3, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedCertificates)('userOne', 3, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedCertificates)('userTwo', 3, 120000, userTwo.store); - }); - test('Users replicated channel and subscribed to it', async () => { - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)('owner', 1, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)('userTwo', 1, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)('userTwo', 1, 120000, userTwo.store); - }); - let ownerMessageData; - let userOneMessageData; - let userTwoMessageData; - test('Every user sends one message to general channel', async () => { - ownerMessageData = await (0, communitiesTestUtils_1.sendMessage)('owner says hi', owner.store); - userOneMessageData = await (0, communitiesTestUtils_1.sendMessage)('userOne says hi', userOne.store); - userTwoMessageData = await (0, communitiesTestUtils_1.sendMessage)('userTwo says hi', userTwo.store); - }); - test('Every user replicated all messages', async () => { - await (0, communitiesTestUtils_1.assertReceivedMessages)('owner', 3, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessages)('userOne', 3, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedMessages)('userTwo', 3, 120000, userTwo.store); - }); - test('Replicated messages are valid', async () => { - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)('owner', [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)('userOne', [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)('userTwo', [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - }); -}); -describe('registrar', () => { - let owner; - beforeAll(async () => { - owner = await (0, utils_1.createAppWithoutTor)(); - }); - afterAll(async () => { - await owner.manager.closeAllServices(); - }); - test('try to join offline registrar', async () => { - await (0, communitiesTestUtils_1.tryToJoinOfflineRegistrar)(owner.store); - }); - test('launch communities and registrars on startup', async () => { - // TODO: Move store mock into separate module and share between all the tests across nectar - const community = { - name: 'communityName', - id: 'F1141EBCF93387E5A28696C5B41E2177', - CA: { - rootCertString: 'MIIBTTCB8wIBATAKBggqhkjOPQQDAjASMRAwDgYDVQQDEwdaYmF5IENBMB4XDTEwMTIyODEwMTAxMFoXDTMwMTIyODEwMTAxMFowEjEQMA4GA1UEAxMHWmJheSBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLr3fF0hy2gOYfXXQKAB2a7iIcLE2M1FQWlSYLOJkqAoBuaVr3tJ+H1wahj3TXdATrt4TNoQASUvprgCa1tO6e6jPzA9MA8GA1UdEwQIMAYBAf8CAQMwCwYDVR0PBAQDAgCGMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAKBggqhkjOPQQDAgNJADBGAiEAhTEZmbAaS4iyTVok8yApc44nmI1tkGiDE8fa5tXpDXMCIQCEwGwkz2mTq2vhr0gs20yDILobXpWaCd9G814o2qO/1w==', - rootKeyString: 'MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgmu613x9FrbAQtIVD56oYGfq8YfeZ99ZZ/WXByN2dXzygCgYIKoZIzj0DAQehRANCAAS693xdIctoDmH110CgAdmu4iHCxNjNRUFpUmCziZKgKAbmla97Sfh9cGoY9013QE67eEzaEAElL6a4AmtbTunu', - }, - registrarUrl: '', - rootCa: '', - peerList: [], - registrar: { - privateKey: '', - address: '', - }, - onionAddress: '', - privateKey: '', - port: 0, - }; - const identity = { - id: 'F1141EBCF93387E5A28696C5B41E2177', - hiddenService: { - onionAddress: 'ybrmqwsudwxjpzugnl66hx2526nox5nzgmrtzveteud5f7anpjw62zqd', - privateKey: 'ED25519-V3:uJESjXQXngfVDTyKrztYrnY00lR5XZSNcHlxZlM/JV+exmG1nI8I+HVlpM6+G7yk4b53Lb3xnFmDWJ7GSN3gDQ==', - }, - peerId: { - id: 'QmXRJb5gdjcrb9VN1UEEnc5VYUHcDppJYykpf5QHWSrGjC', - privKey: 'CAASqAkwggSkAgEAAoIBAQCj5CFP8qQHFAwJKr6tusf4CcLWhrGHaKuweiEoxJKggGM3I1UlB1h/Jn72gwj0RQACLm7Hwwr8gU0z5CIWfH6VBroz/xKNHCM0R6mn11b6GuFiqLJAHpvL733Quxsq61WmF5+vzppdqzcbm8pEAeo1zQqIkm1+zyi/kyzFCUgHUbCYR+yPsWNoYUL042q0XfdupK2FY+zq1IiIiiyWU2/wx/uNxrp1mM7uiy0d/4wRbuUMY965jurOdmE3LzRBR9J1GkHfA2MPnnrZxaJCwKnfLS1wE0Wpn2+r5+8C/rA3Jm5RURsi6D17NEBgUQdvjlkP5Bv4mMZ5B4Gi/0ocXPdrAgMBAAECggEAETpEyiueVGQmE7ybiJWOuaMFCRnlhW9aRNXBsJBhPV/hjgU3yQmposwAIpeJlGvAYXpSCMuW1w4ceGztrGFvyOiJIDga0hx4EuHJkqwPJ4E12fITsqvFAr3tAsj4RR2xxiDLl2ZnUZtS0qMgst9kqD0ic1K5EdBi3yhwV1HvcV1YmYW+xScgbnhjONRtPPdvg1fMxZ97eQ/xdjnpHsphsA9BOpgMKR9Jz/zIlER1zQJJKdivP6VLNZ2wua0E7T+Xo/1pnsG1wKuuLlfog2b8LNySVWrsVPuCdmsReaTlj0NuZcadTroMb6dQ79F30Zsb/IaRLMbHTx0s56MCI52h6QKBgQDki2KftprGbdLvrCCak2dBi02ocEC624d6SMCMnFzNVSBcyx1lGoiU1+wsT2+Ip4efTJLe2YBUBmgN1yWpe1z6rhaeHj3LasVJL5cHTvIxig8q73+P9Ta+sMK6pTpFPO2mwZnrdg0n1w5yfvuf2irCTZvd+Kt9B3Y+TSmlnEQW3QKBgQC3lGht7MALUuTFxKr0DG0Mqp7+73J0qyy01ZGJW05HjEW6ad/R8v8sLhWi3N4yZ48e8tf7cNofnEjNzlb2au2+26xwIWoe+BKAVUQ89iEOiqzZJI69U3/v+JlC6CPNQvITSYTBji9b4s9PMcV+qFf5Bn0Yh2qgcNfnoTMcK/lO5wKBgQCdvh76QZ0ebFr1FgcC6c6RDMczBReIYVFm86QC6UGcb68AnSjSybePlGDsTH+dAJS5PK76pYDPfgR/2QmjqwQH+fSeeh0Is88rrm89mh3MV5AUgG25PPTmNTaSgMxxUZZuTJ4iSL7XyrWsDT07ned5aPu1/5bNm0LfyX5/UhYk+QKBgFPiMl2YQqBp/jMIDH17eBDDnecrjocU+FahB+FVoU08IVhurGEIweR0IlrKxZUOkO05VcuE44ZyKSoxULdEYOJHCmIqQo1oGTweuhGI/c3hO930wGxuTRVf6NgTrthJ8MczXr/6slUwLD4ppe6cCaa2ek7NAcHSDjW/CNWkmkSdAoGBAJ3YMKwuvptdgMmRF2vp6EVhpRRKFAcL+GePoEKo0MXKi0n/YRcJYropgTN8Dt0mn9CHIjslmlyOAXQsXQzbEVrMXBWL3O/poB/gLUPdgN+vvomYL2jDIbnp+KnUGaGHz1yeEtFcq3LGNC0iY3WVCA7P9oUs5IFaEPsLsUCDgNRh', - pubKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCj5CFP8qQHFAwJKr6tusf4CcLWhrGHaKuweiEoxJKggGM3I1UlB1h/Jn72gwj0RQACLm7Hwwr8gU0z5CIWfH6VBroz/xKNHCM0R6mn11b6GuFiqLJAHpvL733Quxsq61WmF5+vzppdqzcbm8pEAeo1zQqIkm1+zyi/kyzFCUgHUbCYR+yPsWNoYUL042q0XfdupK2FY+zq1IiIiiyWU2/wx/uNxrp1mM7uiy0d/4wRbuUMY965jurOdmE3LzRBR9J1GkHfA2MPnnrZxaJCwKnfLS1wE0Wpn2+r5+8C/rA3Jm5RURsi6D17NEBgUQdvjlkP5Bv4mMZ5B4Gi/0ocXPdrAgMBAAE=', - }, - dmKeys: { - publicKey: '0bd934b164fdbf09a2675233bd9d5c396ce3a5944f92485c8c98b72ec3148f51', - privateKey: '51da400fb7323793604ec204c60f3e1c96b1b3023d2eadc515376e37faf4b9f8', - }, - zbayNickname: '', - userCsr: undefined, - userCertificate: '', - }; - let communityChannels = { - id: 'F1141EBCF93387E5A28696C5B41E2177', - currentChannel: 'general', - channels: nectar_7.publicChannelsAdapter.getInitialState(), - channelMessages: nectar_7.channelMessagesAdapter.getInitialState(), - channelLoadingSlice: 0, - }; - const userCsr = await (0, identity_1.createUserCsr)({ - zbayNickname: 'fgdgfg', - commonName: 'ybrmqwsudwxjpzugnl66hx2526nox5nzgmrtzveteud5f7anpjw62zqd', - peerId: 'QmXRJb5gdjcrb9VN1UEEnc5VYUHcDppJYykpf5QHWSrGjC', - dmPublicKey: '0bd934b164fdbf09a2675233bd9d5c396ce3a5944f92485c8c98b72ec3148f51', - signAlg: identity_2.default.signAlg, - hashAlg: identity_2.default.hashAlg, - }); - userCsr.userKey = - 'MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgrSJ366ji2AfRNC9BDnViHl5V+A+fnjiUdUuPav3G8rygCgYIKoZIzj0DAQehRANCAAQpI18Np+59RC7UXkAfcl8mu8mrtgAwjv5pN18RmzGw2vV6iHbJ8RrujJZF9Z5rDqGYZAP2UCTyKzWTOC6740RD'; - identity.userCsr = userCsr; - identity.userCertificate = - 'MIICDTCCAbMCBgF9Lq/VWDAKBggqhkjOPQQDAjASMRAwDgYDVQQDEwdaYmF5IENBMB4XDTIxMTExNzE2MTY1NVoXDTMwMDEzMTIzMDAwMFowSTFHMEUGA1UEAxM+eWJybXF3c3Vkd3hqcHp1Z25sNjZoeDI1MjZub3g1bnpnbXJ0enZldGV1ZDVmN2FucGp3NjJ6cWQub25pb24wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQpI18Np+59RC7UXkAfcl8mu8mrtgAwjv5pN18RmzGw2vV6iHbJ8RrujJZF9Z5rDqGYZAP2UCTyKzWTOC6740RDo4HCMIG/MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgCOMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAvBgkqhkiG9w0BCQwEIgQgFzGXNQSk2IzgcI35nT9GmfKunA1jJHOdV6ZWRhOADhIwFgYKKwYBBAGDjBsCAQQIEwZmZ2RnZmcwPQYJKwYBAgEPAwEBBDATLlFtWFJKYjVnZGpjcmI5Vk4xVUVFbmM1VllVSGNEcHBKWXlrcGY1UUhXU3JHakMwCgYIKoZIzj0EAwIDSAAwRQIhAJmsMNFbttx9i0OMYIzKsALrfCUU8rX70S8Oj2IZp/vWAiA0b+6MR0ANnJkjW6HcClS6K2XHvOizmzQab+8rJNJVag=='; - const app = await (0, utils_1.createApp)({ - [nectar_1.StoreKeys.Communities]: Object.assign(Object.assign({}, new nectar_4.CommunitiesState()), { currentCommunity: 'F1141EBCF93387E5A28696C5B41E2177', communities: Object.assign({}, nectar_3.communitiesAdapter.setAll(nectar_3.communitiesAdapter.getInitialState(), [ - community, - ])) }), - [nectar_1.StoreKeys.Identity]: Object.assign(Object.assign({}, new nectar_5.IdentityState()), { identities: Object.assign({}, nectar_2.identityAdapter.setAll(nectar_2.identityAdapter.getInitialState(), [ - identity, - ])) }), - [nectar_1.StoreKeys.PublicChannels]: Object.assign(Object.assign({}, new nectar_6.PublicChannelsState()), { channels: nectar_7.communityChannelsAdapter.setAll(nectar_7.communityChannelsAdapter.getInitialState(), [communityChannels]) }), - }); - await app.runSaga(communitiesTestUtils_1.launchCommunitiesOnStartupSaga).toPromise(); - await app.manager.closeAllServices(); - }); -}); diff --git a/packages/integration-tests/lib/communitiesTestUtils.js b/packages/integration-tests/lib/communitiesTestUtils.js deleted file mode 100644 index 85c345ab4c..0000000000 --- a/packages/integration-tests/lib/communitiesTestUtils.js +++ /dev/null @@ -1,214 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.launchCommunitiesOnStartupSaga = exports.tryToJoinOfflineRegistrar = exports.joinCommunity = exports.createCommunity = exports.getCommunityOwnerData = exports.assertReceivedMessagesAreValid = exports.assertReceivedMessages = exports.sendMessage = exports.assertReceivedChannelsAndSubscribe = exports.assertReceivedCertificates = void 0; -const typed_redux_saga_1 = require("typed-redux-saga"); -const wait_for_expect_1 = __importDefault(require("wait-for-expect")); -const nectar_1 = require("@zbayapp/nectar"); -const nectar_2 = require("@zbayapp/nectar"); -const nectar_3 = require("@zbayapp/nectar"); -const nectar_4 = require("@zbayapp/nectar"); -const logger_1 = __importDefault(require("./logger")); -const utils_1 = require("./utils"); -const lib_1 = require("@zbayapp/identity/lib"); -const log = (0, logger_1.default)(); -async function assertReceivedCertificates(userName, expectedCount, maxTime = 600000, store) { - log(`User ${userName} starts waiting ${maxTime}ms for certificates`); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Users.certificates.ids).toHaveLength(expectedCount); - }, maxTime); - log(`User ${userName} received ${store.getState().Users.certificates.ids.length} certificates`); -} -exports.assertReceivedCertificates = assertReceivedCertificates; -async function assertReceivedChannelsAndSubscribe(userName, expectedCount, maxTime = 600000, store) { - log(`User ${userName} starts waiting ${maxTime}ms for channels`); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().PublicChannels.channels.entities[communityId].channels - .ids).toHaveLength(expectedCount); - }, maxTime); - await store.dispatch(nectar_3.publicChannels.actions.setCurrentChannel(store.getState().PublicChannels.channels.entities[communityId].channels - .ids[0])); - await store.dispatch(nectar_3.publicChannels.actions.subscribeForAllTopics(communityId)); - log(`User ${userName} received ${store.getState().PublicChannels.channels.entities[communityId].channels - .ids.length} channels`); -} -exports.assertReceivedChannelsAndSubscribe = assertReceivedChannelsAndSubscribe; -async function sendMessage(message, store) { - store.dispatch(nectar_4.messages.actions.sendMessage(message)); - const communityId = store.getState().Communities.communities.ids[0]; - const certificate = store.getState().Identity.identities.entities[communityId].userCertificate; - const parsedCertificate = await (0, lib_1.parseCertificate)(certificate); - const publicKey = (0, lib_1.keyFromCertificate)(parsedCertificate); - return { - message, - publicKey, - }; -} -exports.sendMessage = sendMessage; -async function assertReceivedMessages(userName, expectedCount, maxTime = 600000, store) { - log(`User ${userName} starts waiting ${maxTime}ms for messages`); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().PublicChannels.channels.entities[communityId] - .channelMessages.general.ids).toHaveLength(expectedCount); - }, maxTime); - log(`User ${userName} received ${store.getState().PublicChannels.channels.entities[communityId] - .channelMessages.general.ids.length} messages`); -} -exports.assertReceivedMessages = assertReceivedMessages; -async function assertReceivedMessagesAreValid(userName, messages, maxTime = 600000, store) { - log(`User ${userName} checks is messages are valid`); - const communityId = store.getState().Communities.communities.ids[0]; - const receivedMessages = Object.values(store.getState().PublicChannels.channels.entities[communityId] - .channelMessages.general.messages); - const validMessages = []; - for (let receivedMessage of receivedMessages) { - const msg = messages.filter( - // @ts-ignorets-ignore - (message) => message.publicKey === receivedMessage.pubKey); - if (msg) { - validMessages.push(msg); - } - } - await (0, wait_for_expect_1.default)(() => { - expect(validMessages).toHaveLength(messages.length); - }, maxTime); -} -exports.assertReceivedMessagesAreValid = assertReceivedMessagesAreValid; -const getCommunityOwnerData = (ownerStore) => { - const ownerStoreState = ownerStore.getState(); - const community = ownerStoreState.Communities.communities.entities[ownerStoreState.Communities.currentCommunity]; - const registrarAddress = community.onionAddress; - const ownerIdentityState = ownerStore.getState().Identity; - return { - registrarAddress, - communityId: community.id, - ownerPeerId: ownerIdentityState.identities.entities[ownerIdentityState.identities.ids[0]].peerId.id, - ownerRootCA: community.rootCa, - registrarPort: community.port, - }; -}; -exports.getCommunityOwnerData = getCommunityOwnerData; -async function createCommunity({ userName, store }) { - const timeout = 120000; - const communityName = 'CommunityName'; - store.dispatch(nectar_1.communities.actions.createNewCommunity(communityName)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.ids).toHaveLength(1); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.ids).toHaveLength(1); - }, timeout); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].hiddenService - .onionAddress).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].peerId.id).toHaveLength(46); - }, timeout); - store.dispatch(nectar_2.identity.actions.registerUsername(userName)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].userCertificate).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.entities[communityId].CA).toHaveProperty('rootObject'); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.entities[communityId] - .onionAddress).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Users.certificates.ids).toHaveLength(1); - }, timeout); -} -exports.createCommunity = createCommunity; -async function joinCommunity(payload) { - const { registrarAddress, userName, ownerPeerId, ownerRootCA, expectedPeersCount, registrarPort, store, } = payload; - const timeout = 120000; - let address; - if (payload.registrarAddress === '0.0.0.0') { - address = `${registrarAddress}:${registrarPort}`; - } - else { - address = registrarAddress; - } - store.dispatch(nectar_1.communities.actions.joinCommunity(address)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.ids).toHaveLength(1); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.ids).toHaveLength(1); - }, timeout); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].hiddenService - .onionAddress).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].peerId.id).toHaveLength(46); - }, timeout); - const userPeerId = store.getState().Identity.identities.entities[communityId].peerId.id; - store.dispatch(nectar_2.identity.actions.registerUsername(userName)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].userCertificate).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.entities[communityId].rootCa).toEqual(ownerRootCA); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.entities[communityId].peerList - .length).toEqual(expectedPeersCount); - }, timeout); - const peerList = store.getState().Communities.communities.entities[communityId].peerList; - await (0, wait_for_expect_1.default)(() => { - expect(peerList[0]).toMatch(new RegExp(ownerPeerId)); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(peerList[peerList.length - 1]).toMatch(new RegExp(userPeerId)); - }, timeout); -} -exports.joinCommunity = joinCommunity; -async function tryToJoinOfflineRegistrar(store) { - const timeout = 120000; - const userName = 'userName'; - store.dispatch(nectar_1.communities.actions.joinCommunity('yjnblkcrvqexxmntrs7hscywgebrizvz2jx4g4m5wq4x7uzi5syv5cid')); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.ids).toHaveLength(1); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.ids).toHaveLength(1); - }, timeout); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].hiddenService - .onionAddress).toHaveLength(62); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].peerId.id).toHaveLength(46); - }, timeout); - store.dispatch(nectar_2.identity.actions.registerUsername(userName)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Errors[communityId].entities.registrar.type).toEqual('registrar'); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Errors[communityId].entities.registrar.message).toEqual('Registering username failed.'); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Errors[communityId].entities.registrar.communityId).toEqual(communityId); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Errors[communityId].entities.registrar.code).toEqual(500); - }, timeout); -} -exports.tryToJoinOfflineRegistrar = tryToJoinOfflineRegistrar; -function* launchCommunitiesOnStartupSaga() { - yield* (0, typed_redux_saga_1.spawn)(utils_1.assertNoErrors); - yield* (0, typed_redux_saga_1.take)(nectar_1.communities.actions.launchRegistrar); - yield* (0, typed_redux_saga_1.take)(nectar_1.communities.actions.community); - yield* (0, typed_redux_saga_1.take)(nectar_1.communities.actions.responseRegistrar); -} -exports.launchCommunitiesOnStartupSaga = launchCommunitiesOnStartupSaga; diff --git a/packages/integration-tests/lib/integrationTests/communities/communities.test.js b/packages/integration-tests/lib/integrationTests/communities/communities.test.js deleted file mode 100644 index c3dab10ff2..0000000000 --- a/packages/integration-tests/lib/integrationTests/communities/communities.test.js +++ /dev/null @@ -1,202 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const webcrypto_1 = require("@peculiar/webcrypto"); -const communitiesTestUtils_1 = require("./communitiesTestUtils"); -const identity_1 = require("@zbayapp/identity"); -const nectar_1 = require("@zbayapp/nectar"); -const nectar_2 = require("@zbayapp/nectar"); -const identity_2 = require("@zbayapp/identity"); -const utils_1 = require("../../utils"); -const nectar_3 = require("@zbayapp/nectar"); -const nectar_4 = require("@zbayapp/nectar"); -const nectar_5 = require("@zbayapp/nectar"); -const nectar_6 = require("@zbayapp/nectar"); -const nectar_7 = require("@zbayapp/nectar"); -jest.setTimeout(600000); -const crypto = new webcrypto_1.Crypto(); -global.crypto = crypto; -describe("communities - with tor", () => { - let owner; - let userOne; - let userTwo; - beforeAll(async () => { - owner = await (0, utils_1.createApp)(); - userOne = await (0, utils_1.createApp)(); - userTwo = await (0, utils_1.createApp)(); - }); - afterAll(async () => { - await owner.manager.closeAllServices(); - await userOne.manager.closeAllServices(); - await userTwo.manager.closeAllServices(); - }); - test("Owner creates community", async () => { - await (0, communitiesTestUtils_1.createCommunity)({ userName: "Owner", store: owner.store }); - }); - test("Two users join community", async () => { - const ownerData = (0, communitiesTestUtils_1.getCommunityOwnerData)(owner.store); - await (0, communitiesTestUtils_1.joinCommunity)(Object.assign(Object.assign({}, ownerData), { store: userOne.store, userName: "username1", expectedPeersCount: 2 })); - await (0, communitiesTestUtils_1.joinCommunity)(Object.assign(Object.assign({}, ownerData), { store: userTwo.store, userName: "username2", expectedPeersCount: 3 })); - }); - test("Owner and users received certificates", async () => { - await (0, communitiesTestUtils_1.assertReceivedCertificates)("owner", 3, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedCertificates)("userOne", 3, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedCertificates)("userTwo", 3, 120000, userTwo.store); - }); - test("Users replicated channel and subscribed to it", async () => { - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)("owner", 1, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)("userTwo", 1, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)("userTwo", 1, 120000, userTwo.store); - }); - let ownerMessageData; - let userOneMessageData; - let userTwoMessageData; - test("Every user sends one message to general channel", async () => { - ownerMessageData = await (0, communitiesTestUtils_1.sendMessage)("owner says hi", owner.store); - userOneMessageData = await (0, communitiesTestUtils_1.sendMessage)("userOne says hi", userOne.store); - userTwoMessageData = await (0, communitiesTestUtils_1.sendMessage)("userTwo says hi", userTwo.store); - }); - test("Every user replicated all messages", async () => { - await (0, communitiesTestUtils_1.assertReceivedMessages)("owner", 3, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessages)("userOne", 3, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedMessages)("userTwo", 3, 120000, userTwo.store); - }); - test("Replicated messages are valid", async () => { - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)("owner", [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)("userOne", [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)("userTwo", [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - }); -}); -describe("communities - without tor", () => { - let owner; - let userOne; - let userTwo; - beforeAll(async () => { - owner = await (0, utils_1.createAppWithoutTor)(); - userOne = await (0, utils_1.createAppWithoutTor)(); - userTwo = await (0, utils_1.createAppWithoutTor)(); - }); - afterAll(async () => { - await owner.manager.closeAllServices(); - await userOne.manager.closeAllServices(); - await userTwo.manager.closeAllServices(); - }); - test("Owner creates community", async () => { - await (0, communitiesTestUtils_1.createCommunity)({ userName: "Owner", store: owner.store }); - }); - test("Two users join community", async () => { - const ownerData = (0, communitiesTestUtils_1.getCommunityOwnerData)(owner.store); - await (0, communitiesTestUtils_1.joinCommunity)(Object.assign(Object.assign({}, ownerData), { store: userOne.store, userName: "username1", expectedPeersCount: 2 })); - await (0, communitiesTestUtils_1.joinCommunity)(Object.assign(Object.assign({}, ownerData), { store: userTwo.store, userName: "username2", expectedPeersCount: 3 })); - }); - test("Owner and users received certificates", async () => { - await (0, communitiesTestUtils_1.assertReceivedCertificates)("owner", 3, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedCertificates)("userOne", 3, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedCertificates)("userTwo", 3, 120000, userTwo.store); - }); - test("Users replicated channel and subscribed to it", async () => { - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)("owner", 1, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)("userTwo", 1, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedChannelsAndSubscribe)("userTwo", 1, 120000, userTwo.store); - }); - let ownerMessageData; - let userOneMessageData; - let userTwoMessageData; - test("Every user sends one message to general channel", async () => { - ownerMessageData = await (0, communitiesTestUtils_1.sendMessage)("owner says hi", owner.store); - userOneMessageData = await (0, communitiesTestUtils_1.sendMessage)("userOne says hi", userOne.store); - userTwoMessageData = await (0, communitiesTestUtils_1.sendMessage)("userTwo says hi", userTwo.store); - }); - test("Every user replicated all messages", async () => { - await (0, communitiesTestUtils_1.assertReceivedMessages)("owner", 3, 120000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessages)("userOne", 3, 120000, userOne.store); - await (0, communitiesTestUtils_1.assertReceivedMessages)("userTwo", 3, 120000, userTwo.store); - }); - test("Replicated messages are valid", async () => { - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)("owner", [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)("userOne", [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - await (0, communitiesTestUtils_1.assertReceivedMessagesAreValid)("userTwo", [ownerMessageData, userOneMessageData, userTwoMessageData], 20000, owner.store); - }); -}); -describe("registrar", () => { - let owner; - beforeAll(async () => { - owner = await (0, utils_1.createAppWithoutTor)(); - }); - afterAll(async () => { - await owner.manager.closeAllServices(); - }); - test("try to join offline registrar", async () => { - await (0, communitiesTestUtils_1.tryToJoinOfflineRegistrar)(owner.store); - }); - test("launch communities and registrars on startup", async () => { - // TODO: Move store mock into separate module and share between all the tests across nectar - const community = { - name: "communityName", - id: "F1141EBCF93387E5A28696C5B41E2177", - CA: { - rootCertString: "MIIBTTCB8wIBATAKBggqhkjOPQQDAjASMRAwDgYDVQQDEwdaYmF5IENBMB4XDTEwMTIyODEwMTAxMFoXDTMwMTIyODEwMTAxMFowEjEQMA4GA1UEAxMHWmJheSBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLr3fF0hy2gOYfXXQKAB2a7iIcLE2M1FQWlSYLOJkqAoBuaVr3tJ+H1wahj3TXdATrt4TNoQASUvprgCa1tO6e6jPzA9MA8GA1UdEwQIMAYBAf8CAQMwCwYDVR0PBAQDAgCGMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAKBggqhkjOPQQDAgNJADBGAiEAhTEZmbAaS4iyTVok8yApc44nmI1tkGiDE8fa5tXpDXMCIQCEwGwkz2mTq2vhr0gs20yDILobXpWaCd9G814o2qO/1w==", - rootKeyString: "MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgmu613x9FrbAQtIVD56oYGfq8YfeZ99ZZ/WXByN2dXzygCgYIKoZIzj0DAQehRANCAAS693xdIctoDmH110CgAdmu4iHCxNjNRUFpUmCziZKgKAbmla97Sfh9cGoY9013QE67eEzaEAElL6a4AmtbTunu", - }, - registrarUrl: "", - rootCa: "", - peerList: [], - registrar: { - privateKey: "", - address: "", - }, - onionAddress: "", - privateKey: "", - port: 0, - }; - const user = { - id: "F1141EBCF93387E5A28696C5B41E2177", - hiddenService: { - onionAddress: "ybrmqwsudwxjpzugnl66hx2526nox5nzgmrtzveteud5f7anpjw62zqd", - privateKey: "ED25519-V3:uJESjXQXngfVDTyKrztYrnY00lR5XZSNcHlxZlM/JV+exmG1nI8I+HVlpM6+G7yk4b53Lb3xnFmDWJ7GSN3gDQ==", - }, - peerId: { - id: "QmXRJb5gdjcrb9VN1UEEnc5VYUHcDppJYykpf5QHWSrGjC", - privKey: "CAASqAkwggSkAgEAAoIBAQCj5CFP8qQHFAwJKr6tusf4CcLWhrGHaKuweiEoxJKggGM3I1UlB1h/Jn72gwj0RQACLm7Hwwr8gU0z5CIWfH6VBroz/xKNHCM0R6mn11b6GuFiqLJAHpvL733Quxsq61WmF5+vzppdqzcbm8pEAeo1zQqIkm1+zyi/kyzFCUgHUbCYR+yPsWNoYUL042q0XfdupK2FY+zq1IiIiiyWU2/wx/uNxrp1mM7uiy0d/4wRbuUMY965jurOdmE3LzRBR9J1GkHfA2MPnnrZxaJCwKnfLS1wE0Wpn2+r5+8C/rA3Jm5RURsi6D17NEBgUQdvjlkP5Bv4mMZ5B4Gi/0ocXPdrAgMBAAECggEAETpEyiueVGQmE7ybiJWOuaMFCRnlhW9aRNXBsJBhPV/hjgU3yQmposwAIpeJlGvAYXpSCMuW1w4ceGztrGFvyOiJIDga0hx4EuHJkqwPJ4E12fITsqvFAr3tAsj4RR2xxiDLl2ZnUZtS0qMgst9kqD0ic1K5EdBi3yhwV1HvcV1YmYW+xScgbnhjONRtPPdvg1fMxZ97eQ/xdjnpHsphsA9BOpgMKR9Jz/zIlER1zQJJKdivP6VLNZ2wua0E7T+Xo/1pnsG1wKuuLlfog2b8LNySVWrsVPuCdmsReaTlj0NuZcadTroMb6dQ79F30Zsb/IaRLMbHTx0s56MCI52h6QKBgQDki2KftprGbdLvrCCak2dBi02ocEC624d6SMCMnFzNVSBcyx1lGoiU1+wsT2+Ip4efTJLe2YBUBmgN1yWpe1z6rhaeHj3LasVJL5cHTvIxig8q73+P9Ta+sMK6pTpFPO2mwZnrdg0n1w5yfvuf2irCTZvd+Kt9B3Y+TSmlnEQW3QKBgQC3lGht7MALUuTFxKr0DG0Mqp7+73J0qyy01ZGJW05HjEW6ad/R8v8sLhWi3N4yZ48e8tf7cNofnEjNzlb2au2+26xwIWoe+BKAVUQ89iEOiqzZJI69U3/v+JlC6CPNQvITSYTBji9b4s9PMcV+qFf5Bn0Yh2qgcNfnoTMcK/lO5wKBgQCdvh76QZ0ebFr1FgcC6c6RDMczBReIYVFm86QC6UGcb68AnSjSybePlGDsTH+dAJS5PK76pYDPfgR/2QmjqwQH+fSeeh0Is88rrm89mh3MV5AUgG25PPTmNTaSgMxxUZZuTJ4iSL7XyrWsDT07ned5aPu1/5bNm0LfyX5/UhYk+QKBgFPiMl2YQqBp/jMIDH17eBDDnecrjocU+FahB+FVoU08IVhurGEIweR0IlrKxZUOkO05VcuE44ZyKSoxULdEYOJHCmIqQo1oGTweuhGI/c3hO930wGxuTRVf6NgTrthJ8MczXr/6slUwLD4ppe6cCaa2ek7NAcHSDjW/CNWkmkSdAoGBAJ3YMKwuvptdgMmRF2vp6EVhpRRKFAcL+GePoEKo0MXKi0n/YRcJYropgTN8Dt0mn9CHIjslmlyOAXQsXQzbEVrMXBWL3O/poB/gLUPdgN+vvomYL2jDIbnp+KnUGaGHz1yeEtFcq3LGNC0iY3WVCA7P9oUs5IFaEPsLsUCDgNRh", - pubKey: "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCj5CFP8qQHFAwJKr6tusf4CcLWhrGHaKuweiEoxJKggGM3I1UlB1h/Jn72gwj0RQACLm7Hwwr8gU0z5CIWfH6VBroz/xKNHCM0R6mn11b6GuFiqLJAHpvL733Quxsq61WmF5+vzppdqzcbm8pEAeo1zQqIkm1+zyi/kyzFCUgHUbCYR+yPsWNoYUL042q0XfdupK2FY+zq1IiIiiyWU2/wx/uNxrp1mM7uiy0d/4wRbuUMY965jurOdmE3LzRBR9J1GkHfA2MPnnrZxaJCwKnfLS1wE0Wpn2+r5+8C/rA3Jm5RURsi6D17NEBgUQdvjlkP5Bv4mMZ5B4Gi/0ocXPdrAgMBAAE=", - }, - dmKeys: { - publicKey: "0bd934b164fdbf09a2675233bd9d5c396ce3a5944f92485c8c98b72ec3148f51", - privateKey: "51da400fb7323793604ec204c60f3e1c96b1b3023d2eadc515376e37faf4b9f8", - }, - zbayNickname: "", - userCsr: undefined, - userCertificate: "", - }; - let communityChannels = { - id: "F1141EBCF93387E5A28696C5B41E2177", - currentChannel: "general", - channels: nectar_7.publicChannelsAdapter.getInitialState(), - channelMessages: nectar_7.channelMessagesAdapter.getInitialState(), - channelLoadingSlice: 0, - }; - const userCsr = await (0, identity_1.createUserCsr)({ - zbayNickname: "fgdgfg", - commonName: "ybrmqwsudwxjpzugnl66hx2526nox5nzgmrtzveteud5f7anpjw62zqd", - peerId: "QmXRJb5gdjcrb9VN1UEEnc5VYUHcDppJYykpf5QHWSrGjC", - dmPublicKey: "0bd934b164fdbf09a2675233bd9d5c396ce3a5944f92485c8c98b72ec3148f51", - signAlg: identity_2.configCrypto.signAlg, - hashAlg: identity_2.configCrypto.hashAlg, - }); - userCsr.userKey = - "MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgrSJ366ji2AfRNC9BDnViHl5V+A+fnjiUdUuPav3G8rygCgYIKoZIzj0DAQehRANCAAQpI18Np+59RC7UXkAfcl8mu8mrtgAwjv5pN18RmzGw2vV6iHbJ8RrujJZF9Z5rDqGYZAP2UCTyKzWTOC6740RD"; - user.userCsr = userCsr; - user.userCertificate = - "MIICDTCCAbMCBgF9Lq/VWDAKBggqhkjOPQQDAjASMRAwDgYDVQQDEwdaYmF5IENBMB4XDTIxMTExNzE2MTY1NVoXDTMwMDEzMTIzMDAwMFowSTFHMEUGA1UEAxM+eWJybXF3c3Vkd3hqcHp1Z25sNjZoeDI1MjZub3g1bnpnbXJ0enZldGV1ZDVmN2FucGp3NjJ6cWQub25pb24wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQpI18Np+59RC7UXkAfcl8mu8mrtgAwjv5pN18RmzGw2vV6iHbJ8RrujJZF9Z5rDqGYZAP2UCTyKzWTOC6740RDo4HCMIG/MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgCOMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAvBgkqhkiG9w0BCQwEIgQgFzGXNQSk2IzgcI35nT9GmfKunA1jJHOdV6ZWRhOADhIwFgYKKwYBBAGDjBsCAQQIEwZmZ2RnZmcwPQYJKwYBAgEPAwEBBDATLlFtWFJKYjVnZGpjcmI5Vk4xVUVFbmM1VllVSGNEcHBKWXlrcGY1UUhXU3JHakMwCgYIKoZIzj0EAwIDSAAwRQIhAJmsMNFbttx9i0OMYIzKsALrfCUU8rX70S8Oj2IZp/vWAiA0b+6MR0ANnJkjW6HcClS6K2XHvOizmzQab+8rJNJVag=="; - const app = await (0, utils_1.createApp)({ - [nectar_1.StoreKeys.Communities]: Object.assign(Object.assign({}, new nectar_4.communities.state()), { currentCommunity: "F1141EBCF93387E5A28696C5B41E2177", communities: Object.assign({}, nectar_3.communitiesAdapter.setAll(nectar_3.communitiesAdapter.getInitialState(), [ - community, - ])) }), - [nectar_1.StoreKeys.Identity]: Object.assign(Object.assign({}, new nectar_5.identity.state()), { identities: Object.assign({}, nectar_2.identityAdapter.setAll(nectar_2.identityAdapter.getInitialState(), [ - user, - ])) }), - [nectar_1.StoreKeys.PublicChannels]: Object.assign(Object.assign({}, new nectar_6.publicChannels.state()), { channels: nectar_7.communityChannelsAdapter.setAll(nectar_7.communityChannelsAdapter.getInitialState(), [communityChannels]) }), - }); - await app.runSaga(communitiesTestUtils_1.launchCommunitiesOnStartupSaga).toPromise(); - await app.manager.closeAllServices(); - }); -}); diff --git a/packages/integration-tests/lib/integrationTests/communities/communitiesTestUtils.js b/packages/integration-tests/lib/integrationTests/communities/communitiesTestUtils.js deleted file mode 100644 index 1ef523c940..0000000000 --- a/packages/integration-tests/lib/integrationTests/communities/communitiesTestUtils.js +++ /dev/null @@ -1,214 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.launchCommunitiesOnStartupSaga = exports.tryToJoinOfflineRegistrar = exports.joinCommunity = exports.createCommunity = exports.getCommunityOwnerData = exports.assertReceivedMessagesAreValid = exports.assertReceivedMessages = exports.sendMessage = exports.assertReceivedChannelsAndSubscribe = exports.assertReceivedCertificates = void 0; -const typed_redux_saga_1 = require("typed-redux-saga"); -const wait_for_expect_1 = __importDefault(require("wait-for-expect")); -const nectar_1 = require("@zbayapp/nectar"); -const nectar_2 = require("@zbayapp/nectar"); -const nectar_3 = require("@zbayapp/nectar"); -const nectar_4 = require("@zbayapp/nectar"); -const utils_1 = require("../../utils"); -const logger_1 = __importDefault(require("../../logger")); -const lib_1 = require("@zbayapp/identity/lib"); -const log = (0, logger_1.default)(); -async function assertReceivedCertificates(userName, expectedCount, maxTime = 600000, store) { - log(`User ${userName} starts waiting ${maxTime}ms for certificates`); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Users.certificates.ids).toHaveLength(expectedCount); - }, maxTime); - log(`User ${userName} received ${store.getState().Users.certificates.ids.length} certificates`); -} -exports.assertReceivedCertificates = assertReceivedCertificates; -async function assertReceivedChannelsAndSubscribe(userName, expectedCount, maxTime = 600000, store) { - log(`User ${userName} starts waiting ${maxTime}ms for channels`); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().PublicChannels.channels.entities[communityId].channels - .ids).toHaveLength(expectedCount); - }, maxTime); - await store.dispatch(nectar_3.publicChannels.actions.setCurrentChannel(store.getState().PublicChannels.channels.entities[communityId].channels - .ids[0])); - await store.dispatch(nectar_3.publicChannels.actions.subscribeForAllTopics(communityId)); - log(`User ${userName} received ${store.getState().PublicChannels.channels.entities[communityId].channels - .ids.length} channels`); -} -exports.assertReceivedChannelsAndSubscribe = assertReceivedChannelsAndSubscribe; -async function sendMessage(message, store) { - store.dispatch(nectar_4.messages.actions.sendMessage(message)); - const communityId = store.getState().Communities.communities.ids[0]; - const certificate = store.getState().Identity.identities.entities[communityId].userCertificate; - const parsedCertificate = await (0, lib_1.parseCertificate)(certificate); - const publicKey = (0, lib_1.keyFromCertificate)(parsedCertificate); - return { - message, - publicKey, - }; -} -exports.sendMessage = sendMessage; -async function assertReceivedMessages(userName, expectedCount, maxTime = 600000, store) { - log(`User ${userName} starts waiting ${maxTime}ms for messages`); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().PublicChannels.channels.entities[communityId] - .channelMessages.general.ids).toHaveLength(expectedCount); - }, maxTime); - log(`User ${userName} received ${store.getState().PublicChannels.channels.entities[communityId] - .channelMessages.general.ids.length} messages`); -} -exports.assertReceivedMessages = assertReceivedMessages; -async function assertReceivedMessagesAreValid(userName, messages, maxTime = 600000, store) { - log(`User ${userName} checks if messages are valid`); - const communityId = store.getState().Communities.communities.ids[0]; - const receivedMessages = Object.values(store.getState().PublicChannels.channels.entities[communityId] - .channelMessages.general.messages); - const validMessages = []; - for (let receivedMessage of receivedMessages) { - const msg = messages.filter( - // @ts-ignorets-ignore - (message) => message.publicKey === receivedMessage.pubKey); - if (msg) { - validMessages.push(msg); - } - } - await (0, wait_for_expect_1.default)(() => { - expect(validMessages).toHaveLength(messages.length); - }, maxTime); -} -exports.assertReceivedMessagesAreValid = assertReceivedMessagesAreValid; -const getCommunityOwnerData = (ownerStore) => { - const ownerStoreState = ownerStore.getState(); - const community = ownerStoreState.Communities.communities.entities[ownerStoreState.Communities.currentCommunity]; - const registrarAddress = community.onionAddress; - const ownerIdentityState = ownerStore.getState().Identity; - return { - registrarAddress, - communityId: community.id, - ownerPeerId: ownerIdentityState.identities.entities[ownerIdentityState.identities.ids[0]].peerId.id, - ownerRootCA: community.rootCa, - registrarPort: community.port, - }; -}; -exports.getCommunityOwnerData = getCommunityOwnerData; -async function createCommunity({ userName, store }) { - const timeout = 120000; - const communityName = 'CommunityName'; - store.dispatch(nectar_1.communities.actions.createNewCommunity(communityName)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.ids).toHaveLength(1); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.ids).toHaveLength(1); - }, timeout); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].hiddenService - .onionAddress).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].peerId.id).toHaveLength(46); - }, timeout); - store.dispatch(nectar_2.identity.actions.registerUsername(userName)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].userCertificate).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.entities[communityId].CA).toHaveProperty('rootObject'); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.entities[communityId] - .onionAddress).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Users.certificates.ids).toHaveLength(1); - }, timeout); -} -exports.createCommunity = createCommunity; -async function joinCommunity(payload) { - const { registrarAddress, userName, ownerPeerId, ownerRootCA, expectedPeersCount, registrarPort, store, } = payload; - const timeout = 120000; - let address; - if (payload.registrarAddress === '0.0.0.0') { - address = `${registrarAddress}:${registrarPort}`; - } - else { - address = registrarAddress; - } - store.dispatch(nectar_1.communities.actions.joinCommunity(address)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.ids).toHaveLength(1); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.ids).toHaveLength(1); - }, timeout); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].hiddenService - .onionAddress).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].peerId.id).toHaveLength(46); - }, timeout); - const userPeerId = store.getState().Identity.identities.entities[communityId].peerId.id; - store.dispatch(nectar_2.identity.actions.registerUsername(userName)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].userCertificate).toBeTruthy(); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.entities[communityId].rootCa).toEqual(ownerRootCA); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.entities[communityId].peerList - .length).toEqual(expectedPeersCount); - }, timeout); - const peerList = store.getState().Communities.communities.entities[communityId].peerList; - await (0, wait_for_expect_1.default)(() => { - expect(peerList[0]).toMatch(new RegExp(ownerPeerId)); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(peerList[peerList.length - 1]).toMatch(new RegExp(userPeerId)); - }, timeout); -} -exports.joinCommunity = joinCommunity; -async function tryToJoinOfflineRegistrar(store) { - const timeout = 120000; - const userName = 'userName'; - store.dispatch(nectar_1.communities.actions.joinCommunity('yjnblkcrvqexxmntrs7hscywgebrizvz2jx4g4m5wq4x7uzi5syv5cid')); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.ids).toHaveLength(1); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Communities.communities.ids).toHaveLength(1); - }, timeout); - const communityId = store.getState().Communities.communities.ids[0]; - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].hiddenService - .onionAddress).toHaveLength(62); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Identity.identities.entities[communityId].peerId.id).toHaveLength(46); - }, timeout); - store.dispatch(nectar_2.identity.actions.registerUsername(userName)); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Errors[communityId].entities.registrar.type).toEqual('registrar'); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Errors[communityId].entities.registrar.message).toEqual('Registering username failed.'); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Errors[communityId].entities.registrar.communityId).toEqual(communityId); - }, timeout); - await (0, wait_for_expect_1.default)(() => { - expect(store.getState().Errors[communityId].entities.registrar.code).toEqual(500); - }, timeout); -} -exports.tryToJoinOfflineRegistrar = tryToJoinOfflineRegistrar; -function* launchCommunitiesOnStartupSaga() { - yield* (0, typed_redux_saga_1.spawn)(utils_1.assertNoErrors); - yield* (0, typed_redux_saga_1.take)(nectar_1.communities.actions.launchRegistrar); - yield* (0, typed_redux_saga_1.take)(nectar_1.communities.actions.community); - yield* (0, typed_redux_saga_1.take)(nectar_1.communities.actions.responseRegistrar); -} -exports.launchCommunitiesOnStartupSaga = launchCommunitiesOnStartupSaga; diff --git a/packages/integration-tests/lib/logger.js b/packages/integration-tests/lib/logger.js deleted file mode 100644 index 9053b5f9e4..0000000000 --- a/packages/integration-tests/lib/logger.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const debug_1 = __importDefault(require("debug")); -const resultLogger = () => { - const module = 'test'; - return Object.assign((0, debug_1.default)(`nectar:${module}`), { - failed: (0, debug_1.default)(`nectar:${module}:failed`), - passed: (0, debug_1.default)(`nectar:${module}:passed`), - }); -}; -exports.default = resultLogger; diff --git a/packages/integration-tests/lib/setupTests.js b/packages/integration-tests/lib/setupTests.js deleted file mode 100644 index f21f77331a..0000000000 --- a/packages/integration-tests/lib/setupTests.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const pkijs_1 = require("pkijs"); -const pkijs_2 = require("pkijs"); -const webcrypto_1 = require("@peculiar/webcrypto"); -const webcrypto = new webcrypto_1.Crypto(); -(0, pkijs_1.setEngine)('newEngine', webcrypto, new pkijs_2.CryptoEngine({ - name: '', - crypto: webcrypto, - subtle: webcrypto.subtle, -})); -global.crypto = webcrypto; diff --git a/packages/integration-tests/lib/utils.js b/packages/integration-tests/lib/utils.js deleted file mode 100644 index 9c6bd47f1f..0000000000 --- a/packages/integration-tests/lib/utils.js +++ /dev/null @@ -1,124 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.assertNoErrors = exports.createAppWithoutTor = exports.createApp = exports.createPath = exports.createTmpDir = void 0; -const socket_io_client_1 = require("socket.io-client"); -const libp2p_websockets_1 = __importDefault(require("libp2p-websockets")); -const toolkit_1 = require("@reduxjs/toolkit"); -const typed_redux_saga_1 = require("typed-redux-saga"); -const waggle_1 = __importDefault(require("waggle")); -const nectar_1 = require("@zbayapp/nectar"); -const path_1 = __importDefault(require("path")); -const assert_1 = __importDefault(require("assert")); -const get_port_1 = __importDefault(require("get-port")); -const tmp_1 = __importDefault(require("tmp")); -const logger_1 = __importDefault(require("./logger")); -const log = (0, logger_1.default)(); -const createTmpDir = (prefix) => { - return tmp_1.default.dirSync({ mode: 0o750, prefix, unsafeCleanup: true }); -}; -exports.createTmpDir = createTmpDir; -const createPath = (dirName) => { - return path_1.default.join(dirName, ".nectar"); -}; -exports.createPath = createPath; -const connectToDataport = (url, name) => { - const socket = (0, socket_io_client_1.io)(url); - socket.on("connect", async () => { - log(`websocket connection is ready for app ${name}`); - }); - socket.on("disconnect", () => { - log(`socket disconnected for app ${name}`); - socket.close(); - }); - return socket; -}; -const createApp = async (mockedState) => { - /** - * Configure and initialize ConnectionsManager from waggle, - * configure redux store - */ - const appName = (Math.random() + 1).toString(36).substring(7); - log(`Creating test app for ${appName}`); - const dataServerPort1 = await (0, get_port_1.default)({ port: 4677 }); - const server1 = new waggle_1.default.DataServer(dataServerPort1); - await server1.listen(); - const { store, runSaga } = (0, nectar_1.prepareStore)(mockedState); - const proxyPort = await (0, get_port_1.default)({ port: 1234 }); - const controlPort = await (0, get_port_1.default)({ port: 5555 }); - const httpTunnelPort = await (0, get_port_1.default)({ port: 9000 }); - const manager = new waggle_1.default.ConnectionsManager({ - agentHost: "localhost", - agentPort: proxyPort, - httpTunnelPort, - options: { - env: { - appDataPath: (0, exports.createPath)((0, exports.createTmpDir)(`zbayIntegrationTest-${appName}`).name), - }, - torControlPort: controlPort, - }, - io: server1.io, - }); - await manager.init(); - function* root() { - const socket = yield* (0, typed_redux_saga_1.call)(connectToDataport, `http://localhost:${dataServerPort1}`, appName); - // @ts-expect-error - const task = yield* (0, typed_redux_saga_1.fork)(nectar_1.useIO, socket); - yield* (0, typed_redux_saga_1.take)((0, toolkit_1.createAction)("testFinished")); - yield* (0, typed_redux_saga_1.put)(nectar_1.app.actions.closeServices()); - } - const rootTask = runSaga(root); - return { store, runSaga, rootTask, manager }; -}; -exports.createApp = createApp; -const createAppWithoutTor = async (mockedState) => { - /** - * Configure and initialize ConnectionsManager from waggle, - * configure redux store - */ - const appName = (Math.random() + 1).toString(36).substring(7); - log(`Creating test app for ${appName}`); - const dataServerPort1 = await (0, get_port_1.default)({ port: 4677 }); - const server1 = new waggle_1.default.DataServer(dataServerPort1); - await server1.listen(); - const { store, runSaga } = (0, nectar_1.prepareStore)(mockedState); - const proxyPort = await (0, get_port_1.default)({ port: 1234 }); - const controlPort = await (0, get_port_1.default)({ port: 5555 }); - const httpTunnelPort = await (0, get_port_1.default)({ port: 9000 }); - const manager = new waggle_1.default.ConnectionsManager({ - agentHost: "localhost", - agentPort: proxyPort, - httpTunnelPort, - options: { - env: { - appDataPath: (0, exports.createPath)((0, exports.createTmpDir)(`zbayIntegrationTest-${appName}`).name), - }, - libp2pTransportClass: libp2p_websockets_1.default, - torControlPort: controlPort, - }, - io: server1.io, - }); - manager.initListeners(); - function* root() { - const socket = yield* (0, typed_redux_saga_1.call)(connectToDataport, `http://localhost:${dataServerPort1}`, appName); - // @ts-expect-error - const task = yield* (0, typed_redux_saga_1.fork)(nectar_1.useIO, socket); - yield* (0, typed_redux_saga_1.take)((0, toolkit_1.createAction)("testFinished")); - yield* (0, typed_redux_saga_1.put)(nectar_1.app.actions.closeServices()); - } - const rootTask = runSaga(root); - return { store, runSaga, rootTask, manager }; -}; -exports.createAppWithoutTor = createAppWithoutTor; -const throwAssertionError = (action) => { - throw new assert_1.default.AssertionError({ - message: `Nectar received error: ${JSON.stringify(action.payload)}`, - }); -}; -function* assertNoErrors() { - // Use at the beginning of test saga - yield* (0, typed_redux_saga_1.all)([(0, typed_redux_saga_1.takeEvery)(nectar_1.errors.actions.addError, throwAssertionError)]); -} -exports.assertNoErrors = assertNoErrors;