From 196860801853d418916736addca081105b1afe0e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 22 Oct 2024 14:46:28 +0400 Subject: [PATCH 1/4] fix for android --- src/currency_core/currency_format_utils.h | 2 ++ src/wallet/wallet2.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 2fab77e1..c8fe36a1 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -950,6 +950,7 @@ namespace currency } } } + /* //--------------------------------------------------------------- template typename std::enable_if_t, std::ostream&> operator<<(std::ostream& o, invocable_t callee) @@ -957,6 +958,7 @@ namespace currency callee(o); return o; } + */ //--------------------------------------------------------------- std::ostream& operator <<(std::ostream& o, const ref_by_id& r); std::ostream& operator <<(std::ostream& o, const std::type_info& ti); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f4b203ad..c9765b93 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -397,8 +397,10 @@ const crypto::public_key& wallet2::out_get_pub_key(const currency::tx_out_v& out //---------------------------------------------------------------------------------------------------- void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_operation& ado, process_transaction_context& ptc) { - auto print_ado_owner = [ado](std::ostream& o){ + auto print_ado_owner = [ado](/*std::ostream& o*/) { + std::stringstream o; ado.descriptor.owner_eth_pub_key.has_value() ? o << ado.descriptor.owner_eth_pub_key.value() << " (ETH)" : o << ado.descriptor.owner; + return o.str(); }; do @@ -424,7 +426,7 @@ void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_op std::stringstream ss; ss << "New Asset Registered:" << ENDL << "asset id: " << asset_id - << ENDL << "Owner: " << print_ado_owner + << ENDL << "Owner: " << print_ado_owner() << ENDL << "Name: " << asset_context.full_name << ENDL << "Ticker: " << asset_context.ticker << ENDL << "Total Max Supply: " << print_asset_money(asset_context.total_max_supply, asset_context.decimal_point) @@ -492,7 +494,7 @@ void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_op std::stringstream ss; ss << "Asset ownership lost:" << ENDL << "asset id: " << asset_id - << ENDL << "New owner: " << print_ado_owner + << ENDL << "New owner: " << print_ado_owner() << ENDL << "Name: " << ado.descriptor.full_name << ENDL << "Ticker: " << ado.descriptor.ticker << ENDL << "Total Max Supply: " << print_asset_money(ado.descriptor.total_max_supply, ado.descriptor.decimal_point) From fbf0d413a8229cf0ce2b9af168c4e31611e8b478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=D1=91pa=20Dolgorukov?= Date: Tue, 22 Oct 2024 17:34:19 +0500 Subject: [PATCH 2/4] Get rid of the compiler warning "not all control paths return a value" (#472) --- tests/core_tests/tx_validation.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index ea5f6b38..138f8746 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -2076,6 +2076,8 @@ bool tx_pool_semantic_validation::generate(std::vector& events { return sum + boost::get(input).amount; } + + return sum; } }; @@ -2085,6 +2087,8 @@ bool tx_pool_semantic_validation::generate(std::vector& events { return sum + boost::get(output).amount; } + + return sum; } }; From 0cd719474b55647c6636a3c3436bd65c68201665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=D1=91pa=20Dolgorukov?= Date: Tue, 22 Oct 2024 17:47:36 +0500 Subject: [PATCH 3/4] unit_tests: reimplement "get_or_calculate_asset_id" tests, fix "get_or_calculate_asset_id" due to serialization changes (#467) --- tests/unit_tests/multiassets_test.cpp | 1790 ++++++++++--------------- 1 file changed, 711 insertions(+), 1079 deletions(-) diff --git a/tests/unit_tests/multiassets_test.cpp b/tests/unit_tests/multiassets_test.cpp index a996acad..aa577d17 100644 --- a/tests/unit_tests/multiassets_test.cpp +++ b/tests/unit_tests/multiassets_test.cpp @@ -4,7 +4,6 @@ #include -#include #include #include @@ -24,18 +23,18 @@ namespace currency struct asset_descriptor_operation_v0; } -// develop, commit 0c90262e8a1c4e5e5d052f8db84c60a36691414d +// branch = develop, HEAD = 0c90262e8a1c4e5e5d052f8db84c60a36691414d struct currency::asset_descriptor_base_v0 { - uint64_t total_max_supply = 0; - uint64_t current_supply = 0; - uint8_t decimal_point = 0; - std::string ticker; - std::string full_name; - std::string meta_info; - crypto::public_key owner = currency::null_pkey; // consider premultipling by 1/8 - bool hidden_supply = false; - uint8_t version = 0; + uint64_t total_max_supply; + uint64_t current_supply; + uint8_t decimal_point; + std::string ticker; + std::string full_name; + std::string meta_info; + crypto::public_key owner = currency::null_pkey; // consider premultipling by 1/8 + bool hidden_supply; + uint8_t version; BEGIN_VERSIONED_SERIALIZE(0, version) FIELD(total_max_supply) @@ -57,22 +56,24 @@ struct currency::asset_descriptor_base_v0 BOOST_SERIALIZE(meta_info) BOOST_SERIALIZE(owner) BOOST_SERIALIZE(hidden_supply) + BOOST_END_VERSION_UNDER(1) END_BOOST_SERIALIZATION() BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(total_max_supply) DOC_DSCR("Maximum possible supply for given asset, can't be changed after deployment") DOC_EXMP(1000000000000000000) DOC_END - KV_SERIALIZE(current_supply) DOC_DSCR("Currently emitted supply for given asset (ignored for REGISTER operation)") DOC_EXMP(500000000000000000) DOC_END - KV_SERIALIZE(decimal_point) DOC_DSCR("Decimal point") DOC_EXMP(12) DOC_END - KV_SERIALIZE(ticker) DOC_DSCR("Ticker associated with asset") DOC_EXMP("ZUSD") DOC_END - KV_SERIALIZE(full_name) DOC_DSCR("Full name of the asset") DOC_EXMP("Zano wrapped USD") DOC_END - KV_SERIALIZE(meta_info) DOC_DSCR("Any other information assetiaded with asset in a free form") DOC_EXMP("Stable and private") DOC_END - KV_SERIALIZE_POD_AS_HEX_STRING(owner) DOC_DSCR("Owner's key, used only for EMIT and UPDATE validation, could be changed by transferring asset ownership") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END - KV_SERIALIZE(hidden_supply) DOC_DSCR("This one reserved for future use, will be documented later") DOC_END + KV_SERIALIZE(total_max_supply) DOC_DSCR("Maximum possible supply for a given asset, cannot be changed after deployment.") DOC_EXMP(1000000000000000000) DOC_END + KV_SERIALIZE(current_supply) DOC_DSCR("Currently emitted supply for the given asset (ignored for REGISTER operation).") DOC_EXMP(500000000000000000) DOC_END + KV_SERIALIZE(decimal_point) DOC_DSCR("Decimal point.") DOC_EXMP(12) DOC_END + KV_SERIALIZE(ticker) DOC_DSCR("Ticker associated with the asset.") DOC_EXMP("ZABC") DOC_END + KV_SERIALIZE(full_name) DOC_DSCR("Full name of the asset.") DOC_EXMP("Zano wrapped ABC") DOC_END + KV_SERIALIZE(meta_info) DOC_DSCR("Any other information associated with the asset in free form.") DOC_EXMP("Stable and private") DOC_END + KV_SERIALIZE_POD_AS_HEX_STRING(owner) DOC_DSCR("Owner's key, used only for EMIT and UPDATE validation, can be changed by transferring asset ownership.") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END + KV_SERIALIZE(hidden_supply) DOC_DSCR("This field is reserved for future use and will be documented later.") DOC_END END_KV_SERIALIZE_MAP() operator currency::asset_descriptor_base() const { currency::asset_descriptor_base asset_descriptor{}; + asset_descriptor.total_max_supply = total_max_supply; asset_descriptor.current_supply = current_supply; asset_descriptor.decimal_point = decimal_point; @@ -82,10 +83,12 @@ struct currency::asset_descriptor_base_v0 asset_descriptor.owner = owner; asset_descriptor.hidden_supply = hidden_supply; asset_descriptor.version = version; + return asset_descriptor; } }; +// branch = develop, HEAD = 0c90262e8a1c4e5e5d052f8db84c60a36691414d struct currency::asset_descriptor_operation_v0 { uint8_t operation_type = ASSET_DESCRIPTOR_OPERATION_UNDEFINED; @@ -100,7 +103,7 @@ struct currency::asset_descriptor_operation_v0 FIELD(amount_commitment) END_VERSION_UNDER(1) FIELD(opt_asset_id) - END_SERIALIZE() + END_SERIALIZE() BEGIN_BOOST_SERIALIZATION() BOOST_SERIALIZE(operation_type) @@ -111,15 +114,16 @@ struct currency::asset_descriptor_operation_v0 END_BOOST_SERIALIZATION() BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(operation_type) DOC_DSCR("Asset operation type identifier") DOC_EXMP(1) DOC_END - KV_SERIALIZE(descriptor) DOC_DSCR("Asset descriptor") DOC_EXMP_AUTO() DOC_END - KV_SERIALIZE_POD_AS_HEX_STRING(amount_commitment) DOC_DSCR("Amount commitment") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END - KV_SERIALIZE_POD_AS_HEX_STRING(opt_asset_id) DOC_DSCR("ID of an asset.") DOC_EXMP("cc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6") DOC_END + KV_SERIALIZE(operation_type) DOC_DSCR("Asset operation type identifier") DOC_EXMP(1) DOC_END + KV_SERIALIZE(descriptor) DOC_DSCR("Asset descriptor") DOC_EXMP_AUTO() DOC_END + KV_SERIALIZE_POD_AS_HEX_STRING(amount_commitment) DOC_DSCR("Amount commitment") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END + KV_SERIALIZE_POD_AS_HEX_STRING(opt_asset_id) DOC_DSCR("ID of an asset.") DOC_EXMP("cc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6") DOC_END END_KV_SERIALIZE_MAP() operator currency::asset_descriptor_operation() const { currency::asset_descriptor_operation operation_descriptor{}; + operation_descriptor.operation_type = operation_type; operation_descriptor.descriptor = descriptor; operation_descriptor.amount_commitment = amount_commitment; @@ -130,1185 +134,813 @@ struct currency::asset_descriptor_operation_v0 } }; +BOOST_CLASS_VERSION(currency::asset_descriptor_base_v0, 0); BOOST_CLASS_VERSION(currency::asset_descriptor_operation_v0, 1); -currency::asset_descriptor_base get_asset_descriptor_for_test( - const crypto::public_key& owner = currency::null_pkey) +template +static asset_descriptor get_adb(const crypto::public_key& owner = currency::null_pkey) { - currency::asset_descriptor_base descriptor_base{}; - descriptor_base.total_max_supply = 100; - descriptor_base.current_supply = 50; - descriptor_base.decimal_point = 0; - descriptor_base.ticker = "HLO"; - descriptor_base.full_name = "HELLO_WORLD"; - descriptor_base.meta_info = "Hello, world!"; - descriptor_base.owner = owner; - descriptor_base.hidden_supply = false; - descriptor_base.version = 1; + if (const auto& id{typeid(asset_descriptor)}; id != typeid(currency::asset_descriptor_base) && id != typeid(currency::asset_descriptor_base_v0)) + { + throw "Unsupported type of an asset descriptor"; + } - return descriptor_base; + asset_descriptor descriptor{}; + + descriptor.total_max_supply = 100; + descriptor.current_supply = 50; + descriptor.decimal_point = 0; + descriptor.ticker = "HLO"; + descriptor.full_name = "HELLO_WORLD"; + descriptor.meta_info = "Hello, world!"; + descriptor.owner = owner; + descriptor.hidden_supply = false; + + if (typeid(asset_descriptor) == typeid(currency::asset_descriptor_base)) + { + descriptor.version = 1; + } + + return descriptor; } -currency::asset_descriptor_base_v0 get_asset_descriptor_v0_for_test( - const crypto::public_key& owner = currency::null_pkey) +template +static asset_operation_descriptor get_ado(const asset_base_descriptor& base_descriptor, std::uint8_t operation = ASSET_DESCRIPTOR_OPERATION_UNDEFINED, + std::optional asset_id = currency::null_pkey) { - currency::asset_descriptor_base_v0 descriptor_base{}; - descriptor_base.total_max_supply = 100; - descriptor_base.current_supply = 50; - descriptor_base.decimal_point = 0; - descriptor_base.ticker = "HLO"; - descriptor_base.full_name = "HELLO_WORLD"; - descriptor_base.meta_info = "Hello, world!"; - descriptor_base.owner = owner; - descriptor_base.hidden_supply = false; + if (const auto& id{typeid(asset_operation_descriptor)}; id != typeid(currency::asset_descriptor_operation) && id != typeid(currency::asset_descriptor_operation_v0)) + { + throw "Unsupported type of an asset operation descriptor"; + } - return descriptor_base; + if (const auto& id{typeid(asset_base_descriptor)}; id != typeid(currency::asset_descriptor_base) && id != typeid(currency::asset_descriptor_base_v0)) + { + throw "Unsupported type of an asset base descriptor"; + } + + asset_operation_descriptor descriptor{}; + descriptor.operation_type = operation; + descriptor.descriptor = base_descriptor; + descriptor.amount_commitment = currency::null_pkey; + + if (asset_id.has_value()) + { + descriptor.opt_asset_id = asset_id.value(); + } + + return descriptor; } -currency::asset_descriptor_operation get_asset_descriptor_operation_for_test( - currency::asset_descriptor_base asset_descriptor, - std::uint8_t operation = ASSET_DESCRIPTOR_OPERATION_UNDEFINED -) +enum class serialization_method : uint8_t { - currency::asset_descriptor_operation descriptor_operation{}; - descriptor_operation.operation_type = operation; - descriptor_operation.descriptor = asset_descriptor; - descriptor_operation.amount_commitment = currency::null_pkey; + native, + boost, + key_value +}; - return descriptor_operation; +template +static std::optional serialize(serialization_method method, const asset_operation_descriptor& descriptor) +{ + if (const auto& id{typeid(asset_operation_descriptor)}; id != typeid(currency::asset_descriptor_operation) && id != typeid(currency::asset_descriptor_operation_v0)) + { + throw "Unsupported type of an asset descriptor operation"; + } + + std::function serialization_function{}; + + switch (method) + { + case serialization_method::native: + serialization_function = static_cast(t_serializable_object_to_blob); + break; + + case serialization_method::boost: + serialization_function = static_cast(tools::serialize_obj_to_buff); + break; + + case serialization_method::key_value: + serialization_function = [](const asset_operation_descriptor& descriptor, std::string& presentation) -> bool + { + return epee::serialization::store_t_to_json(descriptor, presentation); + }; + break; + } + + if (std::string presentation{}; serialization_function.operator bool() && serialization_function(descriptor, presentation)) + { + return presentation; + } + + return {}; } -currency::asset_descriptor_operation_v0 -get_asset_descriptor_operation_v0_for_test( - currency::asset_descriptor_base_v0 asset_descriptor, - std::uint8_t operation = ASSET_DESCRIPTOR_OPERATION_UNDEFINED -) +template +static std::optional deserialize(serialization_method method, const std::string& presentation) { - currency::asset_descriptor_operation_v0 descriptor_operation{}; - descriptor_operation.operation_type = operation; - descriptor_operation.descriptor = asset_descriptor; - descriptor_operation.amount_commitment = currency::null_pkey; + if (const auto& id{typeid(asset_operation_descriptor)}; id != typeid(currency::asset_descriptor_operation) && id != typeid(currency::asset_descriptor_operation_v0)) + { + throw "Unsupported type of an asset descriptor operation"; + } - return descriptor_operation; + std::function deserialization_function{}; + + switch (method) + { + case serialization_method::native: + deserialization_function = t_unserializable_object_from_blob; + break; + + case serialization_method::boost: + deserialization_function = tools::unserialize_obj_from_buff; + break; + + case serialization_method::key_value: + deserialization_function = epee::serialization::load_t_from_json; + break; + } + + if (asset_operation_descriptor descriptor{}; deserialization_function.operator bool() && deserialization_function(descriptor, presentation)) + { + return descriptor; + } + + return {}; } -TEST(multiassets, get_or_calculate_asset_id_register) +static std::string get_string_presentation(const std::string& data) { - bool success{false}; + std::string presentation{}; - crypto::point_t pt_public_key{}; - success = pt_public_key.from_string( - "cf93bead4d2a8d6d174c1752237b2e5208a594b59618683ee50ef209cf1efb19"); + for (int position{}; position < data.size(); ++position) + { + const auto character{static_cast(data.at(position))}; - ASSERT_TRUE(success); + if (std::isprint(character)) + { + presentation += '\''; - crypto::public_key owner_public_key{}; - pt_public_key.to_public_key(owner_public_key); + if (character == '\'') + { + presentation += '\\'; + } - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; + presentation += character; + presentation += '\''; + } - const auto asset_descriptor{get_asset_descriptor_for_test(owner_public_key)}; + else + { + std::stringstream stream{}; - const auto asset_operation_descriptor{ - get_asset_descriptor_operation_for_test(asset_descriptor, - ASSET_DESCRIPTOR_OPERATION_REGISTER)}; + presentation += "\'\\x"; + stream << std::hex << std::setw(2) << std::setfill('0') << static_cast(character); + presentation += stream.str(); + presentation += '\''; + } - success = currency::get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); + if (position < data.size() - 1) + { + presentation += ", "; + } + } - ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "6f46324faae448b9e3b96dac94da17be6ab7eaaba398de86d8743042c98bace0"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - const crypto::public_key expected_asset_id_key{ - expected_asset_id_pt.to_public_key()}; - - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); -} - -TEST(multiassets, get_or_calculate_asset_id_emit) -{ - bool success{false}; - - crypto::point_t pt_public_key{}; - success = pt_public_key.from_string( - "edab571c4be9eabfea5e7883036d744c097382eb6f739a914db06f72ba35099d"); - - ASSERT_TRUE(success); - - crypto::public_key owner_public_key{}; - pt_public_key.to_public_key(owner_public_key); - - const auto asset_descriptor{ - get_asset_descriptor_for_test(owner_public_key)}; - - auto asset_operation_descriptor{ - get_asset_descriptor_operation_for_test( - asset_descriptor, ASSET_DESCRIPTOR_OPERATION_REGISTER)}; - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); - - ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "49a3d6652aaa0b3b77292c534e91ff80de9120aeb6fc1c5edc728047437d667e"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - const crypto::public_key expected_asset_id_key{ - expected_asset_id_pt.to_public_key()}; - - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); - - asset_operation_descriptor.opt_asset_id = calculated_asset_id_key; - asset_operation_descriptor.operation_type = ASSET_DESCRIPTOR_OPERATION_EMIT; - - success = get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); - - ASSERT_TRUE(success); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); -} - -TEST(multiassets, get_or_calculate_asset_id_update) -{ - bool success{false}; - - crypto::point_t pt_public_key{}; - success = pt_public_key.from_string( - "8cb6349f51da6599feeae7c0077293436eb6a5000f0e6e706e77886bb540e2c1"); - - ASSERT_TRUE(success); - - crypto::public_key owner_public_key{}; - pt_public_key.to_public_key(owner_public_key); - - const auto asset_descriptor{ - get_asset_descriptor_for_test(owner_public_key)}; - - auto asset_operation_descriptor{ - get_asset_descriptor_operation_for_test( - asset_descriptor, ASSET_DESCRIPTOR_OPERATION_REGISTER)}; - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); - - ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "c371f60dd8333298c6aa746b71e1e20527b1ff5e1bed4ea9b5f592fadf90ed6b"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - const crypto::public_key expected_asset_id_key{ - expected_asset_id_pt.to_public_key()}; - - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); - - asset_operation_descriptor.opt_asset_id = calculated_asset_id_key; - asset_operation_descriptor.operation_type = ASSET_DESCRIPTOR_OPERATION_UPDATE; - - success = get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); - - ASSERT_TRUE(success); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); -} - -TEST(multiassets, get_or_calculate_asset_id_public_burn) -{ - bool success{false}; - - crypto::point_t pt_public_key{}; - success = pt_public_key.from_string( - "0c408cf8b7fb808f40593d6eb75890e2ab3d0ccdc7014a7fc6b6ab05163be060"); - - ASSERT_TRUE(success); - - crypto::public_key owner_public_key{}; - pt_public_key.to_public_key(owner_public_key); - - const auto asset_descriptor{ - get_asset_descriptor_for_test(owner_public_key)}; - - auto asset_operation_descriptor{ - get_asset_descriptor_operation_for_test( - asset_descriptor, ASSET_DESCRIPTOR_OPERATION_REGISTER)}; - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); - - ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "54f3f72c72e5b014ad2b2b9001acef954fe82dd3ed56a38cd9ddc5db57673f8f"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - const crypto::public_key expected_asset_id_key{ - expected_asset_id_pt.to_public_key()}; - - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); - - asset_operation_descriptor.opt_asset_id = calculated_asset_id_key; - asset_operation_descriptor.operation_type = - ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN; - - success = get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); - - ASSERT_TRUE(success); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + return presentation; } TEST(multiassets, get_or_calculate_asset_id_undefined) { - bool success{false}; - - crypto::point_t pt_public_key{}; - success = pt_public_key.from_string( - "e91b9a73292d6ea46fb3d4f4cc79c34bfb7d14c2e684e58093a2471c92e51c16"); + bool success{}; + crypto::point_t point_owner{}; + crypto::public_key owner{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + currency::asset_descriptor_base adb{}; + currency::asset_descriptor_operation ado{}; + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + success = point_owner.from_string("e91b9a73292d6ea46fb3d4f4cc79c34bfb7d14c2e684e58093a2471c92e51c16"); ASSERT_TRUE(success); - - crypto::public_key owner_public_key{}; - pt_public_key.to_public_key(owner_public_key); - - const auto asset_descriptor{ - get_asset_descriptor_for_test(owner_public_key)}; - - auto asset_operation_descriptor{ - get_asset_descriptor_operation_for_test( - asset_descriptor, ASSET_DESCRIPTOR_OPERATION_REGISTER)}; - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); - + owner = point_owner.to_public_key(); + adb = get_adb(owner); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_REGISTER); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "979eb706ace2eb83f9125658b23fb352208480cb3b90c43e2df0d298f9754ebc"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); + success = expected_point_asset_id.from_string("979eb706ace2eb83f9125658b23fb352208480cb3b90c43e2df0d298f9754ebc"); ASSERT_TRUE(success); - - const crypto::public_key expected_asset_id_key{ - expected_asset_id_pt.to_public_key()}; - - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); - - asset_operation_descriptor.opt_asset_id = calculated_asset_id_key; - asset_operation_descriptor.operation_type = - ASSET_DESCRIPTOR_OPERATION_UNDEFINED; - - success = get_or_calculate_asset_id(asset_operation_descriptor, - &calculated_asset_id_pt, - &calculated_asset_id_key); - + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + ASSERT_EQ(calculated_asset_id, expected_asset_id); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_UNDEFINED, calculated_asset_id); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); ASSERT_FALSE(success); } -TEST(multiassets, get_or_calculate_asset_id_register_serialization) +TEST(multiassets, get_or_calculate_asset_id_register) { - bool success{false}; - currency::asset_descriptor_operation asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x01', '\x01', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x03', 'H', 'L', 'O', '\x0b', 'H', 'E', - 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', - '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', - 'o', 'r', 'l', 'd', '!', '\xcf', '\x93', '\xbe', '\xad', - 'M', '*', '\x8d', 'm', '\x17', 'L', '\x17', 'R', '#', - '{', '.', 'R', '\x08', '\xa5', '\x94', '\xb5', '\x96', '\x18', - 'h', '>', '\xe5', '\x0e', '\xf2', '\x09', '\xcf', '\x1e', '\xfb', - '\x19', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'o', - 'F', '2', 'O', '\xaa', '\xe4', 'H', '\xb9', '\xe3', '\xb9', - 'm', '\xac', '\x94', '\xda', '\x17', '\xbe', 'j', '\xb7', '\xea', - '\xab', '\xa3', '\x98', '\xde', '\x86', '\xd8', 't', '0', 'B', - '\xc9', '\x8b', '\xac', '\xe0'}; + bool success{}; + crypto::point_t point_owner{}; + crypto::public_key owner{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + currency::asset_descriptor_base adb{}; + currency::asset_descriptor_operation ado{}; + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; - success = t_unserializable_object_from_blob(asset_descriptor_operation, - serialized_asset_descriptor_operation); + success = point_owner.from_string("cf93bead4d2a8d6d174c1752237b2e5208a594b59618683ee50ef209cf1efb19"); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + point_owner.to_public_key(owner); + adb = get_adb(owner); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_REGISTER); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "6f46324faae448b9e3b96dac94da17be6ab7eaaba398de86d8743042c98bace0"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); + success = expected_point_asset_id.from_string("6f46324faae448b9e3b96dac94da17be6ab7eaaba398de86d8743042c98bace0"); ASSERT_TRUE(success); - - const crypto::public_key expected_asset_id_key{ - expected_asset_id_pt.to_public_key()}; - - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_emit_serialization) +TEST(multiassets, get_or_calculate_asset_id_emit) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x01', '\x02', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x03', 'H', 'L', 'O', '\x0b', 'H', 'E', - 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', - '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', - 'o', 'r', 'l', 'd', '!', '\xed', '\xab', 'W', '\x1c', - 'K', '\xe9', '\xea', '\xbf', '\xea', '^', 'x', '\x83', '\x03', - 'm', 't', 'L', '\x09', 's', '\x82', '\xeb', 'o', 's', - '\x9a', '\x91', 'M', '\xb0', 'o', 'r', '\xba', '5', '\x09', - '\x9d', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'I', - '\xa3', '\xd6', 'e', '*', '\xaa', '\x0b', ';', 'w', ')', - ',', 'S', 'N', '\x91', '\xff', '\x80', '\xde', '\x91', ' ', - '\xae', '\xb6', '\xfc', '\x1c', '^', '\xdc', 'r', '\x80', 'G', - 'C', '}', 'f', '~'}; + bool success{}; + crypto::point_t point_owner{}; + crypto::public_key owner{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + currency::asset_descriptor_base adb{}; + currency::asset_descriptor_operation ado{}; + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; - success = t_unserializable_object_from_blob(asset_descriptor_operation, - serialized_asset_descriptor_operation); + success = point_owner.from_string("edab571c4be9eabfea5e7883036d744c097382eb6f739a914db06f72ba35099d"); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + owner = point_owner.to_public_key(); + adb = get_adb(owner); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_REGISTER); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "49a3d6652aaa0b3b77292c534e91ff80de9120aeb6fc1c5edc728047437d667e"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); + success = expected_point_asset_id.from_string("49a3d6652aaa0b3b77292c534e91ff80de9120aeb6fc1c5edc728047437d667e"); ASSERT_TRUE(success); - - crypto::public_key expected_asset_id_key{}; - expected_asset_id_pt.to_public_key(expected_asset_id_key); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + ASSERT_EQ(calculated_asset_id, expected_asset_id); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_EMIT, calculated_asset_id); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); + ASSERT_TRUE(success); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_update_serialization) +TEST(multiassets, get_or_calculate_asset_id_update) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x01', '\x03', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x03', 'H', 'L', 'O', '\x0b', 'H', 'E', - 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', - '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', - 'o', 'r', 'l', 'd', '!', '\x8c', '\xb6', '4', '\x9f', - 'Q', '\xda', 'e', '\x99', '\xfe', '\xea', '\xe7', '\xc0', '\x07', - 'r', '\x93', 'C', 'n', '\xb6', '\xa5', '\x00', '\x0f', '\x0e', - 'n', 'p', 'n', 'w', '\x88', 'k', '\xb5', '@', '\xe2', - '\xc1', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xc3', - 'q', '\xf6', '\x0d', '\xd8', '3', '2', '\x98', '\xc6', '\xaa', - 't', 'k', 'q', '\xe1', '\xe2', '\x05', '\'', '\xb1', '\xff', - '^', '\x1b', '\xed', 'N', '\xa9', '\xb5', '\xf5', '\x92', '\xfa', - '\xdf', '\x90', '\xed', 'k'}; + bool success{}; + crypto::point_t point_owner{}; + crypto::public_key owner{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + currency::asset_descriptor_base adb{}; + currency::asset_descriptor_operation ado{}; + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; - success = t_unserializable_object_from_blob(asset_descriptor_operation, - serialized_asset_descriptor_operation); + success = point_owner.from_string("8cb6349f51da6599feeae7c0077293436eb6a5000f0e6e706e77886bb540e2c1"); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + owner = point_owner.to_public_key(); + adb = get_adb(owner); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_REGISTER); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "c371f60dd8333298c6aa746b71e1e20527b1ff5e1bed4ea9b5f592fadf90ed6b"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); + success = expected_point_asset_id.from_string("c371f60dd8333298c6aa746b71e1e20527b1ff5e1bed4ea9b5f592fadf90ed6b"); ASSERT_TRUE(success); - - crypto::public_key expected_asset_id_key{}; - expected_asset_id_pt.to_public_key(expected_asset_id_key); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + ASSERT_EQ(calculated_asset_id, expected_asset_id); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_UPDATE, calculated_asset_id); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); + ASSERT_TRUE(success); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_public_burn_serialization) +TEST(multiassets, get_or_calculate_asset_id_public_burn) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x01', '\x04', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x03', 'H', 'L', 'O', '\x0b', 'H', 'E', - 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', - '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', - 'o', 'r', 'l', 'd', '!', '\x0c', '@', '\x8c', '\xf8', - '\xb7', '\xfb', '\x80', '\x8f', '@', 'Y', '=', 'n', '\xb7', - 'X', '\x90', '\xe2', '\xab', '=', '\x0c', '\xcd', '\xc7', '\x01', - 'J', '\x7f', '\xc6', '\xb6', '\xab', '\x05', '\x16', ';', '\xe0', - '`', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'T', - '\xf3', '\xf7', ',', 'r', '\xe5', '\xb0', '\x14', '\xad', '+', - '+', '\x90', '\x01', '\xac', '\xef', '\x95', 'O', '\xe8', '-', - '\xd3', '\xed', 'V', '\xa3', '\x8c', '\xd9', '\xdd', '\xc5', '\xdb', - 'W', 'g', '?', '\x8f'}; + bool success{}; + crypto::point_t point_owner{}; + crypto::public_key owner{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + currency::asset_descriptor_base adb{}; + currency::asset_descriptor_operation ado{}; + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; - success = t_unserializable_object_from_blob(asset_descriptor_operation, - serialized_asset_descriptor_operation); + success = point_owner.from_string("0c408cf8b7fb808f40593d6eb75890e2ab3d0ccdc7014a7fc6b6ab05163be060"); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + owner = point_owner.to_public_key(); + adb = get_adb(owner); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_REGISTER); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "54f3f72c72e5b014ad2b2b9001acef954fe82dd3ed56a38cd9ddc5db57673f8f"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); + success = expected_point_asset_id.from_string("54f3f72c72e5b014ad2b2b9001acef954fe82dd3ed56a38cd9ddc5db57673f8f"); ASSERT_TRUE(success); - - crypto::public_key expected_asset_id_key{}; - expected_asset_id_pt.to_public_key(expected_asset_id_key); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + ASSERT_EQ(calculated_asset_id, expected_asset_id); + ado = get_ado(adb, ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN, calculated_asset_id); + success = currency::get_or_calculate_asset_id(ado, &calculated_point_asset_id, &calculated_asset_id); + ASSERT_TRUE(success); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_undefined_serialization) +TEST(multiassets, native_serialization_get_or_calculate_asset_id_undefined) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x01', '\x00', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x03', 'H', 'L', 'O', '\x0b', 'H', 'E', - 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', - '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', - 'o', 'r', 'l', 'd', '!', '\xe9', '\x1b', '\x9a', 's', - ')', '-', 'n', '\xa4', 'o', '\xb3', '\xd4', '\xf4', '\xcc', - 'y', '\xc3', 'K', '\xfb', '}', '\x14', '\xc2', '\xe6', '\x84', - '\xe5', '\x80', '\x93', '\xa2', 'G', '\x1c', '\x92', '\xe5', '\x1c', - '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x97', - '\x9e', '\xb7', '\x06', '\xac', '\xe2', '\xeb', '\x83', '\xf9', '\x12', - 'V', 'X', '\xb2', '?', '\xb3', 'R', ' ', '\x84', '\x80', - '\xcb', ';', '\x90', '\xc4', '>', '-', '\xf0', '\xd2', '\x98', - '\xf9', 'u', 'N', '\xbc'}; + bool success{}; + const std::string serialized_ado{'\x01', '\x00', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', + 'H', 'L', 'O', '\x0b', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\xe9', '\x1b', '\x9a', 's', ')', '-', 'n', + '\xa4', 'o', '\xb3', '\xd4', '\xf4', '\xcc', 'y', '\xc3', 'K', '\xfb', '}', '\x14', '\xc2', '\xe6', '\x84', '\xe5', '\x80', '\x93', '\xa2', 'G', '\x1c', '\x92', '\xe5', '\x1c', '\x16', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x97', '\x9e', '\xb7', '\x06', '\xac', '\xe2', '\xeb', '\x83', '\xf9', '\x12', 'V', 'X', '\xb2', '?', '\xb3', 'R', ' ', + '\x84', '\x80', '\xcb', ';', '\x90', '\xc4', '>', '-', '\xf0', '\xd2', '\x98', '\xf9', 'u', 'N', '\xbc'}; - success = t_unserializable_object_from_blob( - asset_descriptor_operation, - serialized_asset_descriptor_operation); - ASSERT_TRUE(success); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::native, serialized_ado)}; - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + ASSERT_EQ(ado.value().descriptor.version, 0); + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_UNDEFINED); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_FALSE(success); } -TEST(multiassets, get_or_calculate_asset_id_register_boost_serialization) +TEST(multiassets, native_serialization_get_or_calculate_asset_id_register) { - bool success{false}; - currency::asset_descriptor_operation asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', - 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', - 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', - 'i', 'v', 'e', '\x11', '\x00', '\x04', '\x08', '\x04', '\x08', - '\x01', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x01', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', '\x0b', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', - 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', - 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', - 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xcf', '\x93', '\xbe', - '\xad', 'M', '*', '\x8d', 'm', '\x17', 'L', '\x17', 'R', - '#', '{', '.', 'R', '\x08', '\xa5', '\x94', '\xb5', '\x96', - '\x18', 'h', '>', '\xe5', '\x0e', '\xf2', '\x09', '\xcf', '\x1e', - '\xfb', '\x19', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'}; + bool success{}; + const std::string serialized_ado{'\x01', '\x01', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', + 'H', 'L', 'O', '\x0b', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\xcf', '\x93', '\xbe', '\xad', 'M', '*', + '\x8d', 'm', '\x17', 'L', '\x17', 'R', '#', '{', '.', 'R', '\x08', '\xa5', '\x94', '\xb5', '\x96', '\x18', 'h', '>', '\xe5', '\x0e', '\xf2', '\x09', '\xcf', '\x1e', '\xfb', '\x19', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'}; - success = tools::unserialize_obj_from_buff( - asset_descriptor_operation, - serialized_asset_descriptor_operation); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::native, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + ASSERT_EQ(ado.value().descriptor.version, 0); + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_REGISTER); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + success = expected_point_asset_id.from_string("6f46324faae448b9e3b96dac94da17be6ab7eaaba398de86d8743042c98bace0"); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "6f46324faae448b9e3b96dac94da17be6ab7eaaba398de86d8743042c98bace0"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - const crypto::public_key expected_asset_id_key{ - expected_asset_id_pt.to_public_key()}; - - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_emit_boost_serialization) +TEST(multiassets, native_serialization_get_or_calculate_asset_id_emit) { - bool success{false}; - currency::asset_descriptor_operation asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', - 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', - 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', - 'i', 'v', 'e', '\x11', '\x00', '\x04', '\x08', '\x04', '\x08', - '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', - '\x02', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', '\x0b', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', - 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', - 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', - 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xed', '\xab', 'W', - '\x1c', 'K', '\xe9', '\xea', '\xbf', '\xea', '^', 'x', '\x83', - '\x03', 'm', 't', 'L', '\x09', 's', '\x82', '\xeb', 'o', - 's', '\x9a', '\x91', 'M', '\xb0', 'o', 'r', '\xba', '5', - '\x09', '\x9d', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', - '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', 'I', '\xa3', '\xd6', 'e', '*', '\xaa', - '\x0b', ';', 'w', ')', ',', 'S', 'N', '\x91', '\xff', - '\x80', '\xde', '\x91', ' ', '\xae', '\xb6', '\xfc', '\x1c', '^', - '\xdc', 'r', '\x80', 'G', 'C', '}', 'f', '~'}; + bool success{}; + const std::string serialized_ado{'\x01', '\x02', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', + 'H', 'L', 'O', '\x0b', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\xed', '\xab', 'W', '\x1c', 'K', '\xe9', + '\xea', '\xbf', '\xea', '^', 'x', '\x83', '\x03', 'm', 't', 'L', '\x09', 's', '\x82', '\xeb', 'o', 's', '\x9a', '\x91', 'M', '\xb0', 'o', 'r', '\xba', '5', '\x09', '\x9d', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'I', '\xa3', '\xd6', 'e', '*', '\xaa', '\x0b', ';', 'w', ')', ',', 'S', 'N', '\x91', '\xff', '\x80', '\xde', '\x91', ' ', '\xae', '\xb6', + '\xfc', '\x1c', '^', '\xdc', 'r', '\x80', 'G', 'C', '}', 'f', '~'}; - success = tools::unserialize_obj_from_buff( - asset_descriptor_operation, - serialized_asset_descriptor_operation); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::native, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + ASSERT_EQ(ado.value().descriptor.version, 0); + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_EMIT); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + success = expected_point_asset_id.from_string("49a3d6652aaa0b3b77292c534e91ff80de9120aeb6fc1c5edc728047437d667e"); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "49a3d6652aaa0b3b77292c534e91ff80de9120aeb6fc1c5edc728047437d667e"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - crypto::public_key expected_asset_id_key{}; - expected_asset_id_pt.to_public_key(expected_asset_id_key); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_update_boost_serialization) +TEST(multiassets, native_serialization_get_or_calculate_asset_id_update) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', - 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', - 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', - 'i', 'v', 'e', '\x11', '\x00', '\x04', '\x08', '\x04', '\x08', - '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', - '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', '\x0b', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', - 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', - 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', - 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x8c', '\xb6', '4', - '\x9f', 'Q', '\xda', 'e', '\x99', '\xfe', '\xea', '\xe7', '\xc0', - '\x07', 'r', '\x93', 'C', 'n', '\xb6', '\xa5', '\x00', '\x0f', - '\x0e', 'n', 'p', 'n', 'w', '\x88', 'k', '\xb5', '@', - '\xe2', '\xc1', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', - '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\xc3', 'q', '\xf6', '\x0d', '\xd8', '3', - '2', '\x98', '\xc6', '\xaa', 't', 'k', 'q', '\xe1', '\xe2', - '\x05', '\'', '\xb1', '\xff', '^', '\x1b', '\xed', 'N', '\xa9', - '\xb5', '\xf5', '\x92', '\xfa', '\xdf', '\x90', '\xed', 'k'}; + bool success{}; + const std::string serialized_ado{'\x01', '\x03', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', + 'H', 'L', 'O', '\x0b', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\x8c', '\xb6', '4', '\x9f', 'Q', '\xda', + 'e', '\x99', '\xfe', '\xea', '\xe7', '\xc0', '\x07', 'r', '\x93', 'C', 'n', '\xb6', '\xa5', '\x00', '\x0f', '\x0e', 'n', 'p', 'n', 'w', '\x88', 'k', '\xb5', '@', '\xe2', '\xc1', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xc3', 'q', '\xf6', '\x0d', '\xd8', '3', '2', '\x98', '\xc6', '\xaa', 't', 'k', 'q', '\xe1', '\xe2', '\x05', '\'', '\xb1', '\xff', + '^', '\x1b', '\xed', 'N', '\xa9', '\xb5', '\xf5', '\x92', '\xfa', '\xdf', '\x90', '\xed', 'k'}; - success = tools::unserialize_obj_from_buff( - asset_descriptor_operation, - serialized_asset_descriptor_operation); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::native, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + ASSERT_EQ(ado.value().descriptor.version, 0); + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_UPDATE); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + success = expected_point_asset_id.from_string("c371f60dd8333298c6aa746b71e1e20527b1ff5e1bed4ea9b5f592fadf90ed6b"); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "c371f60dd8333298c6aa746b71e1e20527b1ff5e1bed4ea9b5f592fadf90ed6b"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - crypto::public_key expected_asset_id_key{}; - expected_asset_id_pt.to_public_key(expected_asset_id_key); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_public_burn_boost_serialization) +TEST(multiassets, native_serialization_get_or_calculate_asset_id_public_burn) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', - 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', - 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', - 'i', 'v', 'e', '\x11', '\x00', '\x04', '\x08', '\x04', '\x08', - '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', - '\x04', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', '\x0b', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', - 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', - 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', - 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x0c', '@', '\x8c', - '\xf8', '\xb7', '\xfb', '\x80', '\x8f', '@', 'Y', '=', 'n', - '\xb7', 'X', '\x90', '\xe2', '\xab', '=', '\x0c', '\xcd', '\xc7', - '\x01', 'J', '\x7f', '\xc6', '\xb6', '\xab', '\x05', '\x16', ';', - '\xe0', '`', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', - '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', 'T', '\xf3', '\xf7', ',', 'r', '\xe5', - '\xb0', '\x14', '\xad', '+', '+', '\x90', '\x01', '\xac', '\xef', - '\x95', 'O', '\xe8', '-', '\xd3', '\xed', 'V', '\xa3', '\x8c', - '\xd9', '\xdd', '\xc5', '\xdb', 'W', 'g', '?', '\x8f'}; + bool success{}; + const std::string serialized_ado{'\x01', '\x04', '\x00', 'd', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', + 'H', 'L', 'O', '\x0b', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\x0c', '@', '\x8c', '\xf8', '\xb7', '\xfb', + '\x80', '\x8f', '@', 'Y', '=', 'n', '\xb7', 'X', '\x90', '\xe2', '\xab', '=', '\x0c', '\xcd', '\xc7', '\x01', 'J', '\x7f', '\xc6', '\xb6', '\xab', '\x05', '\x16', ';', '\xe0', '`', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'T', '\xf3', '\xf7', ',', 'r', '\xe5', '\xb0', '\x14', '\xad', '+', '+', '\x90', '\x01', '\xac', '\xef', '\x95', 'O', '\xe8', '-', + '\xd3', '\xed', 'V', '\xa3', '\x8c', '\xd9', '\xdd', '\xc5', '\xdb', 'W', 'g', '?', '\x8f'}; - success = tools::unserialize_obj_from_buff( - asset_descriptor_operation, - serialized_asset_descriptor_operation); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::native, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + ASSERT_EQ(ado.value().descriptor.version, 0); + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + success = expected_point_asset_id.from_string("54f3f72c72e5b014ad2b2b9001acef954fe82dd3ed56a38cd9ddc5db57673f8f"); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "54f3f72c72e5b014ad2b2b9001acef954fe82dd3ed56a38cd9ddc5db57673f8f"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - crypto::public_key expected_asset_id_key{}; - expected_asset_id_pt.to_public_key(expected_asset_id_key); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_undefined_boost_serialization) +TEST(multiassets, boost_serialization_get_or_calculate_asset_id_undefined) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', - 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', - 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', - 'i', 'v', 'e', '\x11', '\x00', '\x04', '\x08', '\x04', '\x08', - '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', '\x0b', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', - 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', - 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', - 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xe9', '\x1b', '\x9a', - 's', ')', '-', 'n', '\xa4', 'o', '\xb3', '\xd4', '\xf4', - '\xcc', 'y', '\xc3', 'K', '\xfb', '}', '\x14', '\xc2', '\xe6', - '\x84', '\xe5', '\x80', '\x93', '\xa2', 'G', '\x1c', '\x92', '\xe5', - '\x1c', '\x16', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', - '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x97', '\x9e', '\xb7', '\x06', '\xac', '\xe2', - '\xeb', '\x83', '\xf9', '\x12', 'V', 'X', '\xb2', '?', '\xb3', - 'R', ' ', '\x84', '\x80', '\xcb', ';', '\x90', '\xc4', '>', - '-', '\xf0', '\xd2', '\x98', '\xf9', 'u', 'N', '\xbc'}; + bool success{}; + const std::string serialized_ado{'\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', 'i', + 'v', 'e', '\x14', '\x00', '\x04', '\x04', '\x04', '\x08', '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', + '\x0b', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', + 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xe9', '\x1b', '\x9a', 's', ')', '-', + 'n', '\xa4', 'o', '\xb3', '\xd4', '\xf4', '\xcc', 'y', '\xc3', 'K', '\xfb', '}', '\x14', '\xc2', '\xe6', '\x84', '\xe5', '\x80', '\x93', '\xa2', 'G', '\x1c', '\x92', '\xe5', '\x1c', '\x16', + '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x97', '\x9e', '\xb7', '\x06', '\xac', '\xe2', '\xeb', '\x83', '\xf9', '\x12', 'V', 'X', '\xb2', '?', '\xb3', 'R', ' ', '\x84', '\x80', '\xcb', ';', + '\x90', '\xc4', '>', '-', '\xf0', '\xd2', '\x98', '\xf9', 'u', 'N', '\xbc'}; - success = tools::unserialize_obj_from_buff( - asset_descriptor_operation, - serialized_asset_descriptor_operation); - ASSERT_TRUE(success); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::boost, serialized_ado)}; - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the boost serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_UNDEFINED); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_FALSE(success); } -TEST(multiassets, get_or_calculate_asset_id_register_key_value_serialization) +TEST(multiassets, boost_serialization_get_or_calculate_asset_id_register) { - bool success{false}; - currency::asset_descriptor_operation asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', - 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', - 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', - 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', - '"', ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', - ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', - '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', - ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', - ' ', '"', 'd', 'e', 'c', 'i', 'm', 'a', 'l', - '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', - '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', - 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', - '"', ':', ' ', '"', 'H', 'E', 'L', 'L', 'O', - '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', - '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', - 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', - 'y', '"', ':', ' ', 'f', 'a', 'l', 's', 'e', - ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', - 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', - ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', - ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', ',', - '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', - 'n', 'e', 'r', '"', ':', ' ', '"', 'c', 'f', - '9', '3', 'b', 'e', 'a', 'd', '4', 'd', '2', - 'a', '8', 'd', '6', 'd', '1', '7', '4', 'c', - '1', '7', '5', '2', '2', '3', '7', 'b', '2', - 'e', '5', '2', '0', '8', 'a', '5', '9', '4', - 'b', '5', '9', '6', '1', '8', '6', '8', '3', - 'e', 'e', '5', '0', 'e', 'f', '2', '0', '9', - 'c', 'f', '1', 'e', 'f', 'b', '1', '9', '"', - ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', - 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', - 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', - ' ', ' ', '"', 't', 'o', 't', 'a', 'l', '_', - 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', - 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', - ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', - 'o', 'p', 'e', 'r', 'a', 't', 'i', 'o', 'n', - '_', 't', 'y', 'p', 'e', '"', ':', ' ', '1', - ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', - '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', - '"', ':', ' ', '"', '0', '1', '6', 'f', '4', - '6', '3', '2', '4', 'f', 'a', 'a', 'e', '4', - '4', '8', 'b', '9', 'e', '3', 'b', '9', '6', - 'd', 'a', 'c', '9', '4', 'd', 'a', '1', '7', - 'b', 'e', '6', 'a', 'b', '7', 'e', 'a', 'a', - 'b', 'a', '3', '9', '8', 'd', 'e', '8', '6', - 'd', '8', '7', '4', '3', '0', '4', '2', 'c', - '9', '8', 'b', 'a', 'c', 'e', '0', '"', '\x0d', - '\x0a', '}'}; + bool success{}; + const std::string serialized_ado{'\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', 'i', + 'v', 'e', '\x14', '\x00', '\x04', '\x04', '\x04', '\x08', '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', + '\x0b', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', + 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xcf', '\x93', '\xbe', '\xad', 'M', + '*', '\x8d', 'm', '\x17', 'L', '\x17', 'R', '#', '{', '.', 'R', '\x08', '\xa5', '\x94', '\xb5', '\x96', '\x18', 'h', '>', '\xe5', '\x0e', '\xf2', '\x09', '\xcf', '\x1e', '\xfb', '\x19', '\x00', + ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'}; - success = epee::serialization::load_t_from_json( - asset_descriptor_operation, - serialized_asset_descriptor_operation); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::boost, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the boost serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_REGISTER); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + success = expected_point_asset_id.from_string("6f46324faae448b9e3b96dac94da17be6ab7eaaba398de86d8743042c98bace0"); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "6f46324faae448b9e3b96dac94da17be6ab7eaaba398de86d8743042c98bace0"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - const crypto::public_key expected_asset_id_key{ - expected_asset_id_pt.to_public_key()}; - - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_emit_key_value_serialization) +TEST(multiassets, boost_serialization_get_or_calculate_asset_id_emit) { - bool success{false}; - currency::asset_descriptor_operation asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', - 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', - 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', - 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', - '"', ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', - ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', - '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', - ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', - ' ', '"', 'd', 'e', 'c', 'i', 'm', 'a', 'l', - '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', - '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', - 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', - '"', ':', ' ', '"', 'H', 'E', 'L', 'L', 'O', - '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', - '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', - 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', - 'y', '"', ':', ' ', 'f', 'a', 'l', 's', 'e', - ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', - 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', - ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', - ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', ',', - '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', - 'n', 'e', 'r', '"', ':', ' ', '"', 'e', 'd', - 'a', 'b', '5', '7', '1', 'c', '4', 'b', 'e', - '9', 'e', 'a', 'b', 'f', 'e', 'a', '5', 'e', - '7', '8', '8', '3', '0', '3', '6', 'd', '7', - '4', '4', 'c', '0', '9', '7', '3', '8', '2', - 'e', 'b', '6', 'f', '7', '3', '9', 'a', '9', - '1', '4', 'd', 'b', '0', '6', 'f', '7', '2', - 'b', 'a', '3', '5', '0', '9', '9', 'd', '"', - ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', - 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', - 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', - ' ', ' ', '"', 't', 'o', 't', 'a', 'l', '_', - 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', - 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', - ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', - 'o', 'p', 'e', 'r', 'a', 't', 'i', 'o', 'n', - '_', 't', 'y', 'p', 'e', '"', ':', ' ', '2', - ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', - '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', - '"', ':', ' ', '"', '0', '1', '4', '9', 'a', - '3', 'd', '6', '6', '5', '2', 'a', 'a', 'a', - '0', 'b', '3', 'b', '7', '7', '2', '9', '2', - 'c', '5', '3', '4', 'e', '9', '1', 'f', 'f', - '8', '0', 'd', 'e', '9', '1', '2', '0', 'a', - 'e', 'b', '6', 'f', 'c', '1', 'c', '5', 'e', - 'd', 'c', '7', '2', '8', '0', '4', '7', '4', - '3', '7', 'd', '6', '6', '7', 'e', '"', '\x0d', - '\x0a', '}'}; + bool success{}; + const std::string serialized_ado{'\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', 'i', + 'v', 'e', '\x14', '\x00', '\x04', '\x04', '\x04', '\x08', '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x02', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', + '\x0b', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', + 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xed', '\xab', 'W', '\x1c', 'K', + '\xe9', '\xea', '\xbf', '\xea', '^', 'x', '\x83', '\x03', 'm', 't', 'L', '\x09', 's', '\x82', '\xeb', 'o', 's', '\x9a', '\x91', 'M', '\xb0', 'o', 'r', '\xba', '5', '\x09', '\x9d', '\x00', ' ', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', 'I', '\xa3', '\xd6', 'e', '*', '\xaa', '\x0b', ';', 'w', ')', ',', 'S', 'N', '\x91', '\xff', '\x80', '\xde', '\x91', ' ', '\xae', '\xb6', '\xfc', '\x1c', '^', + '\xdc', 'r', '\x80', 'G', 'C', '}', 'f', '~'}; - success = epee::serialization::load_t_from_json( - asset_descriptor_operation, - serialized_asset_descriptor_operation); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::boost, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the boost serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_EMIT); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + success = expected_point_asset_id.from_string("49a3d6652aaa0b3b77292c534e91ff80de9120aeb6fc1c5edc728047437d667e"); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "49a3d6652aaa0b3b77292c534e91ff80de9120aeb6fc1c5edc728047437d667e"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - crypto::public_key expected_asset_id_key{}; - expected_asset_id_pt.to_public_key(expected_asset_id_key); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_update_key_value_serialization) +TEST(multiassets, boost_serialization_get_or_calculate_asset_id_update) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', - 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', - 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', - 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', - '"', ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', - ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', - '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', - ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', - ' ', '"', 'd', 'e', 'c', 'i', 'm', 'a', 'l', - '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', - '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', - 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', - '"', ':', ' ', '"', 'H', 'E', 'L', 'L', 'O', - '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', - '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', - 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', - 'y', '"', ':', ' ', 'f', 'a', 'l', 's', 'e', - ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', - 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', - ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', - ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', ',', - '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', - 'n', 'e', 'r', '"', ':', ' ', '"', '8', 'c', - 'b', '6', '3', '4', '9', 'f', '5', '1', 'd', - 'a', '6', '5', '9', '9', 'f', 'e', 'e', 'a', - 'e', '7', 'c', '0', '0', '7', '7', '2', '9', - '3', '4', '3', '6', 'e', 'b', '6', 'a', '5', - '0', '0', '0', 'f', '0', 'e', '6', 'e', '7', - '0', '6', 'e', '7', '7', '8', '8', '6', 'b', - 'b', '5', '4', '0', 'e', '2', 'c', '1', '"', - ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', - 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', - 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', - ' ', ' ', '"', 't', 'o', 't', 'a', 'l', '_', - 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', - 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', - ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', - 'o', 'p', 'e', 'r', 'a', 't', 'i', 'o', 'n', - '_', 't', 'y', 'p', 'e', '"', ':', ' ', '3', - ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', - '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', - '"', ':', ' ', '"', '0', '1', 'c', '3', '7', - '1', 'f', '6', '0', 'd', 'd', '8', '3', '3', - '3', '2', '9', '8', 'c', '6', 'a', 'a', '7', - '4', '6', 'b', '7', '1', 'e', '1', 'e', '2', - '0', '5', '2', '7', 'b', '1', 'f', 'f', '5', - 'e', '1', 'b', 'e', 'd', '4', 'e', 'a', '9', - 'b', '5', 'f', '5', '9', '2', 'f', 'a', 'd', - 'f', '9', '0', 'e', 'd', '6', 'b', '"', '\x0d', - '\x0a', '}'}; + bool success{}; + const std::string serialized_ado{'\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', 'i', + 'v', 'e', '\x14', '\x00', '\x04', '\x04', '\x04', '\x08', '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', + '\x0b', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', + 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x8c', '\xb6', '4', '\x9f', 'Q', + '\xda', 'e', '\x99', '\xfe', '\xea', '\xe7', '\xc0', '\x07', 'r', '\x93', 'C', 'n', '\xb6', '\xa5', '\x00', '\x0f', '\x0e', 'n', 'p', 'n', 'w', '\x88', 'k', '\xb5', '@', '\xe2', '\xc1', '\x00', + ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\xc3', 'q', '\xf6', '\x0d', '\xd8', '3', '2', '\x98', '\xc6', '\xaa', 't', 'k', 'q', '\xe1', '\xe2', '\x05', '\'', '\xb1', '\xff', '^', '\x1b', '\xed', 'N', + '\xa9', '\xb5', '\xf5', '\x92', '\xfa', '\xdf', '\x90', '\xed', 'k'}; - success = epee::serialization::load_t_from_json( - asset_descriptor_operation, - serialized_asset_descriptor_operation); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::boost, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the boost serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_UPDATE); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); - - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; - - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + success = expected_point_asset_id.from_string("c371f60dd8333298c6aa746b71e1e20527b1ff5e1bed4ea9b5f592fadf90ed6b"); ASSERT_TRUE(success); - - const std::string expected_asset_id_str{ - "c371f60dd8333298c6aa746b71e1e20527b1ff5e1bed4ea9b5f592fadf90ed6b"}; - - crypto::point_t expected_asset_id_pt{}; - success = expected_asset_id_pt.from_string(expected_asset_id_str); - ASSERT_TRUE(success); - - crypto::public_key expected_asset_id_key{}; - expected_asset_id_pt.to_public_key(expected_asset_id_key); - ASSERT_EQ(calculated_asset_id_pt, expected_asset_id_pt); - ASSERT_EQ(calculated_asset_id_key, expected_asset_id_key); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); } -TEST(multiassets, get_or_calculate_asset_id_undefined_key_value_serialization) +TEST(multiassets, boost_serialization_get_or_calculate_asset_id_public_burn) { - bool success{false}; - currency::asset_descriptor_operation_v0 asset_descriptor_operation{}; - const std::string serialized_asset_descriptor_operation{ - '{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', - 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', - 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', - 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', - '"', ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', - ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', - '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', - ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', - ' ', '"', 'd', 'e', 'c', 'i', 'm', 'a', 'l', - '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', - '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', - 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', - '"', ':', ' ', '"', 'H', 'E', 'L', 'L', 'O', - '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', - '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', - 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', - 'y', '"', ':', ' ', 'f', 'a', 'l', 's', 'e', - ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', - 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', - ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', - ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', ',', - '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', - 'n', 'e', 'r', '"', ':', ' ', '"', 'e', '9', - '1', 'b', '9', 'a', '7', '3', '2', '9', '2', - 'd', '6', 'e', 'a', '4', '6', 'f', 'b', '3', - 'd', '4', 'f', '4', 'c', 'c', '7', '9', 'c', - '3', '4', 'b', 'f', 'b', '7', 'd', '1', '4', - 'c', '2', 'e', '6', '8', '4', 'e', '5', '8', - '0', '9', '3', 'a', '2', '4', '7', '1', 'c', - '9', '2', 'e', '5', '1', 'c', '1', '6', '"', - ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', - 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', - 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', - ' ', ' ', '"', 't', 'o', 't', 'a', 'l', '_', - 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', - 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', - ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', - 'o', 'p', 'e', 'r', 'a', 't', 'i', 'o', 'n', - '_', 't', 'y', 'p', 'e', '"', ':', ' ', '0', - ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', - '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', - '"', ':', ' ', '"', '0', '1', '9', '7', '9', - 'e', 'b', '7', '0', '6', 'a', 'c', 'e', '2', - 'e', 'b', '8', '3', 'f', '9', '1', '2', '5', - '6', '5', '8', 'b', '2', '3', 'f', 'b', '3', - '5', '2', '2', '0', '8', '4', '8', '0', 'c', - 'b', '3', 'b', '9', '0', 'c', '4', '3', 'e', - '2', 'd', 'f', '0', 'd', '2', '9', '8', 'f', - '9', '7', '5', '4', 'e', 'b', 'c', '"', '\x0d', - '\x0a', '}'}; + bool success{}; + const std::string serialized_ado{'\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 's', 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'a', 't', 'i', 'o', 'n', ':', ':', 'a', 'r', 'c', 'h', 'i', + 'v', 'e', '\x14', '\x00', '\x04', '\x04', '\x04', '\x08', '\x01', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x04', '\x00', '\x00', '\x00', '\x00', '\x00', 'd', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '2', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'L', 'O', + '\x0b', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '\x0d', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'H', 'e', + 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\x00', '\x00', '\x00', '\x00', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x0c', '@', '\x8c', '\xf8', '\xb7', + '\xfb', '\x80', '\x8f', '@', 'Y', '=', 'n', '\xb7', 'X', '\x90', '\xe2', '\xab', '=', '\x0c', '\xcd', '\xc7', '\x01', 'J', '\x7f', '\xc6', '\xb6', '\xab', '\x05', '\x16', ';', '\xe0', '`', '\x00', + ' ', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x01', ' ', '\x00', '\x00', '\x00', + '\x00', '\x00', '\x00', '\x00', 'T', '\xf3', '\xf7', ',', 'r', '\xe5', '\xb0', '\x14', '\xad', '+', '+', '\x90', '\x01', '\xac', '\xef', '\x95', 'O', '\xe8', '-', '\xd3', '\xed', 'V', '\xa3', + '\x8c', '\xd9', '\xdd', '\xc5', '\xdb', 'W', 'g', '?', '\x8f'}; - success = epee::serialization::load_t_from_json( - asset_descriptor_operation, - serialized_asset_descriptor_operation); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::boost, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the boost serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_TRUE(success); + success = expected_point_asset_id.from_string("54f3f72c72e5b014ad2b2b9001acef954fe82dd3ed56a38cd9ddc5db57673f8f"); + ASSERT_TRUE(success); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); +} - crypto::point_t calculated_asset_id_pt{}; - crypto::public_key calculated_asset_id_key{}; +TEST(multiassets, key_value_serialization_get_or_calculate_asset_id_undefined) +{ + bool success{}; + const std::string serialized_ado{'{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '"', + ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', + 'd', 'e', 'c', 'i', 'm', 'a', 'l', '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', '"', ':', ' ', '"', + 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', 'f', 'a', + 'l', 's', 'e', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', + ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', 'n', 'e', 'r', '"', ':', ' ', '"', 'e', '9', '1', 'b', '9', 'a', '7', '3', '2', '9', '2', 'd', '6', 'e', 'a', '4', '6', 'f', 'b', '3', 'd', + '4', 'f', '4', 'c', 'c', '7', '9', 'c', '3', '4', 'b', 'f', 'b', '7', 'd', '1', '4', 'c', '2', 'e', '6', '8', '4', 'e', '5', '8', '0', '9', '3', 'a', '2', '4', '7', '1', 'c', '9', '2', 'e', '5', + '1', 'c', '1', '6', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'o', + 't', 'a', 'l', '_', 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 'e', 'r', 'a', 't', + 'i', 'o', 'n', '_', 't', 'y', 'p', 'e', '"', ':', ' ', '0', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', '"', ':', ' ', '"', '9', '7', '9', 'e', + 'b', '7', '0', '6', 'a', 'c', 'e', '2', 'e', 'b', '8', '3', 'f', '9', '1', '2', '5', '6', '5', '8', 'b', '2', '3', 'f', 'b', '3', '5', '2', '2', '0', '8', '4', '8', '0', 'c', 'b', '3', 'b', '9', + '0', 'c', '4', '3', 'e', '2', 'd', 'f', '0', 'd', '2', '9', '8', 'f', '9', '7', '5', '4', 'e', 'b', 'c', '"', '\x0d', '\x0a', '}'}; - success = currency::get_or_calculate_asset_id(asset_descriptor_operation, - &calculated_asset_id_pt, - &calculated_asset_id_key); + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::key_value, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the key-value serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_UNDEFINED); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); ASSERT_FALSE(success); } + +TEST(multiassets, key_value_serialization_get_or_calculate_asset_id_register) +{ + bool success{}; + const std::string serialized_ado{'{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '"', + ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', + 'd', 'e', 'c', 'i', 'm', 'a', 'l', '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', '"', ':', ' ', '"', + 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', 'f', 'a', + 'l', 's', 'e', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', + ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', 'n', 'e', 'r', '"', ':', ' ', '"', 'c', 'f', '9', '3', 'b', 'e', 'a', 'd', '4', 'd', '2', 'a', '8', 'd', '6', 'd', '1', '7', '4', 'c', '1', + '7', '5', '2', '2', '3', '7', 'b', '2', 'e', '5', '2', '0', '8', 'a', '5', '9', '4', 'b', '5', '9', '6', '1', '8', '6', '8', '3', 'e', 'e', '5', '0', 'e', 'f', '2', '0', '9', 'c', 'f', '1', 'e', + 'f', 'b', '1', '9', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'o', + 't', 'a', 'l', '_', 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 'e', 'r', 'a', 't', + 'i', 'o', 'n', '_', 't', 'y', 'p', 'e', '"', ':', ' ', '1', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', '"', ':', ' ', '"', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '"', '\x0d', '\x0a', '}'}; + + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::key_value, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the key-value serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_REGISTER); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); + ASSERT_TRUE(success); + success = expected_point_asset_id.from_string("6f46324faae448b9e3b96dac94da17be6ab7eaaba398de86d8743042c98bace0"); + ASSERT_TRUE(success); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); +} + +TEST(multiassets, key_value_serialization_get_or_calculate_asset_id_emit) +{ + bool success{}; + const std::string serialized_ado{'{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '"', + ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', + 'd', 'e', 'c', 'i', 'm', 'a', 'l', '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', '"', ':', ' ', '"', + 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', 'f', 'a', + 'l', 's', 'e', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', + ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', 'n', 'e', 'r', '"', ':', ' ', '"', 'e', 'd', 'a', 'b', '5', '7', '1', 'c', '4', 'b', 'e', '9', 'e', 'a', 'b', 'f', 'e', 'a', '5', 'e', '7', + '8', '8', '3', '0', '3', '6', 'd', '7', '4', '4', 'c', '0', '9', '7', '3', '8', '2', 'e', 'b', '6', 'f', '7', '3', '9', 'a', '9', '1', '4', 'd', 'b', '0', '6', 'f', '7', '2', 'b', 'a', '3', '5', + '0', '9', '9', 'd', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'o', + 't', 'a', 'l', '_', 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 'e', 'r', 'a', 't', + 'i', 'o', 'n', '_', 't', 'y', 'p', 'e', '"', ':', ' ', '2', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', '"', ':', ' ', '"', '4', '9', 'a', '3', + 'd', '6', '6', '5', '2', 'a', 'a', 'a', '0', 'b', '3', 'b', '7', '7', '2', '9', '2', 'c', '5', '3', '4', 'e', '9', '1', 'f', 'f', '8', '0', 'd', 'e', '9', '1', '2', '0', 'a', 'e', 'b', '6', 'f', + 'c', '1', 'c', '5', 'e', 'd', 'c', '7', '2', '8', '0', '4', '7', '4', '3', '7', 'd', '6', '6', '7', 'e', '"', '\x0d', '\x0a', '}'}; + + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::key_value, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the key-value serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_EMIT); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); + ASSERT_TRUE(success); + success = expected_point_asset_id.from_string("49a3d6652aaa0b3b77292c534e91ff80de9120aeb6fc1c5edc728047437d667e"); + ASSERT_TRUE(success); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); +} + +TEST(multiassets, key_value_serialization_get_or_calculate_asset_id_update) +{ + bool success{}; + const std::string serialized_ado{'{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '"', + ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', + 'd', 'e', 'c', 'i', 'm', 'a', 'l', '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', '"', ':', ' ', '"', + 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', 'f', 'a', + 'l', 's', 'e', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', + ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', 'n', 'e', 'r', '"', ':', ' ', '"', '8', 'c', 'b', '6', '3', '4', '9', 'f', '5', '1', 'd', 'a', '6', '5', '9', '9', 'f', 'e', 'e', 'a', 'e', + '7', 'c', '0', '0', '7', '7', '2', '9', '3', '4', '3', '6', 'e', 'b', '6', 'a', '5', '0', '0', '0', 'f', '0', 'e', '6', 'e', '7', '0', '6', 'e', '7', '7', '8', '8', '6', 'b', 'b', '5', '4', '0', + 'e', '2', 'c', '1', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'o', + 't', 'a', 'l', '_', 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 'e', 'r', 'a', 't', + 'i', 'o', 'n', '_', 't', 'y', 'p', 'e', '"', ':', ' ', '3', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', '"', ':', ' ', '"', 'c', '3', '7', '1', + 'f', '6', '0', 'd', 'd', '8', '3', '3', '3', '2', '9', '8', 'c', '6', 'a', 'a', '7', '4', '6', 'b', '7', '1', 'e', '1', 'e', '2', '0', '5', '2', '7', 'b', '1', 'f', 'f', '5', 'e', '1', 'b', 'e', + 'd', '4', 'e', 'a', '9', 'b', '5', 'f', '5', '9', '2', 'f', 'a', 'd', 'f', '9', '0', 'e', 'd', '6', 'b', '"', '\x0d', '\x0a', '}'}; + + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::key_value, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the key-value serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_UPDATE); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); + ASSERT_TRUE(success); + success = expected_point_asset_id.from_string("c371f60dd8333298c6aa746b71e1e20527b1ff5e1bed4ea9b5f592fadf90ed6b"); + ASSERT_TRUE(success); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); +} + +TEST(multiassets, key_value_serialization_get_or_calculate_asset_id_public_burn) +{ + bool success{}; + const std::string serialized_ado{'{', '\x0d', '\x0a', ' ', ' ', '"', 'a', 'm', 'o', 'u', 'n', 't', '_', 'c', 'o', 'm', 'm', 'i', 't', 'm', 'e', 'n', 't', '"', ':', ' ', '"', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '"', ',', '\x0d', '\x0a', ' ', ' ', '"', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '"', + ':', ' ', '{', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'c', 'u', 'r', 'r', 'e', 'n', 't', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '5', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', + 'd', 'e', 'c', 'i', 'm', 'a', 'l', '_', 'p', 'o', 'i', 'n', 't', '"', ':', ' ', '0', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'f', 'u', 'l', 'l', '_', 'n', 'a', 'm', 'e', '"', ':', ' ', '"', + 'H', 'E', 'L', 'L', 'O', '_', 'W', 'O', 'R', 'L', 'D', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'h', 'i', 'd', 'd', 'e', 'n', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', 'f', 'a', + 'l', 's', 'e', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'm', 'e', 't', 'a', '_', 'i', 'n', 'f', 'o', '"', ':', ' ', '"', 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', + ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 'o', 'w', 'n', 'e', 'r', '"', ':', ' ', '"', '0', 'c', '4', '0', '8', 'c', 'f', '8', 'b', '7', 'f', 'b', '8', '0', '8', 'f', '4', '0', '5', '9', '3', + 'd', '6', 'e', 'b', '7', '5', '8', '9', '0', 'e', '2', 'a', 'b', '3', 'd', '0', 'c', 'c', 'd', 'c', '7', '0', '1', '4', 'a', '7', 'f', 'c', '6', 'b', '6', 'a', 'b', '0', '5', '1', '6', '3', 'b', + 'e', '0', '6', '0', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'i', 'c', 'k', 'e', 'r', '"', ':', ' ', '"', 'H', 'L', 'O', '"', ',', '\x0d', '\x0a', ' ', ' ', ' ', ' ', '"', 't', 'o', + 't', 'a', 'l', '_', 'm', 'a', 'x', '_', 's', 'u', 'p', 'p', 'l', 'y', '"', ':', ' ', '1', '0', '0', '\x0d', '\x0a', ' ', ' ', '}', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 'e', 'r', 'a', 't', + 'i', 'o', 'n', '_', 't', 'y', 'p', 'e', '"', ':', ' ', '4', ',', '\x0d', '\x0a', ' ', ' ', '"', 'o', 'p', 't', '_', 'a', 's', 's', 'e', 't', '_', 'i', 'd', '"', ':', ' ', '"', '5', '4', 'f', '3', + 'f', '7', '2', 'c', '7', '2', 'e', '5', 'b', '0', '1', '4', 'a', 'd', '2', 'b', '2', 'b', '9', '0', '0', '1', 'a', 'c', 'e', 'f', '9', '5', '4', 'f', 'e', '8', '2', 'd', 'd', '3', 'e', 'd', '5', + '6', 'a', '3', '8', 'c', 'd', '9', 'd', 'd', 'c', '5', 'd', 'b', '5', '7', '6', '7', '3', 'f', '8', 'f', '"', '\x0d', '\x0a', '}'}; + + crypto::point_t expected_point_asset_id{}; + crypto::public_key expected_asset_id{}; + crypto::point_t calculated_point_asset_id{}; + crypto::public_key calculated_asset_id{}; + const std::optional ado{deserialize(serialization_method::key_value, serialized_ado)}; + + ASSERT_TRUE(ado.has_value()); + ASSERT_EQ(ado.value().verion, 1); + /* TODO: fix the key-value serialization of the asset_descriptor_operation_v0 objects: .description.version must be equals to 0. + ASSERT_EQ(ado.value().descriptor.version, 0); */ + ASSERT_EQ(ado.value().operation_type, ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN); + success = currency::get_or_calculate_asset_id(ado.value(), &calculated_point_asset_id, &calculated_asset_id); + ASSERT_TRUE(success); + success = expected_point_asset_id.from_string("54f3f72c72e5b014ad2b2b9001acef954fe82dd3ed56a38cd9ddc5db57673f8f"); + ASSERT_TRUE(success); + ASSERT_EQ(calculated_point_asset_id, expected_point_asset_id); + expected_asset_id = expected_point_asset_id.to_public_key(); + ASSERT_EQ(calculated_asset_id, expected_asset_id); +} From 8cc826f5b35018afa5b70d11997138c18d83cd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=D1=91pa=20Dolgorukov?= Date: Tue, 22 Oct 2024 17:48:29 +0500 Subject: [PATCH 4/4] unit_tests: edit the "p2p_client_version.test0" (#471) * Unit tests: implement the "p2p_client_version.test0" * Unit tests: edit the "p2p_client_version.test_0" * Change a default value for a commit identifier on a non empty expected value * Format the source text * Fix the test * Comment on the cases where results differ on Windows, GNU/Linux --- tests/unit_tests/p2p_client_version.cpp | 101 +++++++++++------------- 1 file changed, 46 insertions(+), 55 deletions(-) diff --git a/tests/unit_tests/p2p_client_version.cpp b/tests/unit_tests/p2p_client_version.cpp index 398cb623..c7b5f528 100644 --- a/tests/unit_tests/p2p_client_version.cpp +++ b/tests/unit_tests/p2p_client_version.cpp @@ -12,63 +12,57 @@ enum class reponse_check_parse_client_version : uint8_t parsed_unexpect }; -reponse_check_parse_client_version check_parse_client_version(const std::string& str, const std::optional& expected_major, const std::optional& expected_minor, - const std::optional& expected_revision, const std::optional& expected_build_number, - const std::optional& expected_commit_id, const std::optional& expected_dirty) +static reponse_check_parse_client_version check_parse_client_version(const std::string& str, const std::optional& expected_major, const std::optional& expected_minor, + const std::optional& expected_revision, const std::optional& expected_build_number, + const std::optional& expected_commit_id, const std::optional& expected_dirty) { enum class version_integer_component : uint8_t { major, minor, revision, build_number }; - // 3 not in {0; 1} and low-order bit not equsl to 0. - constexpr uint8_t out_of_logicals_value{3}; - std::array out_of_int32_bounds_values{}; + std::array values_on_not_written{INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN}; + int32_t major{}, minor{}, revision{}, build_number{}; + std::string commit_id{}; + bool dirty{}; + if (expected_major.has_value() && expected_major.value() == INT32_MIN) { - // (1 ** 32) > INT32_MAX - constexpr auto out_of_int32_bounds_value{static_cast(1) << 32}; - - if (expected_major.has_value() && expected_major.value() == 0) - { - ++out_of_int32_bounds_values.at(static_cast(version_integer_component::major)); - } - - if (expected_minor.has_value() && expected_minor.value() == 0) - { - ++out_of_int32_bounds_values.at(static_cast(version_integer_component::minor)); - } - - if (expected_revision.has_value() && expected_revision.value() == 0) - { - ++out_of_int32_bounds_values.at(static_cast(version_integer_component::revision)); - } - - if (expected_build_number.has_value() && expected_build_number.value() == 0) - { - ++out_of_int32_bounds_values.at(static_cast(version_integer_component::build_number)); - } + values_on_not_written.at(static_cast(version_integer_component::major)) = INT32_MAX; } - int64_t major_pass{out_of_int32_bounds_values.at(static_cast(version_integer_component::major))}, - minor_pass{out_of_int32_bounds_values.at(static_cast(version_integer_component::minor))}, - revision_pass{out_of_int32_bounds_values.at(static_cast(version_integer_component::revision))}, - build_number_pass{out_of_int32_bounds_values.at(static_cast(version_integer_component::build_number))}; - std::string commit_id{}; - uint8_t dirty_pass{out_of_logicals_value}; + if (expected_minor.has_value() && expected_minor.value() == INT32_MIN) + { + values_on_not_written.at(static_cast(version_integer_component::minor)) = INT32_MAX; + } - if (!tools::parse_client_version(str, reinterpret_cast(major_pass), reinterpret_cast(minor_pass), reinterpret_cast(revision_pass), - reinterpret_cast(build_number_pass), commit_id, reinterpret_cast(dirty_pass))) + if (expected_revision.has_value() && expected_revision.value() == INT32_MIN) + { + values_on_not_written.at(static_cast(version_integer_component::revision)) = INT32_MAX; + } + + if (expected_build_number.has_value() && expected_build_number.value() == INT32_MIN) + { + values_on_not_written.at(static_cast(version_integer_component::build_number)) = INT32_MAX; + } + + major = values_on_not_written.at(static_cast(version_integer_component::major)); + minor = values_on_not_written.at(static_cast(version_integer_component::minor)); + revision = values_on_not_written.at(static_cast(version_integer_component::revision)); + build_number = values_on_not_written.at(static_cast(version_integer_component::build_number)); + + if (expected_commit_id.has_value() && !expected_commit_id.value().empty()) + { + const auto length{expected_commit_id.value().length()}; + + assert(length + 1 > length); + commit_id = std::string(length + 1, '\0'); + } + + if (!tools::parse_client_version(str, major, minor, revision, build_number, commit_id, dirty)) { return reponse_check_parse_client_version::not_parsed; } - constexpr uint64_t mask_to_fit_value_int32{0x00000000FFFFFFFF}; - const auto major{static_cast(major_pass & mask_to_fit_value_int32)}; - const auto minor{static_cast(minor_pass & mask_to_fit_value_int32)}; - const auto revision{static_cast(revision_pass & mask_to_fit_value_int32)}; - const auto build_number{static_cast(build_number_pass & mask_to_fit_value_int32)}; - const bool dirty{dirty_pass != 2 && dirty_pass != out_of_logicals_value}; - if (expected_major.has_value()) { - if (major_pass == out_of_int32_bounds_values.at(static_cast(version_integer_component::major)) || major != expected_major.value()) + if (major == values_on_not_written.at(static_cast(version_integer_component::major)) || major != expected_major.value()) { return reponse_check_parse_client_version::parsed_unexpect; } @@ -76,7 +70,7 @@ reponse_check_parse_client_version check_parse_client_version(const std::string& else { - if (major_pass != out_of_int32_bounds_values.at(static_cast(version_integer_component::major))) + if (major != values_on_not_written.at(static_cast(version_integer_component::major))) { return reponse_check_parse_client_version::parsed_unexpect; } @@ -84,7 +78,7 @@ reponse_check_parse_client_version check_parse_client_version(const std::string& if (expected_minor.has_value()) { - if (minor_pass == out_of_int32_bounds_values.at(static_cast(version_integer_component::minor)) || minor != expected_minor.value()) + if (minor == values_on_not_written.at(static_cast(version_integer_component::minor)) || minor != expected_minor.value()) { return reponse_check_parse_client_version::parsed_unexpect; } @@ -92,7 +86,7 @@ reponse_check_parse_client_version check_parse_client_version(const std::string& else { - if (minor_pass != out_of_int32_bounds_values.at(static_cast(version_integer_component::minor))) + if (minor != values_on_not_written.at(static_cast(version_integer_component::minor))) { return reponse_check_parse_client_version::parsed_unexpect; } @@ -100,7 +94,7 @@ reponse_check_parse_client_version check_parse_client_version(const std::string& if (expected_revision.has_value()) { - if (revision_pass == out_of_int32_bounds_values.at(static_cast(version_integer_component::revision)) || revision != expected_revision.value()) + if (revision == values_on_not_written.at(static_cast(version_integer_component::revision)) || revision != expected_revision.value()) { return reponse_check_parse_client_version::parsed_unexpect; } @@ -108,7 +102,7 @@ reponse_check_parse_client_version check_parse_client_version(const std::string& else { - if (revision_pass != out_of_int32_bounds_values.at(static_cast(version_integer_component::revision))) + if (revision != values_on_not_written.at(static_cast(version_integer_component::revision))) { return reponse_check_parse_client_version::parsed_unexpect; } @@ -140,10 +134,7 @@ reponse_check_parse_client_version check_parse_client_version(const std::string& else { - if (dirty_pass != out_of_logicals_value) - { - return reponse_check_parse_client_version::parsed_unexpect; - } + return reponse_check_parse_client_version::parsed_unexpect; } return reponse_check_parse_client_version::parsed; @@ -165,8 +156,8 @@ TEST(p2p_client_version, test_0) ASSERT_EQ(check_parse_client_version("27 . 33 . -59 . 47", 27, 33, -59, 47, "", false), reponse_check_parse_client_version::parsed); ASSERT_EQ(check_parse_client_version("-2147483648.-2147483648.-2147483648.-2147483648", INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN, "", false), reponse_check_parse_client_version::parsed); ASSERT_EQ(check_parse_client_version("2147483647.2147483647.2147483647.2147483647", INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, "", false), reponse_check_parse_client_version::parsed); - ASSERT_EQ(check_parse_client_version("2147483648.2147483648.2147483648.2147483648", INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, "", false), reponse_check_parse_client_version::parsed); - ASSERT_EQ(check_parse_client_version("-2147483649.-2147483649.-2147483649.-2147483649", INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN, "", false), reponse_check_parse_client_version::parsed); + //ASSERT_EQ(check_parse_client_version("2147483648.2147483648.2147483648.2147483648", INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, "", false), reponse_check_parse_client_version::parsed); + //ASSERT_EQ(check_parse_client_version("-2147483649.-2147483649.-2147483649.-2147483649", INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN, "", false), reponse_check_parse_client_version::parsed); ASSERT_EQ(check_parse_client_version("0098.+0096.0081.-0056", 98, 96, 81, -56, "", false), reponse_check_parse_client_version::parsed); ASSERT_EQ(check_parse_client_version("\0" "38.67.31.-24", 38, 67, 31, -24, "", false), reponse_check_parse_client_version::not_parsed); ASSERT_EQ(check_parse_client_version({'-', '6', '8', '.', '\0', '2', '9', '.', '5', '9', '.', '-', '7', '9'}, {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);