Skip to content

Commit

Permalink
adjust tests to the new return type
Browse files Browse the repository at this point in the history
Signed-off-by: Moonraker <[email protected]>
  • Loading branch information
Solonets committed Feb 7, 2018
1 parent efcc252 commit f1ad51a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 26 deletions.
11 changes: 7 additions & 4 deletions test/module/irohad/ametsuchi/ametsuchi_mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

#include <boost/optional.hpp>

#include "common/result.hpp"


namespace iroha {
namespace ametsuchi {
class MockWsvQuery : public WsvQuery {
Expand Down Expand Up @@ -144,7 +147,7 @@ namespace iroha {

class MockTemporaryFactory : public TemporaryFactory {
public:
MOCK_METHOD0(createTemporaryWsv, std::unique_ptr<TemporaryWsv>());
MOCK_METHOD0(createTemporaryWsv, iroha::expected::Result<std::unique_ptr<TemporaryWsv>, std::string>(void));
};

class MockMutableStorage : public MutableStorage {
Expand All @@ -167,7 +170,7 @@ namespace iroha {

class MockMutableFactory : public MutableFactory {
public:
MOCK_METHOD0(createMutableStorage, std::unique_ptr<MutableStorage>());
MOCK_METHOD0(createMutableStorage, iroha::expected::Result<std::unique_ptr<MutableStorage>, std::string>(void));

void commit(std::unique_ptr<MutableStorage> mutableStorage) override {
// gmock workaround for non-copyable parameters
Expand All @@ -189,8 +192,8 @@ namespace iroha {
public:
MOCK_CONST_METHOD0(getWsvQuery, std::shared_ptr<WsvQuery>(void));
MOCK_CONST_METHOD0(getBlockQuery, std::shared_ptr<BlockQuery>(void));
MOCK_METHOD0(createTemporaryWsv, std::unique_ptr<TemporaryWsv>(void));
MOCK_METHOD0(createMutableStorage, std::unique_ptr<MutableStorage>(void));
MOCK_METHOD0(createTemporaryWsv, iroha::expected::Result<std::unique_ptr<TemporaryWsv>, std::string>(void));
MOCK_METHOD0(createMutableStorage, iroha::expected::Result<std::unique_ptr<MutableStorage>, std::string>(void));
MOCK_METHOD1(doCommit, void(MutableStorage *storage));
MOCK_METHOD1(insertBlock, bool(model::Block block));
MOCK_METHOD0(dropStorage, void(void));
Expand Down
110 changes: 91 additions & 19 deletions test/module/irohad/ametsuchi/ametsuchi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,30 @@ void validateAccount(W &&wsv,
*/
template <typename S>
void apply(S &&storage, const Block &block) {
auto ms = storage->createMutableStorage();
std::unique_ptr<MutableStorage> ms;
auto storageResult = storage->createMutableStorage();
storageResult.match(
[&](iroha::expected::Value<std::unique_ptr<MutableStorage>> &_storage) {
ms = std::move(_storage.value);
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ms->apply(block, [](const auto &, auto &, const auto &) { return true; });
storage->commit(std::move(ms));
}

TEST_F(AmetsuchiTest, GetBlocksCompletedWhenCalled) {
// Commit block => get block => observable completed
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> storage;
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
auto blocks = storage->getBlockQuery();

Expand All @@ -171,8 +186,15 @@ TEST_F(AmetsuchiTest, GetBlocksCompletedWhenCalled) {
}

TEST_F(AmetsuchiTest, SampleTest) {
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> storage;
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
auto wsv = storage->getWsvQuery();
auto blocks = storage->getBlockQuery();
Expand Down Expand Up @@ -264,8 +286,15 @@ TEST_F(AmetsuchiTest, SampleTest) {
}

TEST_F(AmetsuchiTest, PeerTest) {
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> storage;
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
auto wsv = storage->getWsvQuery();

Expand All @@ -287,8 +316,15 @@ TEST_F(AmetsuchiTest, PeerTest) {
}

TEST_F(AmetsuchiTest, queryGetAccountAssetTransactionsTest) {
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> storage;
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
auto wsv = storage->getWsvQuery();
auto blocks = storage->getBlockQuery();
Expand Down Expand Up @@ -422,8 +458,15 @@ TEST_F(AmetsuchiTest, queryGetAccountAssetTransactionsTest) {
}

TEST_F(AmetsuchiTest, AddSignatoryTest) {
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> storage;
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
auto wsv = storage->getWsvQuery();

Expand Down Expand Up @@ -668,8 +711,15 @@ TEST_F(AmetsuchiTest, TestingStorageWhenInsertBlock) {
"Test case: create storage "
"=> insert block "
"=> assert that inserted");
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> storage;
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
auto wsv = storage->getWsvQuery();
ASSERT_EQ(0, wsv->getPeers().value().size());
Expand Down Expand Up @@ -702,8 +752,15 @@ TEST_F(AmetsuchiTest, TestingStorageWhenDropAll) {
"Test case: create storage "
"=> insert block "
"=> assert that inserted");
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> storage;
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
auto wsv = storage->getWsvQuery();
ASSERT_EQ(0, wsv->getPeers().value().size());
Expand All @@ -722,8 +779,16 @@ TEST_F(AmetsuchiTest, TestingStorageWhenDropAll) {
storage->dropStorage();

ASSERT_EQ(0, wsv->getPeers().value().size());
auto new_storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> new_storage;
auto new_storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
new_storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);

ASSERT_EQ(0, wsv->getPeers().value().size());
new_storage->dropStorage();
}
Expand All @@ -735,8 +800,15 @@ TEST_F(AmetsuchiTest, TestingStorageWhenDropAll) {
* with some other hash is not found.
*/
TEST_F(AmetsuchiTest, FindTxByHashTest) {
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
std::shared_ptr<StorageImpl> storage;
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
auto blocks = storage->getBlockQuery();

Expand Down
20 changes: 17 additions & 3 deletions test/module/irohad/ametsuchi/kv_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ class KVTest : public AmetsuchiTest {
protected:
void SetUp() override {
AmetsuchiTest::SetUp();
storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
auto storageResult = StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
storageResult.match(
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ASSERT_TRUE(storage);
blocks = storage->getBlockQuery();
wsv_query = storage->getWsvQuery();
Expand Down Expand Up @@ -93,7 +99,15 @@ class KVTest : public AmetsuchiTest {
block1.txs_number = block1.transactions.size();

{
auto ms = storage->createMutableStorage();
std::unique_ptr<MutableStorage> ms;
auto storageResult = storage->createMutableStorage();
storageResult.match(
[&](iroha::expected::Value<std::unique_ptr<MutableStorage>> &_storage) {
ms = std::move(_storage.value);
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
}
);
ms->apply(block1, [](const auto &blk, auto &query, const auto &top_hash) {
return true;
});
Expand Down

0 comments on commit f1ad51a

Please sign in to comment.