Skip to content

Commit

Permalink
feat(vms): tests and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Jun 26, 2023
1 parent 684123a commit 3a19f95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
11 changes: 4 additions & 7 deletions packages/actions/test/unit/ec2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,11 @@ describe("VMs", () => {
})
it("run a command on a VM that is active", async () => {
commandId = await runCommandOnEC2(ssmClient, ssmTestInstance.InstanceId!, [
"echo $(whoami) >> hello.txt"
"echo $(whoami)"
])
expect(commandId).to.not.be.null
await sleep(500)
})
it("should run multiple commands", async () => {
await runCommandOnEC2(ssmClient, ssmTestInstance.InstanceId!, [
"su ubuntu", "whoami", "id", "pwd", "ls -la", "ls -la /root", "ls -la /home/ubuntu",
])
})
it("should throw when trying to call a command on a VM that is not active", async () => {
await expect(runCommandOnEC2(ssmClient, "nonExistentOrOff", ["echo hello world"])).to.be.rejected
})
Expand Down Expand Up @@ -200,7 +195,6 @@ describe("VMs", () => {
// pot upload
await multiPartUpload(userFunctions, ceremonyBucket, potStoragePath, potPath, streamChunkSizeInMb)


// create mock ceremony with circuit data
await createMockCeremony(adminFirestore, ceremony, circuit)
})
Expand All @@ -217,6 +211,7 @@ describe("VMs", () => {

await cleanUpMockUsers(adminAuth, adminFirestore, users)
await cleanUpRecursively(adminFirestore, ceremonyId)
await cleanUpRecursively(adminFirestore, secondCeremonyId)

fs.rmdirSync(`${outputDirectory}`, { recursive: true })
})
Expand All @@ -241,6 +236,7 @@ describe("VMs", () => {
}
})

// @note should run after the first one
it("should verify a contribution", async () => {
// 1. login
await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0])
Expand All @@ -249,6 +245,7 @@ describe("VMs", () => {
const circuits = await getCeremonyCircuits(userFirestore, secondCeremonyId)
expect(circuits.length).to.be.gt(0)


// set the VM instance ID that we setup before
for (const circuit of circuits) {
await adminFirestore.collection(getCircuitsCollectionPath(secondCeremonyId)).doc(circuit.id).set({
Expand Down
18 changes: 9 additions & 9 deletions packages/backend/src/functions/circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,14 @@ export const verifycontribution = functionsV2.https.onCall(
// start vm and give it time to start
await startEC2Instance(ec2Client, vmInstanceId)
await sleep(200000)
console.log("DEBUG VM STARTED")

// check status
const status = await checkEC2Status(ec2Client, vmInstanceId)
if (!status) {
console.log("DEBUG Not running yet")
}
// @todo need debugging of VM status
// // check status
// const status = await checkEC2Status(ec2Client, vmInstanceId)
// if (!status) {
// console.log("DEBUG Not running yet")
// }

const commands = [
`aws s3 cp s3://${bucketName}/${lastZkeyStoragePath} /var/tmp/lastZKey.zkey`,
Expand All @@ -460,10 +462,8 @@ export const verifycontribution = functionsV2.https.onCall(
const ssmClient = await createSSMClient()
const commandId = await runCommandOnEC2(ssmClient, vmInstanceId, commands)
await sleep(5000)

const commandOutput = await retrieveCommandOutput(ssmClient, commandId, vmInstanceId)
if (commandOutput.includes("ZKey Ok!")) isContributionValid = true
console.log("dEBUG output", commandOutput)
printLog(`The contribution has been verified - Result ${isContributionValid}`, LogLevel.DEBUG)

// stop the VM
Expand All @@ -475,7 +475,7 @@ export const verifycontribution = functionsV2.https.onCall(

// Step (1.A.2).

// Compute contribution hash. (@todo compute on VM api)
// Compute contribution hash. (@todo compute on VM?)

// Create a new contribution document.
const contributionDoc = await firestore
Expand Down Expand Up @@ -518,7 +518,7 @@ export const verifycontribution = functionsV2.https.onCall(
transcriptStoragePath: verificationTranscriptStoragePathAndFilename,
lastZkeyStoragePath,
transcriptBlake2bHash,
// lastZkeyBlake2bHash
// lastZkeyBlake2bHash // @todo we need the hash of the last zkey
},
verificationSoftware: {
name: String(process.env.CUSTOM_CONTRIBUTION_VERIFICATION_SOFTWARE_NAME),
Expand Down

0 comments on commit 3a19f95

Please sign in to comment.