Skip to content

Commit

Permalink
feat(data): add getGroupValidatedProofs to SemaphoreSubgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
zkfriendly committed Feb 26, 2024
1 parent 8f73965 commit 9f6c62f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/data/src/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ export default class SemaphoreSubgraph {
return group.members ?? []
}

/**
* Returns a list of validated proofs.
* @param groupId Group id.
* @returns Validated proofs.
*/
async getGroupValidatedProofs(groupId: string): Promise<any[]> {
const group = await this.getGroup(groupId, { validatedProofs: true }) // parameters are checked inside getGroup
return group.validatedProofs ?? []
}

/**
* Returns true if a member is part of group, and false otherwise.
* @param groupId Group id
Expand Down
67 changes: 67 additions & 0 deletions packages/data/tests/subgraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,73 @@ describe("SemaphoreSubgraph", () => {
})
})

describe("# getGroupValidatedProofs", () => {
it("Should return a list of group validated proofs", async () => {
requestMocked.mockImplementationOnce(() =>
Promise.resolve({
groups: [
{
id: "1",
merkleTree: {
depth: 20,
size: 2,
root: "2"
},
admin: "0x7bcd6f009471e9974a77086a69289d16eadba286",
validatedProofs: [
{
message: "0x3243b",
merkleTreeRoot: "1332132",
merkleTreeDepth: "32",
scope: "14324",
nullifier: "442342",
points: ["442342"],
timestamp: "1657306917"
},
{
message: "0x5233a",
merkleTreeRoot: "1332132",
merkleTreeDepth: "32",
scope: "14324",
nullifier: "442342",
points: ["442342"],
timestamp: "1657306923"
}
]
}
]
})
)
const expectedValue = await semaphore.getGroupValidatedProofs("1")

expect(expectedValue).toBeDefined()
expect(Array.isArray(expectedValue)).toBeTruthy()
expect(expectedValue[0]).toEqual({
message: "0x3243b",
merkleTreeRoot: "1332132",
merkleTreeDepth: "32",
scope: "14324",
nullifier: "442342",
points: ["442342"],
timestamp: "1657306917"
})
expect(expectedValue[1]).toEqual({
message: "0x5233a",
merkleTreeRoot: "1332132",
merkleTreeDepth: "32",
scope: "14324",
nullifier: "442342",
points: ["442342"],
timestamp: "1657306923"
})
})

it("Should throw an error if the groupId parameter type is wrong", async () => {
const fun = () => semaphore.getGroupValidatedProofs(1 as any)
await expect(fun).rejects.toThrow("Parameter 'groupId' is not a string")
})
})

describe("# isGroupMember", () => {
it("Should throw an error if the member parameter type is wrong", async () => {
const fun = () => semaphore.isGroupMember("1", 1 as any)
Expand Down

0 comments on commit 9f6c62f

Please sign in to comment.