Skip to content

Commit

Permalink
fix(multipart upload): fixed tests that failed due to the changes
Browse files Browse the repository at this point in the history
fixed actions tests failing due to the changes in the backend
  • Loading branch information
ctrlc03 committed Mar 15, 2023
1 parent 5629dd7 commit eded975
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
18 changes: 11 additions & 7 deletions packages/actions/test/e2e/02-contribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ describe("Contribution", () => {
let lastZkeyLocalFilePath: string = ""
let nextZkeyLocalFilePath: string = ""

const outputDirectory = `${cwd()}/packages/actions/test/data/artifacts/output`

if (envType === TestingEnvironment.PRODUCTION) {
// create dir structure
fs.mkdirSync(`output/contribute/attestation`, { recursive: true })
fs.mkdirSync(`output/contribute/transcripts`, { recursive: true })
fs.mkdirSync(`output/contribute/zkeys`, { recursive: true })
fs.mkdirSync(`${outputDirectory}/contribute/attestation`, { recursive: true })
fs.mkdirSync(`${outputDirectory}/contribute/transcripts`, { recursive: true })
fs.mkdirSync(`${outputDirectory}/contribute/zkeys`, { recursive: true })
}
// s3 objects we have to delete
const objectsToDelete = [potStoragePath, storagePath]
Expand Down Expand Up @@ -170,8 +172,8 @@ describe("Contribution", () => {
// 7. download previous contribution
storagePath = getZkeyStorageFilePath(circuit.data.prefix, `${circuit.data.prefix}_${currentZkeyIndex}.zkey`)

lastZkeyLocalFilePath = `./output/contribute/zkeys/${circuit.data.prefix}_${currentZkeyIndex}.zkey`
nextZkeyLocalFilePath = `./output/contribute/zkeys/${circuit.data.prefix}_${nextZkeyIndex}.zkey`
lastZkeyLocalFilePath = `${outputDirectory}/contribute/zkeys/${circuit.data.prefix}_${currentZkeyIndex}.zkey`
nextZkeyLocalFilePath = `${outputDirectory}/contribute/zkeys/${circuit.data.prefix}_${nextZkeyIndex}.zkey`
const preSignedUrl = await generateGetObjectPreSignedUrl(userFunctions, bucketName, storagePath)
const getResponse = await fetch(preSignedUrl)
// Write the file to disk.
Expand All @@ -181,7 +183,9 @@ describe("Contribution", () => {
await progressToNextCircuitForContribution(userFunctions, ceremonyId)
await sleep(1000)

transcriptLocalFilePath = getTranscriptLocalFilePath(`${circuit.data.prefix}_${nextZkeyIndex}.log`)
transcriptLocalFilePath = `${outputDirectory}/${getTranscriptLocalFilePath(
`${circuit.data.prefix}_${nextZkeyIndex}.log`
)}`
const transcriptLogger = createCustomLoggerForFile(transcriptLocalFilePath)
// 10. do contribution
await zKey.contribute(lastZkeyLocalFilePath, nextZkeyLocalFilePath, users[2].uid, entropy, transcriptLogger)
Expand Down Expand Up @@ -357,7 +361,7 @@ describe("Contribution", () => {
await sleep(2000)
await deleteBucket(bucketName)

if (fs.existsSync(`./output`)) fs.rmSync(`./output`, { recursive: true, force: true })
if (fs.existsSync(outputDirectory)) fs.rmSync(outputDirectory, { recursive: true, force: true })
}
})
})
7 changes: 4 additions & 3 deletions packages/actions/test/e2e/03-finalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe("Finalization e2e", () => {

const ceremonyClosed = fakeCeremoniesData.fakeCeremonyClosedDynamic
const ceremonyOpen = fakeCeremoniesData.fakeCeremonyOpenedFixed
// @todo change circuit here
const finalizizationCircuit = fakeCircuitsData.fakeCircuitSmallNoContributors
const contributionId = randomBytes(20).toString("hex")

Expand All @@ -70,10 +71,10 @@ describe("Finalization e2e", () => {
const verificationKeyFilename = `${finalizizationCircuit?.data.prefix}_vkey.json`
const verifierContractFilename = `${finalizizationCircuit?.data.prefix}_verifier.sol`

const verificationKeyLocalPath = `${cwd()}/packages/actions/test/data/${
const verificationKeyLocalPath = `${cwd()}/packages/actions/test/data/artifacts/${
finalizizationCircuit?.data.prefix
}_vkey.json`
const verifierContractLocalPath = `${cwd()}/packages/actions/test/data/${
const verifierContractLocalPath = `${cwd()}/packages/actions/test/data/artifacts/${
finalizizationCircuit?.data.prefix
}_verifier.sol`

Expand Down Expand Up @@ -149,6 +150,7 @@ describe("Finalization e2e", () => {
if (envType === TestingEnvironment.PRODUCTION) {
await signInWithEmailAndPassword(userAuth, users[2].data.email, passwords[2])
await createS3Bucket(userFunctions, bucketName)
await sleep(500)
await uploadFileToS3(bucketName, verificationKeyStoragePath, verificationKeyLocalPath)
await uploadFileToS3(bucketName, verifierContractStoragePath, verifierContractLocalPath)
}
Expand All @@ -174,7 +176,6 @@ describe("Finalization e2e", () => {
})
if (envType === TestingEnvironment.PRODUCTION) {
it("should finalize a ceremony", async () => {
await sleep(200)
await signInWithEmailAndPassword(userAuth, users[2].data.email, passwords[2])
const result = await checkAndPrepareCoordinatorForFinalization(userFunctions, ceremonyClosed.uid)
expect(result).to.be.true
Expand Down
18 changes: 9 additions & 9 deletions packages/backend/src/functions/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const checkPreConditionForCurrentContributorToInteractWithMultiPartUpload = asyn
* @param ceremonyId <string> - the unique identifier of the ceremony.
* @param objectKey <string> - the object key of the file being uploaded.
*/
const checkUploadedFileValidity = async (contributorId: string, ceremonyId: string, objectKey: string) => {
const checkUploadingFileValidity = async (contributorId: string, ceremonyId: string, objectKey: string) => {
// Get the circuits for the ceremony
const circuits = await getCeremonyCircuits(ceremonyId)

Expand Down Expand Up @@ -90,7 +90,7 @@ const checkUploadedFileValidity = async (contributorId: string, ceremonyId: stri
}
}

// if there was no match for the circuit current contributor, then throw an error
// if there was no match for the current contributor, then throw an error
logAndThrowError(SPECIFIC_ERRORS.SE_STORAGE_CANNOT_INTERACT_WITH_MULTI_PART_UPLOAD)
}

Expand All @@ -99,7 +99,7 @@ const checkUploadedFileValidity = async (contributorId: string, ceremonyId: stri
* @dev this helps to prevent unauthorized access to coordinator's buckets.
* @param bucketName
*/
const checkIfBucketDedicatedToCeremony = async (bucketName: string) => {
const checkIfBucketIsDedicatedToCeremony = async (bucketName: string) => {
// Get Firestore DB.
const firestoreDatabase = admin.firestore()

Expand Down Expand Up @@ -229,7 +229,7 @@ export const generateGetObjectPreSignedUrl = functions.https.onCall(
const { objectKey, bucketName } = data

// Check whether the bucket for which we are generating the pre-signed url is dedicated to a ceremony.
await checkIfBucketDedicatedToCeremony(bucketName)
await checkIfBucketIsDedicatedToCeremony(bucketName)

// Connect to S3 client.
const S3 = await getS3Client()
Expand Down Expand Up @@ -280,10 +280,10 @@ export const startMultiPartUpload = functions.https.onCall(
await checkPreConditionForCurrentContributorToInteractWithMultiPartUpload(userId!, ceremonyId)

// Check whether the bucket where the object for which we are generating the pre-signed url is dedicated to a ceremony.
await checkIfBucketDedicatedToCeremony(bucketName)
await checkIfBucketIsDedicatedToCeremony(bucketName)

// Check the validity of the uploaded file.
await checkUploadedFileValidity(userId!, ceremonyId!, objectKey)
await checkUploadingFileValidity(userId!, ceremonyId!, objectKey)
}

// Connect to S3 client.
Expand Down Expand Up @@ -412,10 +412,10 @@ export const completeMultiPartUpload = functions.https.onCall(
if (context.auth?.token.participant && !!ceremonyId) {
// Check pre-condition.
await checkPreConditionForCurrentContributorToInteractWithMultiPartUpload(userId!, ceremonyId)
}

// Check if the bucket is dedicated to a ceremony.
await checkIfBucketDedicatedToCeremony(bucketName)
// Check if the bucket is dedicated to a ceremony.
await checkIfBucketIsDedicatedToCeremony(bucketName)
}

// Connect to S3.
const S3 = await getS3Client()
Expand Down

0 comments on commit eded975

Please sign in to comment.