Skip to content

Commit

Permalink
Added new delta parameter when calculating the next election identi…
Browse files Browse the repository at this point in the history
…fier
  • Loading branch information
marcvelmer committed Jun 12, 2024
1 parent ab0eab1 commit 7bf863e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/api/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,19 +420,22 @@ 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<IVoteMode>
): Promise<IElectionNextIdResponse> {
return axios
.post<IElectionNextIdResponse>(url + ElectionAPIMethods.NEXT_ELECTION_ID, {
organizationId,
censusOrigin,
envelopeType,
delta,
})
.then((response) => response.data)
.catch(this.isApiError);
Expand Down
5 changes: 3 additions & 2 deletions src/services/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
nextElectionId(address: string, election: UnpublishedElection, delta: number = 0): Promise<string> {
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,
Expand Down
8 changes: 6 additions & 2 deletions test/integration/election.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 7bf863e

Please sign in to comment.