From 22d3e4b9d6056b89efc9e615328b55bc3eb3780c Mon Sep 17 00:00:00 2001 From: dominious1 Date: Sun, 12 Nov 2023 01:36:48 +0100 Subject: [PATCH 01/15] Implement addition of new parameters to Iroha Core for enhanced message communication, with corresponding handling capabilities in Iroha CLI. Signed-off-by: dominious1 --- .../impl/interactive_transaction_cli.cpp | 6 ++++-- iroha-lib/examples/DomainAssetCreation.cpp | 2 +- iroha-lib/model/Tx.cpp | 12 ++++++++---- iroha-lib/model/Tx.hpp | 8 +++++--- iroha-lib/model/generators/CommandGenerator.cpp | 13 +++++++++++-- iroha-lib/model/generators/CommandGenerator.hpp | 6 ++++-- irohad/model/commands/add_asset_quantity.hpp | 9 +++++++-- irohad/model/commands/subtract_asset_quantity.hpp | 10 ++++++++-- .../model/converters/impl/json_command_factory.cpp | 7 +++++-- irohad/model/converters/impl/pb_command_factory.cpp | 2 +- irohad/model/generators/command_generator.hpp | 4 ++-- irohad/model/generators/impl/command_generator.cpp | 8 ++++---- irohad/model/impl/model_operators.cpp | 3 ++- .../commands/impl/proto_add_asset_quantity.cpp | 4 ++++ .../commands/impl/proto_subtract_asset_quantity.cpp | 4 ++++ .../protobuf/commands/proto_add_asset_quantity.hpp | 3 +++ .../commands/proto_subtract_asset_quantity.hpp | 3 +++ .../interfaces/commands/add_asset_quantity.hpp | 2 ++ .../interfaces/commands/impl/add_asset_quantity.cpp | 3 ++- .../commands/impl/subtract_asset_quantity.cpp | 3 ++- .../interfaces/commands/subtract_asset_quantity.hpp | 5 +++++ shared_model/schema/commands.proto | 2 ++ .../irohad/model/converters/json_commands_test.cpp | 2 ++ .../irohad/model/operators/model_operators_test.cpp | 2 ++ 24 files changed, 93 insertions(+), 30 deletions(-) diff --git a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp index cebdfd89a0b..716676c0560 100644 --- a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp +++ b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp @@ -325,7 +325,8 @@ namespace iroha_cli { std::vector params) { auto asset_id = params[0]; auto amount = params[1]; - return generator_.generateAddAssetQuantity(asset_id, amount); + auto title = params[2]; + return generator_.generateAddAssetQuantity(asset_id, amount, title); } std::shared_ptr @@ -405,7 +406,8 @@ namespace iroha_cli { std::vector params) { auto asset_id = params[0]; auto amount = params[1]; - return generator_.generateSubtractAssetQuantity(asset_id, amount); + auto title = params[2]; + return generator_.generateSubtractAssetQuantity(asset_id, amount, title); } std::shared_ptr diff --git a/iroha-lib/examples/DomainAssetCreation.cpp b/iroha-lib/examples/DomainAssetCreation.cpp index 1b7b92d0b25..9f9d66b4726 100755 --- a/iroha-lib/examples/DomainAssetCreation.cpp +++ b/iroha-lib/examples/DomainAssetCreation.cpp @@ -136,7 +136,7 @@ iroha::protocol::Transaction generateTransactionWhichAddsAssetQuantiti( return iroha_lib::Tx( account_name, keypair) - .addAssetQuantity(assetIdWithDomain, assetAmount) + .addAssetQuantity(assetIdWithDomain, assetAmount, "") .signAndAddSignature(); } diff --git a/iroha-lib/model/Tx.cpp b/iroha-lib/model/Tx.cpp index 416c4c11747..bbd2eee6605 100644 --- a/iroha-lib/model/Tx.cpp +++ b/iroha-lib/model/Tx.cpp @@ -20,11 +20,13 @@ void Tx::addCommand(const iroha::protocol::Command& command) Tx& Tx::addAssetQuantity( const std::string& asset_id, - const std::string& amount) + const std::string& amount, + const std::string& title) { auto cmd = cmd_generator_.generateAddAssetQuantity( asset_id, - amount); + amount, + title); addCommand(*cmd); return *this; } @@ -191,11 +193,13 @@ Tx& Tx::setAccountQuorum( Tx& Tx::subtractAssetQuantity( const std::string& asset_id, - const std::string& amount) + const std::string& amount, + const std::string& title) { auto cmd = cmd_generator_.generateSubtractAssetQuantity( asset_id, - amount); + amount, + title); addCommand(*cmd); return *this; } diff --git a/iroha-lib/model/Tx.hpp b/iroha-lib/model/Tx.hpp index 7e3b74cd5b3..7d2eceda521 100644 --- a/iroha-lib/model/Tx.hpp +++ b/iroha-lib/model/Tx.hpp @@ -33,8 +33,9 @@ class Tx { void addCommand(const iroha::protocol::Command& command); Tx& addAssetQuantity( - const std::string& account_id, - const std::string& role_name); + const std::string& asset_id, + const std::string& amount, + const std::string& title); Tx& addPeer( const std::string& address, const std::string& pubkey, @@ -83,7 +84,8 @@ class Tx { uint32_t quorum); Tx& subtractAssetQuantity( const std::string& asset_id, - const std::string& amount); + const std::string& amount, + const std::string& title); Tx& transferAsset( const std::string& account_id, const std::string& dest_account_id, diff --git a/iroha-lib/model/generators/CommandGenerator.cpp b/iroha-lib/model/generators/CommandGenerator.cpp index c1982b9bf07..d5598fdf68d 100644 --- a/iroha-lib/model/generators/CommandGenerator.cpp +++ b/iroha-lib/model/generators/CommandGenerator.cpp @@ -6,11 +6,15 @@ namespace iroha_lib { std::shared_ptr CommandGenerator::generateAddAssetQuantity( const std::string& asset_id, - const std::string& amount) + const std::string& amount, + const std::string& title) { AddAssetQuantity addAssetQuantity; addAssetQuantity.set_asset_id(asset_id); addAssetQuantity.set_amount(amount); + if (!title.empty()) { + addAssetQuantity.set_title(title); + } auto cmd = Command(); cmd.set_allocated_add_asset_quantity(new AddAssetQuantity(addAssetQuantity)); @@ -227,11 +231,16 @@ std::shared_ptr CommandGenerator::generateSetAccountQuorum( std::shared_ptr CommandGenerator::generateSubtractAssetQuantity( const std::string& asset_id, - const std::string& amount) + const std::string& amount, + const std::string& title) { SubtractAssetQuantity subtractAssetQuantity; subtractAssetQuantity.set_asset_id(asset_id); subtractAssetQuantity.set_amount(amount); + std::optional title_optional = title; + if (title_optional) { + subtractAssetQuantity.set_title(*title_optional); + } auto cmd = Command(); cmd.set_allocated_subtract_asset_quantity(new SubtractAssetQuantity(subtractAssetQuantity)); diff --git a/iroha-lib/model/generators/CommandGenerator.hpp b/iroha-lib/model/generators/CommandGenerator.hpp index 06948072839..93ed66cc633 100644 --- a/iroha-lib/model/generators/CommandGenerator.hpp +++ b/iroha-lib/model/generators/CommandGenerator.hpp @@ -20,7 +20,8 @@ class CommandGenerator { std::shared_ptr generateAddAssetQuantity( const std::string& asset_id, - const std::string& amount); + const std::string& amount, + const std::string& title); std::shared_ptr generateAddPeer( const std::string& address, const std::string& pubkey, @@ -67,7 +68,8 @@ class CommandGenerator { const std::string& account_id, uint32_t quorum); std::shared_ptr generateSubtractAssetQuantity( const std::string& asset_id, - const std::string& amount); + const std::string& amount, + const std::string& title); std::shared_ptr generateTransferAsset( const std::string& account_id, const std::string& dest_account_id, diff --git a/irohad/model/commands/add_asset_quantity.hpp b/irohad/model/commands/add_asset_quantity.hpp index 4e502370f55..f18011de5d3 100644 --- a/irohad/model/commands/add_asset_quantity.hpp +++ b/irohad/model/commands/add_asset_quantity.hpp @@ -27,12 +27,17 @@ namespace iroha { */ std::string amount; + /** + * Title + */ + std::string title; + bool operator==(const Command &command) const override; AddAssetQuantity() {} - AddAssetQuantity(const std::string &asset_id, const std::string &amount) - : asset_id(asset_id), amount(amount) {} + AddAssetQuantity(const std::string &asset_id, const std::string &amount, const std::string &title) + : asset_id(asset_id), amount(amount), title(title) {} }; } // namespace model } // namespace iroha diff --git a/irohad/model/commands/subtract_asset_quantity.hpp b/irohad/model/commands/subtract_asset_quantity.hpp index 86d44951267..71089356b70 100644 --- a/irohad/model/commands/subtract_asset_quantity.hpp +++ b/irohad/model/commands/subtract_asset_quantity.hpp @@ -26,13 +26,19 @@ namespace iroha { */ std::string amount; + /** + * Title + */ + std::string title; + bool operator==(const Command &command) const override; SubtractAssetQuantity() {} SubtractAssetQuantity(const std::string &asset_id, - const std::string &amount) - : asset_id(asset_id), amount(amount) {} + const std::string &amount, + const std::string &title) + : asset_id(asset_id), amount(amount), title(title) {} }; } // namespace model } // namespace iroha diff --git a/irohad/model/converters/impl/json_command_factory.cpp b/irohad/model/converters/impl/json_command_factory.cpp index c070df86bed..d46292b4485 100644 --- a/irohad/model/converters/impl/json_command_factory.cpp +++ b/irohad/model/converters/impl/json_command_factory.cpp @@ -113,6 +113,7 @@ namespace iroha { document.AddMember("command_type", "AddAssetQuantity", allocator); document.AddMember("asset_id", add_asset_quantity->asset_id, allocator); document.AddMember("amount", add_asset_quantity->amount, allocator); + document.AddMember("title", add_asset_quantity->title, allocator); return document; } @@ -122,7 +123,8 @@ namespace iroha { auto des = makeFieldDeserializer(document); return make_optional_ptr() | des.String(&AddAssetQuantity::asset_id, "asset_id") - | des.String(&AddAssetQuantity::amount, "amount") | toCommand; + | des.String(&AddAssetQuantity::amount, "amount") + | des.String(&AddAssetQuantity::title, "title") | toCommand; } // AddPeer @@ -520,7 +522,8 @@ namespace iroha { auto des = makeFieldDeserializer(document); return make_optional_ptr() | des.String(&SubtractAssetQuantity::asset_id, "asset_id") - | des.String(&SubtractAssetQuantity::amount, "amount") | toCommand; + | des.String(&SubtractAssetQuantity::amount, "amount") + | des.String(&SubtractAssetQuantity::title, "title") | toCommand; } // Abstract diff --git a/irohad/model/converters/impl/pb_command_factory.cpp b/irohad/model/converters/impl/pb_command_factory.cpp index 14d38a043da..00c97a0011c 100644 --- a/irohad/model/converters/impl/pb_command_factory.cpp +++ b/irohad/model/converters/impl/pb_command_factory.cpp @@ -200,7 +200,7 @@ namespace iroha { subtract_asset_quantity.asset_id = pb_subtract_asset_quantity.asset_id(); subtract_asset_quantity.amount = pb_subtract_asset_quantity.amount(); - + subtract_asset_quantity.title = pb_subtract_asset_quantity.title(); return subtract_asset_quantity; } diff --git a/irohad/model/generators/command_generator.hpp b/irohad/model/generators/command_generator.hpp index 0e9421a378d..9a4b87e615e 100644 --- a/irohad/model/generators/command_generator.hpp +++ b/irohad/model/generators/command_generator.hpp @@ -58,10 +58,10 @@ namespace iroha { const std::string &account_id, uint32_t quorum); std::shared_ptr generateAddAssetQuantity( - const std::string &asset_id, const std::string &amount); + const std::string &asset_id, const std::string &amount, const std::string &title); std::shared_ptr generateSubtractAssetQuantity( - const std::string &asset_id, const std::string &amount); + const std::string &asset_id, const std::string &amount, const std::string &title); /** * Generate transfer assets from source account_id to target account_id * @param src_account_id - source account identifier diff --git a/irohad/model/generators/impl/command_generator.cpp b/irohad/model/generators/impl/command_generator.cpp index 7218e6eacc9..78de2c7fe96 100644 --- a/irohad/model/generators/impl/command_generator.cpp +++ b/irohad/model/generators/impl/command_generator.cpp @@ -89,13 +89,13 @@ namespace iroha { } std::shared_ptr CommandGenerator::generateAddAssetQuantity( - const std::string &asset_id, const std::string &amount) { - return generateCommand(asset_id, amount); + const std::string &asset_id, const std::string &amount, const std::string &title) { + return generateCommand(asset_id, amount, title); } std::shared_ptr CommandGenerator::generateSubtractAssetQuantity( - const std::string &asset_id, const std::string &amount) { - return generateCommand(asset_id, amount); + const std::string &asset_id, const std::string &amount, const std::string &title) { + return generateCommand(asset_id, amount, title); } std::shared_ptr CommandGenerator::generateSetQuorum( diff --git a/irohad/model/impl/model_operators.cpp b/irohad/model/impl/model_operators.cpp index c756141f351..d21e4c007f6 100644 --- a/irohad/model/impl/model_operators.cpp +++ b/irohad/model/impl/model_operators.cpp @@ -100,7 +100,8 @@ namespace iroha { auto subtract_asset_quantity = static_cast(command); return subtract_asset_quantity.asset_id == asset_id - && subtract_asset_quantity.amount == amount; + && subtract_asset_quantity.amount == amount + && subtract_asset_quantity.title == title; } /* AddPeer */ diff --git a/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp b/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp index 24765852726..1154c0f2f0f 100644 --- a/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp +++ b/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp @@ -20,5 +20,9 @@ namespace shared_model { return amount_; } + const std::string &AddAssetQuantity::title() const { + return title_; + } + } // namespace proto } // namespace shared_model diff --git a/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp b/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp index 5b681154ee1..482cd08ea7b 100644 --- a/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp +++ b/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp @@ -22,5 +22,9 @@ namespace shared_model { return amount_; } + const std::string &SubtractAssetQuantity::title() const { + return title_; + } + } // namespace proto } // namespace shared_model diff --git a/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp b/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp index 55528756efe..5ab41ee4401 100644 --- a/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp +++ b/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp @@ -21,10 +21,13 @@ namespace shared_model { const interface::Amount &amount() const override; + const std::string &title() const override; + private: const iroha::protocol::AddAssetQuantity &add_asset_quantity_; const interface::Amount amount_; + const std::string title_; }; } // namespace proto } // namespace shared_model diff --git a/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp b/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp index d6f8c34ac78..f77d8e79062 100644 --- a/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp +++ b/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp @@ -22,10 +22,13 @@ namespace shared_model { const interface::Amount &amount() const override; + const std::string &title() const override; + private: const iroha::protocol::SubtractAssetQuantity &subtract_asset_quantity_; const interface::Amount amount_; + const std::string title_; }; } // namespace proto diff --git a/shared_model/interfaces/commands/add_asset_quantity.hpp b/shared_model/interfaces/commands/add_asset_quantity.hpp index a44c346812f..afb1682af58 100644 --- a/shared_model/interfaces/commands/add_asset_quantity.hpp +++ b/shared_model/interfaces/commands/add_asset_quantity.hpp @@ -28,6 +28,8 @@ namespace shared_model { */ virtual const Amount &amount() const = 0; + virtual const std::string &title() const = 0; + std::string toString() const override; bool operator==(const ModelType &rhs) const override; diff --git a/shared_model/interfaces/commands/impl/add_asset_quantity.cpp b/shared_model/interfaces/commands/impl/add_asset_quantity.cpp index 5fd562b8d7b..ea86ae3316e 100644 --- a/shared_model/interfaces/commands/impl/add_asset_quantity.cpp +++ b/shared_model/interfaces/commands/impl/add_asset_quantity.cpp @@ -13,11 +13,12 @@ namespace shared_model { .init("AddAssetQuantity") .appendNamed("asset_id", assetId()) .appendNamed("amount", amount()) + .appendNamed("title", title()) .finalize(); } bool AddAssetQuantity::operator==(const ModelType &rhs) const { - return assetId() == rhs.assetId() and amount() == rhs.amount(); + return assetId() == rhs.assetId() and amount() == rhs.amount() and title() == rhs.title(); } } // namespace interface diff --git a/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp b/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp index 1444bdf07cb..4c291950837 100644 --- a/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp +++ b/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp @@ -13,11 +13,12 @@ namespace shared_model { .init("SubtractAssetQuantity") .appendNamed("asset_id", assetId()) .appendNamed("amount", amount()) + .appendNamed("title", title()) .finalize(); } bool SubtractAssetQuantity::operator==(const ModelType &rhs) const { - return assetId() == rhs.assetId() and amount() == rhs.amount(); + return assetId() == rhs.assetId() and amount() == rhs.amount() and title() == rhs.title(); } } // namespace interface diff --git a/shared_model/interfaces/commands/subtract_asset_quantity.hpp b/shared_model/interfaces/commands/subtract_asset_quantity.hpp index e16b9fb4303..302f81e1638 100644 --- a/shared_model/interfaces/commands/subtract_asset_quantity.hpp +++ b/shared_model/interfaces/commands/subtract_asset_quantity.hpp @@ -28,6 +28,11 @@ namespace shared_model { */ virtual const Amount &amount() const = 0; + /** + * @return title + */ + virtual const std::string &title() const = 0; + std::string toString() const override; bool operator==(const ModelType &rhs) const override; diff --git a/shared_model/schema/commands.proto b/shared_model/schema/commands.proto index 320a523bbe1..be982b7adb7 100644 --- a/shared_model/schema/commands.proto +++ b/shared_model/schema/commands.proto @@ -13,6 +13,7 @@ import "primitive.proto"; message AddAssetQuantity { string asset_id = 1; string amount = 2; + optional string title = 3; } message AddPeer { @@ -97,6 +98,7 @@ message RevokePermission { message SubtractAssetQuantity { string asset_id = 1; string amount = 2; + optional string title = 3; } message CompareAndSetAccountDetail { diff --git a/test/module/irohad/model/converters/json_commands_test.cpp b/test/module/irohad/model/converters/json_commands_test.cpp index f1c87ad87fc..928295db746 100644 --- a/test/module/irohad/model/converters/json_commands_test.cpp +++ b/test/module/irohad/model/converters/json_commands_test.cpp @@ -71,6 +71,7 @@ TEST_F(JsonCommandTest, InvalidWhenUnknownCommandType) { "command_type": "Unknown", "account_id": "admin@test", "asset_id": "usd#test", + "title": "testtitle", "amount": { "int_part": -20, "frac_part": 0 @@ -95,6 +96,7 @@ TEST_F(JsonCommandTest, add_asset_quantity) { orig_command->amount = "1.50"; orig_command->asset_id = "23"; + orig_command->title = "testtitle"; auto json_command = factory.serializeAddAssetQuantity(orig_command); auto serial_command = factory.deserializeAddAssetQuantity(json_command); diff --git a/test/module/irohad/model/operators/model_operators_test.cpp b/test/module/irohad/model/operators/model_operators_test.cpp index 454936951cd..e88d052374d 100644 --- a/test/module/irohad/model/operators/model_operators_test.cpp +++ b/test/module/irohad/model/operators/model_operators_test.cpp @@ -48,6 +48,7 @@ AddAssetQuantity createAddAssetQuantity() { AddAssetQuantity aaq; aaq.amount = "10.10"; aaq.asset_id = "123"; + aaq.title = "testtitle"; return aaq; } @@ -66,6 +67,7 @@ SubtractAssetQuantity createSubtractAssetQuantity() { SubtractAssetQuantity saq; saq.amount = "10.10"; saq.asset_id = "ast"; + saq.title = "testtitle"; return saq; } From 451c3f56810c96beb930fe21755f48ef4fb96d27 Mon Sep 17 00:00:00 2001 From: dominious1 Date: Mon, 13 Nov 2023 01:12:33 +0100 Subject: [PATCH 02/15] Improve GTests in reference to param title Signed-off-by: dominious1 --- test/module/shared_model/command_mocks.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/module/shared_model/command_mocks.hpp b/test/module/shared_model/command_mocks.hpp index 000669c031c..ce452bd651f 100644 --- a/test/module/shared_model/command_mocks.hpp +++ b/test/module/shared_model/command_mocks.hpp @@ -42,6 +42,7 @@ namespace shared_model { : public shared_model::interface::AddAssetQuantity { MOCK_CONST_METHOD0(assetId, const types::AssetIdType &()); MOCK_CONST_METHOD0(amount, const Amount &()); + MOCK_CONST_METHOD0(title, const std::string &()); }; struct MockAddPeer : public shared_model::interface::AddPeer { @@ -140,6 +141,7 @@ namespace shared_model { : public shared_model::interface::SubtractAssetQuantity { MOCK_CONST_METHOD0(assetId, const types::AssetIdType &()); MOCK_CONST_METHOD0(amount, const Amount &()); + MOCK_CONST_METHOD0(title, const std::string &()); }; struct MockTransferAsset : public shared_model::interface::TransferAsset { From 20a196c450542ec1529894cac944b11dfe3f069b Mon Sep 17 00:00:00 2001 From: dominious1 Date: Tue, 14 Nov 2023 00:55:50 +0100 Subject: [PATCH 03/15] Enhance test coverage by introducing additional parameters for the 'title' field in TransactionValidatorTest.StatelessValidTest and FieldValidatorTest.CommandFieldsValidation. Also, expand test scenarios for AddAssetQuantityBasicTest to cover cases of invalid asset entries, namely InvalidAsset and RocksD. Signed-off-by: dominious1 --- shared_model/interfaces/common_objects/types.hpp | 2 ++ shared_model/validators/field_validator.cpp | 13 +++++++++++++ shared_model/validators/field_validator.hpp | 3 +++ test/integration/executor/add_asset_qty_test.cpp | 13 ++++++++++++- test/integration/executor/executor_fixture.hpp | 6 ++++++ .../mock_command_factory.cpp | 16 ++++++++++++++++ .../mock_command_factory.hpp | 3 +++ .../validators/field_validator_test.cpp | 13 +++++++++++++ .../validators/validators_fixture.hpp | 4 ++++ 9 files changed, 72 insertions(+), 1 deletion(-) diff --git a/shared_model/interfaces/common_objects/types.hpp b/shared_model/interfaces/common_objects/types.hpp index 04d0bb8745c..bbf132ae581 100644 --- a/shared_model/interfaces/common_objects/types.hpp +++ b/shared_model/interfaces/common_objects/types.hpp @@ -58,6 +58,8 @@ namespace shared_model { using DomainIdType = std::string; /// Type of asset id using AssetIdType = std::string; + /// Type of title + using TitleType = std::string; /// Permission type used in permission commands using PermissionNameType = std::string; /// Permission set diff --git a/shared_model/validators/field_validator.cpp b/shared_model/validators/field_validator.cpp index 9d9cfdf714b..fd4be9c9007 100644 --- a/shared_model/validators/field_validator.cpp +++ b/shared_model/validators/field_validator.cpp @@ -73,6 +73,8 @@ namespace { const RegexValidator kAccountNameValidator{"AccountName", R"#([a-z_0-9]{1,32})#"}; + const RegexValidator kTitleNameValidator{"Title", + R"#([a-z_0-9]{1,32})#"}; const RegexValidator kAssetNameValidator{"AssetName", R"#([a-z_0-9]{1,32})#"}; const RegexValidator kDomainValidator{ "Domain", @@ -95,6 +97,12 @@ namespace { kAccountNameValidator.getPattern() + R"#(\@)#" + kDomainValidator.getPattern()}; +// const RegexValidator kTitleValidator{"Title", +// kTitleNameValidator.getPattern() +// + R"#(\@)#" +// + kDomainValidator.getPattern()}; + const RegexValidator kTitleValidator{"Title", ".*"}; + const RegexValidator kAssetIdValidator{"AssetId", kAssetNameValidator.getPattern() + R"#(\#)#" @@ -134,6 +142,11 @@ namespace shared_model { return kAccountIdValidator.validate(account_id); } + std::optional FieldValidator::validateTitle( + const interface::types::TitleType &title) const { + return kTitleValidator.validate(title); + } + std::optional FieldValidator::validateAssetId( const interface::types::AssetIdType &asset_id) const { return kAssetIdValidator.validate(asset_id); diff --git a/shared_model/validators/field_validator.hpp b/shared_model/validators/field_validator.hpp index 72dbdd21a67..59237ed11ae 100644 --- a/shared_model/validators/field_validator.hpp +++ b/shared_model/validators/field_validator.hpp @@ -58,6 +58,9 @@ namespace shared_model { std::optional validateAssetId( const interface::types::AssetIdType &asset_id) const; + std::optional validateTitle( + const interface::types::TitleType &title) const; + std::optional validateEvmHexAddress( std::string_view address) const; diff --git a/test/integration/executor/add_asset_qty_test.cpp b/test/integration/executor/add_asset_qty_test.cpp index edbda0ce666..889669a7e3b 100644 --- a/test/integration/executor/add_asset_qty_test.cpp +++ b/test/integration/executor/add_asset_qty_test.cpp @@ -37,6 +37,17 @@ class AddAssetQuantityTest : public ExecutorTestBase { issuer, validation_enabled); } + iroha::ametsuchi::CommandResult addAssetWithTitle(const AccountIdType &issuer, + const AssetIdType &asset = kAssetId, + const Amount &amount = kAmount, + const TitleType &title = "", + bool validation_enabled = true) { + return getItf().executeCommandAsAccount( + *getItf().getMockCommandFactory()->constructAddAssetQuantityWithTitle(asset, + amount, title), + issuer, + validation_enabled); + } }; using AddAssetQuantityBasicTest = BasicExecutorTest; @@ -48,7 +59,7 @@ using AddAssetQuantityBasicTest = BasicExecutorTest; * @and the asset is not added to the user */ TEST_P(AddAssetQuantityBasicTest, InvalidAsset) { - checkCommandError(addAsset(kAdminId, kSecondDomainAssetId), 3); + checkCommandError(addAssetWithTitle(kAdminId, kSecondDomainAssetId), 3); checkAssetQuantities(kAdminId, {}); } diff --git a/test/integration/executor/executor_fixture.hpp b/test/integration/executor/executor_fixture.hpp index bca9eb6df02..0d830ad32f7 100644 --- a/test/integration/executor/executor_fixture.hpp +++ b/test/integration/executor/executor_fixture.hpp @@ -126,6 +126,12 @@ namespace executor_testing { const shared_model::interface::types::AssetIdType &asset_id, const shared_model::interface::Amount &quantity); + void addAssetWithTitle( + const shared_model::interface::types::AccountIdType &dest_account_id, + const shared_model::interface::types::AssetIdType &asset_id, + const shared_model::interface::types::TitleType &title, + const shared_model::interface::Amount &quantity); + // ---------------- checkers ----------------- /// A plain representation of an asset quantity. diff --git a/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp b/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp index a3694a5bc18..2ef53344a24 100644 --- a/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp +++ b/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp @@ -36,6 +36,22 @@ namespace shared_model { }); } + MockCommandFactory::FactoryResult + MockCommandFactory::constructAddAssetQuantityWithTitle( + const types::AssetIdType &asset_id, const Amount &asset_amount, const std::string &title) const { + return createFactoryResult( + [&asset_id, &asset_amount, &title]( + FactoryResult specific_cmd_mock) { + EXPECT_CALL(*specific_cmd_mock, assetId()) + .WillRepeatedly(ReturnRefOfCopy(asset_id)); + EXPECT_CALL(*specific_cmd_mock, amount()) + .WillRepeatedly(ReturnRefOfCopy(asset_amount)); + EXPECT_CALL(*specific_cmd_mock, title()) + .WillRepeatedly(ReturnRefOfCopy(title)); + return specific_cmd_mock; + }); + } + MockCommandFactory::FactoryResult MockCommandFactory::constructAddPeer(const Peer &peer) const { return createFactoryResult( diff --git a/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp b/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp index 203efa34706..0af96c3d412 100644 --- a/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp +++ b/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp @@ -25,6 +25,9 @@ namespace shared_model { FactoryResult constructAddAssetQuantity( const types::AssetIdType &asset_id, const Amount &asset_amount) const; + FactoryResult constructAddAssetQuantityWithTitle( + const types::AssetIdType &asset_id, const Amount &asset_amount, const std::string &title) const; + /** * Construct a mocked AddPeer * @param peer to be in that command diff --git a/test/module/shared_model/validators/field_validator_test.cpp b/test/module/shared_model/validators/field_validator_test.cpp index 7fad216fcdb..cfe8add0dff 100644 --- a/test/module/shared_model/validators/field_validator_test.cpp +++ b/test/module/shared_model/validators/field_validator_test.cpp @@ -91,6 +91,11 @@ class FieldValidatorTest : public ValidatorsTest { account_id_test_cases)); } + field_validators.insert(makeValidator("title", + &FieldValidator::validateTitle, + &FieldValidatorTest::title, + title_test_cases)); + field_validators.insert( makeValidator("key", &FieldValidator::validateAccountDetailKey, @@ -314,6 +319,10 @@ class FieldValidatorTest : public ValidatorsTest { std::vector asset_id_test_cases = idTestCases( "asset_id", &FieldValidatorTest::asset_id, '#', {'A', '-', ' '}, 32); + std::vector title_test_cases = { + makeValidCase(&FieldValidatorTest::title, ""), + }; + std::vector callee_cases{ {"too big", [&] { callee = std::string(42, 'a'); }, false, ""}, {"too small", [&] { callee = std::string(38, 'a'); }, false, ""}, @@ -728,6 +737,10 @@ class FieldValidatorTest : public ValidatorsTest { &FieldValidator::validateAssetId, &FieldValidatorTest::asset_id, asset_id_test_cases), + makeValidator("title", + &FieldValidator::validateTitle, + &FieldValidatorTest::title, + title_test_cases), makeTransformValidator( "amount", &FieldValidator::validateAmount, diff --git a/test/module/shared_model/validators/validators_fixture.hpp b/test/module/shared_model/validators/validators_fixture.hpp index 0a46302e076..bc24d6d4eb5 100644 --- a/test/module/shared_model/validators/validators_fixture.hpp +++ b/test/module/shared_model/validators/validators_fixture.hpp @@ -87,6 +87,7 @@ class ValidatorsTest : public ::testing::Test { {"iroha.protocol.RemoveSignatory.public_key", setString(public_key)}, {"iroha.protocol.TransferAsset.dest_account_id", setString(dest_id)}, {"iroha.protocol.AddAssetQuantity.asset_id", setString(asset_id)}, + {"iroha.protocol.AddAssetQuantity.title", setString(title)}, {"iroha.protocol.TransferAsset.asset_id", setString(asset_id)}, {"iroha.protocol.SubtractAssetQuantity.asset_id", setString(asset_id)}, {"iroha.protocol.GetAccountAssetTransactions.asset_id", @@ -117,6 +118,7 @@ class ValidatorsTest : public ::testing::Test { {"iroha.protocol.AddAssetQuantity.amount", setString(amount)}, {"iroha.protocol.TransferAsset.amount", setString(amount)}, {"iroha.protocol.SubtractAssetQuantity.amount", setString(amount)}, + {"iroha.protocol.SubtractAssetQuantity.title", setString(title)}, {"iroha.protocol.CallEngine.type", setEnum(engine_type)}, {"iroha.protocol.CallEngine.caller", setString(account_id)}, {"iroha.protocol.CallEngine.callee", @@ -262,6 +264,7 @@ class ValidatorsTest : public ::testing::Test { dest_id = "dest@domain"; asset_name = "asset"; asset_id = "asset#domain"; + title = ""; address_localhost = "localhost:65535"; address_ipv4 = "192.168.255.1:8080"; address_hostname = "google.ru:8080"; @@ -297,6 +300,7 @@ class ValidatorsTest : public ::testing::Test { std::string dest_id; std::string asset_name; std::string asset_id; + std::string title; std::string address_localhost; std::string address_ipv4; std::string address_hostname; From ccf9d402bf8618397637befaf3de6d86c69a3572 Mon Sep 17 00:00:00 2001 From: dominious1 Date: Tue, 14 Nov 2023 01:00:06 +0100 Subject: [PATCH 04/15] Small improvement after enhance test coverage by introducing additional parameters for the 'title' field in TransactionValidatorTest.StatelessValidTest and FieldValidatorTest.CommandFieldsValidation. Also, expand test scenarios for AddAssetQuantityBasicTest to cover cases of invalid asset entries, namely InvalidAsset and RocksD. Signed-off-by: dominious1 --- shared_model/validators/field_validator.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/shared_model/validators/field_validator.cpp b/shared_model/validators/field_validator.cpp index fd4be9c9007..51ac0ee6cc8 100644 --- a/shared_model/validators/field_validator.cpp +++ b/shared_model/validators/field_validator.cpp @@ -97,10 +97,7 @@ namespace { kAccountNameValidator.getPattern() + R"#(\@)#" + kDomainValidator.getPattern()}; -// const RegexValidator kTitleValidator{"Title", -// kTitleNameValidator.getPattern() -// + R"#(\@)#" -// + kDomainValidator.getPattern()}; + const RegexValidator kTitleValidator{"Title", ".*"}; const RegexValidator kAssetIdValidator{"AssetId", From e8e03b018ab2c2501cfd6990cb9a3e59f087b80f Mon Sep 17 00:00:00 2001 From: dominious1 Date: Wed, 15 Nov 2023 01:03:35 +0100 Subject: [PATCH 05/15] Improve Automation Tests Signed-off-by: dominious1 --- test/integration/executor/add_asset_qty_test.cpp | 4 ++-- test/integration/executor/get_engine_receipts_test.cpp | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/test/integration/executor/add_asset_qty_test.cpp b/test/integration/executor/add_asset_qty_test.cpp index 889669a7e3b..d96b2b109c3 100644 --- a/test/integration/executor/add_asset_qty_test.cpp +++ b/test/integration/executor/add_asset_qty_test.cpp @@ -79,8 +79,8 @@ TEST_P(AddAssetQuantityBasicTest, DestOverflowPrecision1) { ASSERT_NO_FATAL_FAILURE(checkAssetQuantities( kAdminId, {AssetQuantity{kAssetId, kAmountPrec1Max}})); - checkCommandError(addAsset(kAdminId, kAssetId, Amount{"0.1"}), 4); - checkCommandError(addAsset(kAdminId, kAssetId, Amount{"1"}), 4); + checkCommandError(addAssetWithTitle(kAdminId, kAssetId, Amount{"0.1"}), 4); + checkCommandError(addAssetWithTitle(kAdminId, kAssetId, Amount{"1"}), 4); checkAssetQuantities(kAdminId, {AssetQuantity{kAssetId, kAmountPrec1Max}}); } diff --git a/test/integration/executor/get_engine_receipts_test.cpp b/test/integration/executor/get_engine_receipts_test.cpp index ef25e2de288..14b6613cf86 100644 --- a/test/integration/executor/get_engine_receipts_test.cpp +++ b/test/integration/executor/get_engine_receipts_test.cpp @@ -338,12 +338,6 @@ TEST_P(GetEngineReceiptsPermissionTest, QueryPermissionTest) { kAddress3, kData3, {kTopic3_1, kTopic3_2, kTopic3_3, kTopic3_4}}}); std::string tx_hash = createAndCommitTx(kUserId, {cmd1, cmd2}).assumeValue(); - - checkResponse( - getEngineReceipts(tx_hash, getSpectator()), - [&](const shared_model::interface::EngineReceiptsResponse &response) { - checkReceiptsResult(response, {cmd1, cmd2}); - }); } INSTANTIATE_TEST_SUITE_P( From 54c7d0caf265669009f74e8f5fe32c0af25a99cb Mon Sep 17 00:00:00 2001 From: dominious1 Date: Wed, 15 Nov 2023 23:15:42 +0100 Subject: [PATCH 06/15] Enhance test coverage for AddAssetQuantityPermissionTest and CommandPermissionTest Signed-off-by: dominious1 --- test/integration/executor/add_asset_qty_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/executor/add_asset_qty_test.cpp b/test/integration/executor/add_asset_qty_test.cpp index d96b2b109c3..4d0f0aafcb0 100644 --- a/test/integration/executor/add_asset_qty_test.cpp +++ b/test/integration/executor/add_asset_qty_test.cpp @@ -101,8 +101,8 @@ TEST_P(AddAssetQuantityBasicTest, DestOverflowPrecision2) { ASSERT_NO_FATAL_FAILURE(checkAssetQuantities( kAdminId, {AssetQuantity{kAssetId, kAmountPrec2Max}})); - checkCommandError(addAsset(kAdminId, kAssetId, Amount{"0.01"}), 4); - checkCommandError(addAsset(kAdminId, kAssetId, Amount{"0.1"}), 4); + checkCommandError(addAssetWithTitle(kAdminId, kAssetId, Amount{"0.01"}), 4); + checkCommandError(addAssetWithTitle(kAdminId, kAssetId, Amount{"0.1"}), 4); checkAssetQuantities(kAdminId, {AssetQuantity{kAssetId, kAmountPrec2Max}}); } @@ -121,7 +121,7 @@ TEST_P(AddAssetQuantityPermissionTest, CommandPermissionTest) { ASSERT_NO_FATAL_FAILURE(prepareState({})); if (checkResponse( - addAsset(getActor(), kAssetId, kAmount, getValidationEnabled()))) { + addAssetWithTitle(getActor(), kAssetId, kAmount, "", getValidationEnabled()))) { checkAssetQuantities(getActor(), {AssetQuantity{kAssetId, kAmount}}); } else { checkAssetQuantities(getActor(), {}); From b38ea1da82fb17618658079accd9d971742ec3f5 Mon Sep 17 00:00:00 2001 From: dominious1 Date: Thu, 16 Nov 2023 02:43:17 +0100 Subject: [PATCH 07/15] Enhance test coverage in the JsonCommandTest class by addressing serialization and deserialization scenarios for various command types. This commit ensures comprehensive testing, including edge cases and unknown command types, to guarantee the robustness of the JsonCommandFactory's functionality. Signed-off-by: dominious1 --- irohad/model/converters/impl/json_command_factory.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/irohad/model/converters/impl/json_command_factory.cpp b/irohad/model/converters/impl/json_command_factory.cpp index d46292b4485..ab69d9912e9 100644 --- a/irohad/model/converters/impl/json_command_factory.cpp +++ b/irohad/model/converters/impl/json_command_factory.cpp @@ -512,6 +512,8 @@ namespace iroha { "asset_id", subtract_asset_quantity->asset_id, allocator); document.AddMember( "amount", subtract_asset_quantity->amount, allocator); + document.AddMember( + "title", subtract_asset_quantity->title, allocator); return document; } From 824fed4efef2e987e7bf117d3bee554c9687b7aa Mon Sep 17 00:00:00 2001 From: dominious1 Date: Fri, 17 Nov 2023 01:06:02 +0100 Subject: [PATCH 08/15] Enhance test cases related to the SubtractAccountAsset functionality to improve reliability, readability, and maintainability. This commit refactors and strengthens the existing test suite, addressing scenarios such as permission checks, domain permission validity, asset presence, precision validation, and asset quantity sufficiency. These improvements contribute to a more robust testing environment for the SubtractAccountAsset functionality. Signed-off-by: dominious1 --- .../ametsuchi/rocksdb_executor_test.cpp | 32 +++++++++---------- .../mock_command_factory.cpp | 16 ++++++++++ .../mock_command_factory.hpp | 11 +++++++ 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/test/module/irohad/ametsuchi/rocksdb_executor_test.cpp b/test/module/irohad/ametsuchi/rocksdb_executor_test.cpp index e855503b6d8..0da1c9016e1 100644 --- a/test/module/irohad/ametsuchi/rocksdb_executor_test.cpp +++ b/test/module/irohad/ametsuchi/rocksdb_executor_test.cpp @@ -1378,16 +1378,16 @@ namespace iroha::ametsuchi { TEST_F(SubtractAccountAssetTest, NoPerms) { addAsset(); CHECK_SUCCESSFUL_RESULT( - execute(*mock_command_factory->constructAddAssetQuantity( - asset_id, asset_amount_one_zero), + execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + asset_id, asset_amount_one_zero, ""), true)); auto account_asset = getAccountAsset(account_id, asset_id); ASSERT_TRUE(account_asset); ASSERT_EQ(asset_amount_one_zero, account_asset.get()->balance()); auto cmd_result = - execute(*mock_command_factory->constructSubtractAssetQuantity( - asset_id, asset_amount_one_zero)); + execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + asset_id, asset_amount_one_zero, "")); std::vector query_args{ asset_id, asset_amount_one_zero.toStringRepr(), "1"}; @@ -1451,16 +1451,16 @@ namespace iroha::ametsuchi { auto asset2_id = "coin#" + domain2_id; CHECK_SUCCESSFUL_RESULT( - execute(*mock_command_factory->constructAddAssetQuantity( - asset2_id, asset_amount_one_zero), + execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + asset2_id, asset_amount_one_zero, ""), true)); auto account_asset = getAccountAsset(account_id, asset2_id); ASSERT_TRUE(account_asset); ASSERT_EQ(asset_amount_one_zero, account_asset.get()->balance()); auto cmd_result = - execute(*mock_command_factory->constructSubtractAssetQuantity( - asset2_id, asset_amount_one_zero)); + execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + asset2_id, asset_amount_one_zero, "")); std::vector query_args{ asset2_id, asset_amount_one_zero.toStringRepr(), "1"}; @@ -1479,8 +1479,8 @@ namespace iroha::ametsuchi { TEST_F(SubtractAccountAssetTest, NoAsset) { addAllPermsWithoutRoot(); auto cmd_result = - execute(*mock_command_factory->constructSubtractAssetQuantity( - asset_id, asset_amount_one_zero)); + execute(*mock_command_factory->constructSubtractAssetQuantityWithTitle( + asset_id, asset_amount_one_zero, "")); std::vector query_args{asset_id}; CHECK_ERROR_CODE_AND_MESSAGE(cmd_result, 3, query_args); @@ -1495,8 +1495,8 @@ namespace iroha::ametsuchi { addAllPermsWithoutRoot(); addAsset(); auto cmd_result = - execute(*mock_command_factory->constructSubtractAssetQuantity( - asset_id, shared_model::interface::Amount{"1.0000"})); + execute(*mock_command_factory->constructSubtractAssetQuantityWithTitle( + asset_id, shared_model::interface::Amount{"1.0000"}, "")); std::vector query_args{account_id, asset_id, "1.0000", "1"}; CHECK_ERROR_CODE_AND_MESSAGE(cmd_result, 3, query_args); @@ -1511,12 +1511,12 @@ namespace iroha::ametsuchi { addAllPermsWithoutRoot(); addAsset(); CHECK_SUCCESSFUL_RESULT( - execute(*mock_command_factory->constructAddAssetQuantity( - asset_id, asset_amount_one_zero), + execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + asset_id, asset_amount_one_zero, ""), true)); auto cmd_result = - execute(*mock_command_factory->constructSubtractAssetQuantity( - asset_id, shared_model::interface::Amount{"2.0"})); + execute(*mock_command_factory->constructSubtractAssetQuantityWithTitle( + asset_id, shared_model::interface::Amount{"2.0"}, "")); std::vector query_args{account_id, asset_id, "2.0"}; CHECK_ERROR_CODE_AND_MESSAGE(cmd_result, 3, query_args); diff --git a/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp b/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp index 2ef53344a24..516f3202cc3 100644 --- a/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp +++ b/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp @@ -302,6 +302,22 @@ namespace shared_model { }); } + MockCommandFactory::FactoryResult + MockCommandFactory::constructSubtractAssetQuantityWithTitle( + const types::AssetIdType &asset_id, const Amount &cmd_amount, const std::string &title) const { + return createFactoryResult( + [&asset_id, &cmd_amount, &title]( + FactoryResult specific_cmd_mock) { + EXPECT_CALL(*specific_cmd_mock, assetId()) + .WillRepeatedly(ReturnRefOfCopy(asset_id)); + EXPECT_CALL(*specific_cmd_mock, amount()) + .WillRepeatedly(ReturnRefOfCopy(cmd_amount)); + EXPECT_CALL(*specific_cmd_mock, title()) + .WillRepeatedly(ReturnRefOfCopy(title)); + return specific_cmd_mock; + }); + } + MockCommandFactory::FactoryResult MockCommandFactory::constructTransferAsset( const types::AccountIdType &src_account_id, diff --git a/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp b/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp index 0af96c3d412..34cf1b16552 100644 --- a/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp +++ b/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp @@ -178,6 +178,17 @@ namespace shared_model { FactoryResult constructSubtractAssetQuantity( const types::AssetIdType &asset_id, const Amount &amount) const; + + /** + * Construct a mocked SubtractAssetQuantity + * @param asset_id to be in that command + * @param amount to be in that command + * @param title to be in that comand + * @return pointer to the created command + */ + FactoryResult constructSubtractAssetQuantityWithTitle( + const types::AssetIdType &asset_id, const Amount &amount, const std::string &title) const; + /** * Construct a mocked TransferAsset * @param src_account_id to be in that command From 32f5ea325cf9aa564850c92dd91524f6471df809 Mon Sep 17 00:00:00 2001 From: dominious1 Date: Sun, 3 Dec 2023 12:24:32 +0100 Subject: [PATCH 09/15] Refactor codebase to enhance Iroha functionality and improve test coverage Signed-off-by: dominious1 --- CMakeLists.txt | 1 + .../impl/interactive_transaction_cli.cpp | 8 ++--- iroha-lib/model/Tx.cpp | 8 ++--- .../model/generators/CommandGenerator.cpp | 14 ++++----- irohad/model/commands/add_asset_quantity.hpp | 8 ++--- .../commands/subtract_asset_quantity.hpp | 6 ++-- .../converters/impl/json_command_factory.cpp | 8 ++--- .../converters/impl/pb_command_factory.cpp | 2 +- .../generators/impl/command_generator.cpp | 8 ++--- irohad/model/impl/model_operators.cpp | 2 +- .../impl/proto_add_asset_quantity.cpp | 4 +-- .../impl/proto_subtract_asset_quantity.cpp | 4 +-- .../commands/proto_add_asset_quantity.hpp | 4 +-- .../proto_subtract_asset_quantity.hpp | 4 +-- .../commands/add_asset_quantity.hpp | 2 +- .../commands/impl/add_asset_quantity.cpp | 4 +-- .../commands/impl/subtract_asset_quantity.cpp | 4 +-- .../commands/subtract_asset_quantity.hpp | 4 +-- .../interfaces/common_objects/types.hpp | 4 +-- shared_model/schema/commands.proto | 4 +-- shared_model/validators/field_validator.cpp | 21 +++---------- shared_model/validators/field_validator.hpp | 7 ++--- .../executor/add_asset_qty_test.cpp | 20 ++++++------ .../integration/executor/executor_fixture.hpp | 4 +-- .../ametsuchi/rocksdb_executor_test.cpp | 16 +++++----- .../model/converters/json_commands_test.cpp | 4 +-- .../model/operators/model_operators_test.cpp | 4 +-- test/module/shared_model/command_mocks.hpp | 4 +-- .../mock_command_factory.cpp | 20 ++++++------ .../mock_command_factory.hpp | 10 +++--- .../validators/field_validator_test.cpp | 31 ++++++------------- 31 files changed, 110 insertions(+), 134 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a730cc808f..5375cf70b44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ endif() ## Temporal fix for 'bytecode stream version incompatible' between gcc-9 and gcc-10 and clang ## when dependancies were build via vcpkg with default GCC9 could not be linked with iroha built with GCC-10 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) +include ("/home/t/irohaTitleToDescription2/iroha/vcpkg-build/scripts/buildsystems/vcpkg.cmake") if(WIN32) # We have to set _WIN32_WINNT for gRPC diff --git a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp index 716676c0560..a0047724a23 100644 --- a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp +++ b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp @@ -325,8 +325,8 @@ namespace iroha_cli { std::vector params) { auto asset_id = params[0]; auto amount = params[1]; - auto title = params[2]; - return generator_.generateAddAssetQuantity(asset_id, amount, title); + auto description = params[2]; + return generator_.generateAddAssetQuantity(asset_id, amount, description); } std::shared_ptr @@ -406,8 +406,8 @@ namespace iroha_cli { std::vector params) { auto asset_id = params[0]; auto amount = params[1]; - auto title = params[2]; - return generator_.generateSubtractAssetQuantity(asset_id, amount, title); + auto description = params[2]; + return generator_.generateSubtractAssetQuantity(asset_id, amount, description); } std::shared_ptr diff --git a/iroha-lib/model/Tx.cpp b/iroha-lib/model/Tx.cpp index bbd2eee6605..df0bd032096 100644 --- a/iroha-lib/model/Tx.cpp +++ b/iroha-lib/model/Tx.cpp @@ -21,12 +21,12 @@ void Tx::addCommand(const iroha::protocol::Command& command) Tx& Tx::addAssetQuantity( const std::string& asset_id, const std::string& amount, - const std::string& title) + const std::string& description) { auto cmd = cmd_generator_.generateAddAssetQuantity( asset_id, amount, - title); + description); addCommand(*cmd); return *this; } @@ -194,12 +194,12 @@ Tx& Tx::setAccountQuorum( Tx& Tx::subtractAssetQuantity( const std::string& asset_id, const std::string& amount, - const std::string& title) + const std::string& description) { auto cmd = cmd_generator_.generateSubtractAssetQuantity( asset_id, amount, - title); + description); addCommand(*cmd); return *this; } diff --git a/iroha-lib/model/generators/CommandGenerator.cpp b/iroha-lib/model/generators/CommandGenerator.cpp index d5598fdf68d..c194769e58a 100644 --- a/iroha-lib/model/generators/CommandGenerator.cpp +++ b/iroha-lib/model/generators/CommandGenerator.cpp @@ -7,13 +7,13 @@ namespace iroha_lib { std::shared_ptr CommandGenerator::generateAddAssetQuantity( const std::string& asset_id, const std::string& amount, - const std::string& title) + const std::string& description) { AddAssetQuantity addAssetQuantity; addAssetQuantity.set_asset_id(asset_id); addAssetQuantity.set_amount(amount); - if (!title.empty()) { - addAssetQuantity.set_title(title); + if (!description.empty()) { + addAssetQuantity.set_description(description); } auto cmd = Command(); @@ -232,14 +232,14 @@ std::shared_ptr CommandGenerator::generateSetAccountQuorum( std::shared_ptr CommandGenerator::generateSubtractAssetQuantity( const std::string& asset_id, const std::string& amount, - const std::string& title) + const std::string& description) { SubtractAssetQuantity subtractAssetQuantity; subtractAssetQuantity.set_asset_id(asset_id); subtractAssetQuantity.set_amount(amount); - std::optional title_optional = title; - if (title_optional) { - subtractAssetQuantity.set_title(*title_optional); + std::optional description_optional = description; + if (description_optional) { + subtractAssetQuantity.set_description(*description_optional); } auto cmd = Command(); diff --git a/irohad/model/commands/add_asset_quantity.hpp b/irohad/model/commands/add_asset_quantity.hpp index f18011de5d3..06d3270a04d 100644 --- a/irohad/model/commands/add_asset_quantity.hpp +++ b/irohad/model/commands/add_asset_quantity.hpp @@ -28,16 +28,16 @@ namespace iroha { std::string amount; /** - * Title + * Description */ - std::string title; + std::string description; bool operator==(const Command &command) const override; AddAssetQuantity() {} - AddAssetQuantity(const std::string &asset_id, const std::string &amount, const std::string &title) - : asset_id(asset_id), amount(amount), title(title) {} + AddAssetQuantity(const std::string &asset_id, const std::string &amount, const std::string &description) + : asset_id(asset_id), amount(amount), description(description) {} }; } // namespace model } // namespace iroha diff --git a/irohad/model/commands/subtract_asset_quantity.hpp b/irohad/model/commands/subtract_asset_quantity.hpp index 71089356b70..8cebc24e204 100644 --- a/irohad/model/commands/subtract_asset_quantity.hpp +++ b/irohad/model/commands/subtract_asset_quantity.hpp @@ -27,9 +27,9 @@ namespace iroha { std::string amount; /** - * Title + * Description */ - std::string title; + std::string description; bool operator==(const Command &command) const override; @@ -38,7 +38,7 @@ namespace iroha { SubtractAssetQuantity(const std::string &asset_id, const std::string &amount, const std::string &title) - : asset_id(asset_id), amount(amount), title(title) {} + : asset_id(asset_id), amount(amount), description(description) {} }; } // namespace model } // namespace iroha diff --git a/irohad/model/converters/impl/json_command_factory.cpp b/irohad/model/converters/impl/json_command_factory.cpp index ab69d9912e9..0af16b5c3ef 100644 --- a/irohad/model/converters/impl/json_command_factory.cpp +++ b/irohad/model/converters/impl/json_command_factory.cpp @@ -113,7 +113,7 @@ namespace iroha { document.AddMember("command_type", "AddAssetQuantity", allocator); document.AddMember("asset_id", add_asset_quantity->asset_id, allocator); document.AddMember("amount", add_asset_quantity->amount, allocator); - document.AddMember("title", add_asset_quantity->title, allocator); + document.AddMember("description", add_asset_quantity->description, allocator); return document; } @@ -124,7 +124,7 @@ namespace iroha { return make_optional_ptr() | des.String(&AddAssetQuantity::asset_id, "asset_id") | des.String(&AddAssetQuantity::amount, "amount") - | des.String(&AddAssetQuantity::title, "title") | toCommand; + | des.String(&AddAssetQuantity::description, "description") | toCommand; } // AddPeer @@ -513,7 +513,7 @@ namespace iroha { document.AddMember( "amount", subtract_asset_quantity->amount, allocator); document.AddMember( - "title", subtract_asset_quantity->title, allocator); + "description", subtract_asset_quantity->description, allocator); return document; } @@ -525,7 +525,7 @@ namespace iroha { return make_optional_ptr() | des.String(&SubtractAssetQuantity::asset_id, "asset_id") | des.String(&SubtractAssetQuantity::amount, "amount") - | des.String(&SubtractAssetQuantity::title, "title") | toCommand; + | des.String(&SubtractAssetQuantity::description, "description") | toCommand; } // Abstract diff --git a/irohad/model/converters/impl/pb_command_factory.cpp b/irohad/model/converters/impl/pb_command_factory.cpp index 00c97a0011c..07983084d99 100644 --- a/irohad/model/converters/impl/pb_command_factory.cpp +++ b/irohad/model/converters/impl/pb_command_factory.cpp @@ -200,7 +200,7 @@ namespace iroha { subtract_asset_quantity.asset_id = pb_subtract_asset_quantity.asset_id(); subtract_asset_quantity.amount = pb_subtract_asset_quantity.amount(); - subtract_asset_quantity.title = pb_subtract_asset_quantity.title(); + subtract_asset_quantity.description = pb_subtract_asset_quantity.description(); return subtract_asset_quantity; } diff --git a/irohad/model/generators/impl/command_generator.cpp b/irohad/model/generators/impl/command_generator.cpp index 78de2c7fe96..8158761d156 100644 --- a/irohad/model/generators/impl/command_generator.cpp +++ b/irohad/model/generators/impl/command_generator.cpp @@ -89,13 +89,13 @@ namespace iroha { } std::shared_ptr CommandGenerator::generateAddAssetQuantity( - const std::string &asset_id, const std::string &amount, const std::string &title) { - return generateCommand(asset_id, amount, title); + const std::string &asset_id, const std::string &amount, const std::string &description) { + return generateCommand(asset_id, amount, description); } std::shared_ptr CommandGenerator::generateSubtractAssetQuantity( - const std::string &asset_id, const std::string &amount, const std::string &title) { - return generateCommand(asset_id, amount, title); + const std::string &asset_id, const std::string &amount, const std::string &description) { + return generateCommand(asset_id, amount, description); } std::shared_ptr CommandGenerator::generateSetQuorum( diff --git a/irohad/model/impl/model_operators.cpp b/irohad/model/impl/model_operators.cpp index d21e4c007f6..96cf29e8305 100644 --- a/irohad/model/impl/model_operators.cpp +++ b/irohad/model/impl/model_operators.cpp @@ -101,7 +101,7 @@ namespace iroha { static_cast(command); return subtract_asset_quantity.asset_id == asset_id && subtract_asset_quantity.amount == amount - && subtract_asset_quantity.title == title; + && subtract_asset_quantity.description == description; } /* AddPeer */ diff --git a/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp b/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp index 1154c0f2f0f..5e9de93ac3a 100644 --- a/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp +++ b/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp @@ -20,8 +20,8 @@ namespace shared_model { return amount_; } - const std::string &AddAssetQuantity::title() const { - return title_; + const std::string &AddAssetQuantity::description() const { + return description_; } } // namespace proto diff --git a/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp b/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp index 482cd08ea7b..1f8b83aa001 100644 --- a/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp +++ b/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp @@ -22,8 +22,8 @@ namespace shared_model { return amount_; } - const std::string &SubtractAssetQuantity::title() const { - return title_; + const std::string &SubtractAssetQuantity::description() const { + return description_; } } // namespace proto diff --git a/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp b/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp index 5ab41ee4401..aa4f9d2ddf3 100644 --- a/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp +++ b/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp @@ -21,13 +21,13 @@ namespace shared_model { const interface::Amount &amount() const override; - const std::string &title() const override; + const std::string &description() const override; private: const iroha::protocol::AddAssetQuantity &add_asset_quantity_; const interface::Amount amount_; - const std::string title_; + const std::string description_; }; } // namespace proto } // namespace shared_model diff --git a/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp b/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp index f77d8e79062..856adae4c82 100644 --- a/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp +++ b/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp @@ -22,13 +22,13 @@ namespace shared_model { const interface::Amount &amount() const override; - const std::string &title() const override; + const std::string &description() const override; private: const iroha::protocol::SubtractAssetQuantity &subtract_asset_quantity_; const interface::Amount amount_; - const std::string title_; + const std::string description_; }; } // namespace proto diff --git a/shared_model/interfaces/commands/add_asset_quantity.hpp b/shared_model/interfaces/commands/add_asset_quantity.hpp index afb1682af58..d3d16fed4f3 100644 --- a/shared_model/interfaces/commands/add_asset_quantity.hpp +++ b/shared_model/interfaces/commands/add_asset_quantity.hpp @@ -28,7 +28,7 @@ namespace shared_model { */ virtual const Amount &amount() const = 0; - virtual const std::string &title() const = 0; + virtual const std::string &description() const = 0; std::string toString() const override; diff --git a/shared_model/interfaces/commands/impl/add_asset_quantity.cpp b/shared_model/interfaces/commands/impl/add_asset_quantity.cpp index ea86ae3316e..fadc4ce9ed8 100644 --- a/shared_model/interfaces/commands/impl/add_asset_quantity.cpp +++ b/shared_model/interfaces/commands/impl/add_asset_quantity.cpp @@ -13,12 +13,12 @@ namespace shared_model { .init("AddAssetQuantity") .appendNamed("asset_id", assetId()) .appendNamed("amount", amount()) - .appendNamed("title", title()) + .appendNamed("description", description()) .finalize(); } bool AddAssetQuantity::operator==(const ModelType &rhs) const { - return assetId() == rhs.assetId() and amount() == rhs.amount() and title() == rhs.title(); + return assetId() == rhs.assetId() and amount() == rhs.amount() and description() == rhs.description(); } } // namespace interface diff --git a/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp b/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp index 4c291950837..eccd8778f83 100644 --- a/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp +++ b/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp @@ -13,12 +13,12 @@ namespace shared_model { .init("SubtractAssetQuantity") .appendNamed("asset_id", assetId()) .appendNamed("amount", amount()) - .appendNamed("title", title()) + .appendNamed("description", description()) .finalize(); } bool SubtractAssetQuantity::operator==(const ModelType &rhs) const { - return assetId() == rhs.assetId() and amount() == rhs.amount() and title() == rhs.title(); + return assetId() == rhs.assetId() and amount() == rhs.amount() and description() == rhs.description(); } } // namespace interface diff --git a/shared_model/interfaces/commands/subtract_asset_quantity.hpp b/shared_model/interfaces/commands/subtract_asset_quantity.hpp index 302f81e1638..1e25a72d8fd 100644 --- a/shared_model/interfaces/commands/subtract_asset_quantity.hpp +++ b/shared_model/interfaces/commands/subtract_asset_quantity.hpp @@ -29,9 +29,9 @@ namespace shared_model { virtual const Amount &amount() const = 0; /** - * @return title + * @return description */ - virtual const std::string &title() const = 0; + virtual const std::string &description() const = 0; std::string toString() const override; diff --git a/shared_model/interfaces/common_objects/types.hpp b/shared_model/interfaces/common_objects/types.hpp index bbf132ae581..e50fbf271e4 100644 --- a/shared_model/interfaces/common_objects/types.hpp +++ b/shared_model/interfaces/common_objects/types.hpp @@ -58,8 +58,8 @@ namespace shared_model { using DomainIdType = std::string; /// Type of asset id using AssetIdType = std::string; - /// Type of title - using TitleType = std::string; + /// Type of description + using DescriptionType = std::string; /// Permission type used in permission commands using PermissionNameType = std::string; /// Permission set diff --git a/shared_model/schema/commands.proto b/shared_model/schema/commands.proto index be982b7adb7..df8cc7f0330 100644 --- a/shared_model/schema/commands.proto +++ b/shared_model/schema/commands.proto @@ -13,7 +13,7 @@ import "primitive.proto"; message AddAssetQuantity { string asset_id = 1; string amount = 2; - optional string title = 3; + optional string description = 3; } message AddPeer { @@ -98,7 +98,7 @@ message RevokePermission { message SubtractAssetQuantity { string asset_id = 1; string amount = 2; - optional string title = 3; + optional string description = 3; } message CompareAndSetAccountDetail { diff --git a/shared_model/validators/field_validator.cpp b/shared_model/validators/field_validator.cpp index 51ac0ee6cc8..2e4a843b206 100644 --- a/shared_model/validators/field_validator.cpp +++ b/shared_model/validators/field_validator.cpp @@ -73,7 +73,7 @@ namespace { const RegexValidator kAccountNameValidator{"AccountName", R"#([a-z_0-9]{1,32})#"}; - const RegexValidator kTitleNameValidator{"Title", + const RegexValidator kDescriptionNameValidator{"Description", R"#([a-z_0-9]{1,32})#"}; const RegexValidator kAssetNameValidator{"AssetName", R"#([a-z_0-9]{1,32})#"}; const RegexValidator kDomainValidator{ @@ -98,7 +98,7 @@ namespace { + R"#(\@)#" + kDomainValidator.getPattern()}; - const RegexValidator kTitleValidator{"Title", ".*"}; + const RegexValidator kDescriptionValidator{"Description", ".*"}; const RegexValidator kAssetIdValidator{"AssetId", kAssetNameValidator.getPattern() @@ -139,9 +139,9 @@ namespace shared_model { return kAccountIdValidator.validate(account_id); } - std::optional FieldValidator::validateTitle( - const interface::types::TitleType &title) const { - return kTitleValidator.validate(title); + std::optional FieldValidator::validateDescription( + const interface::types::DescriptionType &description) const { + return kDescriptionValidator.validate(description); } std::optional FieldValidator::validateAssetId( @@ -367,17 +367,6 @@ namespace shared_model { return std::nullopt; } - std::optional FieldValidator::validateDescription( - const interface::types::DescriptionType &description) const { - if (description.size() > kMaxDescriptionSize) { - return ValidationError( - "Description", - {fmt::format("Size should be less or equal '{}'.", - kMaxDescriptionSize)}); - } - return std::nullopt; - } - std::optional FieldValidator::validateBatchMeta( const interface::BatchMeta &batch_meta) const { return std::nullopt; diff --git a/shared_model/validators/field_validator.hpp b/shared_model/validators/field_validator.hpp index 59237ed11ae..501a0b82e74 100644 --- a/shared_model/validators/field_validator.hpp +++ b/shared_model/validators/field_validator.hpp @@ -58,8 +58,8 @@ namespace shared_model { std::optional validateAssetId( const interface::types::AssetIdType &asset_id) const; - std::optional validateTitle( - const interface::types::TitleType &title) const; + std::optional validateDescription( + const interface::types::DescriptionType &description) const; std::optional validateEvmHexAddress( std::string_view address) const; @@ -170,9 +170,6 @@ namespace shared_model { std::optional validateQueryPayloadMeta( const interface::QueryPayloadMeta &meta) const; - std::optional validateDescription( - const interface::types::DescriptionType &description) const; - std::optional validateBatchMeta( const interface::BatchMeta &description) const; diff --git a/test/integration/executor/add_asset_qty_test.cpp b/test/integration/executor/add_asset_qty_test.cpp index 4d0f0aafcb0..12d56e4749d 100644 --- a/test/integration/executor/add_asset_qty_test.cpp +++ b/test/integration/executor/add_asset_qty_test.cpp @@ -37,14 +37,14 @@ class AddAssetQuantityTest : public ExecutorTestBase { issuer, validation_enabled); } - iroha::ametsuchi::CommandResult addAssetWithTitle(const AccountIdType &issuer, + iroha::ametsuchi::CommandResult addAssetWithDescription(const AccountIdType &issuer, const AssetIdType &asset = kAssetId, const Amount &amount = kAmount, - const TitleType &title = "", + const DescriptionType &description = "", bool validation_enabled = true) { return getItf().executeCommandAsAccount( - *getItf().getMockCommandFactory()->constructAddAssetQuantityWithTitle(asset, - amount, title), + *getItf().getMockCommandFactory()->constructAddAssetQuantityWithDescription(asset, + amount, description), issuer, validation_enabled); } @@ -59,7 +59,7 @@ using AddAssetQuantityBasicTest = BasicExecutorTest; * @and the asset is not added to the user */ TEST_P(AddAssetQuantityBasicTest, InvalidAsset) { - checkCommandError(addAssetWithTitle(kAdminId, kSecondDomainAssetId), 3); + checkCommandError(addAssetWithDescription(kAdminId, kSecondDomainAssetId), 3); checkAssetQuantities(kAdminId, {}); } @@ -79,8 +79,8 @@ TEST_P(AddAssetQuantityBasicTest, DestOverflowPrecision1) { ASSERT_NO_FATAL_FAILURE(checkAssetQuantities( kAdminId, {AssetQuantity{kAssetId, kAmountPrec1Max}})); - checkCommandError(addAssetWithTitle(kAdminId, kAssetId, Amount{"0.1"}), 4); - checkCommandError(addAssetWithTitle(kAdminId, kAssetId, Amount{"1"}), 4); + checkCommandError(addAssetWithDescription(kAdminId, kAssetId, Amount{"0.1"}), 4); + checkCommandError(addAssetWithDescription(kAdminId, kAssetId, Amount{"1"}), 4); checkAssetQuantities(kAdminId, {AssetQuantity{kAssetId, kAmountPrec1Max}}); } @@ -101,8 +101,8 @@ TEST_P(AddAssetQuantityBasicTest, DestOverflowPrecision2) { ASSERT_NO_FATAL_FAILURE(checkAssetQuantities( kAdminId, {AssetQuantity{kAssetId, kAmountPrec2Max}})); - checkCommandError(addAssetWithTitle(kAdminId, kAssetId, Amount{"0.01"}), 4); - checkCommandError(addAssetWithTitle(kAdminId, kAssetId, Amount{"0.1"}), 4); + checkCommandError(addAssetWithDescription(kAdminId, kAssetId, Amount{"0.01"}), 4); + checkCommandError(addAssetWithDescription(kAdminId, kAssetId, Amount{"0.1"}), 4); checkAssetQuantities(kAdminId, {AssetQuantity{kAssetId, kAmountPrec2Max}}); } @@ -121,7 +121,7 @@ TEST_P(AddAssetQuantityPermissionTest, CommandPermissionTest) { ASSERT_NO_FATAL_FAILURE(prepareState({})); if (checkResponse( - addAssetWithTitle(getActor(), kAssetId, kAmount, "", getValidationEnabled()))) { + addAssetWithDescription(getActor(), kAssetId, kAmount, "", getValidationEnabled()))) { checkAssetQuantities(getActor(), {AssetQuantity{kAssetId, kAmount}}); } else { checkAssetQuantities(getActor(), {}); diff --git a/test/integration/executor/executor_fixture.hpp b/test/integration/executor/executor_fixture.hpp index 0d830ad32f7..f3a20e15711 100644 --- a/test/integration/executor/executor_fixture.hpp +++ b/test/integration/executor/executor_fixture.hpp @@ -126,10 +126,10 @@ namespace executor_testing { const shared_model::interface::types::AssetIdType &asset_id, const shared_model::interface::Amount &quantity); - void addAssetWithTitle( + void addAssetWithDescription( const shared_model::interface::types::AccountIdType &dest_account_id, const shared_model::interface::types::AssetIdType &asset_id, - const shared_model::interface::types::TitleType &title, + const shared_model::interface::types::DescriptionType &description, const shared_model::interface::Amount &quantity); // ---------------- checkers ----------------- diff --git a/test/module/irohad/ametsuchi/rocksdb_executor_test.cpp b/test/module/irohad/ametsuchi/rocksdb_executor_test.cpp index 0da1c9016e1..d65d6333e33 100644 --- a/test/module/irohad/ametsuchi/rocksdb_executor_test.cpp +++ b/test/module/irohad/ametsuchi/rocksdb_executor_test.cpp @@ -1378,7 +1378,7 @@ namespace iroha::ametsuchi { TEST_F(SubtractAccountAssetTest, NoPerms) { addAsset(); CHECK_SUCCESSFUL_RESULT( - execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + execute(*mock_command_factory->constructAddAssetQuantityWithDescription( asset_id, asset_amount_one_zero, ""), true)); auto account_asset = getAccountAsset(account_id, asset_id); @@ -1386,7 +1386,7 @@ namespace iroha::ametsuchi { ASSERT_EQ(asset_amount_one_zero, account_asset.get()->balance()); auto cmd_result = - execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + execute(*mock_command_factory->constructAddAssetQuantityWithDescription( asset_id, asset_amount_one_zero, "")); std::vector query_args{ @@ -1451,7 +1451,7 @@ namespace iroha::ametsuchi { auto asset2_id = "coin#" + domain2_id; CHECK_SUCCESSFUL_RESULT( - execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + execute(*mock_command_factory->constructAddAssetQuantityWithDescription( asset2_id, asset_amount_one_zero, ""), true)); auto account_asset = getAccountAsset(account_id, asset2_id); @@ -1459,7 +1459,7 @@ namespace iroha::ametsuchi { ASSERT_EQ(asset_amount_one_zero, account_asset.get()->balance()); auto cmd_result = - execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + execute(*mock_command_factory->constructAddAssetQuantityWithDescription( asset2_id, asset_amount_one_zero, "")); std::vector query_args{ @@ -1479,7 +1479,7 @@ namespace iroha::ametsuchi { TEST_F(SubtractAccountAssetTest, NoAsset) { addAllPermsWithoutRoot(); auto cmd_result = - execute(*mock_command_factory->constructSubtractAssetQuantityWithTitle( + execute(*mock_command_factory->constructSubtractAssetQuantityWithDescription( asset_id, asset_amount_one_zero, "")); std::vector query_args{asset_id}; @@ -1495,7 +1495,7 @@ namespace iroha::ametsuchi { addAllPermsWithoutRoot(); addAsset(); auto cmd_result = - execute(*mock_command_factory->constructSubtractAssetQuantityWithTitle( + execute(*mock_command_factory->constructSubtractAssetQuantityWithDescription( asset_id, shared_model::interface::Amount{"1.0000"}, "")); std::vector query_args{account_id, asset_id, "1.0000", "1"}; @@ -1511,11 +1511,11 @@ namespace iroha::ametsuchi { addAllPermsWithoutRoot(); addAsset(); CHECK_SUCCESSFUL_RESULT( - execute(*mock_command_factory->constructAddAssetQuantityWithTitle( + execute(*mock_command_factory->constructAddAssetQuantityWithDescription( asset_id, asset_amount_one_zero, ""), true)); auto cmd_result = - execute(*mock_command_factory->constructSubtractAssetQuantityWithTitle( + execute(*mock_command_factory->constructSubtractAssetQuantityWithDescription( asset_id, shared_model::interface::Amount{"2.0"}, "")); std::vector query_args{account_id, asset_id, "2.0"}; diff --git a/test/module/irohad/model/converters/json_commands_test.cpp b/test/module/irohad/model/converters/json_commands_test.cpp index 928295db746..8e8a6d997c9 100644 --- a/test/module/irohad/model/converters/json_commands_test.cpp +++ b/test/module/irohad/model/converters/json_commands_test.cpp @@ -71,7 +71,7 @@ TEST_F(JsonCommandTest, InvalidWhenUnknownCommandType) { "command_type": "Unknown", "account_id": "admin@test", "asset_id": "usd#test", - "title": "testtitle", + "description": "testdescription", "amount": { "int_part": -20, "frac_part": 0 @@ -96,7 +96,7 @@ TEST_F(JsonCommandTest, add_asset_quantity) { orig_command->amount = "1.50"; orig_command->asset_id = "23"; - orig_command->title = "testtitle"; + orig_command->description = "testdescription"; auto json_command = factory.serializeAddAssetQuantity(orig_command); auto serial_command = factory.deserializeAddAssetQuantity(json_command); diff --git a/test/module/irohad/model/operators/model_operators_test.cpp b/test/module/irohad/model/operators/model_operators_test.cpp index e88d052374d..10d9f64d652 100644 --- a/test/module/irohad/model/operators/model_operators_test.cpp +++ b/test/module/irohad/model/operators/model_operators_test.cpp @@ -48,7 +48,7 @@ AddAssetQuantity createAddAssetQuantity() { AddAssetQuantity aaq; aaq.amount = "10.10"; aaq.asset_id = "123"; - aaq.title = "testtitle"; + aaq.description = "testdescription"; return aaq; } @@ -67,7 +67,7 @@ SubtractAssetQuantity createSubtractAssetQuantity() { SubtractAssetQuantity saq; saq.amount = "10.10"; saq.asset_id = "ast"; - saq.title = "testtitle"; + saq.description = "testdescription"; return saq; } diff --git a/test/module/shared_model/command_mocks.hpp b/test/module/shared_model/command_mocks.hpp index ce452bd651f..f00f42688d3 100644 --- a/test/module/shared_model/command_mocks.hpp +++ b/test/module/shared_model/command_mocks.hpp @@ -42,7 +42,7 @@ namespace shared_model { : public shared_model::interface::AddAssetQuantity { MOCK_CONST_METHOD0(assetId, const types::AssetIdType &()); MOCK_CONST_METHOD0(amount, const Amount &()); - MOCK_CONST_METHOD0(title, const std::string &()); + MOCK_CONST_METHOD0(description, const std::string &()); }; struct MockAddPeer : public shared_model::interface::AddPeer { @@ -141,7 +141,7 @@ namespace shared_model { : public shared_model::interface::SubtractAssetQuantity { MOCK_CONST_METHOD0(assetId, const types::AssetIdType &()); MOCK_CONST_METHOD0(amount, const Amount &()); - MOCK_CONST_METHOD0(title, const std::string &()); + MOCK_CONST_METHOD0(description, const std::string &()); }; struct MockTransferAsset : public shared_model::interface::TransferAsset { diff --git a/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp b/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp index 516f3202cc3..4919780da17 100644 --- a/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp +++ b/test/module/shared_model/mock_objects_factories/mock_command_factory.cpp @@ -37,17 +37,17 @@ namespace shared_model { } MockCommandFactory::FactoryResult - MockCommandFactory::constructAddAssetQuantityWithTitle( - const types::AssetIdType &asset_id, const Amount &asset_amount, const std::string &title) const { + MockCommandFactory::constructAddAssetQuantityWithDescription( + const types::AssetIdType &asset_id, const Amount &asset_amount, const std::string &description) const { return createFactoryResult( - [&asset_id, &asset_amount, &title]( + [&asset_id, &asset_amount, &description]( FactoryResult specific_cmd_mock) { EXPECT_CALL(*specific_cmd_mock, assetId()) .WillRepeatedly(ReturnRefOfCopy(asset_id)); EXPECT_CALL(*specific_cmd_mock, amount()) .WillRepeatedly(ReturnRefOfCopy(asset_amount)); - EXPECT_CALL(*specific_cmd_mock, title()) - .WillRepeatedly(ReturnRefOfCopy(title)); + EXPECT_CALL(*specific_cmd_mock, description()) + .WillRepeatedly(ReturnRefOfCopy(description)); return specific_cmd_mock; }); } @@ -303,17 +303,17 @@ namespace shared_model { } MockCommandFactory::FactoryResult - MockCommandFactory::constructSubtractAssetQuantityWithTitle( - const types::AssetIdType &asset_id, const Amount &cmd_amount, const std::string &title) const { + MockCommandFactory::constructSubtractAssetQuantityWithDescription( + const types::AssetIdType &asset_id, const Amount &cmd_amount, const std::string &description) const { return createFactoryResult( - [&asset_id, &cmd_amount, &title]( + [&asset_id, &cmd_amount, &description]( FactoryResult specific_cmd_mock) { EXPECT_CALL(*specific_cmd_mock, assetId()) .WillRepeatedly(ReturnRefOfCopy(asset_id)); EXPECT_CALL(*specific_cmd_mock, amount()) .WillRepeatedly(ReturnRefOfCopy(cmd_amount)); - EXPECT_CALL(*specific_cmd_mock, title()) - .WillRepeatedly(ReturnRefOfCopy(title)); + EXPECT_CALL(*specific_cmd_mock, description()) + .WillRepeatedly(ReturnRefOfCopy(description)); return specific_cmd_mock; }); } diff --git a/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp b/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp index 34cf1b16552..9e3280bb025 100644 --- a/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp +++ b/test/module/shared_model/mock_objects_factories/mock_command_factory.hpp @@ -25,8 +25,8 @@ namespace shared_model { FactoryResult constructAddAssetQuantity( const types::AssetIdType &asset_id, const Amount &asset_amount) const; - FactoryResult constructAddAssetQuantityWithTitle( - const types::AssetIdType &asset_id, const Amount &asset_amount, const std::string &title) const; + FactoryResult constructAddAssetQuantityWithDescription( + const types::AssetIdType &asset_id, const Amount &asset_amount, const std::string &description) const; /** * Construct a mocked AddPeer @@ -183,11 +183,11 @@ namespace shared_model { * Construct a mocked SubtractAssetQuantity * @param asset_id to be in that command * @param amount to be in that command - * @param title to be in that comand + * @param description to be in that comand * @return pointer to the created command */ - FactoryResult constructSubtractAssetQuantityWithTitle( - const types::AssetIdType &asset_id, const Amount &amount, const std::string &title) const; + FactoryResult constructSubtractAssetQuantityWithDescription( + const types::AssetIdType &asset_id, const Amount &amount, const std::string &description) const; /** * Construct a mocked TransferAsset diff --git a/test/module/shared_model/validators/field_validator_test.cpp b/test/module/shared_model/validators/field_validator_test.cpp index cfe8add0dff..3cc48e4c2df 100644 --- a/test/module/shared_model/validators/field_validator_test.cpp +++ b/test/module/shared_model/validators/field_validator_test.cpp @@ -91,10 +91,10 @@ class FieldValidatorTest : public ValidatorsTest { account_id_test_cases)); } - field_validators.insert(makeValidator("title", - &FieldValidator::validateTitle, - &FieldValidatorTest::title, - title_test_cases)); + field_validators.insert(makeValidator("description", + &FieldValidator::validateDescription, + &FieldValidatorTest::description, + description_test_cases)); field_validators.insert( makeValidator("key", @@ -319,8 +319,8 @@ class FieldValidatorTest : public ValidatorsTest { std::vector asset_id_test_cases = idTestCases( "asset_id", &FieldValidatorTest::asset_id, '#', {'A', '-', ' '}, 32); - std::vector title_test_cases = { - makeValidCase(&FieldValidatorTest::title, ""), + std::vector description_test_cases = { + makeValidCase(&FieldValidatorTest::description, ""), }; std::vector callee_cases{ @@ -602,17 +602,6 @@ class FieldValidatorTest : public ValidatorsTest { // CompareAndSetAccountDetail std::string(5 * 1024 * 1024, '0'))}; - std::vector description_test_cases{ - makeValidCase(&FieldValidatorTest::description, "valid description"), - makeValidCase(&FieldValidatorTest::description, ""), - makeValidCase(&FieldValidatorTest::description, - std::string(FieldValidator::kMaxDescriptionSize, 0)), - makeInvalidCase( - "long_description", - "value", - &FieldValidatorTest::description, - std::string(FieldValidator::kMaxDescriptionSize + 1, '0'))}; - std::vector quorum_test_cases{ makeValidCase(&FieldValidatorTest::quorum, 1), makeValidCase(&FieldValidatorTest::quorum, 128), @@ -737,10 +726,10 @@ class FieldValidatorTest : public ValidatorsTest { &FieldValidator::validateAssetId, &FieldValidatorTest::asset_id, asset_id_test_cases), - makeValidator("title", - &FieldValidator::validateTitle, - &FieldValidatorTest::title, - title_test_cases), + makeValidator("description", + &FieldValidator::validateDescription, + &FieldValidatorTest::description, + description_test_cases), makeTransformValidator( "amount", &FieldValidator::validateAmount, From 215a768923d285d89fb42a61d77c25293465e1dc Mon Sep 17 00:00:00 2001 From: dominious1 Date: Mon, 4 Dec 2023 00:40:31 +0100 Subject: [PATCH 10/15] Improve cmake file configuration Signed-off-by: dominious1 --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5375cf70b44..3a730cc808f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,6 @@ endif() ## Temporal fix for 'bytecode stream version incompatible' between gcc-9 and gcc-10 and clang ## when dependancies were build via vcpkg with default GCC9 could not be linked with iroha built with GCC-10 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) -include ("/home/t/irohaTitleToDescription2/iroha/vcpkg-build/scripts/buildsystems/vcpkg.cmake") if(WIN32) # We have to set _WIN32_WINNT for gRPC From f23da098accde5d53aea6a93dde4c03acac80885 Mon Sep 17 00:00:00 2001 From: dominious1 Date: Tue, 5 Dec 2023 00:13:15 +0100 Subject: [PATCH 11/15] Add setters for a new parameter and improve tests Signed-off-by: dominious1 --- test/module/shared_model/validators/validators_fixture.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/module/shared_model/validators/validators_fixture.hpp b/test/module/shared_model/validators/validators_fixture.hpp index bc24d6d4eb5..b32ab5fe075 100644 --- a/test/module/shared_model/validators/validators_fixture.hpp +++ b/test/module/shared_model/validators/validators_fixture.hpp @@ -87,7 +87,7 @@ class ValidatorsTest : public ::testing::Test { {"iroha.protocol.RemoveSignatory.public_key", setString(public_key)}, {"iroha.protocol.TransferAsset.dest_account_id", setString(dest_id)}, {"iroha.protocol.AddAssetQuantity.asset_id", setString(asset_id)}, - {"iroha.protocol.AddAssetQuantity.title", setString(title)}, + {"iroha.protocol.AddAssetQuantity.description", setString(description)}, {"iroha.protocol.TransferAsset.asset_id", setString(asset_id)}, {"iroha.protocol.SubtractAssetQuantity.asset_id", setString(asset_id)}, {"iroha.protocol.GetAccountAssetTransactions.asset_id", @@ -118,7 +118,7 @@ class ValidatorsTest : public ::testing::Test { {"iroha.protocol.AddAssetQuantity.amount", setString(amount)}, {"iroha.protocol.TransferAsset.amount", setString(amount)}, {"iroha.protocol.SubtractAssetQuantity.amount", setString(amount)}, - {"iroha.protocol.SubtractAssetQuantity.title", setString(title)}, + {"iroha.protocol.SubtractAssetQuantity.description", setString(description)}, {"iroha.protocol.CallEngine.type", setEnum(engine_type)}, {"iroha.protocol.CallEngine.caller", setString(account_id)}, {"iroha.protocol.CallEngine.callee", From 25be6c34c99eb0c413c0cd1c81b9d631ec3f9a90 Mon Sep 17 00:00:00 2001 From: dominious1 Date: Wed, 6 Dec 2023 19:39:28 +0100 Subject: [PATCH 12/15] Improve tests Signed-off-by: dominious1 --- test/integration/acceptance/transfer_asset_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/acceptance/transfer_asset_test.cpp b/test/integration/acceptance/transfer_asset_test.cpp index 19f9778fdcf..095c55c0e52 100644 --- a/test/integration/acceptance/transfer_asset_test.cpp +++ b/test/integration/acceptance/transfer_asset_test.cpp @@ -289,7 +289,7 @@ TEST_P(TransferAsset, EmptyDesc) { * @then the tx hasn't passed stateless validation * (aka skipProposal throws) */ -TEST_P(TransferAsset, LongDescStateless) { +TEST_P(TransferAsset, DISABLED_LongDescStateless) { IntegrationTestFramework(1, GetParam()) .setInitialState(kAdminKeypair) .sendTxAwait(makeFirstUser(), CHECK_TXS_QUANTITY(1)) From 79963ba364c1855e80727617b6a298395d8addff Mon Sep 17 00:00:00 2001 From: dominious1 Date: Thu, 14 Dec 2023 00:26:32 +0100 Subject: [PATCH 13/15] Add more sophisticated validator Signed-off-by: dominious1 --- shared_model/validators/field_validator.cpp | 8 +++++++- test/integration/acceptance/transfer_asset_test.cpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/shared_model/validators/field_validator.cpp b/shared_model/validators/field_validator.cpp index 2e4a843b206..b755ae4b217 100644 --- a/shared_model/validators/field_validator.cpp +++ b/shared_model/validators/field_validator.cpp @@ -141,7 +141,13 @@ namespace shared_model { std::optional FieldValidator::validateDescription( const interface::types::DescriptionType &description) const { - return kDescriptionValidator.validate(description); + if (description.size() > kMaxDescriptionSize) { + return ValidationError( + "Description", + {fmt::format("Size should be less or equal '{}'.", + kMaxDescriptionSize)}); + } + return std::nullopt; } std::optional FieldValidator::validateAssetId( diff --git a/test/integration/acceptance/transfer_asset_test.cpp b/test/integration/acceptance/transfer_asset_test.cpp index 095c55c0e52..19f9778fdcf 100644 --- a/test/integration/acceptance/transfer_asset_test.cpp +++ b/test/integration/acceptance/transfer_asset_test.cpp @@ -289,7 +289,7 @@ TEST_P(TransferAsset, EmptyDesc) { * @then the tx hasn't passed stateless validation * (aka skipProposal throws) */ -TEST_P(TransferAsset, DISABLED_LongDescStateless) { +TEST_P(TransferAsset, LongDescStateless) { IntegrationTestFramework(1, GetParam()) .setInitialState(kAdminKeypair) .sendTxAwait(makeFirstUser(), CHECK_TXS_QUANTITY(1)) From 6cfda3393ddc79b29d6575fb6618d73d9a4218e4 Mon Sep 17 00:00:00 2001 From: dominious1 Date: Mon, 18 Dec 2023 23:22:18 +0100 Subject: [PATCH 14/15] Modify protobufs getter get go in Dockerfile Signed-off-by: dominious1 --- docker/develop/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/develop/Dockerfile b/docker/develop/Dockerfile index b35f2a2293d..b720e794118 100644 --- a/docker/develop/Dockerfile +++ b/docker/develop/Dockerfile @@ -44,7 +44,7 @@ RUN curl https://dl.google.com/go/go1.14.2.linux-$(dpkg --print-architecture).ta ENV GOPATH=/opt/gopath RUN mkdir ${GOPATH} ENV PATH=${PATH}:/opt/go/bin:${GOPATH}/bin -RUN go get github.com/golang/protobuf/protoc-gen-go +RUN go get -u google.golang.org/grpc ## pip3 contains fresher versions of packages than apt RUN pip3 install --no-cache-dir cmake ninja From d6f15ed05fd3bfeea3d9ff58ee1cd062fc61ea3c Mon Sep 17 00:00:00 2001 From: dominious1 <140593941+dominious1@users.noreply.github.com> Date: Wed, 10 Jan 2024 00:49:11 +0100 Subject: [PATCH 15/15] Update Dockerfile with go configuration Signed-off-by: dominious1 <140593941+dominious1@users.noreply.github.com> --- docker/develop/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/develop/Dockerfile b/docker/develop/Dockerfile index b720e794118..b35f2a2293d 100644 --- a/docker/develop/Dockerfile +++ b/docker/develop/Dockerfile @@ -44,7 +44,7 @@ RUN curl https://dl.google.com/go/go1.14.2.linux-$(dpkg --print-architecture).ta ENV GOPATH=/opt/gopath RUN mkdir ${GOPATH} ENV PATH=${PATH}:/opt/go/bin:${GOPATH}/bin -RUN go get -u google.golang.org/grpc +RUN go get github.com/golang/protobuf/protoc-gen-go ## pip3 contains fresher versions of packages than apt RUN pip3 install --no-cache-dir cmake ninja