reorg files and fix tests
This commit is contained in:
parent
1c05554f7c
commit
1834d298c9
|
@ -1,12 +0,0 @@
|
|||
## Nim-Dagger
|
||||
## Copyright (c) 2021 Status Research & Development GmbH
|
||||
## Licensed under either of
|
||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||
## at your option.
|
||||
## This file may not be copied, modified, or distributed except according to
|
||||
## those terms.
|
||||
|
||||
import ./blockstream/[blockstream, chunkedblockstream]
|
||||
|
||||
export blockstream, chunkedblockstream
|
|
@ -35,6 +35,17 @@ func new*(
|
|||
data: @data)
|
||||
|
||||
func new*(
|
||||
T: type Block,
|
||||
data: openArray[byte] = [],
|
||||
version = CIDv1,
|
||||
hcodec = multiCodec("sha2-256"),
|
||||
codec = multiCodec("raw")): ?!T =
|
||||
let hash = MultiHash.digest($hcodec, data).get()
|
||||
success Block(
|
||||
cid: Cid.init(version, codec, hash).get(),
|
||||
data: @data)
|
||||
|
||||
proc new*(
|
||||
T: type Block,
|
||||
cid: Cid,
|
||||
data: openArray[byte] = [],
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
## Nim-Dagger
|
||||
## Copyright (c) 2021 Status Research & Development GmbH
|
||||
## Licensed under either of
|
||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||
## at your option.
|
||||
## This file may not be copied, modified, or distributed except according to
|
||||
## those terms.
|
||||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import pkg/questionable
|
||||
import pkg/questionable/results
|
||||
|
||||
import ./blockstream
|
||||
import ./chunker
|
||||
|
||||
type
|
||||
ChunkedBlockStreamRef* = ref object of BlockStreamRef
|
||||
chunker*: Chunker
|
||||
|
||||
method nextBlock*(c: ChunkedBlockStreamRef): ?!Block =
|
||||
let data: seq[byte] = c.chunker.getBytes()
|
||||
if data.len > 0:
|
||||
return success Block.new(data)
|
||||
|
||||
proc new*(T: type ChunkedBlockStreamRef, chunker: Chunker): T =
|
||||
T(chunker: chunker)
|
|
@ -26,9 +26,7 @@ proc hashBytes*(mh: MultiHash): seq[byte] =
|
|||
mh.data.buffer[mh.dpos..(mh.dpos + mh.size - 1)]
|
||||
|
||||
proc hashBytes*(b: Block): seq[byte] =
|
||||
without mh =? b.cid.mhash:
|
||||
return
|
||||
|
||||
if mh =? b.cid.mhash:
|
||||
mh.hashBytes()
|
||||
|
||||
method nextBlock*(d: BlockSetRef): ?!Block =
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import std/sequtils
|
||||
|
||||
import pkg/chronos
|
||||
import pkg/asynctest
|
||||
import pkg/stew/results
|
||||
import pkg/dagger/chunker
|
||||
import pkg/dagger/merkletree
|
||||
import pkg/stew/byteutils
|
||||
import pkg/dagger/p2p/rng
|
||||
import pkg/dagger/blocktype as bt
|
||||
|
||||
suite "Data set":
|
||||
|
||||
test "Make from Blocks":
|
||||
let
|
||||
chunker = newRandomChunker(Rng.instance(), size = 256*3, chunkSize = 256)
|
||||
blocks = chunker.mapIt( bt.Block.new(it) )
|
||||
|
||||
let merkle = MerkleTreeRef.fromBlocks(blocks)
|
||||
|
Loading…
Reference in New Issue