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