From 0acb393c3b4b160c02af87293ad634c9a6881998 Mon Sep 17 00:00:00 2001 From: stubbsta Date: Thu, 5 Jun 2025 18:28:26 +0200 Subject: [PATCH] Fix formatting --- .../test_rln_group_manager_onchain.nim | 6 +-- tests/waku_rln_relay/utils_onchain.nim | 11 +++-- .../group_manager/on_chain/group_manager.nim | 46 ++++++++++--------- 3 files changed, 33 insertions(+), 30 deletions(-) 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 0f1893efc..5e6bab732 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -29,10 +29,7 @@ import ./utils_onchain suite "Onchain group manager": - - setup: - # We run Anvil let runAnvil {.used.} = runAnvil() var manager {.threadvar.}: OnchainGroupManager @@ -92,7 +89,8 @@ suite "Onchain group manager": raise newException(CatchableError, "Failed to deploy test token contract") let TOKEN_ADDRESS = testTokenAddressRes.get() - let differentContractAddress = waitFor executeForgeContractDeployScripts(privateKey, acc, web3) + let differentContractAddress = + waitFor executeForgeContractDeployScripts(privateKey, acc, web3) if differentContractAddress.isErr(): error "Failed to deploy RLN contract", error = differentContractAddress.error # simulating a change in the contractAddress diff --git a/tests/waku_rln_relay/utils_onchain.nim b/tests/waku_rln_relay/utils_onchain.nim index d34500588..1aee23d0b 100644 --- a/tests/waku_rln_relay/utils_onchain.nim +++ b/tests/waku_rln_relay/utils_onchain.nim @@ -341,7 +341,7 @@ proc approveTokenAllowanceAndVerify*( return allowanceAfter >= amountWei proc executeForgeContractDeployScripts*( - pk: keys.PrivateKey, acc: Address, web3: Web3 + pk: keys.PrivateKey, acc: Address, web3: Web3 ): Future[Result[Address, string]] {.async, gcsafe.} = ## Executes a set of foundry forge scripts required to deploy the RLN contract and returns the deployed proxy contract address ## submodulePath: path to the submodule containing contract deploy scripts @@ -437,7 +437,7 @@ proc executeForgeContractDeployScripts*( let proxyAddressAddress = Address(proxyAddressBytes) info "Address of the Proxy contract", proxyAddressAddress - + await web3.close() return ok(proxyAddressAddress) @@ -549,9 +549,9 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process = "--transaction-block-keeper", "10", "--disable-console-log", - "--threads", + "--threads", "0", - "--no-request-size-limit" + "--no-request-size-limit", ], options = {poUsePath}, ) @@ -618,7 +618,8 @@ proc setupOnchainGroupManager*( discard await sendMintCall( web3, web3.defaultAccount, TOKEN_ADDRESS, acc, ethToWei(1000.u256), some(0.u256) ) - let contractAddressRes = await executeForgeContractDeployScripts(privateKey, acc, web3) + let contractAddressRes = + await executeForgeContractDeployScripts(privateKey, acc, web3) if contractAddressRes.isErr(): error "Failed to deploy RLN contract", error = contractAddressRes.error raise newException(CatchableError, "Failed to deploy RLN contract") 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 9a3d20b43..e8cd564f6 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 @@ -30,11 +30,17 @@ logScope: # using the when predicate does not work within the contract macro, hence need to dupe contract(WakuRlnContract): # this serves as an entrypoint into the rln membership set - proc register(idCommitment: UInt256, userMessageLimit: UInt32, idCommitmentsToErase: seq[UInt256]) + proc register( + idCommitment: UInt256, userMessageLimit: UInt32, idCommitmentsToErase: seq[UInt256] + ) + # Initializes the implementation contract (only used in unit tests) proc initialize(maxMessageLimit: UInt256) # this event is raised when a new member is registered - proc MembershipRegistered(idCommitment: UInt256, membershipRateLimit: UInt256, index: UInt32) {.event.} + proc MembershipRegistered( + idCommitment: UInt256, membershipRateLimit: UInt256, index: UInt32 + ) {.event.} + # this function denotes existence of a given user proc isInMembershipSet(idCommitment: Uint256): bool {.view.} # this constant describes the next index of a new member @@ -295,17 +301,18 @@ method register*( g.retryWrapper(gasPrice, "Failed to get gas price"): int(await ethRpc.provider.eth_gasPrice()) * 2 let idCommitmentHex = identityCredential.idCommitment.inHex() - debug "identityCredential idCommitmentHex", - idCommitmentNoConvert = idCommitmentHex + debug "identityCredential idCommitmentHex", idCommitmentNoConvert = idCommitmentHex let idCommitment = identityCredential.idCommitment.toUInt256() let idCommitmentsToErase: seq[UInt256] = @[] debug "registering the member", - idCommitment = idCommitment, userMessageLimit = userMessageLimit, idCommitmentsToErase = idCommitmentsToErase + idCommitment = idCommitment, + userMessageLimit = userMessageLimit, + idCommitmentsToErase = idCommitmentsToErase var txHash: TxHash g.retryWrapper(txHash, "Failed to register the member"): - await wakuRlnContract.register(idCommitment, userMessageLimit.stuint(32),idCommitmentsToErase).send( - gasPrice = gasPrice - ) + await wakuRlnContract + .register(idCommitment, userMessageLimit.stuint(32), idCommitmentsToErase) + .send(gasPrice = gasPrice) # wait for the transaction to be mined var tsReceipt: ReceiptObject @@ -328,7 +335,9 @@ method register*( debug "third topic", firstTopic = firstTopic # the hash of the signature of MembershipRegistered(uint256,uint256,uint32) event is equal to the following hex value if firstTopic != - cast[FixedBytes[32]](keccak.keccak256.digest("MembershipRegistered(uint256,uint256,uint32)").data): + cast[FixedBytes[32]](keccak.keccak256.digest( + "MembershipRegistered(uint256,uint256,uint32)" + ).data): raise newException(ValueError, "register: unexpected event signature") # the arguments of the raised event i.e., MembershipRegistered are encoded inside the data field @@ -567,7 +576,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.} # check if the Ethereum client is reachable let ethRpc: Web3 = (await establishConnection(g)).valueOr: return err("failed to connect to Ethereum clients: " & $error) - + debug "fetching chainId" var fetchedChainId: UInt256 g.retryWrapper(fetchedChainId, "Failed to get the chain id"): @@ -599,7 +608,6 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.} debug "contract address", contractAddress = contractAddress, ethContractAddress = g.ethContractAddress - g.ethRpc = some(ethRpc) g.wakuRlnContract = some(wakuRlnContract) @@ -628,13 +636,10 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.} # now we check on the contract if the commitment actually has a membership let idCommitmentBytes = keystoreCred.identityCredential.idCommitment let idCommitmentUInt256 = keystoreCred.identityCredential.idCommitment.toUInt256() - let idCommitmentHex = idCommitmentBytes.inHex() - debug "Keystore idCommitment in bytes", - idCommitmentBytes = idCommitmentBytes - debug "Keystore idCommitment in UInt256 ", - idCommitmentUInt256 = idCommitmentUInt256 - debug "Keystore idCommitment in hex ", - idCommitmentHex = idCommitmentHex + let idCommitmentHex = idCommitmentBytes.inHex() + debug "Keystore idCommitment in bytes", idCommitmentBytes = idCommitmentBytes + debug "Keystore idCommitment in UInt256 ", idCommitmentUInt256 = idCommitmentUInt256 + debug "Keystore idCommitment in hex ", idCommitmentHex = idCommitmentHex let idCommitment = idCommitmentUInt256 try: # let membershipExists = @@ -663,10 +668,9 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.} tx.chainId = Opt.some(g.chainId) let resultBytes = await g.ethRpc.get().provider.eth_call(tx, "latest") - debug "resultBytes", - resultBytes = resultBytes, len = resultBytes.len + debug "resultBytes", resultBytes = resultBytes, len = resultBytes.len if resultBytes.len == 0: - return err("No result returned for function call: " & $functionSignature) + return err("No result returned for function call: " & $functionSignature) let membershipExists = resultBytes.len == 32 and resultBytes[^1] == 1'u8 debug "membershipExists", membershipExists = membershipExists