Get balance for each provider, bump ethers

This commit is contained in:
Eric 2023-10-25 12:47:55 +11:00
parent 10decd2f28
commit bc0652aeb6
No known key found for this signature in database
4 changed files with 65 additions and 32 deletions

View File

@ -80,8 +80,11 @@ proc start(node: HardhatProcess) =
proc waitUntilOutput*(node: HardhatProcess, output: string) =
if not node.started.isNil:
waitFor node.started.wait(5000.milliseconds)
return
try:
waitFor node.started.wait(5000.milliseconds)
return
except AsyncTimeoutError:
discard # should raiseAssert below
else:
for line in node.process.outputStream.lines:
if line.contains(output):

View File

@ -22,6 +22,7 @@ type
RunningNode* = ref object
role*: Role
node*: NodeProcess
address*: ?Address
StartNodes* = object
clients*: StartNodeConfig
providers*: StartNodeConfig
@ -263,17 +264,29 @@ template multinodesuite*(name: string,
for i in 0..<startNodes.clients.numNodes:
let node = startClientNode()
running.add RunningNode(role: Role.Client, node: node)
running.add RunningNode(
role: Role.Client,
node: node,
address: some accounts[running.len]
)
if i == 0:
bootstrap = node.client.info()["spr"].getStr()
for i in 0..<startNodes.providers.numNodes:
let node = startProviderNode()
running.add RunningNode(role: Role.Provider, node: node)
running.add RunningNode(
role: Role.Provider,
node: node,
address: some accounts[running.len]
)
for i in 0..<startNodes.validators.numNodes:
let node = startValidatorNode()
running.add RunningNode(role: Role.Validator, node: node)
running.add RunningNode(
role: Role.Validator,
node: node,
address: some accounts[running.len]
)
teardown:
for r in running:

View File

@ -251,7 +251,7 @@ multinodesuite "Simulate invalid proofs",
.withLogTopics("node"),
providers: StartNodeConfig()
.nodes(2)
.nodes(5)
.simulateProofFailuresFor(providerIdx=0, failEveryNProofs=2)
.debug()
.withLogFile()
@ -280,9 +280,12 @@ multinodesuite "Simulate invalid proofs",
var marketplace: Marketplace
var period: uint64
var token: Erc20Token
setup:
marketplace = Marketplace.new(Marketplace.address, provider)
marketplace = Marketplace.new(Marketplace.address, provider.getSigner())
let tokenAddress = await marketplace.token()
token = Erc20Token.new(tokenAddress, provider.getSigner())
let config = await marketplace.config()
period = config.proofs.period.truncate(uint64)
@ -300,36 +303,35 @@ multinodesuite "Simulate invalid proofs",
let endOfPeriod = periodicity.periodEnd(currentPeriod)
await provider.advanceTimeTo(endOfPeriod + 1)
proc waitUntilPurchaseIsStarted(proofProbability: uint64 = 1,
duration: uint64 = 12.periods,
expiry: uint64 = 4.periods): Future[PurchaseId] {.async.} =
proc requestStorage(proofProbability: uint64 = 1,
duration: uint64 = 12.periods,
expiry: uint64 = 4.periods): Future[PurchaseId] {.async.} =
if clients().len < 1 or providers().len < 2:
raiseAssert("must start at least one client and two providers")
let client0 = clients()[0].node.client
let storageProvider0 = providers()[0].node.client
let storageProvider1 = providers()[1].node.client
# post availability to each provider
for i in 0..<providers().len:
let provider = providers()[i].node.client
discard storageProvider0.postAvailability(
size=0xFFFFF.u256,
duration=duration.u256,
minPrice=300.u256,
maxCollateral=200.u256
)
discard storageProvider1.postAvailability(
size=0xFFFFF.u256,
duration=duration.u256,
minPrice=300.u256,
maxCollateral=200.u256
)
discard provider.postAvailability(
size=261888.u256, # should match 1 slot only
duration=duration.u256,
minPrice=300.u256,
maxCollateral=200.u256
)
let client0 = clients()[0].node.client
let rng = rng.Rng.instance()
let chunker = RandomChunker.new(rng, size = DefaultBlockSize * 2, chunkSize = DefaultBlockSize * 2)
let data = await chunker.getBytes()
let cid = client0.upload(byteutils.toHex(data)).get
let expiry = (await provider.currentTime()) + expiry.u256
# avoid timing issues by filling the slot at the start of the next period
await advanceToNextPeriod()
let id = client0.requestStorage(
cid,
expiry=expiry,
@ -339,27 +341,42 @@ multinodesuite "Simulate invalid proofs",
reward=400.u256,
nodes=2'u
).get
check eventually client0.purchaseStateIs(id, "started")
return id
proc waitUntilPurchaseIsFinished(purchaseId: PurchaseId, duration: int) {.async.} =
let client = clients()[0].node.client
check eventually(client.purchaseStateIs(purchaseId, "finished"), duration * 1000)
# TODO: these are very loose tests in that they are not testing EXACTLY how
# proofs were marked as missed by the validator. These tests should be
# tightened so that they are showing, as an integration test, that specific
# proofs are being marked as missed by the validator.
test "provider that submits invalid proofs is paid out less":
let totalProofs = 7
let clientRestClient = clients()[0].node.client
let provider0 = providers()[0]
let provider1 = providers()[1]
let totalProofs = 25
let purchaseId = await waitUntilPurchaseIsStarted(duration=totalProofs.periods)
let purchaseId = await requestStorage(duration=totalProofs.periods)
check eventually clientRestClient.purchaseStateIs(purchaseId, "started")
# await waitUntilPurchaseIsFinished(purchaseId, duration=totalProofs.periods.int)
let client = clients()[0].node.client
let duration = totalProofs.periods.int
check eventually(client.purchaseStateIs(purchaseId, "finished"), duration * 1000)
let duration = (totalProofs.periods.int + 2) * 10 # 10 seconds per period
check eventually(
clientRestClient.purchaseStateIs(purchaseId, "finished"), duration * 1000
)
check eventually (
(await token.balanceOf(!provider1.address)) >
(await token.balanceOf(!provider0.address))
)
echo "provider1 balance: ", (await token.balanceOf(!provider1.address))
echo "provider0 balance: ", (await token.balanceOf(!provider0.address))
# var slotWasFreed = false
# proc onSlotFreed(event: SlotFreed) =

2
vendor/nim-json-rpc vendored

@ -1 +1 @@
Subproject commit afc958db67ec34cba4c528348d9ce712aee488d6
Subproject commit 60c4c9b5f28b530d5d89fd14c337af1d86390a82