Skip to content

Commit

Permalink
Fix tests on CI with more determinism (#290)
Browse files Browse the repository at this point in the history
* Make the DB test non-async to fix CI

* Remove match of the GenServer startup return for KVs

* Make tests with date more deterministic

* Unify test setup

* Fix race condition in time based tests

* Let validation nodes notify previous storage nodes

* Disable bloom filters causing issues as false negatives
  • Loading branch information
Samuel committed Apr 28, 2022
1 parent 2d3bb24 commit 906ff03
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 85 deletions.
3 changes: 0 additions & 3 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ config :archethic, ArchEthic.Crypto.KeystoreLoader, enabled: false
config :archethic, MockCrypto, enabled: false

config :archethic, ArchEthic.DB, MockDB

config :archethic, ArchEthic.DB.CassandraImpl, host: "127.0.0.1:9042"

config :archethic, MockDB, enabled: false

config :archethic, ArchEthic.Election.Constraints, enabled: false
Expand Down
7 changes: 4 additions & 3 deletions lib/archethic/beacon_chain/summary_timer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ defmodule ArchEthic.BeaconChain.SummaryTimer do
@doc """
Return the next summary times from a date until now
"""
@spec next_summaries(DateTime.t()) :: Enumerable.t() | list(DateTime.t())
def next_summaries(date_from = %DateTime{}) do
@spec next_summaries(from :: DateTime.t(), to :: DateTime.t()) ::
Enumerable.t() | list(DateTime.t())
def next_summaries(date_from = %DateTime{}, date_to = %DateTime{} \\ DateTime.utc_now()) do
get_interval()
|> CronParser.parse!(true)
|> CronScheduler.get_next_run_dates(date_from |> DateTime.to_naive())
|> Stream.take_while(fn datetime ->
datetime
|> DateTime.from_naive!("Etc/UTC")
|> DateTime.compare(DateTime.utc_now()) == :lt
|> DateTime.compare(date_to) == :lt
end)
|> Stream.map(&DateTime.from_naive!(&1, "Etc/UTC"))
end
Expand Down
6 changes: 3 additions & 3 deletions lib/archethic/db/embedded_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule ArchEthic.DB.EmbeddedImpl do
genesis_address = Transaction.previous_address(first_tx)

Enum.each(sorted_chain, fn tx ->
unless ChainIndex.transaction_exists?(tx.address) do
unless ChainIndex.transaction_exists?(tx.address, db_path()) do
ChainWriter.append_transaction(genesis_address, tx)
end
end)
Expand All @@ -63,7 +63,7 @@ defmodule ArchEthic.DB.EmbeddedImpl do
"""
@spec write_transaction(Transaction.t()) :: :ok
def write_transaction(tx = %Transaction{}) do
if ChainIndex.transaction_exists?(tx.address) do
if ChainIndex.transaction_exists?(tx.address, db_path()) do
{:error, :transaction_already_exists}
else
previous_address = Transaction.previous_address(tx)
Expand All @@ -83,7 +83,7 @@ defmodule ArchEthic.DB.EmbeddedImpl do
"""
@spec transaction_exists?(address :: binary()) :: boolean()
def transaction_exists?(address) when is_binary(address) do
ChainIndex.transaction_exists?(address)
ChainIndex.transaction_exists?(address, db_path())
end

@doc """
Expand Down
55 changes: 21 additions & 34 deletions lib/archethic/db/embedded_impl/chain_index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ defmodule ArchEthic.DB.EmbeddedImpl.ChainIndex do
:ets.new(:archethic_db_last_index, [:set, :named_table, :public, read_concurrency: true])
:ets.new(:archethic_db_type_stats, [:set, :named_table, :public, read_concurrency: true])

:ets.new(:archethic_db_bloom_filters, [:set, :named_table, :public, read_concurrency: true])

fill_tables(db_path)

{:ok, %{db_path: db_path}}
end

defp fill_tables(db_path) do
Enum.each(0..255, fn subset ->
bloom_filter = BloomFilter.new(256, 0.001)
:ets.insert(:archethic_db_bloom_filters, {subset, bloom_filter})
subset_summary_filename = index_summary_path(db_path, subset)
scan_summary_table(subset_summary_filename)
end)
Expand Down Expand Up @@ -60,12 +56,6 @@ defmodule ArchEthic.DB.EmbeddedImpl.ChainIndex do
current_address = <<current_curve_id::8, current_hash_type::8, current_digest::binary>>
genesis_address = <<genesis_curve_id::8, genesis_hash_type::8, genesis_digest::binary>>

# Fill the bloom filters
<<subset::8, address_digest::binary>> = current_digest
[{_, bloom_filter}] = :ets.lookup(:archethic_db_bloom_filters, subset)
bloom_filter = BloomFilter.add(bloom_filter, address_digest)
:ets.insert(:archethic_db_bloom_filters, {subset, bloom_filter})

# Register last addresses of genesis address
true = :ets.insert(:archethic_db_last_index, {genesis_address, current_address})

Expand Down Expand Up @@ -123,7 +113,7 @@ defmodule ArchEthic.DB.EmbeddedImpl.ChainIndex do
"""
@spec add_tx(binary(), binary(), non_neg_integer(), db_path :: String.t()) :: :ok
def add_tx(
tx_address = <<_::8, _::8, subset::8, digest::binary>>,
tx_address = <<_::8, _::8, subset::8, _digest::binary>>,
genesis_address,
size,
db_path
Expand Down Expand Up @@ -154,10 +144,6 @@ defmodule ArchEthic.DB.EmbeddedImpl.ChainIndex do
{genesis_address, 0, 0}
)

[{_, bloom_filter}] = :ets.lookup(:archethic_db_bloom_filters, subset)
bloom_filter = BloomFilter.add(bloom_filter, digest)
:ets.insert(:archethic_db_bloom_filters, {subset, bloom_filter})

:ok
end

Expand Down Expand Up @@ -193,10 +179,15 @@ defmodule ArchEthic.DB.EmbeddedImpl.ChainIndex do
@doc """
Determine if a transaction exists
"""
@spec transaction_exists?(binary()) :: boolean()
def transaction_exists?(address = <<_::8, _::8, subset::8, digest::binary>>) do
[{_, bloom_filter}] = :ets.lookup(:archethic_db_bloom_filters, subset)
:ets.member(:archethic_db_tx_index, address) or BloomFilter.has?(bloom_filter, digest)
@spec transaction_exists?(binary(), String.t()) :: boolean()
def transaction_exists?(address = <<_::8, _::8, _subset::8, _digest::binary>>, db_path) do
case get_tx_entry(address, db_path) do
{:ok, _} ->
true

{:error, :not_exists} ->
false
end
end

@doc """
Expand All @@ -217,22 +208,18 @@ defmodule ArchEthic.DB.EmbeddedImpl.ChainIndex do

defp search_tx_entry(search_address = <<_::8, _::8, digest::binary>>, db_path) do
<<subset::8, _::binary>> = digest
[{_, bloom_filter}] = :ets.lookup(:archethic_db_bloom_filters, subset)

with true <- BloomFilter.has?(bloom_filter, digest),
{:ok, fd} <- File.open(index_summary_path(db_path, subset), [:binary, :read]) do
case do_search_tx_entry(fd, search_address) do
nil ->
:file.close(fd)
{:error, :not_exists}
case File.open(index_summary_path(db_path, subset), [:binary, :read]) do
{:ok, fd} ->
case do_search_tx_entry(fd, search_address) do
nil ->
:file.close(fd)
{:error, :not_exists}

{genesis_address, size, offset} ->
:file.close(fd)
{:ok, %{genesis_address: genesis_address, size: size, offset: offset}}
end
else
false ->
{:error, :not_exists}
{genesis_address, size, offset} ->
:file.close(fd)
{:ok, %{genesis_address: genesis_address, size: size, offset: offset}}
end

{:error, _} ->
{:error, :not_exists}
Expand All @@ -251,7 +238,7 @@ defmodule ArchEthic.DB.EmbeddedImpl.ChainIndex do
{:ok, <<size::32, offset::32>>} <- :file.read(fd, 8) do
current_address = <<current_curve_id::8, current_hash_type::8, current_digest::binary>>

# If it's the address we are looking for, we return the genesis address
# If it's the address we are looking for, we return the genesis address
# and the chain file seeking information
if current_address == search_address do
genesis_address = <<genesis_curve_id::8, genesis_hash_type::8, genesis_digest::binary>>
Expand Down
27 changes: 26 additions & 1 deletion lib/archethic/mining/distributed_workflow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ defmodule ArchEthic.Mining.DistributedWorkflow do
alias ArchEthic.P2P.Message.ReplicateTransaction
alias ArchEthic.P2P.Node

alias ArchEthic.Replication

alias ArchEthic.TaskSupervisor

alias ArchEthic.TransactionChain.Transaction
Expand Down Expand Up @@ -622,7 +624,10 @@ defmodule ArchEthic.Mining.DistributedWorkflow do
})

{:keep_state, %{data | context: new_context},
{:next_event, :internal, :notify_attestation}}
[
{:next_event, :internal, :notify_attestation},
{:next_event, :internal, :notify_previous_chain}
]}
else
{:keep_state, %{data | context: new_context}}
end
Expand Down Expand Up @@ -667,6 +672,26 @@ defmodule ArchEthic.Mining.DistributedWorkflow do
transaction: ValidationContext.get_validated_transaction(context)
})

:keep_state_and_data
end

def handle_event(
:internal,
:notify_previous_chain,
:replication,
_data = %{
context: %ValidationContext{
transaction: tx,
validation_stamp: %ValidationStamp{timestamp: tx_timestamp}
}
}
) do
Replication.acknowledge_previous_storage_nodes(
tx.address,
Transaction.previous_address(tx),
tx_timestamp
)

:stop
end

Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/p2p/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ defmodule ArchEthic.P2P.Message do
transaction: tx,
ack_storage?: ack_storage?
}) do
case Replication.validate_and_store_transaction_chain(tx, ack_storage?: ack_storage?) do
case Replication.validate_and_store_transaction_chain(tx) do
:ok ->
if ack_storage? do
tx_summary = TransactionSummary.from_transaction(tx)
Expand Down
13 changes: 1 addition & 12 deletions lib/archethic/replication.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ defmodule ArchEthic.Replication do
and update the internal ledger and views
Options:
- ack_storage?: Determines if the storage node must notify the welcome node and beacon chain about the replication
- self_repair?: Determines if the replication is from a self repair cycle. This switch will be determine to fetch unspent outputs or transaction inputs for a chain role validation
"""
@spec validate_and_store_transaction_chain(
validated_tx :: Transaction.t(),
options :: [ack_storage?: boolean(), self_repair?: boolean()]
options :: [self_repair?: boolean()]
) ::
:ok | {:error, :invalid_transaction} | {:error, :transaction_already_exists}
def validate_and_store_transaction_chain(
Expand Down Expand Up @@ -123,16 +122,6 @@ defmodule ArchEthic.Replication do
%{role: :chain}
)

# Notify previous pools about a new transaction in the chain
# TODO: let the validation nodes leverages this part, once they got enough confirmations
Task.start(fn ->
acknowledge_previous_storage_nodes(
address,
Transaction.previous_address(tx),
timestamp
)
end)

:ok

{:error, reason} ->
Expand Down
3 changes: 0 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ defmodule ArchEthic.MixProject do
{:ranch, "~> 2.1", override: true},
{:connection, "~> 1.1"},

# DB
{:bloom_filter, "~>1.1.0"},

# Net
{:inet_ext, "~> 1.0"},
{:inet_cidr, "~> 1.1", hex: :erl_cidr, override: true},
Expand Down
4 changes: 0 additions & 4 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"artificery": {:hex, :artificery, "0.4.3", "0bc4260f988dcb9dda4b23f9fc3c6c8b99a6220a331534fdf5bf2fd0d4333b02", [:mix], [], "hexpm", "12e95333a30e20884e937abdbefa3e7f5e05609c2ba8cf37b33f000b9ffc0504"},
"benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm", "3ad58ae787e9c7c94dd7ceda3b587ec2c64604563e049b2a0e8baafae832addb"},
"blankable": {:hex, :blankable, "1.0.0", "89ab564a63c55af117e115144e3b3b57eb53ad43ba0f15553357eb283e0ed425", [:mix], [], "hexpm", "7cf11aac0e44f4eedbee0c15c1d37d94c090cb72a8d9fddf9f7aec30f9278899"},
"bloom_filter": {:hex, :bloom_filter, "1.1.0", "f032f6f1134d68446ca01b31ea60e1529d85d1f92f0f63a9d00c827cd66ab223", [:mix], [{:fnv, "~> 0.3.2 ", [hex: :fnv, repo: "hexpm", optional: false]}, {:math, "~> 0.6", [hex: :math, repo: "hexpm", optional: false]}], "hexpm", "a3ed19e20b2f6cc6619d5dc91d4490d89ff5e74d599d0ce8f3b4e01568b003e2"},
"broadway": {:hex, :broadway, "1.0.1", "7b4ca0b439a425730b5fc1bf06aae350df6171434fd4f29bdbbe50d2d9d518fb", [:mix], [{:gen_stage, "~> 1.0", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.7", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6d1c7fdc100ba484a477c42881553dfa1730f31c461308286132efbfeb85568f"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
Expand All @@ -29,11 +28,9 @@
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"floki": {:hex, :floki, "0.32.0", "f915dc15258bc997d49be1f5ef7d3992f8834d6f5695270acad17b41f5bcc8e2", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "1c5a91cae1fd8931c26a4826b5e2372c284813904c8bacb468b5de39c7ececbd"},
"flow": {:hex, :flow, "1.1.0", "b569c1042cb2da97103f6d70a0267a5657dce1402f41b4020bef98bbef9c7c1e", [:mix], [{:gen_stage, "~> 1.0", [hex: :gen_stage, repo: "hexpm", optional: false]}], "hexpm", "066f42f7a1ea6a86cb4ef763310338981a5cfb93bcebce10863a23a4859fd785"},
"fnv": {:hex, :fnv, "0.3.2", "47c9c2933f4b16980219aef920164303c3581cd79472b5e989f59a91e20e46a2", [:mix], [{:hexate, "~> 0.5", [hex: :hexate, repo: "hexpm", optional: false]}], "hexpm", "1993ca598fe7ca402f89ed1836c4a5de320330177104ca7eaac230312e069fe5"},
"gen_stage": {:hex, :gen_stage, "1.1.2", "b1656cd4ba431ed02c5656fe10cb5423820847113a07218da68eae5d6a260c23", [:mix], [], "hexpm", "9e39af23140f704e2b07a3e29d8f05fd21c2aaf4088ff43cb82be4b9e3148d02"},
"gen_state_machine": {:hex, :gen_state_machine, "3.0.0", "1e57f86a494e5c6b14137ebef26a7eb342b3b0070c7135f2d6768ed3f6b6cdff", [:mix], [], "hexpm", "0a59652574bebceb7309f6b749d2a41b45fdeda8dbb4da0791e355dd19f0ed15"},
"git_hooks": {:hex, :git_hooks, "0.4.2", "93604c8f6dff28500aaecc1988de319308fb7aa2c27bc89460b1f48aedd8bf7a", [:mix], [{:blankable, "~> 1.0.0", [hex: :blankable, repo: "hexpm", optional: false]}, {:recase, "~> 0.6.0", [hex: :recase, repo: "hexpm", optional: false]}], "hexpm", "0e46c04847b86d88857149840a614e018d57f79ca3f3b921a93e007cbea546d4"},
"hexate": {:hex, :hexate, "0.6.1", "1cea42e462c1daa32223127d4752e71016c3d933d492b9bb7fa4709a4a0fd50d", [:mix], [], "hexpm", "667c429c0970e3097107c9fafcc645636302888388845d78a3947a739fd946b7"},
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
"inet_cidr": {:hex, :erl_cidr, "1.2.0", "9205ffb290c0de8d2b82147976602fbf5bfa6d594834e60556afaf3b82856b95", [:rebar3], [], "hexpm", "3505f5dfac7d862806c7051a3dd475363a45bccf39ca1faee8eda6a6b33cf335"},
"inet_ext": {:hex, :inet_ext, "1.0.0", "40a82557082827a2dc403ee7007bb389869f347465fb9d25d0abf0769b247c34", [:rebar3], [{:inet_cidr, "~>1.0.2", [hex: :erl_cidr, repo: "hexpm", optional: false]}], "hexpm", "62a8aad524b798de3e1617e2ccfad212cb4cce971574f1adc260441ed99a250c"},
Expand All @@ -42,7 +39,6 @@
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"math": {:hex, :math, "0.7.0", "12af548c3892abf939a2e242216c3e7cbfb65b9b2fe0d872d05c6fb609f8127b", [:mix], [], "hexpm", "7987af97a0c6b58ad9db43eb5252a49fc1dfe1f6d98f17da9282e297f594ebc2"},
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
"mint": {:hex, :mint, "1.4.0", "cd7d2451b201fc8e4a8fd86257fb3878d9e3752899eb67b0c5b25b180bde1212", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "10a99e144b815cbf8522dccbc8199d15802440fc7a64d67b6853adb6fa170217"},
"mox": {:hex, :mox, "0.5.2", "55a0a5ba9ccc671518d068c8dddd20eeb436909ea79d1799e2209df7eaa98b6c", [:mix], [], "hexpm", "df4310628cd628ee181df93f50ddfd07be3e5ecc30232d3b6aadf30bdfe6092b"},
Expand Down
3 changes: 1 addition & 2 deletions test/archethic/beacon_chain/slot_timer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ defmodule ArchEthic.BeaconChain.SlotTimerTest do

test "receive create_slot message after timer elapsed" do
{:ok, pid} = SlotTimer.start_link([interval: "*/1 * * * * * *"], [])
current = DateTime.utc_now()

send(
pid,
{:node_update, %Node{authorized?: true, first_public_key: Crypto.first_node_public_key()}}
)

current = DateTime.utc_now()

receive do
{:create_slot, time} ->
assert 1 == DateTime.diff(time, current)
Expand Down
5 changes: 2 additions & 3 deletions test/archethic/beacon_chain/summary_timer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ defmodule ArchEthic.BeaconChain.SummaryTimerTest do

property "next_summaries/1 should retrieve the next summary times from a date" do
{:ok, _pid} = SummaryTimer.start_link([interval: "* * * * * * *"], [])
ref = DateTime.utc_now() |> DateTime.truncate(:second)

check all(previous_seconds <- StreamData.positive_integer()) do
next_summaries =
SummaryTimer.next_summaries(DateTime.utc_now() |> DateTime.add(-previous_seconds))

next_summaries = SummaryTimer.next_summaries(DateTime.add(ref, -previous_seconds), ref)
assert Enum.count(next_summaries) == previous_seconds
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/archethic/db/embedded_impl/chain_index_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ defmodule ArchEthic.DB.EmbeddedImpl.ChainIndexTest do

# Remove the transaction from the cache and try the bloom filter
:ets.delete(:archethic_db_tx_index, tx_address)
assert true == ChainIndex.transaction_exists?(tx_address)
assert false == ChainIndex.transaction_exists?(:crypto.strong_rand_bytes(32))
assert true == ChainIndex.transaction_exists?(tx_address, db_path)
assert false == ChainIndex.transaction_exists?(:crypto.strong_rand_bytes(32), db_path)
end
end
end
16 changes: 3 additions & 13 deletions test/archethic/db/embedded_impl_test.exs
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
defmodule ArchEthic.DB.EmbeddedTest do
use ArchEthicCase
use ArchEthicCase, async: false

alias ArchEthic.DB.EmbeddedImpl
alias ArchEthic.DB.EmbeddedImpl.BootstrapInfo
alias ArchEthic.DB.EmbeddedImpl.Encoding
alias ArchEthic.DB.EmbeddedImpl.ChainIndex
alias ArchEthic.DB.EmbeddedImpl.ChainWriter
alias ArchEthic.DB.EmbeddedImpl.P2PView
alias ArchEthic.DB.EmbeddedImpl.StatsInfo

alias ArchEthic.TransactionChain.Transaction
alias ArchEthic.TransactionChain.Transaction.ValidationStamp
alias ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations
alias ArchEthic.TransactionFactory

setup do
db_path = Application.app_dir(:archethic, "data_test")
File.mkdir_p!(db_path)
EmbeddedImpl.Supervisor.start_link()

:persistent_term.put(:archethic_db_path, db_path)

{:ok, _} = ChainIndex.start_link(path: db_path)
{:ok, _} = ChainWriter.start_link(path: db_path)
{:ok, _} = BootstrapInfo.start_link(path: db_path)
{:ok, _} = StatsInfo.start_link(path: db_path)
{:ok, _} = P2PView.start_link(path: db_path)
db_path = EmbeddedImpl.db_path()

on_exit(fn ->
File.rm_rf!(Application.app_dir(:archethic, "data_test"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule ArchEthic.SharedSecrets.NodeRenewalSchedulerTest do

setup do
SelfRepairScheduler.start_link(interval: "0 0 0 * *")
start_supervised!({BeaconSlotTimer, interval: "* * * * * *"})
start_supervised!({BeaconSlotTimer, interval: "0 * * * * *"})
Enum.each(BeaconChain.list_subsets(), &Registry.register(SubsetRegistry, &1, []))
:ok
end
Expand Down

0 comments on commit 906ff03

Please sign in to comment.