mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-05 23:13:09 +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
|
# Builds and runs the smart contract tests
|
||||||
testContracts: | build deps
|
testContracts: | build deps
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
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
|
# Builds and runs the integration tests
|
||||||
testIntegration: | build deps
|
testIntegration: | build deps
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
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)
|
# Builds and runs all tests (except for Taiko L2 tests)
|
||||||
testAll: | build deps
|
testAll: | build deps
|
||||||
|
|||||||
@ -23,6 +23,10 @@ ethersuite "On-Chain Clock":
|
|||||||
let future = (getTime() + 42.years).toUnix
|
let future = (getTime() + 42.years).toUnix
|
||||||
discard await ethProvider.send("evm_setNextBlockTimestamp", @[%future])
|
discard await ethProvider.send("evm_setNextBlockTimestamp", @[%future])
|
||||||
discard await ethProvider.send("evm_mine")
|
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
|
check eventually clock.now() == future
|
||||||
|
|
||||||
test "can wait until a certain time is reached by the chain":
|
test "can wait until a certain time is reached by the chain":
|
||||||
|
|||||||
@ -16,16 +16,14 @@ template ethersuite*(name, body) =
|
|||||||
var snapshot: JsonNode
|
var snapshot: JsonNode
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
ethProvider = JsonRpcProvider.new(
|
ethProvider = JsonRpcProvider.new("ws://localhost:8545")
|
||||||
"http://127.0.0.1:8545", pollingInterval = chronos.milliseconds(100)
|
|
||||||
)
|
|
||||||
snapshot = await send(ethProvider, "evm_snapshot")
|
snapshot = await send(ethProvider, "evm_snapshot")
|
||||||
accounts = await ethProvider.listAccounts()
|
accounts = await ethProvider.listAccounts()
|
||||||
|
|
||||||
teardown:
|
teardown:
|
||||||
await ethProvider.close()
|
|
||||||
discard await send(ethProvider, "evm_revert", @[snapshot])
|
discard await send(ethProvider, "evm_revert", @[snapshot])
|
||||||
|
|
||||||
|
await ethProvider.close()
|
||||||
|
|
||||||
body
|
body
|
||||||
|
|
||||||
export asynctest
|
export asynctest
|
||||||
|
|||||||
@ -37,7 +37,7 @@ type
|
|||||||
|
|
||||||
MultiNodeSuiteError = object of CatchableError
|
MultiNodeSuiteError = object of CatchableError
|
||||||
|
|
||||||
const jsonRpcProviderUrl* = "http://127.0.0.1:8545"
|
const jsonRpcProviderUrl* = "ws://localhost:8545"
|
||||||
|
|
||||||
proc raiseMultiNodeSuiteError(msg: string) =
|
proc raiseMultiNodeSuiteError(msg: string) =
|
||||||
raise newException(MultiNodeSuiteError, msg)
|
raise newException(MultiNodeSuiteError, msg)
|
||||||
@ -270,6 +270,8 @@ template multinodesuite*(name: string, body: untyped) =
|
|||||||
else:
|
else:
|
||||||
discard await send(ethProvider, "evm_revert", @[snapshot])
|
discard await send(ethProvider, "evm_revert", @[snapshot])
|
||||||
|
|
||||||
|
await ethProvider.close()
|
||||||
|
|
||||||
running = @[]
|
running = @[]
|
||||||
|
|
||||||
template failAndTeardownOnError(message: string, tryBody: untyped) =
|
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
|
# Workaround for https://github.com/NomicFoundation/hardhat/issues/2053
|
||||||
# Do not use websockets, but use http and polling to stop subscriptions
|
# Do not use websockets, but use http and polling to stop subscriptions
|
||||||
# from being removed after 5 minutes
|
# from being removed after 5 minutes
|
||||||
ethProvider = JsonRpcProvider.new(
|
ethProvider = JsonRpcProvider.new(jsonRpcProviderUrl)
|
||||||
jsonRpcProviderUrl, pollingInterval = chronos.milliseconds(100)
|
|
||||||
)
|
|
||||||
# if hardhat was NOT started by the test, take a snapshot so it can be
|
# if hardhat was NOT started by the test, take a snapshot so it can be
|
||||||
# reverted in the test teardown
|
# reverted in the test teardown
|
||||||
if nodeConfigs.hardhat.isNone:
|
if nodeConfigs.hardhat.isNone:
|
||||||
|
|||||||
@ -14,7 +14,7 @@ suite "tools/cirdl":
|
|||||||
test "circuit download tool":
|
test "circuit download tool":
|
||||||
let
|
let
|
||||||
circuitPath = "testcircuitpath"
|
circuitPath = "testcircuitpath"
|
||||||
rpcEndpoint = "http://127.0.0.1:8545"
|
rpcEndpoint = "ws://localhost:8545"
|
||||||
marketplaceAddress = Marketplace.address
|
marketplaceAddress = Marketplace.address
|
||||||
|
|
||||||
discard existsOrCreateDir(circuitPath)
|
discard existsOrCreateDir(circuitPath)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user