Add root hash to Merkle DAG
This commit is contained in:
parent
c795c698fe
commit
ecc4e50d28
|
@ -4,5 +4,6 @@ description = "Dagger Storage Network"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
requires "nim >= 1.4.2 & < 2.0.0"
|
requires "nim >= 1.4.2 & < 2.0.0"
|
||||||
|
requires "libp2p >= 0.0.2 & < 0.1.0"
|
||||||
requires "chronos >= 2.5.2 & < 3.0.0"
|
requires "chronos >= 2.5.2 & < 3.0.0"
|
||||||
requires "asynctest >= 0.2.1 & < 0.3.0"
|
requires "asynctest >= 0.2.1 & < 0.3.0"
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
import pkg/libp2p/multihash
|
||||||
|
|
||||||
|
export multihash
|
||||||
|
|
||||||
type
|
type
|
||||||
MerkleDag* = object
|
MerkleDag* = object
|
||||||
data*: seq[byte]
|
data*: seq[byte]
|
||||||
|
|
||||||
|
proc rootHash*(dag: MerkleDag): MultiHash =
|
||||||
|
MultiHash.digest("sha2-256", dag.data).get()
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import std/unittest
|
||||||
|
import pkg/dagger/merkledag
|
||||||
|
|
||||||
|
suite "Merkle DAG":
|
||||||
|
|
||||||
|
test "has a root hash":
|
||||||
|
let dag1 = MerkleDag(data: @[1'u8, 2'u8, 3'u8])
|
||||||
|
let dag2 = MerkleDag(data: @[4'u8, 5'u8, 6'u8])
|
||||||
|
let dag3 = MerkleDag(data: @[4'u8, 5'u8, 6'u8])
|
||||||
|
check dag1.rootHash != dag2.rootHash
|
||||||
|
check dag2.rootHash == dag3.rootHash
|
|
@ -1,3 +1,4 @@
|
||||||
|
import ./dagger/testMerkleDag
|
||||||
import ./dagger/testChunking
|
import ./dagger/testChunking
|
||||||
import ./dagger/testDagger
|
import ./dagger/testDagger
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue