Skip to content

Commit

Permalink
Add temporary run_network_test
Browse files Browse the repository at this point in the history
  • Loading branch information
motxx authored and muratovv committed Jul 30, 2017
1 parent 7e18d41 commit f498eb1
Showing 1 changed file with 58 additions and 6 deletions.
64 changes: 58 additions & 6 deletions test/module/iroha-cli/bootstrap_network_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,50 @@
*/

#include "../../../iroha-cli/bootstrap_network.hpp"
#include "../../../iroha-cli/genesis_block_client.hpp"
#include <gmock/gmock.h>
#include <grpc++/grpc++.h>
#include <gtest/gtest.h>
#include <fstream>
#include <memory>
#include "../../../iroha-cli/genesis_block_client.hpp"
#include "ametsuchi/block_serializer.hpp"
#include "common/types.hpp"
#include "crypto/crypto.hpp"
#include "endpoint.grpc.pb.h"
#include "model/block.hpp"
#include "model/model_hash_provider_impl.hpp"
#include "main/genesis_block_server/genesis_block_service.hpp"

using ::testing::Return;

class GenesisBlockClientMock : public iroha_cli::GenesisBlockClient {
/*
MOCK_METHOD2(set_channel, void(const std::string &ip, const int port));
MOCK_METHOD2(
send_genesis_block,
grpc::Status(const iroha::model::Block &iroha_block,
iroha::protocol::ApplyGenesisBlockResponse &response));
MOCK_METHOD1(send_abort_genesis_block, void(const iroha::model::Block &block));
};
iroha::protocol::ApplyGenesisBlockResponse &response));
MOCK_METHOD1(send_abort_genesis_block,
void(const iroha::model::Block &block));
*/

GenesisBlockClientMock client_mock;
void set_channel(const std::string &ip, const int port) {}
grpc::Status send_genesis_block(const iroha::model::Block &iroha_block,
iroha::protocol::ApplyGenesisBlockResponse &response) {
response.set_applied(iroha::protocol::APPLY_SUCCESS);
return grpc::Status::OK;
}

void send_abort_genesis_block(const iroha::model::Block &block) {}
};

TEST(iroha_cli, NormalWhenParseTrustedPeers) {
auto test_path = "/tmp/_boot_strap_test_target.conf";
std::ofstream ofs(test_path);
ofs << R"({"ip":["192.168.0.3","192.168.0.4","192.168.0.5","192.168.0.6"]})";
ofs.close();

GenesisBlockClientMock client_mock;
iroha_cli::BootstrapNetwork bootstrap(client_mock);
auto peers = bootstrap.parse_trusted_peers(test_path);
ASSERT_EQ(peers.size(), 4);
Expand All @@ -60,6 +75,8 @@ TEST(iroha_cli, WrongIPNameWhenParseTrustedPeers) {
std::ofstream ofs(test_path);
ofs << R"({"IP":["192.168.0.3","192.168.0.4","192.168.0.5","192.168.0.6"]})";
ofs.close();

GenesisBlockClientMock client_mock;
iroha_cli::BootstrapNetwork bootstrap(client_mock);
ASSERT_ANY_THROW({ bootstrap.parse_trusted_peers(test_path); });
ASSERT_TRUE(remove(test_path) == 0);
Expand All @@ -70,6 +87,8 @@ TEST(iroha_cli, InvalidIPValueWhenParseTrustedPeers) {
std::ofstream ofs(test_path);
ofs << R"({"ip":["192.168.256.3","192.168.0.4","192.168.0.5","192.168.0.6"]})";
ofs.close();

GenesisBlockClientMock client_mock;
iroha_cli::BootstrapNetwork bootstrap(client_mock);
ASSERT_ANY_THROW({ bootstrap.parse_trusted_peers(test_path); });
ASSERT_TRUE(remove(test_path) == 0);
Expand Down Expand Up @@ -116,9 +135,42 @@ TEST(iroha_cli, NormalWhenParseGenesisBlock) {
)");
ofs.close();

GenesisBlockClientMock client_mock;
iroha_cli::BootstrapNetwork bootstrap(client_mock);
auto genesis = bootstrap.parse_genesis_block(test_path);
ASSERT_TRUE(remove(test_path) == 0);
}

TEST(iroha_cli, NormalWhenRunNetwork) {}
TEST(iroha_cli, NormalWhenRunNetwork) {
iroha::model::Transaction tx;
tx.creator_account_id = "user1";
iroha::model::CreateDomain createDomain;
createDomain.domain_name = "ja";
tx.commands.push_back(
std::make_shared<iroha::model::CreateDomain>(createDomain));
iroha::model::CreateAccount createAccount;
createAccount.account_name = "user2";
createAccount.domain_id = "ja";
tx.commands.push_back(
std::make_shared<iroha::model::CreateAccount>(createAccount));

iroha::model::Block block;
block.transactions.push_back(tx);
block.height = 1;
block.prev_hash.fill(0);
block.txs_number = block.transactions.size();
iroha::model::HashProviderImpl hash_provider;
block.hash = hash_provider.get_hash(block);

GenesisBlockClientMock client_mock;
iroha::protocol::ApplyGenesisBlockResponse response;
//EXPECT_CALL(send_genesis_block, send_genesis_block(block, response))
// .WillRepeatedly(Return(grpc::Status::OK));

iroha_cli::BootstrapNetwork bootstrap(client_mock);

ASSERT_NO_THROW({
bootstrap.run_network(
{"192.168.256.3", "192.168.0.4"}, block);
});
}

0 comments on commit f498eb1

Please sign in to comment.