mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-03 08:34:37 +00:00
Adds check that block size is a multiple of cell size
This commit is contained in:
parent
eead39ba1c
commit
fd156e9cf8
@ -30,7 +30,10 @@ proc new*(
|
||||
return failure("Can only create SlotBuilder using protected manifests.")
|
||||
|
||||
if (manifest.blocksCount mod manifest.ecK) != 0:
|
||||
return failure("Number of blocks must be devisable by number of slots.")
|
||||
return failure("Number of blocks must be divisable by number of slots.")
|
||||
|
||||
if (manifest.blockSize.int mod CellSize) != 0:
|
||||
return failure("Block size must be divisable by cell size.")
|
||||
|
||||
let numberOfSlotBlocks = manifest.blocksCount div manifest.ecK
|
||||
success(SlotBuilder(
|
||||
|
@ -96,6 +96,21 @@ asyncchecksuite "Slot builder":
|
||||
check:
|
||||
SlotBuilder.new(localStore, mismatchManifest).isErr
|
||||
|
||||
test "Block size must be divisable by cell size":
|
||||
let mismatchManifest = Manifest.new(
|
||||
manifest = Manifest.new(
|
||||
treeCid = Cid.example,
|
||||
blockSize = (blockSize - 1).NBytes,
|
||||
datasetSize = (datasetSize - numberOfDatasetBlocks).NBytes),
|
||||
treeCid = Cid.example,
|
||||
datasetSize = (datasetSize - numberOfDatasetBlocks).NBytes,
|
||||
ecK = numberOfSlots,
|
||||
ecM = 0
|
||||
)
|
||||
|
||||
check:
|
||||
SlotBuilder.new(localStore, mismatchManifest).isErr
|
||||
|
||||
proc getNextPowerOfTwo(i: int): int =
|
||||
if i < 1:
|
||||
return 1
|
||||
@ -178,5 +193,3 @@ asyncchecksuite "Slot builder":
|
||||
# 1 pad block
|
||||
slotTree.getLeafCid(numberOfSlotBlocks).tryget() == expectedEmptyCid
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user