mirror of
https://github.com/logos-storage/nim-merkletree.git
synced 2026-03-04 14:13:10 +00:00
This commit does not compile. There is a circular dependency importing the MerkleTree type. The interface needs to be defined in such a way that we can avoid this circular dependency.
45 lines
1.2 KiB
Nim
45 lines
1.2 KiB
Nim
import pkg/unittest2
|
|
|
|
import pkg/questionable/results
|
|
import pkg/stew/byteutils
|
|
|
|
import pkg/merkletree
|
|
import ./helpers
|
|
|
|
const data = [
|
|
"00000000000000000000000000000001".toBytes,
|
|
"00000000000000000000000000000002".toBytes,
|
|
"00000000000000000000000000000003".toBytes,
|
|
"00000000000000000000000000000004".toBytes,
|
|
"00000000000000000000000000000005".toBytes,
|
|
"00000000000000000000000000000006".toBytes,
|
|
"00000000000000000000000000000007".toBytes,
|
|
"00000000000000000000000000000008".toBytes,
|
|
"00000000000000000000000000000009".toBytes, "00000000000000000000000000000010".toBytes,
|
|
]
|
|
|
|
suite "merkletree - coders":
|
|
test "encoding and decoding a tree yields the same tree":
|
|
let
|
|
tree = CodexTree.init(Sha256HashCodec, data).tryGet()
|
|
encodedBytes = tree.encode()
|
|
decodedTree = CodexTree.decode(encodedBytes).tryGet()
|
|
|
|
check:
|
|
tree == decodedTree
|
|
|
|
test "encoding and decoding a proof yields the same proof":
|
|
let
|
|
tree = CodexTree.init(Sha256HashCodec, data).tryGet()
|
|
proof = tree.getProof(4).tryGet()
|
|
|
|
check:
|
|
proof.verify(tree.leaves[4], tree.root.tryGet).isOk
|
|
|
|
let
|
|
encodedBytes = proof.encode()
|
|
decodedProof = CodexProof.decode(encodedBytes).tryGet()
|
|
|
|
check:
|
|
proof == decodedProof
|