Add integration test that repros #821

Reproduces crash in https://github.com/codex-storage/nim-codex/issues/821
This commit is contained in:
Eric 2024-06-14 11:58:43 +10:00
parent d524252f1f
commit 215023bddc
No known key found for this signature in database
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
from pkg/libp2p import Cid, init
import ../examples
import ./marketplacesuite
import ./nodeconfigs
import ./hardhatconfig
marketplacesuite "EC bug":
test "should be able to create storage request and download dataset",
NodeConfigs(
# Uncomment to start Hardhat automatically, typically so logs can be
# inspected locally
hardhat: HardhatConfig().withLogFile().some,
clients:
CodexConfigs.init(nodes=1)
# .debug() # uncomment to enable console log output.debug()
.withLogFile() # uncomment to output log file to tests/integration/logs/<start_datetime> <suite_name>/<test_name>/<node_role>_<node_idx>.log
.withLogTopics("node", "erasure", "marketplace", )
.some,
providers:
CodexConfigs.init(nodes=0)
# .debug() # uncomment to enable console log output
# .withLogFile() # uncomment to output log file to tests/integration/logs/<start_datetime> <suite_name>/<test_name>/<node_role>_<node_idx>.log
# .withLogTopics("node", "marketplace", "sales", "reservations", "node", "proving", "clock")
.some,
):
let reward = 400.u256
let duration = 10.periods
let collateral = 200.u256
let expiry = 5.periods
let data = await RandomChunker.example(blocks=8)
let client = clients()[0]
let clientApi = client.client
let cid = clientApi.upload(data).get
var requestId = none RequestId
proc onStorageRequested(event: StorageRequested) {.raises:[].} =
echo "storage requested event"
requestId = event.requestId.some
let subscription = await marketplace.subscribe(StorageRequested, onStorageRequested)
# client requests storage but requires multiple slots to host the content
let id = await clientApi.requestStorage(
cid,
duration=duration,
reward=reward,
expiry=expiry,
collateral=collateral,
nodes=3,
tolerance=1
)
check eventually(requestId.isSome, timeout=expiry.int * 1000)
let request = await marketplace.getRequest(requestId.get)
let cidFromRequest = Cid.init(request.content.cid).get()
let downloaded = clientApi.download(cidFromRequest, local = true)
check downloaded.isOk
check downloaded.get == data
await subscription.unsubscribe()