Use http subscriptions instead of websocket for tests
To work around this issue when subscriptions are inactive for more than 5 minutes: https://github.com/NomicFoundation/hardhat/issues/2053 Use 100 millisecond polling; default polling interval of 4 seconds is too close to the 5 second timeout for `check eventually`.
This commit is contained in:
parent
d7ae8b734a
commit
ce6d5798a7
|
@ -30,7 +30,7 @@ ethersuite "On-Chain Clock":
|
||||||
let waiting = clock.waitUntil(future)
|
let waiting = clock.waitUntil(future)
|
||||||
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")
|
||||||
check await waiting.withTimeout(chronos.milliseconds(100))
|
check await waiting.withTimeout(chronos.milliseconds(500))
|
||||||
|
|
||||||
test "can wait until a certain time is reached by the wall-clock":
|
test "can wait until a certain time is reached by the wall-clock":
|
||||||
let future = clock.now() + 1 # seconds
|
let future = clock.now() + 1 # seconds
|
||||||
|
|
|
@ -114,8 +114,7 @@ ethersuite "On-Chain Market":
|
||||||
receivedAsks.add(ask)
|
receivedAsks.add(ask)
|
||||||
let subscription = await market.subscribeRequests(onRequest)
|
let subscription = await market.subscribeRequests(onRequest)
|
||||||
await market.requestStorage(request)
|
await market.requestStorage(request)
|
||||||
check receivedIds == @[request.id]
|
check eventually receivedIds == @[request.id] and receivedAsks == @[request.ask]
|
||||||
check receivedAsks == @[request.ask]
|
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "supports filling of slots":
|
test "supports filling of slots":
|
||||||
|
@ -181,8 +180,7 @@ ethersuite "On-Chain Market":
|
||||||
let subscription = await market.subscribeSlotFilled(onSlotFilled)
|
let subscription = await market.subscribeSlotFilled(onSlotFilled)
|
||||||
await market.reserveSlot(request.id, slotIndex)
|
await market.reserveSlot(request.id, slotIndex)
|
||||||
await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral)
|
await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral)
|
||||||
check receivedIds == @[request.id]
|
check eventually receivedIds == @[request.id] and receivedSlotIndices == @[slotIndex]
|
||||||
check receivedSlotIndices == @[slotIndex]
|
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "subscribes only to a certain slot":
|
test "subscribes only to a certain slot":
|
||||||
|
@ -194,10 +192,9 @@ ethersuite "On-Chain Market":
|
||||||
let subscription = await market.subscribeSlotFilled(request.id, slotIndex, onSlotFilled)
|
let subscription = await market.subscribeSlotFilled(request.id, slotIndex, onSlotFilled)
|
||||||
await market.reserveSlot(request.id, otherSlot)
|
await market.reserveSlot(request.id, otherSlot)
|
||||||
await market.fillSlot(request.id, otherSlot, proof, request.ask.collateral)
|
await market.fillSlot(request.id, otherSlot, proof, request.ask.collateral)
|
||||||
check receivedSlotIndices.len == 0
|
|
||||||
await market.reserveSlot(request.id, slotIndex)
|
await market.reserveSlot(request.id, slotIndex)
|
||||||
await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral)
|
await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral)
|
||||||
check receivedSlotIndices == @[slotIndex]
|
check eventually receivedSlotIndices == @[slotIndex]
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "supports slot freed subscriptions":
|
test "supports slot freed subscriptions":
|
||||||
|
@ -211,8 +208,7 @@ ethersuite "On-Chain Market":
|
||||||
receivedIdxs.add(idx)
|
receivedIdxs.add(idx)
|
||||||
let subscription = await market.subscribeSlotFreed(onSlotFreed)
|
let subscription = await market.subscribeSlotFreed(onSlotFreed)
|
||||||
await market.freeSlot(slotId(request.id, slotIndex))
|
await market.freeSlot(slotId(request.id, slotIndex))
|
||||||
check receivedRequestIds == @[request.id]
|
check eventually receivedRequestIds == @[request.id] and receivedIdxs == @[slotIndex]
|
||||||
check receivedIdxs == @[slotIndex]
|
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "supports slot reservations full subscriptions":
|
test "supports slot reservations full subscriptions":
|
||||||
|
@ -235,8 +231,7 @@ ethersuite "On-Chain Market":
|
||||||
switchAccount(account3)
|
switchAccount(account3)
|
||||||
await market.reserveSlot(request.id, slotIndex)
|
await market.reserveSlot(request.id, slotIndex)
|
||||||
|
|
||||||
check receivedRequestIds == @[request.id]
|
check eventually receivedRequestIds == @[request.id] and receivedIdxs == @[slotIndex]
|
||||||
check receivedIdxs == @[slotIndex]
|
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "support fulfillment subscriptions":
|
test "support fulfillment subscriptions":
|
||||||
|
@ -248,7 +243,7 @@ ethersuite "On-Chain Market":
|
||||||
for slotIndex in 0..<request.ask.slots:
|
for slotIndex in 0..<request.ask.slots:
|
||||||
await market.reserveSlot(request.id, slotIndex.u256)
|
await market.reserveSlot(request.id, slotIndex.u256)
|
||||||
await market.fillSlot(request.id, slotIndex.u256, proof, request.ask.collateral)
|
await market.fillSlot(request.id, slotIndex.u256, proof, request.ask.collateral)
|
||||||
check receivedIds == @[request.id]
|
check eventually receivedIds == @[request.id]
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "subscribes only to fulfillment of a certain request":
|
test "subscribes only to fulfillment of a certain request":
|
||||||
|
@ -271,7 +266,7 @@ ethersuite "On-Chain Market":
|
||||||
await market.reserveSlot(otherRequest.id, slotIndex.u256)
|
await market.reserveSlot(otherRequest.id, slotIndex.u256)
|
||||||
await market.fillSlot(otherRequest.id, slotIndex.u256, proof, otherRequest.ask.collateral)
|
await market.fillSlot(otherRequest.id, slotIndex.u256, proof, otherRequest.ask.collateral)
|
||||||
|
|
||||||
check receivedIds == @[request.id]
|
check eventually receivedIds == @[request.id]
|
||||||
|
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
|
@ -285,7 +280,7 @@ ethersuite "On-Chain Market":
|
||||||
|
|
||||||
await advanceToCancelledRequest(request)
|
await advanceToCancelledRequest(request)
|
||||||
await market.withdrawFunds(request.id)
|
await market.withdrawFunds(request.id)
|
||||||
check receivedIds == @[request.id]
|
check eventually receivedIds == @[request.id]
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "support request failed subscriptions":
|
test "support request failed subscriptions":
|
||||||
|
@ -309,7 +304,7 @@ ethersuite "On-Chain Market":
|
||||||
let missingPeriod = periodicity.periodOf(await ethProvider.currentTime())
|
let missingPeriod = periodicity.periodOf(await ethProvider.currentTime())
|
||||||
await advanceToNextPeriod()
|
await advanceToNextPeriod()
|
||||||
discard await marketplace.markProofAsMissing(slotId, missingPeriod)
|
discard await marketplace.markProofAsMissing(slotId, missingPeriod)
|
||||||
check receivedIds == @[request.id]
|
check eventually receivedIds == @[request.id]
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "subscribes only to a certain request cancellation":
|
test "subscribes only to a certain request cancellation":
|
||||||
|
@ -325,9 +320,8 @@ ethersuite "On-Chain Market":
|
||||||
let subscription = await market.subscribeRequestCancelled(request.id, onRequestCancelled)
|
let subscription = await market.subscribeRequestCancelled(request.id, onRequestCancelled)
|
||||||
await advanceToCancelledRequest(otherRequest) # shares expiry with otherRequest
|
await advanceToCancelledRequest(otherRequest) # shares expiry with otherRequest
|
||||||
await market.withdrawFunds(otherRequest.id)
|
await market.withdrawFunds(otherRequest.id)
|
||||||
check receivedIds.len == 0
|
|
||||||
await market.withdrawFunds(request.id)
|
await market.withdrawFunds(request.id)
|
||||||
check receivedIds == @[request.id]
|
check eventually receivedIds == @[request.id]
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "supports proof submission subscriptions":
|
test "supports proof submission subscriptions":
|
||||||
|
@ -340,7 +334,7 @@ ethersuite "On-Chain Market":
|
||||||
receivedIds.add(id)
|
receivedIds.add(id)
|
||||||
let subscription = await market.subscribeProofSubmission(onProofSubmission)
|
let subscription = await market.subscribeProofSubmission(onProofSubmission)
|
||||||
await market.submitProof(slotId(request.id, slotIndex), proof)
|
await market.submitProof(slotId(request.id, slotIndex), proof)
|
||||||
check receivedIds == @[slotId(request.id, slotIndex)]
|
check eventually receivedIds == @[slotId(request.id, slotIndex)]
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
test "request is none when unknown":
|
test "request is none when unknown":
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import std/json
|
import std/json
|
||||||
import pkg/ethers
|
import pkg/ethers
|
||||||
|
import pkg/chronos
|
||||||
|
|
||||||
import ./asynctest
|
import ./asynctest
|
||||||
import ./checktest
|
import ./checktest
|
||||||
|
@ -16,11 +17,15 @@ template ethersuite*(name, body) =
|
||||||
var snapshot: JsonNode
|
var snapshot: JsonNode
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
ethProvider = JsonRpcProvider.new("ws://localhost:8545")
|
ethProvider = JsonRpcProvider.new(
|
||||||
|
"http://localhost: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])
|
||||||
|
|
||||||
body
|
body
|
||||||
|
|
|
@ -196,6 +196,7 @@ template multinodesuite*(name: string, body: untyped) =
|
||||||
proc startClientNode(conf: CodexConfig): Future[NodeProcess] {.async.} =
|
proc startClientNode(conf: CodexConfig): Future[NodeProcess] {.async.} =
|
||||||
let clientIdx = clients().len
|
let clientIdx = clients().len
|
||||||
var config = conf
|
var config = conf
|
||||||
|
config.addCliOption(StartUpCmd.persistence, "--eth-provider", "http://localhost:8545")
|
||||||
config.addCliOption(StartUpCmd.persistence, "--eth-account", $accounts[running.len])
|
config.addCliOption(StartUpCmd.persistence, "--eth-account", $accounts[running.len])
|
||||||
return await newCodexProcess(clientIdx, config, Role.Client)
|
return await newCodexProcess(clientIdx, config, Role.Client)
|
||||||
|
|
||||||
|
@ -203,6 +204,7 @@ template multinodesuite*(name: string, body: untyped) =
|
||||||
let providerIdx = providers().len
|
let providerIdx = providers().len
|
||||||
var config = conf
|
var config = conf
|
||||||
config.addCliOption("--bootstrap-node", bootstrap)
|
config.addCliOption("--bootstrap-node", bootstrap)
|
||||||
|
config.addCliOption(StartUpCmd.persistence, "--eth-provider", "http://localhost:8545")
|
||||||
config.addCliOption(StartUpCmd.persistence, "--eth-account", $accounts[running.len])
|
config.addCliOption(StartUpCmd.persistence, "--eth-account", $accounts[running.len])
|
||||||
config.addCliOption(PersistenceCmd.prover, "--circom-r1cs",
|
config.addCliOption(PersistenceCmd.prover, "--circom-r1cs",
|
||||||
"vendor/codex-contracts-eth/verifier/networks/hardhat/proof_main.r1cs")
|
"vendor/codex-contracts-eth/verifier/networks/hardhat/proof_main.r1cs")
|
||||||
|
@ -217,6 +219,7 @@ template multinodesuite*(name: string, body: untyped) =
|
||||||
let validatorIdx = validators().len
|
let validatorIdx = validators().len
|
||||||
var config = conf
|
var config = conf
|
||||||
config.addCliOption("--bootstrap-node", bootstrap)
|
config.addCliOption("--bootstrap-node", bootstrap)
|
||||||
|
config.addCliOption(StartUpCmd.persistence, "--eth-provider", "http://localhost:8545")
|
||||||
config.addCliOption(StartUpCmd.persistence, "--eth-account", $accounts[running.len])
|
config.addCliOption(StartUpCmd.persistence, "--eth-account", $accounts[running.len])
|
||||||
config.addCliOption(StartUpCmd.persistence, "--validator")
|
config.addCliOption(StartUpCmd.persistence, "--validator")
|
||||||
|
|
||||||
|
@ -264,7 +267,10 @@ 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("http://localhost:8545")
|
ethProvider = JsonRpcProvider.new(
|
||||||
|
"http://localhost:8545",
|
||||||
|
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:
|
||||||
|
|
|
@ -43,6 +43,7 @@ template twonodessuite*(name: string, debug1, debug2: string, body) =
|
||||||
"--circom-r1cs=tests/circuits/fixtures/proof_main.r1cs",
|
"--circom-r1cs=tests/circuits/fixtures/proof_main.r1cs",
|
||||||
"--circom-wasm=tests/circuits/fixtures/proof_main.wasm",
|
"--circom-wasm=tests/circuits/fixtures/proof_main.wasm",
|
||||||
"--circom-zkey=tests/circuits/fixtures/proof_main.zkey",
|
"--circom-zkey=tests/circuits/fixtures/proof_main.zkey",
|
||||||
|
"--eth-provider=http://localhost:8545",
|
||||||
"--eth-account=" & $account1
|
"--eth-account=" & $account1
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ template twonodessuite*(name: string, debug1, debug2: string, body) =
|
||||||
"--circom-r1cs=tests/circuits/fixtures/proof_main.r1cs",
|
"--circom-r1cs=tests/circuits/fixtures/proof_main.r1cs",
|
||||||
"--circom-wasm=tests/circuits/fixtures/proof_main.wasm",
|
"--circom-wasm=tests/circuits/fixtures/proof_main.wasm",
|
||||||
"--circom-zkey=tests/circuits/fixtures/proof_main.zkey",
|
"--circom-zkey=tests/circuits/fixtures/proof_main.zkey",
|
||||||
|
"--eth-provider=http://localhost:8545",
|
||||||
"--eth-account=" & $account2
|
"--eth-account=" & $account2
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ suite "tools/cirdl":
|
||||||
test "circuit download tool":
|
test "circuit download tool":
|
||||||
let
|
let
|
||||||
circuitPath = "testcircuitpath"
|
circuitPath = "testcircuitpath"
|
||||||
rpcEndpoint = "ws://localhost:8545"
|
rpcEndpoint = "http://localhost:8545"
|
||||||
marketplaceAddress = Marketplace.address
|
marketplaceAddress = Marketplace.address
|
||||||
|
|
||||||
discard existsOrCreateDir(circuitPath)
|
discard existsOrCreateDir(circuitPath)
|
||||||
|
|
Loading…
Reference in New Issue