From 98af9d021ca72c173e1da491da1bfd859862c8e6 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Mon, 3 Jul 2023 06:28:20 +0100 Subject: [PATCH] fix(vms): fix emulator tests --- packages/actions/test/unit/ec2.test.ts | 14 +++++++++----- packages/backend/src/functions/ceremony.ts | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/actions/test/unit/ec2.test.ts b/packages/actions/test/unit/ec2.test.ts index d17e3cd1..cfeee0b8 100644 --- a/packages/actions/test/unit/ec2.test.ts +++ b/packages/actions/test/unit/ec2.test.ts @@ -82,8 +82,10 @@ describe("VMs", () => { let ec2: EC2Client beforeAll(async () => { - ec2 = await createEC2Client() - ssmClient = await createSSMClient() + if (envType === TestingEnvironment.PRODUCTION) { + ec2 = await createEC2Client() + ssmClient = await createSSMClient() + } }) if (envType === TestingEnvironment.PRODUCTION) { @@ -335,9 +337,11 @@ describe("VMs", () => { // delete users and mock ceremonies await cleanUpMockUsers(adminAuth, adminFirestore, users) - await cleanUpRecursively(adminFirestore, ceremonyId) - await cleanUpRecursively(adminFirestore, secondCeremonyId) - await cleanUpRecursively(adminFirestore, ceremonyClosed.uid) + try { + await cleanUpRecursively(adminFirestore, ceremonyId) + await cleanUpRecursively(adminFirestore, secondCeremonyId) + await cleanUpRecursively(adminFirestore, ceremonyClosed.uid) + } catch (error: any) {} // remove local files fs.rmdirSync(`${outputDirectory}`, { recursive: true }) diff --git a/packages/backend/src/functions/ceremony.ts b/packages/backend/src/functions/ceremony.ts index 741452fb..0ae4e137 100644 --- a/packages/backend/src/functions/ceremony.ts +++ b/packages/backend/src/functions/ceremony.ts @@ -34,6 +34,7 @@ import { getAWSVariables } from "../lib/utils" import { LogLevel } from "../types/enums" +import { EC2Client } from "@aws-sdk/client-ec2" dotenv.config() @@ -307,7 +308,8 @@ export const finalizeCeremony = functions printLog(`Ceremony ${ceremonyDoc.id} correctly finalized - Coordinator ${participantDoc.id}`, LogLevel.INFO) - const ec2Client = await createEC2Client() + // avoid creating the object if none of the circuits use a VM + let ec2Client: EC2Client // terminate the VMs for (const circuit of circuits) { @@ -315,6 +317,8 @@ export const finalizeCeremony = functions const { verification } = circuitData if (verification.cfOrVm === CircuitContributionVerificationMechanism.VM) { + // avoid creating object twice if the Circuit is not using a VM + ec2Client = await createEC2Client() const { vm } = verification await terminateEC2Instance(ec2Client, vm.vmInstanceId) }