More tests for getBlockRange
This commit is contained in:
parent
080609eee1
commit
7a577b2cef
|
@ -538,7 +538,7 @@ func getBlockRange*(
|
||||||
trace "getBlockRange entered",
|
trace "getBlockRange entered",
|
||||||
head = shortLog(dag.head.root), requestedCount, startSlot, skipStep, headSlot
|
head = shortLog(dag.head.root), requestedCount, startSlot, skipStep, headSlot
|
||||||
|
|
||||||
if startSlot < dag.tail.slot or headSlot <= startSlot:
|
if startSlot < dag.tail.slot or headSlot <= startSlot or requestedCount == 0:
|
||||||
return output.len # Identical to returning an empty set of block as indicated above
|
return output.len # Identical to returning an empty set of block as indicated above
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
|
@ -17,6 +17,9 @@ import
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import chronicles # or some random compile error happens...
|
import chronicles # or some random compile error happens...
|
||||||
|
|
||||||
|
proc `$`(x: BlockRef): string =
|
||||||
|
$x.root
|
||||||
|
|
||||||
template wrappedTimedTest(name: string, body: untyped) =
|
template wrappedTimedTest(name: string, body: untyped) =
|
||||||
# `check` macro takes a copy of whatever it's checking, on the stack!
|
# `check` macro takes a copy of whatever it's checking, on the stack!
|
||||||
# This leads to stack overflow
|
# This leads to stack overflow
|
||||||
|
@ -195,12 +198,23 @@ suiteReport "Block pool processing" & preset():
|
||||||
dag.getBlockRange(Slot(2), 2, blocks.toOpenArray(0, 1)) == 0
|
dag.getBlockRange(Slot(2), 2, blocks.toOpenArray(0, 1)) == 0
|
||||||
blocks[0..<2] == [b2Add[], b4Add[]] # block 3 is missing!
|
blocks[0..<2] == [b2Add[], b4Add[]] # block 3 is missing!
|
||||||
|
|
||||||
|
# large skip step
|
||||||
|
dag.getBlockRange(Slot(0), uint64.high, blocks.toOpenArray(0, 2)) == 2
|
||||||
|
blocks[2..2] == [dag.tail]
|
||||||
|
|
||||||
|
# large skip step
|
||||||
|
dag.getBlockRange(Slot(2), uint64.high, blocks.toOpenArray(0, 1)) == 1
|
||||||
|
blocks[1..1] == [b2Add[]]
|
||||||
|
|
||||||
# empty length
|
# empty length
|
||||||
dag.getBlockRange(Slot(2), 2, blocks.toOpenArray(0, -1)) == 0
|
dag.getBlockRange(Slot(2), 2, blocks.toOpenArray(0, -1)) == 0
|
||||||
|
|
||||||
# No blocks in sight
|
# No blocks in sight
|
||||||
dag.getBlockRange(Slot(5), 1, blocks.toOpenArray(0, 1)) == 2
|
dag.getBlockRange(Slot(5), 1, blocks.toOpenArray(0, 1)) == 2
|
||||||
|
|
||||||
|
# No blocks in sight
|
||||||
|
dag.getBlockRange(Slot(uint64.high), 1, blocks.toOpenArray(0, 1)) == 2
|
||||||
|
|
||||||
# No blocks in sight either due to gaps
|
# No blocks in sight either due to gaps
|
||||||
dag.getBlockRange(Slot(3), 2, blocks.toOpenArray(0, 1)) == 2
|
dag.getBlockRange(Slot(3), 2, blocks.toOpenArray(0, 1)) == 2
|
||||||
blocks[2..<2].len == 0
|
blocks[2..<2].len == 0
|
||||||
|
|
Loading…
Reference in New Issue