Skip to content

Commit f2fbc23

Browse files
test: add e2e tests for bulkOnly parameter
1 parent 4f72d3d commit f2fbc23

File tree

2 files changed

+211
-2
lines changed

2 files changed

+211
-2
lines changed

tests/e2e/fetchMyContacts.test.ts

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { NULL_ADDRESS } from 'iexec/utils';
1111
import {
1212
MAX_EXPECTED_BLOCKTIME,
1313
MAX_EXPECTED_WEB2_SERVICES_TIME,
14+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME,
1415
deployRandomDataset,
1516
getTestWeb3SignerProvider,
1617
getTestIExecOption,
@@ -49,11 +50,11 @@ describe('web3telegram.fetchMyContacts()', () => {
4950
});
5051
expect(
5152
foundContactForASpecificRequester &&
52-
foundContactForASpecificRequester.address
53+
foundContactForASpecificRequester.address
5354
).toBeDefined();
5455
expect(
5556
foundContactForASpecificRequester &&
56-
foundContactForASpecificRequester.address
57+
foundContactForASpecificRequester.address
5758
).toBe(protectedData.address.toLocaleLowerCase());
5859
},
5960
MAX_EXPECTED_WEB2_SERVICES_TIME
@@ -141,4 +142,103 @@ describe('web3telegram.fetchMyContacts()', () => {
141142
},
142143
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
143144
);
145+
146+
describe('bulkOnly parameter', () => {
147+
let protectedDataWithBulk: any;
148+
let protectedDataWithoutBulk: any;
149+
150+
beforeAll(async () => {
151+
protectedDataWithBulk = await dataProtector.core.protectData({
152+
data: { telegram_chatId: 'bulk123' },
153+
name: 'test bulk access',
154+
});
155+
protectedDataWithoutBulk = await dataProtector.core.protectData({
156+
data: { telegram_chatId: 'nobulk456' },
157+
name: 'test no bulk access',
158+
});
159+
await waitSubgraphIndexing();
160+
}, 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME);
161+
162+
it(
163+
'should return only contacts with bulk access when bulkOnly is true',
164+
async () => {
165+
// Grant access with allowBulk: true
166+
await dataProtector.core.grantAccess({
167+
authorizedApp: defaultConfig.dappAddress,
168+
protectedData: protectedDataWithBulk.address,
169+
authorizedUser: wallet.address,
170+
allowBulk: true,
171+
});
172+
173+
// Grant access with allowBulk: false (or default)
174+
await dataProtector.core.grantAccess({
175+
authorizedApp: defaultConfig.dappAddress,
176+
protectedData: protectedDataWithoutBulk.address,
177+
authorizedUser: wallet.address,
178+
allowBulk: false,
179+
});
180+
181+
await waitSubgraphIndexing();
182+
183+
// Fetch contacts with bulkOnly: true
184+
const contactsWithBulkOnly = await web3telegram.fetchMyContacts({
185+
bulkOnly: true,
186+
});
187+
188+
// Should only include the contact with bulk access
189+
const bulkContact = contactsWithBulkOnly.find(
190+
(contact) => contact.address === protectedDataWithBulk.address.toLowerCase()
191+
);
192+
const noBulkContact = contactsWithBulkOnly.find(
193+
(contact) => contact.address === protectedDataWithoutBulk.address.toLowerCase()
194+
);
195+
196+
expect(bulkContact).toBeDefined();
197+
expect(noBulkContact).toBeUndefined();
198+
},
199+
MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_SUBGRAPH_INDEXING_TIME + MAX_EXPECTED_WEB2_SERVICES_TIME
200+
);
201+
202+
it(
203+
'should return all contacts when bulkOnly is false',
204+
async () => {
205+
// Fetch contacts with bulkOnly: false (default)
206+
const contactsWithoutBulkOnly = await web3telegram.fetchMyContacts({
207+
bulkOnly: false,
208+
});
209+
210+
// Should include both contacts
211+
const bulkContact = contactsWithoutBulkOnly.find(
212+
(contact) => contact.address === protectedDataWithBulk.address.toLowerCase()
213+
);
214+
const noBulkContact = contactsWithoutBulkOnly.find(
215+
(contact) => contact.address === protectedDataWithoutBulk.address.toLowerCase()
216+
);
217+
218+
expect(bulkContact).toBeDefined();
219+
expect(noBulkContact).toBeDefined();
220+
},
221+
MAX_EXPECTED_WEB2_SERVICES_TIME
222+
);
223+
224+
it(
225+
'should return all contacts when bulkOnly is not specified (default)',
226+
async () => {
227+
// Fetch contacts without specifying bulkOnly (defaults to false)
228+
const contactsDefault = await web3telegram.fetchMyContacts();
229+
230+
// Should include both contacts
231+
const bulkContact = contactsDefault.find(
232+
(contact) => contact.address === protectedDataWithBulk.address.toLowerCase()
233+
);
234+
const noBulkContact = contactsDefault.find(
235+
(contact) => contact.address === protectedDataWithoutBulk.address.toLowerCase()
236+
);
237+
238+
expect(bulkContact).toBeDefined();
239+
expect(noBulkContact).toBeDefined();
240+
},
241+
MAX_EXPECTED_WEB2_SERVICES_TIME
242+
);
243+
});
144244
});

