From 11eaebfd775294a297bdaf9cf40484803ed1532a Mon Sep 17 00:00:00 2001 From: Tomasz Bekas Date: Wed, 26 Jun 2024 22:02:39 +0200 Subject: [PATCH] Fix verifiable manifest constructor (#844) * Fix verifiable manifest constructor * Add integration test for verifiable manifest download Add integration test for testing download of verifiable dataset after creating request for storage * add missing import * add testecbug to integration suite * Remove hardhat instance from integration test * change description, drop echo --------- Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com> Co-authored-by: gmega --- codex/manifest/manifest.nim | 2 +- tests/codex/testerasure.nim | 20 +++++++++++ tests/integration/codexclient.nim | 27 +++++++++++++- tests/integration/testecbug.nim | 60 +++++++++++++++++++++++++++++++ tests/testIntegration.nim | 1 + 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 tests/integration/testecbug.nim diff --git a/codex/manifest/manifest.nim b/codex/manifest/manifest.nim index abfd5b4c..5966feb3 100644 --- a/codex/manifest/manifest.nim +++ b/codex/manifest/manifest.nim @@ -322,7 +322,7 @@ func new*( protected: true, ecK: manifest.ecK, ecM: manifest.ecM, - originalTreeCid: manifest.treeCid, + originalTreeCid: manifest.originalTreeCid, originalDatasetSize: manifest.originalDatasetSize, protectedStrategy: manifest.protectedStrategy, verifiable: true, diff --git a/tests/codex/testerasure.nim b/tests/codex/testerasure.nim index b92f4ae3..84f4b1c3 100644 --- a/tests/codex/testerasure.nim +++ b/tests/codex/testerasure.nim @@ -17,6 +17,7 @@ import pkg/taskpools import ../asynctest import ./helpers +import ./examples suite "Erasure encode/decode": const BlockSize = 1024'nb @@ -232,3 +233,22 @@ suite "Erasure encode/decode": let encoded = await encode(buffers, parity) discard (await erasure.decode(encoded)).tryGet() + + test "Should handle verifiable manifests": + const + buffers = 20 + parity = 10 + + let + encoded = await encode(buffers, parity) + slotCids = collect(newSeq): + for i in 0.. //_.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/ //_.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:[].} = + 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 = await clientApi.downloadBytes(cidFromRequest, local = true) + check downloaded.isOk + check downloaded.get.toHex == data.toHex + + await subscription.unsubscribe() diff --git a/tests/testIntegration.nim b/tests/testIntegration.nim index de854ecb..b1f81ef4 100644 --- a/tests/testIntegration.nim +++ b/tests/testIntegration.nim @@ -6,5 +6,6 @@ import ./integration/testpurchasing import ./integration/testblockexpiration import ./integration/testmarketplace import ./integration/testproofs +import ./integration/testecbug {.warning[UnusedImport]:off.}