From 197d9b82fa33465b62faceebe43c2d9911ff7086 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 | 20 +++++------ tests/waku_rln_relay/utils_onchain.nim | 7 +++- .../group_manager/on_chain/group_manager.nim | 35 +++++++++++-------- 3 files changed, 37 insertions(+), 25 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 3de48a738..29939dfff 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -33,9 +33,6 @@ initLock(testLock) suite "Onchain group manager": setup: - # Acquire lock to ensure tests run sequentially - acquire(testLock) - let runAnvil {.used.} = runAnvil() var manager {.threadvar.}: OnchainGroupManager @@ -85,14 +82,17 @@ suite "Onchain group manager": let accounts = waitFor web3.provider.eth_accounts() web3.defaultAccount = accounts[2] let (privateKey, acc) = createEthAccount(web3) - let tokenAddress = (waitFor deployTestToken(privateKey, acc, web3)).valueOr: - assert false, "Failed to deploy test token contract: " & $error - return - let differentContractAddress = ( + + let testTokenAddressRes = waitFor deployTestToken(privateKey, acc, web3) + if testTokenAddressRes.isErr(): + error "Failed to deploy test token contract", error = testTokenAddressRes.error + raise newException(CatchableError, "Failed to deploy test token contract") + let TOKEN_ADDRESS = testTokenAddressRes.get() + + let differentContractAddress = waitFor executeForgeContractDeployScripts(privateKey, acc, web3) - ).valueOr: - assert false, "Failed to deploy RLN contract: " & $error - return + if differentContractAddress.isErr(): + error "Failed to deploy RLN contract", error = differentContractAddress.error # simulating a change in the contractAddress let manager2 = OnchainGroupManager( ethClientUrls: @[EthClient], diff --git a/tests/waku_rln_relay/utils_onchain.nim b/tests/waku_rln_relay/utils_onchain.nim index 7c180f41c..772386264 100644 --- a/tests/waku_rln_relay/utils_onchain.nim +++ b/tests/waku_rln_relay/utils_onchain.nim @@ -574,7 +574,7 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process = "--balance", "1000000000", "--chain-id", - $chainId, + $chainId ], options = {poUsePath}, ) @@ -651,6 +651,11 @@ proc setupOnchainGroupManager*( discard await sendMintCall( web3, web3.defaultAccount, testTokenAddress, acc, ethToWei(1000.u256), some(0.u256) ) + 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") let contractAddress = (await executeForgeContractDeployScripts(privateKey, acc, web3)).valueOr: assert false, "Failed to deploy RLN contract: " & $error 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 135c57f34..5a335ca31 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 @@ -299,12 +305,14 @@ method register*( 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 @@ -327,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 @@ -623,13 +633,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 =