Skip to content

Commit

Permalink
fix(data): check address value before setting it
Browse files Browse the repository at this point in the history
fix #358
  • Loading branch information
cedoor committed Sep 12, 2023
1 parent 6f7dd99 commit 20f2831
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
13 changes: 10 additions & 3 deletions packages/data/src/ethers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,27 @@ 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
})

console.log(semaphore5)

Check warning on line 43 in packages/data/src/ethers.test.ts

View workflow job for this annotation

GitHub Actions / style

Unexpected console statement

expect(semaphore.network).toBe("sepolia")
expect(semaphore.contract).toBeInstanceOf(Object)
expect(semaphore1.network).toBe("arbitrum")
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 20f2831

Please sign in to comment.