<commit_before>-module(aec_chain_tests).

-include_lib("eunit/include/eunit.hrl").
-include("common.hrl").
-include("blocks.hrl").

genesis_block() ->
    aec_block_genesis:genesis_block_as_deserialized_from_network().

top_test_() ->
    {foreach,
     fun() ->
             {ok, _} = aec_chain:start_link(genesis_block()),
             {ok, _} = aec_state:start_link(),
             ok
     end,
     fun(_) ->
             ok = aec_state:stop(),
             ok = aec_chain:stop()
     end,
     [{"Initialize chain with genesis block, then check top block with related state trees",
       fun() ->
               GB = genesis_block(),
               ?assertEqual({ok, GB}, aec_chain:top_block()),

               {ok, Top} = aec_chain:top(),
               %% Check block apart from state trees.
               ?assertEqual(GB, Top#block{trees = GB#block.trees}),
               %% Check state trees in block.
               _ = Top#block.trees %% TODO Check.
       end}]}.

genesis_test_() ->
    {setup,
     fun() ->
             {ok, _} = aec_chain:start_link(genesis_block()),
             {ok, _} = aec_state:start_link(),
             ok
     end,
     fun(_) ->
             ok = aec_state:stop(),
             ok = aec_chain:stop()
     end,
     fun() -><commit_msg>Check state trees at initialization<commit_after>-module(aec_chain_tests).

-include_lib("eunit/include/eunit.hrl").
-include("common.hrl").
-include("blocks.hrl").

genesis_block() ->
    aec_block_genesis:genesis_block_as_deserialized_from_network().

top_test_() ->
    {foreach,
     fun() ->
             {ok, _} = aec_chain:start_link(genesis_block()),
             {ok, _} = aec_state:start_link(),
             ok
     end,
     fun(_) ->
             ok = aec_state:stop(),
             ok = aec_chain:stop()
     end,
     [{"Initialize chain with genesis block, then check top block with related state trees",
       fun() ->
               GB = genesis_block(),
               ?assertEqual({ok, GB}, aec_chain:top_block()),

               {ok, Top} = aec_chain:top(),
               %% Check block apart from state trees.
               ?assertEqual(GB,
                            aec_blocks:set_trees(Top, aec_blocks:trees(GB))),
               %% Check state trees in block.
               ?assertEqual(aec_blocks:trees(aec_block_genesis:genesis_block()),
                            aec_blocks:trees(Top))
       end}]}.

genesis_test_() ->
    {setup,
     fun() ->
             {ok, _} = aec_chain:start_link(genesis_block()),
             {ok, _} = aec_state:start_link(),
             ok
     end,
     fun(_) ->
             ok = aec_state:stop(),
             ok = aec_chain:stop()
     end,
     fun() ->
{'fraction_non_alphanumeric': 0.14169741697416974, 'fraction_numerical': 0.0, 'mean_word_length': 1.844700944386149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2870659', 'n_tokens_mistral': 871, 'n_tokens_neox': 842, 'n_words': 157}