Created
September 26, 2020 23:16
-
-
Save yatender-oktalk/0598b69ba45b0dcb7029363ae1f406e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ExChain.BlockchainTest do | |
@moduledoc """ | |
This module contains test related to a blockchain | |
""" | |
use ExUnit.Case | |
alias ExChain.Blockchain | |
alias ExChain.Blockchain.Block | |
describe "Blockchain" do | |
setup [:initialize_blockchain] | |
test "should start with the genesis block", %{blockchain: blockchain} do | |
assert %Block{ | |
data: "genesis data", | |
hash: "F277BF9150CD035D55BA5B48CB5BCBE8E564B134E5AD0D56E439DD04A1528D3B", | |
last_hash: "-", | |
timestamp: 1_599_909_623_805_627 | |
} == hd(blockchain.chain) | |
end | |
test "adds a new block", %{blockchain: blockchain} do | |
data = "foo" | |
blockchain = Blockchain.add_block(blockchain, data) | |
[_, block] = blockchain.chain | |
assert block.data == data | |
end | |
end | |
defp initialize_blockchain(context), do: Map.put(context, :blockchain, Blockchain.new()) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment