Skip to content

Commit

Permalink
adding test data
Browse files Browse the repository at this point in the history
  • Loading branch information
ichub committed Jul 25, 2024
1 parent 7d02f47 commit 3729b74
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
76 changes: 76 additions & 0 deletions apps/passport-client/components/screens/HomeScreen/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { newEdDSAPrivateKey } from "@pcd/eddsa-pcd";
import { EdDSATicketPCDPackage, TicketCategory } from "@pcd/eddsa-ticket-pcd";
import { ArgumentTypeName } from "@pcd/pcd-types";
import { randomUUID } from "@pcd/util";
import { AppState } from "../../../src/state";

export interface EventInfo {
start: string;
end: string;
Expand Down Expand Up @@ -32,9 +38,79 @@ export const EVENTS: Record<string, EventInfo> = {
end: "2023-11-21",
image:
"https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Denver_Skyline_in_Winter.JPG/800px-Denver_Skyline_in_Winter.JPG"
},
Devcon: {
start: "2024-11-12",
end: "2024-11-15",
image:
"https://devcon.org/_next/image/?url=/_next/static/media/backdrop.f0972b01.png&w=3840&q=75"
},
"Devcon/ProgCrypto": {
start: "2024-11-12",
end: "2024-11-12",
image:
"https://online.york.ac.uk/wp-content/uploads/2023/10/Cryptography.jpg"
}
};

export function isEvent(folder: string): folder is keyof typeof EVENTS {
return EVENTS[folder] !== undefined;
}

export async function initTestData(state: AppState): Promise<void> {
if (!state.self) {
return;
}

const testData = {
tickets: ["Devcon", "Devcon", "Devcon/ProgCrypto", "Devcon/ProgCrypto"]
} as const;

const pcds = state.pcds;
if (state.pcds.folders["Devcon"]) {
return;
}

const pkey = newEdDSAPrivateKey();

for (const [i, ticket] of testData.tickets.entries()) {
const eventName = ticket;
const ticketName = "GA";
const ticketId = randomUUID();
const eventId = randomUUID();
const productId = randomUUID();

const pcd = await EdDSATicketPCDPackage.prove({
id: {
argumentType: ArgumentTypeName.String,
value: ticketId
},
privateKey: {
argumentType: ArgumentTypeName.String,
value: pkey
},
ticket: {
argumentType: ArgumentTypeName.Object,
value: {
eventName: eventName,
ticketName: ticketName,
checkerEmail: undefined,
eventId,
productId,
ticketId,
timestampConsumed: 0,
timestampSigned: Date.now(),
attendeeSemaphoreId: state.identity.commitment.toString(),
isConsumed: false,
isRevoked: false,
ticketCategory: TicketCategory.Generic,
attendeeName: "",
attendeeEmail: state.self?.email ?? "[email protected]"
}
}
});

pcds.add(pcd, { upsert: true });
pcds.setFolder(pcd.id, ticket);
}
}
3 changes: 3 additions & 0 deletions apps/passport-client/src/loadInitialState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createStorageBackedCredentialCache } from "@pcd/passport-interface";
import { Identity } from "@semaphore-protocol/identity";
import { initTestData } from "../components/screens/HomeScreen/utils";
import {
loadCheckedInOfflineDevconnectTickets,
loadEncryptionKey,
Expand Down Expand Up @@ -70,5 +71,7 @@ export async function loadInitialState(): Promise<AppState> {
state.modal = { modalType: "invalid-participant" };
}

await initTestData(state);

return state;
}

0 comments on commit 3729b74

Please sign in to comment.