diff --git a/irohad/ametsuchi/impl/temporary_wsv_impl.cpp b/irohad/ametsuchi/impl/temporary_wsv_impl.cpp index 48ebc2e436..bd0d1764d8 100644 --- a/irohad/ametsuchi/impl/temporary_wsv_impl.cpp +++ b/irohad/ametsuchi/impl/temporary_wsv_impl.cpp @@ -54,22 +54,25 @@ namespace iroha { soci::use(boost::size(keys_range), "signatures_count"), soci::use(transaction.creatorAccountId(), "account_id"); } catch (const std::exception &e) { - log_->error(e.what()); - return expected::makeError(validation::CommandError{ - "signatures validation", - (boost::format("database error: %s") % e.what()).str(), - false}); + log_->error( + "Transaction %s failed signatures validation with db error: %s", + transaction.toString(), + e.what()); + // TODO [IR-1816] Akvinikym 29.10.18: substitute error code magic number + // with named constant + return expected::makeError( + validation::CommandError{"signatures validation", 1, false}); } if (signatories_valid and *signatories_valid) { return {}; } else { - return expected::makeError(validation::CommandError{ - "signatures validation", - "possible reasons: no account, number of signatures is less than " - "account quorum, signatures are not a subset of account " - "signatories", - false}); + log_->error("Transaction %s failed signatures validation", + transaction.toString()); + // TODO [IR-1816] Akvinikym 29.10.18: substitute error code magic number + // with named constant + return expected::makeError( + validation::CommandError{"signatures validation", 2, false}); } } @@ -101,7 +104,7 @@ namespace iroha { .match([](expected::Value &) { return true; }, [i, &cmd_error](expected::Error &error) { cmd_error = {error.error.command_name, - error.error.toString(), + error.error.error_code, true, i}; return false; diff --git a/irohad/torii/processor/impl/transaction_processor_impl.cpp b/irohad/torii/processor/impl/transaction_processor_impl.cpp index 9ba2b6138f..091cde2e09 100644 --- a/irohad/torii/processor/impl/transaction_processor_impl.cpp +++ b/irohad/torii/processor/impl/transaction_processor_impl.cpp @@ -25,16 +25,16 @@ namespace iroha { if (not tx_error.first.tx_passed_initial_validation) { return (boost::format("Stateful validation error: transaction %s " "did not pass initial verification: " - "checking '%s', error message '%s'") + "checking '%s', error code '%d'") % tx_error.second.hex() % tx_error.first.name - % tx_error.first.error) + % tx_error.first.error_code) .str(); } return (boost::format("Stateful validation error in transaction %s: " "command '%s' with index '%d' did not pass " - "verification with error '%s'") + "verification with error code '%d'") % tx_error.second.hex() % tx_error.first.name - % tx_error.first.index % tx_error.first.error) + % tx_error.first.index % tx_error.first.error_code) .str(); } } // namespace diff --git a/irohad/validation/impl/stateful_validator_impl.cpp b/irohad/validation/impl/stateful_validator_impl.cpp index c707bea940..c5def674e2 100644 --- a/irohad/validation/impl/stateful_validator_impl.cpp +++ b/irohad/validation/impl/stateful_validator_impl.cpp @@ -24,7 +24,7 @@ namespace iroha { * @param temporary_wsv to apply commands on * @param transactions_errors_log to write errors to * @param tx to be checked - * @return empty result, if check is succesfull, command error otherwise + * @return empty result, if check is successful, command error otherwise */ static bool checkTransactions( ametsuchi::TemporaryWsv &temporary_wsv, diff --git a/irohad/validation/stateful_validator_common.hpp b/irohad/validation/stateful_validator_common.hpp index e03b44ec2e..70acb9a14d 100644 --- a/irohad/validation/stateful_validator_common.hpp +++ b/irohad/validation/stateful_validator_common.hpp @@ -26,8 +26,8 @@ namespace iroha { /// Name of the failed command std::string name; - /// Error, with which the command failed - std::string error; + /// Error code, with which the command failed + uint32_t error_code; /// Shows, if transaction has passed initial validation bool tx_passed_initial_validation; diff --git a/test/module/iroha-cli/client_test.cpp b/test/module/iroha-cli/client_test.cpp index bd46fed4e2..9b5c7551f5 100644 --- a/test/module/iroha-cli/client_test.cpp +++ b/test/module/iroha-cli/client_test.cpp @@ -299,12 +299,12 @@ TEST_F(ClientServerTest, SendTxWhenStatefulInvalid) { std::make_pair(verified_proposal, iroha::validation::TransactionsErrors{std::make_pair( iroha::validation::CommandError{ - "CommandName", "CommandError", true, 2}, + "CommandName", 2, true, 2}, tx.hash())}))); auto stringified_error = "Stateful validation error in transaction " + tx.hash().hex() + ": command 'CommandName' with " "index '2' did not pass verification with " - "error 'CommandError'"; + "error code '2'"; auto getAnswer = [&]() { return client.getTxStatus(shared_model::crypto::toBinaryString(tx.hash())) diff --git a/test/module/irohad/simulator/simulator_test.cpp b/test/module/irohad/simulator/simulator_test.cpp index be15b16a8e..f4cad05311 100644 --- a/test/module/irohad/simulator/simulator_test.cpp +++ b/test/module/irohad/simulator/simulator_test.cpp @@ -286,9 +286,9 @@ TEST_F(SimulatorTest, RightNumberOfFailedTxs) { .transactions(std::vector{tx}) .build()); auto tx_errors = iroha::validation::TransactionsErrors{ - std::make_pair(validation::CommandError{"SomeCommand", "SomeError", true}, + std::make_pair(validation::CommandError{"SomeCommand", 1, true}, shared_model::crypto::Hash(std::string(32, '0'))), - std::make_pair(validation::CommandError{"SomeCommand", "SomeError", true}, + std::make_pair(validation::CommandError{"SomeCommand", 1, true}, shared_model::crypto::Hash(std::string(32, '0')))}; shared_model::proto::Block block = makeBlock(proposal->height() - 1); diff --git a/test/module/irohad/torii/processor/transaction_processor_test.cpp b/test/module/irohad/torii/processor/transaction_processor_test.cpp index 735ac1dac0..3e30443b61 100644 --- a/test/module/irohad/torii/processor/transaction_processor_test.cpp +++ b/test/module/irohad/torii/processor/transaction_processor_test.cpp @@ -382,8 +382,7 @@ TEST_F(TransactionProcessorTest, TransactionProcessorInvalidTxsTest) { auto txs_errors = iroha::validation::TransactionsErrors{}; for (size_t i = 0; i < invalid_txs.size(); ++i) { txs_errors.push_back(std::make_pair( - iroha::validation::CommandError{ - "SomeCommandName", "SomeCommandError", true, i}, + iroha::validation::CommandError{"SomeCommandName", 1, true, i}, invalid_txs[i].hash())); } verified_prop_notifier.get_subscriber().on_next( diff --git a/test/module/irohad/torii/torii_service_test.cpp b/test/module/irohad/torii/torii_service_test.cpp index 69639c3feb..95299e98eb 100644 --- a/test/module/irohad/torii/torii_service_test.cpp +++ b/test/module/irohad/torii/torii_service_test.cpp @@ -327,13 +327,12 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) { .build()); auto errors = iroha::validation::TransactionsErrors{std::make_pair( iroha::validation::CommandError{ - "FailedCommand", "stateful validation failed", true, 2}, + "FailedCommand", 2, true, 2}, failed_tx_hash)}; auto stringified_error = "Stateful validation error in transaction " + failed_tx_hash.hex() + ": " "command 'FailedCommand' with index '2' " - "did not pass verification with error 'stateful " - "validation failed'"; + "did not pass verification with error code '2'"; verified_prop_notifier_.get_subscriber().on_next( std::make_shared( std::make_pair(verified_proposal, errors))); diff --git a/test/module/irohad/validation/stateful_validator_test.cpp b/test/module/irohad/validation/stateful_validator_test.cpp index c4b438cad7..96811b079c 100644 --- a/test/module/irohad/validation/stateful_validator_test.cpp +++ b/test/module/irohad/validation/stateful_validator_test.cpp @@ -197,13 +197,14 @@ TEST_F(Validator, SomeTxsFail) { .build(); EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(invalid_tx)))) - .WillOnce(Return(iroha::expected::Error({}))); + .WillOnce(Return(iroha::expected::makeError(CommandError{"", 2, false}))); EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(valid_tx)))) .WillRepeatedly(Return(iroha::expected::Value({}))); auto verified_proposal_and_errors = sfv->validate(proposal, *temp_wsv_mock); ASSERT_EQ(verified_proposal_and_errors.first->transactions().size(), 2); ASSERT_EQ(verified_proposal_and_errors.second.size(), 1); + ASSERT_EQ(verified_proposal_and_errors.second[0].first.error_code, 2); } /** @@ -267,7 +268,8 @@ TEST_F(Validator, Batches) { EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(txs[2])))) .WillOnce(Return(iroha::expected::Value({}))); EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(txs[3])))) - .WillOnce(Return(iroha::expected::Error({}))); + .WillOnce( + Return(iroha::expected::makeError(CommandError({"", 2, false})))); EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(txs[5])))) .WillOnce(Return(iroha::expected::Value({}))); EXPECT_CALL(*temp_wsv_mock, apply(Eq(ByRef(txs[6])))) @@ -276,4 +278,5 @@ TEST_F(Validator, Batches) { auto verified_proposal_and_errors = sfv->validate(proposal, *temp_wsv_mock); ASSERT_EQ(verified_proposal_and_errors.first->transactions().size(), 5); ASSERT_EQ(verified_proposal_and_errors.second.size(), 1); + ASSERT_EQ(verified_proposal_and_errors.second[0].first.error_code, 2); }