From befe9775be2a3c60c5a55a7ed8ca76bd29be9f1e Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 15 Dec 2023 18:25:54 -0600 Subject: [PATCH] shorten file names --- .../codex/merkletree/testcodexmerkletree.nim | 101 ------------------ tests/codex/testmerkletree.nim | 1 - 2 files changed, 102 deletions(-) delete mode 100644 tests/codex/merkletree/testcodexmerkletree.nim diff --git a/tests/codex/merkletree/testcodexmerkletree.nim b/tests/codex/merkletree/testcodexmerkletree.nim deleted file mode 100644 index e331f230..00000000 --- a/tests/codex/merkletree/testcodexmerkletree.nim +++ /dev/null @@ -1,101 +0,0 @@ -import std/unittest -import std/sequtils -import std/tables - -import pkg/questionable/results -import pkg/stew/byteutils -import pkg/nimcrypto/sha2 - -import pkg/codex/merkletree - -import ../helpers -import ./generictreetests - -# TODO: Generalize to other hashes - -const - data = - [ - "00000000000000000000000000000001".toBytes, - "00000000000000000000000000000002".toBytes, - "00000000000000000000000000000003".toBytes, - "00000000000000000000000000000004".toBytes, - "00000000000000000000000000000005".toBytes, - "00000000000000000000000000000006".toBytes, - "00000000000000000000000000000007".toBytes, - "00000000000000000000000000000008".toBytes, - "00000000000000000000000000000009".toBytes, - "00000000000000000000000000000010".toBytes, - ] - sha256 = multiCodec("sha2-256") - -checksuite "merkletree": - test "Cannot init tree without any multihash leaves": - check: - CodexMerkleTree.init(leaves = newSeq[MultiHash]()).isErr - - test "Cannot init tree without any cid leaves": - check: - CodexMerkleTree.init(leaves = newSeq[Cid]()).isErr - - test "Cannot init tree without any byte leaves": - check: - CodexMerkleTree.init(sha256, leaves = newSeq[ByteHash]()).isErr - - test "Should build tree from multihash leaves": - var - expectedLeaves = data.mapIt( MultiHash.digest($sha256, it).tryGet() ) - - var tree = CodexMerkleTree.init(leaves = expectedLeaves) - check: - tree.isOk - tree.get().leaves == expectedLeaves.mapIt( it.bytes ) - tree.get().mcodec == sha256 - - test "Should build tree from cid leaves": - var - expectedLeaves = data.mapIt( Cid.init( - CidVersion.CIDv1, BlockCodec, MultiHash.digest($sha256, it).tryGet ).tryGet ) - - let - tree = CodexMerkleTree.init(leaves = expectedLeaves) - - check: - tree.isOk - tree.get().leaves == expectedLeaves.mapIt( it.mhash.tryGet.bytes ) - tree.get().mcodec == sha256 - - test "Should build from raw bytes (should not hash leaves)": - let - tree = CodexMerkleTree.init(sha256, leaves = data).tryGet - - check: - tree.mcodec == sha256 - tree.leaves == data - - test "Should build from nodes": - let - tree = CodexMerkleTree.init(sha256, leaves = data).tryGet - fromNodes = CodexMerkleTree.fromNodes( - nodes = toSeq(tree.nodes), - nleaves = tree.leavesCount).tryGet - - check: - tree.mcodec == sha256 - tree == fromNodes - -let - mhash = sha256.getMhash().tryGet - zero: seq[byte] = newSeq[byte](mhash.size) - compress = proc(x, y: seq[byte], key: ByteTreeKey): seq[byte] = - compress(x, y, key, mhash).tryGet - - makeTree = proc(data: seq[seq[byte]]): CodexMerkleTree = - CodexMerkleTree.init(sha256, leaves = data).tryGet - -checkGenericTree( - "CodexMerkleTree", - @data, - zero, - compress, - makeTree) diff --git a/tests/codex/testmerkletree.nim b/tests/codex/testmerkletree.nim index e64b8108..a8c278d8 100644 --- a/tests/codex/testmerkletree.nim +++ b/tests/codex/testmerkletree.nim @@ -1,5 +1,4 @@ import ./merkletree/testcodextree -import ./merkletree/testposeidon2tree import ./merkletree/testcodexcoders import ./merkletree/testmerkledigest