Bump questionable and test for tree init failure (#630)

This commit is contained in:
Tomasz Bekas 2023-11-21 19:30:14 +01:00 committed by GitHub
parent ec8d0c98b2
commit 4d546f9ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 18 deletions

View File

@ -42,7 +42,7 @@ checksuite "merkletree":
setup:
for i in 0..<data.len:
expectedLeaves[i] = MultiHash.digest($sha256, data[i]).tryGet()
builder = MerkleTreeBuilder.init(sha256).tryGet()
var zero: array[32, byte]
var one: array[32, byte]
@ -50,6 +50,12 @@ checksuite "merkletree":
zeroHash = MultiHash.init($sha256, zero).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":
builder.addDataBlock(data[0]).tryGet()
@ -82,7 +88,7 @@ checksuite "merkletree":
let
expectedRoot = combine(
combine(expectedLeaves[0], expectedLeaves[1]),
combine(expectedLeaves[0], expectedLeaves[1]),
combine(expectedLeaves[2], zeroHash)
)
@ -109,15 +115,15 @@ checksuite "merkletree":
combine(
combine(
combine(expectedLeaves[0], expectedLeaves[1]),
combine(expectedLeaves[2], expectedLeaves[3]),
combine(expectedLeaves[2], expectedLeaves[3]),
),
combine(
combine(expectedLeaves[4], expectedLeaves[5]),
combine(
combine(expectedLeaves[4], expectedLeaves[5]),
combine(expectedLeaves[6], expectedLeaves[7])
)
),
combine(
combine(
combine(
combine(expectedLeaves[8], zeroHash),
oneHash
),
@ -148,7 +154,7 @@ checksuite "merkletree":
check:
tree.getProof(0).tryGet().verifyDataBlock(data[0], tree.root).tryGet()
tree.getProof(1).tryGet().verifyDataBlock(data[1], tree.root).tryGet()
test "tree with three leaves provides expected proofs":
builder.addDataBlock(data[0]).tryGet()
builder.addDataBlock(data[1]).tryGet()
@ -186,34 +192,34 @@ checksuite "merkletree":
let tree = builder.build().tryGet()
let expectedProofs = {
4:
4:
MerkleProof.init(4, @[
expectedLeaves[5],
combine(expectedLeaves[6], expectedLeaves[7]),
expectedLeaves[5],
combine(expectedLeaves[6], expectedLeaves[7]),
combine(
combine(expectedLeaves[0], expectedLeaves[1]),
combine(expectedLeaves[2], expectedLeaves[3]),
combine(expectedLeaves[2], expectedLeaves[3]),
),
combine(
combine(
combine(
combine(expectedLeaves[8], zeroHash),
oneHash
),
oneHash
)
]).tryGet(),
8:
8:
MerkleProof.init(8, @[
zeroHash,
zeroHash,
oneHash,
oneHash,
combine(
combine(
combine(expectedLeaves[0], expectedLeaves[1]),
combine(expectedLeaves[2], expectedLeaves[3]),
combine(expectedLeaves[2], expectedLeaves[3]),
),
combine(
combine(expectedLeaves[4], expectedLeaves[5]),
combine(
combine(expectedLeaves[4], expectedLeaves[5]),
combine(expectedLeaves[6], expectedLeaves[7])
)
)

2
vendor/questionable vendored

@ -1 +1 @@
Subproject commit 2dd6b6b220f9f14a1231f6cafdf24f012bcc8414
Subproject commit 1f0afff48bf80ab1149a0957f9743f345bc14b71