blob: 248a37f649b12031b6ed2a099dc09821ce164587 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
defmodule ShardTest.MklTree do
use ExUnit.Case
doctest Shard.Application
test "merkle tree" do
alias SData.MerkleTree, as: MT
nblk = 14119
{:ok, path} = Briefly.create
fh = File.open!(path, [:write])
hashes = for i <- 0..nblk do
block = :enacl.randombytes 4096
:file.write(fh, block)
:crypto.hash(:sha256, block)
end
lastblock = :enacl.randombytes 128
:file.write(fh, lastblock)
hashes = hashes ++ [:crypto.hash(:sha256, lastblock)]
:file.close fh
mt = MT.create(path)
hashes2 = 0..(nblk+1) |> Enum.map(&(MT.get(mt, &1)))
assert hashes == hashes2
end
end
|