Skip to content

Commit

Permalink
fix(tests/integration): fix bootstrap node spr
Browse files Browse the repository at this point in the history
After a change in PR #1031, bootstrap node sprs may not work when Hardhat nodes are started with the tests. This fixes it by appending all started client's and provider's SPR to a sequence, and using that sequence of SPRs to start the next node. This means all subsequently started nodes will be connected to its previously started peers.

This also fixes the case when bootstrap SPRs would not be present if no clients were started.
  • Loading branch information
emizzle committed Dec 18, 2024
1 parent 20bb5e5 commit 0587754
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tests/integration/multinodes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ template multinodesuite*(name: string, body: untyped) =
# ...
let jsonRpcProviderUrl = "http://127.0.0.1:8545"
var running {.inject, used.}: seq[RunningNode]
var bootstrap: string
var bootstrapNodes: seq[string]
let starttime = now().format("yyyy-MM-dd'_'HH:mm:ss")
var currentTestName = ""
var nodeConfigs: NodeConfigs
Expand Down Expand Up @@ -162,8 +162,8 @@ template multinodesuite*(name: string, body: untyped) =
let updatedLogFile = getLogFile(role, some roleIdx)
config.withLogFile(updatedLogFile)

if bootstrap.len > 0:
config.addCliOption("--bootstrap-node", bootstrap)
for bootstrapNode in bootstrapNodes:
config.addCliOption("--bootstrap-node", bootstrapNode)
config.addCliOption("--api-port", $ await nextFreePort(8080 + nodeIdx))
config.addCliOption("--data-dir", datadir)
config.addCliOption("--nat", "127.0.0.1")
Expand Down Expand Up @@ -273,6 +273,13 @@ template multinodesuite*(name: string, body: untyped) =
fail()
quit(1)

proc updateBootstrapNodes(node: CodexProcess) =
without ninfo =? node.client.info():
# raise CatchableError instead of Defect (with .get or !) so we
# can gracefully shutdown and prevent zombies
raiseMultiNodeSuiteError "Failed to get node info"
bootstrapNodes.add ninfo["spr"].getStr()

setup:
if var conf =? nodeConfigs.hardhat:
try:
Expand Down Expand Up @@ -311,12 +318,7 @@ template multinodesuite*(name: string, body: untyped) =
role: Role.Client,
node: node
)
if running.len == 1:
without ninfo =? CodexProcess(node).client.info():
# raise CatchableError instead of Defect (with .get or !) so we
# can gracefully shutdown and prevent zombies
raiseMultiNodeSuiteError "Failed to get node info"
bootstrap = ninfo["spr"].getStr()
CodexProcess(node).updateBootstrapNodes()

if var providers =? nodeConfigs.providers:
failAndTeardownOnError "failed to start provider nodes":
Expand All @@ -326,6 +328,7 @@ template multinodesuite*(name: string, body: untyped) =
role: Role.Provider,
node: node
)
CodexProcess(node).updateBootstrapNodes()

if var validators =? nodeConfigs.validators:
failAndTeardownOnError "failed to start validator nodes":
Expand Down

0 comments on commit 0587754

Please sign in to comment.