2022-01-10 15:32:56 +00:00
|
|
|
import std/sequtils
|
|
|
|
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/questionable/results
|
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
|
2024-02-07 20:54:57 +00:00
|
|
|
import pkg/codex/indexingstrategy
|
2022-01-10 15:32:56 +00:00
|
|
|
|
2024-01-29 20:03:51 +00:00
|
|
|
import ../asynctest
|
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,
|
2024-02-07 20:54:57 +00:00
|
|
|
ecM = 2,
|
|
|
|
strategy = SteppedStrategy
|
2023-12-12 08:11:54 +00:00
|
|
|
)
|
2024-01-11 16:45:23 +00:00
|
|
|
|
2024-10-28 15:52:21 +00:00
|
|
|
leaves = @[
|
2024-01-11 16:45:23 +00:00
|
|
|
0.toF.Poseidon2Hash,
|
|
|
|
1.toF.Poseidon2Hash,
|
|
|
|
2.toF.Poseidon2Hash,
|
|
|
|
3.toF.Poseidon2Hash]
|
|
|
|
|
|
|
|
slotLeavesCids = leaves.toSlotCids().tryGet
|
|
|
|
|
2024-10-28 15:52:21 +00:00
|
|
|
tree = (waitFor 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
|
|
|
|
2024-04-30 15:27:17 +00:00
|
|
|
test "Should encode/decode large manifest":
|
|
|
|
let large = Manifest.new(
|
|
|
|
treeCid = Cid.example,
|
|
|
|
blockSize = (64 * 1024).NBytes,
|
|
|
|
datasetSize = (5 * 1024).MiBs
|
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
encodeDecode(large) == large
|
|
|
|
|
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
|
2024-06-21 22:50:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
suite "Manifest - Attribute Inheritance":
|
|
|
|
proc makeProtectedManifest(strategy: StrategyType): Manifest =
|
|
|
|
Manifest.new(
|
|
|
|
manifest = Manifest.new(
|
|
|
|
treeCid = Cid.example,
|
|
|
|
blockSize = 1.MiBs,
|
|
|
|
datasetSize = 100.MiBs,
|
2024-10-25 13:43:19 +00:00
|
|
|
filename = "codex.png".some,
|
|
|
|
mimetype = "image/png".some
|
2024-06-21 22:50:56 +00:00
|
|
|
),
|
|
|
|
treeCid = Cid.example,
|
|
|
|
datasetSize = 200.MiBs,
|
|
|
|
ecK = 1,
|
|
|
|
ecM = 1,
|
|
|
|
strategy = strategy
|
|
|
|
)
|
|
|
|
|
|
|
|
test "Should preserve interleaving strategy for protected manifest in verifiable manifest":
|
|
|
|
var verifiable = Manifest.new(
|
|
|
|
manifest = makeProtectedManifest(SteppedStrategy),
|
|
|
|
verifyRoot = Cid.example,
|
|
|
|
slotRoots = @[Cid.example, Cid.example]
|
|
|
|
).tryGet()
|
|
|
|
|
|
|
|
check verifiable.protectedStrategy == SteppedStrategy
|
|
|
|
|
|
|
|
verifiable = Manifest.new(
|
|
|
|
manifest = makeProtectedManifest(LinearStrategy),
|
|
|
|
verifyRoot = Cid.example,
|
|
|
|
slotRoots = @[Cid.example, Cid.example]
|
|
|
|
).tryGet()
|
|
|
|
|
|
|
|
check verifiable.protectedStrategy == LinearStrategy
|
2024-10-25 13:43:19 +00:00
|
|
|
|
|
|
|
test "Should preserve metadata for manifest in verifiable manifest":
|
|
|
|
var verifiable = Manifest.new(
|
|
|
|
manifest = makeProtectedManifest(SteppedStrategy),
|
|
|
|
verifyRoot = Cid.example,
|
|
|
|
slotRoots = @[Cid.example, Cid.example]
|
|
|
|
).tryGet()
|
|
|
|
|
|
|
|
check verifiable.filename.isSome == true
|
|
|
|
check verifiable.filename.get() == "codex.png"
|
|
|
|
check verifiable.mimetype.isSome == true
|
|
|
|
check verifiable.mimetype.get() == "image/png"
|