Skip to content

Commit a20d3db

Browse files
committed
refactor: use native bigints
The core libraries can now use native bigints as the new ts target is es2020. Former-commit-id: 238c6b3
1 parent d00c0a3 commit a20d3db

File tree

9 files changed

+177
-191
lines changed

9 files changed

+177
-191
lines changed

packages/contracts/test/Semaphore.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe("Semaphore", () => {
124124

125125
describe("# addMember", () => {
126126
it("Should not add a member if the caller is not the group admin", async () => {
127-
const member = BigInt(2)
127+
const member = 2n
128128

129129
const transaction = semaphoreContract.connect(accounts[1]).addMember(groupId, member)
130130

@@ -149,7 +149,7 @@ describe("Semaphore", () => {
149149

150150
describe("# addMembers", () => {
151151
it("Should not add members if the caller is not the group admin", async () => {
152-
const members = [BigInt(1), BigInt(2), BigInt(3)]
152+
const members = [1n, 2n, 3n]
153153

154154
const transaction = semaphoreContract.connect(accounts[1]).addMembers(groupId, members)
155155

@@ -161,7 +161,7 @@ describe("Semaphore", () => {
161161

162162
it("Should add new members to an existing group", async () => {
163163
const groupId = 3
164-
const members = [BigInt(1), BigInt(2), BigInt(3)]
164+
const members = [1n, 2n, 3n]
165165
const group = new Group()
166166

167167
group.addMembers(members)
@@ -178,7 +178,7 @@ describe("Semaphore", () => {
178178

179179
describe("# updateMember", () => {
180180
it("Should not update a member if the caller is not the group admin", async () => {
181-
const member = BigInt(2)
181+
const member = 2n
182182

183183
const transaction = semaphoreContract.connect(accounts[1]).updateMember(groupId, member, 1, [0, 1])
184184

@@ -190,29 +190,27 @@ describe("Semaphore", () => {
190190

191191
it("Should update a member from an existing group", async () => {
192192
const groupId = 4
193-
const members = [BigInt(1), BigInt(2), BigInt(3)]
193+
const members = [1n, 2n, 3n]
194194
const group = new Group()
195195

196196
group.addMembers(members)
197197

198-
group.updateMember(0, BigInt(4))
198+
group.updateMember(0, 4n)
199199

200200
await semaphoreContract["createGroup(address)"](accountAddresses[0])
201201
await semaphoreContract.addMembers(groupId, members)
202202

203203
const { siblings, root } = group.generateMerkleProof(0)
204204

205-
const transaction = semaphoreContract.updateMember(groupId, BigInt(1), BigInt(4), siblings)
205+
const transaction = semaphoreContract.updateMember(groupId, 1n, 4n, siblings)
206206

207-
await expect(transaction)
208-
.to.emit(semaphoreContract, "MemberUpdated")
209-
.withArgs(groupId, 0, BigInt(1), BigInt(4), root)
207+
await expect(transaction).to.emit(semaphoreContract, "MemberUpdated").withArgs(groupId, 0, 1n, 4n, root)
210208
})
211209
})
212210

213211
describe("# removeMember", () => {
214212
it("Should not remove a member if the caller is not the group admin", async () => {
215-
const member = BigInt(2)
213+
const member = 2n
216214

217215
const transaction = semaphoreContract.connect(accounts[1]).removeMember(groupId, member, [0, 1])
218216

@@ -224,7 +222,7 @@ describe("Semaphore", () => {
224222

225223
it("Should remove a member from an existing group", async () => {
226224
const groupId = 5
227-
const members = [BigInt(1), BigInt(2), BigInt(3)]
225+
const members = [1n, 2n, 3n]
228226
const group = new Group()
229227

230228
group.addMembers(members)
@@ -236,9 +234,9 @@ describe("Semaphore", () => {
236234

237235
const { siblings, root } = group.generateMerkleProof(2)
238236

239-
const transaction = semaphoreContract.removeMember(groupId, BigInt(3), siblings)
237+
const transaction = semaphoreContract.removeMember(groupId, 3n, siblings)
240238

241-
await expect(transaction).to.emit(semaphoreContract, "MemberRemoved").withArgs(groupId, 2, BigInt(3), root)
239+
await expect(transaction).to.emit(semaphoreContract, "MemberRemoved").withArgs(groupId, 2, 3n, root)
242240
})
243241
})
244242

@@ -272,7 +270,7 @@ describe("Semaphore", () => {
272270

273271
await semaphoreContract.addMembers(groupId, members)
274272

275-
proof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth)
273+
proof = await generateProof(identity, group, message, group.root, merkleTreeDepth)
276274
})
277275

278276
it("Should not verify a proof if the group does not exist", async () => {
@@ -303,7 +301,7 @@ describe("Semaphore", () => {
303301

304302
group.addMembers([members[0], members[1]])
305303

306-
const proof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth)
304+
const proof = await generateProof(identity, group, message, group.root, merkleTreeDepth)
307305

308306
const transaction = semaphoreContract.verifyProof(groupId, proof)
309307

@@ -358,12 +356,12 @@ describe("Semaphore", () => {
358356
await semaphoreContract.addMembers(groupId, [members[1], members[2]])
359357
await semaphoreContract.addMember(groupOneMemberId, members[0])
360358

361-
proof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth)
359+
proof = await generateProof(identity, group, message, group.root, merkleTreeDepth)
362360
proofOneMember = await generateProof(
363361
identity,
364362
groupOneMember,
365363
message,
366-
groupOneMember.root as string,
364+
groupOneMember.root,
367365
merkleTreeDepth
368366
)
369367
})

packages/group/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"rollup-plugin-cleanup": "^3.2.1"
4040
},
4141
"dependencies": {
42-
"@zk-kit/imt": "2.0.0-beta.2"
42+
"@zk-kit/imt": "2.0.0-beta.2",
43+
"@zk-kit/utils": "1.0.0-beta"
4344
}
4445
}

packages/group/src/group.ts

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)