mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-05 23:43:07 +00:00
feat(tests): robustify waku_rln_relay test utils (#3650)
This commit is contained in:
parent
1e73213a36
commit
c6cf34df06
@ -82,6 +82,10 @@ proc getForgePath(): string =
|
|||||||
forgePath = joinPath(forgePath, ".foundry/bin/forge")
|
forgePath = joinPath(forgePath, ".foundry/bin/forge")
|
||||||
return $forgePath
|
return $forgePath
|
||||||
|
|
||||||
|
template execForge(cmd: string): tuple[output: string, exitCode: int] =
|
||||||
|
# unset env vars that affect e.g. "forge script" before running forge
|
||||||
|
execCmdEx("unset ETH_FROM ETH_PASSWORD && " & cmd)
|
||||||
|
|
||||||
contract(ERC20Token):
|
contract(ERC20Token):
|
||||||
proc allowance(owner: Address, spender: Address): UInt256 {.view.}
|
proc allowance(owner: Address, spender: Address): UInt256 {.view.}
|
||||||
proc balanceOf(account: Address): UInt256 {.view.}
|
proc balanceOf(account: Address): UInt256 {.view.}
|
||||||
@ -225,11 +229,14 @@ proc deployTestToken*(
|
|||||||
# Deploy TestToken contract
|
# Deploy TestToken contract
|
||||||
let forgeCmdTestToken =
|
let forgeCmdTestToken =
|
||||||
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"""
|
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"""
|
||||||
let (outputDeployTestToken, exitCodeDeployTestToken) = execCmdEx(forgeCmdTestToken)
|
let (outputDeployTestToken, exitCodeDeployTestToken) = execForge(forgeCmdTestToken)
|
||||||
trace "Executed forge command to deploy TestToken contract",
|
trace "Executed forge command to deploy TestToken contract",
|
||||||
output = outputDeployTestToken
|
output = outputDeployTestToken
|
||||||
if exitCodeDeployTestToken != 0:
|
if exitCodeDeployTestToken != 0:
|
||||||
return error("Forge command to deploy TestToken contract failed")
|
error "Forge command to deploy TestToken contract failed",
|
||||||
|
error = outputDeployTestToken
|
||||||
|
return
|
||||||
|
err("Forge command to deploy TestToken contract failed: " & outputDeployTestToken)
|
||||||
|
|
||||||
# Parse the command output to find contract address
|
# Parse the command output to find contract address
|
||||||
let testTokenAddress = getContractAddressFromDeployScriptOutput(outputDeployTestToken).valueOr:
|
let testTokenAddress = getContractAddressFromDeployScriptOutput(outputDeployTestToken).valueOr:
|
||||||
@ -351,7 +358,7 @@ proc executeForgeContractDeployScripts*(
|
|||||||
let forgeCmdPriceCalculator =
|
let forgeCmdPriceCalculator =
|
||||||
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"""
|
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"""
|
||||||
let (outputDeployPriceCalculator, exitCodeDeployPriceCalculator) =
|
let (outputDeployPriceCalculator, exitCodeDeployPriceCalculator) =
|
||||||
execCmdEx(forgeCmdPriceCalculator)
|
execForge(forgeCmdPriceCalculator)
|
||||||
trace "Executed forge command to deploy LinearPriceCalculator contract",
|
trace "Executed forge command to deploy LinearPriceCalculator contract",
|
||||||
output = outputDeployPriceCalculator
|
output = outputDeployPriceCalculator
|
||||||
if exitCodeDeployPriceCalculator != 0:
|
if exitCodeDeployPriceCalculator != 0:
|
||||||
@ -368,7 +375,7 @@ proc executeForgeContractDeployScripts*(
|
|||||||
|
|
||||||
let forgeCmdWakuRln =
|
let forgeCmdWakuRln =
|
||||||
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"""
|
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"""
|
||||||
let (outputDeployWakuRln, exitCodeDeployWakuRln) = execCmdEx(forgeCmdWakuRln)
|
let (outputDeployWakuRln, exitCodeDeployWakuRln) = execForge(forgeCmdWakuRln)
|
||||||
trace "Executed forge command to deploy WakuRlnV2 contract",
|
trace "Executed forge command to deploy WakuRlnV2 contract",
|
||||||
output = outputDeployWakuRln
|
output = outputDeployWakuRln
|
||||||
if exitCodeDeployWakuRln != 0:
|
if exitCodeDeployWakuRln != 0:
|
||||||
@ -388,7 +395,7 @@ proc executeForgeContractDeployScripts*(
|
|||||||
# Deploy Proxy contract
|
# Deploy Proxy contract
|
||||||
let forgeCmdProxy =
|
let forgeCmdProxy =
|
||||||
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"""
|
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"""
|
||||||
let (outputDeployProxy, exitCodeDeployProxy) = execCmdEx(forgeCmdProxy)
|
let (outputDeployProxy, exitCodeDeployProxy) = execForge(forgeCmdProxy)
|
||||||
trace "Executed forge command to deploy proxy contract", output = outputDeployProxy
|
trace "Executed forge command to deploy proxy contract", output = outputDeployProxy
|
||||||
if exitCodeDeployProxy != 0:
|
if exitCodeDeployProxy != 0:
|
||||||
error "Forge command to deploy Proxy failed", error = outputDeployProxy
|
error "Forge command to deploy Proxy failed", error = outputDeployProxy
|
||||||
@ -503,7 +510,7 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process =
|
|||||||
"--chain-id",
|
"--chain-id",
|
||||||
$chainId,
|
$chainId,
|
||||||
],
|
],
|
||||||
options = {poUsePath},
|
options = {poUsePath, poStdErrToStdOut},
|
||||||
)
|
)
|
||||||
let anvilPID = runAnvil.processID
|
let anvilPID = runAnvil.processID
|
||||||
|
|
||||||
@ -516,7 +523,13 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process =
|
|||||||
anvilStartLog.add(cmdline)
|
anvilStartLog.add(cmdline)
|
||||||
if cmdline.contains("Listening on 127.0.0.1:" & $port):
|
if cmdline.contains("Listening on 127.0.0.1:" & $port):
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
error "Anvil daemon exited (closed output)",
|
||||||
|
pid = anvilPID, startLog = anvilStartLog
|
||||||
|
return
|
||||||
except Exception, CatchableError:
|
except Exception, CatchableError:
|
||||||
|
warn "Anvil daemon stdout reading error; assuming it started OK",
|
||||||
|
pid = anvilPID, startLog = anvilStartLog, err = getCurrentExceptionMsg()
|
||||||
break
|
break
|
||||||
info "Anvil daemon is running and ready", pid = anvilPID, startLog = anvilStartLog
|
info "Anvil daemon is running and ready", pid = anvilPID, startLog = anvilStartLog
|
||||||
return runAnvil
|
return runAnvil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user