2022-01-10 15:32:56 +00:00
|
|
|
import std/sequtils
|
|
|
|
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/questionable/results
|
2024-01-10 21:25:57 +00:00
|
|
|
import pkg/asynctest/chronos/unittest
|
|
|
|
import pkg/stew/byteutils
|
|
|
|
|
2022-05-19 19:56:03 +00:00
|
|
|
import pkg/codex/chunker
|
|
|
|
import pkg/codex/blocktype as bt
|
|
|
|
import pkg/codex/manifest
|
2024-01-11 16:45:23 +00:00
|
|
|
import pkg/poseidon2
|
|
|
|
|
|
|
|
import pkg/codex/slots
|
|
|
|
import pkg/codex/merkletree
|
2022-01-10 15:32:56 +00:00
|
|
|
|
|
|
|
import ./helpers
|
2023-11-14 12:02:17 +00:00
|
|
|
import ./examples
|
2022-01-10 15:32:56 +00:00
|
|
|
|
2023-06-22 18:01:21 +00:00
|
|
|
checksuite "Manifest":
|
2023-12-12 08:11:54 +00:00
|
|
|
let
|
|
|
|
manifest = Manifest.new(
|
|
|
|
treeCid = Cid.example,
|
|
|
|
blockSize = 1.MiBs,
|
|
|
|
datasetSize = 100.MiBs
|
|
|
|
)
|
2024-01-11 16:45:23 +00:00
|
|
|
|
2023-12-12 08:11:54 +00:00
|
|
|
protectedManifest = Manifest.new(
|
|
|
|
manifest = manifest,
|
|
|
|
treeCid = Cid.example,
|
|
|
|
datasetSize = 200.MiBs,
|
2024-01-11 16:45:23 +00:00
|
|
|
eck = 2,
|
|
|
|
ecM = 2
|
2023-12-12 08:11:54 +00:00
|
|
|
)
|
2024-01-11 16:45:23 +00:00
|
|
|
|
|
|
|
leaves = [
|
|
|
|
0.toF.Poseidon2Hash,
|
|
|
|
1.toF.Poseidon2Hash,
|
|
|
|
2.toF.Poseidon2Hash,
|
|
|
|
3.toF.Poseidon2Hash]
|
|
|
|
|
|
|
|
slotLeavesCids = leaves.toSlotCids().tryGet
|
|
|
|
|
|
|
|
tree = Poseidon2Tree.init(leaves).tryGet
|
2024-01-17 19:24:34 +00:00
|
|
|
verifyCid = tree.root.tryGet.toVerifyCid().tryGet
|
2024-01-11 16:45:23 +00:00
|
|
|
|
2023-12-12 08:11:54 +00:00
|
|
|
verifiableManifest = Manifest.new(
|
|
|
|
manifest = protectedManifest,
|
2024-01-17 19:24:34 +00:00
|
|
|
verifyRoot = verifyCid,
|
2024-01-11 16:45:23 +00:00
|
|
|
slotRoots = slotLeavesCids
|
2023-12-12 08:11:54 +00:00
|
|
|
).tryGet()
|
|
|
|
|
|
|
|
proc encodeDecode(manifest: Manifest): Manifest =
|
|
|
|
let e = manifest.encode().tryGet()
|
|
|
|
Manifest.decode(e).tryGet()
|
2022-01-10 15:32:56 +00:00
|
|
|
|
2023-12-12 08:11:54 +00:00
|
|
|
test "Should encode/decode to/from base manifest":
|
|
|
|
check:
|
|
|
|
encodeDecode(manifest) == manifest
|
2022-01-10 15:32:56 +00:00
|
|
|
|
2023-12-12 08:11:54 +00:00
|
|
|
test "Should encode/decode to/from protected manifest":
|
2022-04-05 00:46:13 +00:00
|
|
|
check:
|
2023-12-12 08:11:54 +00:00
|
|
|
encodeDecode(protectedManifest) == protectedManifest
|
2022-04-05 00:46:13 +00:00
|
|
|
|
2023-12-12 08:11:54 +00:00
|
|
|
test "Should encode/decode to/from verifiable manifest":
|
|
|
|
check:
|
|
|
|
encodeDecode(verifiableManifest) == verifiableManifest
|