tests/e2e/fetchUserContacts.test.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IExecWeb3telegram, WorkflowError } from '../../src/index.js';
1212
import {
1313
MAX_EXPECTED_BLOCKTIME,
1414
MAX_EXPECTED_WEB2_SERVICES_TIME,
15+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME,
1516
getTestConfig,
1617
waitSubgraphIndexing,
1718
} from '../test-utils.js';
@@ -243,4 +244,112 @@ describe('web3telegram.fetchMyContacts()', () => {
243244
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
244245
);
245246
});
247+
248+
describe('bulkOnly parameter', () => {
249+
let protectedDataWithBulk: ProtectedDataWithSecretProps;
250+
let protectedDataWithoutBulk: ProtectedDataWithSecretProps;
251+
let userWithAccess: string;
252+
253+
beforeAll(async () => {
254+
userWithAccess = Wallet.createRandom().address;
255+
protectedDataWithBulk = await dataProtector.protectData({
256+
data: { telegram_chatId: 'bulk789' },
257+
name: 'test bulk access user',
258+
});
259+
protectedDataWithoutBulk = await dataProtector.protectData({
260+
data: { telegram_chatId: 'nobulk012' },
261+
name: 'test no bulk access user',
262+
});
263+
await waitSubgraphIndexing();
264+
}, 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME);
265+
266+
it(
267+
'should return only contacts with bulk access when bulkOnly is true',
268+
async () => {
269+
const defaultConfig = getChainDefaultConfig(DEFAULT_CHAIN_ID);
270+
expect(defaultConfig).not.toBeNull();
271+
272+
// Grant access with allowBulk: true
273+
await dataProtector.grantAccess({
274+
authorizedApp: defaultConfig!.dappAddress,
275+
protectedData: protectedDataWithBulk.address,
276+
authorizedUser: userWithAccess,
277+
allowBulk: true,
278+
});
279+
280+
// Grant access with allowBulk: false (or default)
281+
await dataProtector.grantAccess({
282+
authorizedApp: defaultConfig!.dappAddress,
283+
protectedData: protectedDataWithoutBulk.address,
284+
authorizedUser: userWithAccess,
285+
allowBulk: false,
286+
});
287+
288+
await waitSubgraphIndexing();
289+
290+
// Fetch contacts with bulkOnly: true
291+
const contactsWithBulkOnly = await web3telegram.fetchUserContacts({
292+
userAddress: userWithAccess,
293+
bulkOnly: true,
294+
});
295+
296+
// Should only include the contact with bulk access
297+
const bulkContact = contactsWithBulkOnly.find(
298+
(contact) => contact.address === protectedDataWithBulk.address.toLowerCase()
299+
);
300+
const noBulkContact = contactsWithBulkOnly.find(
301+
(contact) => contact.address === protectedDataWithoutBulk.address.toLowerCase()
302+
);
303+
304+
expect(bulkContact).toBeDefined();
305+
expect(noBulkContact).toBeUndefined();
306+
},
307+
MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_SUBGRAPH_INDEXING_TIME + MAX_EXPECTED_WEB2_SERVICES_TIME
308+
);
309+
310+
it(
311+
'should return all contacts when bulkOnly is false',
312+
async () => {
313+
// Fetch contacts with bulkOnly: false
314+
const contactsWithoutBulkOnly = await web3telegram.fetchUserContacts({
315+
userAddress: userWithAccess,
316+
bulkOnly: false,
317+
});
318+
319+
// Should include both contacts
320+
const bulkContact = contactsWithoutBulkOnly.find(
321+
(contact) => contact.address === protectedDataWithBulk.address.toLowerCase()
322+
);
323+
const noBulkContact = contactsWithoutBulkOnly.find(
324+
(contact) => contact.address === protectedDataWithoutBulk.address.toLowerCase()
325+
);
326+
327+
expect(bulkContact).toBeDefined();
328+
expect(noBulkContact).toBeDefined();
329+
},
330+
MAX_EXPECTED_WEB2_SERVICES_TIME
331+
);
332+
333+
it(
334+
'should return all contacts when bulkOnly is not specified (default)',
335+
async () => {
336+
// Fetch contacts without specifying bulkOnly (defaults to false)
337+
const contactsDefault = await web3telegram.fetchUserContacts({
338+
userAddress: userWithAccess,
339+
});
340+
341+
// Should include both contacts
342+
const bulkContact = contactsDefault.find(
343+
(contact) => contact.address === protectedDataWithBulk.address.toLowerCase()
344+
);
345+
const noBulkContact = contactsDefault.find(
346+
(contact) => contact.address === protectedDataWithoutBulk.address.toLowerCase()
347+
);
348+
349+
expect(bulkContact).toBeDefined();
350+
expect(noBulkContact).toBeDefined();
351+
},
352+
MAX_EXPECTED_WEB2_SERVICES_TIME
353+
);
354+
});
246355
});

0 commit comments

Comments
 (0)