Skip to content

Commit 9e5b228

Browse files
authored
test: add missing tests in the js libraries (#774)
* test: add missing tests Now all lines of js libraries are 100% covered. re #484 * test(proof): update message type re #484 * test(proof): update constant re #484 * test(proof): update number constant re #484
1 parent de15989 commit 9e5b228

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

packages/data/tests/ethers.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jest.mock("ethers/contract", () => ({
1818
getMerkleTreeRoot: () => "222",
1919
getMerkleTreeDepth: () => BigInt(3),
2020
getMerkleTreeSize: () => BigInt(8),
21-
getGroupAdmin: () => "0xA9C2B639a28cDa8b59C4377e980F75A93dD8605F"
21+
getGroupAdmin: () => "0xA9C2B639a28cDa8b59C4377e980F75A93dD8605F",
22+
hasMember: () => true
2223
}) as any
2324
)
2425
}))
@@ -235,4 +236,25 @@ describe("SemaphoreEthers", () => {
235236
await expect(fun).rejects.toThrow("Group '666' not found")
236237
})
237238
})
239+
240+
describe("isGroupMember", () => {
241+
it("Should return true because the member is part of the group", async () => {
242+
const semaphore = new SemaphoreEthers()
243+
244+
const isMember = await semaphore.isGroupMember("42", "1")
245+
246+
expect(isMember).toBeTruthy()
247+
})
248+
it("Should return false because the member is not part of the group", async () => {
249+
ContractMocked.mockReturnValueOnce({
250+
hasMember: () => false
251+
} as any)
252+
253+
const semaphore = new SemaphoreEthers()
254+
255+
const isMember = await semaphore.isGroupMember("48", "2")
256+
257+
expect(isMember).toBeFalsy()
258+
})
259+
})
238260
})

packages/proof/tests/index.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ describe("Proof", () => {
5858
expect(typeof proof).toBe("object")
5959
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
6060
}, 70000)
61+
62+
it("Should generate a Semaphore proof without passing the tree depth", async () => {
63+
const group = new Group([1n, 2n, identity.commitment])
64+
65+
proof = await generateProof(identity, group, message, scope)
66+
67+
expect(typeof proof).toBe("object")
68+
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
69+
}, 70000)
70+
71+
it("Should throw an error because snarkArtifacts is not an object", async () => {
72+
const group = new Group([1n, 2n, identity.commitment])
73+
const fun = () => generateProof(identity, group, message, scope, undefined, "hello" as any)
74+
75+
await expect(fun).rejects.toThrow("is not an object")
76+
})
77+
78+
it("Should throw an error because the message value is incorrect", async () => {
79+
const group = new Group([1n, 2n, identity.commitment])
80+
81+
const fun = () => generateProof(identity, group, Number.MAX_VALUE, scope, treeDepth)
82+
83+
await expect(fun).rejects.toThrow("overflow")
84+
})
6185
})
6286

6387
describe("# verifyProof", () => {

0 commit comments

Comments
 (0)