Skip to content

Commit

Permalink
Merge pull request #359 from semaphore-protocol/fix/semaphore-ethers
Browse files Browse the repository at this point in the history
Check address value before setting it in `SemaphoreEthers` class
  • Loading branch information
cedoor authored Sep 12, 2023
2 parents e1f66a7 + 729764d commit 91429e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
11 changes: 8 additions & 3 deletions packages/data/src/ethers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ describe("SemaphoreEthers", () => {
const semaphore2 = new SemaphoreEthers("matic")
const semaphore3 = new SemaphoreEthers("optimism-goerli")
const semaphore4 = new SemaphoreEthers("arbitrum-goerli")
const semaphore5 = new SemaphoreEthers("homestead", {
const semaphore5 = new SemaphoreEthers("arbitrum-goerli", {
address: "0x0000000000000000000000000000000000000000",
startBlock: 0
})
const semaphore6 = new SemaphoreEthers("homestead", {
address: "0x0000000000000000000000000000000000000000",
startBlock: 0
})
Expand All @@ -42,9 +46,10 @@ describe("SemaphoreEthers", () => {
expect(semaphore2.network).toBe("maticmum")
expect(semaphore3.network).toBe("optimism-goerli")
expect(semaphore4.network).toBe("arbitrum-goerli")
expect(semaphore5.network).toBe("homestead")
expect(semaphore5.options.startBlock).toBe(0)
expect(semaphore5.options.address).toContain("0x000000")
expect(semaphore6.network).toBe("homestead")
expect(semaphore6.options.startBlock).toBe(0)
expect(semaphore6.options.address).toContain("0x000000")
})

it("Should instantiate a SemaphoreEthers object with different providers", () => {
Expand Down
28 changes: 13 additions & 15 deletions packages/data/src/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,35 @@ export default class SemaphoreEthers {

switch (networkOrEthereumURL) {
case "arbitrum":
options.address = "0xc60E0Ee1a2770d5F619858C641f14FC4a6401520"
options.startBlock = 77278430
options.address ??= "0xc60E0Ee1a2770d5F619858C641f14FC4a6401520"
options.startBlock ??= 77278430
break
case "arbitrum-goerli":
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock = 15174410
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock ??= 15174410
break
case "maticmum":
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock = 33995010
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock ??= 33995010
break
case "goerli":
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock = 8777695
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock ??= 8777695
break
case "sepolia":
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock = 3231111
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock ??= 3231111
break
case "optimism-goerli":
options.address = "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock = 7632846
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
options.startBlock ??= 7632846
break
default:
if (options.address === undefined) {
throw new Error(`You should provide a Semaphore contract address for this network`)
}

if (options.startBlock === undefined) {
options.startBlock = 0
}
options.startBlock ??= 0
}

let provider: Provider
Expand Down

0 comments on commit 91429e0

Please sign in to comment.