mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-02 13:33:10 +00:00
chore(marketplace): switch to websocket (#1166)
* Switch to websocket * Create resubscribe future * Resubscribe websocket events after 5 minutes * Remove the subscribe workaround and use define the resubscribe symbol * Use localhost for ws url * Define 240 seconds for resubscription interval * Ensute that updates are sync when using ws
This commit is contained in:
parent
748830570a
commit
f7d06cd0e8
4
Makefile
4
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
|
||||
|
||||
@ -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":
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user