Skip to content

Commit

Permalink
Move batch size minimal test next to the comprehensive one
Browse files Browse the repository at this point in the history
  • Loading branch information
xandkar committed Feb 23, 2021
1 parent 3f3e5a0 commit 2517352
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions test/hbbft_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

-export([all/0, init_per_testcase/2, end_per_testcase/2]).
-export([
batch_size_limit_minimal_test/1,
init_test/1,
one_actor_no_txns_test/1,
two_actors_no_txns_test/1,
Expand All @@ -17,12 +16,12 @@
one_actor_wrong_key_test/1,
one_actor_corrupted_key_test/1,
one_actor_wrong_batch_size_test/1,
batch_size_limit_minimal_test/1,
initial_fakecast_test/1
]).

all() ->
[
batch_size_limit_minimal_test,
init_test,
one_actor_no_txns_test,
two_actors_no_txns_test,
Expand All @@ -33,6 +32,7 @@ all() ->
one_actor_wrong_key_test,
one_actor_corrupted_key_test,
one_actor_wrong_batch_size_test,
batch_size_limit_minimal_test,
initial_fakecast_test
].

Expand All @@ -48,43 +48,6 @@ init_per_testcase(_, Config) ->
end_per_testcase(_, _Config) ->
ok.

batch_size_limit_minimal_test(_) ->
% Same test goal as one_actor_wrong_batch_size_test, but
% the absolute minimal to test the state transition.
N = 1,
F = 0,
BatchSize = 1,
{ok, Dealer} = dealer:new(N, F + 1, 'SS512'),
{ok, {PK, [SK | _]}} = dealer:deal(Dealer),

% Protocol begins.
ProtocolInstanceId = 0,
State_0 = hbbft:init(SK, N, F, ProtocolInstanceId, BatchSize, infinity),

% Transactions submitted. One more than max batch size.
Buf = [list_to_binary(integer_to_list(Txn)) || Txn <- lists:seq(1, BatchSize + 1)],

% Pretending ACS happened here.
Stamp = <<"trust-me-im-a-stamp">>,
Enc = hbbft:encrypt(PK, hbbft:encode_list([Stamp | Buf])),
{ok, EncKey} = hbbft:get_encrypted_key(SK, Enc),
AcsInstanceId = 0, % E?
State_1 = hbbft:abstraction_breaking_set_acs_results(State_0, [{AcsInstanceId, Enc}]),
State_2 = hbbft:abstraction_breaking_set_enc_keys(State_1, #{AcsInstanceId => EncKey}),

% Decoding transactions from ACS, which we expect to be rejectected.
{State_3, {result, {transactions, [], []}}} =
hbbft:handle_msg(
State_2,
ProtocolInstanceId,
{dec,
hbbft:round(State_2),
AcsInstanceId,
hbbft_utils:share_to_binary(tpke_privkey:decrypt_share(SK, EncKey))
}),
#{sent_txns := true} = hbbft:status(State_3),
ok.

init_test(Config) ->
N = proplists:get_value(n, Config),
F = proplists:get_value(f, Config),
Expand Down Expand Up @@ -429,6 +392,43 @@ one_actor_wrong_batch_size_test(Config) ->
ct:log("chain contains ~p distinct transactions~n", [length(BlockTxns)]),
ok.

batch_size_limit_minimal_test(_) ->
% Same test goal as one_actor_wrong_batch_size_test, but
% the absolute minimal to test the state transition.
N = 1,
F = 0,
BatchSize = 1,
{ok, Dealer} = dealer:new(N, F + 1, 'SS512'),
{ok, {PK, [SK | _]}} = dealer:deal(Dealer),

% Protocol begins.
ProtocolInstanceId = 0,
State_0 = hbbft:init(SK, N, F, ProtocolInstanceId, BatchSize, infinity),

% Transactions submitted. One more than max batch size.
Buf = [list_to_binary(integer_to_list(Txn)) || Txn <- lists:seq(1, BatchSize + 1)],

% Pretending ACS happened here.
Stamp = <<"trust-me-im-a-stamp">>,
Enc = hbbft:encrypt(PK, hbbft:encode_list([Stamp | Buf])),
{ok, EncKey} = hbbft:get_encrypted_key(SK, Enc),
AcsInstanceId = 0, % E?
State_1 = hbbft:abstraction_breaking_set_acs_results(State_0, [{AcsInstanceId, Enc}]),
State_2 = hbbft:abstraction_breaking_set_enc_keys(State_1, #{AcsInstanceId => EncKey}),

% Decoding transactions from ACS, which we expect to be rejectected.
{State_3, {result, {transactions, [], []}}} =
hbbft:handle_msg(
State_2,
ProtocolInstanceId,
{dec,
hbbft:round(State_2),
AcsInstanceId,
hbbft_utils:share_to_binary(tpke_privkey:decrypt_share(SK, EncKey))
}),
#{sent_txns := true} = hbbft:status(State_3),
ok.

-record(state,
{
node_count :: integer(),
Expand Down

0 comments on commit 2517352

Please sign in to comment.