removing old tests

This commit is contained in:
Dmitriy Ryajov 2024-01-16 19:24:36 -06:00
parent 9fc10a5e85
commit cfa927b444
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 0 additions and 354 deletions

View File

@ -1,329 +0,0 @@
# import std/sequtils
# import std/sugar
# import std/random
# import pkg/questionable/results
# import pkg/constantine/math/arithmetic
# import pkg/constantine/math/io/io_fields
# import pkg/poseidon2/types
# import pkg/poseidon2/io
# import pkg/poseidon2
# import pkg/chronos
# import pkg/asynctest
# import pkg/codex/stores/cachestore
# import pkg/codex/chunker
# import pkg/codex/stores
# import pkg/codex/blocktype as bt
# import pkg/codex/contracts/requests
# import pkg/codex/contracts
# import pkg/codex/merkletree
# import pkg/codex/stores/cachestore
# import pkg/codex/slots
# import pkg/codex/proof/misc
# import pkg/codex/proof/types
# import ../helpers
# import ../examples
# import testdatasampler_expected
# let
# bytesPerBlock = 64 * 1024
# challenge: FieldElement = toF(12345)
# datasetRootHash: FieldElement = toF(6789)
# asyncchecksuite "Test proof datasampler - components":
# let
# numberOfSlotBlocks = 16
# slot = Slot(
# request: StorageRequest(
# ask: StorageAsk(
# slots: 10,
# slotSize: u256(bytesPerBlock * numberOfSlotBlocks),
# ),
# content: StorageContent(
# cid: $Cid.example
# )
# ),
# slotIndex: u256(3)
# )
# test "Number of cells is a power of two":
# # This is to check that the data used for testing is sane.
# proc isPow2(value: int): bool =
# let log2 = ceilingLog2(value)
# return (1 shl log2) == value
# let numberOfCells = getNumberOfCellsInSlot(slot).int
# check:
# isPow2(numberOfCells)
# test "Extract low bits":
# proc extract(value: uint64, nBits: int): uint64 =
# let big = toF(value).toBig()
# return extractLowBits(big, nBits)
# check:
# extract(0x88, 4) == 0x8.uint64
# extract(0x88, 7) == 0x8.uint64
# extract(0x9A, 5) == 0x1A.uint64
# extract(0x9A, 7) == 0x1A.uint64
# extract(0x1248, 10) == 0x248.uint64
# extract(0x1248, 12) == 0x248.uint64
# extract(0x1248306A560C9AC0.uint64, 10) == 0x2C0.uint64
# extract(0x1248306A560C9AC0.uint64, 12) == 0xAC0.uint64
# extract(0x1248306A560C9AC0.uint64, 50) == 0x306A560C9AC0.uint64
# extract(0x1248306A560C9AC0.uint64, 52) == 0x8306A560C9AC0.uint64
# test "Should calculate total number of cells in Slot":
# let
# slotSizeInBytes = (slot.request.ask.slotSize).truncate(uint64)
# expectedNumberOfCells = slotSizeInBytes div CellSize
# check:
# expectedNumberOfCells == 512
# expectedNumberOfCells == getNumberOfCellsInSlot(slot)
# asyncchecksuite "Test proof datasampler - main":
# let
# # The number of slot blocks and number of slots, combined with
# # the bytes per block, make it so that there are exactly 256 cells
# # in the dataset.
# numberOfSlotBlocks = 4
# totalNumberOfSlots = 2
# datasetSlotIndex = 1
# localStore = CacheStore.new()
# datasetToSlotProof = MerkleProof.example
# var
# manifest: Manifest
# manifestBlock: bt.Block
# slot: Slot
# datasetBlocks: seq[bt.Block]
# slotPoseidonTree: MerkleTree
# dataSampler: DataSampler
# proc createDatasetBlocks(): Future[void] {.async.} =
# let numberOfCellsNeeded = (numberOfSlotBlocks * totalNumberOfSlots * bytesPerBlock).uint64 div CellSize
# var data: seq[byte] = @[]
# # This generates a number of blocks that have different data, such that
# # Each cell in each block is unique, but nothing is random.
# for i in 0 ..< numberOfCellsNeeded:
# data = data & (i.byte).repeat(CellSize)
# let chunker = MockChunker.new(
# dataset = data,
# chunkSize = bytesPerBlock)
# while true:
# let chunk = await chunker.getBytes()
# if chunk.len <= 0:
# break
# let b = bt.Block.new(chunk).tryGet()
# datasetBlocks.add(b)
# discard await localStore.putBlock(b)
# proc createManifest(): Future[void] {.async.} =
# let
# cids = datasetBlocks.mapIt(it.cid)
# tree = MerkleTree.init(cids).tryGet()
# treeCid = tree.rootCid().tryGet()
# for index, cid in cids:
# let proof = tree.getProof(index).tryget()
# discard await localStore.putBlockCidAndProof(treeCid, index, cid, proof)
# manifest = Manifest.new(
# treeCid = treeCid,
# blockSize = bytesPerBlock.NBytes,
# datasetSize = (bytesPerBlock * numberOfSlotBlocks * totalNumberOfSlots).NBytes)
# manifestBlock = bt.Block.new(manifest.encode().tryGet(), codec = DagPBCodec).tryGet()
# proc createSlot(): void =
# slot = Slot(
# request: StorageRequest(
# ask: StorageAsk(
# slotSize: u256(bytesPerBlock * numberOfSlotBlocks)
# ),
# content: StorageContent(
# cid: $manifestBlock.cid
# ),
# ),
# slotIndex: u256(datasetSlotIndex)
# )
# proc createSlotPoseidonTree(): void =
# let
# slotSize = slot.request.ask.slotSize.truncate(uint64)
# blocksInSlot = slotSize div bytesPerBlock.uint64
# datasetSlotIndex = slot.slotIndex.truncate(uint64)
# datasetBlockIndexFirst = datasetSlotIndex * blocksInSlot
# datasetBlockIndexLast = datasetBlockIndexFirst + numberOfSlotBlocks.uint64
# slotBlocks = datasetBlocks[datasetBlockIndexFirst ..< datasetBlockIndexLast]
# slotBlockCids = slotBlocks.mapIt(it.cid)
# slotPoseidonTree = MerkleTree.init(slotBlockCids).tryGet()
# proc createDataSampler(): Future[void] {.async.} =
# dataSampler = (await DataSampler.new(
# slot,
# localStore,
# datasetRootHash,
# slotPoseidonTree,
# datasetToSlotProof
# )).tryGet()
# setup:
# await createDatasetBlocks()
# await createManifest()
# createSlot()
# discard await localStore.putBlock(manifestBlock)
# createSlotPoseidonTree()
# await createDataSampler()
# test "Number of cells is a power of two":
# # This is to check that the data used for testing is sane.
# proc isPow2(value: int): bool =
# let log2 = ceilingLog2(value)
# return (1 shl log2) == value
# let numberOfCells = getNumberOfCellsInSlot(slot).int
# check:
# isPow2(numberOfCells)
# let knownIndices = @[74.uint64, 41.uint64, 51.uint64]
# test "Can find single slot-cell index":
# proc slotCellIndex(i: int): uint64 =
# let counter: FieldElement = toF(i)
# return dataSampler.findSlotCellIndex(challenge, counter)
# proc getExpectedIndex(i: int): uint64 =
# let
# numberOfCellsInSlot = (bytesPerBlock * numberOfSlotBlocks) div CellSize.int
# slotRootHash = toF(1234) # TODO - replace with slotPoseidonTree.root when it is a poseidon tree.
# hash = Sponge.digest(@[slotRootHash, challenge, toF(i)], rate = 2)
# return extractLowBits(hash.toBig(), ceilingLog2(numberOfCellsInSlot))
# check:
# slotCellIndex(1) == getExpectedIndex(1)
# slotCellIndex(1) == knownIndices[0]
# slotCellIndex(2) == getExpectedIndex(2)
# slotCellIndex(2) == knownIndices[1]
# slotCellIndex(3) == getExpectedIndex(3)
# slotCellIndex(3) == knownIndices[2]
# test "Can find sequence of slot-cell indices":
# proc slotCellIndices(n: int): seq[uint64] =
# dataSampler.findSlotCellIndices(challenge, n)
# proc getExpectedIndices(n: int): seq[uint64] =
# return collect(newSeq, (for i in 1..n: dataSampler.findSlotCellIndex(challenge, toF(i))))
# check:
# slotCellIndices(3) == getExpectedIndices(3)
# slotCellIndices(3) == knownIndices
# let
# bytes = newSeqWith(bytesPerBlock, rand(uint8))
# blk = bt.Block.new(bytes).tryGet()
# cell0Bytes = bytes[0..<CellSize]
# cell1Bytes = bytes[CellSize..<(CellSize*2)]
# cell2Bytes = bytes[(CellSize*2)..<(CellSize*3)]
# test "Can get cell from block":
# let
# sample0 = dataSampler.getCellFromBlock(blk, 0)
# sample1 = dataSampler.getCellFromBlock(blk, 1)
# sample2 = dataSampler.getCellFromBlock(blk, 2)
# check:
# sample0 == cell0Bytes
# sample1 == cell1Bytes
# sample2 == cell2Bytes
# test "Can convert block into cells":
# let cells = dataSampler.getBlockCells(blk)
# check:
# cells.len == (bytesPerBlock div CellSize.int)
# cells[0] == cell0Bytes
# cells[1] == cell1Bytes
# cells[2] == cell2Bytes
# test "Can create mini tree for block cells":
# let miniTree = dataSampler.getBlockCellMiniTree(blk).tryGet()
# let
# cell0Proof = miniTree.getProof(0).tryGet()
# cell1Proof = miniTree.getProof(1).tryGet()
# cell2Proof = miniTree.getProof(2).tryGet()
# check:
# cell0Proof.verifyDataBlock(cell0Bytes, miniTree.root).tryGet()
# cell1Proof.verifyDataBlock(cell1Bytes, miniTree.root).tryGet()
# cell2Proof.verifyDataBlock(cell2Bytes, miniTree.root).tryGet()
# test "Can gather proof input":
# # This is the main entry point for this module, and what it's all about.
# let
# nSamples = 3
# input = (await dataSampler.getProofInput(challenge, nSamples)).tryget()
# proc equal(a: FieldElement, b: FieldElement): bool =
# a.toDecimal() == b.toDecimal()
# proc toStr(proof: MerkleProof): string =
# toHex(proof.nodesBuffer)
# let
# expectedMerkleProofs = getExpectedSlotToBlockProofs()
# expectedCellData = getExpectedCellData()
# check:
# # datasetRoot*: FieldElement
# equal(input.datasetRoot, datasetRootHash)
# # entropy*: FieldElement
# equal(input.entropy, challenge)
# # numberOfCellsInSlot*: uint64
# input.numberOfCellsInSlot == (bytesPerBlock * numberOfSlotBlocks).uint64 div CellSize
# # numberOfSlots*: uint64
# input.numberOfSlots == slot.request.ask.slots
# # datasetSlotIndex*: uint64
# input.datasetSlotIndex == slot.slotIndex.truncate(uint64)
# # slotRoot*: FieldElement
# equal(input.slotRoot, toF(1234)) # TODO - when slotPoseidonTree is a poseidon tree, its root should be a FieldElement.
# # datasetToSlotProof*: MerkleProof
# input.datasetToSlotProof == datasetToSlotProof
# # proofSamples*: seq[ProofSample]
# toStr(input.proofSamples[0].merkleProof) == expectedMerkleProofs[0]
# toStr(input.proofSamples[1].merkleProof) == expectedMerkleProofs[1]
# toStr(input.proofSamples[2].merkleProof) == expectedMerkleProofs[2]
# # cell data
# toHex(input.proofSamples[0].cellData) == expectedCellData[0]
# toHex(input.proofSamples[1].cellData) == expectedCellData[1]
# toHex(input.proofSamples[2].cellData) == expectedCellData[2]
# # input.slotToBlockProofs.mapIt(toStr(it)) == expectedSlotToBlockProofs
# # input.blockToCellProofs.mapIt(toStr(it)) == expectedBlockToCellProofs
# # toHex(input.sampleData) == expectedSampleData
# for (input, expected) in [(10, 0), (31, 0), (32, 1), (63, 1), (64, 2)]:
# test "Can get slotBlockIndex from slotCellIndex (" & $input & " -> " & $expected & ")":
# let
# slotCellIndex = input.uint64
# slotBlockIndex = dataSampler.getSlotBlockIndexForSlotCellIndex(slotCellIndex)
# check:
# slotBlockIndex == expected.uint64
# for (input, expected) in [(10, 10), (31, 31), (32, 0), (63, 31), (64, 0)]:
# test "Can get blockCellIndex from slotCellIndex (" & $input & " -> " & $expected & ")":
# let
# slotCellIndex = input.uint64
# blockCellIndex = dataSampler.getBlockCellIndexForSlotCellIndex(slotCellIndex)
# check:
# blockCellIndex == expected.uint64

View File

@ -1,25 +0,0 @@
# Snapshot of expected values for testdatasampler.
import std/strutils
import pkg/codex/proof/types
# proc getExpectedBlockToCellProofs*(): seq[string] =
# @[
# "43AAA4A0B89548E8694C5C266BEBCC7BD0758F25005E606EDF559536D2227A7261CD0E8636D0CA8B899A070ABA5D9F815C6678877FAF71B984F5CF15300357E1C4C4A35D47EB0BECF6FB31E6C33CDB8A04D7EA0B29C2021678361F27CFBC96B355B36B13CC749463F14A7A0452A2F765E5951547B16CFB53D3824888226EE5D7FDB433239D7F55029C2C97C635A6B1214D1257C7D85C1C649758BA1AF8700E24",
# "F5D40D9722D943D936AF8EFDE070C5E5D8BD0EC57A89F7BF0AA864DCD8BC77D9D8BC10DDDEB897A82318994242DCF2E07BC631B063DD6F9D4D13133FDED2127DC5840256978CA55F93AF0D6C730660813CF6A29C9B0C0153C8E01D152196A03E94AF1258C023CC638A060314259FA97B5CB743CBCE7AA483839BEA37DB71DF97C4F0DD83C0F38D791C75A1406EC9CFC212E7B302508CDD5780728B55CD5F132E",
# "BB4E5BB9F2E0E104F04E2F49D8D39A9259C1419252A0B1150D9F0FE077A2A2258F594C0DC1A29099A3E3AAEB21C0BF00823383FC06F8A09C25462FC2DA11D51EAD968AA8200FBEA0A62FA1F83A46B3EA5D24859FF028351BEB15EA4D94F987D0CCD48366D7038EF9B0BD35FE287E111DB85A19F0E82E93CB9D40423776164D72332992C2849E7EF3AC7685A8DB37F3C44EFF9366BFE3F5FD80AF2B047C62E4A0"
# ]
proc getExpectedSlotToBlockProofs*(): seq[string] =
@[
"9863C3BE0A21CC49A03E3E7B4A134CBBE1F7A241EB61BFAE7478080A4B84E338EC99F9EE1D95A2F6126CE5FD7476E85790A95E03F4D9B63B827854CFF55F1E5236CA91969A70839AF19329616627803B29EA52185FFA8AE50FCC84C0BA8C69C4BA43F4397D2D50DD2982EDC3AF08E4762F34958645DC4749265DA9FC89874A86FFCEAB3B21F48386C75FCDA49656FE73F15C0E4AEE84479A880CA74817861A93",
"1F6B7B8B46ACE123F53BBFBF96999B7EED1A4F07D2BA2831AF8855B312260D39D4E9996BD5F7FD83E293168DEC32B57AD08A54D38A748DD46FD21D2685A194087237F6493DD03FBA989C356E9BD35CF1E833E66E6FF06C212FF5FCB603E59AA762A338CE5CE3BD68D68E4A4A6C799FF935F3829085C86E07A12B27278E7A5AAD77CDFAD51D9B8B13C44646E01450D2140924211CBE62520B7C4916C4E4C955F5",
"F2972FCDA69A1FF6B71BD487618FF1AB871C4D4861724F1B01574E414EB3C1D761CD0E8636D0CA8B899A070ABA5D9F815C6678877FAF71B984F5CF15300357E1C4C4A35D47EB0BECF6FB31E6C33CDB8A04D7EA0B29C2021678361F27CFBC96B355B36B13CC749463F14A7A0452A2F765E5951547B16CFB53D3824888226EE5D7FDB433239D7F55029C2C97C635A6B1214D1257C7D85C1C649758BA1AF8700E24"
]
proc getExpectedCellData*(): seq[string] =
@[
"CA".repeat(CellSize),
"A9".repeat(CellSize),
"B3".repeat(CellSize)
]