mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-11 18:03:09 +00:00
Implements getting treeCID from slot
This commit is contained in:
parent
7a47fb6e5d
commit
f767d2b4d0
@ -2,15 +2,29 @@ import std/bitops
|
||||
import std/sugar
|
||||
|
||||
import pkg/chronos
|
||||
import pkg/chronicles
|
||||
import pkg/libp2p
|
||||
import pkg/questionable
|
||||
import pkg/questionable/results
|
||||
|
||||
import ../contracts/requests
|
||||
import ../stores/blockstore
|
||||
import ../manifest
|
||||
|
||||
proc getTreeCidForSlot*(slot: Slot, blockstore: BlockStore): Future[?!Cid] {.async.} =
|
||||
raiseAssert("a")
|
||||
without manifestBlockCid =? Cid.init(slot.request.content.cid).mapFailure, err:
|
||||
error "Unable to init CID from slot.content.cid"
|
||||
return failure err
|
||||
|
||||
without manifestBlock =? await blockstore.getBlock(manifestBlockCid), err:
|
||||
error "Failed to fetch manifest block", cid = manifestBlockCid
|
||||
return failure err
|
||||
|
||||
without manifest =? Manifest.decode(manifestBlock):
|
||||
error "Unable to decode manifest"
|
||||
return failure("Unable to decode manifest")
|
||||
|
||||
return success(manifest.treeCid)
|
||||
|
||||
proc getSlotBlock*(slot: Slot, blockstore: BlockStore, treeCid: Cid, slotBlockIndex: int): Future[?!Block] {.async.} =
|
||||
raiseAssert("a")
|
||||
|
||||
@ -41,6 +41,8 @@ asyncchecksuite "Test slotblocks":
|
||||
treeCid = Cid.example,
|
||||
blockSize = 1.MiBs,
|
||||
datasetSize = 100.MiBs)
|
||||
|
||||
var
|
||||
manifestBlock = bt.Block.new(manifest.encode().tryGet(), codec = DagPBCodec).tryGet()
|
||||
slot = Slot(
|
||||
request: StorageRequest(
|
||||
@ -67,7 +69,8 @@ asyncchecksuite "Test slotblocks":
|
||||
# break
|
||||
# slotBlocks.add(bt.Block.new(chunk).tryGet())
|
||||
|
||||
# setup:
|
||||
setup:
|
||||
discard await localStore.putBlock(manifestBlock)
|
||||
# await createSlotBlocks()
|
||||
|
||||
test "Can get tree root for slot":
|
||||
@ -75,3 +78,29 @@ asyncchecksuite "Test slotblocks":
|
||||
|
||||
check:
|
||||
cid == manifest.treeCid
|
||||
|
||||
test "Can fail to get tree root for invalid cid":
|
||||
slot.request.content.cid = "invalid"
|
||||
let cid = (await getTreeCidForSlot(slot, localStore))
|
||||
|
||||
check:
|
||||
cid.isErr
|
||||
|
||||
test "Can fail to get tree root when manifest block not found":
|
||||
let
|
||||
emptyStore = CacheStore.new()
|
||||
cid = (await getTreeCidForSlot(slot, emptyStore))
|
||||
|
||||
check:
|
||||
cid.isErr
|
||||
|
||||
test "Can fail to get tree root when manifest fails to decode":
|
||||
manifestBlock.data = @[]
|
||||
|
||||
let cid = (await getTreeCidForSlot(slot, localStore))
|
||||
|
||||
check:
|
||||
cid.isErr
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user