allows to choose a different RPC provider for a given integration test suite
This commit is contained in:
parent
9906f2f990
commit
98e3378900
|
@ -11,9 +11,17 @@ import ../contracts/deployment
|
||||||
export mp
|
export mp
|
||||||
export multinodes
|
export multinodes
|
||||||
|
|
||||||
template marketplacesuite*(name: string, body: untyped) =
|
template marketplacesuite*(name: string,
|
||||||
|
body: untyped) =
|
||||||
|
marketplacesuiteWithProviderUrl name, "http://localhost:8545":
|
||||||
|
body
|
||||||
|
|
||||||
multinodesuite name:
|
# we can't just overload the name and use marketplacesuite here
|
||||||
|
# see: https://github.com/nim-lang/Nim/issues/14827
|
||||||
|
template marketplacesuiteWithProviderUrl*(name: string,
|
||||||
|
jsonRpcProviderUrl: string, body: untyped) =
|
||||||
|
|
||||||
|
multinodesuiteWithProviderUrl name, jsonRpcProviderUrl:
|
||||||
|
|
||||||
var marketplace {.inject, used.}: Marketplace
|
var marketplace {.inject, used.}: Marketplace
|
||||||
var period: uint64
|
var period: uint64
|
||||||
|
|
|
@ -58,7 +58,35 @@ proc nextFreePort(startPort: int): Future[int] {.async.} =
|
||||||
trace "port is not free", port
|
trace "port is not free", port
|
||||||
inc port
|
inc port
|
||||||
|
|
||||||
|
# Following the problem described here:
|
||||||
|
# https://github.com/NomicFoundation/hardhat/issues/2053
|
||||||
|
# It may be desireable to use http RPC provider.
|
||||||
|
# This turns out to be equally important in tests where
|
||||||
|
# subscriptions get wiped out after 5mins even when
|
||||||
|
# a new block is mined.
|
||||||
|
# For this reason, we are using http provider here as the default.
|
||||||
|
# To use a different provider in your test, you may use
|
||||||
|
# multinodesuiteWithProviderUrl template in your tests.
|
||||||
|
# The nodes are still using the default provider (which is ws://localhost:8545).
|
||||||
|
# If you want to use http provider url in the nodes, you can
|
||||||
|
# use withEthProvider config modifiers in the node configs
|
||||||
|
# to set the desired provider url. E.g.:
|
||||||
|
# NodeConfigs(
|
||||||
|
# hardhat:
|
||||||
|
# HardhatConfig.none,
|
||||||
|
# clients:
|
||||||
|
# CodexConfigs.init(nodes=1)
|
||||||
|
# .withEthProvider("http://localhost:8545")
|
||||||
|
# .some,
|
||||||
|
# ...
|
||||||
template multinodesuite*(name: string, body: untyped) =
|
template multinodesuite*(name: string, body: untyped) =
|
||||||
|
multinodesuiteWithProviderUrl name, "http://localhost:8545":
|
||||||
|
body
|
||||||
|
|
||||||
|
# we can't just overload the name and use multinodesuite here
|
||||||
|
# see: https://github.com/nim-lang/Nim/issues/14827
|
||||||
|
template multinodesuiteWithProviderUrl*(name: string, jsonRpcProviderUrl: string,
|
||||||
|
body: untyped) =
|
||||||
|
|
||||||
asyncchecksuite name:
|
asyncchecksuite name:
|
||||||
|
|
||||||
|
@ -261,10 +289,7 @@ template multinodesuite*(name: string, body: untyped) =
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Workaround for https://github.com/NomicFoundation/hardhat/issues/2053
|
ethProvider = JsonRpcProvider.new(jsonRpcProviderUrl)
|
||||||
# Do not use websockets, but use http and polling to stop subscriptions
|
|
||||||
# from being removed after 5 minutes
|
|
||||||
ethProvider = JsonRpcProvider.new("http://localhost:8545")
|
|
||||||
# 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:
|
||||||
|
|
|
@ -15,16 +15,21 @@ export logutils
|
||||||
logScope:
|
logScope:
|
||||||
topics = "integration test validation"
|
topics = "integration test validation"
|
||||||
|
|
||||||
template eventuallyS*(expression: untyped, timeout=10, step = 5,
|
template eventuallyS(expression: untyped, timeout=10, step = 5,
|
||||||
cancelExpression: untyped = false): bool =
|
cancelExpression: untyped = false): bool =
|
||||||
bind Moment, now, seconds
|
bind Moment, now, seconds
|
||||||
|
|
||||||
proc eventuallyS: Future[bool] {.async.} =
|
proc eventuallyS: Future[bool] {.async.} =
|
||||||
let endTime = Moment.now() + timeout.seconds
|
let endTime = Moment.now() + timeout.seconds
|
||||||
var i = 0
|
var i = 0
|
||||||
|
var secondsElapsed = 0
|
||||||
while not expression:
|
while not expression:
|
||||||
inc i
|
inc i
|
||||||
# echo (i*step).seconds
|
secondsElapsed = i*step
|
||||||
|
# echo secondsElapsed.seconds
|
||||||
|
if secondsElapsed mod 180 == 0:
|
||||||
|
await stopTrackingEvents()
|
||||||
|
await marketplace.startTrackingEvents()
|
||||||
if endTime < Moment.now():
|
if endTime < Moment.now():
|
||||||
return false
|
return false
|
||||||
if cancelExpression:
|
if cancelExpression:
|
||||||
|
@ -34,13 +39,11 @@ template eventuallyS*(expression: untyped, timeout=10, step = 5,
|
||||||
|
|
||||||
await eventuallyS()
|
await eventuallyS()
|
||||||
|
|
||||||
marketplacesuite "Validation":
|
marketplacesuiteWithProviderUrl "Validation", "ws://localhost:8545":
|
||||||
let nodes = 3
|
let nodes = 3
|
||||||
let tolerance = 1
|
let tolerance = 1
|
||||||
let proofProbability = 1
|
let proofProbability = 1
|
||||||
|
|
||||||
# var slotsAndRequests = initTable[string, seq[UInt256]]()
|
|
||||||
# var events = initTable[string, seq[ref MarketplaceEvent]]()
|
|
||||||
var events = {
|
var events = {
|
||||||
$SlotFilled: newSeq[ref MarketplaceEvent](),
|
$SlotFilled: newSeq[ref MarketplaceEvent](),
|
||||||
$SlotFreed: newSeq[ref MarketplaceEvent](),
|
$SlotFreed: newSeq[ref MarketplaceEvent](),
|
||||||
|
@ -107,7 +110,7 @@ marketplacesuite "Validation":
|
||||||
slotsFailed.incl(slotId)
|
slotsFailed.incl(slotId)
|
||||||
|
|
||||||
debug "slots failed", slotsFailed = slotsFailed, slotsNotFreed = slotsNotFreed
|
debug "slots failed", slotsFailed = slotsFailed, slotsNotFreed = slotsNotFreed
|
||||||
check slotsNotFreed == slotsFailed
|
check slotsNotFreed == slotsFailed
|
||||||
|
|
||||||
test "validator marks proofs as missing when using validation groups", NodeConfigs(
|
test "validator marks proofs as missing when using validation groups", NodeConfigs(
|
||||||
# Uncomment to start Hardhat automatically, typically so logs can be inspected locally
|
# Uncomment to start Hardhat automatically, typically so logs can be inspected locally
|
||||||
|
|
Loading…
Reference in New Issue