diff --git a/test/hbbft_SUITE.erl b/test/hbbft_SUITE.erl index c8a1a67..192d7a6 100644 --- a/test/hbbft_SUITE.erl +++ b/test/hbbft_SUITE.erl @@ -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, @@ -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, @@ -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 ]. @@ -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), @@ -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(),