Skip to content

Commit 7af714b

Browse files
authored
Merge pull request #359 from semaphore-protocol/fix/semaphore-ethers
Check address value before setting it in `SemaphoreEthers` class Former-commit-id: 91429e0
2 parents 482b64d + c434f8a commit 7af714b

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

packages/data/src/ethers.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ describe("SemaphoreEthers", () => {
3131
const semaphore2 = new SemaphoreEthers("matic")
3232
const semaphore3 = new SemaphoreEthers("optimism-goerli")
3333
const semaphore4 = new SemaphoreEthers("arbitrum-goerli")
34-
const semaphore5 = new SemaphoreEthers("homestead", {
34+
const semaphore5 = new SemaphoreEthers("arbitrum-goerli", {
35+
address: "0x0000000000000000000000000000000000000000",
36+
startBlock: 0
37+
})
38+
const semaphore6 = new SemaphoreEthers("homestead", {
3539
address: "0x0000000000000000000000000000000000000000",
3640
startBlock: 0
3741
})
@@ -42,9 +46,10 @@ describe("SemaphoreEthers", () => {
4246
expect(semaphore2.network).toBe("maticmum")
4347
expect(semaphore3.network).toBe("optimism-goerli")
4448
expect(semaphore4.network).toBe("arbitrum-goerli")
45-
expect(semaphore5.network).toBe("homestead")
46-
expect(semaphore5.options.startBlock).toBe(0)
4749
expect(semaphore5.options.address).toContain("0x000000")
50+
expect(semaphore6.network).toBe("homestead")
51+
expect(semaphore6.options.startBlock).toBe(0)
52+
expect(semaphore6.options.address).toContain("0x000000")
4853
})
4954

5055
it("Should instantiate a SemaphoreEthers object with different providers", () => {

packages/data/src/ethers.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,35 @@ export default class SemaphoreEthers {
4343

4444
switch (networkOrEthereumURL) {
4545
case "arbitrum":
46-
options.address = "0xc60E0Ee1a2770d5F619858C641f14FC4a6401520"
47-
options.startBlock = 77278430
46+
options.address ??= "0xc60E0Ee1a2770d5F619858C641f14FC4a6401520"
47+
options.startBlock ??= 77278430
4848
break
4949
case "arbitrum-goerli":
50-
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
51-
options.startBlock = 15174410
50+
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
51+
options.startBlock ??= 15174410
5252
break
5353
case "maticmum":
54-
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
55-
options.startBlock = 33995010
54+
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
55+
options.startBlock ??= 33995010
5656
break
5757
case "goerli":
58-
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
59-
options.startBlock = 8777695
58+
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
59+
options.startBlock ??= 8777695
6060
break
6161
case "sepolia":
62-
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
63-
options.startBlock = 3231111
62+
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
63+
options.startBlock ??= 3231111
6464
break
6565
case "optimism-goerli":
66-
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
67-
options.startBlock = 7632846
66+
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
67+
options.startBlock ??= 7632846
6868
break
6969
default:
7070
if (options.address === undefined) {
7171
throw new Error(`You should provide a Semaphore contract address for this network`)
7272
}
7373

74-
if (options.startBlock === undefined) {
75-
options.startBlock = 0
76-
}
74+
options.startBlock ??= 0
7775
}
7876

7977
let provider: Provider

0 commit comments

Comments
 (0)