mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-08 00:43:06 +00:00
chore(rln): update ganache (#1347)
* chore: build rln dependecies only when building v2 * chore(rln): deprecate ganache-cli; move installation from makefile to test + uninstall; gracefully terminate ganache * chore: add package.json to gitignore * fix(rln): move ganache package to build folder and remove package once uninstalled * refactor(rln): (un)install/run/stop ganache with separate procs Co-authored-by: Lorenzo Delgado <lorenzo@status.im> Co-authored-by: Aaryamann Challani <43716372+rymnc@users.noreply.github.com>
This commit is contained in:
parent
c15fddb561
commit
8333eb9cf1
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,6 +32,7 @@
|
|||||||
rln
|
rln
|
||||||
*.log
|
*.log
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
package.json
|
||||||
node_modules/
|
node_modules/
|
||||||
/.update.timestamp
|
/.update.timestamp
|
||||||
|
|
||||||
|
|||||||
24
Makefile
24
Makefile
@ -153,13 +153,9 @@ sim1: | build deps wakunode1
|
|||||||
|
|
||||||
## Waku v2 targets
|
## Waku v2 targets
|
||||||
|
|
||||||
test2: | build deps deps2 installganache
|
test2: | build deps deps2
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
$(ENV_SCRIPT) nim test2 $(NIM_PARAMS) waku.nims
|
$(ENV_SCRIPT) nim test2 $(NIM_PARAMS) waku.nims
|
||||||
# the following command (pkill -f ganache-cli) attempts to kill ganache-cli process on macos
|
|
||||||
# if we do not kill the process then it would hang there and causes issue in GitHub Actions macos job (the job never finsihes)
|
|
||||||
(([[ $(detected_OS) = macOS ]] && \
|
|
||||||
pkill -f ganache-cli) || true)
|
|
||||||
|
|
||||||
wakunode2: | build deps deps2
|
wakunode2: | build deps deps2
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
@ -219,25 +215,9 @@ endif
|
|||||||
# control compilation of rln tests that require on chain interaction
|
# control compilation of rln tests that require on chain interaction
|
||||||
ifeq ($(ONCHAIN_RLN), true)
|
ifeq ($(ONCHAIN_RLN), true)
|
||||||
NIM_PARAMS := $(NIM_PARAMS) -d:onchain_rln
|
NIM_PARAMS := $(NIM_PARAMS) -d:onchain_rln
|
||||||
else
|
else ifeq ($(CI), true)
|
||||||
ifeq ($(CI), true)
|
|
||||||
ifeq ($(detected_OS), macOS)
|
|
||||||
NIM_PARAMS := $(NIM_PARAMS) -d:onchain_rln
|
NIM_PARAMS := $(NIM_PARAMS) -d:onchain_rln
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
installganache:
|
|
||||||
ifeq ($(ONCHAIN_RLN), true)
|
|
||||||
npm install ganache-cli; npx ganache-cli -p 8540 -g 0 -l 3000000000000&
|
|
||||||
else
|
|
||||||
ifeq ($(CI), true)
|
|
||||||
ifeq ($(detected_OS), macOS)
|
|
||||||
npm install ganache-cli; npx ganache-cli -p 8540 -g 0 -l 3000000000000&
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
rlnlib:
|
rlnlib:
|
||||||
ifeq ($(RLNKILIC), true)
|
ifeq ($(RLNKILIC), true)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/options,
|
std/[options, osproc, streams, strutils],
|
||||||
testutils/unittests, chronos, chronicles, stint, web3, json,
|
testutils/unittests, chronos, chronicles, stint, web3, json,
|
||||||
stew/byteutils, stew/shims/net as stewNet,
|
stew/byteutils, stew/shims/net as stewNet,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
@ -16,6 +16,8 @@ import
|
|||||||
../test_helpers,
|
../test_helpers,
|
||||||
./test_utils
|
./test_utils
|
||||||
|
|
||||||
|
from posix import kill, SIGINT
|
||||||
|
|
||||||
const RlnRelayPubsubTopic = "waku/2/rlnrelay/proto"
|
const RlnRelayPubsubTopic = "waku/2/rlnrelay/proto"
|
||||||
const RlnRelayContentTopic = "waku/2/rlnrelay/proto"
|
const RlnRelayContentTopic = "waku/2/rlnrelay/proto"
|
||||||
|
|
||||||
@ -103,7 +105,76 @@ proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
|
|||||||
|
|
||||||
return (pk, acc)
|
return (pk, acc)
|
||||||
|
|
||||||
|
|
||||||
|
# Installs Ganache Daemon
|
||||||
|
proc installGanache() =
|
||||||
|
# We install Ganache.
|
||||||
|
# Packages will be installed to the ./build folder through the --prefix option
|
||||||
|
let installGanache = startProcess("npm", args = ["install", "ganache", "--prefix", "./build"], options = {poUsePath})
|
||||||
|
let returnCode = installGanache.waitForExit()
|
||||||
|
debug "Ganache install log", returnCode=returnCode, log=installGanache.outputstream.readAll()
|
||||||
|
|
||||||
|
# Uninstalls Ganache Daemon
|
||||||
|
proc uninstallGanache() =
|
||||||
|
# We uninstall Ganache
|
||||||
|
# Packages will be uninstalled from the ./build folder through the --prefix option.
|
||||||
|
# Passed option is
|
||||||
|
# --save: Package will be removed from your dependencies.
|
||||||
|
# See npm documentation https://docs.npmjs.com/cli/v6/commands/npm-uninstall for further details
|
||||||
|
let uninstallGanache = startProcess("npm", args = ["uninstall", "ganache", "--save", "--prefix", "./build"], options = {poUsePath})
|
||||||
|
let returnCode = uninstallGanache.waitForExit()
|
||||||
|
debug "Ganache uninstall log", returnCode=returnCode, log=uninstallGanache.outputstream.readAll()
|
||||||
|
|
||||||
|
# Runs Ganache daemon
|
||||||
|
proc runGanache(): Process =
|
||||||
|
# We run directly "node node_modules/ganache/dist/node/cli.js" rather than using "npx ganache", so that the daemon does not spawn in a new child process.
|
||||||
|
# In this way, we can directly send a SIGINT signal to the corresponding PID to gracefully terminate Ganache without dealing with multiple processes.
|
||||||
|
# Passed options are
|
||||||
|
# --port Port to listen on.
|
||||||
|
# --miner.blockGasLimit Sets the block gas limit in WEI.
|
||||||
|
# --wallet.defaultBalance The default account balance, specified in ether.
|
||||||
|
# See ganache documentation https://www.npmjs.com/package/ganache for more details
|
||||||
|
let runGanache = startProcess("node", args = ["./build/node_modules/ganache/dist/node/cli.js", "--port", "8540", "--miner.blockGasLimit", "300000000000000", "--wallet.defaultBalance", "10000"], options = {poUsePath})
|
||||||
|
let ganachePID = runGanache.processID
|
||||||
|
|
||||||
|
# We read stdout from Ganache to see when daemon is ready
|
||||||
|
var ganacheStartLog: string
|
||||||
|
var cmdline: string
|
||||||
|
while true:
|
||||||
|
if runGanache.outputstream.readLine(cmdline):
|
||||||
|
ganacheStartLog.add cmdline
|
||||||
|
if cmdline.contains("Listening on 127.0.0.1:8540"):
|
||||||
|
break
|
||||||
|
debug "Ganache daemon is running and ready", pid=ganachePID, startLog=ganacheStartLog
|
||||||
|
return runGanache
|
||||||
|
|
||||||
|
|
||||||
|
# Stops Ganache daemon
|
||||||
|
proc stopGanache(runGanache: Process) =
|
||||||
|
|
||||||
|
let ganachePID = runGanache.processID
|
||||||
|
|
||||||
|
# We gracefully terminate Ganache daemon by sending a SIGINT signal to the runGanache PID to trigger RPC server termination and clean-up
|
||||||
|
let returnCodeSIGINT = kill(ganachePID.int32, SIGINT)
|
||||||
|
debug "Sent SIGINT to Ganache", ganachePID=ganachePID, returnCode=returnCodeSIGINT
|
||||||
|
|
||||||
|
# We wait the daemon to exit
|
||||||
|
let returnCodeExit = runGanache.waitForExit()
|
||||||
|
debug "Ganache daemon terminated", returnCode=returnCodeExit
|
||||||
|
debug "Ganache daemon run log", log=runGanache.outputstream.readAll()
|
||||||
|
|
||||||
procSuite "Waku-rln-relay":
|
procSuite "Waku-rln-relay":
|
||||||
|
|
||||||
|
################################
|
||||||
|
## Installing/running Ganache
|
||||||
|
################################
|
||||||
|
|
||||||
|
# We install Ganache
|
||||||
|
installGanache()
|
||||||
|
|
||||||
|
# We run Ganache
|
||||||
|
let runGanache = runGanache()
|
||||||
|
|
||||||
asyncTest "event subscription":
|
asyncTest "event subscription":
|
||||||
# preparation ------------------------------
|
# preparation ------------------------------
|
||||||
debug "ethereum client address", EthClient
|
debug "ethereum client address", EthClient
|
||||||
@ -533,3 +604,13 @@ procSuite "Waku-rln-relay":
|
|||||||
|
|
||||||
await node.stop()
|
await node.stop()
|
||||||
await node2.stop()
|
await node2.stop()
|
||||||
|
|
||||||
|
################################
|
||||||
|
## Terminating/removing Ganache
|
||||||
|
################################
|
||||||
|
|
||||||
|
# We stop Ganache daemon
|
||||||
|
stopGanache(runGanache)
|
||||||
|
|
||||||
|
# We uninstall Ganache
|
||||||
|
uninstallGanache()
|
||||||
Loading…
x
Reference in New Issue
Block a user