logos-storage-nim/tests/testTaiko.nim
Giuliano Mega 54177e9fbf
feat(integration): use async client instead of standard Nim HTTP client (#1159)
* WiP: migrating CodexClient to chronos http client

* fix(api): fixes #1163

* feat: fully working API integration tests

* convert most of the tests in testupdownload

* feat: working updownload tests on async client

* feat: make testsales work with async codexclient

* feat: make testpurchasing work with async codexclient

* feat: make testblockexpiration work with async codexclient

* feat: make marketplacesuite work with async codexclient

* make testproofs work with async codexclient

* chore: refactor client to express higher level in terms of lower level operations

* fix: set correct content-length for erasure-coded datasets

* feat: make testecbug work with async client

* feat: make testvalidator work with async client

* refactor: simplify request aliases, add close operation

* wire back client.close at node shutdown

* refactor: remove unused exception

* fix: use await instead of waitFor on async call sites
2025-03-17 20:08:24 +00:00

83 lines
2.2 KiB
Nim

import std/times
import std/os
import std/json
import std/tempfiles
import pkg/chronos
import pkg/stint
import pkg/questionable
import pkg/questionable/results
import ./asynctest
import ./integration/nodes
suite "Taiko L2 Integration Tests":
var node1, node2: NodeProcess
setup:
doAssert existsEnv("CODEX_ETH_PRIVATE_KEY"), "Key for Taiko account missing"
node1 = startNode(
[
"--data-dir=" & createTempDir("", ""), "--api-port=8080", "--nat=none",
"--disc-port=8090", "--persistence", "--eth-provider=https://rpc.test.taiko.xyz",
]
)
node1.waitUntilStarted()
let bootstrap = (!(await node1.client.info()))["spr"].getStr()
node2 = startNode(
[
"--data-dir=" & createTempDir("", ""),
"--api-port=8081",
"--nat=none",
"--disc-port=8091",
"--bootstrap-node=" & bootstrap,
"--persistence",
"--eth-provider=https://rpc.test.taiko.xyz",
]
)
node2.waitUntilStarted()
teardown:
node1.stop()
node2.stop()
node1.removeDataDir()
node2.removeDataDir()
test "node 1 buys storage from node 2":
let size = 0xFFFFF.u256
let minPricePerBytePerSecond = 1.u256
let totalCollateral = size * minPricePerBytePerSecond
discard node2.client.postAvailability(
size = size,
duration = 200.u256,
minPricePerBytePerSecond = minPricePerBytePerSecond,
totalCollateral = totalCollateral,
)
let cid = !node1.client.upload("some file contents")
echo " - requesting storage, expires in 5 minutes"
let expiry = getTime().toUnix().uint64 + 5 * 60
let purchase =
!node1.client.requestStorage(
cid,
duration = 30.u256,
pricePerBytePerSecond = 1.u256,
proofProbability = 3.u256,
collateralPerByte = 1.u256,
expiry = expiry.u256,
)
echo " - waiting for request to start, timeout 5 minutes"
check eventually(
node1.client.getPurchase(purchase) .? state == success "started",
timeout = 5 * 60 * 1000,
)
echo " - waiting for request to finish, timeout 1 minute"
check eventually(
node1.client.getPurchase(purchase) .? state == success "finished",
timeout = 1 * 60 * 1000,
)