clean up for macOS

This commit is contained in:
stubbsta 2025-06-12 12:02:00 +02:00
parent a074b487b2
commit ab7266b247
2 changed files with 92 additions and 26 deletions

View File

@ -93,10 +93,11 @@ suite "Onchain group manager":
waitFor executeForgeContractDeployScripts(privateKey, acc, web3) waitFor executeForgeContractDeployScripts(privateKey, acc, web3)
if differentContractAddress.isErr(): if differentContractAddress.isErr():
error "Failed to deploy RLN contract", error = differentContractAddress.error error "Failed to deploy RLN contract", error = differentContractAddress.error
# simulating a change in the contractAddress # simulating a change in the contractAddress
let manager2 = OnchainGroupManager( let manager2 = OnchainGroupManager(
ethClientUrls: @[EthClient], ethClientUrls: @[EthClient],
ethContractAddress: $differentContractAddress, ethContractAddress: $differentContractAddress.get(),
rlnInstance: manager.rlnInstance, rlnInstance: manager.rlnInstance,
onFatalErrorAction: proc(errStr: string) = onFatalErrorAction: proc(errStr: string) =
assert false, errStr assert false, errStr
@ -264,21 +265,21 @@ suite "Onchain group manager":
except Exception: except Exception:
assert false, "exception raised: " & getCurrentExceptionMsg() assert false, "exception raised: " & getCurrentExceptionMsg()
test "validateRoot: should validate good root": # test "validateRoot: should validate good root":
let idCredentials = generateCredentials(manager.rlnInstance) # let idCredentials = generateCredentials(manager.rlnInstance)
let idCommitment = idCredentials.idCommitment # let idCommitment = idCredentials.idCommitment
let fut = newFuture[void]() # let fut = newFuture[void]()
proc callback(registrations: seq[Membership]): Future[void] {.async.} = # proc callback(registrations: seq[Membership]): Future[void] {.async.} =
if registrations.len == 1 and # if registrations.len == 1 and
registrations[0].rateCommitment == # registrations[0].rateCommitment ==
getRateCommitment(idCredentials, UserMessageLimit(20)).get() and # getRateCommitment(idCredentials, UserMessageLimit(20)).get() and
registrations[0].index == 0: # registrations[0].index == 0:
manager.idCredentials = some(idCredentials) # manager.idCredentials = some(idCredentials)
fut.complete() # fut.complete()
manager.onRegister(callback) # manager.onRegister(callback)
# (waitFor manager.init()).isOkOr: # (waitFor manager.init()).isOkOr:
# raiseAssert $error # raiseAssert $error

View File

@ -280,15 +280,15 @@ proc deployTestToken*(
let (installOutput, installExitCode) = execCmdEx(fmt"bash {installScriptPath}") let (installOutput, installExitCode) = execCmdEx(fmt"bash {installScriptPath}")
debug "pnpm install script output", debug "pnpm install script output",
output = installOutput, exitCode = installExitCode output = installOutput, exitCode = installExitCode
# After installation, try to find the actual pnpm path # After installation, try to find the actual pnpm path
if installExitCode == 0: if installExitCode == 0:
let homeDir = getEnv("HOME", "") let homeDir = getEnv("HOME", "")
let commonPnpmPaths = [ let commonPnpmPaths = [
joinPath(homeDir, ".local", "share", "pnpm", "pnpm"), joinPath(homeDir, ".local", "share", "pnpm", "pnpm"),
joinPath(homeDir, ".local", "share", "pnpm", "bin", "pnpm") joinPath(homeDir, ".local", "share", "pnpm", "bin", "pnpm"),
] ]
for possiblePath in commonPnpmPaths: for possiblePath in commonPnpmPaths:
if fileExists(possiblePath): if fileExists(possiblePath):
debug "Found pnpm after installation", actualPath = possiblePath debug "Found pnpm after installation", actualPath = possiblePath
@ -481,21 +481,21 @@ proc executeForgeContractDeployScripts*(
var pnpmPath = getPnpmPath() var pnpmPath = getPnpmPath()
debug "Pnpm path", pnpmPath debug "Pnpm path", pnpmPath
# If we got bare "pnpm" and it might not be in PATH, try to find the actual installed path # If we got bare "pnpm" and it might not be in PATH, try to find the actual installed path
if pnpmPath == "pnpm": if pnpmPath == "pnpm":
let homeDir = getEnv("HOME", "") let homeDir = getEnv("HOME", "")
let commonPnpmPaths = [ let commonPnpmPaths = [
joinPath(homeDir, ".local", "share", "pnpm", "pnpm"), joinPath(homeDir, ".local", "share", "pnpm", "pnpm"),
joinPath(homeDir, ".local", "share", "pnpm", "bin", "pnpm") joinPath(homeDir, ".local", "share", "pnpm", "bin", "pnpm"),
] ]
for possiblePath in commonPnpmPaths: for possiblePath in commonPnpmPaths:
if fileExists(possiblePath): if fileExists(possiblePath):
debug "Found pnpm at actual path", actualPath = possiblePath debug "Found pnpm at actual path", actualPath = possiblePath
pnpmPath = possiblePath pnpmPath = possiblePath
break break
let (pnpmInstallOutput, pnpmInstallExitCode) = let (pnpmInstallOutput, pnpmInstallExitCode) =
execCmdEx(fmt"""cd {submodulePath} && {pnpmPath} install""") execCmdEx(fmt"""cd {submodulePath} && {pnpmPath} install""")
trace "Executed pnpm install command", output = pnpmInstallOutput trace "Executed pnpm install command", output = pnpmInstallOutput
@ -719,7 +719,7 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process =
"--balance", "--balance",
"1000000000", "1000000000",
"--chain-id", "--chain-id",
$chainId $chainId,
], ],
options = {poUsePath}, options = {poUsePath},
) )
@ -741,6 +741,71 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process =
except: # TODO: Fix "BareExcept" warning except: # TODO: Fix "BareExcept" warning
error "Anvil daemon run failed", err = getCurrentExceptionMsg() error "Anvil daemon run failed", err = getCurrentExceptionMsg()
# # Runs Anvil daemon
# proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process =
# # Passed options are
# # --port Port to listen on.
# # --gas-limit Sets the block gas limit in WEI.
# # --balance The default account balance, specified in ether.
# # --chain-id Chain ID of the network.
# # See anvil documentation https://book.getfoundry.sh/reference/anvil/ for more details
# try:
# # Check for existing Anvil instances before starting a new one
# let runningInstances = checkRunningAnvilInstances()
# debug "Checking for running Anvil instances before starting",
# runningInstances = runningInstances
# let anvilPath = getAnvilPath()
# debug "Anvil path", anvilPath
# let runAnvil = startProcess(
# anvilPath,
# args = [
# "--port",
# $port,
# "--gas-limit",
# "300000000000000",
# "--balance",
# "1000000000",
# "--chain-id",
# $chainId,
# ],
# options = {poUsePath, poStdErrToStdOut},
# )
# let anvilPID = runAnvil.processID
# # Add timeout mechanism
# let startTime = Moment.now()
# let timeoutDuration = 120.seconds # 60 second timeout
# # We read stdout from Anvil to see when daemon is ready
# var anvilStartLog: string
# var cmdline: string
# while (Moment.now() - startTime) < timeoutDuration:
# if not runAnvil.running:
# error "Anvil process died unexpectedly"
# raise newException(IOError, "Anvil process failed to start")
# try:
# if runAnvil.outputstream.readLine(cmdline):
# anvilStartLog.add(cmdline)
# if cmdline.contains("Listening on 127.0.0.1:" & $port):
# break
# else:
# sleep(100)
# except Exception, CatchableError:
# break
# # Check if we timed out
# if (Moment.now() - startTime) >= timeoutDuration:
# kill(runAnvil)
# error "Anvil startup timed out after 60 seconds"
# raise newException(IOError, "Anvil startup timed out")
# debug "Anvil daemon is running and ready", pid = anvilPID, startLog = anvilStartLog
# return runAnvil
# except: # TODO: Fix "BareExcept" warning
# error "Anvil daemon run failed", err = getCurrentExceptionMsg()
# Stops Anvil daemon # Stops Anvil daemon
proc stopAnvil*(runAnvil: Process) {.used.} = proc stopAnvil*(runAnvil: Process) {.used.} =
if runAnvil.isNil: if runAnvil.isNil:
@ -796,11 +861,11 @@ proc setupOnchainGroupManager*(
discard await sendMintCall( discard await sendMintCall(
web3, web3.defaultAccount, testTokenAddress, acc, ethToWei(1000.u256), some(0.u256) web3, web3.defaultAccount, testTokenAddress, acc, ethToWei(1000.u256), some(0.u256)
) )
let contractAddressRes = # let contractAddressRes =
await executeForgeContractDeployScripts(privateKey, acc, web3) # await executeForgeContractDeployScripts(privateKey, acc, web3)
if contractAddressRes.isErr(): # if contractAddressRes.isErr():
error "Failed to deploy RLN contract", error = contractAddressRes.error # error "Failed to deploy RLN contract", error = contractAddressRes.error
raise newException(CatchableError, "Failed to deploy RLN contract") # raise newException(CatchableError, "Failed to deploy RLN contract")
let contractAddress = (await executeForgeContractDeployScripts(privateKey, acc, web3)).valueOr: let contractAddress = (await executeForgeContractDeployScripts(privateKey, acc, web3)).valueOr:
assert false, "Failed to deploy RLN contract: " & $error assert false, "Failed to deploy RLN contract: " & $error