Skip to content

Commit

Permalink
Fix getPeers query
Browse files Browse the repository at this point in the history
  • Loading branch information
lebdron committed Jul 18, 2017
1 parent 95171dc commit dc49bc7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
11 changes: 10 additions & 1 deletion irohad/ametsuchi/impl/postgres_wsv_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace iroha {
std::vector<Peer> PostgresWsvQuery::getPeers() {
pqxx::result result;
try {
transaction_.exec(
result = transaction_.exec(
"SELECT \n"
" * \n"
"FROM \n"
Expand All @@ -172,6 +172,15 @@ namespace iroha {
return {};
}
std::vector<Peer> peers;
for (const auto &row : result) {
model::Peer peer;
pqxx::binarystring public_key_str(row.at("public_key"));
ed25519::pubkey_t pubkey;
std::copy(public_key_str.begin(), public_key_str.end(), pubkey.begin());
peer.pubkey = pubkey;
row.at("address") >> peer.address;
peers.push_back(peer);
}
return peers;
}
} // namespace ametsuchi
Expand Down
32 changes: 32 additions & 0 deletions test/module/irohad/ametsuchi/ametsuchi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <gtest/gtest.h>
#include <cpp_redis/cpp_redis>
#include <model/commands/add_asset_quantity.hpp>
#include <model/commands/add_peer.hpp>
#include <model/commands/transfer_asset.hpp>
#include <pqxx/pqxx>
#include "ametsuchi/impl/storage_impl.hpp"
Expand Down Expand Up @@ -188,5 +189,36 @@ namespace iroha {
}
}

TEST_F(AmetsuchiTest, PeerTest) {
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
ASSERT_TRUE(storage);

model::Transaction txn;
model::AddPeer addPeer;
addPeer.peer_key.at(0) = 1;
addPeer.address = "192.168.0.1:50051";
txn.commands.push_back(std::make_shared<model::AddPeer>(addPeer));

model::Block block;
block.transactions.push_back(txn);

{
auto ms = storage->createMutableStorage();
ms->apply(block, [](const auto &blk, auto &executor, auto &query,
const auto &top_block) {
EXPECT_TRUE(
blk.transactions.at(0).commands.at(0)->execute(query, executor));
return true;
});
storage->commit(std::move(ms));
}

auto peers = storage->getPeers();
ASSERT_EQ(peers.size(), 1);
ASSERT_EQ(peers.at(0).pubkey, addPeer.peer_key);
ASSERT_EQ(peers.at(0).address, addPeer.address);
}

} // namespace ametsuchi
} // namespace iroha

0 comments on commit dc49bc7

Please sign in to comment.