allows to choose a different RPC provider for a given integration test suite

This commit is contained in:
Marcin Czenko 2024-10-22 16:03:55 +02:00
parent ba12764721
commit a91c76f235
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
3 changed files with 48 additions and 12 deletions

View File

@ -11,9 +11,17 @@ import ../contracts/deployment
export mp
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 period: uint64

View File

@ -58,7 +58,35 @@ proc nextFreePort(startPort: int): Future[int] {.async.} =
trace "port is not free", 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) =
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:
@ -261,10 +289,7 @@ template multinodesuite*(name: string, body: untyped) =
quit(1)
try:
# 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("http://localhost:8545")
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:

View File

@ -15,16 +15,21 @@ export logutils
logScope:
topics = "integration test validation"
template eventuallyS*(expression: untyped, timeout=10, step = 5,
template eventuallyS(expression: untyped, timeout=10, step = 5,
cancelExpression: untyped = false): bool =
bind Moment, now, seconds
proc eventuallyS: Future[bool] {.async.} =
let endTime = Moment.now() + timeout.seconds
var i = 0
var secondsElapsed = 0
while not expression:
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():
return false
if cancelExpression:
@ -34,13 +39,11 @@ template eventuallyS*(expression: untyped, timeout=10, step = 5,
await eventuallyS()
marketplacesuite "Validation":
marketplacesuiteWithProviderUrl "Validation", "ws://localhost:8545":
let nodes = 3
let tolerance = 1
let proofProbability = 1
# var slotsAndRequests = initTable[string, seq[UInt256]]()
# var events = initTable[string, seq[ref MarketplaceEvent]]()
var events = {
$SlotFilled: newSeq[ref MarketplaceEvent](),
$SlotFreed: newSeq[ref MarketplaceEvent](),
@ -107,7 +110,7 @@ marketplacesuite "Validation":
slotsFailed.incl(slotId)
debug "slots failed", slotsFailed = slotsFailed, slotsNotFreed = slotsNotFreed
check slotsNotFreed == slotsFailed
check slotsNotFreed == slotsFailed
test "validator marks proofs as missing when using validation groups", NodeConfigs(
# Uncomment to start Hardhat automatically, typically so logs can be inspected locally