@@ -2,13 +2,20 @@ defmodule AeMdw.Db.HardforkPresetsTest do
2
2
use ExUnit.Case , async: false
3
3
4
4
alias AeMdw.Collection
5
+ alias AeMdw.Database
5
6
alias AeMdw.Db.HardforkPresets
6
7
alias AeMdw.Db.Model
7
8
alias AeMdw.Db.State
8
9
10
+ import Mock
11
+
9
12
describe "import_account_presets" do
10
- test "saves genesis, minerva, fortuna and lima migrated accounts" do
11
- HardforkPresets . import_account_presets ( )
13
+ test "on mainnet saves genesis, minerva, fortuna and lima migrated accounts" do
14
+ delete_previous_import ( )
15
+
16
+ with_mocks [ { :aec_governance , [ :passthrough ] , get_network_id: fn -> "ae_mainnet" end } ] do
17
+ HardforkPresets . import_account_presets ( )
18
+ end
12
19
13
20
assert 716 ==
14
21
State . new ( )
@@ -49,5 +56,45 @@ defmodule AeMdw.Db.HardforkPresetsTest do
49
56
|> Stream . take_while ( & match? ( { "contracts_lima" , _bi , _target , _txi } , & 1 ) )
50
57
|> Enum . count ( )
51
58
end
59
+
60
+ test "on testnet saves genesis, minerva, fortuna and lima migrated accounts" do
61
+ delete_previous_import ( )
62
+
63
+ with_mocks [ { :aec_governance , [ :passthrough ] , get_network_id: fn -> "ae_uat" end } ] do
64
+ HardforkPresets . import_account_presets ( )
65
+ end
66
+
67
+ assert 1 ==
68
+ State . new ( )
69
+ |> Collection . stream ( Model.KindIntTransferTx , { "accounts_genesis" , nil , nil , nil } )
70
+ |> Stream . take_while ( & match? ( { "accounts_genesis" , _bi , _target , _txi } , & 1 ) )
71
+ |> Enum . count ( )
72
+
73
+ assert 3 ==
74
+ State . new ( )
75
+ |> Collection . stream ( Model.KindIntTransferTx , { "accounts_minerva" , nil , nil , nil } )
76
+ |> Stream . take_while ( & match? ( { "accounts_minerva" , _bi , _target , _txi } , & 1 ) )
77
+ |> Enum . count ( )
78
+ end
79
+
80
+ test "on custom network skips importing accounts" do
81
+ delete_previous_import ( )
82
+
83
+ with_mocks [ { :aec_governance , [ :passthrough ] , get_network_id: fn -> "ae_custom" end } ] do
84
+ HardforkPresets . import_account_presets ( )
85
+ end
86
+
87
+ assert Database . count ( Model.KindIntTransferTx ) == 0
88
+ end
89
+ end
90
+
91
+ defp delete_previous_import do
92
+ State . new ( )
93
+ |> Collection . stream (
94
+ Model.KindIntTransferTx ,
95
+ { "" , nil , nil , nil }
96
+ )
97
+ |> Enum . to_list ( )
98
+ |> Enum . each ( & State . delete ( State . new ( ) , Model.KindIntTransferTx , & 1 ) )
52
99
end
53
100
end
0 commit comments