Skip to content

Commit

Permalink
fix(tests): refactoring of older test suites and added extra ci action
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Mar 24, 2023
1 parent b9958f5 commit 9af9529
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 188 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/deploy_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This is a basic workflow to help you get started with Actions

name: Firebase function deploy

# Controls when the action will run. Triggers the workflow on push
# events but only for the master branch
on:
push:
branches: [ test/cleanup ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-22.04

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
# And of course we need to goto our functions folder to deploy
- name: Install npm packages and write env
run: |
yarn
echo "${{ secrets.ACTIONS_ENV_FILE }}" > ./packages/actions/.env
echo "${{ secrets.BACKEND_ENV_FILE }}" > ./packages/backend/.env
# Deploying the functions to firebase
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only functions --project prod
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_PATH: packages/backend/

test:
runs-on: ubuntu-22.04
environment: p0tion-ci-environment
steps:
- name: checkout repo
uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn

- name: write env file for Firebase
run: |
echo "${{ secrets.ACTIONS_ENV_FILE }}" > ./packages/actions/.env
- name: write Firebase service account key
id: create-json
uses: jsdaniell/create-json@v1.2.1
with:
name: "serviceAccountKey.json"
json: ${{ secrets.SERVICE_ACCOUNT_KEY }}
dir: "./packages/backend/"

- name: install dependencies
run: yarn install --frozen-lockfile

- name: build packages
run: yarn build
env:
NODE_OPTIONS: "--max_old_space_size=4096"

- name: run test (unit & e2e)
run: yarn test:ci-prod
env:
GOOGLE_APPLICATION_CREDENTIALS: ./packages/backend/serviceAccountKey.json
11 changes: 7 additions & 4 deletions .github/workflows/test-ci-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ jobs:
# Install Firebase-cli
npm install -g firebase-tools
- name: deploy to Firebase
run: firebase deploy --only functions --project prod
working-directory: packages/backend
# Deploying the functions to firebase
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only functions --project prod
env:
GOOGLE_APPLICATION_CREDENTIALS: ./serviceAccountKey.json
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_PATH: packages/backend/

unit-e2e-test:
needs: deploy
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/test/data/samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const fakeCeremonyContributeTest = generateFakeCeremony({
})

const fakeCeremonyClosedDynamic = generateFakeCeremony({
uid: "0000000000000000000D",
uid: "0000000000000000000F",
data: {
coordinatorId: fakeUser1.uid,
title: "Ceremony Closed Dynamic",
Expand Down
15 changes: 2 additions & 13 deletions packages/actions/test/e2e/01-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ describe("Setup", () => {
const potStorageFilePath = getPotStorageFilePath(potName)

const r1csName = `${circuit.data.prefix}.r1cs`
const r1csLocalFilePath = `./${r1csName}`
const r1csLocalFilePath = `./${setupFolder}/${r1csName}`
const r1csStorageFilePath = getR1csStorageFilePath(circuit.data.prefix!, r1csName)

const wasmName = `${circuit.data.prefix}.wasm`
const wasmLocalFilePath = `./${wasmName}`
const wasmLocalFilePath = `./${setupFolder}/${wasmName}`
const wasmStorageFilePath = getWasmStorageFilePath(circuit.data.prefix!, wasmName)

let ceremonyId: string
Expand Down Expand Up @@ -209,17 +209,6 @@ describe("Setup", () => {
expect(await checkIfObjectExist(userFunctions, ceremonyBucket, r1csStorageFilePath)).to.be.true
expect(await checkIfObjectExist(userFunctions, ceremonyBucket, wasmStorageFilePath)).to.be.true
})
it("should fail to create a new ceremony when the coordinator provides the wrong path to a file required for a ceremony setup (zkey)", async () => {
const objectName = "test_upload.zkey"
const nonExistentLocalPath = "./nonExistentPath.zkey"
// make sure we are logged in as coordinator
await signInWithEmailAndPassword(userAuth, users[1].data.email, passwords[1])

// 2. multi part upload
await expect(
multiPartUpload(userFunctions, ceremonyBucket, objectName, nonExistentLocalPath, streamChunkSizeInMb)
).to.be.rejectedWith("ENOENT: no such file or directory")
})
}

afterAll(async () => {
Expand Down
15 changes: 8 additions & 7 deletions packages/actions/test/e2e/02-contribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { fakeCeremoniesData, fakeCircuitsData, fakeUsersData } from "../data/sam
import {
initializeAdminServices,
initializeUserServices,
generatePseudoRandomStringOfNumbers,
deleteAdminApp,
createMockCeremony,
cleanUpMockUsers,
Expand All @@ -46,7 +45,8 @@ import {
envType,
sleep,
getTranscriptLocalFilePath,
cleanUpRecursively
cleanUpRecursively,
generateUserPasswords
} from "../utils"
import { generateFakeParticipant } from "../data/generators"
import { ParticipantContributionStep, ParticipantStatus, TestingEnvironment } from "../../src/types/enums"
Expand All @@ -61,11 +61,7 @@ describe("Contribution", () => {
const userAuth = getAuth(userApp)

const users = [fakeUsersData.fakeUser1, fakeUsersData.fakeUser2, fakeUsersData.fakeUser3]
const passwords = [
generatePseudoRandomStringOfNumbers(24),
generatePseudoRandomStringOfNumbers(24),
generatePseudoRandomStringOfNumbers(24)
]
const passwords = generateUserPasswords(users.length)

let ceremonyBucketPostfix: string = ""
let streamChunkSizeInMb: number = 0
Expand Down Expand Up @@ -108,6 +104,10 @@ describe("Contribution", () => {
const objectsToDelete = [potStoragePath, storagePath]

beforeAll(async () => {
// @note this test suite needs some delay if run after other
// test suites
await sleep(1000)

// Create users
for (let i = 0; i < users.length; i++) {
users[i].uid = await createMockUser(
Expand Down Expand Up @@ -233,6 +233,7 @@ describe("Contribution", () => {
await sleep(1000)

objectsToDelete.push(nextZkeyStoragePath)

// Execute contribution verification.
const { valid } = await verifyContribution(
userFunctions,
Expand Down
7 changes: 1 addition & 6 deletions packages/actions/test/e2e/03-finalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
finalizeCeremony,
finalizeCircuit,
getBucketName,
getClosedCeremonies,
getDocumentById,
getParticipantsCollectionPath,
getVerificationKeyStorageFilePath,
Expand Down Expand Up @@ -168,11 +167,6 @@ describe("Finalization e2e", () => {
finalizeCeremony(userFunctions, fakeCeremoniesData.fakeCeremonyClosedDynamic.uid)
).to.be.rejectedWith("You do not have privileges to perform this operation.")
})
it("should return all ceremonies that need finalizing", async () => {
const closedCeremonies = await getClosedCeremonies(userFirestore)
// make sure there is at least one ceremony that needs finalizing
expect(closedCeremonies.length).to.be.gt(0)
})
if (envType === TestingEnvironment.PRODUCTION) {
it("should finalize a ceremony", async () => {
await signInWithEmailAndPassword(userAuth, users[2].data.email, passwords[2])
Expand Down Expand Up @@ -213,6 +207,7 @@ describe("Finalization e2e", () => {
if (envType === TestingEnvironment.PRODUCTION) {
await deleteObjectFromS3(bucketName, verificationKeyStoragePath)
await deleteObjectFromS3(bucketName, verifierContractStoragePath)
await sleep(500)
await deleteBucket(bucketName)
}

Expand Down
40 changes: 0 additions & 40 deletions packages/actions/test/e2e/04-clean.test.ts

This file was deleted.

8 changes: 6 additions & 2 deletions packages/actions/test/unit/authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
generatePseudoRandomStringOfNumbers,
initializeAdminServices,
initializeUserServices,
setCustomClaims
setCustomClaims,
sleep
} from "../utils"
import { fakeUsersData } from "../data/samples"
import { commonTerms, getCurrentFirebaseAuthUser, isCoordinator, signInToFirebaseWithCredentials } from "../../src"
Expand Down Expand Up @@ -57,8 +58,11 @@ describe("Authentication", () => {
userPassword
)

await sleep(500)
userFromCredential = userFirebaseCredentials.user
userUID = userFromCredential.uid

const authUser = getCurrentFirebaseAuthUser(userApp)
userUID = authUser.uid
})

it("should return the current Firebase user authenticated for a given application", async () => {
Expand Down
13 changes: 2 additions & 11 deletions packages/actions/test/unit/contribute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,6 @@ describe("Contribute", () => {
"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore"
)
})
it("should return the same data to coordinators and participants", async () => {
// auth
await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0])
const circuits = await getCeremonyCircuits(userFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid)
// auth
await signInWithEmailAndPassword(userAuth, users[2].data.email, passwords[2])
const circuits2 = await getCeremonyCircuits(userFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid)
expect(circuits2).to.deep.equal(circuits)
})
afterAll(async () => {
await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid)
})
Expand Down Expand Up @@ -679,7 +670,6 @@ describe("Contribute", () => {
).to.be.rejectedWith("internal")
})
it("should store the contribution verification result", async () => {})
it("should allow a coordinator to finalize a ceremony if in state CLOSED", async () => {})
afterAll(async () => {
await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyContributeTest.uid)
})
Expand Down Expand Up @@ -767,8 +757,8 @@ describe("Contribute", () => {
).to.be.fulfilled
})
afterAll(async () => {
await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedDynamic.uid)
await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid)
await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedDynamic.uid)
})
})

Expand Down Expand Up @@ -914,6 +904,7 @@ describe("Contribute", () => {
)
})
})

describe("generateValidContributionsAttestation", () => {})

afterAll(async () => {
Expand Down
Loading

0 comments on commit 9af9529

Please sign in to comment.