From 7bf863eebcb9cb19131cf93bc8353e49bef6affd Mon Sep 17 00:00:00 2001 From: Marc Velmer Date: Wed, 12 Jun 2024 12:33:51 +0200 Subject: [PATCH] Added new `delta` parameter when calculating the next election identifier --- src/api/election.ts | 3 +++ src/services/election.ts | 5 +++-- test/integration/election.test.ts | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api/election.ts b/src/api/election.ts index e8092bcf..9f5cc59a 100644 --- a/src/api/election.ts +++ b/src/api/election.ts @@ -420,12 +420,14 @@ export abstract class ElectionAPI extends API { * @param url - API endpoint URL * @param organizationId - The identifier of the organization * @param censusOrigin - The census origin + * @param delta - The stride to next election id, being 0 the next one * @param envelopeType - The envelope type */ public static nextElectionId( url: string, organizationId: string, censusOrigin: number, + delta: number = 0, envelopeType?: Partial ): Promise { return axios @@ -433,6 +435,7 @@ export abstract class ElectionAPI extends API { organizationId, censusOrigin, envelopeType, + delta, }) .then((response) => response.data) .catch(this.isApiError); diff --git a/src/services/election.ts b/src/services/election.ts index 8ef846dd..09b86800 100644 --- a/src/services/election.ts +++ b/src/services/election.ts @@ -303,12 +303,13 @@ export class ElectionService extends Service implements ElectionServicePropertie * * @param address - The address of the account * @param election - The unpublished election + * @param delta - The stride to next election id, being 0 the next one * @returns The next election identifier */ - nextElectionId(address: string, election: UnpublishedElection): Promise { + nextElectionId(address: string, election: UnpublishedElection, delta: number = 0): Promise { invariant(this.url, 'No URL set'); const censusOrigin = ElectionCore.censusOriginFromCensusType(election.census.type); - return ElectionAPI.nextElectionId(this.url, address, censusOrigin, { + return ElectionAPI.nextElectionId(this.url, address, censusOrigin, delta, { serial: false, // TODO anonymous: election.electionType.anonymous, encryptedVotes: election.electionType.secretUntilTheEnd, diff --git a/test/integration/election.test.ts b/test/integration/election.test.ts index b4758c8c..a82ee729 100644 --- a/test/integration/election.test.ts +++ b/test/integration/election.test.ts @@ -1256,8 +1256,12 @@ describe('Election integration tests', () => { return waitForElectionReady(client, electionId); }) .then(async () => { - const nextElectionId = await client.electionService.nextElectionId(await client.wallet.getAddress(), election); - expect(nextElectionId).toEqual(client.electionId.slice(0, -1) + '1'); + expect(await client.electionService.nextElectionId(await client.wallet.getAddress(), election)).toEqual( + client.electionId.slice(0, -1) + '1' + ); + expect(await client.electionService.nextElectionId(await client.wallet.getAddress(), election, 1)).toEqual( + client.electionId.slice(0, -1) + '2' + ); }); }, 85000); it('should vote with steps', async () => {