From 16aad0c7488cd14723efa4505f30c17af2397690 Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 10 Oct 2023 16:51:56 +1100 Subject: [PATCH] test: started processExpireRequestResponse --- ts/session/apis/snode_api/expireRequest.ts | 7 +- .../unit/disappearing/ExpireRequest_test.ts | 95 ++++++++++++++++++- 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/ts/session/apis/snode_api/expireRequest.ts b/ts/session/apis/snode_api/expireRequest.ts index c58a221d9..09669c043 100644 --- a/ts/session/apis/snode_api/expireRequest.ts +++ b/ts/session/apis/snode_api/expireRequest.ts @@ -67,9 +67,12 @@ export async function verifyExpireMsgsResponseSignature({ } } -type ExpireRequestResponseResults = Record; expiry: number }>; +export type ExpireRequestResponseResults = Record< + string, + { hashes: Array; expiry: number } +>; -async function processExpireRequestResponse( +export async function processExpireRequestResponse( pubkey: string, targetNode: Snode, swarm: ExpireMessagesResultsContent, diff --git a/ts/test/session/unit/disappearing/ExpireRequest_test.ts b/ts/test/session/unit/disappearing/ExpireRequest_test.ts index 1baf459f1..e02d9fc8a 100644 --- a/ts/test/session/unit/disappearing/ExpireRequest_test.ts +++ b/ts/test/session/unit/disappearing/ExpireRequest_test.ts @@ -1,10 +1,12 @@ import chai, { expect } from 'chai'; import Sinon from 'sinon'; import chaiAsPromised from 'chai-as-promised'; -import { stubWindowLog } from '../../../test-utils/utils'; +import { generateFakeSnode, stubWindowLog } from '../../../test-utils/utils'; import { ExpireMessageOnSnodeProps, + ExpireRequestResponseResults, buildExpireRequest, + processExpireRequestResponse, verifyExpireMsgsResponseSignature, verifyExpireMsgsResponseSignatureProps, } from '../../../../session/apis/snode_api/expireRequest'; @@ -147,4 +149,95 @@ describe('ExpireRequest', () => { expect(isValid, 'should return false').to.be.false; }); }); + + describe('processExpireRequestResponse', () => { + 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]); + }); + }); });