From 430a50f63bf9a285f68bdf9de49d08e9d0af5fed Mon Sep 17 00:00:00 2001 From: Fedor Muratov Date: Tue, 19 Dec 2017 11:24:19 +0900 Subject: [PATCH] Fix following issues: * add hash generation into tx deserialization * fix test for mst-transport * fix blocking issue in mst-propagation strategy Signed-off-by: Fedor Muratov --- irohad/main/application.cpp | 1 + .../converters/impl/pb_transaction_factory.cpp | 2 +- .../impl/gossip_propagation_strategy.cpp | 2 +- .../pipeline/tx_pipeline_integration_test.cpp | 1 + .../gossip_propagation_strategy_test.cpp | 2 +- .../multi_sig_transactions/mst_test_helpers.hpp | 13 +++++++++++-- .../multi_sig_transactions/transport_test.cpp | 17 +++++++++-------- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/irohad/main/application.cpp b/irohad/main/application.cpp index 4e7e5398c3..6f89c6a53a 100644 --- a/irohad/main/application.cpp +++ b/irohad/main/application.cpp @@ -194,6 +194,7 @@ void Irohad::initMstProcessor() { auto mst_time = std::make_shared(); mst_processor = std::make_shared(mst_transport, mst_storage, mst_propagation, mst_time); + log_->info("[Init] => MST processor"); } void Irohad::initTransactionCommandService() { diff --git a/irohad/model/converters/impl/pb_transaction_factory.cpp b/irohad/model/converters/impl/pb_transaction_factory.cpp index 591e55f4ae..86334393df 100644 --- a/irohad/model/converters/impl/pb_transaction_factory.cpp +++ b/irohad/model/converters/impl/pb_transaction_factory.cpp @@ -71,7 +71,7 @@ namespace iroha { tx.commands.push_back( commandFactory.deserializeAbstractCommand(pb_command)); } - + tx.tx_hash = iroha::hash(tx); return std::make_shared(tx); } diff --git a/irohad/multi_sig_transactions/impl/gossip_propagation_strategy.cpp b/irohad/multi_sig_transactions/impl/gossip_propagation_strategy.cpp index 9b26666ab9..c227805242 100644 --- a/irohad/multi_sig_transactions/impl/gossip_propagation_strategy.cpp +++ b/irohad/multi_sig_transactions/impl/gossip_propagation_strategy.cpp @@ -48,7 +48,7 @@ namespace iroha { })) {} rxcpp::observable GossipPropagationStrategy::emitter() { - return emitent; + return emitent.subscribe_on(rxcpp::observe_on_new_thread()); } bool GossipPropagationStrategy::initQueue() { diff --git a/test/integration/pipeline/tx_pipeline_integration_test.cpp b/test/integration/pipeline/tx_pipeline_integration_test.cpp index 6c9e1b2e4a..79394b7675 100644 --- a/test/integration/pipeline/tx_pipeline_integration_test.cpp +++ b/test/integration/pipeline/tx_pipeline_integration_test.cpp @@ -31,6 +31,7 @@ class TxPipelineIntegrationTest : public TxPipelineIntegrationTestFixture { auto genesis_tx = TransactionGenerator().generateGenesisTransaction(0, {"0.0.0.0:10001"}); + genesis_tx.quorum = 1; genesis_block = iroha::model::generators::BlockGenerator().generateGenesisBlock( 0, {genesis_tx}); diff --git a/test/module/irohad/multi_sig_transactions/gossip_propagation_strategy_test.cpp b/test/module/irohad/multi_sig_transactions/gossip_propagation_strategy_test.cpp index d3758e1361..6ca1332ecf 100644 --- a/test/module/irohad/multi_sig_transactions/gossip_propagation_strategy_test.cpp +++ b/test/module/irohad/multi_sig_transactions/gossip_propagation_strategy_test.cpp @@ -75,7 +75,7 @@ PropagationData subscribe_and_emit(nonstd::optional data, auto subscriber = rxcpp::make_subscriber([&emitted](auto v) { std::copy(v.begin(), v.end(), std::back_inserter(emitted)); }); - strategy.emitter().take(take).subscribe(subscriber); + strategy.emitter().take(take).as_blocking().subscribe(subscriber); return emitted; } diff --git a/test/module/irohad/multi_sig_transactions/mst_test_helpers.hpp b/test/module/irohad/multi_sig_transactions/mst_test_helpers.hpp index ebe734e3f4..e394bf9012 100644 --- a/test/module/irohad/multi_sig_transactions/mst_test_helpers.hpp +++ b/test/module/irohad/multi_sig_transactions/mst_test_helpers.hpp @@ -18,10 +18,11 @@ #ifndef IROHA_MST_TEST_HELPERS_HPP #define IROHA_MST_TEST_HELPERS_HPP +#include #include "common/types.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/transaction.hpp" #include "multi_sig_transactions/mst_types.hpp" -#include using namespace std; using namespace iroha; @@ -47,6 +48,14 @@ inline auto makeTx(const string &hash_value, return make_shared(tx); } +inline auto makeTxWithCorrectHash(const string &signature_value, + uint8_t quorum = 3, + iroha::TimeType created_time = 1) { + auto tx = makeTx("0", signature_value, quorum, created_time); + tx->tx_hash = iroha::hash(*tx); + return tx; +} + inline auto makePeer(const string &address, const string &pub_key) { iroha::model::Peer p; p.address = address; @@ -54,4 +63,4 @@ inline auto makePeer(const string &address, const string &pub_key) { return p; } -#endif //IROHA_MST_TEST_HELPERS_HPP +#endif // IROHA_MST_TEST_HELPERS_HPP diff --git a/test/module/irohad/multi_sig_transactions/transport_test.cpp b/test/module/irohad/multi_sig_transactions/transport_test.cpp index 4211989275..955869281f 100644 --- a/test/module/irohad/multi_sig_transactions/transport_test.cpp +++ b/test/module/irohad/multi_sig_transactions/transport_test.cpp @@ -17,6 +17,7 @@ #include #include +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "module/irohad/multi_sig_transactions/mst_mocks.hpp" #include "module/irohad/multi_sig_transactions/mst_test_helpers.hpp" #include "multi_sig_transactions/state/mst_state.hpp" @@ -30,8 +31,8 @@ using ::testing::AtLeast; using ::testing::InvokeWithoutArgs; /** - * @brief Sends data over MstTransportGrpc (MstState and Peer objects) and receives - * them. When received deserializes them end ensures that deserialized + * @brief Sends data over MstTransportGrpc (MstState and Peer objects) and + * receives them. When received deserializes them end ensures that deserialized * objects equal to objects before sending. * * @given Initialized transport @@ -53,10 +54,10 @@ TEST(TransportTest, SendAndReceive) { auto peer = makePeer("localhost:50051", "abcdabcdabcdabcdabcdabcdabcdabcd"); MstState state = MstState::empty(); - state += makeTx("1", "5", 3); - state += makeTx("2", "6", 4); - state += makeTx("3", "7", 5); - state += makeTx("4", "8", 5); + state += makeTxWithCorrectHash("5", 3); + state += makeTxWithCorrectHash("6", 4); + state += makeTxWithCorrectHash("7", 5); + state += makeTxWithCorrectHash("8", 5); // we want to ensure that server side will call onNewState() // with same parameters as on the client side @@ -66,8 +67,8 @@ TEST(TransportTest, SendAndReceive) { grpc::ServerBuilder builder; int port = 0; - builder.AddListeningPort(peer.address, grpc::InsecureServerCredentials(), - &port); + builder.AddListeningPort( + peer.address, grpc::InsecureServerCredentials(), &port); builder.RegisterService(transport.get()); server = builder.BuildAndStart(); ASSERT_TRUE(server);