Sets up calculating number of cells in a slot

This commit is contained in:
benbierens 2023-11-20 14:41:29 +01:00 committed by Dmitriy Ryajov
parent 57f678bbf3
commit fc6ce6491c
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 46 additions and 3 deletions

View File

@ -0,0 +1,9 @@
import ../contracts/requests
const
# Size of a cell.
# A cell is a sample of storage-data selected for proving.
CellSize* = u256(2048)
proc getNumberOfCellsInSlot*(slot: Slot): Uint256 =
slot.request.ask.slotSize div CellSize

View File

@ -18,6 +18,10 @@ import pkg/codex/stores
import pkg/codex/blocktype as bt import pkg/codex/blocktype as bt
import pkg/codex/clock import pkg/codex/clock
import pkg/codex/utils/asynciter import pkg/codex/utils/asynciter
import pkg/codex/contracts/requests
import pkg/codex/contracts
import pkg/codex/proof/datasampler
import ../helpers import ../helpers
import ../examples import ../examples
@ -25,9 +29,31 @@ import ../examples
let let
bytesPerBlock = 64 * 1024 bytesPerBlock = 64 * 1024
numberOfSlotBlocks = 10 numberOfSlotBlocks = 10
slot = Slot(
request: StorageRequest(
client: Address.example,
ask: StorageAsk(
slots: 10,
slotSize: u256(bytesPerBlock * numberOfSlotBlocks),
duration: UInt256.example,
proofProbability: UInt256.example,
reward: UInt256.example,
collateral: UInt256.example,
maxSlotLoss: 123.uint64
),
content: StorageContent(
cid: "cidstringtodo",
erasure: StorageErasure(),
por: StoragePoR()
),
expiry: UInt256.example,
nonce: Nonce.example
),
slotIndex: u256(3)
)
asyncchecksuite "Test proof datasampler": asyncchecksuite "Test proof datasampler":
let chunker = RandomChunker.new(Rng.instance(), let chunker = RandomChunker.new(rng.Rng.instance(),
size = bytesPerBlock * numberOfSlotBlocks, size = bytesPerBlock * numberOfSlotBlocks,
chunkSize = bytesPerBlock) chunkSize = bytesPerBlock)
@ -43,5 +69,13 @@ asyncchecksuite "Test proof datasampler":
setup: setup:
await createSlotBlocks() await createSlotBlocks()
test "Should pass": test "Should calculate total number of cells in Slot":
check true let
slotSizeInBytes = slot.request.ask.slotSize
expectedNumberOfCells = slotSizeInBytes div CellSize
check:
expectedNumberOfCells == 320
expectedNumberOfCells == getNumberOfCellsInSlot(slot)