Bump questionable and test for tree init failure (#630)
This commit is contained in:
parent
ec8d0c98b2
commit
4d546f9ace
|
@ -42,7 +42,7 @@ checksuite "merkletree":
|
||||||
setup:
|
setup:
|
||||||
for i in 0..<data.len:
|
for i in 0..<data.len:
|
||||||
expectedLeaves[i] = MultiHash.digest($sha256, data[i]).tryGet()
|
expectedLeaves[i] = MultiHash.digest($sha256, data[i]).tryGet()
|
||||||
|
|
||||||
builder = MerkleTreeBuilder.init(sha256).tryGet()
|
builder = MerkleTreeBuilder.init(sha256).tryGet()
|
||||||
var zero: array[32, byte]
|
var zero: array[32, byte]
|
||||||
var one: array[32, byte]
|
var one: array[32, byte]
|
||||||
|
@ -50,6 +50,12 @@ checksuite "merkletree":
|
||||||
zeroHash = MultiHash.init($sha256, zero).tryGet()
|
zeroHash = MultiHash.init($sha256, zero).tryGet()
|
||||||
oneHash = MultiHash.init($sha256, one).tryGet()
|
oneHash = MultiHash.init($sha256, one).tryGet()
|
||||||
|
|
||||||
|
test "cannot init tree without any leafs":
|
||||||
|
let treeOrErr = MerkleTree.init(newSeq[MultiHash]())
|
||||||
|
|
||||||
|
check:
|
||||||
|
treeOrErr.isErr
|
||||||
|
|
||||||
test "tree with one leaf has expected structure":
|
test "tree with one leaf has expected structure":
|
||||||
builder.addDataBlock(data[0]).tryGet()
|
builder.addDataBlock(data[0]).tryGet()
|
||||||
|
|
||||||
|
@ -82,7 +88,7 @@ checksuite "merkletree":
|
||||||
|
|
||||||
let
|
let
|
||||||
expectedRoot = combine(
|
expectedRoot = combine(
|
||||||
combine(expectedLeaves[0], expectedLeaves[1]),
|
combine(expectedLeaves[0], expectedLeaves[1]),
|
||||||
combine(expectedLeaves[2], zeroHash)
|
combine(expectedLeaves[2], zeroHash)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -109,15 +115,15 @@ checksuite "merkletree":
|
||||||
combine(
|
combine(
|
||||||
combine(
|
combine(
|
||||||
combine(expectedLeaves[0], expectedLeaves[1]),
|
combine(expectedLeaves[0], expectedLeaves[1]),
|
||||||
combine(expectedLeaves[2], expectedLeaves[3]),
|
combine(expectedLeaves[2], expectedLeaves[3]),
|
||||||
),
|
),
|
||||||
combine(
|
combine(
|
||||||
combine(expectedLeaves[4], expectedLeaves[5]),
|
combine(expectedLeaves[4], expectedLeaves[5]),
|
||||||
combine(expectedLeaves[6], expectedLeaves[7])
|
combine(expectedLeaves[6], expectedLeaves[7])
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
combine(
|
combine(
|
||||||
combine(
|
combine(
|
||||||
combine(expectedLeaves[8], zeroHash),
|
combine(expectedLeaves[8], zeroHash),
|
||||||
oneHash
|
oneHash
|
||||||
),
|
),
|
||||||
|
@ -148,7 +154,7 @@ checksuite "merkletree":
|
||||||
check:
|
check:
|
||||||
tree.getProof(0).tryGet().verifyDataBlock(data[0], tree.root).tryGet()
|
tree.getProof(0).tryGet().verifyDataBlock(data[0], tree.root).tryGet()
|
||||||
tree.getProof(1).tryGet().verifyDataBlock(data[1], tree.root).tryGet()
|
tree.getProof(1).tryGet().verifyDataBlock(data[1], tree.root).tryGet()
|
||||||
|
|
||||||
test "tree with three leaves provides expected proofs":
|
test "tree with three leaves provides expected proofs":
|
||||||
builder.addDataBlock(data[0]).tryGet()
|
builder.addDataBlock(data[0]).tryGet()
|
||||||
builder.addDataBlock(data[1]).tryGet()
|
builder.addDataBlock(data[1]).tryGet()
|
||||||
|
@ -186,34 +192,34 @@ checksuite "merkletree":
|
||||||
let tree = builder.build().tryGet()
|
let tree = builder.build().tryGet()
|
||||||
|
|
||||||
let expectedProofs = {
|
let expectedProofs = {
|
||||||
4:
|
4:
|
||||||
MerkleProof.init(4, @[
|
MerkleProof.init(4, @[
|
||||||
expectedLeaves[5],
|
expectedLeaves[5],
|
||||||
combine(expectedLeaves[6], expectedLeaves[7]),
|
combine(expectedLeaves[6], expectedLeaves[7]),
|
||||||
combine(
|
combine(
|
||||||
combine(expectedLeaves[0], expectedLeaves[1]),
|
combine(expectedLeaves[0], expectedLeaves[1]),
|
||||||
combine(expectedLeaves[2], expectedLeaves[3]),
|
combine(expectedLeaves[2], expectedLeaves[3]),
|
||||||
),
|
),
|
||||||
combine(
|
combine(
|
||||||
combine(
|
combine(
|
||||||
combine(expectedLeaves[8], zeroHash),
|
combine(expectedLeaves[8], zeroHash),
|
||||||
oneHash
|
oneHash
|
||||||
),
|
),
|
||||||
oneHash
|
oneHash
|
||||||
)
|
)
|
||||||
]).tryGet(),
|
]).tryGet(),
|
||||||
8:
|
8:
|
||||||
MerkleProof.init(8, @[
|
MerkleProof.init(8, @[
|
||||||
zeroHash,
|
zeroHash,
|
||||||
oneHash,
|
oneHash,
|
||||||
oneHash,
|
oneHash,
|
||||||
combine(
|
combine(
|
||||||
combine(
|
combine(
|
||||||
combine(expectedLeaves[0], expectedLeaves[1]),
|
combine(expectedLeaves[0], expectedLeaves[1]),
|
||||||
combine(expectedLeaves[2], expectedLeaves[3]),
|
combine(expectedLeaves[2], expectedLeaves[3]),
|
||||||
),
|
),
|
||||||
combine(
|
combine(
|
||||||
combine(expectedLeaves[4], expectedLeaves[5]),
|
combine(expectedLeaves[4], expectedLeaves[5]),
|
||||||
combine(expectedLeaves[6], expectedLeaves[7])
|
combine(expectedLeaves[6], expectedLeaves[7])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2dd6b6b220f9f14a1231f6cafdf24f012bcc8414
|
Subproject commit 1f0afff48bf80ab1149a0957f9743f345bc14b71
|
Loading…
Reference in New Issue