-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced hs_proposal_message::get_height() with ::get_view_number(), …
…added unit tests. Work-in-progress towards #1521
- Loading branch information
Showing
8 changed files
with
202 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <boost/test/unit_test.hpp> | ||
#include <eosio/chain/types.hpp> | ||
#include <eosio/chain/block_header.hpp> | ||
|
||
#include <fc/exception/exception.hpp> | ||
|
||
#include <eosio/hotstuff/qc_chain.hpp> | ||
|
||
BOOST_AUTO_TEST_CASE(view_number_tests) try { | ||
|
||
eosio::hotstuff::hs_proposal_message hspm_1; | ||
eosio::hotstuff::hs_proposal_message hspm_2; | ||
eosio::hotstuff::hs_proposal_message hspm_3; | ||
eosio::hotstuff::hs_proposal_message hspm_4; | ||
eosio::hotstuff::hs_proposal_message hspm_5; | ||
|
||
hspm_1.block_id = eosio::chain::block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 | ||
hspm_1.phase_counter = 0; | ||
|
||
hspm_2.block_id = eosio::chain::block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 | ||
hspm_2.phase_counter = 1; | ||
|
||
hspm_3.block_id = eosio::chain::block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217068 | ||
hspm_3.phase_counter = 0; | ||
|
||
hspm_4.block_id = eosio::chain::block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217068 | ||
hspm_4.phase_counter = 1; | ||
|
||
hspm_5.block_id = eosio::chain::block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217068 | ||
hspm_5.phase_counter = 2; | ||
|
||
eosio::hotstuff::view_number vn_1 = hspm_1.get_view_number(); | ||
eosio::hotstuff::view_number vn_2 = hspm_2.get_view_number(); | ||
eosio::hotstuff::view_number vn_3 = hspm_3.get_view_number(); | ||
eosio::hotstuff::view_number vn_4 = hspm_4.get_view_number(); | ||
eosio::hotstuff::view_number vn_5 = hspm_5.get_view_number(); | ||
|
||
//test getters | ||
|
||
BOOST_CHECK_EQUAL(vn_1.block_height() == 194217067, true); | ||
BOOST_CHECK_EQUAL(vn_1.phase_counter() == 0, true); | ||
|
||
//test operators == true | ||
BOOST_CHECK_EQUAL(vn_1 == vn_1, true); | ||
BOOST_CHECK_EQUAL(vn_1 != vn_2, true); | ||
|
||
BOOST_CHECK_EQUAL(vn_1 < vn_2, true); | ||
BOOST_CHECK_EQUAL(vn_2 < vn_3, true); | ||
BOOST_CHECK_EQUAL(vn_3 < vn_4, true); | ||
BOOST_CHECK_EQUAL(vn_4 < vn_5, true); | ||
|
||
//test operators == false | ||
BOOST_CHECK_EQUAL(vn_1 >= vn_2, false); | ||
BOOST_CHECK_EQUAL(vn_2 > vn_3, false); | ||
|
||
//test constructor | ||
|
||
eosio::hotstuff::view_number vn_6 = eosio::hotstuff::view_number(std::make_pair(194217068, 2)); | ||
|
||
BOOST_CHECK_EQUAL(vn_5 == vn_6, true); | ||
|
||
} FC_LOG_AND_RETHROW(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <boost/test/unit_test.hpp> | ||
#include <eosio/chain/types.hpp> | ||
|
||
#include <fc/io/cfile.hpp> | ||
|
||
#include <fc/exception/exception.hpp> | ||
#include <eosio/hotstuff/qc_chain.hpp> | ||
|
||
//#include <eosio/hotstuff/stuff.cpp> | ||
|
||
using std::cout; | ||
|
||
struct safety_state { | ||
|
||
eosio::chain::view_number v_height; | ||
eosio::chain::view_number b_lock; | ||
|
||
}; | ||
|
||
struct liveness_state { | ||
|
||
eosio::chain::quorum_certificate high_qc; | ||
eosio::chain::view_number b_exec; | ||
|
||
}; | ||
|
||
BOOST_AUTO_TEST_SUITE(test_hotstuff_state) | ||
|
||
const std::string file_path("temp"); | ||
|
||
BOOST_AUTO_TEST_CASE(write_state_to_file) try { | ||
|
||
/* eosio::hotstuff::hs_proposal_message hspm; | ||
hspm.block_id = eosio::chain::block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 | ||
hspm.phase_counter = 0; | ||
eosio::hotstuff::view_number vn = hspm.get_view_number(); | ||
BOOST_CHECK_EQUAL(vn.block_height() == 194217067, true); | ||
BOOST_CHECK_EQUAL(vn.phase_counter() == 0, true); | ||
*/ | ||
safety_state ss; | ||
|
||
//ss.test_val = 2; | ||
|
||
// writing | ||
fc::cfile pfile; | ||
pfile.set_file_path(file_path); | ||
pfile.open(fc::cfile::truncate_rw_mode); | ||
auto data = fc::raw::pack(ss); | ||
pfile.write(data.data(), data.size()); | ||
pfile.close(); // or let destructor do it | ||
|
||
bool ok = true; | ||
|
||
BOOST_CHECK_EQUAL(ok, true); | ||
|
||
|
||
} FC_LOG_AND_RETHROW(); | ||
|
||
BOOST_AUTO_TEST_CASE(read_state_from_file) try { | ||
|
||
safety_state ss; | ||
|
||
// reading | ||
fc::cfile pfile; | ||
pfile.set_file_path(file_path); | ||
pfile.open("rb"); | ||
auto ds = pfile.create_datastream(); | ||
fc::raw::unpack(ds, ss); | ||
pfile.close(); // or let destructor do it | ||
|
||
//bool ok = ss.test_val == 2; | ||
|
||
BOOST_CHECK_EQUAL(true, true); | ||
|
||
} FC_LOG_AND_RETHROW(); | ||
|
||
BOOST_AUTO_TEST_SUITE_END() | ||
|
||
FC_REFLECT(safety_state, (v_height)(b_lock)) | ||
FC_REFLECT(liveness_state, (high_qc)(b_exec)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters