1
0
Fork 0
forked from lthn/blockchain

Merge branch 'develop' into emmit_burn_refactoring

# Conflicts:
#	src/wallet/wallet2.cpp
#	tests/unit_tests/multiassets_test.cpp
This commit is contained in:
sowle 2024-10-22 15:58:29 +02:00
commit 121067e36d
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
5 changed files with 774 additions and 1143 deletions

View file

@ -954,6 +954,7 @@ namespace currency
}
}
}
/*
//---------------------------------------------------------------
template<typename invocable_t>
typename std::enable_if_t<std::is_invocable_v<invocable_t, std::ostream&>, std::ostream&> operator<<(std::ostream& o, invocable_t callee)
@ -961,6 +962,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);

View file

@ -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){
(ado.opt_descriptor.has_value() && ado.opt_descriptor->owner_eth_pub_key.has_value()) ? o << ado.opt_descriptor->owner_eth_pub_key.value() << " (ETH)" : o << ado.opt_descriptor->owner;
auto print_ado_owner = [ado](/*std::ostream& o*/) { // temporary reverted to boring std::string, until operator<<(std::ostream& o, invocable_t callee) is fixed for C++17/Android
std::stringstream o;
if (ado.opt_descriptor.has_value()) { ado.opt_descriptor->owner_eth_pub_key.has_value() ? o << ado.opt_descriptor->owner_eth_pub_key.value() << " (ETH)" : o << ado.opt_descriptor->owner; }
return o.str();
};
do
@ -426,7 +428,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)
@ -499,7 +501,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.opt_descriptor->full_name
<< ENDL << "Ticker: " << ado.opt_descriptor->ticker
<< ENDL << "Total Max Supply: " << print_asset_money(ado.opt_descriptor->total_max_supply, ado.opt_descriptor->decimal_point)

View file

@ -2076,6 +2076,8 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
{
return sum + boost::get<txin_multisig>(input).amount;
}
return sum;
}
};
@ -2085,6 +2087,8 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
{
return sum + boost::get<tx_out_bare>(output).amount;
}
return sum;
}
};

File diff suppressed because it is too large Load diff

View file

@ -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<int>& expected_major, const std::optional<int>& expected_minor,
const std::optional<int>& expected_revision, const std::optional<int>& expected_build_number,
const std::optional<std::string>& expected_commit_id, const std::optional<bool>& expected_dirty)
static reponse_check_parse_client_version check_parse_client_version(const std::string& str, const std::optional<int>& expected_major, const std::optional<int>& expected_minor,
const std::optional<int>& expected_revision, const std::optional<int>& expected_build_number,
const std::optional<std::string>& expected_commit_id, const std::optional<bool>& 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<int64_t, 4> out_of_int32_bounds_values{};
std::array<int32_t, 4> 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<int64_t>(1) << 32};
if (expected_major.has_value() && expected_major.value() == 0)
{
++out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::major));
}
if (expected_minor.has_value() && expected_minor.value() == 0)
{
++out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::minor));
}
if (expected_revision.has_value() && expected_revision.value() == 0)
{
++out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::revision));
}
if (expected_build_number.has_value() && expected_build_number.value() == 0)
{
++out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::build_number));
}
values_on_not_written.at(static_cast<uint8_t>(version_integer_component::major)) = INT32_MAX;
}
int64_t major_pass{out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::major))},
minor_pass{out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::minor))},
revision_pass{out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::revision))},
build_number_pass{out_of_int32_bounds_values.at(static_cast<uint8_t>(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<uint8_t>(version_integer_component::minor)) = INT32_MAX;
}
if (!tools::parse_client_version(str, reinterpret_cast<int32_t&>(major_pass), reinterpret_cast<int32_t&>(minor_pass), reinterpret_cast<int32_t&>(revision_pass),
reinterpret_cast<int32_t&>(build_number_pass), commit_id, reinterpret_cast<bool&>(dirty_pass)))
if (expected_revision.has_value() && expected_revision.value() == INT32_MIN)
{
values_on_not_written.at(static_cast<uint8_t>(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<uint8_t>(version_integer_component::build_number)) = INT32_MAX;
}
major = values_on_not_written.at(static_cast<uint8_t>(version_integer_component::major));
minor = values_on_not_written.at(static_cast<uint8_t>(version_integer_component::minor));
revision = values_on_not_written.at(static_cast<uint8_t>(version_integer_component::revision));
build_number = values_on_not_written.at(static_cast<uint8_t>(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<int32_t>(major_pass & mask_to_fit_value_int32)};
const auto minor{static_cast<int32_t>(minor_pass & mask_to_fit_value_int32)};
const auto revision{static_cast<int32_t>(revision_pass & mask_to_fit_value_int32)};
const auto build_number{static_cast<int32_t>(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<uint8_t>(version_integer_component::major)) || major != expected_major.value())
if (major == values_on_not_written.at(static_cast<uint8_t>(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<uint8_t>(version_integer_component::major)))
if (major != values_on_not_written.at(static_cast<uint8_t>(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<uint8_t>(version_integer_component::minor)) || minor != expected_minor.value())
if (minor == values_on_not_written.at(static_cast<uint8_t>(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<uint8_t>(version_integer_component::minor)))
if (minor != values_on_not_written.at(static_cast<uint8_t>(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<uint8_t>(version_integer_component::revision)) || revision != expected_revision.value())
if (revision == values_on_not_written.at(static_cast<uint8_t>(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<uint8_t>(version_integer_component::revision)))
if (revision != values_on_not_written.at(static_cast<uint8_t>(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);