diff --git a/ts/session/apis/snode_api/getExpiriesRequest.ts b/ts/session/apis/snode_api/getExpiriesRequest.ts index 182711d86..d035ae0b3 100644 --- a/ts/session/apis/snode_api/getExpiriesRequest.ts +++ b/ts/session/apis/snode_api/getExpiriesRequest.ts @@ -11,16 +11,16 @@ import { SnodeSignature } from './snodeSignatures'; import { GetExpiriesResultsContent } from './types'; import { SeedNodeAPI } from '../seed_node_api'; -type GetExpiriesRequestResponseResults = Record; +export type GetExpiriesRequestResponseResults = Record; -async function processGetExpiriesRequestResponse( +export async function processGetExpiriesRequestResponse( targetNode: Snode, expiries: GetExpiriesResultsContent, messageHashes: Array ): Promise { if (isEmpty(expiries)) { throw Error( - `[processExpireRequestResponse] Expiries are missing! ${JSON.stringify(messageHashes)}` + `[processGetExpiriesRequestResponse] Expiries are missing! ${JSON.stringify(messageHashes)}` ); } @@ -34,7 +34,7 @@ async function processGetExpiriesRequestResponse( for (const messageHash of Object.keys(expiries)) { if (!expiries[messageHash]) { window.log.warn( - `WIP: [processExpireRequestResponse] Expiries result failure on ${ + `WIP: [processGetExpiriesRequestResponse] Expiries result failure on ${ targetNode.pubkey_ed25519 } for messageHash ${messageHash}\n${JSON.stringify(expiries[messageHash])}` ); diff --git a/ts/test/session/unit/disappearing/GetExpiriesRequest_test.ts b/ts/test/session/unit/disappearing/GetExpiriesRequest_test.ts index 766ac3283..51ae4a381 100644 --- a/ts/test/session/unit/disappearing/GetExpiriesRequest_test.ts +++ b/ts/test/session/unit/disappearing/GetExpiriesRequest_test.ts @@ -2,21 +2,15 @@ import chai, { expect } from 'chai'; import Sinon from 'sinon'; import chaiAsPromised from 'chai-as-promised'; import { TypedStub, generateFakeSnode, stubWindowLog } from '../../../test-utils/utils'; -import { - ExpireRequestResponseResults, - buildExpireRequest, - processExpireRequestResponse, -} from '../../../../session/apis/snode_api/expireRequest'; -import { - GetExpiriesFromNodeSubRequest, - UpdateExpiryOnNodeSubRequest, -} from '../../../../session/apis/snode_api/SnodeRequestTypes'; +import { GetExpiriesFromNodeSubRequest } from '../../../../session/apis/snode_api/SnodeRequestTypes'; import { UserUtils } from '../../../../session/utils'; import { isValidUnixTimestamp } from '../../../../session/utils/Timestamps'; import { GetNetworkTime } from '../../../../session/apis/snode_api/getNetworkTime'; import { GetExpiriesFromSnodeProps, + GetExpiriesRequestResponseResults, buildGetExpiriesRequest, + processGetExpiriesRequestResponse, } from '../../../../session/apis/snode_api/getExpiriesRequest'; import { SnodeSignature } from '../../../../session/apis/snode_api/snodeSignatures'; @@ -87,103 +81,45 @@ describe('GetExpiriesRequest', () => { }); }); - // describe('processGetExpiriesRequestResponse', () => { - // const props = { - // pubkey: '058dc8432a63f9dda4d642bfc3eb5e037838bbd779f73e0a6dfb92b8040a1e7848', - // targetNode: generateFakeSnode(), - // swarm: { - // '33c17a108940ecc353e588dc17496d63e726b8fc83c423b4840bf5c2697fa522': { - // expiry: 1696915132498, - // signature: - // 'Aln2BPZoj5M0c+sdGshiKELYQRjwpjBUeoHPrmSongmxstw1RdWj0Jx/zWYOYlw6WVA1yvv9hvziceWi9gdYCA==', - // unchanged: {}, - // updated: ['zwyjWbyAV3ZtSSTJSj0Ib7UbNIFxx6mXVMvnK2toIso'], - // }, - // '361896969a83fffaac8c095bd0e704ba4abba5e644b324bb2de77640ab5bba64': { - // expiry: 1696915132498, - // signature: - // 'vPQuyFKRgDt6IvlGT0fYgPo5nM9EGQNWETbgtnlHIxfdNbwBUNQdm2K997GdYrnO5O/R07dmOreW8LrYrO6bBw==', - // unchanged: {}, - // updated: ['zwyjWbyAV3ZtSSTJSj0Ib7UbNIFxx6mXVMvnK2toIso'], - // }, - // '949465ed4ba994018eedc4cd3968bf167ff95fc4c1a30dce07ed1c191a9ef8bd': { - // expiry: 1696915132498, - // signature: - // 't91Zp01YcrLemy+XJllKsxjPIX9capys47XUsrwyOJEyJsHwxn4EsFqAn6bJ2jrU1NMNxJiNIacR1nNRP0w3BQ==', - // unchanged: {}, - // updated: ['zwyjWbyAV3ZtSSTJSj0Ib7UbNIFxx6mXVMvnK2toIso'], - // }, - // cafe02aa206a99c3699a028a3805fe9d65776f2a3588dc094d54da82f36fbb02: { - // expiry: 1696915132498, - // signature: - // 'gWe9gI6b5ZLtYUcA9WV68wLEBwVvRyzJX5oiHhbPRVZMp6u6BBX0m43eA/NuCMTspSpaXZ+M3uwV6PM7QEvtDA==', - // unchanged: {}, - // updated: ['zwyjWbyAV3ZtSSTJSj0Ib7UbNIFxx6mXVMvnK2toIso'], - // }, - // cafe17d1dd66a01f49b69b54c7b892b31a26844fda66108fbf3a5cb8e6ed3251: { - // expiry: 1696915132498, - // signature: - // 'EC+XO/lY/rVxXCC/h91n0moTuSONgn+Lb5USTb6BpvtK5fnyQUzjQto7hq8Uzf6XugM2slZDo68Xn6iNS7w+AA==', - // unchanged: {}, - // updated: ['zwyjWbyAV3ZtSSTJSj0Ib7UbNIFxx6mXVMvnK2toIso'], - // }, - // cafe30e590138993ec8f0c371624fa585d6c0f5f7199f34194c0e36b428814f0: { - // expiry: 1696915132498, - // signature: - // 'yllKSsNTYXZVtIoQb+XVHwAiCXd5hO8/CcCtIrucFYZFiP5xRta4o0NcIsJGKTMMtgPDglug8OH0+R5bvPkKDg==', - // unchanged: {}, - // updated: ['zwyjWbyAV3ZtSSTJSj0Ib7UbNIFxx6mXVMvnK2toIso'], - // }, - // d9a0fe4581988bdbb3a586f0b254ef60f4e411523be6267b128d1d49bb4585bb: { - // expiry: 1696915132498, - // signature: - // 'KLXME1eCdX36ByDm97Ouci4TLh7myThrDOjO4bImoWf6qvaTWwrTS/sF+7mMdbZNEhQM6IHcRZWGkZYEsEn3BQ==', - // unchanged: {}, - // updated: ['zwyjWbyAV3ZtSSTJSj0Ib7UbNIFxx6mXVMvnK2toIso'], - // }, - // }, - // messageHashes: ['zwyjWbyAV3ZtSSTJSj0Ib7UbNIFxx6mXVMvnK2toIso'], - // }; - - // it('returns valid results if the response is valid', async () => { - // const results: ExpireRequestResponseResults = await processExpireRequestResponse( - // props.pubkey, - // props.targetNode, - // props.swarm, - // props.messageHashes - // ); - // const [firstResultKey, firstResultValue] = Object.entries(results)[0]; - - // expect(results, 'should not be empty').to.be.not.empty; - // expect(firstResultValue, 'there should be at least one result').to.not.be.undefined; - // expect( - // firstResultValue.expiry, - // 'there should be a matching expiry value in the result' - // ).to.equal((props.swarm as any)[firstResultKey].expiry); - // expect( - // isValidUnixTimestamp(firstResultValue.expiry), - // 'the expiry value should be a valid unix timestamp' - // ).to.be.true; - // expect( - // firstResultValue.hashes[0], - // 'the result hashes array should contain our messageHash' - // ).to.equal(props.messageHashes[0]); - // expect(firstResultValue.hashes, 'a result should an array of message hashes').to.be.an( - // 'array' - // ); - // expect( - // firstResultValue.hashes[0], - // 'the result hashes array should contain our messageHash' - // ).to.equal(props.messageHashes[0]); - // }); - // it('returns an error if the swarm is empty', async () => { - // try { - // await processExpireRequestResponse(props.pubkey, props.targetNode, {}, props.messageHashes); - // } catch (err) { - // expect(err.message).to.equal( - // `[processExpireRequestResponse] Swarm is missing! ${props.messageHashes}` - // ); - // } - // }); - // }); + describe('processGetExpiriesRequestResponse', () => { + const props = { + targetNode: generateFakeSnode(), + expiries: { 'FLTUh/C/6E+sWRgNtrqWPXhQqKlIrpHVKJJtZsBMWKw': 1696983251624 }, + // FIXME There is a bug in the snode code that requires at least 2 messages to be requested. Will be fixed in next storage server release + messageHashes: ['FLTUh/C/6E+sWRgNtrqWPXhQqKlIrpHVKJJtZsBMWKw', 'fakehash'], + }; + + it('returns valid results if the response is valid', async () => { + const results: GetExpiriesRequestResponseResults = await processGetExpiriesRequestResponse( + props.targetNode, + props.expiries, + props.messageHashes + ); + const [firstResultKey, firstResultValue] = Object.entries(results)[0]; + + expect(results, 'should not be empty').to.be.not.empty; + expect(firstResultValue, 'there should be at least one result').to.not.be.undefined; + expect(firstResultValue, 'there should be a matching expiry value in the result').to.equal( + (props.expiries as any)[firstResultKey] + ); + expect( + isValidUnixTimestamp(firstResultValue), + 'the expiry value should be a valid unix timestamp' + ).to.be.true; + expect(firstResultKey, 'the result hash key should match our messageHash').to.equal( + props.messageHashes[0] + ); + }); + it('returns an error if expiries is empty', async () => { + try { + await processGetExpiriesRequestResponse(props.targetNode, {}, props.messageHashes); + } catch (err) { + expect(err.message).to.equal( + `[processGetExpiriesRequestResponse] Expiries are missing! ${JSON.stringify( + props.messageHashes + )}` + ); + } + }); + }); });