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 checksuite "merkletree": const data = [ "0123456789012345678901234567890123456789".toBytes, "1234567890123456789012345678901234567890".toBytes, "2345678901234567890123456789012345678901".toBytes, "3456789012345678901234567890123456789012".toBytes, "4567890123456789012345678901234567890123".toBytes, "5678901234567890123456789012345678901234".toBytes, "6789012345678901234567890123456789012345".toBytes, "7890123456789012345678901234567890123456".toBytes, "8901234567890123456789012345678901234567".toBytes, "9012345678901234567890123456789012345678".toBytes, ] const sha256 = multiCodec("sha2-256") const sha512 = multiCodec("sha2-512") proc combine(a, b: MultiHash, codec: MultiCodec = sha256): MultiHash = var buf = newSeq[byte](a.size + b.size) copyMem(addr buf[0], unsafeAddr a.data.buffer[a.dpos], a.size) copyMem(addr buf[a.size], unsafeAddr b.data.buffer[b.dpos], b.size) return MultiHash.digest($codec, buf).tryGet() var zeroHash: MultiHash var oneHash: MultiHash var expectedLeaves: array[data.len, MultiHash] var builder: MerkleTreeBuilder setup: for i in 0..