Skip to content

Commit

Permalink
allows to choose a different RPC provider for a given integration tes…
Browse files Browse the repository at this point in the history
…t suite
  • Loading branch information
marcinczenko committed Nov 24, 2024
1 parent ba12764 commit a91c76f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
12 changes: 10 additions & 2 deletions tests/integration/marketplacesuite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

# 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) =

multinodesuite name:
multinodesuiteWithProviderUrl name, jsonRpcProviderUrl:

var marketplace {.inject, used.}: Marketplace
var period: uint64
Expand Down
33 changes: 29 additions & 4 deletions tests/integration/multinodes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down
15 changes: 9 additions & 6 deletions tests/integration/testvalidator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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](),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a91c76f

Please sign in to comment.