From 8f487a21795b23e737aafb06795b0b59f215d0c6 Mon Sep 17 00:00:00 2001 From: gabrielmer <101006718+gabrielmer@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:33:15 +0200 Subject: [PATCH] fix: checking for keystore file existence (#2427) --- tests/waku_rln_relay/test_rln_group_manager_onchain.nim | 7 +++++++ .../group_manager/on_chain/group_manager.nim | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim index 7c95ee763a..9087aef5fb 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -223,6 +223,13 @@ suite "Onchain group manager": rlnInstance: manager.rlnInstance) expect(ValueError): await manager2.init() + asyncTest "should error when keystore path and password are provided but file doesn't exist": + let manager = await setup() + manager.keystorePath = some("/inexistent/file") + manager.keystorePassword = some("password") + + expect(CatchableError): await manager.init() + asyncTest "startGroupSync: should start group sync": let manager = await setup() diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 22b392967a..20891d4b26 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -4,6 +4,7 @@ else: {.push raises: [].} import + os, web3, web3/ethtypes, eth/keys as keys, @@ -630,6 +631,10 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = g.registryContract = some(registryContract) if g.keystorePath.isSome() and g.keystorePassword.isSome(): + if not existsFile(g.keystorePath.get()): + error "File provided as keystore path does not exist", path=g.keystorePath.get() + raise newException(CatchableError, "missing keystore") + var keystoreQuery = KeystoreMembership( membershipContract: MembershipContract( chainId: $g.chainId.get(),