From 76d5ec2a4dbb8db32eabbf6c82262033fc88b7c9 Mon Sep 17 00:00:00 2001
From: Artyom Bakhtin
Date: Sat, 31 Mar 2018 13:05:51 +0300
Subject: [PATCH 001/110] Selected branches coverage (#1122)
* run coverage for selected branches only
Signed-off-by: Artyom Bakhtin
* branches to cover as a separate script
Signed-off-by: Artyom Bakhtin
---
.jenkinsci/selected-branches-coverage.groovy | 13 ++++++++++++
Jenkinsfile | 21 ++++++++++++++------
2 files changed, 28 insertions(+), 6 deletions(-)
create mode 100644 .jenkinsci/selected-branches-coverage.groovy
diff --git a/.jenkinsci/selected-branches-coverage.groovy b/.jenkinsci/selected-branches-coverage.groovy
new file mode 100644
index 0000000000..dce5d5ae70
--- /dev/null
+++ b/.jenkinsci/selected-branches-coverage.groovy
@@ -0,0 +1,13 @@
+#!/usr/bin/env groovy
+
+def selectedBranchesCoverage(branches, PRCoverage=true) {
+ // trigger coverage if branch is either develop or master, or it is a PR
+ if (PRCoverage) {
+ return env.BRANCH_NAME in branches || env.CHANGE_ID != null
+ }
+ else {
+ return env.BRANCH_NAME in branches
+ }
+}
+
+return this
\ No newline at end of file
diff --git a/Jenkinsfile b/Jenkinsfile
index 6a6d71bf16..8a33536581 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -93,7 +93,13 @@ pipeline {
steps {
script {
debugBuild = load ".jenkinsci/debug-build.groovy"
- debugBuild.doDebugBuild(true)
+ coverage = load ".jenkinsci/selected-branches-coverage.groovy"
+ if (coverage.selectedBranchesCoverage(['develop', 'master'])) {
+ debugBuild.doDebugBuild(true)
+ }
+ else {
+ debugBuild.doDebugBuild()
+ }
if (BRANCH_NAME ==~ /(master|develop)/) {
releaseBuild = load ".jenkinsci/release-build.groovy"
releaseBuild.doReleaseBuild()
@@ -117,8 +123,9 @@ pipeline {
agent { label 'armv7' }
steps {
script {
- def debugBuild = load ".jenkinsci/debug-build.groovy"
- if (!params.Linux && !params.ARMv8 && !params.MacOS) {
+ debugBuild = load ".jenkinsci/debug-build.groovy"
+ coverage = load ".jenkinsci/selected-branches-coverage.groovy"
+ if (!params.Linux && !params.ARMv8 && !params.MacOS && (coverage.selectedBranchesCoverage(['develop', 'master']))) {
debugBuild.doDebugBuild(true)
}
else {
@@ -147,8 +154,9 @@ pipeline {
agent { label 'armv8' }
steps {
script {
- def debugBuild = load ".jenkinsci/debug-build.groovy"
- if (!params.Linux && !params.MacOS) {
+ debugBuild = load ".jenkinsci/debug-build.groovy"
+ coverage = load ".jenkinsci/selected-branches-coverage.groovy"
+ if (!params.Linux && !params.MacOS && (coverage.selectedBranchesCoverage(['develop', 'master']))) {
debugBuild.doDebugBuild(true)
}
else {
@@ -179,7 +187,8 @@ pipeline {
script {
def coverageEnabled = false
def cmakeOptions = ""
- if (!params.Linux) {
+ coverage = load ".jenkinsci/selected-branches-coverage.groovy"
+ if (!params.Linux && (coverage.selectedBranchesCoverage(['develop', 'master']))) {
coverageEnabled = true
cmakeOptions = " -DCOVERAGE=ON "
}
From 15de16f2fa68358b257784d9624e5b8feab7557c Mon Sep 17 00:00:00 2001
From: Andrei Lebedev
Date: Thu, 5 Apr 2018 13:13:36 +0300
Subject: [PATCH 002/110] Fix std::string constructor arguments in tests
(#1178)
Signed-off-by: Andrei Lebedev
---
test/module/irohad/ametsuchi/ametsuchi_test.cpp | 8 ++++----
test/module/irohad/ametsuchi/block_query_test.cpp | 4 ++--
.../module/irohad/ametsuchi/block_query_transfer_test.cpp | 2 +-
.../irohad/consensus/yac/yac_crypto_provider_test.cpp | 4 ++--
test/module/irohad/simulator/simulator_test.cpp | 2 +-
test/module/irohad/torii/torii_service_test.cpp | 2 +-
6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/test/module/irohad/ametsuchi/ametsuchi_test.cpp b/test/module/irohad/ametsuchi/ametsuchi_test.cpp
index d859d45e5e..7089d9c0d1 100644
--- a/test/module/irohad/ametsuchi/ametsuchi_test.cpp
+++ b/test/module/irohad/ametsuchi/ametsuchi_test.cpp
@@ -402,8 +402,8 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
ASSERT_TRUE(storage);
auto wsv = storage->getWsvQuery();
- shared_model::crypto::PublicKey pubkey1(std::string("1", 32));
- shared_model::crypto::PublicKey pubkey2(std::string("2", 32));
+ shared_model::crypto::PublicKey pubkey1(std::string(32, '1'));
+ shared_model::crypto::PublicKey pubkey2(std::string(32, '2'));
auto user1id = "userone@domain";
auto user2id = "usertwo@domain";
@@ -691,8 +691,8 @@ TEST_F(AmetsuchiTest, FindTxByHashTest) {
ASSERT_TRUE(storage);
auto blocks = storage->getBlockQuery();
- shared_model::crypto::PublicKey pubkey1(std::string("1", 32));
- shared_model::crypto::PublicKey pubkey2(std::string("2", 32));
+ shared_model::crypto::PublicKey pubkey1(std::string(32, '1'));
+ shared_model::crypto::PublicKey pubkey2(std::string(32, '2'));
auto txn1 =
TestTransactionBuilder()
diff --git a/test/module/irohad/ametsuchi/block_query_test.cpp b/test/module/irohad/ametsuchi/block_query_test.cpp
index 8e70a0df32..e0490c4043 100644
--- a/test/module/irohad/ametsuchi/block_query_test.cpp
+++ b/test/module/irohad/ametsuchi/block_query_test.cpp
@@ -104,7 +104,7 @@ class BlockQueryTest : public AmetsuchiTest {
std::string creator1 = "user1@test";
std::string creator2 = "user2@test";
std::size_t blocks_total{0};
- std::string zero_string = std::string("0", 32);
+ std::string zero_string = std::string(32, '0');
};
/**
@@ -186,7 +186,7 @@ TEST_F(BlockQueryTest, GetTransactionsExistingTxHashes) {
*/
TEST_F(BlockQueryTest, GetTransactionsIncludesNonExistingTxHashes) {
shared_model::crypto::Hash invalid_tx_hash_1(zero_string),
- invalid_tx_hash_2(std::string("9", 32));
+ invalid_tx_hash_2(std::string(32, '9'));
auto wrapper = make_test_subscriber(
blocks->getTransactions({invalid_tx_hash_1, invalid_tx_hash_2}), 2);
wrapper.subscribe(
diff --git a/test/module/irohad/ametsuchi/block_query_transfer_test.cpp b/test/module/irohad/ametsuchi/block_query_transfer_test.cpp
index 4ca512aa04..7075af3004 100644
--- a/test/module/irohad/ametsuchi/block_query_transfer_test.cpp
+++ b/test/module/irohad/ametsuchi/block_query_transfer_test.cpp
@@ -77,7 +77,7 @@ namespace iroha {
std::string asset = "coin#test";
};
- auto zero_string = std::string("0", 32);
+ auto zero_string = std::string(32, '0');
auto fake_hash = shared_model::crypto::Hash(zero_string);
/**
diff --git a/test/module/irohad/consensus/yac/yac_crypto_provider_test.cpp b/test/module/irohad/consensus/yac/yac_crypto_provider_test.cpp
index 2d448f39be..8d7683280c 100644
--- a/test/module/irohad/consensus/yac/yac_crypto_provider_test.cpp
+++ b/test/module/irohad/consensus/yac/yac_crypto_provider_test.cpp
@@ -22,8 +22,8 @@
#include "consensus/yac/messages.hpp"
#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp"
-const auto pubkey = std::string('0', 32);
-const auto signed_data = std::string('1', 32);
+const auto pubkey = std::string(32, '0');
+const auto signed_data = std::string(32, '1');
namespace iroha {
namespace consensus {
namespace yac {
diff --git a/test/module/irohad/simulator/simulator_test.cpp b/test/module/irohad/simulator/simulator_test.cpp
index fcdd8ddd65..d9122e7b2d 100644
--- a/test/module/irohad/simulator/simulator_test.cpp
+++ b/test/module/irohad/simulator/simulator_test.cpp
@@ -77,7 +77,7 @@ shared_model::proto::Block makeBlock(int height) {
return TestBlockBuilder()
.transactions(std::vector())
.height(height)
- .prevHash(shared_model::crypto::Hash(std::string("0", 32)))
+ .prevHash(shared_model::crypto::Hash(std::string(32, '0')))
.build();
}
diff --git a/test/module/irohad/torii/torii_service_test.cpp b/test/module/irohad/torii/torii_service_test.cpp
index 865948544d..5b0f80dc8c 100644
--- a/test/module/irohad/torii/torii_service_test.cpp
+++ b/test/module/irohad/torii/torii_service_test.cpp
@@ -127,7 +127,7 @@ class ToriiServiceTest : public testing::Test {
*/
TEST_F(ToriiServiceTest, CommandClient) {
iroha::protocol::TxStatusRequest tx_request;
- tx_request.set_tx_hash(std::string('1', 32));
+ tx_request.set_tx_hash(std::string(32, '1'));
iroha::protocol::ToriiResponse toriiResponse;
auto client1 = torii::CommandSyncClient(Ip, Port);
From f63a9ac8ca44851b3229522b19e761f5c62c6d92 Mon Sep 17 00:00:00 2001
From: Andrei Lebedev
Date: Thu, 5 Apr 2018 17:39:30 +0300
Subject: [PATCH 003/110] Ordering gate queue proposals order (#1181)
* Add order test for OrderingGate, simplify AlwaysValidValidator
* Replace regular queue with priority queue in OrderingGateImpl
Signed-off-by: Andrei Lebedev
---
irohad/ordering/impl/ordering_gate_impl.cpp | 10 +++-
irohad/ordering/impl/ordering_gate_impl.hpp | 15 +++++-
.../irohad/ordering/ordering_gate_test.cpp | 51 +++++++++++++++++++
.../builders/protobuf/test_block_builder.hpp | 2 +-
.../protobuf/test_proposal_builder.hpp | 3 +-
.../builders/protobuf/test_query_builder.hpp | 4 +-
.../protobuf/test_transaction_builder.hpp | 4 +-
.../shared_model/validators/validators.hpp | 10 +---
8 files changed, 82 insertions(+), 17 deletions(-)
diff --git a/irohad/ordering/impl/ordering_gate_impl.cpp b/irohad/ordering/impl/ordering_gate_impl.cpp
index 0dfad79966..bf55528127 100644
--- a/irohad/ordering/impl/ordering_gate_impl.cpp
+++ b/irohad/ordering/impl/ordering_gate_impl.cpp
@@ -17,12 +17,20 @@
#include
-#include "interfaces/transaction.hpp"
#include "ordering/impl/ordering_gate_impl.hpp"
+#include "interfaces/iroha_internal/proposal.hpp"
+#include "interfaces/transaction.hpp"
+
namespace iroha {
namespace ordering {
+ bool ProposalComparator::operator()(
+ const std::shared_ptr &lhs,
+ const std::shared_ptr &rhs) const {
+ return lhs->height() > rhs->height();
+ }
+
OrderingGateImpl::OrderingGateImpl(
std::shared_ptr transport)
: transport_(std::move(transport)), log_(logger::log("OrderingGate")) {}
diff --git a/irohad/ordering/impl/ordering_gate_impl.hpp b/irohad/ordering/impl/ordering_gate_impl.hpp
index 3f4e8c52bb..a455160535 100644
--- a/irohad/ordering/impl/ordering_gate_impl.hpp
+++ b/irohad/ordering/impl/ordering_gate_impl.hpp
@@ -21,7 +21,7 @@
#include "network/ordering_gate.hpp"
#include
-#include
+#include
#include "logger/logger.hpp"
#include "network/impl/async_grpc_client.hpp"
@@ -37,6 +37,15 @@ namespace shared_model {
namespace iroha {
namespace ordering {
+ /**
+ * Compare proposals by height
+ */
+ struct ProposalComparator {
+ bool operator()(
+ const std::shared_ptr &lhs,
+ const std::shared_ptr &rhs) const;
+ };
+
/**
* OrderingGate implementation with gRPC asynchronous client
* Interacts with given OrderingService
@@ -78,7 +87,9 @@ namespace iroha {
std::atomic_bool unlock_next_{true};
/// queue with all proposals received from ordering service
- tbb::concurrent_queue>
+ tbb::concurrent_priority_queue<
+ std::shared_ptr,
+ ProposalComparator>
proposal_queue_;
/// subscription of pcs::on_commit
diff --git a/test/module/irohad/ordering/ordering_gate_test.cpp b/test/module/irohad/ordering/ordering_gate_test.cpp
index 8e488bbd65..f6c2c846bb 100644
--- a/test/module/irohad/ordering/ordering_gate_test.cpp
+++ b/test/module/irohad/ordering/ordering_gate_test.cpp
@@ -224,3 +224,54 @@ TEST(OrderingGateQueueBehaviour, SendManyProposals) {
ASSERT_TRUE(wrapper_after.validate());
}
+
+/**
+ * @given Initialized OrderingGate
+ * AND MockPeerCommunicationService
+ * @when Receive proposals in random order
+ * @then on_proposal output is ordered
+ */
+TEST(OrderingGateQueueBehaviour, ReceiveUnordered) {
+ std::shared_ptr transport =
+ std::make_shared();
+
+ std::shared_ptr pcs =
+ std::make_shared();
+ rxcpp::subjects::subject commit_subject;
+ EXPECT_CALL(*pcs, on_commit())
+ .WillOnce(Return(commit_subject.get_observable()));
+
+ auto pushCommit = [&] {
+ commit_subject.get_subscriber().on_next(rxcpp::observable<>::just(
+ std::static_pointer_cast(
+ std::make_shared(
+ TestBlockBuilder().build()))));
+ };
+
+ OrderingGateImpl ordering_gate(transport);
+ ordering_gate.setPcs(*pcs);
+
+ auto pushProposal = [&](auto height) {
+ ordering_gate.onProposal(std::make_shared(
+ TestProposalBuilder().height(height).build()));
+ };
+
+ std::vector messages;
+ ordering_gate.on_proposal().subscribe([&](auto val) {
+ messages.push_back(val);
+ });
+
+ // this will set unlock_next_ to false, so proposals 4 and 3 are enqueued
+ pushProposal(2);
+
+ pushProposal(4);
+ pushProposal(3);
+
+ pushCommit();
+ pushCommit();
+
+ ASSERT_EQ(3, messages.size());
+ ASSERT_EQ(2, messages.at(0)->height());
+ ASSERT_EQ(3, messages.at(1)->height());
+ ASSERT_EQ(4, messages.at(2)->height());
+}
diff --git a/test/module/shared_model/builders/protobuf/test_block_builder.hpp b/test/module/shared_model/builders/protobuf/test_block_builder.hpp
index 9fe486a673..b53f88bca9 100644
--- a/test/module/shared_model/builders/protobuf/test_block_builder.hpp
+++ b/test/module/shared_model/builders/protobuf/test_block_builder.hpp
@@ -27,6 +27,6 @@
*/
using TestBlockBuilder = shared_model::proto::TemplateBlockBuilder<
(1 << shared_model::proto::TemplateBlockBuilder<>::total) - 1,
- shared_model::validation::BlockAlwaysValidValidator,
+ shared_model::validation::AlwaysValidValidator,
shared_model::proto::Block>;
#endif // IROHA_TEST_BLOCK_BUILDER_HPP
diff --git a/test/module/shared_model/builders/protobuf/test_proposal_builder.hpp b/test/module/shared_model/builders/protobuf/test_proposal_builder.hpp
index fb8da46423..11bc2f3eba 100644
--- a/test/module/shared_model/builders/protobuf/test_proposal_builder.hpp
+++ b/test/module/shared_model/builders/protobuf/test_proposal_builder.hpp
@@ -19,6 +19,7 @@
#define IROHA_TEST_PROPOSAL_BUILDER_HPP
#include "builders/protobuf/builder_templates/proposal_template.hpp"
+#include "module/shared_model/validators/validators.hpp"
/**
* Builder alias, to build shared model proto proposal object avoiding "required
@@ -26,6 +27,6 @@
*/
using TestProposalBuilder = shared_model::proto::TemplateProposalBuilder<
(1 << shared_model::proto::TemplateProposalBuilder<>::total) - 1,
- shared_model::validation::DefaultProposalValidator>;
+ shared_model::validation::AlwaysValidValidator>;
#endif // IROHA_TEST_PROPOSAL_BUILDER_HPP
diff --git a/test/module/shared_model/builders/protobuf/test_query_builder.hpp b/test/module/shared_model/builders/protobuf/test_query_builder.hpp
index 5324c1d288..3e567eb0a9 100644
--- a/test/module/shared_model/builders/protobuf/test_query_builder.hpp
+++ b/test/module/shared_model/builders/protobuf/test_query_builder.hpp
@@ -27,12 +27,12 @@
*/
using TestQueryBuilder = shared_model::proto::TemplateQueryBuilder<
(1 << shared_model::proto::TemplateQueryBuilder<>::total) - 1,
- shared_model::validation::QueryAlwaysValidValidator,
+ shared_model::validation::AlwaysValidValidator,
shared_model::proto::Query>;
using TestUnsignedQueryBuilder = shared_model::proto::TemplateQueryBuilder<
(1 << shared_model::proto::TemplateQueryBuilder<>::total) - 1,
- shared_model::validation::QueryAlwaysValidValidator,
+ shared_model::validation::AlwaysValidValidator,
shared_model::proto::UnsignedWrapper>;
#endif // IROHA_TEST_QUERY_BUILDER_HPP
diff --git a/test/module/shared_model/builders/protobuf/test_transaction_builder.hpp b/test/module/shared_model/builders/protobuf/test_transaction_builder.hpp
index 6de9f472f4..9b9f74da50 100644
--- a/test/module/shared_model/builders/protobuf/test_transaction_builder.hpp
+++ b/test/module/shared_model/builders/protobuf/test_transaction_builder.hpp
@@ -27,13 +27,13 @@
*/
using TestTransactionBuilder = shared_model::proto::TemplateTransactionBuilder<
(1 << shared_model::proto::TemplateTransactionBuilder<>::total) - 1,
- shared_model::validation::TransactionAlwaysValidValidator,
+ shared_model::validation::AlwaysValidValidator,
shared_model::proto::Transaction>;
using TestUnsignedTransactionBuilder =
shared_model::proto::TemplateTransactionBuilder<
(1 << shared_model::proto::TemplateTransactionBuilder<>::total) - 1,
- shared_model::validation::TransactionAlwaysValidValidator,
+ shared_model::validation::AlwaysValidValidator,
shared_model::proto::UnsignedWrapper>;
#endif // IROHA_TEST_TRANSACTION_BUILDER_HPP
diff --git a/test/module/shared_model/validators/validators.hpp b/test/module/shared_model/validators/validators.hpp
index 86d7e3c775..29c8d2f991 100644
--- a/test/module/shared_model/validators/validators.hpp
+++ b/test/module/shared_model/validators/validators.hpp
@@ -27,18 +27,12 @@ namespace shared_model {
// TODO: kamilsa 01.02.2018 IR-873 Replace all these validators with mock
// classes
- template
struct AlwaysValidValidator {
- Answer validate(const Iface &) const {
+ template
+ Answer validate(const T &) const {
return {};
}
};
- using TransactionAlwaysValidValidator =
- AlwaysValidValidator;
- using BlockAlwaysValidValidator = AlwaysValidValidator;
- using ProposalAlwaysValidValidator =
- AlwaysValidValidator;
- using QueryAlwaysValidValidator = AlwaysValidValidator;
} // namespace validation
} // namespace shared_model
From 321d6bf1b407efe4b565ae3da336101f9afca8f3 Mon Sep 17 00:00:00 2001
From: Artyom Bakhtin
Date: Mon, 9 Apr 2018 10:17:33 +0300
Subject: [PATCH 004/110] no symlinks + apt-get install (#1169)
Signed-off-by: Artyom Bakhtin
---
.jenkinsci/release-build.groovy | 2 +-
docker/release/aarch64/Dockerfile | 16 +++++++++++++++-
docker/release/aarch64/entrypoint.sh | 5 ++++-
docker/release/armv7l/Dockerfile | 16 +++++++++++++++-
docker/release/armv7l/entrypoint.sh | 5 ++++-
docker/release/x86_64/Dockerfile | 11 ++++-------
docker/release/x86_64/entrypoint.sh | 1 -
7 files changed, 43 insertions(+), 13 deletions(-)
mode change 120000 => 100644 docker/release/aarch64/Dockerfile
mode change 120000 => 100755 docker/release/aarch64/entrypoint.sh
mode change 120000 => 100644 docker/release/armv7l/Dockerfile
mode change 120000 => 100755 docker/release/armv7l/entrypoint.sh
diff --git a/.jenkinsci/release-build.groovy b/.jenkinsci/release-build.groovy
index 05d6613917..dc4db9ddab 100644
--- a/.jenkinsci/release-build.groovy
+++ b/.jenkinsci/release-build.groovy
@@ -57,7 +57,7 @@ def doReleaseBuild() {
sh "curl -L -o /tmp/${env.GIT_COMMIT}/entrypoint.sh https://raw.githubusercontent.com/hyperledger/iroha/${env.GIT_COMMIT}/docker/release/${platform}/entrypoint.sh"
sh "cp /tmp/${GIT_COMMIT}-${BUILD_NUMBER}/iroha.deb /tmp/${env.GIT_COMMIT}"
sh "chmod +x /tmp/${env.GIT_COMMIT}/entrypoint.sh"
- iCRelease = docker.build("hyperledger/iroha:${GIT_COMMIT}-${BUILD_NUMBER}-release", "-f /tmp/${env.GIT_COMMIT}/Dockerfile /tmp/${env.GIT_COMMIT}")
+ iCRelease = docker.build("hyperledger/iroha:${GIT_COMMIT}-${BUILD_NUMBER}-release", "--no-cache -f /tmp/${env.GIT_COMMIT}/Dockerfile /tmp/${env.GIT_COMMIT}")
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
if (env.BRANCH_NAME == 'develop') {
iCRelease.push("${platform}-develop-latest")
diff --git a/docker/release/aarch64/Dockerfile b/docker/release/aarch64/Dockerfile
deleted file mode 120000
index d810e95633..0000000000
--- a/docker/release/aarch64/Dockerfile
+++ /dev/null
@@ -1 +0,0 @@
-../x86_64/Dockerfile
\ No newline at end of file
diff --git a/docker/release/aarch64/Dockerfile b/docker/release/aarch64/Dockerfile
new file mode 100644
index 0000000000..c07120cb32
--- /dev/null
+++ b/docker/release/aarch64/Dockerfile
@@ -0,0 +1,15 @@
+FROM ubuntu:16.04
+
+RUN apt-get update; \
+ apt-get install -y libc-ares-dev
+
+#Install iroha
+COPY iroha.deb /tmp/iroha.deb
+RUN apt-get install -y /tmp/iroha.deb; \
+ rm -f /tmp/iroha.deb
+
+WORKDIR /opt/iroha_data
+
+COPY entrypoint.sh /entrypoint.sh
+ENTRYPOINT ["/entrypoint.sh"]
+CMD ["/sbin/init"]
diff --git a/docker/release/aarch64/entrypoint.sh b/docker/release/aarch64/entrypoint.sh
deleted file mode 120000
index d87c399ff9..0000000000
--- a/docker/release/aarch64/entrypoint.sh
+++ /dev/null
@@ -1 +0,0 @@
-../x86_64/entrypoint.sh
\ No newline at end of file
diff --git a/docker/release/aarch64/entrypoint.sh b/docker/release/aarch64/entrypoint.sh
new file mode 100755
index 0000000000..709e3d9bbc
--- /dev/null
+++ b/docker/release/aarch64/entrypoint.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+echo key=$KEY
+echo $PWD
+irohad --genesis_block genesis.block --config config.sample --keypair_name $KEY
diff --git a/docker/release/armv7l/Dockerfile b/docker/release/armv7l/Dockerfile
deleted file mode 120000
index d810e95633..0000000000
--- a/docker/release/armv7l/Dockerfile
+++ /dev/null
@@ -1 +0,0 @@
-../x86_64/Dockerfile
\ No newline at end of file
diff --git a/docker/release/armv7l/Dockerfile b/docker/release/armv7l/Dockerfile
new file mode 100644
index 0000000000..c07120cb32
--- /dev/null
+++ b/docker/release/armv7l/Dockerfile
@@ -0,0 +1,15 @@
+FROM ubuntu:16.04
+
+RUN apt-get update; \
+ apt-get install -y libc-ares-dev
+
+#Install iroha
+COPY iroha.deb /tmp/iroha.deb
+RUN apt-get install -y /tmp/iroha.deb; \
+ rm -f /tmp/iroha.deb
+
+WORKDIR /opt/iroha_data
+
+COPY entrypoint.sh /entrypoint.sh
+ENTRYPOINT ["/entrypoint.sh"]
+CMD ["/sbin/init"]
diff --git a/docker/release/armv7l/entrypoint.sh b/docker/release/armv7l/entrypoint.sh
deleted file mode 120000
index d87c399ff9..0000000000
--- a/docker/release/armv7l/entrypoint.sh
+++ /dev/null
@@ -1 +0,0 @@
-../x86_64/entrypoint.sh
\ No newline at end of file
diff --git a/docker/release/armv7l/entrypoint.sh b/docker/release/armv7l/entrypoint.sh
new file mode 100755
index 0000000000..709e3d9bbc
--- /dev/null
+++ b/docker/release/armv7l/entrypoint.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+echo key=$KEY
+echo $PWD
+irohad --genesis_block genesis.block --config config.sample --keypair_name $KEY
diff --git a/docker/release/x86_64/Dockerfile b/docker/release/x86_64/Dockerfile
index 53f05883fd..c07120cb32 100644
--- a/docker/release/x86_64/Dockerfile
+++ b/docker/release/x86_64/Dockerfile
@@ -1,15 +1,12 @@
FROM ubuntu:16.04
-RUN apt-get update;\
- apt-get upgrade -y; \
- apt-get install -y \
- libc-ares-dev
+RUN apt-get update; \
+ apt-get install -y libc-ares-dev
#Install iroha
COPY iroha.deb /tmp/iroha.deb
-RUN dpkg -i /tmp/iroha.deb
-
-RUN apt-get -fy install;rm -f /tmp/iroha.deb
+RUN apt-get install -y /tmp/iroha.deb; \
+ rm -f /tmp/iroha.deb
WORKDIR /opt/iroha_data
diff --git a/docker/release/x86_64/entrypoint.sh b/docker/release/x86_64/entrypoint.sh
index 85595eb18a..709e3d9bbc 100755
--- a/docker/release/x86_64/entrypoint.sh
+++ b/docker/release/x86_64/entrypoint.sh
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
echo key=$KEY
echo $PWD
-iroha-cli --genesis_block --peers_address peers.list
irohad --genesis_block genesis.block --config config.sample --keypair_name $KEY
From 2e0306321f44d0226498368402d0b083688bea7b Mon Sep 17 00:00:00 2001
From: Andrei Lebedev
Date: Mon, 9 Apr 2018 13:23:22 +0300
Subject: [PATCH 005/110] Fix consensus getting locked due to synchronous
subscribers (#1180)
* Fix consensus getting locked due to synchronous subscribers
* Add tests for operation order on vote and on reject
Signed-off-by: Andrei Lebedev
---
irohad/consensus/yac/impl/yac.cpp | 4 +-
.../yac/yac_simple_cold_case_test.cpp | 66 +++++++++++++++++--
2 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/irohad/consensus/yac/impl/yac.cpp b/irohad/consensus/yac/impl/yac.cpp
index a663f4e13a..014895eeee 100644
--- a/irohad/consensus/yac/impl/yac.cpp
+++ b/irohad/consensus/yac/impl/yac.cpp
@@ -210,8 +210,8 @@ namespace iroha {
// IR-497
},
[&](const CommitMessage &commit) {
- notifier_.get_subscriber().on_next(commit);
this->propagateCommit(commit);
+ notifier_.get_subscriber().on_next(commit);
});
}
this->closeRound();
@@ -246,8 +246,8 @@ namespace iroha {
// propagate for all
log_->info("Propagate commit {} to whole network",
vote.hash.block_hash);
- notifier_.get_subscriber().on_next(commit);
this->propagateCommit(commit);
+ notifier_.get_subscriber().on_next(commit);
},
[&](const RejectMessage &reject) {
// propagate reject for all
diff --git a/test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp b/test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp
index 4978884e57..2476988ade 100644
--- a/test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp
+++ b/test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp
@@ -15,9 +15,6 @@
* limitations under the License.
*/
-#ifndef IROHA_YAC_SIMPLE_CASE_TEST_HPP
-#define IROHA_YAC_SIMPLE_CASE_TEST_HPP
-
#include
#include
#include
@@ -34,6 +31,7 @@ using ::testing::_;
using ::testing::An;
using ::testing::AtLeast;
using ::testing::Return;
+using ::testing::Invoke;
using namespace iroha::consensus::yac;
using namespace framework::test_subscriber;
@@ -176,4 +174,64 @@ TEST_F(YacTest, YacWhenColdStartAndAchieveCommitMessage) {
ASSERT_TRUE(wrapper.validate());
}
-#endif // IROHA_YAC_SIMPLE_CASE_TEST_HPP
+
+/**
+ * @given initialized YAC
+ * @when receive supermajority of votes for a hash
+ * @then commit is sent to the network before notifying subscribers
+ */
+TEST_F(YacTest, PropagateCommitBeforeNotifyingSubscribersApplyVote) {
+ EXPECT_CALL(*crypto, verify(An())).Times(default_peers.size())
+ .WillRepeatedly(Return(true));
+ std::vector messages;
+ EXPECT_CALL(*network, send_commit(_, _))
+ .Times(default_peers.size())
+ .WillRepeatedly(Invoke([&](const auto &, const auto &msg) {
+ messages.push_back(msg);
+ }));
+
+ yac->on_commit().subscribe([&](auto msg) {
+ // verify that commits are already sent to the network
+ ASSERT_EQ(default_peers.size(), messages.size());
+ messages.push_back(msg);
+ });
+
+ for (size_t i = 0; i < default_peers.size(); ++i) {
+ yac->on_vote(create_vote(YacHash{}, std::to_string(i)));
+ }
+
+ // verify that on_commit subscribers are notified
+ ASSERT_EQ(default_peers.size() + 1, messages.size());
+}
+
+/**
+ * @given initialized YAC
+ * @when receive reject message which triggers commit
+ * @then commit is sent to the network before notifying subscribers
+ */
+TEST_F(YacTest, PropagateCommitBeforeNotifyingSubscribersApplyReject) {
+ EXPECT_CALL(*crypto, verify(An())).WillOnce(Return(true));
+ EXPECT_CALL(*timer, deny()).Times(AtLeast(1));
+ std::vector messages;
+ EXPECT_CALL(*network, send_commit(_, _))
+ .Times(default_peers.size())
+ .WillRepeatedly(Invoke([&](const auto &, const auto &msg) {
+ messages.push_back(msg);
+ }));
+
+ yac->on_commit().subscribe([&](auto msg) {
+ // verify that commits are already sent to the network
+ ASSERT_EQ(default_peers.size(), messages.size());
+ messages.push_back(msg);
+ });
+
+ RejectMessage reject({});
+ for (size_t i = 0; i < default_peers.size(); ++i) {
+ reject.votes.push_back(create_vote(YacHash{}, std::to_string(i)));
+ }
+
+ yac->on_reject(reject);
+
+ // verify that on_commit subscribers are notified
+ ASSERT_EQ(default_peers.size() + 1, messages.size());
+}
From 9a87c2bbef7f31c3e512642dc2280ebb188e03b8 Mon Sep 17 00:00:00 2001
From: Konstantin Munichev
Date: Tue, 10 Apr 2018 11:58:16 +0300
Subject: [PATCH 006/110] Change namespace for permissions (#1194)
- Use shared_model::permissions namespace for permissions.hpp
- Corresponding changes in dependent files
Signed-off-by: luckychess
---
.../impl/interactive_transaction_cli.cpp | 1 +
irohad/execution/impl/command_executor.cpp | 102 +++++++++++-------
.../converters/impl/pb_command_factory.cpp | 19 ++--
.../generators/impl/command_generator.cpp | 1 +
irohad/model/impl/query_execution.cpp | 1 +
shared_model/validators/field_validator.cpp | 10 +-
shared_model/validators/permissions.hpp | 14 +--
.../integration_test_framework.cpp | 12 +--
test/framework/test_block_generator.cpp | 3 +-
.../acceptance/add_asset_qty_test.cpp | 12 +--
.../acceptance/create_account_test.cpp | 6 +-
.../acceptance/create_domain_test.cpp | 6 +-
.../acceptance/create_role_test.cpp | 21 ++--
.../acceptance/get_transactions_test.cpp | 16 +--
.../acceptance/subtract_asset_qty_test.cpp | 8 +-
.../acceptance/transfer_asset_test.cpp | 24 +++--
test/integration/client_test.cpp | 1 +
.../irohad/ametsuchi/ametsuchi_test.cpp | 53 ++++-----
.../irohad/ametsuchi/kv_storage_test.cpp | 8 +-
.../model/command_validate_execute_test.cpp | 1 +
.../model/converters/json_commands_test.cpp | 1 +
.../model/converters/pb_commands_test.cpp | 1 +
.../torii/processor/query_processor_test.cpp | 8 +-
.../irohad/torii/torii_queries_test.cpp | 43 +++++---
.../irohad/validation/query_execution.cpp | 1 +
.../validators/field_validator_test.cpp | 17 +--
26 files changed, 230 insertions(+), 160 deletions(-)
diff --git a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp
index 386629218c..c2af842707 100644
--- a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp
+++ b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp
@@ -36,6 +36,7 @@
#include "parser/parser.hpp" // for parser::ParseValue
using namespace iroha::model;
+using namespace shared_model::permissions;
namespace iroha_cli {
namespace interactive {
diff --git a/irohad/execution/impl/command_executor.cpp b/irohad/execution/impl/command_executor.cpp
index a6bd3eda6e..6170e524a2 100644
--- a/irohad/execution/impl/command_executor.cpp
+++ b/irohad/execution/impl/command_executor.cpp
@@ -21,8 +21,8 @@
#include "execution/common_executor.hpp"
#include "interfaces/commands/command.hpp"
-#include "validators/permissions.hpp"
#include "utils/amount_utils.hpp"
+#include "validators/permissions.hpp"
namespace iroha {
@@ -362,8 +362,8 @@ namespace iroha {
.str(),
command_name);
}
- auto account_asset = queries->getAccountAsset(
- command->accountId(), command->assetId());
+ auto account_asset =
+ queries->getAccountAsset(command->accountId(), command->assetId());
if (not account_asset) {
return makeExecutionError((boost::format("%s do not have %s")
% command->accountId() % command->assetId())
@@ -506,7 +506,9 @@ namespace iroha {
// any asset
return creator_account_id == command.accountId()
and checkAccountRolePermission(
- creator_account_id, queries, model::can_add_asset_qty);
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_add_asset_qty);
}
bool CommandValidator::hasPermissions(
@@ -514,7 +516,7 @@ namespace iroha {
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
return checkAccountRolePermission(
- creator_account_id, queries, model::can_add_peer);
+ creator_account_id, queries, shared_model::permissions::can_add_peer);
}
bool CommandValidator::hasPermissions(
@@ -526,11 +528,15 @@ namespace iroha {
// account and he has permission CanAddSignatory
(command.accountId() == creator_account_id
and checkAccountRolePermission(
- creator_account_id, queries, model::can_add_signatory))
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_add_signatory))
or
// Case 2. Creator has granted permission for it
(queries.hasAccountGrantablePermission(
- creator_account_id, command.accountId(), model::can_add_signatory));
+ creator_account_id,
+ command.accountId(),
+ shared_model::permissions::can_add_signatory));
}
bool CommandValidator::hasPermissions(
@@ -538,7 +544,9 @@ namespace iroha {
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
return checkAccountRolePermission(
- creator_account_id, queries, model::can_append_role);
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_append_role);
}
bool CommandValidator::hasPermissions(
@@ -546,7 +554,9 @@ namespace iroha {
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
return checkAccountRolePermission(
- creator_account_id, queries, model::can_create_account);
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_create_account);
}
bool CommandValidator::hasPermissions(
@@ -554,7 +564,9 @@ namespace iroha {
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
return checkAccountRolePermission(
- creator_account_id, queries, model::can_create_asset);
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_create_asset);
}
bool CommandValidator::hasPermissions(
@@ -562,7 +574,9 @@ namespace iroha {
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
return checkAccountRolePermission(
- creator_account_id, queries, model::can_create_domain);
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_create_domain);
}
bool CommandValidator::hasPermissions(
@@ -570,7 +584,9 @@ namespace iroha {
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
return checkAccountRolePermission(
- creator_account_id, queries, model::can_create_role);
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_create_role);
}
bool CommandValidator::hasPermissions(
@@ -578,7 +594,9 @@ namespace iroha {
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
return checkAccountRolePermission(
- creator_account_id, queries, model::can_detach_role);
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_detach_role);
}
bool CommandValidator::hasPermissions(
@@ -588,7 +606,7 @@ namespace iroha {
return checkAccountRolePermission(
creator_account_id,
queries,
- model::can_grant + command.permissionName());
+ shared_model::permissions::can_grant + command.permissionName());
}
bool CommandValidator::hasPermissions(
@@ -600,11 +618,14 @@ namespace iroha {
// permission on it
(creator_account_id == command.accountId()
and checkAccountRolePermission(
- creator_account_id, queries, model::can_remove_signatory))
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_remove_signatory))
// 2. Creator has granted permission on removal
- or (queries.hasAccountGrantablePermission(creator_account_id,
- command.accountId(),
- model::can_remove_signatory));
+ or (queries.hasAccountGrantablePermission(
+ creator_account_id,
+ command.accountId(),
+ shared_model::permissions::can_remove_signatory));
}
bool CommandValidator::hasPermissions(
@@ -624,7 +645,9 @@ namespace iroha {
creator_account_id == command.accountId() or
// Case 2. Creator has grantable permission to set account key/value
queries.hasAccountGrantablePermission(
- creator_account_id, command.accountId(), model::can_set_detail);
+ creator_account_id,
+ command.accountId(),
+ shared_model::permissions::can_set_detail);
}
bool CommandValidator::hasPermissions(
@@ -635,10 +658,14 @@ namespace iroha {
// 1. Creator set quorum for his account -> must have permission
(creator_account_id == command.accountId()
and checkAccountRolePermission(
- creator_account_id, queries, model::can_set_quorum))
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_set_quorum))
// 2. Creator has granted permission on it
or (queries.hasAccountGrantablePermission(
- creator_account_id, command.accountId(), model::can_set_quorum));
+ creator_account_id,
+ command.accountId(),
+ shared_model::permissions::can_set_quorum));
}
bool CommandValidator::hasPermissions(
@@ -647,7 +674,9 @@ namespace iroha {
const shared_model::interface::types::AccountIdType &creator_account_id) {
return creator_account_id == command.accountId()
and checkAccountRolePermission(
- creator_account_id, queries, model::can_subtract_asset_qty);
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_subtract_asset_qty);
}
bool CommandValidator::hasPermissions(
@@ -660,15 +689,18 @@ namespace iroha {
and queries.hasAccountGrantablePermission(
creator_account_id,
command.srcAccountId(),
- model::can_transfer))
+ shared_model::permissions::can_transfer))
or
// 2. Creator transfer from their account
(creator_account_id == command.srcAccountId()
and checkAccountRolePermission(
- creator_account_id, queries, model::can_transfer)))
+ creator_account_id,
+ queries,
+ shared_model::permissions::can_transfer)))
// For both cases, dest_account must have can_receive
- and checkAccountRolePermission(
- command.destAccountId(), queries, model::can_receive);
+ and checkAccountRolePermission(command.destAccountId(),
+ queries,
+ shared_model::permissions::can_receive);
}
bool CommandValidator::isValid(
@@ -745,12 +777,12 @@ namespace iroha {
const shared_model::interface::CreateRole &command,
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
- return std::all_of(
- command.rolePermissions().begin(),
- command.rolePermissions().end(),
- [&queries, &creator_account_id](auto perm) {
- return checkAccountRolePermission(creator_account_id, queries, perm);
- });
+ return std::all_of(command.rolePermissions().begin(),
+ command.rolePermissions().end(),
+ [&queries, &creator_account_id](auto perm) {
+ return checkAccountRolePermission(
+ creator_account_id, queries, perm);
+ });
}
bool CommandValidator::isValid(
@@ -772,8 +804,7 @@ namespace iroha {
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
auto account = queries.getAccount(command.accountId());
- auto signatories =
- queries.getSignatories(command.accountId());
+ auto signatories = queries.getSignatories(command.accountId());
if (not(account and signatories)) {
// No account or signatories found
@@ -803,8 +834,7 @@ namespace iroha {
const shared_model::interface::SetQuorum &command,
ametsuchi::WsvQuery &queries,
const shared_model::interface::types::AccountIdType &creator_account_id) {
- auto signatories =
- queries.getSignatories(command.accountId());
+ auto signatories = queries.getSignatories(command.accountId());
if (not(signatories)) {
// No signatories of an account found
diff --git a/irohad/model/converters/impl/pb_command_factory.cpp b/irohad/model/converters/impl/pb_command_factory.cpp
index 3a68bb484c..9d1fbd1818 100644
--- a/irohad/model/converters/impl/pb_command_factory.cpp
+++ b/irohad/model/converters/impl/pb_command_factory.cpp
@@ -21,6 +21,8 @@
#include "model/converters/pb_common.hpp"
+using namespace shared_model::permissions;
+
namespace iroha {
namespace model {
namespace converters {
@@ -85,19 +87,24 @@ namespace iroha {
// Can get all account assets
(protocol::RolePermission::can_get_all_acc_ast, can_get_all_acc_ast)
// Can get domain account assets
- (protocol::RolePermission::can_get_domain_acc_ast, can_get_domain_acc_ast)
+ (protocol::RolePermission::can_get_domain_acc_ast,
+ can_get_domain_acc_ast)
// Can get my account detail
- (protocol::RolePermission::can_get_my_acc_detail, can_get_my_acc_detail)
+ (protocol::RolePermission::can_get_my_acc_detail,
+ can_get_my_acc_detail)
// Can get all account detail
- (protocol::RolePermission::can_get_all_acc_detail, can_get_all_acc_detail)
+ (protocol::RolePermission::can_get_all_acc_detail,
+ can_get_all_acc_detail)
// Can get domain account detail
- (protocol::RolePermission::can_get_domain_acc_detail, can_get_domain_acc_detail)
+ (protocol::RolePermission::can_get_domain_acc_detail,
+ can_get_domain_acc_detail)
// Can get my account transactions
(protocol::RolePermission::can_get_my_acc_txs, can_get_my_acc_txs)
// Can get all account transactions
(protocol::RolePermission::can_get_all_acc_txs, can_get_all_acc_txs)
// Can get domain account transactions
- (protocol::RolePermission::can_get_domain_acc_txs, can_get_domain_acc_txs)
+ (protocol::RolePermission::can_get_domain_acc_txs,
+ can_get_domain_acc_txs)
// Can get my account assets transactions
(protocol::RolePermission::can_get_my_acc_ast_txs,
can_get_my_acc_ast_txs)
@@ -142,7 +149,7 @@ namespace iroha {
can_set_detail)
// Can transfer my assets
(protocol::GrantablePermission::can_transfer_my_assets,
- can_transfer);
+ can_transfer);
}
// asset quantity
diff --git a/irohad/model/generators/impl/command_generator.cpp b/irohad/model/generators/impl/command_generator.cpp
index 5b79890bef..6c1fcd4220 100644
--- a/irohad/model/generators/impl/command_generator.cpp
+++ b/irohad/model/generators/impl/command_generator.cpp
@@ -32,6 +32,7 @@
#include "validators/permissions.hpp"
using namespace generator;
+using namespace shared_model::permissions;
namespace iroha {
namespace model {
diff --git a/irohad/model/impl/query_execution.cpp b/irohad/model/impl/query_execution.cpp
index 6feec625d0..cd68b41f35 100644
--- a/irohad/model/impl/query_execution.cpp
+++ b/irohad/model/impl/query_execution.cpp
@@ -23,6 +23,7 @@
#include "validators/permissions.hpp"
using namespace iroha::model;
+using namespace shared_model::permissions;
using namespace iroha::ametsuchi;
// TODO: 28/03/2018 x3medima17 remove poly wrapper, IR-1011
diff --git a/shared_model/validators/field_validator.cpp b/shared_model/validators/field_validator.cpp
index 64cf17a4c3..5bd825fec0 100644
--- a/shared_model/validators/field_validator.cpp
+++ b/shared_model/validators/field_validator.cpp
@@ -18,8 +18,8 @@
#include "validators/field_validator.hpp"
#include
#include
-#include "permissions.hpp"
#include "cryptography/crypto_provider/crypto_verifier.hpp"
+#include "permissions.hpp"
// TODO: 15.02.18 nickaleks Change structure to compositional IR-978
@@ -213,8 +213,8 @@ namespace shared_model {
void FieldValidator::validatePermission(
ReasonsGroupType &reason,
const interface::types::PermissionNameType &permission_name) const {
- if (iroha::model::all_perm_group.find(permission_name)
- == iroha::model::all_perm_group.end()) {
+ if (shared_model::permissions::all_perm_group.find(permission_name)
+ == shared_model::permissions::all_perm_group.end()) {
reason.second.push_back("Provided permission does not exist");
}
}
@@ -226,8 +226,8 @@ namespace shared_model {
reason.second.push_back(
"Permission set should contain at least one permission");
}
- if (not std::includes(iroha::model::role_perm_group.begin(),
- iroha::model::role_perm_group.end(),
+ if (not std::includes(shared_model::permissions::role_perm_group.begin(),
+ shared_model::permissions::role_perm_group.end(),
permissions.begin(),
permissions.end())) {
reason.second.push_back(
diff --git a/shared_model/validators/permissions.hpp b/shared_model/validators/permissions.hpp
index 0f692b0dfa..8c3e1281ae 100644
--- a/shared_model/validators/permissions.hpp
+++ b/shared_model/validators/permissions.hpp
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-#ifndef IROHA_PERMISSIONS_HPP
-#define IROHA_PERMISSIONS_HPP
+#ifndef SHARED_MODEL_PERMISSIONS_HPP
+#define SHARED_MODEL_PERMISSIONS_HPP
#include
#include
-namespace iroha {
- namespace model {
+namespace shared_model {
+ namespace permissions {
/* ~~~~~~~~ Command-related permissions ~~~~~~~~ */
@@ -252,7 +252,7 @@ namespace iroha {
can_set_my_account_detail,
can_transfer_my_assets};
- } // namespace model
-} // namespace iroha
+ } // namespace shared_model
+} // namespace permissions
-#endif // IROHA_PERMISSIONS_HPP
+#endif // SHARED_MODEL_PERMISSIONS_HPP
diff --git a/test/framework/integration_framework/integration_test_framework.cpp b/test/framework/integration_framework/integration_test_framework.cpp
index de9bccc4f9..d20bc3f546 100644
--- a/test/framework/integration_framework/integration_test_framework.cpp
+++ b/test/framework/integration_framework/integration_test_framework.cpp
@@ -75,12 +75,12 @@ DROP TABLE IF EXISTS index_by_id_height_asset;
.txCounter(1)
.createdTime(iroha::time::now())
.addPeer("0.0.0.0:50541", key.publicKey())
- .createRole(
- kDefaultRole,
- // TODO (@l4l) IR-874 create more confort way for
- // permssion-dependent proto building
- std::vector{iroha::model::role_perm_group.begin(),
- iroha::model::role_perm_group.end()})
+ .createRole(kDefaultRole,
+ // TODO (@l4l) IR-874 create more confort way for
+ // permssion-dependent proto building
+ std::vector{
+ shared_model::permissions::role_perm_group.begin(),
+ shared_model::permissions::role_perm_group.end()})
.createDomain(kDefaultDomain, kDefaultRole)
.createAccount(kAdminName, kDefaultDomain, key.publicKey())
.createAsset(kAssetName, kDefaultDomain, 1)
diff --git a/test/framework/test_block_generator.cpp b/test/framework/test_block_generator.cpp
index 3dd0a229cd..12081bc710 100644
--- a/test/framework/test_block_generator.cpp
+++ b/test/framework/test_block_generator.cpp
@@ -22,11 +22,12 @@
#include "model/commands/create_account.hpp"
#include "model/commands/create_asset.hpp"
#include "model/commands/create_domain.hpp"
-#include "validators/permissions.hpp"
#include "model/sha3_hash.hpp"
+#include "validators/permissions.hpp"
using namespace iroha;
using namespace iroha::model;
+using namespace shared_model::permissions;
namespace framework {
namespace generator {
diff --git a/test/integration/acceptance/add_asset_qty_test.cpp b/test/integration/acceptance/add_asset_qty_test.cpp
index ed49ed805e..5a66b3ec11 100644
--- a/test/integration/acceptance/add_asset_qty_test.cpp
+++ b/test/integration/acceptance/add_asset_qty_test.cpp
@@ -21,8 +21,8 @@
#include "datetime/time.hpp"
#include "framework/base_tx.hpp"
#include "framework/integration_framework/integration_test_framework.hpp"
-#include "validators/permissions.hpp"
#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
+#include "validators/permissions.hpp"
using namespace std::string_literals;
using namespace integration_framework;
@@ -36,7 +36,7 @@ class AddAssetQuantity : public ::testing::Test {
* @return built tx and a hash of its payload
*/
auto makeUserWithPerms(const std::vector &perms = {
- iroha::model::can_add_asset_qty}) {
+ shared_model::permissions::can_add_asset_qty}) {
return framework::createUserWithPerms(
kUser, kUserKeypair.publicKey(), "role"s, perms)
.build()
@@ -100,7 +100,7 @@ TEST_F(AddAssetQuantity, Basic) {
TEST_F(AddAssetQuantity, NoPermissions) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_get_my_txs}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_get_my_txs}))
.skipProposal()
.skipBlock()
.sendTx(completeTx(baseTx().addAssetQuantity(kUserId, kAsset, kAmount)))
@@ -252,9 +252,9 @@ TEST_F(AddAssetQuantity, OtherDomain) {
.creatorAccountId(
integration_framework::IntegrationTestFramework::kAdminId)
.createdTime(iroha::time::now())
- .createRole(
- kNewRole,
- std::vector{iroha::model::can_get_my_txs})
+ .createRole(kNewRole,
+ std::vector{
+ shared_model::permissions::can_get_my_txs})
.createDomain(kNewDomain, kNewRole)
.createAccount(
kNewUser,
diff --git a/test/integration/acceptance/create_account_test.cpp b/test/integration/acceptance/create_account_test.cpp
index e0f3512725..7eb2c60370 100644
--- a/test/integration/acceptance/create_account_test.cpp
+++ b/test/integration/acceptance/create_account_test.cpp
@@ -21,8 +21,8 @@
#include "datetime/time.hpp"
#include "framework/base_tx.hpp"
#include "framework/integration_framework/integration_test_framework.hpp"
-#include "validators/permissions.hpp"
#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
+#include "validators/permissions.hpp"
using namespace std::string_literals;
using namespace integration_framework;
@@ -36,7 +36,7 @@ class CreateAccount : public ::testing::Test {
* @return built tx and a hash of its payload
*/
auto makeUserWithPerms(const std::vector &perms = {
- iroha::model::can_create_account}) {
+ shared_model::permissions::can_create_account}) {
return framework::createUserWithPerms(
kUser, kUserKeypair.publicKey(), "role"s, perms)
.build()
@@ -103,7 +103,7 @@ TEST_F(CreateAccount, Basic) {
TEST_F(CreateAccount, NoPermissions) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_get_my_txs}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_get_my_txs}))
.skipProposal()
.skipBlock()
.sendTx(completeTx(baseTx().createAccount(
diff --git a/test/integration/acceptance/create_domain_test.cpp b/test/integration/acceptance/create_domain_test.cpp
index d8e3e73131..90a636a542 100644
--- a/test/integration/acceptance/create_domain_test.cpp
+++ b/test/integration/acceptance/create_domain_test.cpp
@@ -21,8 +21,8 @@
#include "datetime/time.hpp"
#include "framework/base_tx.hpp"
#include "framework/integration_framework/integration_test_framework.hpp"
-#include "validators/permissions.hpp"
#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
+#include "validators/permissions.hpp"
using namespace std::string_literals;
using namespace integration_framework;
@@ -36,7 +36,7 @@ class CreateDomain : public ::testing::Test {
* @return built tx
*/
auto makeUserWithPerms(const std::vector &perms = {
- iroha::model::can_create_domain}) {
+ shared_model::permissions::can_create_domain}) {
return framework::createUserWithPerms(
kUser, kUserKeypair.publicKey(), kRole, perms)
.build()
@@ -100,7 +100,7 @@ TEST_F(CreateDomain, Basic) {
TEST_F(CreateDomain, NoPermissions) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_get_my_txs}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_get_my_txs}))
.skipProposal()
.skipBlock()
.sendTx(completeTx(baseTx().createDomain(kNewDomain, kRole)))
diff --git a/test/integration/acceptance/create_role_test.cpp b/test/integration/acceptance/create_role_test.cpp
index 8f75a234f2..65b88943af 100644
--- a/test/integration/acceptance/create_role_test.cpp
+++ b/test/integration/acceptance/create_role_test.cpp
@@ -21,8 +21,8 @@
#include "datetime/time.hpp"
#include "framework/base_tx.hpp"
#include "framework/integration_framework/integration_test_framework.hpp"
-#include "validators/permissions.hpp"
#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
+#include "validators/permissions.hpp"
using namespace std::string_literals;
using namespace integration_framework;
@@ -36,8 +36,8 @@ class CreateRole : public ::testing::Test {
* @return built tx and a hash of its payload
*/
auto makeUserWithPerms(const std::vector &perms = {
- iroha::model::can_get_my_txs,
- iroha::model::can_create_role}) {
+ shared_model::permissions::can_get_my_txs,
+ shared_model::permissions::can_create_role}) {
return framework::createUserWithPerms(
kUser, kUserKeypair.publicKey(), kNewRole, perms)
.build()
@@ -60,7 +60,7 @@ class CreateRole : public ::testing::Test {
}
auto baseTx(const std::vector &perms = {
- iroha::model::can_get_my_txs}) {
+ shared_model::permissions::can_get_my_txs}) {
return baseTx(perms, kRole);
}
@@ -110,7 +110,7 @@ TEST_F(CreateRole, Basic) {
TEST_F(CreateRole, HaveNoPerms) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_get_my_txs}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_get_my_txs}))
.skipProposal()
.skipBlock()
.sendTx(completeTx(baseTx()))
@@ -131,7 +131,8 @@ TEST_F(CreateRole, EmptyRole) {
.sendTx(makeUserWithPerms())
.skipProposal()
.skipBlock()
- .sendTx(completeTx(baseTx({iroha::model::can_get_my_txs}, "")));
+ .sendTx(
+ completeTx(baseTx({shared_model::permissions::can_get_my_txs}, "")));
ASSERT_ANY_THROW(itf.skipProposal());
}
@@ -163,8 +164,8 @@ TEST_F(CreateRole, LongRoleName) {
.sendTx(makeUserWithPerms())
.skipProposal()
.skipBlock()
- .sendTx(completeTx(
- baseTx({iroha::model::can_get_my_txs}, std::string(33, 'a'))));
+ .sendTx(completeTx(baseTx({shared_model::permissions::can_get_my_txs},
+ std::string(33, 'a'))));
ASSERT_ANY_THROW(itf.skipProposal());
}
@@ -179,8 +180,8 @@ TEST_F(CreateRole, MaxLenRoleName) {
.sendTx(makeUserWithPerms())
.skipProposal()
.skipBlock()
- .sendTx(completeTx(
- baseTx({iroha::model::can_get_my_txs}, std::string(32, 'a'))))
+ .sendTx(completeTx(baseTx({shared_model::permissions::can_get_my_txs},
+ std::string(32, 'a'))))
.skipProposal()
.checkBlock(
[](auto &block) { ASSERT_EQ(block->transactions().size(), 1); })
diff --git a/test/integration/acceptance/get_transactions_test.cpp b/test/integration/acceptance/get_transactions_test.cpp
index a290197902..b21a37543c 100644
--- a/test/integration/acceptance/get_transactions_test.cpp
+++ b/test/integration/acceptance/get_transactions_test.cpp
@@ -23,8 +23,8 @@
#include "framework/base_tx.hpp"
#include "framework/integration_framework/integration_test_framework.hpp"
#include "interfaces/utils/specified_visitor.hpp"
-#include "validators/permissions.hpp"
#include "utils/query_error_response_visitor.hpp"
+#include "validators/permissions.hpp"
using namespace std::string_literals;
using namespace integration_framework;
@@ -39,7 +39,7 @@ class GetTransactions : public ::testing::Test {
*/
auto makeUserWithPerms(const std::vector &perms) {
auto new_perms = perms;
- new_perms.push_back(iroha::model::can_set_quorum);
+ new_perms.push_back(shared_model::permissions::can_set_quorum);
return framework::createUserWithPerms(
kUser, kUserKeypair.publicKey(), kNewRole, new_perms)
.build()
@@ -101,7 +101,7 @@ TEST_F(GetTransactions, HaveNoGetPerms) {
auto dummy_tx = dummyTx();
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_read_assets}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_read_assets}))
.sendTx(dummy_tx)
.checkBlock(
[](auto &block) { ASSERT_EQ(block->transactions().size(), 2); })
@@ -127,7 +127,7 @@ TEST_F(GetTransactions, HaveGetAllTx) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_get_all_txs}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_get_all_txs}))
.sendTx(dummy_tx)
.checkBlock(
[](auto &block) { ASSERT_EQ(block->transactions().size(), 2); })
@@ -153,7 +153,7 @@ TEST_F(GetTransactions, HaveGetMyTx) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_get_my_txs}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_get_my_txs}))
.sendTx(dummy_tx)
.checkBlock(
[](auto &block) { ASSERT_EQ(block->transactions().size(), 2); })
@@ -187,7 +187,7 @@ TEST_F(GetTransactions, InvalidSignatures) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_get_my_txs}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_get_my_txs}))
.sendQuery(query, check)
.done();
}
@@ -208,7 +208,7 @@ TEST_F(GetTransactions, InexistentHash) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_get_my_txs}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_get_my_txs}))
.checkBlock(
[](auto &block) { ASSERT_EQ(block->transactions().size(), 1); })
.sendQuery(makeQuery(crypto::Hash(std::string(32, '0'))), check)
@@ -230,7 +230,7 @@ TEST_F(GetTransactions, DISABLED_OtherUserTx) {
ASSERT_EQ(resp.value()->transactions().size(), 0);
};
- auto tx = makeUserWithPerms({iroha::model::can_get_my_txs});
+ auto tx = makeUserWithPerms({shared_model::permissions::can_get_my_txs});
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
.sendTx(tx)
diff --git a/test/integration/acceptance/subtract_asset_qty_test.cpp b/test/integration/acceptance/subtract_asset_qty_test.cpp
index 5cb78ecf57..c161ed4630 100644
--- a/test/integration/acceptance/subtract_asset_qty_test.cpp
+++ b/test/integration/acceptance/subtract_asset_qty_test.cpp
@@ -21,8 +21,8 @@
#include "datetime/time.hpp"
#include "framework/base_tx.hpp"
#include "framework/integration_framework/integration_test_framework.hpp"
-#include "validators/permissions.hpp"
#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
+#include "validators/permissions.hpp"
using namespace std::string_literals;
using namespace integration_framework;
@@ -36,8 +36,8 @@ class SubtractAssetQuantity : public ::testing::Test {
* @return built tx and a hash of its payload
*/
auto makeUserWithPerms(const std::vector &perms = {
- iroha::model::can_subtract_asset_qty,
- iroha::model::can_add_asset_qty}) {
+ shared_model::permissions::can_subtract_asset_qty,
+ shared_model::permissions::can_add_asset_qty}) {
return framework::createUserWithPerms(
kUser, kUserKeypair.publicKey(), "role"s, perms)
.build()
@@ -131,7 +131,7 @@ TEST_F(SubtractAssetQuantity, Overdraft) {
TEST_F(SubtractAssetQuantity, NoPermissions) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms({iroha::model::can_add_asset_qty}))
+ .sendTx(makeUserWithPerms({shared_model::permissions::can_add_asset_qty}))
.sendTx(replenish())
.skipProposal()
.skipBlock()
diff --git a/test/integration/acceptance/transfer_asset_test.cpp b/test/integration/acceptance/transfer_asset_test.cpp
index cb06c4657e..4d434166d6 100644
--- a/test/integration/acceptance/transfer_asset_test.cpp
+++ b/test/integration/acceptance/transfer_asset_test.cpp
@@ -25,9 +25,9 @@
#include "framework/base_tx.hpp"
#include "framework/integration_framework/integration_test_framework.hpp"
#include "interfaces/utils/specified_visitor.hpp"
-#include "validators/permissions.hpp"
#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
#include "utils/query_error_response_visitor.hpp"
+#include "validators/permissions.hpp"
using namespace std::string_literals;
using namespace integration_framework;
@@ -103,9 +103,10 @@ class TransferAsset : public ::testing::Test {
crypto::DefaultCryptoAlgorithmType::generateKeypair();
const crypto::Keypair kUser2Keypair =
crypto::DefaultCryptoAlgorithmType::generateKeypair();
- const std::vector kPerms{iroha::model::can_add_asset_qty,
- iroha::model::can_transfer,
- iroha::model::can_receive};
+ const std::vector kPerms{
+ shared_model::permissions::can_add_asset_qty,
+ shared_model::permissions::can_transfer,
+ shared_model::permissions::can_receive};
};
/**
@@ -137,8 +138,10 @@ TEST_F(TransferAsset, Basic) {
TEST_F(TransferAsset, WithOnlyCanTransferPerm) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms(
- kUser1, kUser1Keypair, {iroha::model::can_transfer}, kRole1))
+ .sendTx(makeUserWithPerms(kUser1,
+ kUser1Keypair,
+ {shared_model::permissions::can_transfer},
+ kRole1))
.sendTx(makeUserWithPerms(kUser2, kUser2Keypair, kPerms, kRole2))
.sendTx(addAssets(kUser1, kUser1Keypair))
.skipProposal()
@@ -160,8 +163,10 @@ TEST_F(TransferAsset, WithOnlyCanTransferPerm) {
TEST_F(TransferAsset, WithOnlyCanReceivePerm) {
IntegrationTestFramework()
.setInitialState(kAdminKeypair)
- .sendTx(makeUserWithPerms(
- kUser1, kUser1Keypair, {iroha::model::can_receive}, kRole1))
+ .sendTx(makeUserWithPerms(kUser1,
+ kUser1Keypair,
+ {shared_model::permissions::can_receive},
+ kRole1))
.sendTx(makeUserWithPerms(kUser2, kUser2Keypair, kPerms, kRole2))
.sendTx(addAssets(kUser1, kUser1Keypair))
.skipProposal()
@@ -406,7 +411,8 @@ TEST_F(TransferAsset, InterDomain) {
integration_framework::IntegrationTestFramework::kAdminId)
.createdTime(iroha::time::now())
.createRole(kNewRole,
- std::vector{iroha::model::can_receive})
+ std::vector{
+ shared_model::permissions::can_receive})
.createDomain(kNewDomain, kNewRole)
.createAccount(
kUser2,
diff --git a/test/integration/client_test.cpp b/test/integration/client_test.cpp
index 5871442384..f914aadb57 100644
--- a/test/integration/client_test.cpp
+++ b/test/integration/client_test.cpp
@@ -58,6 +58,7 @@ using namespace iroha::validation;
using namespace iroha::model::converters;
using namespace iroha::model;
using namespace shared_model::proto;
+using namespace shared_model::permissions;
using namespace std::chrono_literals;
constexpr std::chrono::milliseconds proposal_delay = 10s;
diff --git a/test/module/irohad/ametsuchi/ametsuchi_test.cpp b/test/module/irohad/ametsuchi/ametsuchi_test.cpp
index 7089d9c0d1..3412c85601 100644
--- a/test/module/irohad/ametsuchi/ametsuchi_test.cpp
+++ b/test/module/irohad/ametsuchi/ametsuchi_test.cpp
@@ -24,10 +24,10 @@
#include "ametsuchi/mutable_storage.hpp"
#include "builders/protobuf/transaction.hpp"
#include "framework/test_subscriber.hpp"
-#include "validators/permissions.hpp"
#include "module/irohad/ametsuchi/ametsuchi_fixture.hpp"
#include "module/shared_model/builders/protobuf/test_block_builder.hpp"
#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
+#include "validators/permissions.hpp"
using namespace iroha::ametsuchi;
using namespace framework::test_subscriber;
@@ -195,9 +195,9 @@ TEST_F(AmetsuchiTest, SampleTest) {
.createRole(
"user",
shared_model::interface::types::PermissionSetType{
- iroha::model::can_add_peer,
- iroha::model::can_create_asset,
- iroha::model::can_get_my_account})
+ shared_model::permissions::can_add_peer,
+ shared_model::permissions::can_create_asset,
+ shared_model::permissions::can_get_my_account})
.createDomain(domain, "user")
.createAccount(user1name, domain, fake_pubkey)
.build()}))
@@ -234,7 +234,7 @@ TEST_F(AmetsuchiTest, SampleTest) {
// Block store tests
auto hashes = {block1.hash(), block2.hash()};
validateCalls(blocks->getBlocks(1, 2),
- [i = 0, &hashes](auto eachBlock) mutable {
+ [ i = 0, &hashes ](auto eachBlock) mutable {
EXPECT_EQ(*(hashes.begin() + i), eachBlock->hash());
++i;
},
@@ -293,9 +293,10 @@ TEST_F(AmetsuchiTest, queryGetAccountAssetTransactionsTest) {
TestTransactionBuilder()
.creatorAccountId(admin)
.createRole("user",
- std::set{iroha::model::can_add_peer,
- iroha::model::can_create_asset,
- iroha::model::can_get_my_account})
+ std::set{
+ shared_model::permissions::can_add_peer,
+ shared_model::permissions::can_create_asset,
+ shared_model::permissions::can_get_my_account})
.createDomain(domain, "user")
.createAccount(user1name, domain, fake_pubkey)
.createAccount(user2name, domain, fake_pubkey)
@@ -376,7 +377,7 @@ TEST_F(AmetsuchiTest, queryGetAccountAssetTransactionsTest) {
// Block store test
auto hashes = {block1.hash(), block2.hash(), block3.hash()};
validateCalls(blocks->getBlocks(1, 3),
- [i = 0, &hashes](auto eachBlock) mutable {
+ [ i = 0, &hashes ](auto eachBlock) mutable {
EXPECT_EQ(*(hashes.begin() + i), eachBlock->hash());
++i;
},
@@ -413,9 +414,10 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
TestTransactionBuilder()
.creatorAccountId("adminone")
.createRole("user",
- std::set{iroha::model::can_add_peer,
- iroha::model::can_create_asset,
- iroha::model::can_get_my_account})
+ std::set{
+ shared_model::permissions::can_add_peer,
+ shared_model::permissions::can_create_asset,
+ shared_model::permissions::can_get_my_account})
.createDomain("domain", "user")
.createAccount("userone", "domain", pubkey1)
.build();
@@ -698,9 +700,10 @@ TEST_F(AmetsuchiTest, FindTxByHashTest) {
TestTransactionBuilder()
.creatorAccountId("admin1")
.createRole("user",
- std::set{iroha::model::can_add_peer,
- iroha::model::can_create_asset,
- iroha::model::can_get_my_account})
+ std::set{
+ shared_model::permissions::can_add_peer,
+ shared_model::permissions::can_create_asset,
+ shared_model::permissions::can_get_my_account})
.createDomain("domain", "user")
.createAccount("userone", "domain", pubkey1)
.build();
@@ -709,9 +712,10 @@ TEST_F(AmetsuchiTest, FindTxByHashTest) {
TestTransactionBuilder()
.creatorAccountId("admin1")
.createRole("usertwo",
- std::set{iroha::model::can_add_peer,
- iroha::model::can_create_asset,
- iroha::model::can_get_my_account})
+ std::set{
+ shared_model::permissions::can_add_peer,
+ shared_model::permissions::can_create_asset,
+ shared_model::permissions::can_get_my_account})
.createDomain("domaintwo", "user")
.build();
@@ -866,12 +870,13 @@ TEST_F(AmetsuchiTest, TestRestoreWSV) {
.txCounter(1)
.createdTime(iroha::time::now())
.createRole(default_role,
- std::vector{iroha::model::can_create_domain,
- iroha::model::can_create_account,
- iroha::model::can_add_asset_qty,
- iroha::model::can_add_peer,
- iroha::model::can_receive,
- iroha::model::can_transfer})
+ std::vector{
+ shared_model::permissions::can_create_domain,
+ shared_model::permissions::can_create_account,
+ shared_model::permissions::can_add_asset_qty,
+ shared_model::permissions::can_add_peer,
+ shared_model::permissions::can_receive,
+ shared_model::permissions::can_transfer})
.createDomain(default_domain, default_role)
.build()
.signAndAddSignature(
diff --git a/test/module/irohad/ametsuchi/kv_storage_test.cpp b/test/module/irohad/ametsuchi/kv_storage_test.cpp
index 4d09b1179a..a91b2741d0 100644
--- a/test/module/irohad/ametsuchi/kv_storage_test.cpp
+++ b/test/module/irohad/ametsuchi/kv_storage_test.cpp
@@ -24,9 +24,9 @@
#include "ametsuchi/impl/storage_impl.hpp"
#include "ametsuchi/mutable_storage.hpp"
#include "model/block.hpp"
-#include "validators/permissions.hpp"
#include "model/sha3_hash.hpp"
#include "module/irohad/ametsuchi/ametsuchi_fixture.hpp"
+#include "validators/permissions.hpp"
// TODO: 14-02-2018 Alexey Chernyshov remove this after relocation to
// shared_model https://soramitsu.atlassian.net/browse/IR-887
@@ -61,9 +61,9 @@ class KVTest : public AmetsuchiTest {
iroha::model::CreateRole createRole;
createRole.role_name = "user";
- createRole.permissions = {iroha::model::can_add_peer,
- iroha::model::can_create_asset,
- iroha::model::can_get_my_account};
+ createRole.permissions = {shared_model::permissions::can_add_peer,
+ shared_model::permissions::can_create_asset,
+ shared_model::permissions::can_get_my_account};
// Create domain ru
txn1_1.commands.push_back(
diff --git a/test/module/irohad/model/command_validate_execute_test.cpp b/test/module/irohad/model/command_validate_execute_test.cpp
index b82d35f85d..f0de843127 100644
--- a/test/module/irohad/model/command_validate_execute_test.cpp
+++ b/test/module/irohad/model/command_validate_execute_test.cpp
@@ -49,6 +49,7 @@ using namespace iroha;
using namespace iroha::ametsuchi;
using namespace iroha::model;
using namespace framework::expected;
+using namespace shared_model::permissions;
class CommandValidateExecuteTest : public ::testing::Test {
public:
diff --git a/test/module/irohad/model/converters/json_commands_test.cpp b/test/module/irohad/model/converters/json_commands_test.cpp
index dd816056f9..df227e5eca 100644
--- a/test/module/irohad/model/converters/json_commands_test.cpp
+++ b/test/module/irohad/model/converters/json_commands_test.cpp
@@ -43,6 +43,7 @@ using namespace rapidjson;
using namespace iroha;
using namespace iroha::model;
using namespace iroha::model::converters;
+using namespace shared_model::permissions;
class JsonCommandTest : public ::testing::Test {
public:
diff --git a/test/module/irohad/model/converters/pb_commands_test.cpp b/test/module/irohad/model/converters/pb_commands_test.cpp
index 6fe0fb1543..3b8bf4c783 100644
--- a/test/module/irohad/model/converters/pb_commands_test.cpp
+++ b/test/module/irohad/model/converters/pb_commands_test.cpp
@@ -37,6 +37,7 @@
#include "validators/permissions.hpp"
using namespace iroha::model;
+using namespace shared_model::permissions;
void command_converter_test(iroha::model::Command &abstract_command) {
auto factory = iroha::model::converters::PbCommandFactory();
diff --git a/test/module/irohad/torii/processor/query_processor_test.cpp b/test/module/irohad/torii/processor/query_processor_test.cpp
index b842f0a3a5..b18cbbd1e1 100644
--- a/test/module/irohad/torii/processor/query_processor_test.cpp
+++ b/test/module/irohad/torii/processor/query_processor_test.cpp
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-#include "validators/permissions.hpp"
#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
#include "module/irohad/validation/validation_mocks.hpp"
+#include "validators/permissions.hpp"
#include "framework/test_subscriber.hpp"
#include "model/queries/responses/error_response.hpp"
@@ -91,7 +91,8 @@ TEST_F(QueryProcessorTest, QueryProcessorWhereInvokeInvalidQuery) {
shared_model::proto::AccountBuilder().accountId(account_id).build());
auto role = "admin";
std::vector roles = {role};
- std::vector perms = {iroha::model::can_get_my_account};
+ std::vector perms = {
+ shared_model::permissions::can_get_my_account};
EXPECT_CALL(*storage, getWsvQuery()).WillRepeatedly(Return(wsv_queries));
EXPECT_CALL(*storage, getBlockQuery()).WillRepeatedly(Return(block_queries));
@@ -147,7 +148,8 @@ TEST_F(QueryProcessorTest, QueryProcessorWithWrongKey) {
shared_model::proto::AccountBuilder().accountId(account_id).build());
auto role = "admin";
std::vector roles = {role};
- std::vector perms = {iroha::model::can_get_my_account};
+ std::vector perms = {
+ shared_model::permissions::can_get_my_account};
EXPECT_CALL(*storage, getWsvQuery()).WillRepeatedly(Return(wsv_queries));
EXPECT_CALL(*storage, getBlockQuery()).WillRepeatedly(Return(block_queries));
diff --git a/test/module/irohad/torii/torii_queries_test.cpp b/test/module/irohad/torii/torii_queries_test.cpp
index 3a23bca782..2aab5b337d 100644
--- a/test/module/irohad/torii/torii_queries_test.cpp
+++ b/test/module/irohad/torii/torii_queries_test.cpp
@@ -27,10 +27,10 @@ limitations under the License.
#include "model/converters/pb_common.hpp"
#include "main/server_runner.hpp"
-#include "validators/permissions.hpp"
#include "torii/processor/query_processor_impl.hpp"
#include "torii/query_client.hpp"
#include "torii/query_service.hpp"
+#include "validators/permissions.hpp"
#include "builders/protobuf/queries.hpp"
#include "cryptography/crypto_provider/crypto_defaults.hpp"
@@ -151,10 +151,11 @@ TEST_F(ToriiQueriesTest, FindAccountWhenNoGrantPermissions) {
account.account_id = "b@domain";
auto creator = "a@domain";
- EXPECT_CALL(
- *wsv_query,
- hasAccountGrantablePermission(
- creator, account.account_id, iroha::model::can_get_my_account))
+ EXPECT_CALL(*wsv_query,
+ hasAccountGrantablePermission(
+ creator,
+ account.account_id,
+ shared_model::permissions::can_get_my_account))
.WillOnce(Return(false));
EXPECT_CALL(*wsv_query, getSignatories(creator))
@@ -193,10 +194,11 @@ TEST_F(ToriiQueriesTest, FindAccountWhenHasReadPermissions) {
EXPECT_CALL(*wsv_query, getSignatories(creator))
.WillRepeatedly(Return(signatories));
- EXPECT_CALL(
- *wsv_query,
- hasAccountGrantablePermission(
- creator, accountB->accountId(), iroha::model::can_get_my_account))
+ EXPECT_CALL(*wsv_query,
+ hasAccountGrantablePermission(
+ creator,
+ accountB->accountId(),
+ shared_model::permissions::can_get_my_account))
.WillOnce(Return(true));
// Should be called once, after successful stateful validation
@@ -239,7 +241,8 @@ TEST_F(ToriiQueriesTest, FindAccountWhenHasRolePermission) {
std::vector roles = {"test"};
EXPECT_CALL(*wsv_query, getAccountRoles(creator))
.WillRepeatedly(Return(roles));
- std::vector perm = {iroha::model::can_get_my_account};
+ std::vector perm = {
+ shared_model::permissions::can_get_my_account};
EXPECT_CALL(*wsv_query, getRolePermissions("test")).WillOnce(Return(perm));
iroha::protocol::QueryResponse response;
@@ -276,9 +279,10 @@ TEST_F(ToriiQueriesTest, FindAccountAssetWhenNoGrantPermissions) {
EXPECT_CALL(*wsv_query, getSignatories(creator))
.WillRepeatedly(Return(signatories));
- EXPECT_CALL(*wsv_query,
- hasAccountGrantablePermission(
- creator, accountb_id, iroha::model::can_get_my_acc_ast))
+ EXPECT_CALL(
+ *wsv_query,
+ hasAccountGrantablePermission(
+ creator, accountb_id, shared_model::permissions::can_get_my_acc_ast))
.WillOnce(Return(false));
EXPECT_CALL(*wsv_query, getAccountRoles(creator))
.WillOnce(Return(boost::none));
@@ -332,7 +336,8 @@ TEST_F(ToriiQueriesTest, FindAccountAssetWhenHasRolePermissions) {
.WillRepeatedly(Return(signatories));
std::vector roles = {"test"};
EXPECT_CALL(*wsv_query, getAccountRoles(creator)).WillOnce(Return(roles));
- std::vector perm = {iroha::model::can_get_my_acc_ast};
+ std::vector perm = {
+ shared_model::permissions::can_get_my_acc_ast};
EXPECT_CALL(*wsv_query, getRolePermissions("test")).WillOnce(Return(perm));
EXPECT_CALL(*wsv_query, getAccountAsset(_, _))
.WillOnce(Return(account_asset));
@@ -386,7 +391,9 @@ TEST_F(ToriiQueriesTest, FindSignatoriesWhenNoGrantPermissions) {
.WillRepeatedly(Return(signatories));
EXPECT_CALL(*wsv_query,
hasAccountGrantablePermission(
- creator, "b@domain", iroha::model::can_get_my_signatories))
+ creator,
+ "b@domain",
+ shared_model::permissions::can_get_my_signatories))
.WillOnce(Return(false));
EXPECT_CALL(*wsv_query, getAccountRoles(creator))
.WillOnce(Return(boost::none));
@@ -425,7 +432,8 @@ TEST_F(ToriiQueriesTest, FindSignatoriesHasRolePermissions) {
std::vector roles = {"test"};
EXPECT_CALL(*wsv_query, getAccountRoles(creator)).WillOnce(Return(roles));
- std::vector perm = {iroha::model::can_get_my_signatories};
+ std::vector perm = {
+ shared_model::permissions::can_get_my_signatories};
EXPECT_CALL(*wsv_query, getRolePermissions("test")).WillOnce(Return(perm));
iroha::protocol::QueryResponse response;
@@ -482,7 +490,8 @@ TEST_F(ToriiQueriesTest, FindTransactionsWhenValid) {
.WillRepeatedly(Return(signatories));
std::vector roles = {"test"};
EXPECT_CALL(*wsv_query, getAccountRoles(creator)).WillOnce(Return(roles));
- std::vector perm = {iroha::model::can_get_my_acc_txs};
+ std::vector perm = {
+ shared_model::permissions::can_get_my_acc_txs};
EXPECT_CALL(*wsv_query, getRolePermissions("test")).WillOnce(Return(perm));
EXPECT_CALL(*block_query, getAccountTransactions(creator))
.WillOnce(Return(txs_observable));
diff --git a/test/module/irohad/validation/query_execution.cpp b/test/module/irohad/validation/query_execution.cpp
index 996882270b..5fc8c9be67 100644
--- a/test/module/irohad/validation/query_execution.cpp
+++ b/test/module/irohad/validation/query_execution.cpp
@@ -39,6 +39,7 @@ using ::testing::_;
using namespace iroha::ametsuchi;
using namespace iroha::model;
using namespace framework::test_subscriber;
+using namespace shared_model::permissions;
using wTransaction = std::shared_ptr;
diff --git a/test/module/shared_model/validators/field_validator_test.cpp b/test/module/shared_model/validators/field_validator_test.cpp
index 5c801c92f5..31c43f5dcd 100644
--- a/test/module/shared_model/validators/field_validator_test.cpp
+++ b/test/module/shared_model/validators/field_validator_test.cpp
@@ -29,10 +29,10 @@
#include "backend/protobuf/common_objects/peer.hpp"
#include "builders/protobuf/queries.hpp"
#include "builders/protobuf/transaction.hpp"
-#include "validators/permissions.hpp"
#include "module/shared_model/validators/validators_fixture.hpp"
#include "utils/lazy_initializer.hpp"
#include "validators/field_validator.hpp"
+#include "validators/permissions.hpp"
using namespace shared_model;
@@ -516,14 +516,15 @@ class FieldValidatorTest : public ValidatorsTest {
"too big quorum size", &FieldValidatorTest::quorum, 129, false, "")};
std::vector permissionTestCases() {
- auto valid_cases = iroha::model::role_perm_group
+ auto valid_cases =
+ shared_model::permissions::role_perm_group
| boost::adaptors::transformed([&](const auto &permission) {
- return this->makeTestCase(permission,
- &FieldValidatorTest::permission,
- permission,
- true,
- "");
- });
+ return this->makeTestCase(permission,
+ &FieldValidatorTest::permission,
+ permission,
+ true,
+ "");
+ });
std::vector invalid_cases = {
makeInvalidCase("non existing permission",
"permission",
From 1d1a02ad1bb838ee02ad717fa4b8d098f373be11 Mon Sep 17 00:00:00 2001
From: Kitsu
Date: Tue, 10 Apr 2018 15:24:07 +0300
Subject: [PATCH 007/110] Remove empty files (#1197)
Signed-off-by: Eugene Minibaev
---
deploy/ansible/playbooks/iroha-docker-cluster/main.yml | 0
test/integration/pipeline/tx_pipeline_integration_test.cpp | 0
2 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 deploy/ansible/playbooks/iroha-docker-cluster/main.yml
delete mode 100644 test/integration/pipeline/tx_pipeline_integration_test.cpp
diff --git a/deploy/ansible/playbooks/iroha-docker-cluster/main.yml b/deploy/ansible/playbooks/iroha-docker-cluster/main.yml
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/test/integration/pipeline/tx_pipeline_integration_test.cpp b/test/integration/pipeline/tx_pipeline_integration_test.cpp
deleted file mode 100644
index e69de29bb2..0000000000
From 80bae880c5bfc07bb2d219823c5d770be7113685 Mon Sep 17 00:00:00 2001
From: Artyom Bakhtin
Date: Tue, 10 Apr 2018 15:57:28 +0300
Subject: [PATCH 008/110] Uploading of the build artifacts (#1170)
* upload artifacts on successful build
Signed-off-by: Artyom Bakhtin
* temporarily disable mac coverage
Signed-off-by: Artyom Bakhtin
* remove WIP
Signed-off-by: Artyom Bakhtin
* replace artifacts.groovy paths concat with a more elegant version
Signed-off-by: Artyom Bakhtin
---
.jenkinsci/artifacts.groovy | 44 ++++++++++
.jenkinsci/debug-build.groovy | 11 +--
.jenkinsci/linux-post-step.groovy | 22 +++++
.jenkinsci/mac-release-build.groovy | 28 +++++++
Jenkinsfile | 126 +++++++++++++---------------
5 files changed, 154 insertions(+), 77 deletions(-)
create mode 100644 .jenkinsci/artifacts.groovy
create mode 100644 .jenkinsci/linux-post-step.groovy
create mode 100644 .jenkinsci/mac-release-build.groovy
diff --git a/.jenkinsci/artifacts.groovy b/.jenkinsci/artifacts.groovy
new file mode 100644
index 0000000000..3a5aa0a68b
--- /dev/null
+++ b/.jenkinsci/artifacts.groovy
@@ -0,0 +1,44 @@
+#!/usr/bin/env groovy
+
+def uploadArtifacts(filePaths, uploadPath, artifactServers=['artifact.soramitsu.co.jp']) {
+ def baseUploadPath = 'files'
+ def filePathsConverted = []
+ agentType = sh(script: 'uname', returnStdout: true).trim()
+ uploadPath = baseUploadPath + uploadPath
+ filePaths.each {
+ fp = sh(script: "ls -d ${it} | tr '\n' ','", returnStdout: true).trim()
+ filePathsConverted.addAll(fp.split(','))
+ }
+ def shaSumBinary = 'sha256sum'
+ def md5SumBinary = 'md5sum'
+ if (agentType == 'Darwin') {
+ shaSumBinary = 'shasum -a 256'
+ md5SumBinary = 'md5 -r'
+ }
+ sh "> \$(pwd)/batch.txt"
+ filePathsConverted.each {
+ sh "echo put ${it} $uploadPath >> \$(pwd)/batch.txt;"
+ sh "$shaSumBinary ${it} | cut -d' ' -f1 > \$(pwd)/\$(basename ${it}).sha256"
+ sh "$md5SumBinary ${it} | cut -d' ' -f1 > \$(pwd)/\$(basename ${it}).md5"
+ sh "echo put \$(pwd)/\$(basename ${it}).sha256 $uploadPath >> \$(pwd)/batch.txt;"
+ sh "echo put \$(pwd)/\$(basename ${it}).md5 $uploadPath >> \$(pwd)/batch.txt;"
+ }
+ // mkdirs recursively
+ uploadPath = uploadPath.split('/')
+ def p = ''
+ sh "> \$(pwd)/mkdirs.txt"
+ uploadPath.each {
+ p += "/${it}"
+ sh("echo -mkdir $p >> \$(pwd)/mkdirs.txt")
+ }
+
+ sshagent(['jenkins-artifact']) {
+ sh "ssh-agent"
+ artifactServers.each {
+ sh "sftp -b \$(pwd)/mkdirs.txt jenkins@${it} || true"
+ sh "sftp -b \$(pwd)/batch.txt jenkins@${it}"
+ }
+ }
+}
+
+return this
diff --git a/.jenkinsci/debug-build.groovy b/.jenkinsci/debug-build.groovy
index dd430e67d6..5d934dd8fa 100644
--- a/.jenkinsci/debug-build.groovy
+++ b/.jenkinsci/debug-build.groovy
@@ -40,7 +40,8 @@ def doDebugBuild(coverageEnabled=false) {
+ " -e IROHA_POSTGRES_USER=${env.IROHA_POSTGRES_USER}"
+ " -e IROHA_POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD}"
+ " --network=${env.IROHA_NETWORK}"
- + " -v /var/jenkins/ccache:${CCACHE_DIR}") {
+ + " -v /var/jenkins/ccache:${CCACHE_DIR}"
+ + " -v /tmp/${GIT_COMMIT}-${BUILD_NUMBER}:/tmp/${GIT_COMMIT}") {
def scmVars = checkout scm
def cmakeOptions = ""
@@ -95,12 +96,8 @@ def doDebugBuild(coverageEnabled=false) {
sh "python /tmp/lcov_cobertura.py build/reports/coverage.info -o build/reports/coverage.xml"
cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/build/reports/coverage.xml', conditionalCoverageTargets: '75, 50, 0', failUnhealthy: false, failUnstable: false, lineCoverageTargets: '75, 50, 0', maxNumberOfBuilds: 50, methodCoverageTargets: '75, 50, 0', onlyStable: false, zoomCoverageChart: false
}
-
- // TODO: replace with upload to artifactory server
- // develop branch only
- if ( env.BRANCH_NAME == "develop" ) {
- //archive(includes: 'build/bin/,compile_commands.json')
- }
+ // copy built binaries to the volume
+ sh "cp ./build/bin/* /tmp/${GIT_COMMIT}/"
}
}
return this
diff --git a/.jenkinsci/linux-post-step.groovy b/.jenkinsci/linux-post-step.groovy
new file mode 100644
index 0000000000..0dc8611445
--- /dev/null
+++ b/.jenkinsci/linux-post-step.groovy
@@ -0,0 +1,22 @@
+def linuxPostStep() {
+ timeout(time: 600, unit: "SECONDS") {
+ try {
+ if (currentBuild.result != "UNSTABLE" && BRANCH_NAME ==~ /(master|develop)/) {
+ def artifacts = load ".jenkinsci/artifacts.groovy"
+ def commit = env.GIT_COMMIT
+ def platform = sh(script: 'uname -m', returnStdout: true).trim()
+ filePaths = [ '/tmp/${GIT_COMMIT}-${BUILD_NUMBER}/*' ]
+ artifacts.uploadArtifacts(filePaths, sprintf('/iroha/linux/%4%s/%1$s-%2$s-%3$s', [BRANCH_NAME, sh(script: 'date "+%Y%m%d"', returnStdout: true).trim(), commit.substring(0,6), platform]))
+ }
+ }
+ finally {
+ if (env.BUILD_TYPE == 'Debug') {
+ def cleanup = load ".jenkinsci/docker-cleanup.groovy"
+ cleanup.doDockerCleanup()
+ }
+ cleanWs()
+ }
+ }
+}
+
+return this
diff --git a/.jenkinsci/mac-release-build.groovy b/.jenkinsci/mac-release-build.groovy
new file mode 100644
index 0000000000..b799e19200
--- /dev/null
+++ b/.jenkinsci/mac-release-build.groovy
@@ -0,0 +1,28 @@
+#!/usr/bin/env groovy
+
+def doReleaseBuild(coverageEnabled=false) {
+ def scmVars = checkout scm
+ env.IROHA_VERSION = "0x${scmVars.GIT_COMMIT}"
+ env.IROHA_HOME = "/opt/iroha"
+ env.IROHA_BUILD = "${env.IROHA_HOME}/build"
+
+ sh """
+ export CCACHE_DIR=${CCACHE_RELEASE_DIR}
+ ccache --version
+ ccache --show-stats
+ ccache --zero-stats
+ ccache --max-size=1G
+
+ cmake -H. \
+ -Bbuild \
+ -DCOVERAGE=OFF \
+ -DPACKAGE_TGZ=ON \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DIROHA_VERSION=${env.IROHA_VERSION}
+
+ cmake --build build --target package -- -j${params.PARALLELISM}
+ ccache --show-stats
+ """
+}
+
+return this
diff --git a/Jenkinsfile b/Jenkinsfile
index 8a33536581..7975707397 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -109,11 +109,8 @@ pipeline {
post {
always {
script {
- timeout(time: 60, unit: "SECONDS") {
- def cleanup = load ".jenkinsci/docker-cleanup.groovy"
- cleanup.doDockerCleanup()
- cleanWs()
- }
+ post = load ".jenkinsci/linux-post-step.groovy"
+ post.linuxPostStep()
}
}
}
@@ -140,11 +137,8 @@ pipeline {
post {
always {
script {
- timeout(time: 60, unit: "SECONDS") {
- def cleanup = load ".jenkinsci/docker-cleanup.groovy"
- cleanup.doDockerCleanup()
- cleanWs()
- }
+ post = load ".jenkinsci/linux-post-step.groovy"
+ post.linuxPostStep()
}
}
}
@@ -171,11 +165,8 @@ pipeline {
post {
always {
script {
- timeout(time: 60, unit: "SECONDS") {
- def cleanup = load ".jenkinsci/docker-cleanup.groovy"
- cleanup.doDockerCleanup()
- cleanWs()
- }
+ post = load ".jenkinsci/linux-post-step.groovy"
+ post.linuxPostStep()
}
}
}
@@ -246,25 +237,34 @@ pipeline {
sh "cmake --build build --target coverage.info"
sh "python /usr/local/bin/lcov_cobertura.py build/reports/coverage.info -o build/reports/coverage.xml"
cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/build/reports/coverage.xml', conditionalCoverageTargets: '75, 50, 0', failUnhealthy: false, failUnstable: false, lineCoverageTargets: '75, 50, 0', maxNumberOfBuilds: 50, methodCoverageTargets: '75, 50, 0', onlyStable: false, zoomCoverageChart: false
-
}
-
- // TODO: replace with upload to artifactory server
- // only develop branch
- if ( env.BRANCH_NAME == "develop" ) {
- //archive(includes: 'build/bin/,compile_commands.json')
+ if (BRANCH_NAME ==~ /(master|develop)/) {
+ releaseBuild = load ".jenkinsci/mac-release-build.groovy"
+ releaseBuild.doReleaseBuild()
}
}
}
post {
always {
script {
- timeout(time: 60, unit: "SECONDS") {
- cleanWs()
- sh """
- pg_ctl -D /var/jenkins/${GIT_COMMIT}-${BUILD_NUMBER}/ stop && \
- rm -rf /var/jenkins/${GIT_COMMIT}-${BUILD_NUMBER}/
- """
+ timeout(time: 600, unit: "SECONDS") {
+ if (currentBuild.result != "UNSTABLE") {
+ if (BRANCH_NAME ==~ /(master|develop)/) {
+ try {
+ def artifacts = load ".jenkinsci/artifacts.groovy"
+ def commit = env.GIT_COMMIT
+ filePaths = [ '\$(pwd)/build/*.tar.gz' ]
+ artifacts.uploadArtifacts(filePaths, sprintf('/iroha/macos/%1$s-%2$s-%3$s', [BRANCH_NAME, sh(script: 'date "+%Y%m%d"', returnStdout: true).trim(), commit.substring(0,6)]))
+ }
+ finally {
+ cleanWs()
+ sh """
+ pg_ctl -D /var/jenkins/${GIT_COMMIT}-${BUILD_NUMBER}/ stop && \
+ rm -rf /var/jenkins/${GIT_COMMIT}-${BUILD_NUMBER}/
+ """
+ }
+ }
+ }
}
}
}
@@ -282,7 +282,7 @@ pipeline {
parallel {
stage('Linux') {
when { expression { return params.Linux } }
- agent { label 'linux && x86_64' }
+ agent { label 'x86_64' }
steps {
script {
def releaseBuild = load ".jenkinsci/release-build.groovy"
@@ -292,11 +292,8 @@ pipeline {
post {
always {
script {
- timeout(time: 60, unit: "SECONDS") {
- def cleanup = load ".jenkinsci/docker-cleanup.groovy"
- cleanup.doDockerCleanup()
- cleanWs()
- }
+ post = load ".jenkinsci/linux-post-step.groovy"
+ post.linuxPostStep()
}
}
}
@@ -313,14 +310,11 @@ pipeline {
post {
always {
script {
- timeout(time: 60, unit: "SECONDS") {
- def cleanup = load ".jenkinsci/docker-cleanup.groovy"
- cleanup.doDockerCleanup()
- cleanWs()
- }
+ post = load ".jenkinsci/linux-post-step.groovy"
+ post.linuxPostStep()
}
}
- }
+ }
}
stage('ARMv8') {
when { expression { return params.ARMv8 } }
@@ -334,44 +328,36 @@ pipeline {
post {
always {
script {
- timeout(time: 60, unit: "SECONDS") {
- def cleanup = load ".jenkinsci/docker-cleanup.groovy"
- cleanup.doDockerCleanup()
- cleanWs()
- }
+ post = load ".jenkinsci/linux-post-step.groovy"
+ post.linuxPostStep()
}
}
- }
+ }
}
stage('MacOS') {
when { expression { return params.MacOS } }
steps {
script {
- def scmVars = checkout scm
- env.IROHA_VERSION = "0x${scmVars.GIT_COMMIT}"
- env.IROHA_HOME = "/opt/iroha"
- env.IROHA_BUILD = "${env.IROHA_HOME}/build"
-
- sh """
- ccache --version
- ccache --show-stats
- ccache --zero-stats
- ccache --max-size=5G
- """
- sh """
- cmake \
- -H. \
- -Bbuild \
- -DCMAKE_BUILD_TYPE=${params.BUILD_TYPE} \
- -DIROHA_VERSION=${env.IROHA_VERSION}
- """
- sh "cmake --build build -- -j${params.PARALLELISM}"
- sh "ccache --show-stats"
-
- // TODO: replace with upload to artifactory server
- // only develop branch
- if ( env.BRANCH_NAME == "develop" ) {
- //archive(includes: 'build/bin/,compile_commands.json')
+ def releaseBuild = load ".jenkinsci/mac-release-build.groovy"
+ releaseBuild.doReleaseBuild()
+ }
+ }
+ post {
+ always {
+ script {
+ timeout(time: 600, unit: "SECONDS") {
+ if (BRANCH_NAME ==~ /(master|develop)/) {
+ try {
+ def artifacts = load ".jenkinsci/artifacts.groovy"
+ def commit = env.GIT_COMMIT
+ filePaths = [ '\$(pwd)/build/*.tar.gz' ]
+ artifacts.uploadArtifacts(filePaths, sprintf('/iroha/macos/%1$s-%2$s-%3$s', [BRANCH_NAME, sh(script: 'date "+%Y%m%d"', returnStdout: true).trim(), commit.substring(0,6)]))
+ }
+ finally {
+ cleanWs()
+ }
+ }
+ }
}
}
}
From 8e3944f5a5f4da94cdd25feb6cfc41c9b215c438 Mon Sep 17 00:00:00 2001
From: Bulat Nasrulin
Date: Wed, 11 Apr 2018 14:21:35 +0800
Subject: [PATCH 009/110] Add comments, apply clang-format in keys_manager
(#1195)
Signed-off-by: grimadas
---
libs/crypto/keys_manager_impl.cpp | 4 +++-
test/module/libs/crypto/keys_manager_test.cpp | 7 ++++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/libs/crypto/keys_manager_impl.cpp b/libs/crypto/keys_manager_impl.cpp
index f9a9973605..8b9b2d1eb7 100644
--- a/libs/crypto/keys_manager_impl.cpp
+++ b/libs/crypto/keys_manager_impl.cpp
@@ -58,8 +58,10 @@ namespace iroha {
template
static std::string encrypt(const T &key, const std::string &pass_phrase) {
std::string ciphertext(key.size(), '\0');
+ // pass_size will always be > 0
const auto pass_size = std::max(1ul, pass_phrase.size());
-
+ // When pass_phrase is empty it, pass_phrase[0] is "\0", so no out_of_range
+ // exception is possible
for (auto i = 0u; i < key.size(); i++) {
ciphertext[i] = key[i] ^ pass_phrase[i % pass_size];
}
diff --git a/test/module/libs/crypto/keys_manager_test.cpp b/test/module/libs/crypto/keys_manager_test.cpp
index 1244b5783e..d461c49631 100644
--- a/test/module/libs/crypto/keys_manager_test.cpp
+++ b/test/module/libs/crypto/keys_manager_test.cpp
@@ -60,9 +60,10 @@ class KeyManager : public ::testing::Test {
"36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80"s;
KeysManagerImpl manager = KeysManagerImpl(filepath);
const std::string passphrase = "test";
- const std::string nonexistent = (boost::filesystem::temp_directory_path()
- / "path" / "that" / "doesnt" / "exist")
- .string();
+ const std::string nonexistent =
+ (boost::filesystem::temp_directory_path() / "path" / "that" / "doesnt"
+ / "exist")
+ .string();
};
TEST_F(KeyManager, LoadNonExistentKeyFile) {
From ebcf06d38068784951d3622ebf326bdb71fcb4c0 Mon Sep 17 00:00:00 2001
From: Dumitru
Date: Wed, 11 Apr 2018 22:14:56 +0300
Subject: [PATCH 010/110] Replace signature with signatures (#1203)
Signed-off-by: Dumitru
---
irohad/model/converters/impl/pb_transaction_factory.cpp | 4 ++--
schema/block.proto | 2 +-
shared_model/backend/protobuf/transaction.hpp | 4 ++--
test/integration/acceptance/invalid_fields_test.cpp | 4 ++--
.../backend_proto/shared_proto_transaction_test.cpp | 2 +-
test/module/shared_model/validators/field_validator_test.cpp | 2 +-
6 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/irohad/model/converters/impl/pb_transaction_factory.cpp b/irohad/model/converters/impl/pb_transaction_factory.cpp
index c4fc9ec257..91c5d10145 100644
--- a/irohad/model/converters/impl/pb_transaction_factory.cpp
+++ b/irohad/model/converters/impl/pb_transaction_factory.cpp
@@ -43,7 +43,7 @@ namespace iroha {
}
for (const auto &sig_obj : tx.signatures) {
- auto proto_signature = pbtx.add_signature();
+ auto proto_signature = pbtx.add_signatures();
proto_signature->set_pubkey(sig_obj.pubkey.to_string());
proto_signature->set_signature(sig_obj.signature.to_string());
}
@@ -60,7 +60,7 @@ namespace iroha {
tx.creator_account_id = pl.creator_account_id();
tx.created_ts = pl.created_time();
- for (const auto &pb_sig : pb_tx.signature()) {
+ for (const auto &pb_sig : pb_tx.signatures()) {
model::Signature sig{};
sig.pubkey = pubkey_t::from_string(pb_sig.pubkey());
sig.signature = sig_t::from_string(pb_sig.signature());
diff --git a/schema/block.proto b/schema/block.proto
index 3b37491963..4563e995e0 100644
--- a/schema/block.proto
+++ b/schema/block.proto
@@ -17,7 +17,7 @@ message Header {
}
Payload payload = 1;
- repeated Signature signature = 2;
+ repeated Signature signatures = 2;
}
message Block {
diff --git a/shared_model/backend/protobuf/transaction.hpp b/shared_model/backend/protobuf/transaction.hpp
index 76a5caca49..f78c22ad77 100644
--- a/shared_model/backend/protobuf/transaction.hpp
+++ b/shared_model/backend/protobuf/transaction.hpp
@@ -79,7 +79,7 @@ namespace shared_model {
return false;
}
- auto sig = proto_->add_signature();
+ auto sig = proto_->add_signatures();
sig->set_signature(crypto::toBinaryString(signed_blob));
sig->set_pubkey(crypto::toBinaryString(public_key));
@@ -119,7 +119,7 @@ namespace shared_model {
[this] { return makeBlob(payload_); }};
const Lazy signatures_{[this] {
- return boost::accumulate(proto_->signature(),
+ return boost::accumulate(proto_->signatures(),
interface::SignatureSetType{},
[](auto &&acc, const auto &sig) {
acc.emplace(new Signature(sig));
diff --git a/test/integration/acceptance/invalid_fields_test.cpp b/test/integration/acceptance/invalid_fields_test.cpp
index e5bdbbfdec..8134b11bb5 100644
--- a/test/integration/acceptance/invalid_fields_test.cpp
+++ b/test/integration/acceptance/invalid_fields_test.cpp
@@ -53,7 +53,7 @@ TEST_F(InvalidField, Signature) {
.signAndAddSignature(kAdminKeypair)
.getTransport();
// extend signature to invalid size
- auto sig = tx.mutable_signature(0)->mutable_signature();
+ auto sig = tx.mutable_signatures(0)->mutable_signature();
sig->resize(sig->size() + 1, 'a');
auto check = [](auto &resp) {
ASSERT_TRUE(boost::apply_visitor(
@@ -82,7 +82,7 @@ TEST_F(InvalidField, Pubkey) {
.signAndAddSignature(kAdminKeypair)
.getTransport();
// extend public key to invalid size
- auto pkey = tx.mutable_signature(0)->mutable_pubkey();
+ auto pkey = tx.mutable_signatures(0)->mutable_pubkey();
pkey->resize(pkey->size() + 1, 'a');
auto check = [](auto &resp) {
ASSERT_TRUE(boost::apply_visitor(
diff --git a/test/module/shared_model/backend_proto/shared_proto_transaction_test.cpp b/test/module/shared_model/backend_proto/shared_proto_transaction_test.cpp
index 297b0a2067..aeb294cbbb 100644
--- a/test/module/shared_model/backend_proto/shared_proto_transaction_test.cpp
+++ b/test/module/shared_model/backend_proto/shared_proto_transaction_test.cpp
@@ -93,7 +93,7 @@ TEST(ProtoTransaction, Builder) {
shared_model::crypto::Blob(proto_tx.payload().SerializeAsString()),
keypair);
- auto sig = proto_tx.add_signature();
+ auto sig = proto_tx.add_signatures();
sig->set_pubkey(shared_model::crypto::toBinaryString(keypair.publicKey()));
sig->set_signature(shared_model::crypto::toBinaryString(signedProto));
diff --git a/test/module/shared_model/validators/field_validator_test.cpp b/test/module/shared_model/validators/field_validator_test.cpp
index 31c43f5dcd..f7a7630896 100644
--- a/test/module/shared_model/validators/field_validator_test.cpp
+++ b/test/module/shared_model/validators/field_validator_test.cpp
@@ -655,7 +655,7 @@ TEST_F(FieldValidatorTest, CommandFieldsValidation) {
*/
TEST_F(FieldValidatorTest, TransactionFieldsValidation) {
iroha::protocol::Transaction proto_tx;
- proto_tx.add_signature(); // at least one signature in message
+ proto_tx.add_signatures(); // at least one signature in message
// iterate over all fields in transaction
iterateContainer(
From 520674774b190cf2486c6ef526b151b29e56cf93 Mon Sep 17 00:00:00 2001
From: Fedor Muratov
Date: Wed, 11 Apr 2018 19:02:57 +0300
Subject: [PATCH 011/110] Fix toString in account
Signed-off-by: Fedor Muratov
---
shared_model/interfaces/common_objects/account.hpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/shared_model/interfaces/common_objects/account.hpp b/shared_model/interfaces/common_objects/account.hpp
index 545d5aa335..3e22a276b7 100644
--- a/shared_model/interfaces/common_objects/account.hpp
+++ b/shared_model/interfaces/common_objects/account.hpp
@@ -65,6 +65,7 @@ namespace shared_model {
.append("accountId", accountId())
.append("domainId", domainId())
.append("quorum", std::to_string(quorum()))
+ .append("json", jsonData())
.finalize();
}
From a9f49237c37806cf9d695c3496416ae799d21d12 Mon Sep 17 00:00:00 2001
From: Fedor Muratov
Date: Thu, 12 Apr 2018 15:28:50 +0300
Subject: [PATCH 012/110] Tests for heavy transactions (#1198)
Tests for heavy transactions and queries
Signed-off-by: Fedor Muratov
---
shared_model/validators/field_validator.cpp | 3 +-
test/integration/acceptance/CMakeLists.txt | 9 +
test/integration/acceptance/tx_heavy_data.cpp | 234 ++++++++++++++++++
3 files changed, 245 insertions(+), 1 deletion(-)
create mode 100644 test/integration/acceptance/tx_heavy_data.cpp
diff --git a/shared_model/validators/field_validator.cpp b/shared_model/validators/field_validator.cpp
index 5bd825fec0..725def24e3 100644
--- a/shared_model/validators/field_validator.cpp
+++ b/shared_model/validators/field_validator.cpp
@@ -47,7 +47,8 @@ namespace shared_model {
const std::string FieldValidator::role_id_pattern_ = R"#([a-z_0-9]{1,32})#";
const size_t FieldValidator::public_key_size = 32;
- const size_t FieldValidator::value_size = 4096;
+ /// limit for the set account detail size in bytes
+ const size_t FieldValidator::value_size = 4 * 1024 * 1024;
const size_t FieldValidator::description_size = 64;
FieldValidator::FieldValidator(time_t future_gap)
diff --git a/test/integration/acceptance/CMakeLists.txt b/test/integration/acceptance/CMakeLists.txt
index 990bed52eb..e73ab3769e 100644
--- a/test/integration/acceptance/CMakeLists.txt
+++ b/test/integration/acceptance/CMakeLists.txt
@@ -23,6 +23,7 @@ target_link_libraries(tx_acceptance_test
integration_framework
shared_model_stateless_validation
)
+
addtest(get_transactions_test get_transactions_test.cpp)
target_link_libraries(get_transactions_test
application
@@ -86,3 +87,11 @@ target_link_libraries(create_account_test
shared_model_proto_builders
shared_model_stateless_validation
)
+
+addtest(tx_heavy_data tx_heavy_data.cpp)
+target_link_libraries(tx_heavy_data
+ application
+ integration_framework
+ shared_model_proto_builders
+ shared_model_stateless_validation
+ )
diff --git a/test/integration/acceptance/tx_heavy_data.cpp b/test/integration/acceptance/tx_heavy_data.cpp
new file mode 100644
index 0000000000..1bc11d0720
--- /dev/null
+++ b/test/integration/acceptance/tx_heavy_data.cpp
@@ -0,0 +1,234 @@
+/**
+ * Copyright Soramitsu Co., Ltd. 2018 All Rights Reserved.
+ * http://soramitsu.co.jp
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+
+#include "builders/protobuf/queries.hpp"
+#include "builders/protobuf/transaction.hpp"
+#include "cryptography/crypto_provider/crypto_defaults.hpp"
+#include "datetime/time.hpp"
+#include "framework/base_tx.hpp"
+#include "framework/integration_framework/integration_test_framework.hpp"
+#include "interfaces/utils/specified_visitor.hpp"
+#include "module/shared_model/builders/protobuf/test_query_builder.hpp"
+#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
+#include "validators/permissions.hpp"
+
+using namespace std::string_literals;
+using namespace integration_framework;
+using namespace shared_model;
+
+class HeavyTransactionTest : public ::testing::Test {
+ public:
+ /**
+ * Creates the transaction with the user creation commands
+ * @param perms are the permissions of the user
+ * @return built tx and a hash of its payload
+ */
+ auto makeUserWithPerms(
+ const std::vector &perms = {
+ shared_model::permissions::role_perm_group.begin(),
+ shared_model::permissions::role_perm_group.end()}) {
+ return framework::createUserWithPerms(
+ kUser, kUserKeypair.publicKey(), "role"s, perms)
+ .build()
+ .signAndAddSignature(kAdminKeypair);
+ }
+
+ /**
+ * Create valid base pre-built transaction
+ * @return pre-built tx
+ */
+ auto baseTx() {
+ return TestUnsignedTransactionBuilder()
+ .txCounter(1)
+ .creatorAccountId(kUserId)
+ .createdTime(iroha::time::now());
+ }
+
+ /**
+ * Generate stub of transaction for setting data to default user account
+ * @param key - key for the insertion
+ * @param value - data that will be attached
+ * @return generated builder, without signature
+ */
+ auto setAcountDetailTx(const std::string &key, const std::string &value) {
+ return baseTx().setAccountDetail(kUserId, key, value);
+ }
+
+ /**
+ * Util method for stub data generation
+ * @param quantity - number of bytes
+ * @return new string with passed quantity length
+ */
+ static auto generateData(size_t quantity) {
+ return std::string(quantity, 'F');
+ }
+
+ /**
+ * Sign pre-built object
+ * @param builder is a pre-built signable object
+ * @return completed object
+ */
+ template
+ auto complete(Builder builder) {
+ return builder.build().signAndAddSignature(kUserKeypair);
+ }
+
+ /**
+ * Create valid basis of pre-built query
+ * @return query stub with counter, creator and time
+ */
+ auto baseQuery() {
+ return TestUnsignedQueryBuilder()
+ .queryCounter(1)
+ .creatorAccountId(kUserId)
+ .createdTime(iroha::time::now());
+ }
+
+ const std::string kUser = "user"s;
+ const std::string kUserId =
+ kUser + "@"s + IntegrationTestFramework::kDefaultDomain;
+ const crypto::Keypair kUserKeypair =
+ crypto::DefaultCryptoAlgorithmType::generateKeypair();
+ const crypto::Keypair kAdminKeypair =
+ crypto::DefaultCryptoAlgorithmType::generateKeypair();
+};
+
+/**
+ * @given some user with all required permissions
+ * @when send tx with addAccountDetail with big, but stateless invalid data
+ * inside
+ * @then transaction is passed
+ */
+TEST_F(HeavyTransactionTest, OneLargeTx) {
+ IntegrationTestFramework()
+ .setInitialState(kAdminKeypair)
+ .sendTx(makeUserWithPerms())
+ .skipProposal()
+ .checkBlock(
+ [](auto &block) { ASSERT_EQ(block->transactions().size(), 1); })
+ // "foo" transactions will not be passed because it has large size into
+ // one field - 5Mb per one set
+ .sendTx(complete(setAcountDetailTx("foo", generateData(5 * 1024 * 1024))))
+ .skipProposal()
+ .checkBlock(
+ [](auto &block) { ASSERT_EQ(block->transactions().size(), 0); })
+ .done();
+}
+
+/**
+ * NOTE: test is disabled until fix of
+ * https://soramitsu.atlassian.net/browse/IR-1205 will not be completed.
+ * @given some user with all required permissions
+ * @when send many txes with addAccountDetail with large data inside
+ * @then transaction have been passed
+ */
+TEST_F(HeavyTransactionTest, DISABLED_ManyLargeTxes) {
+ IntegrationTestFramework itf;
+
+ itf.setInitialState(kAdminKeypair)
+ .sendTx(makeUserWithPerms())
+ .skipProposal()
+ .checkBlock([](auto &b) { ASSERT_EQ(b->transactions().size(), 1); });
+
+ auto number_of_txes = 4u;
+ for (auto i = 0u; i < number_of_txes; ++i) {
+ itf.sendTx(complete(setAcountDetailTx("foo_" + std::to_string(i),
+ generateData(2 * 1024 * 1024))));
+ }
+ itf.skipProposal()
+ .checkBlock(
+ [&](auto &b) { ASSERT_EQ(b->transactions().size(), number_of_txes); })
+ .done();
+}
+
+/**
+ * NOTE: test is disabled until fix of
+ * https://soramitsu.atlassian.net/browse/IR-1205 will not be completed.
+ * @given some user with all required permissions
+ * @when send tx with many addAccountDetails with large data inside
+ * @then transaction is passed
+ */
+TEST_F(HeavyTransactionTest, DISABLED_VeryLargeTxWithManyCommands) {
+ auto big_data = generateData(3 * 1024 * 1024);
+ auto large_tx_builder = setAcountDetailTx("foo_1", big_data)
+ .setAccountDetail(kUserId, "foo_2", big_data)
+ .setAccountDetail(kUserId, "foo_3", big_data);
+
+ IntegrationTestFramework()
+ .setInitialState(kAdminKeypair)
+ .sendTx(makeUserWithPerms())
+ // in itf tx build from large_tx_build will pass in Torii but in
+ // production the transaction will be failed before stateless validation
+ // because of size.
+ .sendTx(complete(large_tx_builder))
+ .skipProposal()
+ .checkBlock(
+ [](auto &block) { ASSERT_EQ(block->transactions().size(), 1); })
+ .done();
+}
+
+/**
+ * NOTE: test is disabled until fix of
+ * https://soramitsu.atlassian.net/browse/IR-1205 will not be completed.
+ * @given some user with all required permissions
+ * AND max proposal size is 1.
+ * @when send txes with addAccountDetail with large data inside.
+ * AND transactions are passed stateful validation
+ * @then query executed sucessfully
+ */
+TEST_F(HeavyTransactionTest, DISABLED_QueryLargeData) {
+ auto number_of_times = 15u;
+ auto size_of_data = 3 * 1024 * 1024u;
+ auto data = generateData(size_of_data);
+
+ auto name_generator = [](auto val) { return "foo_" + std::to_string(val); };
+
+ auto query_checker = [&](auto &status) {
+ auto response = *boost::apply_visitor(
+ interface::SpecifiedVisitor(),
+ status.get());
+
+ boost::property_tree::ptree root;
+ boost::property_tree::read_json(response->account().jsonData(), root);
+ auto user = root.get_child(kUserId);
+
+ ASSERT_EQ(number_of_times, user.size());
+
+ for (auto i = 0u; i < number_of_times; ++i) {
+ ASSERT_EQ(data, user.get(name_generator(i)));
+ }
+ };
+
+ IntegrationTestFramework itf(1);
+ itf.setInitialState(kAdminKeypair).sendTx(makeUserWithPerms());
+
+ for (auto i = 0u; i < number_of_times; ++i) {
+ itf.sendTx(complete(setAcountDetailTx(name_generator(i), data)))
+ .skipProposal()
+ .checkBlock(
+ [](auto &block) { ASSERT_EQ(block->transactions().size(), 1); });
+ }
+
+ // The query works fine only with ITF. It doesn't work in production version
+ // of Iroha
+ itf.sendQuery(complete(baseQuery().getAccount(kUserId)), query_checker)
+ .done();
+}
From f1db8a1eba917dca7741fa760bf317854f11daaf Mon Sep 17 00:00:00 2001
From: Dumitru
Date: Thu, 12 Apr 2018 16:18:56 +0300
Subject: [PATCH 013/110] Shared model/torii test (#1202)
* Remove old model from Torii test
Signed-off-by: Dumitru
* Docs
Signed-off-by: Dumitru
* Fix typo
Signed-off-by: Dumitru
* Remove getError, refactor
Signed-off-by: Dumitru
---
.../query_responses/error_query_response.hpp | 2 +
.../torii/processor/query_processor_test.cpp | 30 +--
.../processor/transaction_processor_test.cpp | 1 +
.../irohad/torii/query_service_test.cpp | 44 ++--
test/module/irohad/torii/torii_mocks.hpp | 1 +
.../irohad/torii/torii_queries_test.cpp | 203 +++++++++---------
.../irohad/torii/torii_service_test.cpp | 119 +++++-----
.../protobuf/test_query_response_builder.hpp | 3 +-
8 files changed, 198 insertions(+), 205 deletions(-)
diff --git a/shared_model/interfaces/query_responses/error_query_response.hpp b/shared_model/interfaces/query_responses/error_query_response.hpp
index c8aa5a4a8c..480c3f9a45 100644
--- a/shared_model/interfaces/query_responses/error_query_response.hpp
+++ b/shared_model/interfaces/query_responses/error_query_response.hpp
@@ -19,6 +19,7 @@
#define IROHA_SHARED_MODEL_QUERY_ERROR_RESPONSE_HPP
#include
+
#include "interfaces/base/primitive.hpp"
#include "interfaces/query_responses/error_responses/no_account_assets_error_response.hpp"
#include "interfaces/query_responses/error_responses/no_account_detail_error_response.hpp"
@@ -29,6 +30,7 @@
#include "interfaces/query_responses/error_responses/not_supported_error_response.hpp"
#include "interfaces/query_responses/error_responses/stateful_failed_error_response.hpp"
#include "interfaces/query_responses/error_responses/stateless_failed_error_response.hpp"
+#include "utils/visitor_apply_for_all.hpp"
namespace shared_model {
namespace interface {
diff --git a/test/module/irohad/torii/processor/query_processor_test.cpp b/test/module/irohad/torii/processor/query_processor_test.cpp
index b18cbbd1e1..98fc386ba5 100644
--- a/test/module/irohad/torii/processor/query_processor_test.cpp
+++ b/test/module/irohad/torii/processor/query_processor_test.cpp
@@ -15,21 +15,19 @@
* limitations under the License.
*/
-#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
-#include "module/irohad/validation/validation_mocks.hpp"
-#include "validators/permissions.hpp"
-
-#include "framework/test_subscriber.hpp"
-#include "model/queries/responses/error_response.hpp"
-#include "model/query_execution.hpp"
-#include "network/ordering_gate.hpp"
-#include "torii/processor/query_processor_impl.hpp"
-
#include "backend/protobuf/query_responses/proto_error_query_response.hpp"
#include "builders/protobuf/common_objects/proto_account_builder.hpp"
#include "cryptography/crypto_provider/crypto_defaults.hpp"
#include "cryptography/keypair.hpp"
+#include "framework/test_subscriber.hpp"
+#include "model/query_execution.hpp"
+#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
+#include "module/irohad/validation/validation_mocks.hpp"
#include "module/shared_model/builders/protobuf/test_query_builder.hpp"
+#include "module/shared_model/builders/protobuf/test_query_response_builder.hpp"
+#include "network/ordering_gate.hpp"
+#include "torii/processor/query_processor_impl.hpp"
+#include "validators/permissions.hpp"
using namespace iroha;
using namespace iroha::ametsuchi;
@@ -54,9 +52,6 @@ class QueryProcessorTest : public ::testing::Test {
shared_model::crypto::Keypair keypair =
shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair();
- decltype(shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair())
- pair =
- shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair();
std::vector signatories = {
keypair.publicKey()};
};
@@ -83,12 +78,9 @@ TEST_F(QueryProcessorTest, QueryProcessorWhereInvokeInvalidQuery) {
.build()
.signAndAddSignature(keypair);
- auto qry_resp = std::make_shared();
- auto account = model::Account();
- account.account_id = account_id;
- qry_resp->account = account;
std::shared_ptr shared_account = clone(
shared_model::proto::AccountBuilder().accountId(account_id).build());
+
auto role = "admin";
std::vector roles = {role};
std::vector perms = {
@@ -140,10 +132,6 @@ TEST_F(QueryProcessorTest, QueryProcessorWithWrongKey) {
shared_model::crypto::DefaultCryptoAlgorithmType::
generateKeypair());
- auto qry_resp = std::make_shared();
- auto account = model::Account();
- account.account_id = account_id;
- qry_resp->account = account;
std::shared_ptr shared_account = clone(
shared_model::proto::AccountBuilder().accountId(account_id).build());
auto role = "admin";
diff --git a/test/module/irohad/torii/processor/transaction_processor_test.cpp b/test/module/irohad/torii/processor/transaction_processor_test.cpp
index f0905112bf..867656d309 100644
--- a/test/module/irohad/torii/processor/transaction_processor_test.cpp
+++ b/test/module/irohad/torii/processor/transaction_processor_test.cpp
@@ -16,6 +16,7 @@
*/
#include
+
#include "builders/protobuf/proposal.hpp"
#include "builders/protobuf/transaction.hpp"
#include "framework/test_subscriber.hpp"
diff --git a/test/module/irohad/torii/query_service_test.cpp b/test/module/irohad/torii/query_service_test.cpp
index 8bddc449f8..b30ea1fc33 100644
--- a/test/module/irohad/torii/query_service_test.cpp
+++ b/test/module/irohad/torii/query_service_test.cpp
@@ -17,8 +17,11 @@
#include "torii/query_service.hpp"
#include "backend/protobuf/query_responses/proto_query_response.hpp"
+#include "builders/protobuf/common_objects/proto_account_builder.hpp"
#include "builders/protobuf/queries.hpp"
#include "module/irohad/torii/torii_mocks.hpp"
+#include "module/shared_model/builders/protobuf/test_query_response_builder.hpp"
+#include "utils/query_error_response_visitor.hpp"
using namespace torii;
@@ -48,19 +51,16 @@ class QueryServiceTest : public ::testing::Test {
shared_model::crypto::DefaultCryptoAlgorithmType::
generateKeypair()));
- // TODO: IR-1041 Update to query response builders (kamilsa, 04.03.2018)
- protocol::QueryResponse response;
- response.set_query_hash(
- shared_model::crypto::toBinaryString(query->hash()));
- auto account_response = response.mutable_account_response();
- account_response->add_account_roles("user");
- auto account = account_response->mutable_account();
- account->set_domain_id("ru");
- account->set_account_id("a");
- account->set_quorum(2);
-
- model_response = std::make_shared(
- std::move(response));
+ auto account = shared_model::proto::AccountBuilder()
+ .accountId("a")
+ .domainId("ru")
+ .quorum(2)
+ .build();
+
+ model_response = clone(TestQueryResponseBuilder()
+ .accountResponse(account, {"user"})
+ .queryHash(query->hash())
+ .build());
}
void init() {
@@ -99,8 +99,8 @@ TEST_F(QueryServiceTest, ValidWhenUniqueHash) {
protocol::QueryResponse response;
query_service->Find(query->getTransport(), response);
- ASSERT_EQ(response.SerializeAsString(),
- model_response->getTransport().SerializeAsString());
+ auto resp = shared_model::proto::QueryResponse(response);
+ ASSERT_EQ(resp, *model_response);
}
/**
@@ -129,8 +129,11 @@ TEST_F(QueryServiceTest, InvalidWhenUniqueHash) {
protocol::QueryResponse response;
query_service->Find(query->getTransport(), response);
ASSERT_TRUE(response.has_error_response());
- ASSERT_EQ(response.error_response().reason(),
- protocol::ErrorResponse::NOT_SUPPORTED);
+ auto resp = shared_model::proto::QueryResponse(response);
+ ASSERT_TRUE(boost::apply_visitor(
+ shared_model::interface::QueryErrorResponseChecker<
+ shared_model::interface::NotSupportedErrorResponse>(),
+ resp.get()));
}
/**
@@ -154,6 +157,9 @@ TEST_F(QueryServiceTest, InvalidWhenDuplicateHash) {
// second call of the same query
query_service->Find(query->getTransport(), response);
ASSERT_TRUE(response.has_error_response());
- ASSERT_EQ(response.error_response().reason(),
- protocol::ErrorResponse::STATELESS_INVALID);
+ auto resp = shared_model::proto::QueryResponse(response);
+ ASSERT_TRUE(boost::apply_visitor(
+ shared_model::interface::QueryErrorResponseChecker<
+ shared_model::interface::StatelessFailedErrorResponse>(),
+ resp.get()));
}
diff --git a/test/module/irohad/torii/torii_mocks.hpp b/test/module/irohad/torii/torii_mocks.hpp
index 0889042328..10fb2ded6e 100644
--- a/test/module/irohad/torii/torii_mocks.hpp
+++ b/test/module/irohad/torii/torii_mocks.hpp
@@ -24,6 +24,7 @@
namespace iroha {
namespace torii {
+
class MockQueryProcessor : public QueryProcessor {
public:
MOCK_METHOD1(queryHandle,
diff --git a/test/module/irohad/torii/torii_queries_test.cpp b/test/module/irohad/torii/torii_queries_test.cpp
index 2aab5b337d..08e8c9a088 100644
--- a/test/module/irohad/torii/torii_queries_test.cpp
+++ b/test/module/irohad/torii/torii_queries_test.cpp
@@ -14,28 +14,26 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
+#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
+#include "module/irohad/network/network_mocks.hpp"
+#include "module/irohad/torii/torii_mocks.hpp"
+#include "module/irohad/validation/validation_mocks.hpp"
+
#include "builders/protobuf/common_objects/proto_account_asset_builder.hpp"
#include "builders/protobuf/common_objects/proto_account_builder.hpp"
#include "builders/protobuf/common_objects/proto_amount_builder.hpp"
#include "builders/protobuf/common_objects/proto_asset_builder.hpp"
-#include "generator/generator.hpp"
-#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
-#include "module/irohad/network/network_mocks.hpp"
-#include "module/irohad/validation/validation_mocks.hpp"
+#include "builders/protobuf/queries.hpp"
+#include "module/shared_model/builders/protobuf/test_query_builder.hpp"
#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
-// to compare pb amount and iroha amount
-#include "model/converters/pb_common.hpp"
#include "main/server_runner.hpp"
#include "torii/processor/query_processor_impl.hpp"
#include "torii/query_client.hpp"
#include "torii/query_service.hpp"
+#include "utils/query_error_response_visitor.hpp"
#include "validators/permissions.hpp"
-#include "builders/protobuf/queries.hpp"
-#include "cryptography/crypto_provider/crypto_defaults.hpp"
-#include "module/shared_model/builders/protobuf/test_query_builder.hpp"
-
constexpr const char *Ip = "0.0.0.0";
constexpr int Port = 50051;
@@ -47,6 +45,7 @@ using ::testing::AtLeast;
using ::testing::Return;
using namespace iroha::ametsuchi;
+using namespace iroha::torii;
using wTransaction = std::shared_ptr;
@@ -77,20 +76,14 @@ class ToriiQueriesTest : public testing::Test {
}
ServerRunner *runner;
- decltype(shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair())
- pair =
- shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair();
+ shared_model::crypto::Keypair pair =
+ shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair();
std::vector signatories = {
pair.publicKey()};
std::shared_ptr wsv_query;
std::shared_ptr block_query;
std::shared_ptr storage;
-
- // just random hex strings
- const std::string pubkey_test = generator::random_blob<16>(0).to_hexstring();
- const std::string signature_test =
- generator::random_blob<32>(0).to_hexstring();
};
/**
@@ -100,12 +93,11 @@ class ToriiQueriesTest : public testing::Test {
*/
TEST_F(ToriiQueriesTest, QueryClient) {
iroha::protocol::QueryResponse response;
- auto query = iroha::protocol::Query();
-
- query.mutable_payload()->set_creator_account_id("accountA");
- query.mutable_payload()->mutable_get_account()->set_account_id("accountB");
- query.mutable_signature()->set_pubkey(pubkey_test);
- query.mutable_signature()->set_signature(signature_test);
+ auto query = TestUnsignedQueryBuilder()
+ .creatorAccountId("accountA")
+ .getAccount("accountB")
+ .build()
+ .signAndAddSignature(pair);
auto client1 = torii_utils::QuerySyncClient(Ip, Port);
// Copy ctor
@@ -116,7 +108,7 @@ TEST_F(ToriiQueriesTest, QueryClient) {
torii_utils::QuerySyncClient client4(std::move(client3));
// move assignment
auto client5 = std::move(client4);
- auto stat = client5.Find(query, response);
+ auto stat = client5.Find(query.getTransport(), response);
ASSERT_TRUE(stat.ok());
}
@@ -126,19 +118,23 @@ TEST_F(ToriiQueriesTest, QueryClient) {
TEST_F(ToriiQueriesTest, FindWhenResponseInvalid) {
iroha::protocol::QueryResponse response;
- auto query = iroha::protocol::Query();
-
- query.mutable_payload()->set_creator_account_id("accountA");
- query.mutable_payload()->mutable_get_account()->set_account_id("accountB");
- query.mutable_signature()->set_pubkey(pubkey_test);
- query.mutable_signature()->set_signature(signature_test);
-
- auto stat = torii_utils::QuerySyncClient(Ip, Port).Find(query, response);
+ auto query = TestUnsignedQueryBuilder()
+ .creatorAccountId("accountA")
+ .getAccount("accountB")
+ .build()
+ .signAndAddSignature(pair);
+
+ auto stat = torii_utils::QuerySyncClient(Ip, Port).Find(query.getTransport(),
+ response);
+ auto resp = shared_model::proto::QueryResponse(response);
ASSERT_TRUE(stat.ok());
// Must return Error Response
- ASSERT_EQ(response.error_response().reason(),
- iroha::model::ErrorResponse::STATELESS_INVALID);
- ASSERT_EQ(iroha::hash(query).to_string(), response.query_hash());
+ ASSERT_TRUE(boost::apply_visitor(
+ shared_model::interface::QueryErrorResponseChecker<
+ shared_model::interface::StatelessFailedErrorResponse>(),
+ resp.get()));
+
+ ASSERT_EQ(query.hash(), resp.queryHash());
}
/**
@@ -146,15 +142,14 @@ TEST_F(ToriiQueriesTest, FindWhenResponseInvalid) {
*/
TEST_F(ToriiQueriesTest, FindAccountWhenNoGrantPermissions) {
- // TODO: kamilsa 19.02.2017 remove old model
- iroha::model::Account account;
- account.account_id = "b@domain";
+ auto account =
+ shared_model::proto::AccountBuilder().accountId("b@domain").build();
auto creator = "a@domain";
EXPECT_CALL(*wsv_query,
hasAccountGrantablePermission(
creator,
- account.account_id,
+ account.accountId(),
shared_model::permissions::can_get_my_account))
.WillOnce(Return(false));
@@ -169,7 +164,7 @@ TEST_F(ToriiQueriesTest, FindAccountWhenNoGrantPermissions) {
.creatorAccountId(creator)
.queryCounter(1)
.createdTime(iroha::time::now())
- .getAccount(account.account_id)
+ .getAccount(account.accountId())
.build()
.signAndAddSignature(pair);
@@ -177,13 +172,15 @@ TEST_F(ToriiQueriesTest, FindAccountWhenNoGrantPermissions) {
model_query.getTransport(), response);
ASSERT_TRUE(stat.ok());
-
+ auto resp = shared_model::proto::QueryResponse(response);
// Must be invalid due to failed stateful validation caused by no permission
// to read account
- ASSERT_EQ(response.error_response().reason(),
- iroha::model::ErrorResponse::STATEFUL_INVALID);
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+ ASSERT_TRUE(boost::apply_visitor(
+ shared_model::interface::QueryErrorResponseChecker<
+ shared_model::interface::StatefulFailedErrorResponse>(),
+ resp.get()));
+
+ ASSERT_EQ(model_query.hash(), resp.queryHash());
}
TEST_F(ToriiQueriesTest, FindAccountWhenHasReadPermissions) {
@@ -220,14 +217,18 @@ TEST_F(ToriiQueriesTest, FindAccountWhenHasReadPermissions) {
auto stat = torii_utils::QuerySyncClient(Ip, Port).Find(
model_query.getTransport(), response);
+ auto resp = shared_model::proto::QueryResponse(response);
+
ASSERT_TRUE(stat.ok());
// Should not return Error Response because tx is stateless and stateful valid
ASSERT_FALSE(response.has_error_response());
- ASSERT_EQ(response.account_response().account().account_id(),
- accountB->accountId());
- ASSERT_EQ(response.account_response().account_roles().size(), 1);
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+
+ auto account_resp = boost::get>(resp.get());
+
+ ASSERT_EQ(account_resp->account().accountId(), accountB->accountId());
+ ASSERT_EQ(account_resp->roles().size(), 1);
+ ASSERT_EQ(model_query.hash(), resp.queryHash());
}
TEST_F(ToriiQueriesTest, FindAccountWhenHasRolePermission) {
@@ -257,16 +258,17 @@ TEST_F(ToriiQueriesTest, FindAccountWhenHasRolePermission) {
auto stat = torii_utils::QuerySyncClient(Ip, Port).Find(
model_query.getTransport(), response);
+ auto resp = shared_model::proto::QueryResponse(response);
ASSERT_TRUE(stat.ok());
// Should not return Error Response because tx is stateless and stateful valid
ASSERT_FALSE(response.has_error_response());
- // ASSERT_EQ(response.account_detail_response().detail(), "value");
- ASSERT_EQ(response.account_response().account().account_id(),
- account->accountId());
- ASSERT_EQ(response.account_response().account().domain_id(),
- account->domainId());
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+
+ auto detail_resp = boost::get>(resp.get());
+
+ ASSERT_EQ(detail_resp->account().accountId(), account->accountId());
+ ASSERT_EQ(detail_resp->account().domainId(), account->domainId());
+ ASSERT_EQ(model_query.hash(), resp.queryHash());
}
/**
@@ -302,13 +304,16 @@ TEST_F(ToriiQueriesTest, FindAccountAssetWhenNoGrantPermissions) {
auto stat = torii_utils::QuerySyncClient(Ip, Port).Find(
model_query.getTransport(), response);
+ auto resp = shared_model::proto::QueryResponse(response);
ASSERT_TRUE(stat.ok());
// Must be invalid due to failed stateful validation caused by no permission
// to read account asset
- ASSERT_EQ(response.error_response().reason(),
- iroha::model::ErrorResponse::STATEFUL_INVALID);
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+ ASSERT_TRUE(boost::apply_visitor(
+ shared_model::interface::QueryErrorResponseChecker<
+ shared_model::interface::StatefulFailedErrorResponse>(),
+ resp.get()));
+
+ ASSERT_EQ(model_query.hash(), resp.queryHash());
}
TEST_F(ToriiQueriesTest, FindAccountAssetWhenHasRolePermissions) {
@@ -361,18 +366,15 @@ TEST_F(ToriiQueriesTest, FindAccountAssetWhenHasRolePermissions) {
// Should not return Error Response because tx is stateless and stateful valid
ASSERT_FALSE(response.has_error_response());
+ auto resp = shared_model::proto::QueryResponse(response);
+ auto asset_resp = boost::get>(resp.get());
+
// Check if the fields in account asset response are correct
- ASSERT_EQ(response.account_assets_response().account_asset().asset_id(),
- account_asset->assetId());
- ASSERT_EQ(response.account_assets_response().account_asset().account_id(),
- account_asset->accountId());
- auto iroha_amount_asset = iroha::model::converters::deserializeAmount(
- response.account_assets_response().account_asset().balance());
- ASSERT_EQ(
- iroha_amount_asset,
- *std::unique_ptr(account_asset->balance().makeOldModel()));
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+ ASSERT_EQ(asset_resp->accountAsset().assetId(), account_asset->assetId());
+ ASSERT_EQ(asset_resp->accountAsset().accountId(), account_asset->accountId());
+ ASSERT_EQ(asset_resp->accountAsset().balance(), account_asset->balance());
+ ASSERT_EQ(model_query.hash(), resp.queryHash());
}
/**
@@ -413,10 +415,13 @@ TEST_F(ToriiQueriesTest, FindSignatoriesWhenNoGrantPermissions) {
ASSERT_TRUE(stat.ok());
// Must be invalid due to failed stateful validation caused by no permission
// to read account
- ASSERT_EQ(response.error_response().reason(),
- iroha::model::ErrorResponse::STATEFUL_INVALID);
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+ auto resp = shared_model::proto::QueryResponse(response);
+ ASSERT_TRUE(boost::apply_visitor(
+ shared_model::interface::QueryErrorResponseChecker<
+ shared_model::interface::StatefulFailedErrorResponse>(),
+ resp.get()));
+
+ ASSERT_EQ(model_query.hash(), resp.queryHash());
}
TEST_F(ToriiQueriesTest, FindSignatoriesHasRolePermissions) {
@@ -460,8 +465,7 @@ TEST_F(ToriiQueriesTest, FindSignatoriesHasRolePermissions) {
ASSERT_FALSE(response.has_error_response());
// check if fields in response are valid
ASSERT_EQ(*resp_pubkey, signatories.back());
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+ ASSERT_EQ(model_query.hash(), shared_response.queryHash());
}
/**
@@ -469,16 +473,15 @@ TEST_F(ToriiQueriesTest, FindSignatoriesHasRolePermissions) {
*/
TEST_F(ToriiQueriesTest, FindTransactionsWhenValid) {
- // TODO 19.02.2018 kamilsa remove old model
- iroha::model::Account account;
- account.account_id = "accountA";
+ auto account =
+ shared_model::proto::AccountBuilder().accountId("accountA").build();
auto creator = "a@domain";
- auto txs_observable = rxcpp::observable<>::iterate([account] {
+ auto txs_observable = rxcpp::observable<>::iterate([&account] {
std::vector result;
for (size_t i = 0; i < 3; ++i) {
std::shared_ptr current =
clone(TestTransactionBuilder()
- .creatorAccountId(account.account_id)
+ .creatorAccountId(account.accountId())
.txCounter(i)
.build());
result.push_back(current);
@@ -511,19 +514,16 @@ TEST_F(ToriiQueriesTest, FindTransactionsWhenValid) {
ASSERT_TRUE(stat.ok());
// Should not return Error Response because tx is stateless and stateful valid
ASSERT_FALSE(response.has_error_response());
- for (auto i = 0; i < response.transactions_response().transactions_size();
- i++) {
- ASSERT_EQ(response.transactions_response()
- .transactions(i)
- .payload()
- .creator_account_id(),
- account.account_id);
- ASSERT_EQ(
- response.transactions_response().transactions(i).payload().tx_counter(),
- i);
+ auto resp = shared_model::proto::QueryResponse(response);
+ auto tx_resp = boost::get>(resp.get());
+
+ const auto &txs = tx_resp->transactions();
+ for (auto i = 0ul; i < txs.size(); i++) {
+ ASSERT_EQ(txs.at(i)->creatorAccountId(), account.accountId());
+ ASSERT_EQ(txs.at(i)->transactionCounter(), i);
}
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+ ASSERT_EQ(model_query.hash(), resp.queryHash());
}
TEST_F(ToriiQueriesTest, FindManyTimesWhereQueryServiceSync) {
@@ -542,10 +542,13 @@ TEST_F(ToriiQueriesTest, FindManyTimesWhereQueryServiceSync) {
auto stat = client.Find(model_query.getTransport(), response);
ASSERT_TRUE(stat.ok());
+ auto resp = shared_model::proto::QueryResponse(response);
// Must return Error Response
- ASSERT_EQ(response.error_response().reason(),
- iroha::model::ErrorResponse::STATELESS_INVALID);
- ASSERT_EQ(iroha::hash(model_query.getTransport()).to_string(),
- response.query_hash());
+ ASSERT_TRUE(boost::apply_visitor(
+ shared_model::interface::QueryErrorResponseChecker<
+ shared_model::interface::StatelessFailedErrorResponse>(),
+ resp.get()));
+
+ ASSERT_EQ(model_query.hash(), resp.queryHash());
}
}
diff --git a/test/module/irohad/torii/torii_service_test.cpp b/test/module/irohad/torii/torii_service_test.cpp
index 5b0f80dc8c..f1fbceabc0 100644
--- a/test/module/irohad/torii/torii_service_test.cpp
+++ b/test/module/irohad/torii/torii_service_test.cpp
@@ -15,16 +15,16 @@ limitations under the License.
*/
#include "builders/protobuf/block.hpp"
-#include "builders/protobuf/transaction.hpp"
#include "builders/protobuf/proposal.hpp"
+#include "builders/protobuf/transaction.hpp"
#include "endpoint.pb.h"
#include "main/server_runner.hpp"
-#include "model/converters/pb_transaction_factory.hpp"
-#include "model/sha3_hash.hpp"
#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
#include "module/irohad/network/network_mocks.hpp"
#include "module/shared_model/builders/protobuf/test_block_builder.hpp"
#include "module/shared_model/builders/protobuf/test_proposal_builder.hpp"
+#include "module/shared_model/builders/protobuf/test_query_response_builder.hpp"
+#include "module/shared_model/builders/protobuf/test_transaction_builder.hpp"
#include "torii/command_client.hpp"
#include "torii/command_service.hpp"
#include "torii/processor/transaction_processor_impl.hpp"
@@ -86,8 +86,6 @@ class ToriiServiceTest : public testing::Test {
auto tx_processor =
std::make_shared(pcsMock);
- auto pb_tx_factory =
- std::make_shared();
EXPECT_CALL(*block_query, getTxByHashSync(_))
.WillRepeatedly(Return(boost::none));
@@ -149,22 +147,17 @@ TEST_F(ToriiServiceTest, CommandClient) {
* @then ensure those are not received
*/
TEST_F(ToriiServiceTest, StatusWhenTxWasNotReceivedBlocking) {
- std::vector txs;
- std::vector tx_hashes;
-
- iroha::model::converters::PbTransactionFactory tx_factory;
+ std::vector txs;
+ std::vector tx_hashes;
// create transactions, but do not send them
for (size_t i = 0; i < TimesToriiBlocking; ++i) {
- auto new_tx = iroha::protocol::Transaction();
- auto payload = new_tx.mutable_payload();
- payload->set_tx_counter(i);
- payload->set_creator_account_id("accountA");
-
- auto iroha_tx = tx_factory.deserialize(new_tx);
- txs.push_back(*iroha_tx);
- auto tx_hash = iroha::hash(*iroha_tx);
- tx_hashes.push_back(tx_hash.to_string());
+ auto tx = TestTransactionBuilder()
+ .creatorAccountId("accountA")
+ .txCounter(i)
+ .build();
+ txs.push_back(tx);
+ tx_hashes.push_back(tx.hash());
}
// get statuses of unsent transactions
@@ -172,10 +165,10 @@ TEST_F(ToriiServiceTest, StatusWhenTxWasNotReceivedBlocking) {
for (size_t i = 0; i < TimesToriiBlocking; ++i) {
iroha::protocol::TxStatusRequest tx_request;
- tx_request.set_tx_hash(tx_hashes.at(i));
+ tx_request.set_tx_hash(
+ shared_model::crypto::toBinaryString(tx_hashes.at(i)));
iroha::protocol::ToriiResponse toriiResponse;
client.Status(tx_request, toriiResponse);
-
ASSERT_EQ(toriiResponse.tx_status(),
iroha::protocol::TxStatus::NOT_RECEIVED);
}
@@ -196,7 +189,7 @@ TEST_F(ToriiServiceTest, StatusWhenTxWasNotReceivedBlocking) {
*/
TEST_F(ToriiServiceTest, StatusWhenBlocking) {
std::vector txs;
- std::vector tx_hashes;
+ std::vector tx_hashes;
auto client1 = torii::CommandSyncClient(Ip, Port);
@@ -212,19 +205,22 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
.signAndAddSignature(
shared_model::crypto::DefaultCryptoAlgorithmType::
generateKeypair());
- auto new_tx = shm_tx.getTransport();
+ const auto &new_tx = shm_tx.getTransport();
auto stat = client1.Torii(new_tx);
txs.push_back(shm_tx);
- auto tx_hash = shared_model::crypto::toBinaryString(shm_tx.hash());
- tx_hashes.push_back(tx_hash);
+ tx_hashes.push_back(shm_tx.hash());
ASSERT_TRUE(stat.ok());
}
// create proposal from these transactions
auto proposal = std::make_shared(
- TestProposalBuilder().height(1).createdTime(iroha::time::now()).transactions(txs).build());
+ TestProposalBuilder()
+ .height(1)
+ .createdTime(iroha::time::now())
+ .transactions(txs)
+ .build());
prop_notifier_.get_subscriber().on_next(proposal);
torii::CommandSyncClient client2(client1);
@@ -232,7 +228,8 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
// check if stateless validation passed
for (size_t i = 0; i < TimesToriiBlocking; ++i) {
iroha::protocol::TxStatusRequest tx_request;
- tx_request.set_tx_hash(tx_hashes.at(i));
+ tx_request.set_tx_hash(
+ shared_model::crypto::toBinaryString(tx_hashes.at(i)));
iroha::protocol::ToriiResponse toriiResponse;
client2.Status(tx_request, toriiResponse);
@@ -242,13 +239,13 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
// create block from the all transactions but the last one
txs.pop_back();
- auto block = std::make_shared(
- TestBlockBuilder()
- .transactions(txs)
- .height(1)
- .createdTime(0)
- .prevHash(shared_model::crypto::Hash(std::string(32, '0')))
- .build());
+ auto block =
+ clone(TestBlockBuilder()
+ .transactions(txs)
+ .height(1)
+ .createdTime(0)
+ .prevHash(shared_model::crypto::Hash(std::string(32, '0')))
+ .build());
// create commit from block notifier's observable
rxcpp::subjects::subject>
@@ -257,13 +254,14 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
// invoke on next of commit_notifier by sending new block to commit
commit_notifier_.get_subscriber().on_next(commit);
- block_notifier_.get_subscriber().on_next(block);
+ block_notifier_.get_subscriber().on_next(std::move(block));
auto client3 = client2;
// check if all transactions but the last one passed stateful validation
for (size_t i = 0; i < TimesToriiBlocking - 1; ++i) {
iroha::protocol::TxStatusRequest tx_request;
- tx_request.set_tx_hash(tx_hashes.at(i));
+ tx_request.set_tx_hash(
+ shared_model::crypto::toBinaryString(tx_hashes.at(i)));
iroha::protocol::ToriiResponse toriiResponse;
client3.Status(tx_request, toriiResponse);
@@ -278,7 +276,8 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
// check if all transactions but the last have committed state
for (size_t i = 0; i < TimesToriiBlocking - 1; ++i) {
iroha::protocol::TxStatusRequest tx_request;
- tx_request.set_tx_hash(tx_hashes.at(i));
+ tx_request.set_tx_hash(
+ shared_model::crypto::toBinaryString(tx_hashes.at(i)));
iroha::protocol::ToriiResponse toriiResponse;
client4.Status(tx_request, toriiResponse);
@@ -288,7 +287,8 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
torii::CommandSyncClient client5(client4);
// check if the last transaction from txs has failed stateful validation
iroha::protocol::TxStatusRequest last_tx_request;
- last_tx_request.set_tx_hash(tx_hashes.at(TimesToriiBlocking - 1));
+ last_tx_request.set_tx_hash(shared_model::crypto::toBinaryString(
+ tx_hashes.at(TimesToriiBlocking - 1)));
iroha::protocol::ToriiResponse stful_invalid_response;
client5.Status(last_tx_request, stful_invalid_response);
ASSERT_EQ(stful_invalid_response.tx_status(),
@@ -302,19 +302,13 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
*/
TEST_F(ToriiServiceTest, CheckHash) {
// given
- std::vector tx_hashes;
+ std::vector tx_hashes;
const int tx_num = 10;
- iroha::model::converters::PbTransactionFactory tx_factory;
-
// create transactions, but do not send them
for (size_t i = 0; i < tx_num; ++i) {
- auto new_tx = iroha::protocol::Transaction();
- auto payload = new_tx.mutable_payload();
- payload->set_tx_counter(i);
- auto tx = tx_factory.deserialize(new_tx);
-
- tx_hashes.push_back(iroha::hash(*tx).to_string());
+ auto tx = TestTransactionBuilder().txCounter(i).build();
+ tx_hashes.push_back(tx.hash());
}
auto client = torii::CommandSyncClient(Ip, Port);
@@ -322,12 +316,13 @@ TEST_F(ToriiServiceTest, CheckHash) {
// get statuses of transactions
for (auto &hash : tx_hashes) {
iroha::protocol::TxStatusRequest tx_request;
- tx_request.set_tx_hash(hash);
+ tx_request.set_tx_hash(shared_model::crypto::toBinaryString(hash));
iroha::protocol::ToriiResponse toriiResponse;
// when
client.Status(tx_request, toriiResponse);
// then
- ASSERT_EQ(toriiResponse.tx_hash(), hash);
+ ASSERT_EQ(toriiResponse.tx_hash(),
+ shared_model::crypto::toBinaryString(hash));
}
}
@@ -341,13 +336,12 @@ TEST_F(ToriiServiceTest, CheckHash) {
TEST_F(ToriiServiceTest, StreamingFullPipelineTest) {
using namespace shared_model;
- iroha::model::converters::PbTransactionFactory tx_factory;
auto client = torii::CommandSyncClient(Ip, Port);
- auto new_tx = iroha::protocol::Transaction();
- auto payload = new_tx.mutable_payload();
- payload->set_tx_counter(1);
- payload->set_creator_account_id("accountA");
+ auto new_tx = TestTransactionBuilder()
+ .creatorAccountId("accountA")
+ .txCounter(1)
+ .build();
auto iroha_tx = proto::TransactionBuilder()
.txCounter(1)
@@ -369,7 +363,7 @@ TEST_F(ToriiServiceTest, StreamingFullPipelineTest) {
client.StatusStream(tx_request, torii_response);
});
- client.Torii(new_tx);
+ client.Torii(new_tx.getTransport());
std::vector txs;
txs.push_back(iroha_tx);
@@ -381,14 +375,13 @@ TEST_F(ToriiServiceTest, StreamingFullPipelineTest) {
.build());
prop_notifier_.get_subscriber().on_next(proposal);
- auto block = std::make_shared(
- proto::BlockBuilder()
- .height(1)
- .createdTime(iroha::time::now())
- .transactions(txs)
- .prevHash(crypto::Hash(std::string(32, '0')))
- .build()
- .signAndAddSignature(keypair));
+ auto block = clone(proto::BlockBuilder()
+ .height(1)
+ .createdTime(iroha::time::now())
+ .transactions(txs)
+ .prevHash(crypto::Hash(std::string(32, '0')))
+ .build()
+ .signAndAddSignature(keypair));
// create commit from block notifier's observable
rxcpp::subjects::subject>
@@ -397,7 +390,7 @@ TEST_F(ToriiServiceTest, StreamingFullPipelineTest) {
// invoke on next of commit_notifier by sending new block to commit
commit_notifier_.get_subscriber().on_next(commit);
- block_notifier_.get_subscriber().on_next(block);
+ block_notifier_.get_subscriber().on_next(std::move(block));
block_notifier_.get_subscriber().on_completed();
t.join();
diff --git a/test/module/shared_model/builders/protobuf/test_query_response_builder.hpp b/test/module/shared_model/builders/protobuf/test_query_response_builder.hpp
index f904a80f93..8d1b03d8fe 100644
--- a/test/module/shared_model/builders/protobuf/test_query_response_builder.hpp
+++ b/test/module/shared_model/builders/protobuf/test_query_response_builder.hpp
@@ -26,7 +26,6 @@
*/
using TestQueryResponseBuilder =
shared_model::proto::TemplateQueryResponseBuilder<
- (1 << shared_model::proto::TemplateQueryResponseBuilder<>::total) - 1,
- shared_model::proto::QueryResponse>;
+ (1 << shared_model::proto::TemplateQueryResponseBuilder<>::total) - 1>;
#endif // IROHA_TEST_QUERY_RESPONSE_BUILDER_HPP
From 50255f14101ab07e1517b869e0a75a67994d3e67 Mon Sep 17 00:00:00 2001
From: kamilsa
Date: Fri, 13 Apr 2018 11:18:09 +0300
Subject: [PATCH 014/110] Rework test/framework (#1215)
* Remove test block generator
Signed-off-by: kamilsa
---
test/framework/CMakeLists.txt | 12 ---
test/framework/test_block_generator.cpp | 101 ------------------
test/framework/test_block_generator.hpp | 34 ------
test/module/irohad/common/CMakeLists.txt | 2 +-
.../irohad/common/raw_block_loader_test.cpp | 17 ++-
5 files changed, 14 insertions(+), 152 deletions(-)
delete mode 100644 test/framework/test_block_generator.cpp
delete mode 100644 test/framework/test_block_generator.hpp
diff --git a/test/framework/CMakeLists.txt b/test/framework/CMakeLists.txt
index 9363c06aaa..aa55bdd915 100644
--- a/test/framework/CMakeLists.txt
+++ b/test/framework/CMakeLists.txt
@@ -20,13 +20,6 @@ target_link_libraries(test_subscriber_testing
rxcpp
)
-add_library(test_block_generator test_block_generator.cpp)
-target_link_libraries(test_block_generator
- model
- )
-
-target_include_directories(test_block_generator PUBLIC ${PROJECT_SOURCE_DIR}/test)
-
add_library(integration_framework
integration_framework/integration_test_framework.cpp
@@ -34,11 +27,6 @@ add_library(integration_framework
)
target_link_libraries(integration_framework
application
- raw_block_insertion
- keys_manager
- model_generators
- pb_model_converters
- tbb
)
target_include_directories(integration_framework PUBLIC ${PROJECT_SOURCE_DIR}/test)
diff --git a/test/framework/test_block_generator.cpp b/test/framework/test_block_generator.cpp
deleted file mode 100644
index 12081bc710..0000000000
--- a/test/framework/test_block_generator.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
- * http://soramitsu.co.jp
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "framework/test_block_generator.hpp"
-#include
-#include
-#include "model/commands/add_peer.hpp"
-#include "model/commands/create_account.hpp"
-#include "model/commands/create_asset.hpp"
-#include "model/commands/create_domain.hpp"
-#include "model/sha3_hash.hpp"
-#include "validators/permissions.hpp"
-
-using namespace iroha;
-using namespace iroha::model;
-using namespace shared_model::permissions;
-
-namespace framework {
- namespace generator {
- Transaction getAddPeerTransaction(uint64_t create_time,
- std::string address) {
- Transaction transaction;
- transaction.created_ts = create_time;
- Signature sign{};
- transaction.signatures = {sign};
-
- auto add_peer = std::make_shared();
- add_peer->peer.address = address;
- add_peer->peer.pubkey = {};
-
- transaction.commands = {add_peer};
- return transaction;
- }
-
- Transaction getTestCreateTransaction(uint64_t create_time) {
- Transaction transaction;
- transaction.created_ts = create_time;
- Signature sign{};
- transaction.signatures = {sign};
-
- auto create_role = std::make_shared("user", role_perm_group);
-
- auto create_domain = std::make_shared();
- create_domain->domain_id = "test";
- create_domain->user_default_role = "user";
-
- auto create_asset = std::make_shared();
- create_asset->domain_id = "test";
- create_asset->asset_name = "coin";
- create_asset->precision = 2;
-
- auto create_admin = std::make_shared();
- create_admin->domain_id = "test";
- create_admin->account_name = "admin";
-
- auto create_acc = std::make_shared();
- create_acc->domain_id = "test";
- create_acc->account_name = "test";
-
- transaction.commands = {
- create_domain, create_asset, create_admin, create_acc};
- return transaction;
- }
-
- Block generateBlock() {
- Block block;
- block.created_ts = 100500;
- block.height = 1;
- std::fill(block.prev_hash.begin(), block.prev_hash.end(), 0);
- block.txs_number = 4;
-
- auto start_port = 10001u;
- for (size_t i = start_port; i < start_port + block.txs_number; ++i) {
- block.transactions.push_back(getAddPeerTransaction(
- block.created_ts, "0.0.0.0:" + std::to_string(i)));
- }
-
- block.transactions.push_back(getTestCreateTransaction(block.created_ts));
- block.txs_number++;
-
- Signature sign{};
- block.sigs = {sign};
- block.hash = hash(block);
- return block;
- }
- } // namespace generator
-} // namespace framework
diff --git a/test/framework/test_block_generator.hpp b/test/framework/test_block_generator.hpp
deleted file mode 100644
index c3ecc46266..0000000000
--- a/test/framework/test_block_generator.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
- * http://soramitsu.co.jp
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IROHA_TEST_BLOCK_GENERATOR_HPP
-#define IROHA_TEST_BLOCK_GENERATOR_HPP
-
-#include "model/block.hpp"
-#include "model/transaction.hpp"
-
-namespace framework {
- namespace generator {
- iroha::model::Transaction getAddPeerTransaction(uint64_t create_time,
- std::string address);
-
- iroha::model::Transaction getTestCreateTransaction(uint64_t create_time);
-
- iroha::model::Block generateBlock();
- } // namespace generator
-} // namespace framework
-#endif // IROHA_TEST_BLOCK_GENERATOR_HPP
diff --git a/test/module/irohad/common/CMakeLists.txt b/test/module/irohad/common/CMakeLists.txt
index 685320ae24..56dea9f068 100644
--- a/test/module/irohad/common/CMakeLists.txt
+++ b/test/module/irohad/common/CMakeLists.txt
@@ -6,7 +6,7 @@ target_link_libraries(blob_converter_test
AddTest(block_insertion_test raw_block_loader_test.cpp)
target_link_libraries(block_insertion_test
json_model_converters
- test_block_generator
raw_block_insertion
+ shared_model_cryptography_model
logger
)
diff --git a/test/module/irohad/common/raw_block_loader_test.cpp b/test/module/irohad/common/raw_block_loader_test.cpp
index 20906b3eef..da4e9bba7b 100644
--- a/test/module/irohad/common/raw_block_loader_test.cpp
+++ b/test/module/irohad/common/raw_block_loader_test.cpp
@@ -18,15 +18,23 @@
#include "main/raw_block_loader.hpp"
#include
-#include "framework/test_block_generator.hpp"
#include "model/converters/json_block_factory.hpp"
#include "model/converters/json_common.hpp"
#include "model/converters/pb_command_factory.hpp"
+#include "module/shared_model/builders/protobuf/test_block_builder.hpp"
using namespace iroha::main;
using namespace iroha::model::converters;
using namespace iroha;
+auto generateBlock() {
+ return TestBlockBuilder()
+ .createdTime(100500)
+ .height(1)
+ .prevHash(shared_model::crypto::Hash(std::string(32, '0')))
+ .build();
+}
+
/**
* @given generated block
*
@@ -37,10 +45,11 @@ using namespace iroha;
*/
TEST(BlockLoaderTest, BlockLoaderWhenParseBlock) {
BlockLoader loader;
- auto block = framework::generator::generateBlock();
- auto doc = JsonBlockFactory().serialize(block);
+ auto block = generateBlock();
+ auto old_block = *std::unique_ptr(block.makeOldModel());
+ auto doc = JsonBlockFactory().serialize(old_block);
auto str = jsonToString(doc);
auto new_block = loader.parseBlock(str);
ASSERT_TRUE(new_block);
- ASSERT_EQ(block, *new_block);
+ ASSERT_EQ(old_block, *new_block);
}
From 4ae6a7885e864acc66e53f4490c2333f98904cd0 Mon Sep 17 00:00:00 2001
From: Alexey
Date: Sat, 24 Mar 2018 08:08:57 +0300
Subject: [PATCH 015/110] Feature/rework postgres block query with shared model
(#1110)
rework postgres_block_query with shared_model
Storage now uses the new JSON format provided by ptotobuf
Signed-off-by: Alexey Chernyshov
---
.../ametsuchi/impl/mutable_storage_impl.cpp | 4 +-
.../ametsuchi/impl/postgres_block_query.cpp | 104 +++++++++---------
.../ametsuchi/impl/postgres_block_query.hpp | 2 -
irohad/ametsuchi/impl/storage_impl.cpp | 15 ++-
irohad/ametsuchi/impl/storage_impl.hpp | 3 -
irohad/main/iroha_conf_loader.hpp | 1 +
.../irohad/ametsuchi/ametsuchi_test.cpp | 11 +-
.../irohad/ametsuchi/block_query_test.cpp | 14 +--
.../ametsuchi/block_query_transfer_test.cpp | 16 +--
9 files changed, 77 insertions(+), 93 deletions(-)
diff --git a/irohad/ametsuchi/impl/mutable_storage_impl.cpp b/irohad/ametsuchi/impl/mutable_storage_impl.cpp
index 45a34b4c20..f60b911be6 100644
--- a/irohad/ametsuchi/impl/mutable_storage_impl.cpp
+++ b/irohad/ametsuchi/impl/mutable_storage_impl.cpp
@@ -76,9 +76,7 @@ namespace iroha {
execute_transaction);
if (result) {
- block_store_.insert(std::make_pair(
- block.height(),
- clone(block)));
+ block_store_.insert(std::make_pair(block.height(), clone(block)));
block_index_->index(block);
top_hash_ = block.hash();
diff --git a/irohad/ametsuchi/impl/postgres_block_query.cpp b/irohad/ametsuchi/impl/postgres_block_query.cpp
index d17aa25c41..dd33cd42e9 100644
--- a/irohad/ametsuchi/impl/postgres_block_query.cpp
+++ b/irohad/ametsuchi/impl/postgres_block_query.cpp
@@ -16,9 +16,11 @@
*/
#include "ametsuchi/impl/postgres_block_query.hpp"
+
#include
#include
-#include "backend/protobuf/from_old_model.hpp"
+
+#include "converters/protobuf/json_proto_converter.hpp"
namespace iroha {
namespace ametsuchi {
@@ -38,26 +40,26 @@ namespace iroha {
if (height > to or count == 0) {
return rxcpp::observable<>::empty();
}
- return rxcpp::observable<>::range(height, to).flat_map([this](auto i) {
- // TODO IR-975 victordrobny 12.02.2018 convert directly to
- // shared_model::proto::Block after FlatFile will be reworked to new
- // model
- auto block = block_store_.get(i) | [](const auto &bytes) {
- return model::converters::stringToJson(bytesToString(bytes));
- } | [this](const auto &d) {
- return serializer_.deserialize(d);
- } | [](const auto &block_old) {
- return std::make_shared(
- shared_model::proto::from_old(block_old));
- };
- return rxcpp::observable<>::create(
- [block{std::move(block)}](auto s) {
+ return rxcpp::observable<>::range(height, to)
+ .flat_map([this](const auto &i) {
+ auto block = block_store_.get(i) | [](const auto &bytes) {
+ return shared_model::converters::protobuf::jsonToModel<
+ shared_model::proto::Block>(bytesToString(bytes));
+ };
+ if (not block) {
+ log_->error("error while converting from JSON");
+ }
+
+ return rxcpp::observable<>::create<
+ PostgresBlockQuery::wBlock>([block{std::move(block)}](
+ const auto &s) {
if (block) {
- s.on_next(block);
+ s.on_next(std::make_shared(
+ block.value()));
}
s.on_completed();
});
- });
+ });
}
rxcpp::observable PostgresBlockQuery::getBlocksFrom(
@@ -111,19 +113,20 @@ namespace iroha {
std::function PostgresBlockQuery::callback(
const rxcpp::subscriber &subscriber, uint64_t block_id) {
return [this, &subscriber, block_id](pqxx::result &result) {
- auto block = block_store_.get(block_id) | [this](auto bytes) {
- // TODO IR-975 victordrobny 12.02.2018 convert directly to
- // shared_model::proto::Block after FlatFile will be reworked to new
- // model
- return boost::optional(
- shared_model::proto::from_old(*serializer_.deserialize(
- *model::converters::stringToJson(bytesToString(bytes)))));
+ auto block = block_store_.get(block_id) | [this](const auto &bytes) {
+ return shared_model::converters::protobuf::jsonToModel<
+ shared_model::proto::Block>(bytesToString(bytes));
};
+ if (not block) {
+ log_->error("error while converting from JSON");
+ return;
+ }
+
boost::for_each(
result | boost::adaptors::transformed([](const auto &x) {
return x.at("index").template as();
}),
- [&](auto x) {
+ [&](const auto &x) {
subscriber.on_next(PostgresBlockQuery::wTransaction(
clone(*block->transactions().at(x))));
});
@@ -134,7 +137,7 @@ namespace iroha {
PostgresBlockQuery::getAccountTransactions(
const shared_model::interface::types::AccountIdType &account_id) {
return rxcpp::observable<>::create(
- [this, account_id](auto subscriber) {
+ [this, account_id](const auto &subscriber) {
auto block_ids = this->getBlockIds(account_id);
if (block_ids.empty()) {
subscriber.on_completed();
@@ -183,10 +186,10 @@ namespace iroha {
PostgresBlockQuery::getTransactions(
const std::vector &tx_hashes) {
return rxcpp::observable<>::create>(
- [this, tx_hashes](auto subscriber) {
+ [this, tx_hashes](const auto &subscriber) {
std::for_each(tx_hashes.begin(),
tx_hashes.end(),
- [that = this, &subscriber](auto tx_hash) {
+ [ that = this, &subscriber ](const auto &tx_hash) {
subscriber.on_next(that->getTxByHashSync(tx_hash));
});
subscriber.on_completed();
@@ -196,30 +199,27 @@ namespace iroha {
boost::optional
PostgresBlockQuery::getTxByHashSync(
const shared_model::crypto::Hash &hash) {
- return getBlockId(hash) |
- [this](auto blockId) { return block_store_.get(blockId); } |
- [](auto bytes) {
- // TODO IR-975 victordrobny 12.02.2018 convert directly to
- // shared_model::proto::Block after FlatFile will be reworked to new
- // model
- return model::converters::stringToJson(bytesToString(bytes));
- }
- | [&](const auto &json) { return serializer_.deserialize(json); } |
- [](const auto &block) {
- return boost::optional(
- shared_model::proto::from_old(block));
- }
- | [&](const auto &block) {
- boost::optional result;
- auto it =
- std::find_if(block.transactions().begin(),
- block.transactions().end(),
- [&hash](auto tx) { return tx->hash() == hash; });
- if (it != block.transactions().end()) {
- result = boost::optional(clone(**it));
- }
- return result;
- };
+ auto block = getBlockId(hash) | [this](const auto &block_id) {
+ return block_store_.get(block_id);
+ } | [](const auto &bytes) {
+ return shared_model::converters::protobuf::jsonToModel<
+ shared_model::proto::Block>(bytesToString(bytes));
+ };
+ if (not block) {
+ log_->error("error while converting from JSON");
+ return boost::none;
+ }
+
+ boost::optional result;
+ auto it =
+ std::find_if(block->transactions().begin(),
+ block->transactions().end(),
+ [&hash](const auto &tx) { return tx->hash() == hash; });
+ if (it != block->transactions().end()) {
+ result = boost::optional(
+ PostgresBlockQuery::wTransaction(clone(**it)));
+ }
+ return result;
}
} // namespace ametsuchi
diff --git a/irohad/ametsuchi/impl/postgres_block_query.hpp b/irohad/ametsuchi/impl/postgres_block_query.hpp
index 7343331e4a..dce3fe07ee 100644
--- a/irohad/ametsuchi/impl/postgres_block_query.hpp
+++ b/irohad/ametsuchi/impl/postgres_block_query.hpp
@@ -24,7 +24,6 @@
#include "ametsuchi/block_query.hpp"
#include "ametsuchi/impl/flat_file/flat_file.hpp"
#include "logger/logger.hpp"
-#include "model/converters/json_block_factory.hpp"
#include "postgres_wsv_common.hpp"
namespace iroha {
@@ -95,7 +94,6 @@ namespace iroha {
logger::Logger log_;
using ExecuteType = decltype(makeExecuteOptional(transaction_, log_));
ExecuteType execute_;
- model::converters::JsonBlockFactory serializer_;
};
} // namespace ametsuchi
} // namespace iroha
diff --git a/irohad/ametsuchi/impl/storage_impl.cpp b/irohad/ametsuchi/impl/storage_impl.cpp
index d020533ab3..4d1f8e4725 100644
--- a/irohad/ametsuchi/impl/storage_impl.cpp
+++ b/irohad/ametsuchi/impl/storage_impl.cpp
@@ -22,7 +22,8 @@
#include "ametsuchi/impl/postgres_block_query.hpp"
#include "ametsuchi/impl/postgres_wsv_query.hpp"
#include "ametsuchi/impl/temporary_wsv_impl.hpp"
-#include "model/converters/json_common.hpp"
+#include "converters/protobuf/json_proto_converter.hpp"
+#include "model/execution/command_executor_factory.hpp" // for CommandExecutorFactory
#include "postgres_ordering_service_persistent_state.hpp"
// TODO: 14-02-2018 Alexey Chernyshov remove this after relocation to
@@ -257,13 +258,11 @@ DROP TABLE IF EXISTS index_by_id_height_asset;
auto storage_ptr = std::move(mutableStorage); // get ownership of storage
auto storage = static_cast(storage_ptr.get());
for (const auto &block : storage->block_store_) {
- // TODO: rework to shared model converters once they are available
- // IR-1084 Nikita Alekseev
- auto old_block =
- *std::unique_ptr(block.second->makeOldModel());
- block_store_->add(block.first,
- stringToBytes(model::converters::jsonToString(
- serializer_.serialize(old_block))));
+ block_store_->add(
+ block.first,
+ stringToBytes(shared_model::converters::protobuf::modelToJson(
+ *std::static_pointer_cast(
+ block.second))));
}
storage->transaction_->exec("COMMIT;");
diff --git a/irohad/ametsuchi/impl/storage_impl.hpp b/irohad/ametsuchi/impl/storage_impl.hpp
index c9838da7fc..b44b6eb3c1 100644
--- a/irohad/ametsuchi/impl/storage_impl.hpp
+++ b/irohad/ametsuchi/impl/storage_impl.hpp
@@ -25,7 +25,6 @@
#include
#include
#include "logger/logger.hpp"
-#include "model/converters/json_block_factory.hpp"
namespace iroha {
namespace ametsuchi {
@@ -111,8 +110,6 @@ namespace iroha {
std::shared_ptr blocks_;
- model::converters::JsonBlockFactory serializer_;
-
// Allows multiple readers and a single writer
std::shared_timed_mutex rw_lock_;
diff --git a/irohad/main/iroha_conf_loader.hpp b/irohad/main/iroha_conf_loader.hpp
index 63982aa871..099137df3f 100644
--- a/irohad/main/iroha_conf_loader.hpp
+++ b/irohad/main/iroha_conf_loader.hpp
@@ -18,6 +18,7 @@
#ifndef IROHA_CONF_LOADER_HPP
#define IROHA_CONF_LOADER_HPP
+#include
#include
#include
#include
diff --git a/test/module/irohad/ametsuchi/ametsuchi_test.cpp b/test/module/irohad/ametsuchi/ametsuchi_test.cpp
index 3412c85601..6addddf223 100644
--- a/test/module/irohad/ametsuchi/ametsuchi_test.cpp
+++ b/test/module/irohad/ametsuchi/ametsuchi_test.cpp
@@ -734,13 +734,14 @@ TEST_F(AmetsuchiTest, FindTxByHashTest) {
auto tx2hash = txn2.hash();
auto tx3hash = shared_model::crypto::Hash("some garbage");
- auto tx1check = *blocks->getTxByHashSync(tx1hash);
+ auto tx1 = blocks->getTxByHashSync(tx1hash);
+ ASSERT_TRUE(tx1);
- auto tx1 = *blocks->getTxByHashSync(tx1hash);
- auto tx2 = *blocks->getTxByHashSync(tx2hash);
+ auto tx2 = blocks->getTxByHashSync(tx2hash);
+ ASSERT_TRUE(tx2);
- ASSERT_EQ(*tx1.operator->(), txn1);
- ASSERT_EQ(*tx2.operator->(), txn2);
+ ASSERT_EQ(**tx1, txn1);
+ ASSERT_EQ(**tx2, txn2);
ASSERT_EQ(blocks->getTxByHashSync(tx3hash), boost::none);
}
diff --git a/test/module/irohad/ametsuchi/block_query_test.cpp b/test/module/irohad/ametsuchi/block_query_test.cpp
index e0490c4043..ceb9c79877 100644
--- a/test/module/irohad/ametsuchi/block_query_test.cpp
+++ b/test/module/irohad/ametsuchi/block_query_test.cpp
@@ -19,7 +19,7 @@
#include
#include "ametsuchi/impl/postgres_block_index.hpp"
#include "ametsuchi/impl/postgres_block_query.hpp"
-#include "backend/protobuf/from_old_model.hpp"
+#include "converters/protobuf/json_proto_converter.hpp"
#include "framework/test_subscriber.hpp"
#include "module/irohad/ametsuchi/ametsuchi_fixture.hpp"
#include "module/shared_model/builders/protobuf/test_block_builder.hpp"
@@ -83,13 +83,9 @@ class BlockQueryTest : public AmetsuchiTest {
.build();
for (const auto &b : {block1, block2}) {
- // TODO IR-975 victordrobny 12.02.2018 convert from
- // shared_model::proto::Block after FlatFile will be reworked to new
- // model
- auto old_block = *std::unique_ptr(b.makeOldModel());
file->add(b.height(),
- iroha::stringToBytes(iroha::model::converters::jsonToString(
- iroha::model::converters::JsonBlockFactory().serialize(old_block))));
+ iroha::stringToBytes(
+ shared_model::converters::protobuf::modelToJson(b)));
index->index(b);
blocks_total++;
}
@@ -167,10 +163,10 @@ TEST_F(BlockQueryTest, GetTransactionsExistingTxHashes) {
static auto subs_cnt = 0;
subs_cnt++;
if (subs_cnt == 1) {
- EXPECT_TRUE(tx);
+ ASSERT_TRUE(tx);
EXPECT_EQ(tx_hashes[1], (*tx)->hash());
} else {
- EXPECT_TRUE(tx);
+ ASSERT_TRUE(tx);
EXPECT_EQ(tx_hashes[3], (*tx)->hash());
}
});
diff --git a/test/module/irohad/ametsuchi/block_query_transfer_test.cpp b/test/module/irohad/ametsuchi/block_query_transfer_test.cpp
index 7075af3004..2820721a70 100644
--- a/test/module/irohad/ametsuchi/block_query_transfer_test.cpp
+++ b/test/module/irohad/ametsuchi/block_query_transfer_test.cpp
@@ -18,7 +18,7 @@
#include
#include "ametsuchi/impl/postgres_block_index.hpp"
#include "ametsuchi/impl/postgres_block_query.hpp"
-#include "backend/protobuf/from_old_model.hpp"
+#include "converters/protobuf/json_proto_converter.hpp"
#include "framework/test_subscriber.hpp"
#include "module/irohad/ametsuchi/ametsuchi_fixture.hpp"
#include "module/shared_model/builders/protobuf/test_block_builder.hpp"
@@ -52,16 +52,10 @@ namespace iroha {
transaction->exec(init_);
}
- void insert(const shared_model::interface::Block &block) {
- // TODO IR-975 victordrobny 12.02.2018 convert from
- // shared_model::proto::Block after FlatFile will be reworked to new
- // model
- auto old_block =
- *std::unique_ptr(block.makeOldModel());
- file->add(
- block.height(),
- iroha::stringToBytes(model::converters::jsonToString(
- model::converters::JsonBlockFactory().serialize(old_block))));
+ void insert(const shared_model::proto::Block &block) {
+ file->add(block.height(),
+ iroha::stringToBytes(
+ shared_model::converters::protobuf::modelToJson(block)));
index->index(block);
}
From 056bf717dd31a52017c8a2434a2ad6328fcd1c43 Mon Sep 17 00:00:00 2001
From: Nikita Alekseev
Date: Tue, 27 Mar 2018 16:20:15 +0300
Subject: [PATCH 016/110] shared model raw block loader (#1135)
Rework raw_block_loader to shared model
Signed-off-by: Nikita Alekseev
---
irohad/main/impl/raw_block_loader.cpp | 26 ++++----
irohad/main/irohad.cpp | 4 +-
irohad/main/raw_block_loader.hpp | 24 +++----
.../irohad/common/raw_block_loader_test.cpp | 62 +++++++++----------
4 files changed, 61 insertions(+), 55 deletions(-)
diff --git a/irohad/main/impl/raw_block_loader.cpp b/irohad/main/impl/raw_block_loader.cpp
index 38f1600e98..a4c601c243 100644
--- a/irohad/main/impl/raw_block_loader.cpp
+++ b/irohad/main/impl/raw_block_loader.cpp
@@ -16,26 +16,30 @@
*/
#include "main/raw_block_loader.hpp"
+
#include
-#include
-#include "common/types.hpp"
-#include "model/converters/json_common.hpp"
+
+#include "converters/protobuf/json_proto_converter.hpp"
+#include "backend/protobuf/block.hpp"
namespace iroha {
namespace main {
+ using shared_model::converters::protobuf::jsonToProto;
+ using shared_model::interface::Block;
+
BlockLoader::BlockLoader() : log_(logger::log("BlockLoader")) {}
- boost::optional BlockLoader::parseBlock(std::string data) {
- auto document = model::converters::stringToJson(data);
- if (not document) {
- log_->error("Blob parsing failed");
- return boost::none;
- }
- return block_factory_.deserialize(document.value());
+ boost::optional> BlockLoader::parseBlock(
+ const std::string &data) {
+ return jsonToProto(data) | [](auto &&block) {
+ return boost::optional>(
+ std::make_shared(std::move(block)));
+ };
}
- boost::optional BlockLoader::loadFile(std::string path) {
+ boost::optional BlockLoader::loadFile(
+ const std::string &path) {
std::ifstream file(path);
if (not file) {
log_->error("Cannot read '" + path + "'");
diff --git a/irohad/main/irohad.cpp b/irohad/main/irohad.cpp
index 06f6936630..9fac29ac32 100644
--- a/irohad/main/irohad.cpp
+++ b/irohad/main/irohad.cpp
@@ -151,9 +151,9 @@ int main(int argc, char *argv[]) {
log->info("Block is parsed");
// Applying transactions from genesis block to iroha storage
- irohad.storage->insertBlock(shared_model::proto::from_old(block.value()));
+ irohad.storage->insertBlock(*block.value());
log->info("Genesis block inserted, number of transactions: {}",
- block.value().transactions.size());
+ block.value()->transactions().size());
}
// init pipeline components
diff --git a/irohad/main/raw_block_loader.hpp b/irohad/main/raw_block_loader.hpp
index e6500c4b04..c6fc3b0c66 100644
--- a/irohad/main/raw_block_loader.hpp
+++ b/irohad/main/raw_block_loader.hpp
@@ -19,13 +19,17 @@
#define IROHA_RAW_BLOCK_INSERTION_HPP
#include
-#include
#include
-#include
-#include "ametsuchi/storage.hpp"
+
+#include
+
#include "logger/logger.hpp"
-#include "model/block.hpp"
-#include "model/converters/json_block_factory.hpp"
+
+namespace shared_model {
+ namespace interface {
+ class Block;
+ }
+}
namespace iroha {
namespace main {
@@ -44,19 +48,17 @@ namespace iroha {
* @param data - raw presenetation of block
* @return object if operation done successfully, nullopt otherwise
*/
- boost::optional parseBlock(std::string data);
+ boost::optional>
+ parseBlock(const std::string &data);
/**
- * Additional method
* Loading file from target path
* @param path - target file
- * @return string with content or nullopt
+ * @return string with file content or nullopt
*/
- boost::optional loadFile(std::string path);
+ boost::optional loadFile(const std::string &path);
private:
- model::converters::JsonBlockFactory block_factory_;
-
logger::Logger log_;
};
diff --git a/test/module/irohad/common/raw_block_loader_test.cpp b/test/module/irohad/common/raw_block_loader_test.cpp
index da4e9bba7b..353c4e73d4 100644
--- a/test/module/irohad/common/raw_block_loader_test.cpp
+++ b/test/module/irohad/common/raw_block_loader_test.cpp
@@ -15,41 +15,41 @@
* limitations under the License.
*/
-#include "main/raw_block_loader.hpp"
#include
-#include "model/converters/json_block_factory.hpp"
-#include "model/converters/json_common.hpp"
-#include "model/converters/pb_command_factory.hpp"
-#include "module/shared_model/builders/protobuf/test_block_builder.hpp"
-
-using namespace iroha::main;
-using namespace iroha::model::converters;
-using namespace iroha;
-
-auto generateBlock() {
- return TestBlockBuilder()
- .createdTime(100500)
- .height(1)
- .prevHash(shared_model::crypto::Hash(std::string(32, '0')))
- .build();
-}
+#include "interfaces/iroha_internal/block.hpp"
+#include "main/raw_block_loader.hpp"
+
+using iroha::main::BlockLoader;
/**
- * @given generated block
- *
- * @when convert block to JSON
- * AND parseBlock() with BlockLoader API
- *
- * @then check that blocks are equal
+ * @given block in json format
+ * @when converting json to block using raw block loader
+ * @then check that the block is correct
*/
-TEST(BlockLoaderTest, BlockLoaderWhenParseBlock) {
+TEST(BlockLoaderTest, BlockLoaderJsonParsing) {
BlockLoader loader;
- auto block = generateBlock();
- auto old_block = *std::unique_ptr(block.makeOldModel());
- auto doc = JsonBlockFactory().serialize(old_block);
- auto str = jsonToString(doc);
- auto new_block = loader.parseBlock(str);
- ASSERT_TRUE(new_block);
- ASSERT_EQ(old_block, *new_block);
+ auto str =
+ R"({
+"payload": {
+ "transactions": [],
+ "height": 1,
+ "prev_block_hash": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=",
+ "created_time": 0
+ },
+"signatures": []
+})";
+
+ auto block = loader.parseBlock(str);
+
+
+
+ ASSERT_TRUE(block);
+ auto b = block.value();
+
+ ASSERT_EQ(b->transactions().size(), 0);
+ ASSERT_EQ(b->height(), 1);
+ ASSERT_EQ(b->createdTime(), 0);
+ ASSERT_TRUE(b->signatures().empty());
+ ASSERT_EQ(b->prevHash().hex(), "0101010101010101010101010101010101010101010101010101010101010101");
}
From 1c8d1d9dd98740c7658c062f175903c783786155 Mon Sep 17 00:00:00 2001
From: victordrobny
Date: Tue, 27 Mar 2018 18:56:33 +0300
Subject: [PATCH 017/110] Genesis block is now generated in new format (#1111)
* Genesis block now generates in new format
Signed-off-by: Victor Drobny
---
example/admin@test.priv | 2 +-
example/admin@test.pub | 2 +-
example/genesis.block | 231 ++++++++++++++++++++--------------------
example/node0.priv | 2 +-
example/node0.pub | 2 +-
example/test@test.priv | 2 +-
example/test@test.pub | 2 +-
iroha-cli/main.cpp | 6 +-
8 files changed, 128 insertions(+), 121 deletions(-)
diff --git a/example/admin@test.priv b/example/admin@test.priv
index ef24e1430d..87ff52af36 100644
--- a/example/admin@test.priv
+++ b/example/admin@test.priv
@@ -1 +1 @@
-1d7e0a32ee0affeb4d22acd73c2c6fb6bd58e266c8c2ce4fa0ffe3dd6a253ffb
\ No newline at end of file
+0f0ce16d2afbb8eca23c7d8c2724f0c257a800ee2bbd54688cec6b898e3f7e33
\ No newline at end of file
diff --git a/example/admin@test.pub b/example/admin@test.pub
index d80b9b299f..1dfda5428f 100644
--- a/example/admin@test.pub
+++ b/example/admin@test.pub
@@ -1 +1 @@
-407e57f50ca48969b08ba948171bb2435e035d82cec417e18e4a38f5fb113f83
\ No newline at end of file
+889f6b881e331be21487db77dcf32c5f8d3d5e8066e78d2feac4239fe91d416f
\ No newline at end of file
diff --git a/example/genesis.block b/example/genesis.block
index a8f665dd13..004f42d54a 100644
--- a/example/genesis.block
+++ b/example/genesis.block
@@ -1,116 +1,119 @@
{
- "signatures": [],
- "created_ts": 0,
- "hash": "ef9781aadf6d4d5ac8d01e14f7bbc805278ed9bb7200dafe8335bfc3a254e82b",
- "prev_hash": "0000000000000000000000000000000000000000000000000000000000000000",
- "height": 1,
- "txs_number": 1,
- "transactions": [
- {
- "signatures": [],
- "created_ts": 0,
- "creator_account_id": "",
- "tx_counter": 0,
- "commands": [
- {
- "command_type": "AddPeer",
- "peer": {
- "address": "localhost:10001",
- "peer_key": "292a8714694095edce6be799398ed5d6244cd7be37eb813106b217d850d261f2"
- }
- },
- {
- "command_type": "CreateRole",
- "role_name": "admin",
- "permissions": [
- "can_add_peer",
- "can_add_signatory",
- "can_create_account",
- "can_create_domain",
- "can_get_my_acc_detail",
- "can_get_all_acc_detail",
- "can_get_all_acc_ast",
- "can_get_all_acc_ast_txs",
- "can_get_all_acc_txs",
- "can_get_all_accounts",
- "can_get_all_signatories",
- "can_get_all_txs",
- "can_get_roles",
- "can_read_assets",
- "can_remove_signatory",
- "can_set_detail",
- "can_set_quorum"
- ]
- },
- {
- "command_type": "CreateRole",
- "role_name": "user",
- "permissions": [
- "can_add_signatory",
- "can_get_my_account",
- "can_get_my_acc_detail",
- "can_get_domain_acc_detail",
- "can_get_my_acc_ast",
- "can_get_my_acc_ast_txs",
- "can_get_my_acc_txs",
- "can_get_my_signatories",
- "can_get_my_txs",
- "can_grant_can_add_signatory",
- "can_grant_can_remove_signatory",
- "can_grant_can_set_detail",
- "can_grant_can_set_quorum",
- "can_grant_can_transfer",
- "can_receive",
- "can_remove_signatory",
- "can_set_quorum",
- "can_set_detail",
- "can_transfer"
- ]
- },
- {
- "command_type": "CreateRole",
- "role_name": "money_creator",
- "permissions": [
- "can_add_asset_qty",
- "can_create_asset",
- "can_receive",
- "can_transfer"
- ]
- },
- {
- "command_type": "CreateDomain",
- "domain_id": "test",
- "user_default_role": "user"
- },
- {
- "command_type": "CreateAsset",
- "asset_name": "coin",
- "domain_id": "test",
- "precision": 2
- },
- {
- "command_type": "CreateAccount",
- "account_name": "admin",
- "domain_id": "test",
- "pubkey": "407e57f50ca48969b08ba948171bb2435e035d82cec417e18e4a38f5fb113f83"
- },
- {
- "command_type": "CreateAccount",
- "account_name": "test",
- "domain_id": "test",
- "pubkey": "359f925e4eeecfdd6aa1abc0b79a6a121a5dd63bb612b603247ea4f8ad160156"
- },
- {
- "command_type": "AppendRole",
- "account_id": "admin@test",
- "role_name": "admin"
- },
- {
- "command_type": "AppendRole",
- "account_id": "admin@test",
- "role_name": "money_creator"
- }
- ]
- }
- ]
+ "payload":{
+ "transactions":[
+ {
+ "payload":{
+ "commands":[
+ {
+ "addPeer":{
+ "peer":{
+ "address":"localhost:10001",
+ "peerKey":"0E2icbV/5jQmrh3Jf2lSEEA3QR/PTztzncIX9F5fyZs="
+ }
+ }
+ },
+ {
+ "createRole":{
+ "roleName":"admin",
+ "permissions":[
+ "can_add_peer",
+ "can_add_signatory",
+ "can_create_account",
+ "can_create_domain",
+ "can_get_all_acc_ast",
+ "can_get_all_acc_ast_txs",
+ "can_get_all_acc_detail",
+ "can_get_all_acc_txs",
+ "can_get_all_accounts",
+ "can_get_all_signatories",
+ "can_get_all_txs",
+ "can_get_roles",
+ "can_read_assets",
+ "can_remove_signatory",
+ "can_set_quorum"
+ ]
+ }
+ },
+ {
+ "createRole":{
+ "roleName":"user",
+ "permissions":[
+ "can_add_signatory",
+ "can_get_my_acc_ast",
+ "can_get_my_acc_ast_txs",
+ "can_get_my_acc_detail",
+ "can_get_my_acc_txs",
+ "can_get_my_account",
+ "can_get_my_signatories",
+ "can_get_my_txs",
+ "can_grant_can_add_signatory",
+ "can_grant_can_remove_signatory",
+ "can_grant_can_set_detail",
+ "can_grant_can_set_quorum",
+ "can_grant_can_transfer",
+ "can_receive",
+ "can_remove_signatory",
+ "can_set_quorum",
+ "can_transfer"
+ ]
+ }
+ },
+ {
+ "createRole":{
+ "roleName":"money_creator",
+ "permissions":[
+ "can_add_asset_qty",
+ "can_create_asset",
+ "can_receive",
+ "can_transfer"
+ ]
+ }
+ },
+ {
+ "createDomain":{
+ "domainId":"test",
+ "defaultRole":"user"
+ }
+ },
+ {
+ "createAsset":{
+ "assetName":"coin",
+ "domainId":"test",
+ "precision":2
+ }
+ },
+ {
+ "createAccount":{
+ "accountName":"admin",
+ "domainId":"test",
+ "mainPubkey":"iJ9riB4zG+IUh9t33PMsX409XoBm540v6sQjn+kdQW8="
+ }
+ },
+ {
+ "createAccount":{
+ "accountName":"test",
+ "domainId":"test",
+ "mainPubkey":"3MfszkSPLhkKSBrsfKIe5S7aVG5mC0gg9JdtATIVcJc="
+ }
+ },
+ {
+ "appendRole":{
+ "accountId":"admin@test",
+ "roleName":"admin"
+ }
+ },
+ {
+ "appendRole":{
+ "accountId":"admin@test",
+ "roleName":"money_creator"
+ }
+ }
+ ]
+ }
+ }
+ ],
+ "txNumber":1,
+ "height":"1",
+ "prevBlockHash":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
+ }
}
diff --git a/example/node0.priv b/example/node0.priv
index 4ee1612c19..1362af9c39 100644
--- a/example/node0.priv
+++ b/example/node0.priv
@@ -1 +1 @@
-8316fe25fda2bb3964ae756251b5f1fe010fafe56443978d524dc6485548be76
\ No newline at end of file
+41209bd907789fd5a796ac6bdff908bac2f7abcf7a1d0b99a18290f285f6e965
\ No newline at end of file
diff --git a/example/node0.pub b/example/node0.pub
index e3e0793df3..bb7c1c9dcd 100644
--- a/example/node0.pub
+++ b/example/node0.pub
@@ -1 +1 @@
-292a8714694095edce6be799398ed5d6244cd7be37eb813106b217d850d261f2
\ No newline at end of file
+d04da271b57fe63426ae1dc97f6952104037411fcf4f3b739dc217f45e5fc99b
\ No newline at end of file
diff --git a/example/test@test.priv b/example/test@test.priv
index 7e6f039b91..f41898d68e 100644
--- a/example/test@test.priv
+++ b/example/test@test.priv
@@ -1 +1 @@
-4209ba343a92f4d086921a3f3c1eb26f50f2fece610ec3524058de79281564c2
\ No newline at end of file
+2e5b37fd881f260323dca4f0776e6e1e969bef7dab14673858f82663e7cd8556
\ No newline at end of file
diff --git a/example/test@test.pub b/example/test@test.pub
index 556317b45f..95419850c9 100644
--- a/example/test@test.pub
+++ b/example/test@test.pub
@@ -1 +1 @@
-359f925e4eeecfdd6aa1abc0b79a6a121a5dd63bb612b603247ea4f8ad160156
\ No newline at end of file
+dcc7ecce448f2e190a481aec7ca21ee52eda546e660b4820f4976d0132157097
\ No newline at end of file
diff --git a/iroha-cli/main.cpp b/iroha-cli/main.cpp
index cc9d533804..542e4b2302 100644
--- a/iroha-cli/main.cpp
+++ b/iroha-cli/main.cpp
@@ -20,8 +20,10 @@
#include
#include
+#include "backend/protobuf/from_old_model.hpp"
#include "client.hpp"
#include "common/assert_config.hpp"
+#include "converters/protobuf/json_proto_converter.hpp"
#include "crypto/keys_manager_impl.hpp"
#include "grpc_response_handler.hpp"
#include "interactive/interactive_cli.hpp"
@@ -94,7 +96,9 @@ int main(int argc, char *argv[]) {
JsonBlockFactory json_factory;
auto doc = json_factory.serialize(block);
std::ofstream output_file("genesis.block");
- output_file << jsonToString(doc);
+ output_file << shared_model::converters::protobuf::modelToJson(
+ shared_model::proto::from_old(block)
+ );
logger->info("File saved to genesis.block");
}
// Create new pub/priv key, register in Iroha Network
From f41eee8a859b9e10d0b20bb321e12afd9e684072 Mon Sep 17 00:00:00 2001
From: Alexey Chernyshov
Date: Thu, 29 Mar 2018 09:28:15 +0300
Subject: [PATCH 018/110] fix cmake
fix build and remove unused captures
fix unused includes
Signed-off-by: Alexey Chernyshov
---
iroha-cli/main.cpp | 2 --
irohad/ametsuchi/impl/postgres_block_query.cpp | 2 +-
irohad/ametsuchi/impl/storage_impl.cpp | 5 -----
irohad/main/CMakeLists.txt | 8 ++++----
test/integration/acceptance/CMakeLists.txt | 2 +-
test/module/irohad/common/CMakeLists.txt | 9 +++------
test/module/irohad/common/raw_block_loader_test.cpp | 2 --
7 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/iroha-cli/main.cpp b/iroha-cli/main.cpp
index 542e4b2302..c3e0bbfdcb 100644
--- a/iroha-cli/main.cpp
+++ b/iroha-cli/main.cpp
@@ -93,8 +93,6 @@ int main(int argc, char *argv[]) {
0, std::move(peers_address));
auto block = generator.generateGenesisBlock(0, {transaction});
// Convert to json
- JsonBlockFactory json_factory;
- auto doc = json_factory.serialize(block);
std::ofstream output_file("genesis.block");
output_file << shared_model::converters::protobuf::modelToJson(
shared_model::proto::from_old(block)
diff --git a/irohad/ametsuchi/impl/postgres_block_query.cpp b/irohad/ametsuchi/impl/postgres_block_query.cpp
index dd33cd42e9..7477048ce1 100644
--- a/irohad/ametsuchi/impl/postgres_block_query.cpp
+++ b/irohad/ametsuchi/impl/postgres_block_query.cpp
@@ -113,7 +113,7 @@ namespace iroha {
std::function PostgresBlockQuery::callback(
const rxcpp::subscriber &subscriber, uint64_t block_id) {
return [this, &subscriber, block_id](pqxx::result &result) {
- auto block = block_store_.get(block_id) | [this](const auto &bytes) {
+ auto block = block_store_.get(block_id) | [](const auto &bytes) {
return shared_model::converters::protobuf::jsonToModel<
shared_model::proto::Block>(bytesToString(bytes));
};
diff --git a/irohad/ametsuchi/impl/storage_impl.cpp b/irohad/ametsuchi/impl/storage_impl.cpp
index 4d1f8e4725..150c30f948 100644
--- a/irohad/ametsuchi/impl/storage_impl.cpp
+++ b/irohad/ametsuchi/impl/storage_impl.cpp
@@ -23,13 +23,8 @@
#include "ametsuchi/impl/postgres_wsv_query.hpp"
#include "ametsuchi/impl/temporary_wsv_impl.hpp"
#include "converters/protobuf/json_proto_converter.hpp"
-#include "model/execution/command_executor_factory.hpp" // for CommandExecutorFactory
#include "postgres_ordering_service_persistent_state.hpp"
-// TODO: 14-02-2018 Alexey Chernyshov remove this after relocation to
-// shared_model https://soramitsu.atlassian.net/browse/IR-887
-#include "backend/protobuf/from_old_model.hpp"
-
namespace iroha {
namespace ametsuchi {
diff --git a/irohad/main/CMakeLists.txt b/irohad/main/CMakeLists.txt
index 39d1427740..8f071832e5 100644
--- a/irohad/main/CMakeLists.txt
+++ b/irohad/main/CMakeLists.txt
@@ -24,9 +24,9 @@ target_link_libraries(server_runner
boost # iroha::expected::Result
)
-add_library(raw_block_insertion impl/raw_block_loader.cpp)
-target_link_libraries(raw_block_insertion
- json_model_converters
+add_library(raw_block_loader impl/raw_block_loader.cpp)
+target_link_libraries(raw_block_loader
+ model_interfaces
)
add_library(application
@@ -57,7 +57,7 @@ target_link_libraries(application
add_executable(irohad irohad.cpp)
target_link_libraries(irohad
application
- raw_block_insertion
+ raw_block_loader
gflags
rapidjson
keys_manager
diff --git a/test/integration/acceptance/CMakeLists.txt b/test/integration/acceptance/CMakeLists.txt
index e73ab3769e..588066356f 100644
--- a/test/integration/acceptance/CMakeLists.txt
+++ b/test/integration/acceptance/CMakeLists.txt
@@ -18,7 +18,7 @@
addtest(tx_acceptance_test tx_acceptance_test.cpp)
target_link_libraries(tx_acceptance_test
application
- raw_block_insertion
+ raw_block_loader
model_generators
integration_framework
shared_model_stateless_validation
diff --git a/test/module/irohad/common/CMakeLists.txt b/test/module/irohad/common/CMakeLists.txt
index 56dea9f068..879ed80660 100644
--- a/test/module/irohad/common/CMakeLists.txt
+++ b/test/module/irohad/common/CMakeLists.txt
@@ -3,10 +3,7 @@ target_link_libraries(blob_converter_test
common
)
-AddTest(block_insertion_test raw_block_loader_test.cpp)
-target_link_libraries(block_insertion_test
- json_model_converters
- raw_block_insertion
- shared_model_cryptography_model
- logger
+AddTest(raw_block_loader_test raw_block_loader_test.cpp)
+target_link_libraries(raw_block_loader_test
+ raw_block_loader
)
diff --git a/test/module/irohad/common/raw_block_loader_test.cpp b/test/module/irohad/common/raw_block_loader_test.cpp
index 353c4e73d4..62b23a7a5e 100644
--- a/test/module/irohad/common/raw_block_loader_test.cpp
+++ b/test/module/irohad/common/raw_block_loader_test.cpp
@@ -42,8 +42,6 @@ TEST(BlockLoaderTest, BlockLoaderJsonParsing) {
auto block = loader.parseBlock(str);
-
-
ASSERT_TRUE(block);
auto b = block.value();
From d4917932014a8a9708fe453ea4aa9054676a0b1c Mon Sep 17 00:00:00 2001
From: Dumitru
Date: Mon, 9 Apr 2018 15:03:55 +0300
Subject: [PATCH 019/110] Shared model/new block loader (#1164)
* Block loader impl
Signed-off-by: Dumitru
Block loader service
Signed-off-by: Dumitru
New block loader
Signed-off-by: Dumitru
* Fix block loader test
Signed-off-by: Dumitru
* Remove unused imports, clang-format, remove unused variables in lambda closure
Signed-off-by: Dumitru
* Remove unused imports
Signed-off-by: Dumitru
* Static to dynamic pointer cast
Signed-off-by: Dumitru
---
irohad/network/impl/block_loader_impl.cpp | 32 +++++++------------
irohad/network/impl/block_loader_impl.hpp | 11 ++++---
irohad/network/impl/block_loader_service.cpp | 29 +++++++----------
.../irohad/network/block_loader_test.cpp | 2 +-
4 files changed, 31 insertions(+), 43 deletions(-)
diff --git a/irohad/network/impl/block_loader_impl.cpp b/irohad/network/impl/block_loader_impl.cpp
index 01670afb0c..6557b7986a 100644
--- a/irohad/network/impl/block_loader_impl.cpp
+++ b/irohad/network/impl/block_loader_impl.cpp
@@ -17,8 +17,6 @@
#include "network/impl/block_loader_impl.hpp"
-#include
-
#include
#include "backend/protobuf/block.hpp"
@@ -43,7 +41,6 @@ BlockLoaderImpl::BlockLoaderImpl(
const char *kPeerNotFound = "Cannot find peer";
const char *kTopBlockRetrieveFail = "Failed to retrieve top block";
-const char *kInvalidBlockSignatures = "Block signatures are invalid";
const char *kPeerRetrieveFail = "Failed to retrieve peers";
const char *kPeerFindFail = "Failed to find requested peer";
@@ -51,14 +48,11 @@ rxcpp::observable> BlockLoaderImpl::retrieveBlocks(
const PublicKey &peer_pubkey) {
return rxcpp::observable<>::create>(
[this, peer_pubkey](auto subscriber) {
- boost::optional top_block;
+ boost::optional> top_block;
block_query_->getTopBlocks(1)
.subscribe_on(rxcpp::observe_on_new_thread())
.as_blocking()
- .subscribe([&top_block](auto block) {
- top_block =
- *std::unique_ptr(block->makeOldModel());
- });
+ .subscribe([&top_block](auto block) { top_block = block; });
if (not top_block) {
log_->error(kTopBlockRetrieveFail);
subscriber.on_completed();
@@ -77,10 +71,10 @@ rxcpp::observable