Skip to content

Commit c6cf34d

Browse files
authored
feat(tests): robustify waku_rln_relay test utils (#3650)
1 parent 1e73213 commit c6cf34d

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tests/waku_rln_relay/utils_onchain.nim

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ proc getForgePath(): string =
8282
forgePath = joinPath(forgePath, ".foundry/bin/forge")
8383
return $forgePath
8484

85+
template execForge(cmd: string): tuple[output: string, exitCode: int] =
86+
# unset env vars that affect e.g. "forge script" before running forge
87+
execCmdEx("unset ETH_FROM ETH_PASSWORD && " & cmd)
88+
8589
contract(ERC20Token):
8690
proc allowance(owner: Address, spender: Address): UInt256 {.view.}
8791
proc balanceOf(account: Address): UInt256 {.view.}
@@ -225,11 +229,14 @@ proc deployTestToken*(
225229
# Deploy TestToken contract
226230
let forgeCmdTestToken =
227231
fmt"""cd {submodulePath} && {forgePath} script test/TestToken.sol --broadcast -vvv --rpc-url http://localhost:8540 --tc TestTokenFactory --private-key {pk} && rm -rf broadcast/*/*/run-1*.json && rm -rf cache/*/*/run-1*.json"""
228-
let (outputDeployTestToken, exitCodeDeployTestToken) = execCmdEx(forgeCmdTestToken)
232+
let (outputDeployTestToken, exitCodeDeployTestToken) = execForge(forgeCmdTestToken)
229233
trace "Executed forge command to deploy TestToken contract",
230234
output = outputDeployTestToken
231235
if exitCodeDeployTestToken != 0:
232-
return error("Forge command to deploy TestToken contract failed")
236+
error "Forge command to deploy TestToken contract failed",
237+
error = outputDeployTestToken
238+
return
239+
err("Forge command to deploy TestToken contract failed: " & outputDeployTestToken)
233240

234241
# Parse the command output to find contract address
235242
let testTokenAddress = getContractAddressFromDeployScriptOutput(outputDeployTestToken).valueOr:
@@ -351,7 +358,7 @@ proc executeForgeContractDeployScripts*(
351358
let forgeCmdPriceCalculator =
352359
fmt"""cd {submodulePath} && {forgePath} script script/Deploy.s.sol --broadcast -vvvv --rpc-url http://localhost:8540 --tc DeployPriceCalculator --private-key {privateKey} && rm -rf broadcast/*/*/run-1*.json && rm -rf cache/*/*/run-1*.json"""
353360
let (outputDeployPriceCalculator, exitCodeDeployPriceCalculator) =
354-
execCmdEx(forgeCmdPriceCalculator)
361+
execForge(forgeCmdPriceCalculator)
355362
trace "Executed forge command to deploy LinearPriceCalculator contract",
356363
output = outputDeployPriceCalculator
357364
if exitCodeDeployPriceCalculator != 0:
@@ -368,7 +375,7 @@ proc executeForgeContractDeployScripts*(
368375

369376
let forgeCmdWakuRln =
370377
fmt"""cd {submodulePath} && {forgePath} script script/Deploy.s.sol --broadcast -vvvv --rpc-url http://localhost:8540 --tc DeployWakuRlnV2 --private-key {privateKey} && rm -rf broadcast/*/*/run-1*.json && rm -rf cache/*/*/run-1*.json"""
371-
let (outputDeployWakuRln, exitCodeDeployWakuRln) = execCmdEx(forgeCmdWakuRln)
378+
let (outputDeployWakuRln, exitCodeDeployWakuRln) = execForge(forgeCmdWakuRln)
372379
trace "Executed forge command to deploy WakuRlnV2 contract",
373380
output = outputDeployWakuRln
374381
if exitCodeDeployWakuRln != 0:
@@ -388,7 +395,7 @@ proc executeForgeContractDeployScripts*(
388395
# Deploy Proxy contract
389396
let forgeCmdProxy =
390397
fmt"""cd {submodulePath} && {forgePath} script script/Deploy.s.sol --broadcast -vvvv --rpc-url http://localhost:8540 --tc DeployProxy --private-key {privateKey} && rm -rf broadcast/*/*/run-1*.json && rm -rf cache/*/*/run-1*.json"""
391-
let (outputDeployProxy, exitCodeDeployProxy) = execCmdEx(forgeCmdProxy)
398+
let (outputDeployProxy, exitCodeDeployProxy) = execForge(forgeCmdProxy)
392399
trace "Executed forge command to deploy proxy contract", output = outputDeployProxy
393400
if exitCodeDeployProxy != 0:
394401
error "Forge command to deploy Proxy failed", error = outputDeployProxy
@@ -503,7 +510,7 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process =
503510
"--chain-id",
504511
$chainId,
505512
],
506-
options = {poUsePath},
513+
options = {poUsePath, poStdErrToStdOut},
507514
)
508515
let anvilPID = runAnvil.processID
509516

@@ -516,7 +523,13 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process =
516523
anvilStartLog.add(cmdline)
517524
if cmdline.contains("Listening on 127.0.0.1:" & $port):
518525
break
526+
else:
527+
error "Anvil daemon exited (closed output)",
528+
pid = anvilPID, startLog = anvilStartLog
529+
return
519530
except Exception, CatchableError:
531+
warn "Anvil daemon stdout reading error; assuming it started OK",
532+
pid = anvilPID, startLog = anvilStartLog, err = getCurrentExceptionMsg()
520533
break
521534
info "Anvil daemon is running and ready", pid = anvilPID, startLog = anvilStartLog
522535
return runAnvil

0 commit comments

Comments
 (0)