mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-04 09:39:46 +00:00
Get balance for each provider, bump ethers
This commit is contained in:
parent
10decd2f28
commit
bc0652aeb6
@ -80,8 +80,11 @@ proc start(node: HardhatProcess) =
|
|||||||
|
|
||||||
proc waitUntilOutput*(node: HardhatProcess, output: string) =
|
proc waitUntilOutput*(node: HardhatProcess, output: string) =
|
||||||
if not node.started.isNil:
|
if not node.started.isNil:
|
||||||
waitFor node.started.wait(5000.milliseconds)
|
try:
|
||||||
return
|
waitFor node.started.wait(5000.milliseconds)
|
||||||
|
return
|
||||||
|
except AsyncTimeoutError:
|
||||||
|
discard # should raiseAssert below
|
||||||
else:
|
else:
|
||||||
for line in node.process.outputStream.lines:
|
for line in node.process.outputStream.lines:
|
||||||
if line.contains(output):
|
if line.contains(output):
|
||||||
|
|||||||
@ -22,6 +22,7 @@ type
|
|||||||
RunningNode* = ref object
|
RunningNode* = ref object
|
||||||
role*: Role
|
role*: Role
|
||||||
node*: NodeProcess
|
node*: NodeProcess
|
||||||
|
address*: ?Address
|
||||||
StartNodes* = object
|
StartNodes* = object
|
||||||
clients*: StartNodeConfig
|
clients*: StartNodeConfig
|
||||||
providers*: StartNodeConfig
|
providers*: StartNodeConfig
|
||||||
@ -263,17 +264,29 @@ template multinodesuite*(name: string,
|
|||||||
|
|
||||||
for i in 0..<startNodes.clients.numNodes:
|
for i in 0..<startNodes.clients.numNodes:
|
||||||
let node = startClientNode()
|
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:
|
if i == 0:
|
||||||
bootstrap = node.client.info()["spr"].getStr()
|
bootstrap = node.client.info()["spr"].getStr()
|
||||||
|
|
||||||
for i in 0..<startNodes.providers.numNodes:
|
for i in 0..<startNodes.providers.numNodes:
|
||||||
let node = startProviderNode()
|
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:
|
for i in 0..<startNodes.validators.numNodes:
|
||||||
let node = startValidatorNode()
|
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:
|
teardown:
|
||||||
for r in running:
|
for r in running:
|
||||||
|
|||||||
@ -251,7 +251,7 @@ multinodesuite "Simulate invalid proofs",
|
|||||||
.withLogTopics("node"),
|
.withLogTopics("node"),
|
||||||
|
|
||||||
providers: StartNodeConfig()
|
providers: StartNodeConfig()
|
||||||
.nodes(2)
|
.nodes(5)
|
||||||
.simulateProofFailuresFor(providerIdx=0, failEveryNProofs=2)
|
.simulateProofFailuresFor(providerIdx=0, failEveryNProofs=2)
|
||||||
.debug()
|
.debug()
|
||||||
.withLogFile()
|
.withLogFile()
|
||||||
@ -280,9 +280,12 @@ multinodesuite "Simulate invalid proofs",
|
|||||||
|
|
||||||
var marketplace: Marketplace
|
var marketplace: Marketplace
|
||||||
var period: uint64
|
var period: uint64
|
||||||
|
var token: Erc20Token
|
||||||
|
|
||||||
setup:
|
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()
|
let config = await marketplace.config()
|
||||||
period = config.proofs.period.truncate(uint64)
|
period = config.proofs.period.truncate(uint64)
|
||||||
|
|
||||||
@ -300,36 +303,35 @@ multinodesuite "Simulate invalid proofs",
|
|||||||
let endOfPeriod = periodicity.periodEnd(currentPeriod)
|
let endOfPeriod = periodicity.periodEnd(currentPeriod)
|
||||||
await provider.advanceTimeTo(endOfPeriod + 1)
|
await provider.advanceTimeTo(endOfPeriod + 1)
|
||||||
|
|
||||||
proc waitUntilPurchaseIsStarted(proofProbability: uint64 = 1,
|
proc requestStorage(proofProbability: uint64 = 1,
|
||||||
duration: uint64 = 12.periods,
|
duration: uint64 = 12.periods,
|
||||||
expiry: uint64 = 4.periods): Future[PurchaseId] {.async.} =
|
expiry: uint64 = 4.periods): Future[PurchaseId] {.async.} =
|
||||||
|
|
||||||
if clients().len < 1 or providers().len < 2:
|
if clients().len < 1 or providers().len < 2:
|
||||||
raiseAssert("must start at least one client and two providers")
|
raiseAssert("must start at least one client and two providers")
|
||||||
|
|
||||||
let client0 = clients()[0].node.client
|
# post availability to each provider
|
||||||
let storageProvider0 = providers()[0].node.client
|
for i in 0..<providers().len:
|
||||||
let storageProvider1 = providers()[1].node.client
|
let provider = providers()[i].node.client
|
||||||
|
|
||||||
discard storageProvider0.postAvailability(
|
discard provider.postAvailability(
|
||||||
size=0xFFFFF.u256,
|
size=261888.u256, # should match 1 slot only
|
||||||
duration=duration.u256,
|
duration=duration.u256,
|
||||||
minPrice=300.u256,
|
minPrice=300.u256,
|
||||||
maxCollateral=200.u256
|
maxCollateral=200.u256
|
||||||
)
|
)
|
||||||
discard storageProvider1.postAvailability(
|
|
||||||
size=0xFFFFF.u256,
|
|
||||||
duration=duration.u256,
|
let client0 = clients()[0].node.client
|
||||||
minPrice=300.u256,
|
|
||||||
maxCollateral=200.u256
|
|
||||||
)
|
|
||||||
let rng = rng.Rng.instance()
|
let rng = rng.Rng.instance()
|
||||||
let chunker = RandomChunker.new(rng, size = DefaultBlockSize * 2, chunkSize = DefaultBlockSize * 2)
|
let chunker = RandomChunker.new(rng, size = DefaultBlockSize * 2, chunkSize = DefaultBlockSize * 2)
|
||||||
let data = await chunker.getBytes()
|
let data = await chunker.getBytes()
|
||||||
let cid = client0.upload(byteutils.toHex(data)).get
|
let cid = client0.upload(byteutils.toHex(data)).get
|
||||||
let expiry = (await provider.currentTime()) + expiry.u256
|
let expiry = (await provider.currentTime()) + expiry.u256
|
||||||
|
|
||||||
# avoid timing issues by filling the slot at the start of the next period
|
# avoid timing issues by filling the slot at the start of the next period
|
||||||
await advanceToNextPeriod()
|
await advanceToNextPeriod()
|
||||||
|
|
||||||
let id = client0.requestStorage(
|
let id = client0.requestStorage(
|
||||||
cid,
|
cid,
|
||||||
expiry=expiry,
|
expiry=expiry,
|
||||||
@ -339,27 +341,42 @@ multinodesuite "Simulate invalid proofs",
|
|||||||
reward=400.u256,
|
reward=400.u256,
|
||||||
nodes=2'u
|
nodes=2'u
|
||||||
).get
|
).get
|
||||||
check eventually client0.purchaseStateIs(id, "started")
|
|
||||||
return id
|
return id
|
||||||
|
|
||||||
proc waitUntilPurchaseIsFinished(purchaseId: PurchaseId, duration: int) {.async.} =
|
proc waitUntilPurchaseIsFinished(purchaseId: PurchaseId, duration: int) {.async.} =
|
||||||
let client = clients()[0].node.client
|
let client = clients()[0].node.client
|
||||||
check eventually(client.purchaseStateIs(purchaseId, "finished"), duration * 1000)
|
check eventually(client.purchaseStateIs(purchaseId, "finished"), duration * 1000)
|
||||||
|
|
||||||
|
|
||||||
# TODO: these are very loose tests in that they are not testing EXACTLY how
|
# 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
|
# proofs were marked as missed by the validator. These tests should be
|
||||||
# tightened so that they are showing, as an integration test, that specific
|
# tightened so that they are showing, as an integration test, that specific
|
||||||
# proofs are being marked as missed by the validator.
|
# proofs are being marked as missed by the validator.
|
||||||
|
|
||||||
test "provider that submits invalid proofs is paid out less":
|
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)
|
# await waitUntilPurchaseIsFinished(purchaseId, duration=totalProofs.periods.int)
|
||||||
|
|
||||||
let client = clients()[0].node.client
|
let duration = (totalProofs.periods.int + 2) * 10 # 10 seconds per period
|
||||||
let duration = totalProofs.periods.int
|
|
||||||
check eventually(client.purchaseStateIs(purchaseId, "finished"), duration * 1000)
|
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
|
# var slotWasFreed = false
|
||||||
# proc onSlotFreed(event: SlotFreed) =
|
# proc onSlotFreed(event: SlotFreed) =
|
||||||
|
|||||||
2
vendor/nim-json-rpc
vendored
2
vendor/nim-json-rpc
vendored
@ -1 +1 @@
|
|||||||
Subproject commit afc958db67ec34cba4c528348d9ce712aee488d6
|
Subproject commit 60c4c9b5f28b530d5d89fd14c337af1d86390a82
|
||||||
Loading…
x
Reference in New Issue
Block a user