wip: fixing test compile

This commit is contained in:
benbierens 2024-10-28 16:52:21 +01:00
parent cad74cc750
commit 599a5220b3
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
9 changed files with 47 additions and 24 deletions

View File

@ -92,7 +92,7 @@ proc init*(
proc init*(
_: type Poseidon2Tree,
leaves: seq[array[31, byte]]): Future[?!Poseidon2Tree] {.async.} =
Poseidon2Tree.init(
await Poseidon2Tree.init(
leaves.mapIt( Poseidon2Hash.fromBytes(it) ))
proc fromNodes*(

View File

@ -54,7 +54,7 @@ proc makeManifestAndTree*(blocks: seq[Block]): ?!(Manifest, CodexTree) =
let
datasetSize = blocks.mapIt(it.data.len).foldl(a + b)
blockSize = blocks.mapIt(it.data.len).foldl(max(a, b))
tree = ? CodexTree.init(blocks.mapIt(it.cid))
tree = ? (waitFor CodexTree.init(blocks.mapIt(it.cid)))
treeCid = ? tree.rootCid
manifest = Manifest.new(
treeCid = treeCid,
@ -93,7 +93,7 @@ proc storeDataGetManifest*(store: BlockStore, chunker: Chunker): Future[Manifest
(await store.putBlock(blk)).tryGet()
let
tree = CodexTree.init(cids).tryGet()
tree = (waitFor CodexTree.init(cids)).tryGet()
treeCid = tree.rootCid.tryGet()
manifest = Manifest.new(
treeCid = treeCid,

View File

@ -1,6 +1,7 @@
import std/unittest
import std/sequtils
import pkg/chronos
import pkg/questionable/results
import pkg/stew/byteutils
@ -8,7 +9,7 @@ import pkg/codex/merkletree
import ./helpers
const data =
[
@[
"00000000000000000000000000000001".toBytes,
"00000000000000000000000000000002".toBytes,
"00000000000000000000000000000003".toBytes,
@ -25,7 +26,7 @@ checksuite "merkletree - coders":
test "encoding and decoding a tree yields the same tree":
let
tree = CodexTree.init(Sha256HashCodec, data).tryGet()
tree = (waitFor CodexTree.init(Sha256HashCodec, data)).tryGet()
encodedBytes = tree.encode()
decodedTree = CodexTree.decode(encodedBytes).tryGet()
@ -34,7 +35,7 @@ checksuite "merkletree - coders":
test "encoding and decoding a proof yields the same proof":
let
tree = CodexTree.init(Sha256HashCodec, data).tryGet()
tree = (waitFor CodexTree.init(Sha256HashCodec, data)).tryGet()
proof = tree.getProof(4).tryGet()
check:

View File

@ -2,6 +2,7 @@ import std/unittest
import std/sequtils
import std/tables
import pkg/chronos
import pkg/questionable/results
import pkg/stew/byteutils
import pkg/nimcrypto/sha2
@ -18,7 +19,7 @@ import ./generictreetests
const
data =
[
@[
"00000000000000000000000000000001".toBytes,
"00000000000000000000000000000002".toBytes,
"00000000000000000000000000000003".toBytes,
@ -33,23 +34,32 @@ const
sha256 = Sha256HashCodec
suite "Test CodexTree":
proc CodexTreeInit(leaves: seq[MultiHash]): ?!CodexTree =
waitFor CodexTree.init(leaves)
proc CodexTreeInit(leaves: seq[Cid]): ?!CodexTree =
waitFor CodexTree.init(leaves)
proc CodexTreeInit(mcodec: MultiCodec, leaves: seq[ByteHash]): ?!CodexTree =
waitFor CodexTree.init(mcodec, leaves)
test "Cannot init tree without any multihash leaves":
check:
CodexTree.init(leaves = newSeq[MultiHash]()).isErr
CodexTreeInit(leaves = newSeq[MultiHash]()).isErr
test "Cannot init tree without any cid leaves":
check:
CodexTree.init(leaves = newSeq[Cid]()).isErr
CodexTreeInit(leaves = newSeq[Cid]()).isErr
test "Cannot init tree without any byte leaves":
check:
CodexTree.init(sha256, leaves = newSeq[ByteHash]()).isErr
CodexTreeInit(sha256, leaves = newSeq[ByteHash]()).isErr
test "Should build tree from multihash leaves":
var
expectedLeaves = data.mapIt( MultiHash.digest($sha256, it).tryGet() )
var tree = CodexTree.init(leaves = expectedLeaves)
var tree = CodexTreeInit(leaves = expectedLeaves)
check:
tree.isOk
tree.get().leaves == expectedLeaves.mapIt( it.digestBytes )
@ -65,7 +75,7 @@ suite "Test CodexTree":
).tryGet )
let
tree = CodexTree.init(leaves = expectedLeaves)
tree = CodexTreeInit(leaves = expectedLeaves)
check:
tree.isOk
@ -74,7 +84,7 @@ suite "Test CodexTree":
test "Should build from raw digestbytes (should not hash leaves)":
let
tree = CodexTree.init(sha256, leaves = data).tryGet
tree = CodexTreeInit(sha256, leaves = data).tryGet
check:
tree.mcodec == sha256
@ -82,7 +92,7 @@ suite "Test CodexTree":
test "Should build from nodes":
let
tree = CodexTree.init(sha256, leaves = data).tryGet
tree = CodexTreeInit(sha256, leaves = data).tryGet
fromNodes = CodexTree.fromNodes(
nodes = toSeq(tree.nodes),
nleaves = tree.leavesCount).tryGet
@ -98,7 +108,7 @@ let
compress(x, y, key, mhash).tryGet
makeTree = proc(data: seq[seq[byte]]): CodexTree =
CodexTree.init(sha256, leaves = data).tryGet
(waitFor CodexTree.init(sha256, leaves = data)).tryGet
testGenericTree(
"CodexTree",

View File

@ -2,6 +2,7 @@ import std/unittest
import std/sequtils
import std/sugar
import pkg/chronos
import pkg/poseidon2
import pkg/poseidon2/io
import pkg/questionable/results
@ -20,7 +21,7 @@ import ./helpers
const
data =
[
@[
"0000000000000000000000000000001".toBytes,
"0000000000000000000000000000002".toBytes,
"0000000000000000000000000000003".toBytes,
@ -33,6 +34,12 @@ const
]
suite "Test Poseidon2Tree":
proc Poseidon2TreeInit(leaves: seq[Poseidon2Hash]): ?!Poseidon2Tree =
waitFor Poseidon2Tree.init(leaves)
proc Poseidon2TreeInit(leaves: seq[array[31, byte]]): ?!Poseidon2Tree =
waitFor Poseidon2Tree.init(leaves)
var
expectedLeaves: seq[Poseidon2Hash]
@ -41,18 +48,18 @@ suite "Test Poseidon2Tree":
test "Should fail init tree from empty leaves":
check:
Poseidon2Tree.init( leaves = newSeq[Poseidon2Hash](0) ).isErr
Poseidon2TreeInit( leaves = newSeq[Poseidon2Hash](0) ).isErr
test "Init tree from poseidon2 leaves":
let
tree = Poseidon2Tree.init( leaves = expectedLeaves ).tryGet
tree = Poseidon2TreeInit( leaves = expectedLeaves ).tryGet
check:
tree.leaves == expectedLeaves
test "Init tree from byte leaves":
let
tree = Poseidon2Tree.init(
tree = Poseidon2TreeInit(
leaves = expectedLeaves.mapIt(
array[31, byte].initCopyFrom( it.toBytes )
)).tryGet
@ -62,7 +69,7 @@ suite "Test Poseidon2Tree":
test "Should build from nodes":
let
tree = Poseidon2Tree.init(leaves = expectedLeaves).tryGet
tree = Poseidon2TreeInit(leaves = expectedLeaves).tryGet
fromNodes = Poseidon2Tree.fromNodes(
nodes = toSeq(tree.nodes),
nleaves = tree.leavesCount).tryGet
@ -77,7 +84,7 @@ let
compress(x, y, key.toKey)
makeTree = proc(data: seq[Poseidon2Hash]): Poseidon2Tree =
Poseidon2Tree.init(leaves = data).tryGet
(waitFor Poseidon2Tree.init(leaves = data)).tryGet
testGenericTree(
"Poseidon2Tree",

View File

@ -96,6 +96,7 @@ asyncchecksuite "Test Node - Host contracts":
verifiable.encode().tryGet(),
codec = ManifestCodec).tryGet()
(await builder.init()).tryGet()
(await localStore.putBlock(verifiableBlock)).tryGet()
test "onExpiryUpdate callback is set":

View File

@ -153,6 +153,7 @@ asyncchecksuite "Test Node - Basic":
verifiable.encode().tryGet(),
codec = ManifestCodec).tryGet()
(await builder.init()).tryGet()
(await localStore.putBlock(manifestBlock)).tryGet()
let

View File

@ -160,7 +160,10 @@ proc createVerifiableManifest*(
totalDatasetSize)
builder = Poseidon2Builder.new(store, protectedManifest, cellSize = cellSize).tryGet
verifiableManifest = (await builder.buildManifest()).tryGet
(await builder.init()).tryGet()
let verifiableManifest = (await builder.buildManifest()).tryGet
# build the slots and manifest
(manifest, protectedManifest, verifiableManifest)

View File

@ -32,7 +32,7 @@ checksuite "Manifest":
strategy = SteppedStrategy
)
leaves = [
leaves = @[
0.toF.Poseidon2Hash,
1.toF.Poseidon2Hash,
2.toF.Poseidon2Hash,
@ -40,7 +40,7 @@ checksuite "Manifest":
slotLeavesCids = leaves.toSlotCids().tryGet
tree = Poseidon2Tree.init(leaves).tryGet
tree = (waitFor Poseidon2Tree.init(leaves)).tryGet
verifyCid = tree.root.tryGet.toVerifyCid().tryGet
verifiableManifest = Manifest.new(