Skip to content

Commit

Permalink
also pass version opts at reestablish (#2698)
Browse files Browse the repository at this point in the history
* also pass version opts at reestablish

* Simulate fsm version env in aest_db_SUITE
  • Loading branch information
uwiger committed Aug 23, 2019
1 parent 48dad15 commit 18caa08
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
31 changes: 24 additions & 7 deletions system_test/common/aest_channels_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
%% Helpers
-export([
create_state_channel_perform_operations_leave/2,
reestablish_state_channel_perform_operations/3
reestablish_state_channel_perform_operations/3,
set_old_update_vsn/1,
simulate_fsm_vsn_env/1
]).

-import(aest_nodes, [
Expand Down Expand Up @@ -149,19 +151,35 @@ test_simple_different_nodes_channel(Cfg) ->

test_compat_with_initiator_node_using_fortuna_major_channel_version(Cfg) ->
test_different_nodes_channel_(set_genesis_accounts(node_base_spec_with_fortuna_major_channel_version()),
set_genesis_accounts(#{}), Cfg).
set_genesis_accounts(#{}),
set_old_update_vsn(Cfg)).

test_compat_with_responder_node_using_fortuna_major_channel_version(Cfg) ->
test_different_nodes_channel_(set_genesis_accounts(#{}),
set_genesis_accounts(node_base_spec_with_fortuna_major_channel_version()), Cfg).
set_genesis_accounts(node_base_spec_with_fortuna_major_channel_version()),
set_old_update_vsn(Cfg)).

test_compat_with_initiator_node_using_latest_stable_version(Cfg) ->
test_different_nodes_channel_(set_genesis_accounts(node_base_spec_with_latest_stable_version()),
set_genesis_accounts(#{}), Cfg).
set_genesis_accounts(#{}),
set_old_update_vsn(Cfg)).

test_compat_with_responder_node_using_latest_stable_version(Cfg) ->
test_different_nodes_channel_(set_genesis_accounts(#{}),
set_genesis_accounts(node_base_spec_with_latest_stable_version()), Cfg).
set_genesis_accounts(node_base_spec_with_latest_stable_version()),
set_old_update_vsn(Cfg)).

set_old_update_vsn(Cfg) ->
[{channel_opts, #{version_offchain_update => 1}}|Cfg].

simulate_fsm_vsn_env(Cfg) ->
case lists:keyfind(channel_opts, 1, Cfg) of
{_, #{version_offchain_update := V}} ->
aesc_offchain_update:set_vsn(V),
ok;
false ->
ok
end.

test_different_nodes_channel_(InitiatorNodeBaseSpec, ResponderNodeBaseSpec, Cfg) ->
ChannelOpts = #{
Expand All @@ -171,8 +189,7 @@ test_different_nodes_channel_(InitiatorNodeBaseSpec, ResponderNodeBaseSpec, Cfg)
responder_node => node2,
responder_id => ?ALICE,
responder_amount => 50000 * aest_nodes:gas_price(),
push_amount => 2,
version_offchain_update => 1
push_amount => 2
},
simple_channel_test(ChannelOpts, InitiatorNodeBaseSpec, ResponderNodeBaseSpec, Cfg).

Expand Down
13 changes: 10 additions & 3 deletions system_test/common/aest_db_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ node_can_reuse_state_channel_db_of_node_and_fortuna_release_with_sc_persistance_

%=== INTERNAL FUNCTIONS ========================================================

node_can_reuse_db_of_other_node_(T = #db_reuse_test_spec{}, Cfg)
node_can_reuse_db_of_other_node_(T = #db_reuse_test_spec{}, Cfg0)
when is_function(T#db_reuse_test_spec.create, 2),
is_function(T#db_reuse_test_spec.populate, 2),
is_function(T#db_reuse_test_spec.pre_reuse, 3),
is_function(T#db_reuse_test_spec.reuse, 2),
is_function(T#db_reuse_test_spec.assert, 3) ->
Cfg = aest_channels_SUITE:set_old_update_vsn(Cfg0),
DbHostPath = node_db_host_path(node1, Cfg),
N1 = (T#db_reuse_test_spec.create)(node1, DbHostPath),
aest_nodes:setup_nodes([N1], Cfg),
Expand All @@ -125,11 +126,12 @@ node_can_reuse_db_of_other_node_(T = #db_reuse_test_spec{}, Cfg)
ok = (T#db_reuse_test_spec.assert)(node2, DbFingerprint, Cfg),
ok.

node_can_reuse_state_channel_db_of_other_node_(T = #db_reuse_test_spec{}, Cfg)
node_can_reuse_state_channel_db_of_other_node_(T = #db_reuse_test_spec{}, Cfg0)
when is_function(T#db_reuse_test_spec.create, 2),
is_function(T#db_reuse_test_spec.populate, 2),
is_function(T#db_reuse_test_spec.reuse, 2),
is_function(T#db_reuse_test_spec.assert, 3) ->
Cfg = aest_channels_SUITE:set_old_update_vsn(Cfg0),
AliceDbHostPath = node_db_host_path(alice1, Cfg),
BobDbHostPath = node_db_host_path(bob1, Cfg),
A1 = (T#db_reuse_test_spec.create)(alice1, AliceDbHostPath),
Expand Down Expand Up @@ -230,7 +232,12 @@ patron() ->
, privkey => <<237,12,20,128,115,166,32,106,220,142,111,97,141,104,201,130,56,100,64,142,139,163,87,166,185,94,4,159,217,243,160,169,200,171,93,11,3,93,177,65,197,27,123,127,177,165,190,211,20,112,79,108,85,78,88,181,26,207,191,211,40,225,138,154>>
}.

populate_db_with_channels_force_progress_tx(NodeName, _Cfg) ->
populate_db_with_channels_force_progress_tx(NodeName, Cfg) ->
%% This function actually uses the latest code to populate a possibly old database
%% The state channel fsm sets its environment to be able to encode data using old
%% protocols, but in this case, we're not producing the tx inside the fsm, so we
%% must simulate the relevant part of the environment.
aest_channels_SUITE:simulate_fsm_vsn_env(Cfg),
#{tx_hash := TxHash} =
aest_nodes:post_force_progress_state_channel_tx(
NodeName,
Expand Down
30 changes: 22 additions & 8 deletions system_test/common/helpers/aest_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ sc_open(Params, Cfg) ->
responder_amount => RAmt,
channel_reserve => maps:get(channel_reserve, Params, 2)
},
maps:with([version_offchain_update], Params)),
maybe_version_opts(Cfg)),

{IConn, RConn} = sc_start_ws_peers(INodeName, RNodeName, Opts, Cfg),
ok = sc_wait_channel_open(IConn, RConn),
Expand Down Expand Up @@ -116,13 +116,14 @@ sc_reestablish(#{ channel_id := ChannelId
, responder := {RAccount, _}} = Chan
, INodeName, RNodeName, LatestState, Cfg) ->
{Host, _Port} = node_ws_int_addr(RNodeName, Cfg),
Opts = #{
existing_channel_id => aeser_api_encoder:encode(channel, ChannelId),
host => Host,
offchain_tx => LatestState,
port => 9000,
protocol => <<"json-rpc">>
},
Opts = maps:merge(
#{
existing_channel_id => aeser_api_encoder:encode(channel, ChannelId),
host => Host,
offchain_tx => LatestState,
port => 9000,
protocol => <<"json-rpc">>
}, maybe_version_opts(Cfg)),

{IConn, RConn} = sc_start_ws_peers(INodeName, RNodeName, Opts, Cfg),
{ok, #{ <<"event">> := <<"channel_reestablished">> }} = sc_wait_for_channel_event(IConn, info),
Expand Down Expand Up @@ -408,3 +409,16 @@ ws_send(ConnPid, Tag, Data) ->
?WS:json_rpc_notify(ConnPid,
#{ <<"method">> => Method
, <<"params">> => Data}).

%--- HELPER TO MANAGE ENCODING OPTIONS -----------------------------------------

maybe_version_opts(Cfg) ->
case lists:keyfind(channel_opts, 1, Cfg) of
{_, Opts} ->
version_opts(Opts);
false ->
#{}
end.

version_opts(Params) ->
maps:with([version_offchain_update], Params).

0 comments on commit 18caa08

Please sign in to comment.