diff --git a/Makefile b/Makefile index c9f1f10e..6915a119 100644 --- a/Makefile +++ b/Makefile @@ -139,12 +139,12 @@ test: | build deps # Builds and runs the smart contract tests testContracts: | build deps echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim testContracts $(NIM_PARAMS) build.nims + $(ENV_SCRIPT) nim testContracts $(NIM_PARAMS) --define:ws_resubscribe=240 build.nims # Builds and runs the integration tests testIntegration: | build deps echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim testIntegration $(NIM_PARAMS) build.nims + $(ENV_SCRIPT) nim testIntegration $(NIM_PARAMS) --define:ws_resubscribe=240 build.nims # Builds and runs all tests (except for Taiko L2 tests) testAll: | build deps diff --git a/tests/contracts/testClock.nim b/tests/contracts/testClock.nim index abc47496..4c3ad03c 100644 --- a/tests/contracts/testClock.nim +++ b/tests/contracts/testClock.nim @@ -23,6 +23,10 @@ ethersuite "On-Chain Clock": let future = (getTime() + 42.years).toUnix discard await ethProvider.send("evm_setNextBlockTimestamp", @[%future]) discard await ethProvider.send("evm_mine") + + # Ensure that state updates are sync with WS + discard await ethProvider.getBlock(BlockTag.latest) + check eventually clock.now() == future test "can wait until a certain time is reached by the chain": diff --git a/tests/ethertest.nim b/tests/ethertest.nim index dddcb874..2cab8bf5 100644 --- a/tests/ethertest.nim +++ b/tests/ethertest.nim @@ -16,16 +16,14 @@ template ethersuite*(name, body) = var snapshot: JsonNode setup: - ethProvider = JsonRpcProvider.new( - "http://127.0.0.1:8545", pollingInterval = chronos.milliseconds(100) - ) + ethProvider = JsonRpcProvider.new("ws://localhost:8545") snapshot = await send(ethProvider, "evm_snapshot") accounts = await ethProvider.listAccounts() - teardown: - await ethProvider.close() discard await send(ethProvider, "evm_revert", @[snapshot]) + await ethProvider.close() + body export asynctest diff --git a/tests/integration/multinodes.nim b/tests/integration/multinodes.nim index 4b183674..a95fde58 100644 --- a/tests/integration/multinodes.nim +++ b/tests/integration/multinodes.nim @@ -37,7 +37,7 @@ type MultiNodeSuiteError = object of CatchableError -const jsonRpcProviderUrl* = "http://127.0.0.1:8545" +const jsonRpcProviderUrl* = "ws://localhost:8545" proc raiseMultiNodeSuiteError(msg: string) = raise newException(MultiNodeSuiteError, msg) @@ -270,6 +270,8 @@ template multinodesuite*(name: string, body: untyped) = else: discard await send(ethProvider, "evm_revert", @[snapshot]) + await ethProvider.close() + running = @[] template failAndTeardownOnError(message: string, tryBody: untyped) = @@ -307,9 +309,7 @@ template multinodesuite*(name: string, body: untyped) = # Workaround for https://github.com/NomicFoundation/hardhat/issues/2053 # Do not use websockets, but use http and polling to stop subscriptions # from being removed after 5 minutes - ethProvider = JsonRpcProvider.new( - jsonRpcProviderUrl, pollingInterval = chronos.milliseconds(100) - ) + ethProvider = JsonRpcProvider.new(jsonRpcProviderUrl) # if hardhat was NOT started by the test, take a snapshot so it can be # reverted in the test teardown if nodeConfigs.hardhat.isNone: diff --git a/tests/tools/cirdl/testcirdl.nim b/tests/tools/cirdl/testcirdl.nim index dc02be4d..8311a456 100644 --- a/tests/tools/cirdl/testcirdl.nim +++ b/tests/tools/cirdl/testcirdl.nim @@ -14,7 +14,7 @@ suite "tools/cirdl": test "circuit download tool": let circuitPath = "testcircuitpath" - rpcEndpoint = "http://127.0.0.1:8545" + rpcEndpoint = "ws://localhost:8545" marketplaceAddress = Marketplace.address discard existsOrCreateDir(circuitPath)