Skip to content

Commit 730df2e

Browse files
committed
Create a post start function to run hardhat scripts after startup
1 parent 926e96f commit 730df2e

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

tests/integration/hardhatprocess.nim

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,31 @@ method start*(node: HardhatProcess) {.async.} =
6767
options = poptions,
6868
stdoutHandle = AsyncProcess.Pipe,
6969
)
70-
71-
discard await startProcess(
72-
node.executable,
73-
node.workingDir,
74-
@["node", "run", "scripts/mine.js", "--network", "localhost"].concat(
75-
node.arguments
76-
),
77-
options = poptions,
78-
stdoutHandle = AsyncProcess.Pipe,
79-
)
80-
81-
discard await startProcess(
82-
node.executable,
83-
node.workingDir,
84-
@[
85-
"node", "ignition", "deploy", "ignition/modules/marketplace.js", "--network",
86-
"localhost",
87-
].concat(node.arguments),
88-
options = poptions,
89-
stdoutHandle = AsyncProcess.Pipe,
90-
)
9170
except CancelledError as error:
9271
raise error
9372
except CatchableError as e:
9473
error "failed to start hardhat process", error = e.msg
9574

75+
proc postStart*(
76+
node: HardhatProcess
77+
): Future[void] {.async: (raises: [CancelledError, NodeProcessError]).} =
78+
try:
79+
var execResult = await execCommandEx(
80+
"cd " & node.workingDir() & " && " & node.workingDir() / node.executable() &
81+
" run " & node.workingDir() / "scripts" / "mine.js --network localhost"
82+
)
83+
assert execResult.status == 0
84+
85+
execResult = await execCommandEx(
86+
"cd " & node.workingDir() & " && " & node.workingDir() / node.executable() &
87+
" ignition deploy ignition/modules/marketplace.js --network localhost"
88+
)
89+
assert execResult.status == 0
90+
except CancelledError as e:
91+
raise e
92+
except Exception as e:
93+
raise newException(NodeProcessError, e.msg)
94+
9695
proc startNode*(
9796
_: type HardhatProcess,
9897
args: seq[string],

tests/integration/multinodes.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ template multinodesuite*(name: string, body: untyped) =
146146
raiseMultiNodeSuiteError "hardhat node not started: " & e.msg
147147

148148
trace "hardhat node started"
149+
150+
try:
151+
await node.postStart()
152+
except NodeProcessError as e:
153+
raiseMultiNodeSuiteError "cannot run the post start scripts: " & e.msg
154+
155+
trace "hardhat post start scripts executed"
156+
149157
return node
150158

151159
proc newCodexProcess(

0 commit comments

Comments
 (0)