Skip to content

Commit

Permalink
Merge pull request #2681 from aeternity/create_accounts_in_dry_run
Browse files Browse the repository at this point in the history
Allow account creation in dry-run
  • Loading branch information
hanssv committed Aug 22, 2019
2 parents 1e241ab + 847fc34 commit b3056d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
20 changes: 12 additions & 8 deletions apps/aecore/src/aec_dry_run.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ dry_run_res(STx, _Trees, Err) ->
{Type, _} = aetx:specialize_type(aetx_sign:tx(STx)),
{Type, Err}.

add_accounts(Trees, []) ->
Trees;
add_accounts(Trees, [#{pub_key := PK, amount := A} | Accounts]) ->
AccountsTree = aec_trees:accounts(Trees),
{value, Account} = aec_accounts_trees:lookup(PK, AccountsTree),
{ok, Account1} = aec_accounts:earn(Account, A),
AccountsTree1 = aec_accounts_trees:enter(Account1, AccountsTree),
add_accounts(aec_trees:set_accounts(Trees, AccountsTree1), Accounts).

add_accounts(Trees, Accounts) ->
AccountsTree = lists:foldl(fun add_account/2, aec_trees:accounts(Trees), Accounts),
aec_trees:set_accounts(Trees, AccountsTree).

add_account(#{pub_key := PK, amount := A}, AccountsTree) ->
{ok, Account} =
case aec_accounts_trees:lookup(PK, AccountsTree) of
none -> {ok, aec_accounts:new(PK, A)};
{value, Account0} -> aec_accounts:earn(Account0, A)
end,
aec_accounts_trees:enter(Account, AccountsTree).

dummy_sign_txs(Txs) ->
[ aetx_sign:new(Tx, [dummy_sign()]) || Tx <- Txs ].
Expand Down
5 changes: 4 additions & 1 deletion apps/aehttp/test/aehttp_dryrun_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ accounts(Config) ->
{ok, 200, #{ <<"results">> := [#{ <<"result">> := <<"ok">> }, #{ <<"result">> := <<"ok">> }] }} =
dry_run(TopHash, [Tx1, Tx2], [#{ pub_key => APub, amount => 100000000}]),


{ok, 200, #{ <<"results">> := [#{ <<"result">> := <<"error">> }, #{ <<"result">> := <<"ok">> }] }} =
dry_run(TopHash, [Tx2, Tx1]),

%% Should work on GenHash if we create and top up EPub
{ok, 200, #{ <<"results">> := [#{ <<"result">> := <<"ok">> }, #{ <<"result">> := <<"ok">> }] }} =
dry_run(TopHash, [Tx2, Tx1], [#{ pub_key => EPub, amount => 1000000000000000}]),

ok.

%% --- Internal functions ---
Expand Down
4 changes: 1 addition & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@
{deps, [
bbmustache,
{hackney, "1.14.3"},
{websocket_client, ".*", {git, "git://github.com/aeternity/websocket_client", {ref, "a4fb3db"}}},
{aesophia, {git, "https://github.com/aeternity/aesophia.git", {ref,"df12f6a"}}},
{aesophia_cli, {git, "git://github.com/aeternity/aesophia_cli", {tag, "v3.2.0"}}}
{websocket_client, ".*", {git, "git://github.com/aeternity/websocket_client", {ref, "a4fb3db"}}}
]},
{ct_opts, [{create_priv_dir, auto_per_tc}]}
]},
Expand Down

0 comments on commit b3056d6

Please sign in to comment.