From 32cb4545cc2843e4b177c43a9a5c361e36679b79 Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov aka xDimon Date: Mon, 20 Jan 2025 19:49:10 +0800 Subject: [PATCH 01/30] refactor: force apply clang-format Signed-off-by: Dmitriy Khaustov aka xDimon --- cmake/Hunter/config.cmake | 5 +++++ .../state/requests/get_storage_size.hpp | 2 +- core/application/app_configuration.hpp | 4 ++-- core/application/modes/precompile_wasm.cpp | 3 ++- core/blockchain/impl/block_tree_impl.cpp | 20 +++++++++---------- core/common/blob.hpp | 8 ++++---- core/common/buffer.hpp | 2 +- .../babe/impl/babe_config_repository_impl.cpp | 2 +- .../grandpa/impl/environment_impl.cpp | 3 +-- core/consensus/grandpa/impl/grandpa_impl.cpp | 2 +- core/consensus/timeline/types.hpp | 3 +-- .../impl/dispute_coordinator_impl.cpp | 12 +++++------ core/injector/application_injector.cpp | 2 +- .../impl/protocols/beefy_protocol_impl.cpp | 4 +--- core/network/impl/protocols/parachain.cpp | 2 +- core/network/types/grandpa_message.hpp | 3 +-- .../approval/approval_distribution.cpp | 9 ++++----- .../approval/approval_distribution.hpp | 5 ++--- .../approval/approval_thread_pool.hpp | 2 +- .../availability/fetch/fetch_impl.cpp | 6 +++--- core/parachain/pvf/module_precompiler.cpp | 7 +++++-- core/parachain/pvf/precheck.cpp | 3 ++- .../statement_distribution.cpp | 6 ++---- core/primitives/event_types.hpp | 2 +- .../binaryen/module/module_factory_impl.cpp | 3 ++- .../runtime/common/runtime_instances_pool.cpp | 3 +-- .../runtime_api/transaction_payment_api.hpp | 3 +-- core/runtime/wabt/instrument.cpp | 3 ++- .../trie/polkadot_trie/polkadot_trie_impl.cpp | 12 +++++------ core/telemetry/impl/connection_impl.cpp | 4 ++-- node/main.cpp | 8 ++++---- .../core/api/service/chain/chain_api_test.cpp | 6 ++---- .../core/api/service/state/state_api_test.cpp | 6 ++---- test/core/consensus/grandpa/chain_test.cpp | 3 +-- .../core/parachain/prospective_parachains.cpp | 3 ++- .../mock/core/runtime/parachain_host_mock.hpp | 9 +++++---- 36 files changed, 89 insertions(+), 91 deletions(-) diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 069debd195..ae175e4b74 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -111,3 +111,8 @@ hunter_config( KEEP_PACKAGE_SOURCES ) +hunter_config( + qtils + URL https://github.com/qdrvm/qtils/archive/0dd35029f54e9a6218ee261b0227ef23762f2d4b.tar.gz + SHA1 66ec5b05cc3a864f896f19021c1f3b44d096588a +) diff --git a/core/api/service/state/requests/get_storage_size.hpp b/core/api/service/state/requests/get_storage_size.hpp index 49db76170b..5debe604f5 100644 --- a/core/api/service/state/requests/get_storage_size.hpp +++ b/core/api/service/state/requests/get_storage_size.hpp @@ -24,7 +24,7 @@ namespace kagome::api::state::request { GetStorageSize &operator=(GetStorageSize &&) = default; explicit GetStorageSize(std::shared_ptr api) - : api_(std::move(api)) {}; + : api_(std::move(api)){}; ~GetStorageSize() = default; outcome::result init(const jsonrpc::Request::Parameters ¶ms); diff --git a/core/application/app_configuration.hpp b/core/application/app_configuration.hpp index d77402de77..1324b7f73f 100644 --- a/core/application/app_configuration.hpp +++ b/core/application/app_configuration.hpp @@ -218,8 +218,8 @@ namespace kagome::application { * List of telemetry endpoints specified via CLI argument or config file * @return a vector of parsed telemetry endpoints */ - virtual const std::vector - &telemetryEndpoints() const = 0; + virtual const std::vector & + telemetryEndpoints() const = 0; /** * @return enum constant of the chosen sync method diff --git a/core/application/modes/precompile_wasm.cpp b/core/application/modes/precompile_wasm.cpp index 10e9e13ec6..49d0e441b9 100644 --- a/core/application/modes/precompile_wasm.cpp +++ b/core/application/modes/precompile_wasm.cpp @@ -78,7 +78,8 @@ namespace kagome::application::mode { auto code_hash = hasher_->blake2b_256(bytes); OUTCOME_TRY(config, parachain::sessionParams(*parachain_api_, block.hash)); - OUTCOME_TRY(module_factory_->precompile(code_hash, bytes, config.context_params)); + OUTCOME_TRY( + module_factory_->precompile(code_hash, bytes, config.context_params)); } return outcome::success(); } diff --git a/core/blockchain/impl/block_tree_impl.cpp b/core/blockchain/impl/block_tree_impl.cpp index c17bf6e557..360a806a27 100644 --- a/core/blockchain/impl/block_tree_impl.cpp +++ b/core/blockchain/impl/block_tree_impl.cpp @@ -395,16 +395,16 @@ namespace kagome::blockchain { std::shared_ptr state_pruner, common::MainThreadPool &main_thread_pool) : block_tree_data_{BlockTreeData{ - .storage_ = std::move(storage), - .state_pruner_ = std::move(state_pruner), - .tree_ = std::make_unique(finalized), - .hasher_ = std::move(hasher), - .extrinsic_event_key_repo_ = std::move(extrinsic_event_key_repo), - .justification_storage_policy_ = - std::move(justification_storage_policy), - .genesis_block_hash_ = {}, - .blocks_pruning_ = {app_config.blocksPruning(), finalized.number}, - }}, + .storage_ = std::move(storage), + .state_pruner_ = std::move(state_pruner), + .tree_ = std::make_unique(finalized), + .hasher_ = std::move(hasher), + .extrinsic_event_key_repo_ = std::move(extrinsic_event_key_repo), + .justification_storage_policy_ = + std::move(justification_storage_policy), + .genesis_block_hash_ = {}, + .blocks_pruning_ = {app_config.blocksPruning(), finalized.number}, + }}, chain_events_engine_{std::move(chain_events_engine)}, main_pool_handler_{main_thread_pool.handlerStarted()}, extrinsic_events_engine_{std::move(extrinsic_events_engine)} { diff --git a/core/common/blob.hpp b/core/common/blob.hpp index 1a0807c5ec..87ec763881 100644 --- a/core/common/blob.hpp +++ b/core/common/blob.hpp @@ -90,8 +90,8 @@ struct fmt::formatter \ : fmt::formatter { \ template \ - auto format(const space_name::class_name &blob, \ - FormatCtx &ctx) const -> decltype(ctx.out()) { \ + auto format(const space_name::class_name &blob, FormatCtx &ctx) const \ + -> decltype(ctx.out()) { \ return fmt::formatter::format(blob, ctx); \ } \ }; @@ -277,8 +277,8 @@ struct fmt::formatter> { // Formats the Blob using the parsed format specification (presentation) // stored in this formatter. template - auto format(const kagome::common::Blob &blob, - FormatContext &ctx) const -> decltype(ctx.out()) { + auto format(const kagome::common::Blob &blob, FormatContext &ctx) const + -> decltype(ctx.out()) { if (presentation == 's') { if constexpr (N > 4) { uint16_t head = static_cast(blob[1]) diff --git a/core/common/buffer.hpp b/core/common/buffer.hpp index 35f4937a59..677d714a8d 100644 --- a/core/common/buffer.hpp +++ b/core/common/buffer.hpp @@ -54,7 +54,7 @@ namespace kagome::common { explicit SLBuffer(const std::array &other) : Base(other.begin(), other.end()) {} - SLBuffer(const uint8_t *begin, const uint8_t *end) : Base(begin, end) {}; + SLBuffer(const uint8_t *begin, const uint8_t *end) : Base(begin, end){}; using Base::Base; using Base::operator=; diff --git a/core/consensus/babe/impl/babe_config_repository_impl.cpp b/core/consensus/babe/impl/babe_config_repository_impl.cpp index 9d2556e502..9abb36ed44 100644 --- a/core/consensus/babe/impl/babe_config_repository_impl.cpp +++ b/core/consensus/babe/impl/babe_config_repository_impl.cpp @@ -57,7 +57,7 @@ namespace kagome::consensus::babe { primitives::events::ChainSubscriptionEnginePtr chain_events_engine, LazySPtr slots_util) : persistent_storage_( - persistent_storage->getSpace(storage::Space::kDefault)), + persistent_storage->getSpace(storage::Space::kDefault)), config_warp_sync_{app_config.syncMethod() == application::SyncMethod::Warp}, timings_(timings), diff --git a/core/consensus/grandpa/impl/environment_impl.cpp b/core/consensus/grandpa/impl/environment_impl.cpp index e9dd9d91eb..c075152dd9 100644 --- a/core/consensus/grandpa/impl/environment_impl.cpp +++ b/core/consensus/grandpa/impl/environment_impl.cpp @@ -220,8 +220,7 @@ namespace kagome::consensus::grandpa { // Select best block with actual set_id if (voter_set_id.has_value()) { while (best_block.number > finalized.number) { - OUTCOME_TRY(header, - block_tree_->getBlockHeader(best_block.hash)); + OUTCOME_TRY(header, block_tree_->getBlockHeader(best_block.hash)); auto parent_block = *header.parentInfo(); auto voter_set = authority_manager_->authorities( diff --git a/core/consensus/grandpa/impl/grandpa_impl.cpp b/core/consensus/grandpa/impl/grandpa_impl.cpp index b45077338f..21ef8173d9 100644 --- a/core/consensus/grandpa/impl/grandpa_impl.cpp +++ b/core/consensus/grandpa/impl/grandpa_impl.cpp @@ -1410,7 +1410,7 @@ namespace kagome::consensus::grandpa { auto *index = vote.is() ? &votes.prevote_idx : vote.is() ? &votes.precommit_idx : nullptr; - if (index and not*index) { + if (index and not *index) { *index = votes.seen.size(); } } diff --git a/core/consensus/timeline/types.hpp b/core/consensus/timeline/types.hpp index 4ed1f15510..616b1fadb7 100644 --- a/core/consensus/timeline/types.hpp +++ b/core/consensus/timeline/types.hpp @@ -34,8 +34,7 @@ namespace kagome::consensus { template SlotDuration(const std::chrono::duration &duration) : std::chrono::milliseconds( - std::chrono::duration_cast(duration)) { - } + std::chrono::duration_cast(duration)) {} template requires std::is_integral_v diff --git a/core/dispute_coordinator/impl/dispute_coordinator_impl.cpp b/core/dispute_coordinator/impl/dispute_coordinator_impl.cpp index bf902625d7..bc4e6c781f 100644 --- a/core/dispute_coordinator/impl/dispute_coordinator_impl.cpp +++ b/core/dispute_coordinator/impl/dispute_coordinator_impl.cpp @@ -1227,12 +1227,12 @@ namespace kagome::dispute { auto is_old_concluded_for = intermediate_result.old_state.dispute_status.has_value() ? is_type( - intermediate_result.old_state.dispute_status.value()) + intermediate_result.old_state.dispute_status.value()) : false; auto is_new_concluded_for = intermediate_result.new_state.dispute_status.has_value() ? is_type( - intermediate_result.new_state.dispute_status.value()) + intermediate_result.new_state.dispute_status.value()) : false; auto is_freshly_concluded_for = not is_old_concluded_for and is_new_concluded_for; @@ -1240,12 +1240,12 @@ namespace kagome::dispute { auto is_old_concluded_against = intermediate_result.old_state.dispute_status.has_value() ? is_type( - intermediate_result.old_state.dispute_status.value()) + intermediate_result.old_state.dispute_status.value()) : false; auto is_new_concluded_against = intermediate_result.new_state.dispute_status.has_value() ? is_type( - intermediate_result.new_state.dispute_status.value()) + intermediate_result.new_state.dispute_status.value()) : false; auto is_freshly_concluded_against = not is_old_concluded_against and is_new_concluded_against; @@ -1256,12 +1256,12 @@ namespace kagome::dispute { auto is_old_confirmed_concluded = intermediate_result.old_state.dispute_status.has_value() ? not is_type( - intermediate_result.old_state.dispute_status.value()) + intermediate_result.old_state.dispute_status.value()) : false; auto is_new_confirmed_concluded = intermediate_result.new_state.dispute_status.has_value() ? not is_type( - intermediate_result.new_state.dispute_status.value()) + intermediate_result.new_state.dispute_status.value()) : false; auto is_freshly_confirmed = not is_old_confirmed_concluded and is_new_confirmed_concluded; diff --git a/core/injector/application_injector.cpp b/core/injector/application_injector.cpp index 07afea544a..d50e27e270 100644 --- a/core/injector/application_injector.cpp +++ b/core/injector/application_injector.cpp @@ -963,7 +963,7 @@ namespace kagome::injector { KagomeNodeInjector::KagomeNodeInjector( sptr app_config) : pimpl_{std::make_unique( - makeKagomeNodeInjector(std::move(app_config)))} {} + makeKagomeNodeInjector(std::move(app_config)))} {} sptr KagomeNodeInjector::injectAppConfig() { return pimpl_->injector_ diff --git a/core/network/impl/protocols/beefy_protocol_impl.cpp b/core/network/impl/protocols/beefy_protocol_impl.cpp index 915f694d18..5e8d8846b2 100644 --- a/core/network/impl/protocols/beefy_protocol_impl.cpp +++ b/core/network/impl/protocols/beefy_protocol_impl.cpp @@ -23,9 +23,7 @@ namespace kagome::network { Roles roles, std::shared_ptr beefy) : notifications_{notifications_factory.make( - {make_protocols(kBeefyProtocol, genesis)}, - kPeersLimit, - kPeersLimit)}, + {make_protocols(kBeefyProtocol, genesis)}, kPeersLimit, kPeersLimit)}, roles_{roles}, beefy_{std::move(beefy)} {} diff --git a/core/network/impl/protocols/parachain.cpp b/core/network/impl/protocols/parachain.cpp index 72fc8f7816..83f8b860e8 100644 --- a/core/network/impl/protocols/parachain.cpp +++ b/core/network/impl/protocols/parachain.cpp @@ -66,7 +66,7 @@ namespace kagome::network { size_t limit_in, size_t limit_out) : notifications_{inject.notifications_factory->make( - std::move(protocols_groups), limit_in, limit_out)}, + std::move(protocols_groups), limit_in, limit_out)}, collation_versions_{CollationVersion::VStaging, CollationVersion::V1}, roles_{inject.roles}, peer_manager_{inject.peer_manager}, diff --git a/core/network/types/grandpa_message.hpp b/core/network/types/grandpa_message.hpp index 6a1ad82e79..973ea62abe 100644 --- a/core/network/types/grandpa_message.hpp +++ b/core/network/types/grandpa_message.hpp @@ -29,8 +29,7 @@ namespace kagome::network { struct GrandpaVote : public VoteMessage { using VoteMessage::VoteMessage; - explicit GrandpaVote(VoteMessage &&vm) - : VoteMessage(std::move(vm)){}; + explicit GrandpaVote(VoteMessage &&vm) : VoteMessage(std::move(vm)){}; }; // Network level commit message with topic information. diff --git a/core/parachain/approval/approval_distribution.cpp b/core/parachain/approval/approval_distribution.cpp index 13e3622bb1..323dc67c60 100644 --- a/core/parachain/approval/approval_distribution.cpp +++ b/core/parachain/approval/approval_distribution.cpp @@ -588,7 +588,7 @@ namespace kagome::parachain { common::MainThreadPool &main_thread_pool, LazySPtr dispute_coordinator) : approval_thread_handler_{poolHandlerReadyMake( - this, app_state_manager, approval_thread_pool, logger_)}, + this, app_state_manager, approval_thread_pool, logger_)}, worker_pool_handler_{worker_thread_pool.handler(*app_state_manager)}, parachain_host_(std::move(parachain_host)), slots_util_(slots_util), @@ -2894,10 +2894,9 @@ namespace kagome::parachain { }; return approval::min_or_some( e.next_no_show, - (e.last_assignment_tick - ? filter(*e.last_assignment_tick + kApprovalDelay, - tick_now) - : std::optional{})); + (e.last_assignment_tick ? filter( + *e.last_assignment_tick + kApprovalDelay, tick_now) + : std::optional{})); }, [&](const approval::PendingRequiredTranche &e) { std::optional next_announced{}; diff --git a/core/parachain/approval/approval_distribution.hpp b/core/parachain/approval/approval_distribution.hpp index a42584100e..4ac4185db9 100644 --- a/core/parachain/approval/approval_distribution.hpp +++ b/core/parachain/approval/approval_distribution.hpp @@ -240,9 +240,8 @@ namespace kagome::parachain { CandidateEntry(const network::CandidateReceipt &receipt, SessionIndex session_index, size_t approvals_size) - : CandidateEntry(HashedCandidateReceipt{receipt}, - session_index, - approvals_size) {} + : CandidateEntry( + HashedCandidateReceipt{receipt}, session_index, approvals_size) {} std::optional> approval_entry( const network::RelayHash &relay_hash) { diff --git a/core/parachain/approval/approval_thread_pool.hpp b/core/parachain/approval/approval_thread_pool.hpp index 711afe0e56..8b0994b8e1 100644 --- a/core/parachain/approval/approval_thread_pool.hpp +++ b/core/parachain/approval/approval_thread_pool.hpp @@ -20,6 +20,6 @@ namespace kagome::parachain { public: StatementDistributionThreadPool(std::shared_ptr watchdog) : ThreadPool( - std::move(watchdog), "statement-distribution", 1, std::nullopt) {} + std::move(watchdog), "statement-distribution", 1, std::nullopt) {} }; } // namespace kagome::parachain diff --git a/core/parachain/availability/fetch/fetch_impl.cpp b/core/parachain/availability/fetch/fetch_impl.cpp index 2ffdeb6246..53bc920e03 100644 --- a/core/parachain/availability/fetch/fetch_impl.cpp +++ b/core/parachain/availability/fetch/fetch_impl.cpp @@ -155,9 +155,9 @@ namespace kagome::parachain { return; } SL_DEBUG(log(), - "candidate={} chunk={} not found", - candidate_hash, - active.chunk_index); + "candidate={} chunk={} not found", + candidate_hash, + active.chunk_index); active_.erase(it); } diff --git a/core/parachain/pvf/module_precompiler.cpp b/core/parachain/pvf/module_precompiler.cpp index 99029f360b..42d0d6bdcc 100644 --- a/core/parachain/pvf/module_precompiler.cpp +++ b/core/parachain/pvf/module_precompiler.cpp @@ -103,8 +103,11 @@ namespace kagome::parachain { core = cores.back(); cores.pop_back(); } - auto res = self->precompileModulesForCore( - stats, last_finalized, executor_params.context_params, ParachainCore{core}); + auto res = + self->precompileModulesForCore(stats, + last_finalized, + executor_params.context_params, + ParachainCore{core}); if (!res) { using namespace std::string_literals; auto id = get_para_id(core); diff --git a/core/parachain/pvf/precheck.cpp b/core/parachain/pvf/precheck.cpp index 35bf99ac1d..47f41a18aa 100644 --- a/core/parachain/pvf/precheck.cpp +++ b/core/parachain/pvf/precheck.cpp @@ -100,7 +100,8 @@ namespace kagome::parachain { auto &code_zstd = *code_zstd_res.value(); auto res = [&]() -> outcome::result { OUTCOME_TRY(config, sessionParams(*parachain_api_, block.hash)); - OUTCOME_TRY(pvf_pool_->precompile(code_hash, code_zstd, config.context_params)); + OUTCOME_TRY(pvf_pool_->precompile( + code_hash, code_zstd, config.context_params)); return outcome::success(); }(); if (res) { diff --git a/core/parachain/validator/statement_distribution/statement_distribution.cpp b/core/parachain/validator/statement_distribution/statement_distribution.cpp index 69cb83b2b0..bddf691c2c 100644 --- a/core/parachain/validator/statement_distribution/statement_distribution.cpp +++ b/core/parachain/validator/statement_distribution/statement_distribution.cpp @@ -120,10 +120,8 @@ namespace kagome::parachain::statement_distribution { LazySPtr _slots_util, std::shared_ptr _babe_config_repo, primitives::events::PeerSubscriptionEnginePtr _peer_events_engine) - : implicit_view(_prospective_parachains, - _parachain_host, - _block_tree, - std::nullopt), + : implicit_view( + _prospective_parachains, _parachain_host, _block_tree, std::nullopt), per_session(RefCache::create()), signer_factory(std::move(sf)), peer_use_count( diff --git a/core/primitives/event_types.hpp b/core/primitives/event_types.hpp index 4235d3ae2c..c5a4aa8f41 100644 --- a/core/primitives/event_types.hpp +++ b/core/primitives/event_types.hpp @@ -308,7 +308,7 @@ namespace kagome::primitives::events { struct ChainSub { ChainSub(ChainSubscriptionEnginePtr engine) : sub{std::make_shared( - std::move(engine))} {} + std::move(engine))} {} void onBlock(ChainEventType type, auto f) { subscribe(*sub, type, [f{std::move(f)}](const ChainEventParams &args) { diff --git a/core/runtime/binaryen/module/module_factory_impl.cpp b/core/runtime/binaryen/module/module_factory_impl.cpp index d9974c3cc2..4ad595409d 100644 --- a/core/runtime/binaryen/module/module_factory_impl.cpp +++ b/core/runtime/binaryen/module/module_factory_impl.cpp @@ -43,7 +43,8 @@ namespace kagome::runtime::binaryen { } CompilationOutcome> ModuleFactoryImpl::loadCompiled( - std::filesystem::path path_compiled, const RuntimeContext::ContextParams &config) const { + std::filesystem::path path_compiled, + const RuntimeContext::ContextParams &config) const { Buffer code; if (config.wasm_ext_bulk_memory) { return CompilationError{"bulk memory is not supported"}; diff --git a/core/runtime/common/runtime_instances_pool.cpp b/core/runtime/common/runtime_instances_pool.cpp index be030038c6..1ca46b8951 100644 --- a/core/runtime/common/runtime_instances_pool.cpp +++ b/core/runtime/common/runtime_instances_pool.cpp @@ -211,8 +211,7 @@ namespace kagome::runtime { } OUTCOME_TRY(code_zstd, get_code()); OUTCOME_TRY(code, uncompressCodeIfNeeded(*code_zstd)); - BOOST_OUTCOME_TRY(code, - instrument_->instrument(code, config)); + BOOST_OUTCOME_TRY(code, instrument_->instrument(code, config)); OUTCOME_TRY(module_factory_->compile(path, code, config)); } OUTCOME_TRY(module, module_factory_->loadCompiled(path, config)); diff --git a/core/runtime/runtime_api/transaction_payment_api.hpp b/core/runtime/runtime_api/transaction_payment_api.hpp index 6b983b67f4..b70e1c7a66 100644 --- a/core/runtime/runtime_api/transaction_payment_api.hpp +++ b/core/runtime/runtime_api/transaction_payment_api.hpp @@ -17,8 +17,7 @@ namespace kagome::runtime { public: virtual ~TransactionPaymentApi() = default; - virtual outcome::result< - primitives::RuntimeDispatchInfo> + virtual outcome::result> query_info(const primitives::BlockHash &block, const primitives::Extrinsic &ext, uint32_t len) = 0; diff --git a/core/runtime/wabt/instrument.cpp b/core/runtime/wabt/instrument.cpp index b07dd33973..fbb18c5b45 100644 --- a/core/runtime/wabt/instrument.cpp +++ b/core/runtime/wabt/instrument.cpp @@ -97,7 +97,8 @@ namespace kagome::runtime { } WabtOutcome WasmInstrumenter::instrument( - common::BufferView code, const RuntimeContext::ContextParams &config) const { + common::BufferView code, + const RuntimeContext::ContextParams &config) const { return instrumentCodeForCompilation(code, config); } } // namespace kagome::runtime diff --git a/core/storage/trie/polkadot_trie/polkadot_trie_impl.cpp b/core/storage/trie/polkadot_trie/polkadot_trie_impl.cpp index 665dd2b67a..859b902e38 100644 --- a/core/storage/trie/polkadot_trie/polkadot_trie_impl.cpp +++ b/core/storage/trie/polkadot_trie/polkadot_trie_impl.cpp @@ -319,17 +319,17 @@ namespace kagome::storage::trie { PolkadotTrieImpl::PolkadotTrieImpl(RetrieveFunctions retrieve_functions) : nodes_{std::make_unique( - std::move(retrieve_functions.retrieve_node), - std::move(retrieve_functions.retrieve_value), - nullptr)}, + std::move(retrieve_functions.retrieve_node), + std::move(retrieve_functions.retrieve_value), + nullptr)}, logger_{log::createLogger("PolkadotTrie", "trie")} {} PolkadotTrieImpl::PolkadotTrieImpl(NodePtr root, RetrieveFunctions retrieve_functions) : nodes_{std::make_unique( - std::move(retrieve_functions.retrieve_node), - std::move(retrieve_functions.retrieve_value), - std::move(root))}, + std::move(retrieve_functions.retrieve_node), + std::move(retrieve_functions.retrieve_value), + std::move(root))}, logger_{log::createLogger("PolkadotTrie", "trie")} {} // PolkadotTrieImpl::~PolkadotTrieImpl() {} diff --git a/core/telemetry/impl/connection_impl.cpp b/core/telemetry/impl/connection_impl.cpp index 5c3a495f53..24ddc70c1f 100644 --- a/core/telemetry/impl/connection_impl.cpp +++ b/core/telemetry/impl/connection_impl.cpp @@ -158,9 +158,9 @@ namespace kagome::telemetry { boost::beast::lowest_layer_type & TelemetryConnectionImpl::stream_lowest_layer() { return secure_ ? boost::beast::get_lowest_layer( - *boost::relaxed_get(ws_)) + *boost::relaxed_get(ws_)) : boost::beast::get_lowest_layer( - *boost::relaxed_get(ws_)); + *boost::relaxed_get(ws_)); } template diff --git a/node/main.cpp b/node/main.cpp index f6492370f9..95c8603a42 100644 --- a/node/main.cpp +++ b/node/main.cpp @@ -36,7 +36,7 @@ int db_editor_main(int argc, const char **argv); namespace kagome { int benchmark_main(int argc, const char **argv); int key_main(int argc, const char **argv); -} +} // namespace kagome namespace { int run_node(int argc, const char **argv) { @@ -139,10 +139,10 @@ int main(int argc, const char **argv, const char **env) { auto kagome_log_configurator = custom_log_config_path.has_value() ? std::make_shared( - std::move(libp2p_log_configurator), - custom_log_config_path.value()) + std::move(libp2p_log_configurator), + custom_log_config_path.value()) : std::make_shared( - std::move(libp2p_log_configurator)); + std::move(libp2p_log_configurator)); return std::make_shared( std::move(kagome_log_configurator)); diff --git a/test/core/api/service/chain/chain_api_test.cpp b/test/core/api/service/chain/chain_api_test.cpp index 9801ff2dc0..c6db0ef455 100644 --- a/test/core/api/service/chain/chain_api_test.cpp +++ b/test/core/api/service/chain/chain_api_test.cpp @@ -103,8 +103,7 @@ TEST_F(ChainApiTest, GetBlockHashNoParam) { */ TEST_F(ChainApiTest, GetBlockHashByNumber) { // kagome::primitives::BlockId did = "D"_hash256; - EXPECT_CALL(*block_tree, getHashByNumber(42)) - .WillOnce(Return("CDE"_hash256)); + EXPECT_CALL(*block_tree, getHashByNumber(42)).WillOnce(Return("CDE"_hash256)); EXPECT_OUTCOME_TRUE(r, api->getBlockHash(42)); ASSERT_EQ(r, "CDE"_hash256); @@ -116,8 +115,7 @@ TEST_F(ChainApiTest, GetBlockHashByNumber) { * @then the correct hash value is returned */ TEST_F(ChainApiTest, GetBlockHashByHexNumber) { - EXPECT_CALL(*block_tree, getHashByNumber(42)) - .WillOnce(Return("CDE"_hash256)); + EXPECT_CALL(*block_tree, getHashByNumber(42)).WillOnce(Return("CDE"_hash256)); EXPECT_OUTCOME_TRUE(r, api->getBlockHash("0x2a")); ASSERT_EQ(r, "CDE"_hash256); diff --git a/test/core/api/service/state/state_api_test.cpp b/test/core/api/service/state/state_api_test.cpp index 68a29aed47..b4866e3ac7 100644 --- a/test/core/api/service/state/state_api_test.cpp +++ b/test/core/api/service/state/state_api_test.cpp @@ -381,8 +381,7 @@ namespace kagome::api { .WillOnce(testing::Return(block_range)); EXPECT_CALL(*block_tree_, getNumberByHash(from)) .WillOnce(testing::Return(1)); - EXPECT_CALL(*block_tree_, getNumberByHash(to)) - .WillOnce(testing::Return(4)); + EXPECT_CALL(*block_tree_, getNumberByHash(to)).WillOnce(testing::Return(4)); for (auto &block_hash : block_range) { primitives::BlockHash state_root; auto s = block_hash.toString() + "_etats"; @@ -423,8 +422,7 @@ namespace kagome::api { */ TEST_F(StateApiTest, HitsBlockRangeLimits) { primitives::BlockHash from{"from"_hash256}, to{"to"_hash256}; - EXPECT_CALL(*block_tree_, getNumberByHash(from)) - .WillOnce(Return(42)); + EXPECT_CALL(*block_tree_, getNumberByHash(from)).WillOnce(Return(42)); EXPECT_CALL(*block_tree_, getNumberByHash(to)) .WillOnce(Return(42 + StateApiImpl::kMaxBlockRange + 1)); EXPECT_OUTCOME_FALSE( diff --git a/test/core/consensus/grandpa/chain_test.cpp b/test/core/consensus/grandpa/chain_test.cpp index b96ba2ccb3..ef754fb345 100644 --- a/test/core/consensus/grandpa/chain_test.cpp +++ b/test/core/consensus/grandpa/chain_test.cpp @@ -115,8 +115,7 @@ class ChainTest : public testing::Test { BlockHeader hh; hh.number = number; hh.parent_hash = parent; - EXPECT_CALL(*tree, getBlockHeader(hash)) - .WillRepeatedly(Return(hh)); + EXPECT_CALL(*tree, getBlockHeader(hash)).WillRepeatedly(Return(hh)); }; addBlock(h[3], h[2], 42); diff --git a/test/core/parachain/prospective_parachains.cpp b/test/core/parachain/prospective_parachains.cpp index 16bd50a422..80110241fd 100644 --- a/test/core/parachain/prospective_parachains.cpp +++ b/test/core/parachain/prospective_parachains.cpp @@ -191,7 +191,8 @@ class ProspectiveParachainsTest : public ProspectiveParachainsTestHarness { .digest = {}, .hash_opt = {}, }; - EXPECT_CALL(*block_tree_, tryGetBlockHeader(h_)).WillRepeatedly(Return(h)); + EXPECT_CALL(*block_tree_, tryGetBlockHeader(h_)) + .WillRepeatedly(Return(h)); EXPECT_CALL(*parachain_api_, session_index_for_child(h_)) .WillRepeatedly(Return(outcome::success(1))); used_relay_parents.emplace(h_); diff --git a/test/mock/core/runtime/parachain_host_mock.hpp b/test/mock/core/runtime/parachain_host_mock.hpp index c3809ab968..271326c541 100644 --- a/test/mock/core/runtime/parachain_host_mock.hpp +++ b/test/mock/core/runtime/parachain_host_mock.hpp @@ -80,10 +80,11 @@ namespace kagome::runtime { (const primitives::BlockHash &, ParachainId), (override)); - MOCK_METHOD(outcome::result>>, - candidates_pending_availability, - (const primitives::BlockHash &, ParachainId), - (override)); + MOCK_METHOD( + outcome::result>>, + candidates_pending_availability, + (const primitives::BlockHash &, ParachainId), + (override)); MOCK_METHOD(outcome::result>, candidate_events, From b43dcda2f4f6b73fd36e4d6b525e829ad2eb2bc4 Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov aka xDimon Date: Tue, 4 Feb 2025 03:07:15 +0800 Subject: [PATCH 02/30] update: qtils, scale Signed-off-by: Dmitriy Khaustov aka xDimon --- cmake/Hunter/config.cmake | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index ae175e4b74..5b95ee840b 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -111,8 +111,16 @@ hunter_config( KEEP_PACKAGE_SOURCES ) +hunter_config( + scale + URL https://github.com/qdrvm/scale-codec-cpp/archive/617b1bf72a83615144d96d0d9d9a65dc661376fe.tar.gz + SHA1 7e744b6195b4cd0eb9405647d3bff043b27a5b64 + KEEP_PACKAGE_SOURCES +) + hunter_config( qtils - URL https://github.com/qdrvm/qtils/archive/0dd35029f54e9a6218ee261b0227ef23762f2d4b.tar.gz - SHA1 66ec5b05cc3a864f896f19021c1f3b44d096588a + URL https://github.com/qdrvm/qtils/archive/16e7c819dd50af2f64e2d319b918d0d815332266.tar.gz + SHA1 71989938b5c8b7650eaf1a8195c2b52c5a8c250b + KEEP_PACKAGE_SOURCES ) From 500a40edda6dff9bea16790390a9f65103aebdbd Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov aka xDimon Date: Thu, 6 Feb 2025 21:54:21 +0800 Subject: [PATCH 03/30] refactor: explicit using of Tagged Signed-off-by: Dmitriy Khaustov aka xDimon --- core/consensus/grandpa/impl/environment_impl.cpp | 2 +- core/consensus/grandpa/impl/grandpa_impl.cpp | 3 ++- .../grandpa/impl/verified_justification_queue.cpp | 8 +++++--- core/consensus/grandpa/impl/voting_round_impl.cpp | 8 ++++++-- core/network/impl/peer_manager_impl.hpp | 2 +- core/network/warp/sync.cpp | 10 +++++++--- .../grandpa/voting_round/voting_round_test.cpp | 12 +++++++++--- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/core/consensus/grandpa/impl/environment_impl.cpp b/core/consensus/grandpa/impl/environment_impl.cpp index c075152dd9..f3a64f33fb 100644 --- a/core/consensus/grandpa/impl/environment_impl.cpp +++ b/core/consensus/grandpa/impl/environment_impl.cpp @@ -421,7 +421,7 @@ namespace kagome::consensus::grandpa { outcome::result EnvironmentImpl::finalize( VoterSetId id, const GrandpaJustification &grandpa_justification) { auto voters_res = authority_manager_->authorities( - grandpa_justification.block_info, false); + grandpa_justification.block_info, IsBlockFinalized(false)); if (not voters_res) { return VotingRoundError::NO_KNOWN_AUTHORITIES_FOR_BLOCK; } diff --git a/core/consensus/grandpa/impl/grandpa_impl.cpp b/core/consensus/grandpa/impl/grandpa_impl.cpp index 21ef8173d9..3be3c154b2 100644 --- a/core/consensus/grandpa/impl/grandpa_impl.cpp +++ b/core/consensus/grandpa/impl/grandpa_impl.cpp @@ -277,7 +277,8 @@ namespace kagome::consensus::grandpa { outcome::result GrandpaImpl::makeRoundAfterLastFinalized() { auto finalized = block_tree_->getLastFinalized(); - auto authorities = authority_manager_->authorities(finalized, true); + auto authorities = + authority_manager_->authorities(finalized, IsBlockFinalized(true)); if (not authorities) { return VotingRoundError::NO_KNOWN_AUTHORITIES_FOR_BLOCK; } diff --git a/core/consensus/grandpa/impl/verified_justification_queue.cpp b/core/consensus/grandpa/impl/verified_justification_queue.cpp index 483bd59d29..bf26c2b509 100644 --- a/core/consensus/grandpa/impl/verified_justification_queue.cpp +++ b/core/consensus/grandpa/impl/verified_justification_queue.cpp @@ -18,6 +18,8 @@ namespace kagome::consensus::grandpa { /// When to start fetching justification range constexpr size_t kRangeStart = 8; + using consensus::grandpa::IsBlockFinalized; + VerifiedJustificationQueue::VerifiedJustificationQueue( application::AppStateManager &app_state_manager, common::MainThreadPool &main_thread_pool, @@ -42,7 +44,7 @@ namespace kagome::consensus::grandpa { void VerifiedJustificationQueue::start() { if (auto r = authority_manager_->authorities( - block_tree_->getLastFinalized(), true)) { + block_tree_->getLastFinalized(), IsBlockFinalized(true))) { expected_ = (**r).id; } chain_sub_.onHead([weak{weak_from_this()}]() { @@ -251,8 +253,8 @@ namespace kagome::consensus::grandpa { void VerifiedJustificationQueue::warp() { if (auto r = authority_manager_->authorities( - block_tree_->getLastFinalized(), true)) { - expected_ = (**r).id; + block_tree_->getLastFinalized(), IsBlockFinalized(true))) { + expected_ = (*r)->id; } required_.clear(); } diff --git a/core/consensus/grandpa/impl/voting_round_impl.cpp b/core/consensus/grandpa/impl/voting_round_impl.cpp index f868877ebc..38f2fe5933 100644 --- a/core/consensus/grandpa/impl/voting_round_impl.cpp +++ b/core/consensus/grandpa/impl/voting_round_impl.cpp @@ -538,7 +538,9 @@ namespace kagome::consensus::grandpa { } auto &signed_prevote = signed_prevote_opt.value(); if (onPrevote({}, signed_prevote, Propagation::NEEDLESS)) { - update(false, true, false); + update(IsPreviousRoundChanged{false}, + IsPrevotesChanged{true}, + IsPrecommitsChanged{false}); } env_->onVoted(round_number_, voter_set_->id(), signed_prevote); } @@ -586,7 +588,9 @@ namespace kagome::consensus::grandpa { } auto &signed_precommit = signed_precommit_opt.value(); if (onPrecommit({}, signed_precommit, Propagation::NEEDLESS)) { - update(false, false, true); + update(IsPreviousRoundChanged{false}, + IsPrevotesChanged{false}, + IsPrecommitsChanged{true}); } env_->onVoted(round_number_, voter_set_->id(), signed_precommit); } diff --git a/core/network/impl/peer_manager_impl.hpp b/core/network/impl/peer_manager_impl.hpp index 732fb6342f..a4af742340 100644 --- a/core/network/impl/peer_manager_impl.hpp +++ b/core/network/impl/peer_manager_impl.hpp @@ -164,7 +164,7 @@ namespace kagome::network { void clearClosedPingingConnections(); using IsLight = Tagged; - size_t countPeers(PeerType in_out, IsLight in_light = false) const; + size_t countPeers(PeerType in_out, IsLight in_light = IsLight{false}) const; void collectGarbage(); diff --git a/core/network/warp/sync.cpp b/core/network/warp/sync.cpp index b33af39922..949c0a9f99 100644 --- a/core/network/warp/sync.cpp +++ b/core/network/warp/sync.cpp @@ -21,6 +21,9 @@ #include "utils/safe_object.hpp" namespace kagome::network { + + using consensus::grandpa::IsBlockFinalized; + WarpSync::WarpSync( application::AppStateManager &app_state_manager, std::shared_ptr hasher, @@ -88,9 +91,10 @@ namespace kagome::network { if (not change.scheduled and i != res.proofs.size() - 1) { return; } - auto authorities = - authority_manager_->authorities(block_tree_->getLastFinalized(), true) - .value(); + auto authorities = authority_manager_ + ->authorities(block_tree_->getLastFinalized(), + IsBlockFinalized(true)) + .value(); auto result = grandpa_->verifyJustification(fragment.justification, *authorities); diff --git a/test/core/consensus/grandpa/voting_round/voting_round_test.cpp b/test/core/consensus/grandpa/voting_round/voting_round_test.cpp index c2ecf91e1a..3902be0f7f 100644 --- a/test/core/consensus/grandpa/voting_round/voting_round_test.cpp +++ b/test/core/consensus/grandpa/voting_round/voting_round_test.cpp @@ -356,12 +356,16 @@ TEST_F(VotingRoundTest, EquivocateDoesNotDoubleCount) { // Another vote in the same round; should be ignored, cause already reported round_->onPrevote({}, alice3, Propagation::NEEDLESS); - round_->update(false, true, false); + round_->update(IsPreviousRoundChanged{false}, + IsPrevotesChanged{true}, + IsPrecommitsChanged{false}); ASSERT_EQ(round_->prevoteGhost(), std::nullopt); auto bob = preparePrevote(kBob, kBobSignature, Prevote{7, "FA"_H}); round_->onPrevote({}, bob, Propagation::NEEDLESS); - round_->update(false, true, false); + round_->update(IsPreviousRoundChanged{false}, + IsPrevotesChanged{true}, + IsPrecommitsChanged{false}); ASSERT_EQ(round_->prevoteGhost(), (BlockInfo{7, "FA"_H})); } @@ -390,7 +394,9 @@ TEST_F(VotingRoundTest, HistoricalVotesWorks) { saveHistoricalVote( round_->voterSetId(), round_->roundNumber(), alice2, true)); round_->onPrevote({}, alice2, Propagation::NEEDLESS); - round_->update(false, true, true); + round_->update(IsPreviousRoundChanged{false}, + IsPrevotesChanged{true}, + IsPrecommitsChanged{true}); } /** From c5bcdf27a7884c2f23e13169f24b2a8137559500 Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov aka xDimon Date: Tue, 28 Jan 2025 15:21:54 +0800 Subject: [PATCH 04/30] feature: adapt to support aggregate coding Signed-off-by: Dmitriy Khaustov aka xDimon --- core/api/jrpc/value_converter.hpp | 8 +- .../impl/app_configuration_impl.cpp | 7 +- .../query/authority_peer_info.hpp | 3 - core/authority_discovery/query/query_impl.cpp | 4 +- core/benchmark/block_execution_benchmark.cpp | 30 ++-- core/blockchain/impl/cached_tree.cpp | 2 +- core/blockchain/indexer.hpp | 5 +- core/common/custom_equality.hpp | 17 +++ core/common/empty.hpp | 27 ++-- core/common/tagged.hpp | 86 ++--------- core/common/unused.hpp | 37 ++--- core/common/visitor.hpp | 5 - .../babe/impl/babe_block_validator_impl.hpp | 1 + .../babe/impl/babe_config_repository_impl.hpp | 5 +- .../consensus/babe/impl/babe_digests_util.cpp | 3 +- .../consensus/babe/impl/babe_lottery_impl.cpp | 7 +- core/consensus/babe/types/authority.hpp | 3 +- .../babe/types/babe_configuration.hpp | 4 - core/consensus/babe/types/epoch_data.hpp | 2 - .../babe/types/equivocation_proof.hpp | 4 +- .../consensus/babe/types/scheduled_change.hpp | 5 +- core/consensus/babe/types/seal.hpp | 3 - core/consensus/beefy/types.hpp | 9 +- core/consensus/grandpa/historical_votes.hpp | 2 - .../grandpa/impl/authority_manager_impl.hpp | 8 +- .../grandpa/impl/environment_impl.cpp | 10 +- .../impl/vote_crypto_provider_impl.cpp | 7 +- .../consensus/grandpa/movable_round_state.hpp | 3 - core/consensus/grandpa/structs.hpp | 30 +--- core/consensus/grandpa/types/authority.hpp | 11 +- .../grandpa/types/equivocation_proof.hpp | 3 - .../grandpa/types/scheduled_change.hpp | 25 --- core/consensus/grandpa/voter_set.hpp | 2 +- core/consensus/timeline/types.hpp | 1 - .../bandersnatch_provider_impl.cpp | 6 +- core/crypto/bandersnatch/vrf.hpp | 4 - core/crypto/bandersnatch_types.hpp | 1 - core/crypto/ecdsa/ecdsa_provider_impl.cpp | 7 +- core/crypto/ed25519/ed25519_provider_impl.cpp | 3 +- core/crypto/ed25519_types.hpp | 3 - core/crypto/sr25519_types.hpp | 6 +- .../impl/prioritized_selection.hpp | 2 - core/dispute_coordinator/types.hpp | 8 - .../types/block_announce_handshake.hpp | 9 +- core/network/types/block_attributes.hpp | 12 +- core/network/types/collator_messages.hpp | 68 +-------- .../types/collator_messages_vstaging.hpp | 41 ++--- core/network/types/dispute_messages.hpp | 7 - core/network/types/grandpa_message.hpp | 15 +- core/network/types/propagate_transactions.hpp | 3 - core/network/types/roles.hpp | 8 +- core/network/types/state_request.hpp | 3 - core/network/warp/sync.hpp | 2 - core/network/warp/types.hpp | 4 - core/offchain/impl/http_request.cpp | 7 +- core/offchain/types.hpp | 1 - core/parachain/approval/approval.hpp | 24 +-- .../approval/approval_distribution.hpp | 8 +- core/parachain/availability/chunks.hpp | 2 + core/parachain/backing/cluster.hpp | 15 +- core/parachain/parachain_inherent_data.hpp | 2 - .../parachain/peer_relay_parent_knowledge.hpp | 1 - core/parachain/pvf/pvf_impl.cpp | 4 +- core/parachain/pvf/pvf_impl.hpp | 2 - core/parachain/pvf/pvf_worker_types.hpp | 5 +- core/parachain/pvf/runtime_params.hpp | 1 - core/parachain/pvf/secure_mode_precheck.hpp | 3 - core/parachain/types.hpp | 46 ++---- core/parachain/ump_signal.hpp | 2 - .../validator/parachain_processor.hpp | 6 +- core/parachain/validator/signer.hpp | 2 - core/primitives/apply_result.hpp | 15 +- core/primitives/arithmetic_error.hpp | 14 +- core/primitives/block.hpp | 6 +- core/primitives/block_data.hpp | 4 +- core/primitives/block_header.hpp | 30 ++-- core/primitives/check_inherents_result.hpp | 2 - core/primitives/common.hpp | 10 +- core/primitives/digest.hpp | 49 ++++-- core/primitives/extrinsic.hpp | 4 +- core/primitives/inherent_data.cpp | 14 -- core/primitives/inherent_data.hpp | 46 ++---- core/primitives/justification.hpp | 4 +- core/primitives/kill_storage_result.hpp | 5 +- core/primitives/mmr.hpp | 3 - core/primitives/parachain_host.hpp | 1 - core/primitives/rpc_methods.hpp | 4 - core/primitives/runtime_dispatch_info.hpp | 35 +---- core/primitives/token_error.hpp | 12 +- core/primitives/transaction_validity.hpp | 25 ++- core/primitives/version.hpp | 3 - .../common/runtime_upgrade_tracker_impl.hpp | 11 -- core/runtime/heap_alloc_strategy.hpp | 9 +- .../runtime_api/parachain_host_types.hpp | 45 ++---- core/runtime/runtime_context.hpp | 2 +- core/runtime/types.hpp | 5 +- core/runtime/wavm/module_factory_impl.cpp | 5 +- core/scale/big_fixed_integers.hpp | 137 +++++++---------- core/scale/encoder/primitives.hpp | 14 +- core/scale/kagome_scale.hpp | 20 ++- core/scale/tie.hpp | 142 ------------------ core/scale/tie_hash.hpp | 24 ++- .../trie_pruner/impl/trie_pruner_impl.cpp | 1 + .../trie_pruner/impl/trie_pruner_impl.hpp | 6 - core/utils/struct_to_tuple.hpp | 2 +- .../api/service/payment/payment_api_test.cpp | 6 +- test/core/common/buffer_view_test.cpp | 3 + .../grandpa/authority_manager_test.cpp | 2 +- test/core/network/rpc_libp2p_test.cpp | 10 +- test/core/runtime/allocator_test.cpp | 7 - test/core/runtime/executor_test.cpp | 12 +- test/testutil/outcome.hpp | 2 + test/testutil/scale_test_comparator.hpp | 4 +- 113 files changed, 435 insertions(+), 1042 deletions(-) create mode 100644 core/common/custom_equality.hpp delete mode 100644 core/scale/tie.hpp diff --git a/core/api/jrpc/value_converter.hpp b/core/api/jrpc/value_converter.hpp index 1bb78fe30e..cd3cc5466b 100644 --- a/core/api/jrpc/value_converter.hpp +++ b/core/api/jrpc/value_converter.hpp @@ -98,19 +98,19 @@ namespace kagome::api { } inline jsonrpc::Value makeValue(const primitives::Balance &val) { - jsonrpc::Value ret((*val).str()); + jsonrpc::Value ret(val.str()); return ret; } inline jsonrpc::Value makeValue(const primitives::Weight &val) { jStruct data; - data["ref_time"] = static_cast(*val.ref_time); - data["proof_size"] = static_cast(*val.proof_size); + data["ref_time"] = static_cast(val.ref_time); + data["proof_size"] = static_cast(val.proof_size); return data; } inline jsonrpc::Value makeValue(const primitives::OldWeight &val) { - jsonrpc::Value ret(static_cast(*val)); + jsonrpc::Value ret(static_cast(val)); return ret; } diff --git a/core/application/impl/app_configuration_impl.cpp b/core/application/impl/app_configuration_impl.cpp index 123819f19a..2b70936760 100644 --- a/core/application/impl/app_configuration_impl.cpp +++ b/core/application/impl/app_configuration_impl.cpp @@ -178,11 +178,12 @@ namespace { static constexpr std::array - interpreters{ + interpreters { #if KAGOME_WASM_COMPILER_WASM_EDGE == 1 - "WasmEdge", + "WasmEdge", #endif - "Binaryen"}; + "Binaryen" + }; static const std::string interpreters_str = fmt::format("[{}]", fmt::join(interpreters, ", ")); diff --git a/core/authority_discovery/query/authority_peer_info.hpp b/core/authority_discovery/query/authority_peer_info.hpp index 5393aa6d11..0b4c0dc925 100644 --- a/core/authority_discovery/query/authority_peer_info.hpp +++ b/core/authority_discovery/query/authority_peer_info.hpp @@ -10,12 +10,9 @@ #include "authority_discovery/timestamp.hpp" #include "common/buffer.hpp" #include "scale/libp2p_types.hpp" -#include "scale/tie.hpp" namespace kagome::authority_discovery { struct AuthorityPeerInfo { - SCALE_TIE(3); - common::Buffer raw{}; std::optional time{}; ::scale::PeerInfoSerializable peer{}; diff --git a/core/authority_discovery/query/query_impl.cpp b/core/authority_discovery/query/query_impl.cpp index ef2c347066..75009a5ced 100644 --- a/core/authority_discovery/query/query_impl.cpp +++ b/core/authority_discovery/query/query_impl.cpp @@ -311,8 +311,8 @@ namespace kagome::authority_discovery { OUTCOME_TRY(tmp, scale::decode( qtils::str2byte(record.creation_time().timestamp()))); - time = *tmp; - if (it and it->time and time <= it->time->number) { + time = (Timestamp)tmp; + if (it and it->time and time <= it->time) { SL_TRACE(log_, "lookup: outdated record for authority {}", authority); return outcome::success(); } diff --git a/core/benchmark/block_execution_benchmark.cpp b/core/benchmark/block_execution_benchmark.cpp index 30e8fd275b..9d65f500f0 100644 --- a/core/benchmark/block_execution_benchmark.cpp +++ b/core/benchmark/block_execution_benchmark.cpp @@ -10,6 +10,7 @@ #include #include +#include #include "blockchain/block_tree.hpp" #include "primitives/runtime_dispatch_info.hpp" @@ -17,6 +18,8 @@ #include "runtime/runtime_api/core.hpp" #include "storage/trie/trie_storage.hpp" +#define OUTCOME_UNIQUE QTILS_UNIQUE_NAME(outcome) + OUTCOME_CPP_DEFINE_CATEGORY(kagome::benchmark, BlockExecutionBenchmark::Error, e) { @@ -192,8 +195,6 @@ namespace kagome::benchmark { template struct PerDispatchClass { - SCALE_TIE(3) - // value for `Normal` extrinsics. T normal; // value for `Operational` extrinsics. @@ -204,20 +205,19 @@ namespace kagome::benchmark { primitives::Weight totalWeight( const PerDispatchClass &weight_per_class) { - return primitives::Weight{ - weight_per_class.normal.ref_time.number - + weight_per_class.operational.ref_time.number - + weight_per_class.mandatory.ref_time.number, - weight_per_class.normal.proof_size.number - + weight_per_class.operational.proof_size.number - + weight_per_class.mandatory.proof_size.number}; + return primitives::Weight{weight_per_class.normal.ref_time + + weight_per_class.operational.ref_time + + weight_per_class.mandatory.ref_time, + weight_per_class.normal.proof_size + + weight_per_class.operational.proof_size + + weight_per_class.mandatory.proof_size}; } primitives::OldWeight totalWeight( const PerDispatchClass &weight_per_class) { - return primitives::OldWeight{weight_per_class.normal.number - + weight_per_class.operational.number - + weight_per_class.mandatory.number}; + return primitives::OldWeight{weight_per_class.normal + + weight_per_class.operational + + weight_per_class.mandatory}; } using ConsumedWeight = PerDispatchClass; @@ -245,9 +245,9 @@ namespace kagome::benchmark { return BlockExecutionBenchmark::Error::BLOCK_WEIGHT_DECODE_FAILED; } - return std::chrono::nanoseconds{static_cast(std::floor( - static_cast(totalWeight(block_weight).ref_time.number) - / static_cast(WEIGHT_REF_TIME_PER_NANOS)))}; + return std::chrono::nanoseconds{static_cast( + std::floor(static_cast(totalWeight(block_weight).ref_time) + / static_cast(WEIGHT_REF_TIME_PER_NANOS)))}; } outcome::result BlockExecutionBenchmark::run(const Config config) { diff --git a/core/blockchain/impl/cached_tree.cpp b/core/blockchain/impl/cached_tree.cpp index 0332b8f24e..5dcb7b1712 100644 --- a/core/blockchain/impl/cached_tree.cpp +++ b/core/blockchain/impl/cached_tree.cpp @@ -91,7 +91,7 @@ namespace kagome::blockchain { bool operator()(const std::shared_ptr &lhs, const std::shared_ptr &rhs) const { BOOST_ASSERT(lhs and rhs); - return lhs->info > rhs->info; + return rhs->info < lhs->info; } }; diff --git a/core/blockchain/indexer.hpp b/core/blockchain/indexer.hpp index 428b047c77..4f7d195480 100644 --- a/core/blockchain/indexer.hpp +++ b/core/blockchain/indexer.hpp @@ -70,8 +70,6 @@ namespace kagome::blockchain { template struct Indexed { - SCALE_TIE_ONLY(value, prev); - /** * Empty `value` means that blocks from `prev` to current have been indexed, * and current block doesn't have own `value`. @@ -85,6 +83,9 @@ namespace kagome::blockchain { * Does this block inherit value from `prev` or has own `value`. */ bool inherit = false; + + private: + SCALE_CUSTOM_DECOMPOSING(Indexed, value, prev); }; /** diff --git a/core/common/custom_equality.hpp b/core/common/custom_equality.hpp new file mode 100644 index 0000000000..8d29b2e8e5 --- /dev/null +++ b/core/common/custom_equality.hpp @@ -0,0 +1,17 @@ +/** + * Copyright Quadrivium LLC + * All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#define CUSTOM_EQUALITY(Self, ...) \ + decltype(auto) _tie() const { \ + return std::tie(__VA_ARGS__); \ + } \ + bool operator==(const Self &other) const noexcept { \ + return _tie() == other._tie(); \ + } diff --git a/core/common/empty.hpp b/core/common/empty.hpp index 35d92055f5..d1d19ff1af 100644 --- a/core/common/empty.hpp +++ b/core/common/empty.hpp @@ -6,26 +6,17 @@ #pragma once -#include +#include namespace kagome { - /// Special zero-size-type for some things /// (e.g. unsupported, experimental or empty). - struct Empty { - inline constexpr bool operator==(const Empty &) const { - return true; - } - - template - friend inline Stream &operator<<(Stream &s, const Empty &) { - return s; - } - - template - friend inline Stream &operator>>(Stream &s, const Empty &) { - return s; - } - }; - + using qtils::Empty; } // namespace kagome + +namespace qtils { + // auxiliary definition fot gtest + inline std::ostream &operator<<(std::ostream &s, const Empty &) { + return s; + } +} // namespace qtils diff --git a/core/common/tagged.hpp b/core/common/tagged.hpp index b0a858d860..8bd1517287 100644 --- a/core/common/tagged.hpp +++ b/core/common/tagged.hpp @@ -6,83 +6,19 @@ #pragma once -#include -#include - -#include +#include namespace kagome { - template >> - struct Wrapper { - template - Wrapper(Args &&...args) : value(std::forward(args)...) {} - - protected: - T value; - }; - - template , Wrapper, T>> - class Tagged : public Base { - public: - using tag = Tag; - - Tagged() : Base() {} - - Tagged(T value) : Base(std::move(value)) {} - - // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) - Tagged &operator=(T &&value) noexcept( - not std::is_lvalue_reference_v) { - if constexpr (std::is_scalar_v) { - this->Wrapper::value = std::forward(value); - } else { - static_cast(*this) = std::forward(value); - } - return *this; - } - - template - explicit operator Out() const { - // NOLINTNEXTLINE(readability-else-after-return) - if constexpr (std::is_scalar_v) { - return this->Wrapper::value; - } else { - return *this; - } - } - - private: - friend inline ::scale::ScaleEncoderStream &operator<<( - ::scale::ScaleEncoderStream &s, const Tagged &tagged) { - if constexpr (std::is_scalar_v) { - return s << tagged.Wrapper::value; - } else { - return s << static_cast(tagged); - } - } - - friend inline ::scale::ScaleDecoderStream &operator>>( - ::scale::ScaleDecoderStream &s, Tagged &tagged) { - if constexpr (std::is_scalar_v) { - s >> tagged.Wrapper::value; - } else { - s >> static_cast(tagged); - } - return s; - } - }; - - template < - typename T, - typename Tag, - typename Base = std::conditional_t, Wrapper, T>> - inline std::ostream &operator<<(std::ostream &os, - const Tagged &view) { - return os << (const T &)view; - } + /** + * The Tagged class wraps an underlying type T with an associated tag. + * It enables type safety and operator overloading while mimicking the + * behavior of T. + * + * @tparam T The underlying type. + * @tparam Tag The tag type used for differentiation. + */ + template + using Tagged = qtils::Tagged; } // namespace kagome diff --git a/core/common/unused.hpp b/core/common/unused.hpp index 538b50409e..912991f564 100644 --- a/core/common/unused.hpp +++ b/core/common/unused.hpp @@ -6,16 +6,13 @@ #pragma once -#include - #include - -#include "common/empty.hpp" -#include "common/tagged.hpp" +#include +#include namespace kagome { - enum UnusedError : uint8_t { + enum class UnusedError : uint8_t { AttemptToEncodeUnused = 1, AttemptToDecodeUnused, }; @@ -23,44 +20,30 @@ namespace kagome { using E = decltype(e); switch (e) { case E::AttemptToEncodeUnused: - return "AttemptToEncodeUnused"; + return "Attempt to encode a value that must be unused"; case E::AttemptToDecodeUnused: - return "AttemptToDecodeUnused"; + return "Attempt to decode a value that must be unused"; } abort(); } - /// Number-based marker-type for using as tag - template - struct NumTag { - private: - static constexpr size_t tag = Num; - }; - /// Special zero-size-type for some things /// (e.g., dummy types of variant, unsupported or experimental). template - using Unused = Tagged>; - - template - constexpr bool operator==(const Unused &, const Unused &) { - return true; - } + using Unused = qtils::Unused; /// To raise failure while attempt to encode unused entity template - inline ::scale::ScaleEncoderStream &operator<<(::scale::ScaleEncoderStream &s, - const Unused &) { + [[noreturn]] ::scale::ScaleEncoderStream &operator<<( + ::scale::ScaleEncoderStream &, const Unused &) { ::scale::raise(UnusedError::AttemptToEncodeUnused); - return s; } /// To raise failure while attempt to decode unused entity template - inline ::scale::ScaleDecoderStream &operator>>(::scale::ScaleDecoderStream &s, - const Unused &) { + [[noreturn]] ::scale::ScaleDecoderStream &operator>>( + ::scale::ScaleDecoderStream &, Unused &) { ::scale::raise(UnusedError::AttemptToDecodeUnused); - return s; } } // namespace kagome diff --git a/core/common/visitor.hpp b/core/common/visitor.hpp index e8f8249f22..864a4311c9 100644 --- a/core/common/visitor.hpp +++ b/core/common/visitor.hpp @@ -138,11 +138,6 @@ namespace kagome { return boost::get(&variant) != nullptr; } - template - constexpr bool is_tagged_by(TVariant &&variant) { - return is_type>(&variant); - } - /// apply Matcher to optional T template constexpr decltype(auto) match(T &&t, Matcher &&m) { diff --git a/core/consensus/babe/impl/babe_block_validator_impl.hpp b/core/consensus/babe/impl/babe_block_validator_impl.hpp index 39614ecb62..2ca86f6cb5 100644 --- a/core/consensus/babe/impl/babe_block_validator_impl.hpp +++ b/core/consensus/babe/impl/babe_block_validator_impl.hpp @@ -28,6 +28,7 @@ namespace kagome::consensus { namespace kagome::consensus::babe { class BabeConfigRepository; + struct BabeBlockHeader; struct Seal; } // namespace kagome::consensus::babe diff --git a/core/consensus/babe/impl/babe_config_repository_impl.hpp b/core/consensus/babe/impl/babe_config_repository_impl.hpp index 95aad199b5..7e4b7bdf10 100644 --- a/core/consensus/babe/impl/babe_config_repository_impl.hpp +++ b/core/consensus/babe/impl/babe_config_repository_impl.hpp @@ -43,8 +43,6 @@ namespace kagome::storage::trie { namespace kagome::consensus::babe { struct BabeIndexedValue { - SCALE_TIE_ONLY(config, state, next_state_warp); - /** * `NextConfigData` is rare digest, so always store recent config. */ @@ -62,6 +60,9 @@ namespace kagome::consensus::babe { * Next epoch lazily computed from `config` and digests. */ std::optional> next_state; + + private: + SCALE_CUSTOM_DECOMPOSING(BabeIndexedValue, config, state, next_state_warp); }; class BabeConfigRepositoryImpl final diff --git a/core/consensus/babe/impl/babe_digests_util.cpp b/core/consensus/babe/impl/babe_digests_util.cpp index 87ac6feb76..9eab15904d 100644 --- a/core/consensus/babe/impl/babe_digests_util.cpp +++ b/core/consensus/babe/impl/babe_digests_util.cpp @@ -6,6 +6,7 @@ #include "consensus/babe/impl/babe_digests_util.hpp" +#include "common/visitor.hpp" #include "scale/scale.hpp" OUTCOME_CPP_DEFINE_CATEGORY(kagome::consensus::babe, DigestError, e) { @@ -26,7 +27,7 @@ namespace { template std::optional>> getFromVariant( VarT &&v) { - return visit_in_place( + return kagome::visit_in_place( std::forward(v), [](const T &expected_val) -> std::optional>> { diff --git a/core/consensus/babe/impl/babe_lottery_impl.cpp b/core/consensus/babe/impl/babe_lottery_impl.cpp index c419527713..00f7d999d7 100644 --- a/core/consensus/babe/impl/babe_lottery_impl.cpp +++ b/core/consensus/babe/impl/babe_lottery_impl.cpp @@ -98,9 +98,10 @@ namespace kagome::consensus::babe { } // Index of secondary leader - auto auth_index_of_leader = be_bytes_to_uint256(hasher_->blake2b_256( - scale::encode(randomness_, slot).value())) - % auth_number_; + auto auth_index_of_leader = + be_bytes_to_uint256(hasher_->blake2b_256( + scale::encode(std::tie(randomness_, slot)).value())) + % auth_number_; if (keypair_->second != auth_index_of_leader) { // Author is not a secondary leader diff --git a/core/consensus/babe/types/authority.hpp b/core/consensus/babe/types/authority.hpp index 7911806008..c5eef05d1c 100644 --- a/core/consensus/babe/types/authority.hpp +++ b/core/consensus/babe/types/authority.hpp @@ -16,10 +16,9 @@ namespace kagome::consensus::babe { using AuthorityWeight = uint64_t; struct Authority { - SCALE_TIE(2); - AuthorityId id; AuthorityWeight weight{}; + bool operator==(const Authority &other) const = default; }; using Authorities = common::SLVector; diff --git a/core/consensus/babe/types/babe_configuration.hpp b/core/consensus/babe/types/babe_configuration.hpp index 9d9032d2ef..7c4aa5d2fe 100644 --- a/core/consensus/babe/types/babe_configuration.hpp +++ b/core/consensus/babe/types/babe_configuration.hpp @@ -32,8 +32,6 @@ namespace kagome::consensus::babe { /// Configuration data used by the BABE consensus engine. struct BabeConfiguration { - SCALE_TIE(6); - /// The slot duration in milliseconds for BABE. Currently, only /// the value provided by this type at genesis will be used. /// @@ -62,8 +60,6 @@ namespace kagome::consensus::babe { }; struct Epoch { - SCALE_TIE(7); - EpochNumber epoch_index; SlotNumber start_slot; EpochLength duration; diff --git a/core/consensus/babe/types/epoch_data.hpp b/core/consensus/babe/types/epoch_data.hpp index 9e5f91844b..e17ead6610 100644 --- a/core/consensus/babe/types/epoch_data.hpp +++ b/core/consensus/babe/types/epoch_data.hpp @@ -13,8 +13,6 @@ namespace kagome::consensus::babe { /// Data are corresponding to the epoch struct EpochData { - SCALE_TIE(2); - /// The authorities actual for corresponding epoch Authorities authorities; diff --git a/core/consensus/babe/types/equivocation_proof.hpp b/core/consensus/babe/types/equivocation_proof.hpp index e0608944cf..525232dbdf 100644 --- a/core/consensus/babe/types/equivocation_proof.hpp +++ b/core/consensus/babe/types/equivocation_proof.hpp @@ -8,7 +8,6 @@ #include "consensus/timeline/types.hpp" #include "primitives/block_header.hpp" -#include "scale/tie.hpp" namespace kagome::consensus::babe { @@ -26,8 +25,6 @@ namespace kagome::consensus::babe { /// are the given distinct headers that were signed by the validator and which /// include the slot number. struct EquivocationProof { - SCALE_TIE(4); - /// Returns the authority id of the equivocator. AuthorityId offender; /// The slot at which the equivocation happened. @@ -36,6 +33,7 @@ namespace kagome::consensus::babe { primitives::BlockHeader first_header; /// The second header involved in the equivocation. primitives::BlockHeader second_header; + bool operator==(const EquivocationProof &other) const = default; }; } // namespace kagome::consensus::babe diff --git a/core/consensus/babe/types/scheduled_change.hpp b/core/consensus/babe/types/scheduled_change.hpp index e66b7b0580..95b9772a73 100644 --- a/core/consensus/babe/types/scheduled_change.hpp +++ b/core/consensus/babe/types/scheduled_change.hpp @@ -7,21 +7,18 @@ #pragma once #include "common/unused.hpp" -#include "consensus/babe/types/authority.hpp" #include "consensus/babe/types/babe_configuration.hpp" -#include "scale/tie.hpp" namespace kagome::consensus::babe { struct NextConfigDataV1 final { - SCALE_TIE(2); std::pair ratio; AllowedSlots second_slot{}; + bool operator==(const NextConfigDataV1 &other) const = default; }; using NextConfigData = std::variant, NextConfigDataV1>; struct OnDisabled { - SCALE_TIE(1); AuthorityIndex authority_index = 0; }; diff --git a/core/consensus/babe/types/seal.hpp b/core/consensus/babe/types/seal.hpp index 77866b5d50..6b9629fe51 100644 --- a/core/consensus/babe/types/seal.hpp +++ b/core/consensus/babe/types/seal.hpp @@ -7,15 +7,12 @@ #pragma once #include "crypto/sr25519_types.hpp" -#include "scale/tie.hpp" namespace kagome::consensus::babe { /** * Basically a signature of the block's header */ struct Seal { - SCALE_TIE(1); - /// Sig_sr25519(Blake2s(block_header)) crypto::Sr25519Signature signature; }; diff --git a/core/consensus/beefy/types.hpp b/core/consensus/beefy/types.hpp index f04ea7bc37..0b74827df5 100644 --- a/core/consensus/beefy/types.hpp +++ b/core/consensus/beefy/types.hpp @@ -25,8 +25,6 @@ namespace kagome::consensus::beefy { using MmrRootHash = common::Hash256; struct ValidatorSet { - SCALE_TIE(2); - std::vector validators; AuthoritySetId id = 0; @@ -49,16 +47,13 @@ namespace kagome::consensus::beefy { constexpr PayloadId kMmr{{'m', 'h'}}; struct Commitment { - SCALE_TIE(3); - std::vector> payload; primitives::BlockNumber block_number; AuthoritySetId validator_set_id; + bool operator==(const Commitment &other) const = default; }; struct VoteMessage { - SCALE_TIE(3); - Commitment commitment; crypto::EcdsaPublicKey id; crypto::EcdsaSignature signature; @@ -128,8 +123,6 @@ namespace kagome::consensus::beefy { using BeefyGossipMessage = boost::variant; struct DoubleVotingProof { - SCALE_TIE(2); - VoteMessage first; VoteMessage second; }; diff --git a/core/consensus/grandpa/historical_votes.hpp b/core/consensus/grandpa/historical_votes.hpp index 1f535ae6b9..01bf7deba5 100644 --- a/core/consensus/grandpa/historical_votes.hpp +++ b/core/consensus/grandpa/historical_votes.hpp @@ -14,8 +14,6 @@ namespace kagome::consensus::grandpa { * https://github.com/paritytech/finality-grandpa/blob/8c45a664c05657f0c71057158d3ba555ba7d20de/src/lib.rs#L544 */ struct HistoricalVotes { - SCALE_TIE(3); - std::vector seen; std::optional prevote_idx, precommit_idx; }; diff --git a/core/consensus/grandpa/impl/authority_manager_impl.hpp b/core/consensus/grandpa/impl/authority_manager_impl.hpp index 3e6768dd64..ed4ffd31d5 100644 --- a/core/consensus/grandpa/impl/authority_manager_impl.hpp +++ b/core/consensus/grandpa/impl/authority_manager_impl.hpp @@ -32,8 +32,6 @@ namespace kagome::consensus::grandpa { // TODO(turuslan): #1857, grandpa voting during forced change struct GrandpaIndexedValue { - SCALE_TIE_ONLY(next_set_id, forced_target, state); - /** * Set id is missing from grandpa digests. */ @@ -48,6 +46,12 @@ namespace kagome::consensus::grandpa { * Next authorities lazily computed from `set_id` and digest. */ std::optional> next; + + private: + SCALE_CUSTOM_DECOMPOSING(GrandpaIndexedValue, + next_set_id, + forced_target, + state); }; class AuthorityManagerImpl final diff --git a/core/consensus/grandpa/impl/environment_impl.cpp b/core/consensus/grandpa/impl/environment_impl.cpp index f3a64f33fb..81bd35fce4 100644 --- a/core/consensus/grandpa/impl/environment_impl.cpp +++ b/core/consensus/grandpa/impl/environment_impl.cpp @@ -294,11 +294,11 @@ namespace kagome::consensus::grandpa { vote.id, vote.getBlockInfo()); - self->transmitter_->sendVoteMessage(network::GrandpaVote{{ + self->transmitter_->sendVoteMessage(network::GrandpaVote{ .round_number = round, .counter = set_id, .vote = vote, - }}); + }); } }); } @@ -327,9 +327,9 @@ namespace kagome::consensus::grandpa { ; self->transmitter_->sendVoteMessage( peer_id, - network::GrandpaVote{{.round_number = state.round_number, - .counter = voter_set_id, - .vote = vote}}); + network::GrandpaVote{.round_number = state.round_number, + .counter = voter_set_id, + .vote = vote}); }; for (const auto &vv : state.votes) { diff --git a/core/consensus/grandpa/impl/vote_crypto_provider_impl.cpp b/core/consensus/grandpa/impl/vote_crypto_provider_impl.cpp index b83c7abf7f..6ee6163947 100644 --- a/core/consensus/grandpa/impl/vote_crypto_provider_impl.cpp +++ b/core/consensus/grandpa/impl/vote_crypto_provider_impl.cpp @@ -26,7 +26,8 @@ namespace kagome::consensus::grandpa { if (not keypair_) { return std::nullopt; } - auto payload = scale::encode(vote, round_number_, voter_set_->id()).value(); + auto payload = + scale::encode(std::tie(vote, round_number_, voter_set_->id())).value(); auto signature = ed_provider_->sign(*keypair_, payload).value(); return {{.message = std::move(vote), .signature = signature, @@ -36,7 +37,7 @@ namespace kagome::consensus::grandpa { bool VoteCryptoProviderImpl::verify(const SignedMessage &vote, RoundNumber number) const { auto payload = - scale::encode(vote.message, number, voter_set_->id()).value(); + scale::encode(std::tie(vote.message, number, voter_set_->id())).value(); auto verifying_result = ed_provider_->verify(vote.signature, payload, vote.id); bool result = verifying_result.has_value() and verifying_result.value(); @@ -47,7 +48,7 @@ namespace kagome::consensus::grandpa { for (auto n = number > 100 ? number - 100 : 0; n < number + 100; n++) { for (auto id = voter_set_->id() - 100; id < voter_set_->id() + 100; id++) { - auto payload = scale::encode(vote.message, n, id).value(); + auto payload = scale::encode(std::tie(vote.message, n, id)).value(); auto verifying_result = ed_provider_->verify(vote.signature, payload, vote.id); if (verifying_result.has_value() and verifying_result.value()) { diff --git a/core/consensus/grandpa/movable_round_state.hpp b/core/consensus/grandpa/movable_round_state.hpp index bfbc9c941a..def92b27b0 100644 --- a/core/consensus/grandpa/movable_round_state.hpp +++ b/core/consensus/grandpa/movable_round_state.hpp @@ -9,14 +9,11 @@ #include #include "consensus/grandpa/structs.hpp" -#include "scale/tie.hpp" namespace kagome::consensus::grandpa { /// Stores the current state of the round struct MovableRoundState { - SCALE_TIE(4); - RoundNumber round_number; BlockInfo last_finalized_block; std::vector votes; diff --git a/core/consensus/grandpa/structs.hpp b/core/consensus/grandpa/structs.hpp index 6378439e4e..a27b46108d 100644 --- a/core/consensus/grandpa/structs.hpp +++ b/core/consensus/grandpa/structs.hpp @@ -49,28 +49,9 @@ namespace kagome::consensus::grandpa { return message.type() == typeid(T); } - bool operator==(const SignedMessage &rhs) const { - return message == rhs.message && signature == rhs.signature - && id == rhs.id; - } - - bool operator!=(const SignedMessage &rhs) const { - return !operator==(rhs); - } + bool operator==(const SignedMessage &other) const = default; }; - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const SignedMessage &signed_msg) { - return s << signed_msg.message << signed_msg.signature << signed_msg.id; - } - - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, SignedMessage &signed_msg) { - return s >> signed_msg.message >> signed_msg.signature >> signed_msg.id; - } - using EquivocatorySignedMessage = std::pair; using VoteVariant = boost::variant; @@ -117,8 +98,6 @@ namespace kagome::consensus::grandpa { // justification that contains a list of signed precommits justifying the // validity of the block struct GrandpaJustification { - SCALE_TIE(4); - RoundNumber round_number; primitives::BlockInfo block_info; std::vector items{}; @@ -127,8 +106,6 @@ namespace kagome::consensus::grandpa { // either prevote, precommit or primary propose struct VoteMessage { - SCALE_TIE(3); - RoundNumber round_number{0}; VoterSetId counter{0}; SignedMessage vote; @@ -136,6 +113,9 @@ namespace kagome::consensus::grandpa { Id id() const { return vote.id; } + + private: + SCALE_CUSTOM_DECOMPOSING(VoteMessage, round_number, counter, vote); }; struct TotalWeight { @@ -147,8 +127,6 @@ namespace kagome::consensus::grandpa { // @See // https://github.com/paritytech/finality-grandpa/blob/v0.14.2/src/lib.rs#L312 struct CompactCommit { - SCALE_TIE(4); - // The target block's hash. primitives::BlockHash target_hash; // The target block's number. diff --git a/core/consensus/grandpa/types/authority.hpp b/core/consensus/grandpa/types/authority.hpp index 756043659c..3b958df66c 100644 --- a/core/consensus/grandpa/types/authority.hpp +++ b/core/consensus/grandpa/types/authority.hpp @@ -16,10 +16,9 @@ namespace kagome::consensus::grandpa { using AuthorityWeight = uint64_t; struct Authority { - SCALE_TIE(2); - AuthorityId id; AuthorityWeight weight{}; + bool operator==(const Authority &other) const = default; }; using Authorities = @@ -31,15 +30,9 @@ namespace kagome::consensus::grandpa { * List of authorities with an identifier */ struct AuthoritySet { - SCALE_TIE(2); - - AuthoritySet() = default; - - AuthoritySet(AuthoritySetId id, Authorities authorities) - : id{id}, authorities{std::move(authorities)} {} - AuthoritySetId id{}; Authorities authorities; + bool operator==(const AuthoritySet &other) const = default; }; } // namespace kagome::consensus::grandpa diff --git a/core/consensus/grandpa/types/equivocation_proof.hpp b/core/consensus/grandpa/types/equivocation_proof.hpp index cc44d37777..65f3264278 100644 --- a/core/consensus/grandpa/types/equivocation_proof.hpp +++ b/core/consensus/grandpa/types/equivocation_proof.hpp @@ -12,7 +12,6 @@ #include "consensus/grandpa/types/authority.hpp" #include "consensus/grandpa/vote_types.hpp" #include "primitives/block_header.hpp" -#include "scale/tie.hpp" namespace kagome::consensus::grandpa { @@ -73,8 +72,6 @@ namespace kagome::consensus::grandpa { /// prevote or precommit stage) for different blocks. Proving is achieved /// by collecting the signed messages of conflicting votes. struct EquivocationProof { - SCALE_TIE(2); - AuthoritySetId set_id; Equivocation equivocation; }; diff --git a/core/consensus/grandpa/types/scheduled_change.hpp b/core/consensus/grandpa/types/scheduled_change.hpp index de77b98d58..d4bf7f338b 100644 --- a/core/consensus/grandpa/types/scheduled_change.hpp +++ b/core/consensus/grandpa/types/scheduled_change.hpp @@ -6,57 +6,32 @@ #pragma once -#include "common/unused.hpp" #include "consensus/grandpa/types/authority.hpp" #include "primitives/common.hpp" -#include "scale/tie.hpp" namespace kagome::consensus::grandpa { struct ScheduledChange { - SCALE_TIE(2); Authorities authorities{}; uint32_t subchain_length = 0; - - ScheduledChange() = default; - ScheduledChange(Authorities authorities, uint32_t delay) - : authorities(std::move(authorities)), subchain_length(delay) {} }; struct ForcedChange { - SCALE_TIE(3); primitives::BlockNumber delay_start = 0; Authorities authorities{}; uint32_t subchain_length = 0; - - ForcedChange() = default; - ForcedChange(Authorities authorities, - uint32_t delay, - primitives::BlockNumber delay_start) - : delay_start(delay_start), - authorities(std::move(authorities)), - subchain_length(delay) {} }; struct OnDisabled { - SCALE_TIE(1); AuthorityIndex authority_index = 0; }; struct Pause { - SCALE_TIE(1); uint32_t subchain_length = 0; - - Pause() = default; - explicit Pause(uint32_t delay) : subchain_length(delay) {} }; struct Resume { - SCALE_TIE(1); uint32_t subchain_length = 0; - - Resume() = default; - explicit Resume(uint32_t delay) : subchain_length(delay) {} }; } // namespace kagome::consensus::grandpa diff --git a/core/consensus/grandpa/voter_set.hpp b/core/consensus/grandpa/voter_set.hpp index 0b2e3a020e..dbb853bff0 100644 --- a/core/consensus/grandpa/voter_set.hpp +++ b/core/consensus/grandpa/voter_set.hpp @@ -40,7 +40,7 @@ namespace kagome::consensus::grandpa { /** * \return unique voter set membership id */ - inline VoterSetId id() const { + inline const VoterSetId &id() const { return id_; } diff --git a/core/consensus/timeline/types.hpp b/core/consensus/timeline/types.hpp index 616b1fadb7..c62bb5ab1f 100644 --- a/core/consensus/timeline/types.hpp +++ b/core/consensus/timeline/types.hpp @@ -10,7 +10,6 @@ #include "clock/clock.hpp" #include "crypto/sr25519_types.hpp" -#include "scale/tie.hpp" namespace kagome::consensus { diff --git a/core/crypto/bandersnatch/bandersnatch_provider_impl.cpp b/core/crypto/bandersnatch/bandersnatch_provider_impl.cpp index a4d491a9c2..a8537ffb64 100644 --- a/core/crypto/bandersnatch/bandersnatch_provider_impl.cpp +++ b/core/crypto/bandersnatch/bandersnatch_provider_impl.cpp @@ -44,9 +44,9 @@ namespace kagome::crypto { return BandersnatchProviderError::SOFT_JUNCTION_NOT_SUPPORTED; } auto hash = hasher_->blake2b_256( - scale::encode("bandersnatch-vrf-HDKD"_bytes, - seed_with_junctions.unsafeBytes(), - junction.cc) + scale::encode(std::tuple("bandersnatch-vrf-HDKD"_bytes, + seed_with_junctions.unsafeBytes(), + junction.cc)) .value()); seed_with_junctions = BandersnatchSeed::from(SecureCleanGuard(hash)); } diff --git a/core/crypto/bandersnatch/vrf.hpp b/core/crypto/bandersnatch/vrf.hpp index 12dffdc162..9d5e36ff8a 100644 --- a/core/crypto/bandersnatch/vrf.hpp +++ b/core/crypto/bandersnatch/vrf.hpp @@ -146,8 +146,6 @@ namespace kagome::crypto::bandersnatch::vrf { /// /// Includes both the transcript `signature` and the `outputs` generated from struct VrfSignature { - SCALE_TIE(2); - /// VRF (pre)outputs. VrfIosVec outputs; @@ -157,8 +155,6 @@ namespace kagome::crypto::bandersnatch::vrf { /// Ring VRF signature. struct RingVrfSignature { - SCALE_TIE(2); - /// VRF (pre)outputs. VrfIosVec outputs; diff --git a/core/crypto/bandersnatch_types.hpp b/core/crypto/bandersnatch_types.hpp index f0764df385..81cb8cc4d9 100644 --- a/core/crypto/bandersnatch_types.hpp +++ b/core/crypto/bandersnatch_types.hpp @@ -15,7 +15,6 @@ #include "common/int_serialization.hpp" #include "crypto/common.hpp" #include "primitives/math.hpp" -#include "scale/tie.hpp" namespace kagome::crypto::constants::bandersnatch { /// Important constants to deal with bandersnatch diff --git a/core/crypto/ecdsa/ecdsa_provider_impl.cpp b/core/crypto/ecdsa/ecdsa_provider_impl.cpp index f51dbfa9e2..8953439de4 100644 --- a/core/crypto/ecdsa/ecdsa_provider_impl.cpp +++ b/core/crypto/ecdsa/ecdsa_provider_impl.cpp @@ -41,9 +41,10 @@ namespace kagome::crypto { if (not junction.hard) { return Error::SOFT_JUNCTION_NOT_SUPPORTED; } - auto bytes = - scale::encode("Secp256k1HDKD"_bytes, seed.unsafeBytes(), junction.cc) - .value(); + auto bytes = scale::encode(std::tuple("Secp256k1HDKD"_bytes, + seed.unsafeBytes(), + junction.cc)) + .value(); SecureCleanGuard g{bytes}; auto _ = hasher_->blake2b_256(bytes); seed = EcdsaSeed::from( diff --git a/core/crypto/ed25519/ed25519_provider_impl.cpp b/core/crypto/ed25519/ed25519_provider_impl.cpp index 10de613092..cc029ab3aa 100644 --- a/core/crypto/ed25519/ed25519_provider_impl.cpp +++ b/core/crypto/ed25519/ed25519_provider_impl.cpp @@ -40,7 +40,8 @@ namespace kagome::crypto { return Error::SOFT_JUNCTION_NOT_SUPPORTED; } auto hash = hasher_->blake2b_256( - scale::encode("Ed25519HDKD"_bytes, seed.unsafeBytes(), junction.cc) + scale::encode( + std::tuple("Ed25519HDKD"_bytes, seed.unsafeBytes(), junction.cc)) .value()); seed = Ed25519Seed::from(SecureCleanGuard(hash)); } diff --git a/core/crypto/ed25519_types.hpp b/core/crypto/ed25519_types.hpp index bb4728f2dd..81dc960d80 100644 --- a/core/crypto/ed25519_types.hpp +++ b/core/crypto/ed25519_types.hpp @@ -12,7 +12,6 @@ extern "C" { #include "common/blob.hpp" #include "crypto/common.hpp" -#include "scale/tie.hpp" namespace kagome::crypto::constants::ed25519 { /** @@ -45,8 +44,6 @@ namespace kagome::crypto { template struct Ed25519Signed { using Type = std::decay_t; - SCALE_TIE(2); - Type payload; Ed25519Signature signature; }; diff --git a/core/crypto/sr25519_types.hpp b/core/crypto/sr25519_types.hpp index c65dc04b78..74c0dbac09 100644 --- a/core/crypto/sr25519_types.hpp +++ b/core/crypto/sr25519_types.hpp @@ -16,7 +16,6 @@ extern "C" { #include "common/int_serialization.hpp" #include "crypto/common.hpp" #include "primitives/math.hpp" -#include "scale/tie.hpp" namespace kagome::crypto { namespace constants::sr25519 { @@ -55,12 +54,11 @@ namespace kagome::crypto { * verification of its randomness. */ struct VRFOutput { - SCALE_TIE(2); - // an internal representation of the generated random value VRFPreOutput output{}; // the proof to the output, serves as the verification of its randomness VRFProof proof{}; + bool operator==(const VRFOutput &other) const = default; }; /** @@ -92,8 +90,6 @@ namespace kagome::crypto { template struct Sr25519Signed { using Type = std::decay_t; - SCALE_TIE(2); - Type payload; Sr25519Signature signature; }; diff --git a/core/dispute_coordinator/provisioner/impl/prioritized_selection.hpp b/core/dispute_coordinator/provisioner/impl/prioritized_selection.hpp index c27ec7e5fe..b5f2d93cea 100644 --- a/core/dispute_coordinator/provisioner/impl/prioritized_selection.hpp +++ b/core/dispute_coordinator/provisioner/impl/prioritized_selection.hpp @@ -22,8 +22,6 @@ namespace kagome::dispute { /// The entire state of a dispute. struct DisputeState { - SCALE_TIE(4); - /// A bitfield indicating all validators for the candidate. scale::BitVec validators_for; /// A bitfield indicating all validators against the candidate. diff --git a/core/dispute_coordinator/types.hpp b/core/dispute_coordinator/types.hpp index 45a4ec61ff..c0960ee5d0 100644 --- a/core/dispute_coordinator/types.hpp +++ b/core/dispute_coordinator/types.hpp @@ -32,8 +32,6 @@ namespace kagome::dispute { using CbOutcome = std::function)>; struct StoredWindow { - SCALE_TIE(2); - SessionIndex earliest_session; std::vector session_info; }; @@ -77,8 +75,6 @@ namespace kagome::dispute { /// Tracked votes on candidates, for the purposes of dispute resolution. struct CandidateVotes { - SCALE_TIE(3); - /// The receipt of the candidate itself. CandidateReceipt candidate_receipt; /// Votes of validity, sorted by validator index. @@ -233,8 +229,6 @@ namespace kagome::dispute { /// A set of statements about a specific candidate. struct DisputeStatementSet { - SCALE_TIE(3); - /// The candidate referenced by this set. CandidateHash candidate_hash; @@ -252,8 +246,6 @@ namespace kagome::dispute { /// Scraped runtime backing votes and resolved disputes. struct ScrapedOnChainVotes { - SCALE_TIE(3); - /// The session in which the block was included. SessionIndex session; diff --git a/core/network/types/block_announce_handshake.hpp b/core/network/types/block_announce_handshake.hpp index a7acbdc40c..fbc27a01ba 100644 --- a/core/network/types/block_announce_handshake.hpp +++ b/core/network/types/block_announce_handshake.hpp @@ -21,13 +21,18 @@ namespace kagome::network { * posibility of the correct communication with it. */ struct BlockAnnounceHandshake { - SCALE_TIE_ONLY(roles, best_block.number, best_block.hash, genesis_hash); - Roles roles; //!< Supported roles. primitives::BlockInfo best_block; //!< Best block. BlockHash genesis_hash; //!< Genesis block hash. + + private: + SCALE_CUSTOM_DECOMPOSING(BlockAnnounceHandshake, + roles, + best_block.number, + best_block.hash, + genesis_hash); }; } // namespace kagome::network diff --git a/core/network/types/block_attributes.hpp b/core/network/types/block_attributes.hpp index dc985bd8d7..f58fefbc07 100644 --- a/core/network/types/block_attributes.hpp +++ b/core/network/types/block_attributes.hpp @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include "common/outcome_throw.hpp" @@ -47,14 +47,8 @@ namespace kagome::network { return (l & r) == r; } - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const BlockAttribute &v) { - return s << static_cast(v); - } - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, BlockAttribute &attributes) { + inline scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + BlockAttribute &attributes) { uint8_t value = 0u; s >> value; attributes = toBlockAttribute(value); diff --git a/core/network/types/collator_messages.hpp b/core/network/types/collator_messages.hpp index 625a9cdf7e..b708e80b2b 100644 --- a/core/network/types/collator_messages.hpp +++ b/core/network/types/collator_messages.hpp @@ -23,7 +23,6 @@ #include "primitives/common.hpp" #include "primitives/compact_integer.hpp" #include "primitives/digest.hpp" -#include "scale/tie.hpp" #include "storage/trie/types.hpp" namespace kagome::runtime { @@ -44,8 +43,6 @@ namespace kagome::network { * Advertisement of a collation. */ struct CollatorAdvertisement { - SCALE_TIE(1); - primitives::BlockHash relay_parent; /// Hash of the parachain block. }; @@ -54,7 +51,6 @@ namespace kagome::network { * Declaration of the intent to advertise a collation. */ struct CollatorDeclaration { - SCALE_TIE(3); CollatorPublicKey collator_id; /// Public key of the collator. ParachainId para_id; /// Parachain Id. Signature signature; /// Signature of the collator using the PeerId of the @@ -63,8 +59,6 @@ namespace kagome::network { /// A chunk of erasure-encoded block data. struct ErasureChunk { - SCALE_TIE(3); - /// The erasure-encoded chunk of data belonging to the candidate block. common::Buffer chunk; /// The index of this erasure-encoded chunk of data. @@ -77,11 +71,10 @@ namespace kagome::network { * PoV */ struct ParachainBlock { - SCALE_TIE(1); - /// Contains the necessary data to for parachain specific state transition /// logic common::Buffer payload; + bool operator==(const ParachainBlock &other) const = default; }; using PoV = ParachainBlock; @@ -89,8 +82,6 @@ namespace kagome::network { using ResponsePov = boost::variant; struct CollationResponse { - SCALE_TIE(2); - /// Candidate receipt CandidateReceipt receipt; @@ -99,7 +90,6 @@ namespace kagome::network { }; struct CollationWithParentHeadData { - SCALE_TIE(3); /// The receipt of the candidate. CandidateReceipt receipt; @@ -119,8 +109,6 @@ namespace kagome::network { * specified relay chain block. */ struct CollationFetchingRequest { - SCALE_TIE(2); - Hash relay_parent; /// Hash of the relay chain block ParachainId para_id; /// Parachain Id. }; @@ -129,8 +117,6 @@ namespace kagome::network { * Sent by nodes to the clients who issued a collation fetching request. */ struct CollationFetchingResponse { - SCALE_TIE(1); - ReqCollationResponseData response_data; /// Response data }; @@ -138,8 +124,6 @@ namespace kagome::network { * Sent by clients who want to retrieve chunks of a parachain candidate. */ struct FetchChunkRequest { - SCALE_TIE(2); - CandidateHash candidate; /// parachain candidate hash ChunkIndex chunk_index; /// index of the chunk }; @@ -149,8 +133,6 @@ namespace kagome::network { * Version 1 (obsolete) */ struct ChunkObsolete { - SCALE_TIE(2); - /// chunk data common::Buffer data; /// chunk proof @@ -162,8 +144,6 @@ namespace kagome::network { * Sent by nodes to the clients who issued a chunk fetching request. Version 2 */ struct Chunk { - SCALE_TIE(3); - /// chunk data common::Buffer data; /// chunk index @@ -178,15 +158,12 @@ namespace kagome::network { boost::variant; struct FetchStatementRequest { - SCALE_TIE(2); RelayHash relay_parent; CandidateHash candidate_hash; }; using FetchStatementResponse = boost::variant; struct ValidityAttestation { - SCALE_TIE(2); - struct Implicit : Empty {}; struct Explicit : Empty {}; @@ -195,8 +172,6 @@ namespace kagome::network { }; struct BackedCandidate { - SCALE_TIE(3); - CommittedCandidateReceipt candidate; std::vector validity_votes; scale::BitVec validator_indices; @@ -244,9 +219,6 @@ namespace kagome::network { >; struct Statement { - SCALE_TIE(1); - Statement() = default; - Statement(CandidateState &&c) : candidate_state{std::move(c)} {} CandidateState candidate_state{Unused<0>{}}; }; using SignedStatement = IndexedAndSigned; @@ -256,8 +228,6 @@ namespace kagome::network { } struct Seconded { - SCALE_TIE(2); - primitives::BlockHash relay_parent; /// relay parent hash SignedStatement statement{}; /// statement of seconded candidate }; @@ -266,16 +236,12 @@ namespace kagome::network { using SignedBitfield = parachain::IndexedAndSigned; struct BitfieldDistribution { - SCALE_TIE(2); - primitives::BlockHash relay_parent; /// Hash of the relay chain block SignedBitfield data; }; /// Data that makes a statement unique. struct StatementMetadata { - SCALE_TIE(2); - /// Relay parent this statement is relevant under. primitives::BlockHash relay_parent; /// Hash of candidate that was used create the `CommitedCandidateRecept`. @@ -289,8 +255,6 @@ namespace kagome::network { /// The rust representation: /// https://github.com/paritytech/polkadot/blob/master/node/network/protocol/src/lib.rs#L160 struct View { - SCALE_TIE(2); - /// A bounded amount of chain heads. /// Invariant: Sorted. std::vector heads_; @@ -302,6 +266,7 @@ namespace kagome::network { const auto it = std::lower_bound(heads_.begin(), heads_.end(), hash); return it != heads_.end() && *it == hash; } + bool operator==(const View &other) const = default; }; using LargeStatement = parachain::IndexedAndSigned; @@ -329,23 +294,17 @@ namespace kagome::network { parachain::approval::IndirectSignedApprovalVote; struct Assignment { - SCALE_TIE(2); - kagome::parachain::approval::IndirectAssignmentCert indirect_assignment_cert; CandidateIndex candidate_ix; }; struct Assignments { - SCALE_TIE(1); - std::vector assignments; /// Assignments for candidates in /// recent, unfinalized blocks. }; struct Approvals { - SCALE_TIE(1); - std::vector approvals; /// Approvals for candidates in some recent, unfinalized /// block. @@ -370,8 +329,6 @@ namespace kagome::network { Tagged>; // 2 struct CommittedCandidate { - SCALE_TIE(3); - CommittedCandidateReceipt candidate_receipt; /// Committed candidate receipt std::vector @@ -381,22 +338,6 @@ namespace kagome::network { /// within the validator group }; - // using DisputeStatement = - // boost::variant, - // Tagged, - // Tagged, - // Tagged>; - // - // struct Vote { - // SCALE_TIE(3); - // - // uint32_t validator_index; /// An unsigned 32-bit integer indicating the - // /// validator index in the authority set - // Signature signature; /// The signature of the validator - // DisputeStatement - // statement; /// A varying datatype and implies the dispute statement - // }; - /** * Validator -> Validator. * Used by validators to broadcast relevant information about certain steps in @@ -431,18 +372,17 @@ namespace kagome::network { /// ViewUpdate message. Maybe will be implemented later. struct ViewUpdate { - SCALE_TIE(1) View view; }; /// Information about a core which is currently occupied. struct ScheduledCore { - SCALE_TIE(2) - /// The ID of a para scheduled. ParachainId para_id; /// The collator required to author the block, if any. std::optional collator; + + auto operator<=>(const ScheduledCore &) const = default; }; inline const CandidateHash &candidateHash(const CompactStatement &val) { diff --git a/core/network/types/collator_messages_vstaging.hpp b/core/network/types/collator_messages_vstaging.hpp index 424b5b28da..6b57b63716 100644 --- a/core/network/types/collator_messages_vstaging.hpp +++ b/core/network/types/collator_messages_vstaging.hpp @@ -6,12 +6,13 @@ #pragma once -#include -#include #include #include #include +#include +#include + #include "common/blob.hpp" #include "consensus/grandpa/common.hpp" #include "crypto/hasher.hpp" @@ -19,13 +20,7 @@ #include "network/types/collator_messages.hpp" #include "parachain/approval/approval.hpp" #include "parachain/types.hpp" -#include "primitives/block_header.hpp" -#include "primitives/common.hpp" -#include "primitives/compact_integer.hpp" -#include "primitives/digest.hpp" #include "runtime/runtime_api/parachain_host_types.hpp" -#include "scale/tie.hpp" -#include "storage/trie/types.hpp" namespace kagome::network::vstaging { using Dummy = network::Dummy; @@ -41,23 +36,17 @@ namespace kagome::network::vstaging { parachain::approval::IndirectSignedApprovalVoteV2; struct Assignment { - SCALE_TIE(2); - kagome::parachain::approval::IndirectAssignmentCertV2 indirect_assignment_cert; scale::BitVec candidate_bitfield; }; struct Assignments { - SCALE_TIE(1); - std::vector assignments; /// Assignments for candidates in /// recent, unfinalized blocks. }; struct Approvals { - SCALE_TIE(1); - std::vector approvals; /// Approvals for candidates in some recent, unfinalized /// block. @@ -73,7 +62,6 @@ namespace kagome::network::vstaging { Approvals>; struct CollatorProtocolMessageAdvertiseCollation { - SCALE_TIE(3); /// Hash of the relay parent advertised collation is based on. RelayHash relay_parent; /// Candidate hash. @@ -92,13 +80,13 @@ namespace kagome::network::vstaging { using CollationMessage0 = boost::variant; struct SecondedCandidateHash { - SCALE_TIE(1); CandidateHash hash; + bool operator==(const SecondedCandidateHash &other) const = default; }; struct ValidCandidateHash { - SCALE_TIE(1); CandidateHash hash; + bool operator==(const ValidCandidateHash &other) const = default; }; /// Statements that can be made about parachain candidates. These are the @@ -187,8 +175,6 @@ namespace kagome::network::vstaging { /// A notification of a signed statement in compact form, for a given /// relay parent. struct StatementDistributionMessageStatement { - SCALE_TIE(2); - RelayHash relay_parent; SignedCompactStatement compact; }; @@ -209,8 +195,6 @@ namespace kagome::network::vstaging { }; struct StatementFilter { - SCALE_TIE(2); - /// Seconded statements. '1' is known or undesired. scale::BitVec seconded_in_group; /// Valid statements. '1' is known or undesired. @@ -222,6 +206,14 @@ namespace kagome::network::vstaging { validated_in_group.bits.assign(len, val); } + bool operator==(const StatementFilter &other) const = default; + + private: + SCALE_CUSTOM_DECOMPOSING(StatementFilter, + seconded_in_group, + validated_in_group); + + public: void mask_seconded(const scale::BitVec &mask) { for (size_t i = 0; i < seconded_in_group.bits.size(); ++i) { const bool m = (i < mask.bits.size()) ? mask.bits[i] : false; @@ -294,7 +286,6 @@ namespace kagome::network::vstaging { /// A manifest of a known backed candidate, along with a description /// of the statements backing it. struct BackedCandidateManifest { - SCALE_TIE(6); /// The relay-parent of the candidate. RelayHash relay_parent; /// The hash of the candidate. @@ -318,13 +309,11 @@ namespace kagome::network::vstaging { }; struct AttestedCandidateRequest { - SCALE_TIE(2); CandidateHash candidate_hash; StatementFilter mask; }; struct AttestedCandidateResponse { - SCALE_TIE(3); CommittedCandidateReceipt candidate_receipt; runtime::PersistedValidationData persisted_validation_data; std::vector> statements; @@ -332,7 +321,6 @@ namespace kagome::network::vstaging { /// An acknowledgement of a backed candidate being known. struct BackedCandidateAcknowledgement { - SCALE_TIE(2); /// The hash of the candidate. CandidateHash candidate_hash; /// A statement filter which indicates which validators in the @@ -364,7 +352,6 @@ namespace kagome::network::vstaging { >; struct CollationFetchingRequest { - SCALE_TIE(3); /// Relay parent collation is built on top of. RelayHash relay_parent; /// The `ParaId` of the collation. @@ -404,11 +391,11 @@ namespace kagome::network { /// Candidate supplied with a para head it's built on top of. /// polkadot/node/network/collator-protocol/src/validator_side/collation.rs struct ProspectiveCandidate { - SCALE_TIE(2); /// Candidate hash. CandidateHash candidate_hash; /// Parent head-data hash as supplied in advertisement. Hash parent_head_data_hash; + bool operator==(const ProspectiveCandidate &other) const = default; }; struct PendingCollation { diff --git a/core/network/types/dispute_messages.hpp b/core/network/types/dispute_messages.hpp index b5962d03c7..05fd981e44 100644 --- a/core/network/types/dispute_messages.hpp +++ b/core/network/types/dispute_messages.hpp @@ -7,7 +7,6 @@ #pragma once #include "dispute_coordinator/types.hpp" -#include "scale/tie.hpp" namespace kagome::network { @@ -16,8 +15,6 @@ namespace kagome::network { /// Any invalid vote (currently only explicit). struct InvalidDisputeVote { - SCALE_TIE(3); - /// The voting validator index. ValidatorIndex index; @@ -31,8 +28,6 @@ namespace kagome::network { /// Any valid vote (backing, approval, explicit). struct ValidDisputeVote { - SCALE_TIE(3); - /// The voting validator index. ValidatorIndex index; @@ -54,8 +49,6 @@ namespace kagome::network { /// need to be versioned. // https://github.com/paritytech/polkadot/blob/40974fb99c86f5c341105b7db53c7aa0df707d66/node/primitives/src/disputes/message.rs#L40 struct DisputeMessage { - SCALE_TIE(4); - /// The candidate being disputed. CandidateReceipt candidate_receipt; diff --git a/core/network/types/grandpa_message.hpp b/core/network/types/grandpa_message.hpp index 973ea62abe..7373514a94 100644 --- a/core/network/types/grandpa_message.hpp +++ b/core/network/types/grandpa_message.hpp @@ -11,7 +11,6 @@ #include "consensus/grandpa/common.hpp" #include "consensus/grandpa/structs.hpp" #include "primitives/common.hpp" -#include "scale/tie.hpp" namespace kagome::network { @@ -27,17 +26,12 @@ namespace kagome::network { using primitives::BlockInfo; using primitives::BlockNumber; - struct GrandpaVote : public VoteMessage { - using VoteMessage::VoteMessage; - explicit GrandpaVote(VoteMessage &&vm) : VoteMessage(std::move(vm)){}; - }; + using GrandpaVote = VoteMessage; // Network level commit message with topic information. // @See // https://github.com/paritytech/substrate/blob/polkadot-v0.9.7/client/finality-grandpa/src/communication/gossip.rs#L350 struct FullCommitMessage { - SCALE_TIE(3); - // The round this message is from. RoundNumber round{0}; // The voter set ID this message is from. @@ -47,17 +41,14 @@ namespace kagome::network { }; struct GrandpaNeighborMessage { - SCALE_TIE(4); - uint8_t version = 1; RoundNumber round_number; VoterSetId voter_set_id; BlockNumber last_finalized; + bool operator==(const GrandpaNeighborMessage &other) const = default; }; struct CatchUpRequest { - SCALE_TIE(2); - RoundNumber round_number; VoterSetId voter_set_id; @@ -72,8 +63,6 @@ namespace kagome::network { }; struct CatchUpResponse { - SCALE_TIE(5); - VoterSetId voter_set_id{}; RoundNumber round_number{}; std::vector prevote_justification; diff --git a/core/network/types/propagate_transactions.hpp b/core/network/types/propagate_transactions.hpp index 468339f274..a869f315e4 100644 --- a/core/network/types/propagate_transactions.hpp +++ b/core/network/types/propagate_transactions.hpp @@ -7,15 +7,12 @@ #pragma once #include "primitives/transaction.hpp" -#include "scale/tie.hpp" namespace kagome::network { /** * Propagate transactions in network */ struct PropagatedExtrinsics { - SCALE_TIE(1); - std::vector extrinsics; }; } // namespace kagome::network diff --git a/core/network/types/roles.hpp b/core/network/types/roles.hpp index f58799324b..04bd6240d4 100644 --- a/core/network/types/roles.hpp +++ b/core/network/types/roles.hpp @@ -6,14 +6,10 @@ #pragma once -#include "scale/tie.hpp" - // NOLINTBEGIN(cppcoreguidelines-pro-type-union-access) namespace kagome::network { struct Roles { - SCALE_TIE_ONLY(value); - union { struct { /** @@ -38,6 +34,10 @@ namespace kagome::network { Roles() : value(0) {} Roles(uint8_t v) : value(v) {} + private: + SCALE_CUSTOM_DECOMPOSING(Roles, value); + + public: // https://github.com/paritytech/polkadot-sdk/blob/6c3219ebe9231a0305f53c7b33cb558d46058062/substrate/client/network/common/src/role.rs#L101 bool isFull() const { return flags.full != 0 or isAuthority(); diff --git a/core/network/types/state_request.hpp b/core/network/types/state_request.hpp index 09088f9b2d..9a8035d6c8 100644 --- a/core/network/types/state_request.hpp +++ b/core/network/types/state_request.hpp @@ -8,15 +8,12 @@ #include "common/buffer.hpp" #include "primitives/common.hpp" -#include "scale/tie.hpp" namespace kagome::network { /** * Request for state to another peer */ struct StateRequest { - SCALE_TIE(3); - /// Block header hash. primitives::BlockHash hash; diff --git a/core/network/warp/sync.hpp b/core/network/warp/sync.hpp index bd15d94ca3..6565154cda 100644 --- a/core/network/warp/sync.hpp +++ b/core/network/warp/sync.hpp @@ -49,8 +49,6 @@ namespace kagome::network { class WarpSync : public std::enable_shared_from_this { public: struct Op { - SCALE_TIE(4); - primitives::BlockInfo block_info; primitives::BlockHeader header; consensus::grandpa::GrandpaJustification justification; diff --git a/core/network/warp/types.hpp b/core/network/warp/types.hpp index e71fe7be98..6c35d784f9 100644 --- a/core/network/warp/types.hpp +++ b/core/network/warp/types.hpp @@ -10,15 +10,11 @@ namespace kagome::network { struct WarpSyncFragment { - SCALE_TIE(2); - primitives::BlockHeader header; consensus::grandpa::GrandpaJustification justification; }; struct WarpSyncProof { - SCALE_TIE(2); - std::vector proofs; bool is_finished = false; }; diff --git a/core/offchain/impl/http_request.cpp b/core/offchain/impl/http_request.cpp index e08d2b6e5f..951cdb9182 100644 --- a/core/offchain/impl/http_request.cpp +++ b/core/offchain/impl/http_request.cpp @@ -154,10 +154,9 @@ namespace kagome::offchain { resolver_iterator_->endpoint().address().to_string(), resolver_iterator_->endpoint().port()); - auto &stream = secure_ ? boost::beast::get_lowest_layer( - *boost::relaxed_get(stream_)) - : boost::beast::get_lowest_layer( - *boost::relaxed_get(stream_)); + auto &stream = + secure_ ? get_lowest_layer(*boost::relaxed_get(stream_)) + : get_lowest_layer(*boost::relaxed_get(stream_)); auto connect_handler = [wp{weak_from_this()}](const auto &ec, const auto &it) { diff --git a/core/offchain/types.hpp b/core/offchain/types.hpp index e67a6dc4a5..48e46874c0 100644 --- a/core/offchain/types.hpp +++ b/core/offchain/types.hpp @@ -58,7 +58,6 @@ namespace kagome::offchain { return true; } }; - SCALE_EMPTY_CODER(NoPayload); struct Success : public NoPayload {}; struct Failure : public NoPayload {}; diff --git a/core/parachain/approval/approval.hpp b/core/parachain/approval/approval.hpp index 80fe4081c8..6acba20954 100644 --- a/core/parachain/approval/approval.hpp +++ b/core/parachain/approval/approval.hpp @@ -23,8 +23,8 @@ namespace kagome::parachain::approval { /// /// The context used to produce bytes is [`RELAY_VRF_MODULO_CONTEXT`] struct RelayVRFModulo { - SCALE_TIE(1); uint32_t sample; /// The sample number used in this cert. + bool operator==(const RelayVRFModulo &other) const = default; }; /// An assignment story based on the VRF that authorized the relay-chain block @@ -33,24 +33,23 @@ namespace kagome::parachain::approval { /// /// The context is [`RELAY_VRF_DELAY_CONTEXT`] struct RelayVRFDelay { - SCALE_TIE(1); CoreIndex core_index; /// The core index chosen in this cert. + bool operator==(const RelayVRFDelay &other) const = default; }; /// random bytes derived from the VRF submitted within the block by the /// block author as a credential and used as input to approval assignment /// criteria. struct RelayVRFStory { - SCALE_TIE(1); ConstBuffer data; }; /// Multiple assignment stories based on the VRF that authorized the /// relay-chain block where the candidates were included. struct RelayVRFModuloCompact { - SCALE_TIE(1); /// A bitfield representing the core indices claimed by this assignment. scale::BitVec core_bitfield; + bool operator==(const RelayVRFModuloCompact &other) const = default; }; /// Different kinds of input data or criteria that can prove a validator's @@ -59,8 +58,6 @@ namespace kagome::parachain::approval { /// A certification of assignment. struct AssignmentCert { - SCALE_TIE(2); - AssignmentCertKind kind; /// The criterion which is claimed to be met by this cert. crypto::VRFOutput vrf; /// The VRF showing the criterion is met. @@ -73,8 +70,6 @@ namespace kagome::parachain::approval { /// A certification of assignment. struct AssignmentCertV2 { - SCALE_TIE(2); - /// The criterion which is claimed to be met by this cert. AssignmentCertKindV2 kind; @@ -89,13 +84,16 @@ namespace kagome::parachain::approval { .vrf = src.vrf, }; } + + bool operator==(const AssignmentCertV2 &other) const = default; + + private: + SCALE_CUSTOM_DECOMPOSING(AssignmentCertV2, kind, vrf) }; /// An assignment criterion which refers to the candidate under which the /// assignment is relevant by block hash. struct IndirectAssignmentCert { - SCALE_TIE(3); - Hash block_hash; /// A block hash where the candidate appears. ValidatorIndex validator; /// The validator index. AssignmentCert cert; /// The cert itself. @@ -104,8 +102,6 @@ namespace kagome::parachain::approval { /// An assignment criterion which refers to the candidate under which the /// assignment is relevant by block hash. struct IndirectAssignmentCertV2 { - SCALE_TIE(3); - /// A block hash where the candidate appears. Hash block_hash; @@ -130,8 +126,6 @@ namespace kagome::parachain::approval { /// In practice, we have a look-up from block hash and candidate index to /// candidate hash, so this can be transformed into a `SignedApprovalVote`. struct IndirectApprovalVote { - SCALE_TIE(2); - Hash block_hash; /// A block hash where the candidate appears. CandidateIndex candidate_index; /// The index of the candidate in the list of @@ -145,8 +139,6 @@ namespace kagome::parachain::approval { /// In practice, we have a look-up from block hash and candidate index to /// candidate hash, so this can be transformed into a `SignedApprovalVote`. struct IndirectApprovalVoteV2 { - SCALE_TIE(2); - /// A block hash where the candidate appears. Hash block_hash; diff --git a/core/parachain/approval/approval_distribution.hpp b/core/parachain/approval/approval_distribution.hpp index 4ac4185db9..ce667e1d28 100644 --- a/core/parachain/approval/approval_distribution.hpp +++ b/core/parachain/approval/approval_distribution.hpp @@ -83,11 +83,11 @@ namespace kagome::parachain { public IApprovedAncestor { public: struct OurAssignment { - SCALE_TIE(4); approval::AssignmentCertV2 cert; uint32_t tranche; ValidatorIndex validator_index; bool triggered; /// Whether the assignment has been triggered already. + bool operator==(const OurAssignment &) const = default; }; using HashedCandidateReceipt = crypto:: @@ -96,12 +96,11 @@ namespace kagome::parachain { /// Metadata regarding a specific tranche of assignments for a specific /// candidate. struct TrancheEntry { - SCALE_TIE(2); - network::DelayTranche tranche; // Assigned validators, and the instant we received their assignment, // rounded to the nearest tick. std::vector> assignments; + bool operator==(const TrancheEntry &other) const = default; }; using DistribApprovalEntryKey = std::pair; @@ -117,7 +116,6 @@ namespace kagome::parachain { }; struct ApprovalEntry { - SCALE_TIE(6); using MaybeCert = std::optional< std::tuple, ValidatorIndex, @@ -142,6 +140,8 @@ namespace kagome::parachain { assignments.bits.end(), assignments_size, false); } + bool operator==(const ApprovalEntry &) const = default; + /// Whether a validator is already assigned. bool is_assigned(ValidatorIndex validator_index) const { if (validator_index < assignments.bits.size()) { diff --git a/core/parachain/availability/chunks.hpp b/core/parachain/availability/chunks.hpp index bb689428b7..9951f27302 100644 --- a/core/parachain/availability/chunks.hpp +++ b/core/parachain/availability/chunks.hpp @@ -11,6 +11,8 @@ #include "parachain/availability/erasure_coding_error.hpp" #include "runtime/runtime_api/parachain_host_types.hpp" +#define OUTCOME_UNIQUE QTILS_UNIQUE_NAME(outcome) + #define _EC_CPP_TRY_VOID(tmp, expr) \ auto &&tmp = expr; \ if (ec_cpp::resultHasError(tmp)) { \ diff --git a/core/parachain/backing/cluster.hpp b/core/parachain/backing/cluster.hpp index a8399c5a36..188af6e832 100644 --- a/core/parachain/backing/cluster.hpp +++ b/core/parachain/backing/cluster.hpp @@ -70,37 +70,32 @@ namespace kagome::parachain { struct GeneralKnowledge { - SCALE_TIE(1); - CandidateHash hash; + bool operator==(const GeneralKnowledge &other) const = default; }; // Specific knowledge of a given statement (with its originator) struct SpecificKnowledge { - SCALE_TIE(2); - network::CompactStatement statement; ValidatorIndex index; + bool operator==(const SpecificKnowledge &other) const = default; }; // A piece of knowledge about a candidate using Knowledge = std::variant; struct IncomingP2P { - SCALE_TIE(1); - Knowledge knowledge; + bool operator==(const IncomingP2P &other) const = default; }; struct OutgoingP2P { - SCALE_TIE(1); - Knowledge knowledge; + bool operator==(const OutgoingP2P &other) const = default; }; struct Seconded { - SCALE_TIE(1); - CandidateHash hash; + bool operator==(const Seconded &other) const = default; }; using TaggedKnowledge = std::variant; diff --git a/core/parachain/parachain_inherent_data.hpp b/core/parachain/parachain_inherent_data.hpp index 2f9a856bc5..3d019e698d 100644 --- a/core/parachain/parachain_inherent_data.hpp +++ b/core/parachain/parachain_inherent_data.hpp @@ -13,8 +13,6 @@ namespace kagome::parachain { struct ParachainInherentData { - SCALE_TIE(4); - /// The array of signed bitfields by validators claiming the candidate is /// available (or not). /// @note The array must be sorted by validator index corresponding to the diff --git a/core/parachain/peer_relay_parent_knowledge.hpp b/core/parachain/peer_relay_parent_knowledge.hpp index 4487784e9e..f64ca9bb9a 100644 --- a/core/parachain/peer_relay_parent_knowledge.hpp +++ b/core/parachain/peer_relay_parent_knowledge.hpp @@ -18,7 +18,6 @@ namespace kagome::parachain { struct PeerRelayParentKnowledge { using CandidateHash = network::CandidateHash; struct PeerStatement { - SCALE_TIE(2); network::CompactStatement compact_statement; network::ValidatorIndex validator_index; }; diff --git a/core/parachain/pvf/pvf_impl.cpp b/core/parachain/pvf/pvf_impl.cpp index af74011c52..2bc6a5b88f 100644 --- a/core/parachain/pvf/pvf_impl.cpp +++ b/core/parachain/pvf/pvf_impl.cpp @@ -33,6 +33,8 @@ #include "runtime/runtime_instances_pool.hpp" #include "runtime/wasm_compiler_definitions.hpp" // this header-file is generated +#define OUTCOME_UNIQUE QTILS_UNIQUE_NAME(outcome) + #define _CB_TRY_VOID(tmp, expr) \ auto tmp = (expr); \ if (tmp.has_error()) { \ @@ -134,8 +136,6 @@ namespace kagome::parachain { } struct ValidationParams { - SCALE_TIE(4); - HeadData parent_head; ParachainBlock block_data; BlockNumber relay_parent_number{}; diff --git a/core/parachain/pvf/pvf_impl.hpp b/core/parachain/pvf/pvf_impl.hpp index 24af532134..bca2bc6deb 100644 --- a/core/parachain/pvf/pvf_impl.hpp +++ b/core/parachain/pvf/pvf_impl.hpp @@ -44,8 +44,6 @@ namespace kagome::parachain { struct ValidationParams; struct ValidationResult { - SCALE_TIE(6); - HeadData head_data; std::optional new_validation_code; std::vector upward_messages; diff --git a/core/parachain/pvf/pvf_worker_types.hpp b/core/parachain/pvf/pvf_worker_types.hpp index 21705e1964..fd9f40dae0 100644 --- a/core/parachain/pvf/pvf_worker_types.hpp +++ b/core/parachain/pvf/pvf_worker_types.hpp @@ -12,7 +12,6 @@ #include "parachain/pvf/secure_mode_precheck.hpp" #include "runtime/runtime_context.hpp" #include "scale/scale.hpp" -#include "scale/tie.hpp" namespace kagome::application { class AppConfiguration; @@ -31,8 +30,6 @@ namespace kagome::parachain { const application::AppConfiguration &app_config); struct PvfWorkerInputConfig { - SCALE_TIE(5); - RuntimeEngine engine; std::string cache_dir; std::vector log_params; @@ -41,9 +38,9 @@ namespace kagome::parachain { }; struct PvfWorkerInputCodeParams { - SCALE_TIE(2); std::string path; kagome::runtime::RuntimeContext::ContextParams context_params; + bool operator==(const PvfWorkerInputCodeParams &other) const = default; }; using PvfWorkerInputArgs = Buffer; diff --git a/core/parachain/pvf/runtime_params.hpp b/core/parachain/pvf/runtime_params.hpp index 4fa48ca86e..fd093625ca 100644 --- a/core/parachain/pvf/runtime_params.hpp +++ b/core/parachain/pvf/runtime_params.hpp @@ -7,7 +7,6 @@ namespace kagome::parachain { static constexpr uint64_t DEFAULT_APPROVAL_EXECUTION_TIMEOUT = 12000; struct RuntimeParams { - SCALE_TIE(3); kagome::runtime::RuntimeContext::ContextParams context_params; uint64_t pvf_exec_timeout_approval_ms = DEFAULT_APPROVAL_EXECUTION_TIMEOUT; uint64_t pvf_exec_timeout_backing_ms = DEFAULT_BACKING_EXECUTION_TIMEOUT; diff --git a/core/parachain/pvf/secure_mode_precheck.hpp b/core/parachain/pvf/secure_mode_precheck.hpp index 6802d462e8..099bca30cd 100644 --- a/core/parachain/pvf/secure_mode_precheck.hpp +++ b/core/parachain/pvf/secure_mode_precheck.hpp @@ -10,7 +10,6 @@ #include "parachain/pvf/secure_mode.hpp" #include "qtils/outcome.hpp" -#include "scale/tie.hpp" namespace kagome::parachain { @@ -19,8 +18,6 @@ namespace kagome::parachain { * platform */ struct SecureModeSupport { - SCALE_TIE(4); - // The filesystem root of the PVF process can be set to the worker directory bool chroot; diff --git a/core/parachain/types.hpp b/core/parachain/types.hpp index 5d2c26ee4d..479b42dce3 100644 --- a/core/parachain/types.hpp +++ b/core/parachain/types.hpp @@ -13,6 +13,7 @@ #include #include "common/blob.hpp" +#include "common/custom_equality.hpp" #include "common/visitor.hpp" #include "consensus/grandpa/common.hpp" #include "crypto/sr25519_types.hpp" @@ -20,7 +21,6 @@ #include "primitives/common.hpp" #include "primitives/compact_integer.hpp" #include "primitives/digest.hpp" -#include "scale/tie.hpp" #include "storage/trie/types.hpp" namespace kagome::parachain { @@ -61,8 +61,6 @@ namespace kagome::parachain { template struct Indexed { using Type = std::decay_t; - SCALE_TIE(2) - Type payload; ValidatorIndex ix; }; @@ -84,8 +82,6 @@ namespace kagome::parachain { } struct PvfCheckStatement { - SCALE_TIE(4); - bool accept; ValidationCodeHash subject; SessionIndex session_index; @@ -101,37 +97,33 @@ namespace kagome::parachain { namespace kagome::network { struct OutboundHorizontal { - SCALE_TIE(2); - /// The para that will get this message in its downward message queue. parachain::ParachainId recipient; - /// The message payload. common::Buffer data; + bool operator==(const OutboundHorizontal &other) const = default; }; struct InboundDownwardMessage { - SCALE_TIE(2); /// The block number at which these messages were put into the downward /// message queue. parachain::BlockNumber sent_at; /// The actual downward message to processes. parachain::DownwardMessage msg; + bool operator==(const InboundDownwardMessage &other) const = default; }; struct InboundHrmpMessage { - SCALE_TIE(2); /// The block number at which this message was sent. /// Specifically, it is the block number at which the candidate that sends /// this message was enacted. parachain::BlockNumber sent_at; /// The message payload. common::Buffer data; + bool operator==(const InboundHrmpMessage &other) const = default; }; struct CandidateCommitments { - SCALE_TIE(6); - std::vector upward_msgs; /// upward messages std::vector outbound_hor_msgs; /// outbound horizontal messages @@ -144,14 +136,13 @@ namespace kagome::network { watermark; /// watermark which specifies the relay chain block /// number up to which all inbound horizontal messages /// have been processed + bool operator==(const CandidateCommitments &other) const = default; }; /** * Unique descriptor of a candidate receipt. */ struct CandidateDescriptor { - SCALE_TIE(9); - parachain::ParachainId para_id; /// Parachain Id primitives::BlockHash relay_parent; /// Hash of the relay chain block the candidate is @@ -169,13 +160,15 @@ namespace kagome::network { primitives::BlockHash validation_code_hash; /// Hash of the parachain Runtime. + bool operator==(const CandidateDescriptor &) const = default; + common::Buffer signable() const { return common::Buffer{ - scale::encode(relay_parent, - para_id, - persisted_data_hash, - pov_hash, - validation_code_hash) + scale::encode(std::tie(relay_parent, + para_id, + persisted_data_hash, + pov_hash, + validation_code_hash)) .value(), }; } @@ -198,12 +191,10 @@ namespace kagome::network { return hash_.value(); } - SCALE_TIE_ONLY(descriptor, commitments_hash); + CUSTOM_EQUALITY(CandidateReceipt, descriptor, commitments_hash); }; struct CommittedCandidateReceipt { - SCALE_TIE(2); - CandidateDescriptor descriptor; /// Candidate descriptor CandidateCommitments commitments; /// commitments retrieved from validation /// result and produced by the execution @@ -216,6 +207,8 @@ namespace kagome::network { hasher.blake2b_256(scale::encode(commitments).value()); return receipt; } + + bool operator==(const CommittedCandidateReceipt &r) const = default; }; } // namespace kagome::network @@ -229,7 +222,6 @@ namespace kagome::parachain::fragment { }; struct CandidatePendingAvailability { - SCALE_TIE(5); /// The hash of the candidate. CandidateHash candidate_hash; /// The candidate's descriptor. @@ -244,14 +236,12 @@ namespace kagome::parachain::fragment { /// Constraints on inbound HRMP channels. struct InboundHrmpLimitations { - SCALE_TIE(1); /// An exhaustive set of all valid watermarks, sorted ascending std::vector valid_watermarks; }; /// Constraints on outbound HRMP channels. struct OutboundHrmpChannelLimitations { - SCALE_TIE(2); /// The maximum bytes that can be written to the channel. uint32_t bytes_remaining; /// The maximum messages that can be written to the channel. @@ -259,11 +249,9 @@ namespace kagome::parachain::fragment { }; struct HrmpWatermarkUpdateHead { - SCALE_TIE(1); BlockNumber v; }; struct HrmpWatermarkUpdateTrunk { - SCALE_TIE(1); BlockNumber v; }; using HrmpWatermarkUpdate = @@ -273,7 +261,6 @@ namespace kagome::parachain::fragment { } struct OutboundHrmpChannelModification { - SCALE_TIE(2); /// The number of bytes submitted to the channel. uint32_t bytes_submitted; /// The number of messages submitted to the channel. @@ -319,7 +306,6 @@ namespace kagome::parachain::fragment { }; struct Constraints { - SCALE_TIE(14); enum class Error { DISALLOWED_HRMP_WATERMARK, NO_SUCH_HRMP_CHANNEL, @@ -371,7 +357,6 @@ namespace kagome::parachain::fragment { }; struct BackingState { - SCALE_TIE(2); /// The state-machine constraints of the parachain. Constraints constraints; /// The candidates pending availability. These should be ordered, i.e. they @@ -382,7 +367,6 @@ namespace kagome::parachain::fragment { }; struct AsyncBackingParams { - SCALE_TIE(2); /// The maximum number of para blocks between the para head in a relay /// parent and a new candidate. Restricts nodes from building arbitrary long /// chains and spamming other validators. diff --git a/core/parachain/ump_signal.hpp b/core/parachain/ump_signal.hpp index a5a0cfda7d..5a41509379 100644 --- a/core/parachain/ump_signal.hpp +++ b/core/parachain/ump_signal.hpp @@ -35,8 +35,6 @@ namespace kagome::parachain { /// `CoreSelector` and `ClaimQueueOffset` to compute the index of the core the /// candidate has committed to. struct UMPSignalSelectCore { - SCALE_TIE(2); - uint8_t core_selector; uint8_t claim_queue_offset; }; diff --git a/core/parachain/validator/parachain_processor.hpp b/core/parachain/validator/parachain_processor.hpp index bfd73150e2..69a4bcdd0b 100644 --- a/core/parachain/validator/parachain_processor.hpp +++ b/core/parachain/validator/parachain_processor.hpp @@ -821,8 +821,10 @@ namespace kagome::parachain { metrics::RegistryPtr metrics_registry_ = metrics::createRegistry(); metrics::Gauge *metric_is_parachain_validator_; - metrics::Counter *metric_kagome_parachain_candidate_backing_signed_statements_total_; - metrics::Counter *metric_kagome_parachain_candidate_backing_candidates_seconded_total_; + metrics::Counter + *metric_kagome_parachain_candidate_backing_signed_statements_total_; + metrics::Counter + *metric_kagome_parachain_candidate_backing_candidates_seconded_total_; }; } // namespace kagome::parachain diff --git a/core/parachain/validator/signer.hpp b/core/parachain/validator/signer.hpp index d264173e90..e20444ab08 100644 --- a/core/parachain/validator/signer.hpp +++ b/core/parachain/validator/signer.hpp @@ -37,8 +37,6 @@ namespace kagome::parachain { } public: - SCALE_TIE(2); - /// Make signing context for given block. static outcome::result make( const std::shared_ptr ¶chain_api, diff --git a/core/primitives/apply_result.hpp b/core/primitives/apply_result.hpp index f8be859f0d..21f3b1d965 100644 --- a/core/primitives/apply_result.hpp +++ b/core/primitives/apply_result.hpp @@ -11,8 +11,6 @@ #include "primitives/arithmetic_error.hpp" #include "primitives/token_error.hpp" #include "primitives/transaction_validity.hpp" -#include "scale/scale.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { @@ -22,25 +20,19 @@ namespace kagome::primitives { // https://w3f-research.readthedocs.io/en/latest/_static/pdfview/viewer.html?file=https://w3f.github.io/polkadot-spec/spec/host/nightly.pdf#label329 class DispatchSuccess {}; - SCALE_EMPTY_CODER(DispatchSuccess); namespace dispatch_error { /// Some unclassified error occurred. struct Other { - SCALE_TIE(1) std::string value; }; /// Failed to lookup some data. struct CannotLookup {}; - SCALE_EMPTY_CODER(CannotLookup); /// A bad origin. struct BadOrigin {}; - SCALE_EMPTY_CODER(BadOrigin); /// A custom error in a module. struct Module { - SCALE_TIE_ONLY(index, error); - /// Module index, matching the metadata module index. uint8_t index; /// Module specific error value. @@ -48,25 +40,20 @@ namespace kagome::primitives { /// Optional error message. std::optional message; // not currently used in rust impl, thus not scale encoded + SCALE_CUSTOM_DECOMPOSING(Module, index, error); }; /// At least one consumer is remaining so the account cannot be destroyed. struct ConsumerRemaining {}; - SCALE_EMPTY_CODER(ConsumerRemaining); /// There are no providers so the account cannot be created. struct NoProviders {}; - SCALE_EMPTY_CODER(NoProviders); /// An error to do with tokens. struct Token { - SCALE_TIE(1); - TokenError error; }; /// An arithmetic error. struct Arithmetic { - SCALE_TIE(1); - ArithmeticError error; }; } // namespace dispatch_error diff --git a/core/primitives/arithmetic_error.hpp b/core/primitives/arithmetic_error.hpp index f90e8cd996..2061a536ce 100644 --- a/core/primitives/arithmetic_error.hpp +++ b/core/primitives/arithmetic_error.hpp @@ -8,6 +8,8 @@ #include +#include + #include "outcome/outcome.hpp" namespace kagome::primitives { @@ -21,17 +23,15 @@ namespace kagome::primitives { DivisionByZero, }; - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const ArithmeticError &v) { + inline scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const ArithmeticError &v) { // index shift is required for compatibility with rust implementation. // std::error_code policy preserves 0 index for success cases. - return s << static_cast(v) - 1; + return s << (static_cast(v) - 1); } - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, ArithmeticError &v) { + inline scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + ArithmeticError &v) { uint8_t value = 0u; s >> value; // index shift is required for compatibility with rust implementation. diff --git a/core/primitives/block.hpp b/core/primitives/block.hpp index 8097a81d13..dfd247f01b 100644 --- a/core/primitives/block.hpp +++ b/core/primitives/block.hpp @@ -8,7 +8,6 @@ #include "primitives/block_header.hpp" #include "primitives/extrinsic.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { using BlockBody = std::vector; @@ -17,15 +16,12 @@ namespace kagome::primitives { * @brief Block class represents polkadot block primitive */ struct Block { - SCALE_TIE(2); - BlockHeader header; ///< block header BlockBody body{}; ///< extrinsics collection + bool operator==(const Block &other) const = default; }; struct BlockReflection { - SCALE_TIE(2); - BlockHeaderReflection header; ///< block header // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const BlockBody &body; ///< extrinsics collection diff --git a/core/primitives/block_data.hpp b/core/primitives/block_data.hpp index 539f0ca2a5..04b32026c3 100644 --- a/core/primitives/block_data.hpp +++ b/core/primitives/block_data.hpp @@ -10,7 +10,6 @@ #include "primitives/block.hpp" #include "primitives/justification.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { @@ -19,8 +18,6 @@ namespace kagome::primitives { * to get certain information about the block */ struct BlockData { - SCALE_TIE(7); - primitives::BlockHash hash; std::optional header{}; std::optional body{}; @@ -28,6 +25,7 @@ namespace kagome::primitives { std::optional message_queue{}; std::optional justification{}; std::optional beefy_justification{}; + bool operator==(const BlockData &other) const = default; }; struct BlockDataFlags { diff --git a/core/primitives/block_header.hpp b/core/primitives/block_header.hpp index 35c06d968a..3e5a9939e3 100644 --- a/core/primitives/block_header.hpp +++ b/core/primitives/block_header.hpp @@ -18,6 +18,8 @@ #include "primitives/digest.hpp" #include "storage/trie/types.hpp" +#include + namespace kagome::primitives { /** * @struct BlockHeader represents header of a block @@ -30,18 +32,12 @@ namespace kagome::primitives { Digest digest{}; ///< Chain-specific auxiliary data mutable std::optional hash_opt{}; ///< Block hash if calculated - bool operator==(const BlockHeader &rhs) const { - return std::tie(parent_hash, number, state_root, extrinsics_root, digest) - == std::tie(rhs.parent_hash, - rhs.number, - rhs.state_root, - rhs.extrinsics_root, - rhs.digest); - } - - bool operator!=(const BlockHeader &rhs) const { - return !operator==(rhs); - } + CUSTOM_EQUALITY(BlockHeader, // + parent_hash, + number, + state_root, + extrinsics_root, + digest) std::optional parentInfo() const { if (number != 0) { @@ -118,9 +114,8 @@ namespace kagome::primitives { * @param v value to output * @return reference to stream */ - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const BlockHeader &bh) { + inline scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const BlockHeader &bh) { return s << bh.parent_hash << CompactInteger(bh.number) << bh.state_root << bh.extrinsics_root << bh.digest; } @@ -132,9 +127,8 @@ namespace kagome::primitives { * @param v value to output * @return reference to stream */ - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, BlockHeader &bh) { + inline scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + BlockHeader &bh) { CompactInteger number_compact; s >> bh.parent_hash >> number_compact >> bh.state_root >> bh.extrinsics_root >> bh.digest; diff --git a/core/primitives/check_inherents_result.hpp b/core/primitives/check_inherents_result.hpp index 6ee1f59904..53664d3ea1 100644 --- a/core/primitives/check_inherents_result.hpp +++ b/core/primitives/check_inherents_result.hpp @@ -13,8 +13,6 @@ namespace kagome::primitives { * @brief result of check_inherents method of BlockBuilder runtime api */ struct CheckInherentsResult { - SCALE_TIE(3); - /// Did the check succeed? bool is_okay = false; /// Did we encounter a fatal error? diff --git a/core/primitives/common.hpp b/core/primitives/common.hpp index 440a3e8cca..e692b1e635 100644 --- a/core/primitives/common.hpp +++ b/core/primitives/common.hpp @@ -13,7 +13,6 @@ #include "common/blob.hpp" #include "macro/endianness_utils.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { using BlockNumber = uint32_t; @@ -24,10 +23,7 @@ namespace kagome::primitives { // base data structure for the types describing block information // (BlockInfo, Prevote, Precommit, PrimaryPropose) template - struct BlockInfoT : public boost::equality_comparable>, - public boost::less_than_comparable> { - SCALE_TIE_ONLY(hash, number); - + struct BlockInfoT { BlockInfoT() = default; BlockInfoT(const BlockNumber &n, const BlockHash &h) @@ -42,6 +38,10 @@ namespace kagome::primitives { bool operator<(const BlockInfoT &o) const { return number < o.number or (number == o.number and hash < o.hash); } + auto operator<=>(const BlockInfoT &o) const = default; + + private: + SCALE_CUSTOM_DECOMPOSING(BlockInfoT, hash, number); }; } // namespace detail diff --git a/core/primitives/digest.hpp b/core/primitives/digest.hpp index ea9f4da07c..65aaa993e8 100644 --- a/core/primitives/digest.hpp +++ b/core/primitives/digest.hpp @@ -6,19 +6,16 @@ #pragma once -#include - #include "common/buffer.hpp" +#include "common/empty.hpp" #include "common/tagged.hpp" #include "common/unused.hpp" -#include "consensus/babe/types/babe_block_header.hpp" #include "consensus/babe/types/babe_configuration.hpp" #include "consensus/babe/types/epoch_data.hpp" #include "consensus/babe/types/scheduled_change.hpp" #include "consensus/constants.hpp" #include "consensus/grandpa/types/scheduled_change.hpp" #include "scale/scale.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { /// Consensus engine unique ID. @@ -36,15 +33,14 @@ namespace kagome::primitives { inline const auto kBeefyEngineId = ConsensusEngineId::fromString("BEEF").value(); - struct Other : public common::Buffer {}; + using Other = Tagged; namespace detail { struct DigestItemCommon { - SCALE_TIE(2); - ConsensusEngineId consensus_engine_id; common::SLBuffer data; + bool operator==(const DigestItemCommon &other) const = default; }; } // namespace detail @@ -54,7 +50,16 @@ namespace kagome::primitives { /// the consensus engine can (and should) read them itself to avoid /// code and state duplication. It is erroneous for a runtime to produce /// these, but this is not (yet) checked. - struct PreRuntime : public detail::DigestItemCommon {}; + struct PreRuntime : public detail::DigestItemCommon { + friend scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const PreRuntime &v) { + return s << static_cast(v); + } + friend scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + PreRuntime &v) { + return s >> static_cast(v); + } + }; /// https://github.com/paritytech/substrate/blob/polkadot-v0.9.8/primitives/consensus/babe/src/lib.rs#L130 using BabeDigest = @@ -149,11 +154,29 @@ namespace kagome::primitives { outcome::result decode() const { return DecodedConsensusMessage::create(consensus_engine_id, data); } + + friend scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const Consensus &v) { + return s << static_cast(v); + } + friend scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + Consensus &v) { + return s >> static_cast(v); + } }; /// Put a Seal on it. /// This is only used by native code, and is never seen by runtimes. - struct Seal : public detail::DigestItemCommon {}; + struct Seal : public detail::DigestItemCommon { + friend scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const Seal &v) { + return s << static_cast(v); + } + friend scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + Seal &v) { + return s >> static_cast(v); + } + }; /// Runtime code or heap pages updated. struct RuntimeEnvironmentUpdated : public Empty {}; @@ -172,11 +195,9 @@ namespace kagome::primitives { Unused<7>, // 7 RuntimeEnvironmentUpdated>; // 8 - namespace { - // This value is enough to disable each of validators in each of two - // consensus engines - constexpr auto kMaxItemsInDigest = consensus::kMaxValidatorsNumber * 4; - } // namespace + // This value is enough to disable each of validators in each of two + // consensus engines + constexpr auto kMaxItemsInDigest = consensus::kMaxValidatorsNumber * 4; /** * Digest is an implementation- and usage-defined entity, for example, diff --git a/core/primitives/extrinsic.hpp b/core/primitives/extrinsic.hpp index ef826e627f..b722ce861a 100644 --- a/core/primitives/extrinsic.hpp +++ b/core/primitives/extrinsic.hpp @@ -9,7 +9,6 @@ #include #include "common/buffer.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { @@ -22,8 +21,7 @@ namespace kagome::primitives { * @brief Extrinsic class represents extrinsic */ struct Extrinsic { - SCALE_TIE(1); - common::Buffer data; ///< extrinsic content as byte array + bool operator==(const Extrinsic &other) const = default; }; } // namespace kagome::primitives diff --git a/core/primitives/inherent_data.cpp b/core/primitives/inherent_data.cpp index 8222bc0bd3..a537201e59 100644 --- a/core/primitives/inherent_data.cpp +++ b/core/primitives/inherent_data.cpp @@ -16,17 +16,3 @@ OUTCOME_CPP_DEFINE_CATEGORY(kagome::primitives, InherentDataError, e) { } return "Unknown error"; } - -namespace kagome::primitives { - - bool InherentData::operator==( - const kagome::primitives::InherentData &rhs) const { - return data == rhs.data; - } - - bool InherentData::operator!=( - const kagome::primitives::InherentData &rhs) const { - return !operator==(rhs); - } - -} // namespace kagome::primitives diff --git a/core/primitives/inherent_data.hpp b/core/primitives/inherent_data.hpp index 2483ec94e0..476a11da2c 100644 --- a/core/primitives/inherent_data.hpp +++ b/core/primitives/inherent_data.hpp @@ -7,16 +7,14 @@ #pragma once #include +#include #include -#include -#include -#include +#include + #include "common/blob.hpp" #include "common/buffer.hpp" #include "common/outcome_throw.hpp" -#include "scale/scale.hpp" -#include "scale/scale_error.hpp" namespace kagome::primitives { /** @@ -78,52 +76,26 @@ namespace kagome::primitives { return InherentDataError::IDENTIFIER_DOES_NOT_EXIST; } - bool operator==(const InherentData &rhs) const; - - bool operator!=(const InherentData &rhs) const; - std::map data; - }; - /** - * @brief output InherentData object instance to stream - * @tparam Stream stream type - * @param s stream reference - * @param v value to output - * @return reference to stream - */ - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const InherentData &v) { - const auto &data = v.data; - std::vector> vec; - vec.reserve(data.size()); - for (auto &pair : data) { - vec.emplace_back(pair); - } - s << vec; - return s; - } + bool operator==(const InherentData &) const = default; + }; /** * @brief decodes InherentData object instance from stream - * @tparam Stream input stream type * @param s stream reference * @param v value to decode * @return reference to stream */ - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, InherentData &v) { + inline scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + InherentData &v) { std::vector> vec; s >> vec; - for (const auto &item : vec) { - // throw if identifier already exists - if (v.data.find(item.first) != v.data.end()) { + for (const auto &pair : vec) { + if (not v.data.emplace(pair).second) { common::raise(InherentDataError::IDENTIFIER_ALREADY_EXISTS); } - v.data.insert(item); } return s; diff --git a/core/primitives/justification.hpp b/core/primitives/justification.hpp index ef2998c375..4871d8f489 100644 --- a/core/primitives/justification.hpp +++ b/core/primitives/justification.hpp @@ -7,15 +7,13 @@ #pragma once #include "common/buffer.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { /** * Justification of the finalized block */ struct Justification { - SCALE_TIE(1); - common::Buffer data; + bool operator==(const Justification &other) const = default; }; } // namespace kagome::primitives diff --git a/core/primitives/kill_storage_result.hpp b/core/primitives/kill_storage_result.hpp index 11e2e83e01..9f0a17e2a1 100644 --- a/core/primitives/kill_storage_result.hpp +++ b/core/primitives/kill_storage_result.hpp @@ -6,8 +6,6 @@ #pragma once -#include "scale/tie.hpp" - namespace kagome { /** * `clear_prefix` host api limit argument. @@ -19,9 +17,8 @@ namespace kagome { * https://github.com/paritytech/polkadot-sdk/blob/e5a93fbcd4a6acec7ab83865708e5c5df3534a7b/substrate/primitives/io/src/lib.rs#L159 */ struct KillStorageResult { - SCALE_TIE(2); - bool more{}; uint32_t loops{}; + bool operator==(const KillStorageResult &other) const = default; }; } // namespace kagome diff --git a/core/primitives/mmr.hpp b/core/primitives/mmr.hpp index f775b5fc61..566b8626d3 100644 --- a/core/primitives/mmr.hpp +++ b/core/primitives/mmr.hpp @@ -8,7 +8,6 @@ #include "common/buffer.hpp" #include "primitives/common.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { enum class MmrError : uint8_t { @@ -30,8 +29,6 @@ namespace kagome::primitives { using MmrLeaves = std::vector; struct MmrProof { - SCALE_TIE(3); - std::vector leaf_indices; uint64_t leaf_count; std::vector items; diff --git a/core/primitives/parachain_host.hpp b/core/primitives/parachain_host.hpp index 0337280397..c037ef3a1b 100644 --- a/core/primitives/parachain_host.hpp +++ b/core/primitives/parachain_host.hpp @@ -31,7 +31,6 @@ namespace kagome::primitives::parachain { * @brief Relay primitive is empty in polkadot for now */ struct Relay {}; - SCALE_EMPTY_CODER(Relay); /** * @brief Parachain primitive diff --git a/core/primitives/rpc_methods.hpp b/core/primitives/rpc_methods.hpp index 1bb64ec8e9..18a0d3d589 100644 --- a/core/primitives/rpc_methods.hpp +++ b/core/primitives/rpc_methods.hpp @@ -9,8 +9,6 @@ #include #include -#include "scale/tie.hpp" - namespace kagome::primitives { // The version number is just hardcoded in substrate implementation @@ -21,8 +19,6 @@ namespace kagome::primitives { * A descriptor for a set of methods supported via RPC */ struct RpcMethods { - SCALE_TIE(2); - using Version = uint32_t; using Methods = std::vector; diff --git a/core/primitives/runtime_dispatch_info.hpp b/core/primitives/runtime_dispatch_info.hpp index d0e1f21bd7..4a69416c7e 100644 --- a/core/primitives/runtime_dispatch_info.hpp +++ b/core/primitives/runtime_dispatch_info.hpp @@ -7,7 +7,6 @@ #pragma once #include -#include #include "common/unused.hpp" #include "scale/big_fixed_integers.hpp" @@ -18,20 +17,12 @@ namespace kagome::primitives { using OldWeight = scale::Compact; struct Weight { - // NOLINTBEGIN - SCALE_TIE(2); - // NOLINTEND - Weight() = default; - - explicit Weight(OldWeight w) : ref_time{w}, proof_size{0} {} - - Weight(uint64_t ref_time, uint64_t proof_size) - : ref_time{ref_time}, proof_size{proof_size} {} - // The weight of computational time used based on some reference hardware. scale::Compact ref_time; // The weight of storage space used by proof of validity. - scale::Compact proof_size; + scale::Compact proof_size{0}; + + bool operator==(const Weight &) const = default; }; // for some reason encoded as variant in substrate, thus custom encode/decode @@ -59,30 +50,13 @@ namespace kagome::primitives { Mandatory }; - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &stream, DispatchClass &dispatch_class) { - uint8_t dispatch_class_byte; - stream >> dispatch_class_byte; - dispatch_class = static_cast(dispatch_class_byte); - return stream; - } - - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &stream, DispatchClass dispatch_class) { - return stream << dispatch_class; - } - - struct Balance : public scale::Fixed {}; + using Balance = scale::Fixed; /** Information related to a dispatchable class, weight, and fee that can be * queried from the runtime. */ template struct RuntimeDispatchInfo { - SCALE_TIE(3); // NOLINT - Weight weight; DispatchClass dispatch_class; @@ -91,6 +65,7 @@ namespace kagome::primitives { * `SignedExtension`). */ Balance partial_fee; + bool operator==(const RuntimeDispatchInfo &) const = default; }; } // namespace kagome::primitives diff --git a/core/primitives/token_error.hpp b/core/primitives/token_error.hpp index 95ab602eab..1f8437c29e 100644 --- a/core/primitives/token_error.hpp +++ b/core/primitives/token_error.hpp @@ -8,6 +8,8 @@ #include +#include + #include "outcome/outcome.hpp" namespace kagome::primitives { @@ -29,17 +31,15 @@ namespace kagome::primitives { Unsupported, }; - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const TokenError &v) { + inline scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const TokenError &v) { // index shift is required for compatibility with rust implementation. // std::error_code policy preserves 0 index for success cases. return s << static_cast(v) - 1; } - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, TokenError &v) { + inline scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + TokenError &v) { uint8_t value = 0u; s >> value; // index shift is required for compatibility with rust implementation. diff --git a/core/primitives/transaction_validity.hpp b/core/primitives/transaction_validity.hpp index f85acf2bf3..fdb64630a3 100644 --- a/core/primitives/transaction_validity.hpp +++ b/core/primitives/transaction_validity.hpp @@ -13,7 +13,6 @@ #include #include "primitives/transaction.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { @@ -47,8 +46,6 @@ namespace kagome::primitives { * https://github.com/paritytech/substrate/blob/a31c01b398d958ccf0a24d8c1c11fb073df66212/core/sr-primitives/src/transaction_validity.rs#L178 */ struct ValidTransaction { - SCALE_TIE(5); - /** * @brief Priority of the transaction. * Priority determines the ordering of two transactions that have all @@ -88,6 +85,8 @@ namespace kagome::primitives { * never be sent to other peers. */ bool propagate{}; + + bool operator==(const ValidTransaction &other) const = default; }; /// Transaction is invalid. Details are described by the error code. @@ -140,9 +139,8 @@ namespace kagome::primitives { } }; - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const InvalidTransaction &v) { + inline scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const InvalidTransaction &v) { // -1 is needed for compatibility with Rust; indices of error codes start // from 0 there, while in kagome they must start from 1 because of // std::error_code policy @@ -153,9 +151,8 @@ namespace kagome::primitives { return s; } - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, InvalidTransaction &v) { + inline scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + InvalidTransaction &v) { uint8_t value = 0u; s >> value; @@ -193,9 +190,8 @@ namespace kagome::primitives { uint8_t custom_value{}; }; - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const UnknownTransaction &v) { + inline scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const UnknownTransaction &v) { // -1 is needed for compatibility with Rust; indices of error codes start // from 0 there, while in kagome they must start from 1 because of // std::error_code policy @@ -206,9 +202,8 @@ namespace kagome::primitives { return s; } - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, UnknownTransaction &v) { + inline scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + UnknownTransaction &v) { uint8_t value = 0u; s >> value; diff --git a/core/primitives/version.hpp b/core/primitives/version.hpp index 4e1f46d8e9..9653e72655 100644 --- a/core/primitives/version.hpp +++ b/core/primitives/version.hpp @@ -11,7 +11,6 @@ #include #include "common/blob.hpp" -#include "scale/tie.hpp" namespace kagome::primitives { /** @@ -44,8 +43,6 @@ namespace kagome::primitives { * `impl_version` since they change the semantics of the runtime. */ struct Version { - SCALE_TIE(8); - /** * Identifies the different Substrate runtimes. There'll be at least * polkadot and node. diff --git a/core/runtime/common/runtime_upgrade_tracker_impl.hpp b/core/runtime/common/runtime_upgrade_tracker_impl.hpp index 557e0bc96f..f3fab63a36 100644 --- a/core/runtime/common/runtime_upgrade_tracker_impl.hpp +++ b/core/runtime/common/runtime_upgrade_tracker_impl.hpp @@ -12,9 +12,7 @@ #include "application/chain_spec.hpp" #include "log/logger.hpp" -#include "outcome/outcome.hpp" #include "primitives/event_types.hpp" -#include "scale/tie.hpp" #include "storage/spaced_storage.hpp" #include "storage/trie/types.hpp" @@ -37,15 +35,6 @@ namespace kagome::runtime { std::shared_ptr block_tree); struct RuntimeUpgradeData { - SCALE_TIE(2); - - RuntimeUpgradeData() = default; - - template - RuntimeUpgradeData(BlockInfo &&block, RootHash &&state) - : block{std::forward(block)}, - state{std::forward(state)} {} - primitives::BlockInfo block; storage::trie::RootHash state; }; diff --git a/core/runtime/heap_alloc_strategy.hpp b/core/runtime/heap_alloc_strategy.hpp index 096c9ce77d..4828bddb33 100644 --- a/core/runtime/heap_alloc_strategy.hpp +++ b/core/runtime/heap_alloc_strategy.hpp @@ -10,7 +10,6 @@ #include #include -#include "scale/tie.hpp" #include "scale/tie_hash.hpp" namespace kagome { @@ -19,7 +18,6 @@ namespace kagome { * allow it to grow dynamically. */ struct HeapAllocStrategyDynamic { - SCALE_TIE(1); SCALE_TIE_HASH_BOOST(HeapAllocStrategyDynamic); /** @@ -29,6 +27,9 @@ namespace kagome { * maximum limit supported by WASM (4GB). */ std::optional maximum_pages; + + bool operator==(const HeapAllocStrategyDynamic &other) const = default; + SCALE_CUSTOM_DECOMPOSING(HeapAllocStrategyDynamic, maximum_pages); }; /** * Allocate a static number of heap pages. @@ -36,7 +37,6 @@ namespace kagome { * pages requested by the wasm file plus the `extra_pages`. */ struct HeapAllocStrategyStatic { - SCALE_TIE(1); SCALE_TIE_HASH_BOOST(HeapAllocStrategyStatic); /** @@ -44,6 +44,9 @@ namespace kagome { * requested by the wasm file. */ uint32_t extra_pages; + + bool operator==(const HeapAllocStrategyStatic &other) const = default; + SCALE_CUSTOM_DECOMPOSING(HeapAllocStrategyStatic, extra_pages); }; /** * Defines the heap pages allocation strategy the wasm runtime should use. diff --git a/core/runtime/runtime_api/parachain_host_types.hpp b/core/runtime/runtime_api/parachain_host_types.hpp index fc5ff6d2e5..4c85e46f6c 100644 --- a/core/runtime/runtime_api/parachain_host_types.hpp +++ b/core/runtime/runtime_api/parachain_host_types.hpp @@ -41,7 +41,6 @@ namespace kagome::runtime { using CandidateDescriptor = network::CandidateDescriptor; struct ClaimQueueSnapshot { - SCALE_TIE(1); std::map> claimes; std::optional get_claim_for(CoreIndex core_index, @@ -103,8 +102,6 @@ namespace kagome::runtime { }; struct GroupDescriptor { - SCALE_TIE(3); - /// The block number where the session started. BlockNumber session_start_block; @@ -114,6 +111,8 @@ namespace kagome::runtime { /// The current block number. BlockNumber now_block_num; + bool operator==(const GroupDescriptor &rhs) const = default; + /// Returns the index of the group needed to validate the core at the given /// index, assuming the given number of cores. GroupIndex groupForCore(CoreIndex core_index, size_t cores) const { @@ -167,13 +166,13 @@ namespace kagome::runtime { }; struct ValidatorGroup { - SCALE_TIE(1); std::vector validators; bool contains(kagome::parachain::ValidatorIndex validator_ix) const { - return std::find(validators.begin(), validators.end(), validator_ix) - != validators.end(); + return std::ranges::find(validators, validator_ix) != validators.end(); } + + bool operator==(const ValidatorGroup &rhs) const = default; }; using FreeCore = Empty; @@ -189,8 +188,6 @@ namespace kagome::runtime { Free // 2 }; struct PersistedValidationData { - SCALE_TIE(4); - /// The parent head-data. HeadData parent_head; /// The relay-chain block number this is in the context of. @@ -199,15 +196,15 @@ namespace kagome::runtime { Hash relay_parent_storage_root; /// The maximum legal size of a POV block, in bytes. uint32_t max_pov_size; + bool operator==(const PersistedValidationData &) const = default; }; struct AvailableData { - SCALE_TIE(2); - /// The Proof-of-Validation of the candidate. network::ParachainBlock pov; /// The persisted validation data needed for secondary checks. runtime::PersistedValidationData validation_data; + bool operator==(const AvailableData &) const = default; }; using OutboundHrmpMessage = network::OutboundHorizontal; @@ -220,25 +217,21 @@ namespace kagome::runtime { HeadData head_data; CoreIndex core_index; - bool operator==(const Candidate &rhs) const { - return candidate_receipt == rhs.candidate_receipt - and head_data == rhs.head_data // - and core_index == rhs.core_index; - } + bool operator==(const Candidate &rhs) const = default; }; struct CandidateBacked : public Candidate { GroupIndex group_index{}; - bool operator==(const CandidateBacked &rhs) const { - return (const Candidate &)(*this) == (const Candidate &)rhs - and group_index == rhs.group_index; - } + bool operator==(const CandidateBacked &rhs) const = default; }; struct CandidateIncluded : public Candidate, public boost::equality_comparable { + using Candidate::candidate_receipt; + using Candidate::core_index; + using Candidate::head_data; GroupIndex group_index{}; bool operator==(const CandidateIncluded &rhs) const { @@ -247,7 +240,7 @@ namespace kagome::runtime { } }; - struct CandidateTimedOut : public Candidate {}; + using CandidateTimedOut = Tagged; using CandidateEvent = boost::variant< /// This candidate receipt was backed in the most recent block. @@ -267,8 +260,6 @@ namespace kagome::runtime { using AuthorityDiscoveryId = common::Hash256; using AssignmentId = common::Blob<32>; struct SessionInfo { - SCALE_TIE(13); - /****** New in v2 *******/ /// All the validators actively participating in parachain consensus. /// Indices are into the broader validator set. @@ -382,42 +373,34 @@ namespace kagome::runtime { /// Maximum number of memory pages (64KiB bytes per page) the executor can /// allocate. struct MaxMemoryPages { - SCALE_TIE(1) uint32_t limit; }; /// Wasm logical stack size limit (max. number of Wasm values on stack) struct StackLogicalMax { - SCALE_TIE(1) uint32_t max_values_num; }; /// Executor machine stack size limit, in bytes struct StackNativeMax { - SCALE_TIE(1) uint32_t max_bytes_num; }; /// Max. amount of memory the preparation worker is allowed to use during /// pre-checking, in bytes struct PrecheckingMaxMemory { - SCALE_TIE(1) uint64_t max_bytes_num; }; /// PVF preparation timeouts, millisec struct PvfPrepTimeout { - SCALE_TIE(2) PvfPrepTimeoutKind kind; uint64_t msec; }; /// PVF execution timeouts, millisec struct PvfExecTimeout { - SCALE_TIE(2) PvfExecTimeoutKind kind; uint64_t msec; }; - struct WasmExtBulkMemory { - SCALE_TIE(0); - }; + struct WasmExtBulkMemory {}; using ExecutorParam = std::variant, MaxMemoryPages, diff --git a/core/runtime/runtime_context.hpp b/core/runtime/runtime_context.hpp index 5aeeb77ee4..6950a29f32 100644 --- a/core/runtime/runtime_context.hpp +++ b/core/runtime/runtime_context.hpp @@ -47,9 +47,9 @@ namespace kagome::runtime { static constexpr bool DEFAULT_WASM_EXT_BULK_MEMORY = false; struct ContextParams { - SCALE_TIE(2); MemoryLimits memory_limits; bool wasm_ext_bulk_memory = DEFAULT_WASM_EXT_BULK_MEMORY; + bool operator==(const ContextParams &other) const = default; }; const std::shared_ptr module_instance; diff --git a/core/runtime/types.hpp b/core/runtime/types.hpp index 2f60677a17..993647ad97 100644 --- a/core/runtime/types.hpp +++ b/core/runtime/types.hpp @@ -10,9 +10,7 @@ #include #include -#include "outcome/outcome.hpp" #include "runtime/heap_alloc_strategy.hpp" -#include "scale/tie.hpp" namespace kagome::runtime { /** @@ -52,10 +50,9 @@ namespace kagome::runtime { using WasmI64 = int64_t; struct MemoryLimits { - SCALE_TIE(2); - std::optional max_stack_values_num{}; HeapAllocStrategy heap_alloc_strategy; + bool operator==(const MemoryLimits &) const = default; }; struct MemoryConfig { diff --git a/core/runtime/wavm/module_factory_impl.cpp b/core/runtime/wavm/module_factory_impl.cpp index a3d0c9930f..3e7cff9c0f 100644 --- a/core/runtime/wavm/module_factory_impl.cpp +++ b/core/runtime/wavm/module_factory_impl.cpp @@ -23,9 +23,8 @@ namespace kagome::runtime::wavm { struct Compiled { - SCALE_TIE(2); - - Buffer wasm, compiled; + Buffer wasm; + Buffer compiled; }; static thread_local std::shared_ptr loading; diff --git a/core/scale/big_fixed_integers.hpp b/core/scale/big_fixed_integers.hpp index 153c332c03..702c560ae9 100644 --- a/core/scale/big_fixed_integers.hpp +++ b/core/scale/big_fixed_integers.hpp @@ -9,61 +9,46 @@ #include #include +#include #include -#include "common/int_serialization.hpp" +#include "common/tagged.hpp" namespace scale { - template - struct IntegerTraits; - - /** - * Wrapper for an integer to make distinct integer aliases - * @tparam Tag - * @tparam T - */ - template - struct IntWrapper { - static_assert(!std::is_reference_v); - static_assert(!std::is_pointer_v); - static_assert(!std::is_const_v); - - using Self = IntWrapper; - using ValueType = T; - - static constexpr size_t kByteSize = IntegerTraits::kBitSize / 8; - - T &operator*() { - return number; - } - - const T &operator*() const { - return number; - } + using uint128_t = boost::multiprecision::checked_uint128_t; + using uint256_t = boost::multiprecision::checked_uint256_t; - bool operator==(const Self &other) const { - return **this == *other; - } + template + concept SupportedInteger = std::is_unsigned_v // + or std::is_same_v // + or std::is_same_v; - T number; + template + struct IntegerTraits { + static constexpr size_t kBitSize = sizeof(T) * 8; + }; + template <> + struct IntegerTraits { + static constexpr size_t kBitSize = 128; + }; + template <> + struct IntegerTraits { + static constexpr size_t kBitSize = 256; }; // TODO(Harrm) #1480 add check for narrowing conversion - template >> - U convert_to(T t) { - return static_cast(t); + template + requires std::is_trivial_v + To convert_to(From t) { + return static_cast(t); } - template < - typename U, - typename T, - typename = std::enable_if_t::value>> - U convert_to(const T &t) { + template + requires boost::multiprecision::is_number::value + To convert_to(const From &t) { try { - return t.template convert_to(); + return t.template convert_to(); } catch (const std::runtime_error &e) { // scale::decode catches std::system_errors throw std::system_error{ @@ -72,71 +57,51 @@ namespace scale { } } - struct FixedTag {}; - // an integer intended to be encoded with fixed length template - using Fixed = IntWrapper; - - struct CompactTag {}; + requires SupportedInteger + using Fixed = kagome::Tagged; // an integer intended to be encoded with compact encoding template - using Compact = IntWrapper; + requires SupportedInteger + using Compact = qtils::Tagged; - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &stream, Fixed &fixed) { - for (size_t i = 0; i < Fixed::kByteSize * 8; i += 8) { - *fixed |= N(stream.nextByte()) << i; + template + ScaleDecoderStream &operator>>(ScaleDecoderStream &stream, Fixed &fixed) { + T decoded = 0; + for (size_t i = 0; i < IntegerTraits::kBitSize; i += 8) { + decoded |= T(stream.nextByte()) << i; } + fixed = decoded; return stream; } - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &stream, const Fixed &fixed) { - constexpr size_t bits = Fixed::kByteSize * 8; - for (size_t i = 0; i < bits; i += 8) { - stream << convert_to((*fixed >> i) & 0xFFu); + template + ScaleEncoderStream &operator<<(ScaleEncoderStream &stream, + const Fixed &fixed) { + T original = untagged(fixed); + for (size_t i = 0; i < IntegerTraits::kBitSize; i += 8) { + stream << convert_to((original >> i) & 0xFFu); } return stream; } - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &stream, Compact &compact) { + template + ScaleDecoderStream &operator>>(ScaleDecoderStream &stream, + Compact &compact) { scale::CompactInteger n; stream >> n; - compact.number = n.convert_to(); + compact = n.convert_to(); return stream; } - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &stream, const Compact &compact) { - scale::CompactInteger n = *compact; + template + ScaleEncoderStream &operator<<(ScaleEncoderStream &stream, + const Compact &compact) { + scale::CompactInteger n = untagged(compact); stream << n; return stream; } -#define SPECIALIZE_INTEGER_TRAITS(type, bit_size) \ - template <> \ - struct IntegerTraits { \ - static constexpr size_t kBitSize = bit_size; \ - }; - - using uint128_t = boost::multiprecision::checked_uint128_t; - using uint256_t = boost::multiprecision::checked_uint256_t; - - SPECIALIZE_INTEGER_TRAITS(uint8_t, 8); - SPECIALIZE_INTEGER_TRAITS(uint16_t, 16); - SPECIALIZE_INTEGER_TRAITS(uint32_t, 32); - SPECIALIZE_INTEGER_TRAITS(uint64_t, 64); - - SPECIALIZE_INTEGER_TRAITS(uint128_t, 128); - SPECIALIZE_INTEGER_TRAITS(uint256_t, 256); - -#undef SPECIALIZE_INTEGER_TRAITS - } // namespace scale diff --git a/core/scale/encoder/primitives.hpp b/core/scale/encoder/primitives.hpp index 8604f6f57b..b7648fc686 100644 --- a/core/scale/encoder/primitives.hpp +++ b/core/scale/encoder/primitives.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -119,7 +120,18 @@ namespace kagome::scale { const auto val = math::toLE(v); putByte(func, (uint8_t *)&val, size); } else { - kagome::scale::encode(func, utils::to_tuple_refs(v)); + // kagome::scale::encode(func, utils::to_tuple_refs(v)); + if constexpr (requires { + decompose_and_apply( + v, [&](const auto &...tuple_elements) { + kagome::scale::encode(func, + std::tie(tuple_elements...)); + }); + }) { + decompose_and_apply(v, [&](const auto &...tuple_elements) { + kagome::scale::encode(func, std::tie(tuple_elements...)); + }); + } } } diff --git a/core/scale/kagome_scale.hpp b/core/scale/kagome_scale.hpp index aa1c90d5a7..b598fa12f3 100644 --- a/core/scale/kagome_scale.hpp +++ b/core/scale/kagome_scale.hpp @@ -67,9 +67,8 @@ namespace kagome::scale { const Invocable auto &func, const common::SLVector &c); - template - constexpr void encode(const Invocable auto &func, - const Tagged &c); + template + constexpr void encode(const Invocable auto &func, const Tagged &c); template constexpr void encode(const Invocable auto &func, @@ -179,11 +178,10 @@ namespace kagome::scale { func, static_cast &>(c)); } - template - constexpr void encode(const Invocable auto &func, - const Tagged &c) { + template + constexpr void encode(const Invocable auto &func, const Tagged &c) { if constexpr (std::is_scalar_v) { - kagome::scale::encode(func, c.Wrapper::value); + kagome::scale::encode(func, c.template Wrapper::value); } else { kagome::scale::encode(func, static_cast(c)); } @@ -315,10 +313,10 @@ namespace kagome::scale { } template - constexpr void encode(const Invocable auto &func, const Fixed &c) { - constexpr size_t bits = Fixed::kByteSize * 8; - for (size_t i = 0; i < bits; i += 8) { - encode(func, ::scale::convert_to((*c >> i) & 0xFFu)); + constexpr void encode(const Invocable auto &func, const Fixed &fixed) { + T original = untagged(fixed); + for (size_t i = 0; i < ::scale::IntegerTraits::kBitSize; i += 8) { + encode(func, ::scale::convert_to((original >> i) & 0xFFu)); } } diff --git a/core/scale/tie.hpp b/core/scale/tie.hpp deleted file mode 100644 index 5601c67b67..0000000000 --- a/core/scale/tie.hpp +++ /dev/null @@ -1,142 +0,0 @@ -/** - * Copyright Quadrivium LLC - * All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include -#include - -#define SCALE_TIE_EQ \ - template \ - bool operator==(const _ScaleTieType &r) const { \ - using ThisT = std::decay_t; \ - using ExtT = std::decay_t<_ScaleTieType>; \ - static_assert(std::is_same_v \ - || std::is_base_of_v); \ - return ::scale::as_tie(*this, [&](auto l) { \ - return ::scale::as_tie(r, [&](auto r) { return l == r; }); \ - }); \ - } \ - template \ - bool operator!=(const _ScaleTieType &r) const { \ - return !operator==(r); \ - } - -#define SCALE_TIE_ONLY(...) \ - auto as_tie() { \ - return std::tie(__VA_ARGS__); \ - } \ - SCALE_TIE_EQ - -#define SCALE_TIE(N) \ - static constexpr size_t scale_tie = N; \ - SCALE_TIE_EQ - -namespace scale { - class ScaleEncoderStream; - class ScaleDecoderStream; - - template >>() - .as_tie())> - // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) - auto as_tie(T &&v, F &&f) { - return f(const_cast> &>(v) - .as_tie()); - } - - // generated by housekeeping/scale_tie.py - template ::scale_tie> - // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) - auto as_tie(T &&v, F &&f) { - if constexpr (N == 0) { - return std::tie(); - } else if constexpr (N == 1) { - auto &[v0] = v; - return std::forward(f)(std::tie(v0)); - } else if constexpr (N == 2) { - auto &[v0, v1] = v; - return std::forward(f)(std::tie(v0, v1)); - } else if constexpr (N == 3) { - auto &[v0, v1, v2] = v; - return std::forward(f)(std::tie(v0, v1, v2)); - } else if constexpr (N == 4) { - auto &[v0, v1, v2, v3] = v; - return std::forward(f)(std::tie(v0, v1, v2, v3)); - } else if constexpr (N == 5) { - auto &[v0, v1, v2, v3, v4] = v; - return std::forward(f)(std::tie(v0, v1, v2, v3, v4)); - } else if constexpr (N == 6) { - auto &[v0, v1, v2, v3, v4, v5] = v; - return std::forward(f)(std::tie(v0, v1, v2, v3, v4, v5)); - } else if constexpr (N == 7) { - auto &[v0, v1, v2, v3, v4, v5, v6] = v; - return std::forward(f)(std::tie(v0, v1, v2, v3, v4, v5, v6)); - } else if constexpr (N == 8) { - auto &[v0, v1, v2, v3, v4, v5, v6, v7] = v; - return std::forward(f)(std::tie(v0, v1, v2, v3, v4, v5, v6, v7)); - } else if constexpr (N == 9) { - auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8] = v; - return std::forward(f)(std::tie(v0, v1, v2, v3, v4, v5, v6, v7, v8)); - } else if constexpr (N == 10) { - auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8, v9] = v; - return std::forward(f)( - std::tie(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)); - } else if constexpr (N == 11) { - auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10] = v; - return std::forward(f)( - std::tie(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)); - } else if constexpr (N == 12) { - auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11] = v; - return std::forward(f)( - std::tie(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)); - } else if constexpr (N == 13) { - auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12] = v; - return std::forward(f)( - std::tie(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)); - } else if constexpr (N == 14) { - auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13] = v; - return std::forward(f)( - std::tie(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)); - } else if constexpr (N == 15) { - auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14] = - v; - return std::forward(f)(std::tie( - v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)); - } else { - // generate code for bigger tuples - BOOST_STATIC_ASSERT_MSG(N > 15, "No code for such big tuple"); - } - } - - constexpr auto as_tie_sfinae = [](auto &&) {}; - - template (), - as_tie_sfinae))> - ScaleEncoderStream &operator<<(ScaleEncoderStream &s, const T &v) { - as_tie(v, [&](auto v) { - std::apply([&](const auto &...v) { (..., (s << v)); }, v); - }); - return s; - } - - template (), - as_tie_sfinae))> - ScaleDecoderStream &operator>>(ScaleDecoderStream &s, T &v) { - as_tie(v, [&](auto v) { - std::apply([&](auto &...v) { (..., (s >> v)); }, v); - }); - return s; - } - -} // namespace scale diff --git a/core/scale/tie_hash.hpp b/core/scale/tie_hash.hpp index 0d785a8b66..25609922ed 100644 --- a/core/scale/tie_hash.hpp +++ b/core/scale/tie_hash.hpp @@ -6,14 +6,30 @@ #pragma once -#include "scale/tie.hpp" +#include #include "utils/tuple_hash.hpp" namespace scale { - auto tieHash(const auto &v) { - return ::scale::as_tie(v, - [](auto t) { return std::hash{}(t); }); + class ScaleEncoderStream; + + using detail::decompose_and_apply; + + size_t tieHash(const auto &value) { + size_t seed = 0; + + auto append = [&](const T &element) { + boost::hash_combine(seed, std::hash>()(element)); + }; + + auto apply = [&](const auto &...elements) { // + (append(elements), ...); + }; + + decompose_and_apply(value, apply); + + return seed; } + } // namespace scale #define SCALE_TIE_HASH_BOOST(type) \ diff --git a/core/storage/trie_pruner/impl/trie_pruner_impl.cpp b/core/storage/trie_pruner/impl/trie_pruner_impl.cpp index ea3da3d5e8..554db079ce 100644 --- a/core/storage/trie_pruner/impl/trie_pruner_impl.cpp +++ b/core/storage/trie_pruner/impl/trie_pruner_impl.cpp @@ -15,6 +15,7 @@ #include "application/app_state_manager.hpp" #include "blockchain/block_tree.hpp" #include "crypto/hasher/hasher_impl.hpp" +#include "log/profiling_logger.hpp" #include "storage/database_error.hpp" #include "storage/predefined_keys.hpp" #include "storage/spaced_storage.hpp" diff --git a/core/storage/trie_pruner/impl/trie_pruner_impl.hpp b/core/storage/trie_pruner/impl/trie_pruner_impl.hpp index d52ddb9887..802bc8608c 100644 --- a/core/storage/trie_pruner/impl/trie_pruner_impl.hpp +++ b/core/storage/trie_pruner/impl/trie_pruner_impl.hpp @@ -8,18 +8,14 @@ #include "storage/trie_pruner/trie_pruner.hpp" -#include #include #include #include #include -#include "scale/tie.hpp" - #include "common/buffer.hpp" #include "log/logger.hpp" -#include "log/profiling_logger.hpp" #include "storage/buffer_map_types.hpp" namespace kagome::application { @@ -55,8 +51,6 @@ namespace kagome::storage::trie_pruner { ":trie_pruner:info"_buf; struct TriePrunerInfo { - SCALE_TIE(1); - std::optional last_pruned_block; }; diff --git a/core/utils/struct_to_tuple.hpp b/core/utils/struct_to_tuple.hpp index 03bf5189b2..3599d7594c 100644 --- a/core/utils/struct_to_tuple.hpp +++ b/core/utils/struct_to_tuple.hpp @@ -93,7 +93,7 @@ namespace kagome::utils { template inline auto to_tuple_refs(const T &object) { using type = std::decay_t; - TO_TUPLE9; + TO_TUPLE9 } } // namespace kagome::utils diff --git a/test/core/api/service/payment/payment_api_test.cpp b/test/core/api/service/payment/payment_api_test.cpp index 33cdc491a2..14ddffb217 100644 --- a/test/core/api/service/payment/payment_api_test.cpp +++ b/test/core/api/service/payment/payment_api_test.cpp @@ -83,8 +83,8 @@ TEST_F(PaymentApiTest, DecodeRuntimeDispatchInfo) { auto info = scale::decode>(data).value(); - ASSERT_EQ(*info.weight.ref_time, 144460000); - ASSERT_EQ(*info.weight.proof_size, 3593); + ASSERT_EQ(info.weight.ref_time, 144460000); + ASSERT_EQ(info.weight.proof_size, 3593); ASSERT_EQ(info.dispatch_class, kagome::primitives::DispatchClass::Normal); - ASSERT_EQ(*info.partial_fee, 154146098); + ASSERT_EQ(info.partial_fee, 154146098); } diff --git a/test/core/common/buffer_view_test.cpp b/test/core/common/buffer_view_test.cpp index 527a942eaf..ce45566109 100644 --- a/test/core/common/buffer_view_test.cpp +++ b/test/core/common/buffer_view_test.cpp @@ -8,6 +8,9 @@ #include +#include +#include + using namespace kagome::common; using Span = BufferView; diff --git a/test/core/consensus/grandpa/authority_manager_test.cpp b/test/core/consensus/grandpa/authority_manager_test.cpp index 00337d2f62..8fb9856fbe 100644 --- a/test/core/consensus/grandpa/authority_manager_test.cpp +++ b/test/core/consensus/grandpa/authority_manager_test.cpp @@ -88,9 +88,9 @@ class AuthorityManagerTest : public testing::Test { .authorities; if (it->second.second) { header.digest.emplace_back(Consensus{ForcedChange{ + *it->second.second, list, 0, - *it->second.second, }}); } else { header.digest.emplace_back(Consensus{ScheduledChange{list, 0}}); diff --git a/test/core/network/rpc_libp2p_test.cpp b/test/core/network/rpc_libp2p_test.cpp index d4ee8977b1..c22e63ed21 100644 --- a/test/core/network/rpc_libp2p_test.cpp +++ b/test/core/network/rpc_libp2p_test.cpp @@ -34,16 +34,14 @@ using ScaleRPC = RPC; namespace kagome::network { /// outputs object of type BlockResponse to stream - template - requires Stream::is_encoder_stream - Stream &operator<<(Stream &s, const BlocksResponse &v) { + scale::ScaleEncoderStream &operator<<(scale::ScaleEncoderStream &s, + const BlocksResponse &v) { return s << v.blocks; } /// decodes object of type BlockResponse from stream - template - requires Stream::is_decoder_stream - Stream &operator>>(Stream &s, BlocksResponse &v) { + scale::ScaleDecoderStream &operator>>(scale::ScaleDecoderStream &s, + BlocksResponse &v) { return s >> v.blocks; } } // namespace kagome::network diff --git a/test/core/runtime/allocator_test.cpp b/test/core/runtime/allocator_test.cpp index a386ca857d..279554872d 100644 --- a/test/core/runtime/allocator_test.cpp +++ b/test/core/runtime/allocator_test.cpp @@ -6,7 +6,6 @@ #include #include "runtime/common/memory_allocator.hpp" -#include "scale/tie.hpp" #include "testutil/runtime/memory.hpp" using kagome::common::unhex; @@ -16,16 +15,10 @@ using kagome::runtime::MemoryConfig; using kagome::runtime::TestMemory; struct Replay { - SCALE_TIE(3); - struct OpAllocate { - SCALE_TIE(2); - uint32_t size, ptr; }; struct OpDeallocate { - SCALE_TIE(1); - uint32_t ptr; }; using Op = boost::variant; diff --git a/test/core/runtime/executor_test.cpp b/test/core/runtime/executor_test.cpp index bf666e2a9a..e7ce2deddf 100644 --- a/test/core/runtime/executor_test.cpp +++ b/test/core/runtime/executor_test.cpp @@ -151,7 +151,7 @@ TEST_F(ExecutorTest, LatestStateSwitchesCorrectly) { kagome::primitives::BlockInfo block_info2{43, "block_hash2"_hash256}; kagome::primitives::BlockInfo block_info3{44, "block_hash3"_hash256}; - Buffer enc_args{scale::encode(2, 3).value()}; + Buffer enc_args{scale::encode(std::tuple(2, 3)).value()}; EXPECT_OUTCOME_TRUE(ctx1, prepareCall(block_info1, "state_hash1"_hash256, @@ -161,7 +161,7 @@ TEST_F(ExecutorTest, LatestStateSwitchesCorrectly) { auto res = executor.call(ctx1, "addTwo", 2, 3).value(); EXPECT_EQ(res, 5); - enc_args = scale::encode(7, 10).value(); + enc_args = scale::encode(std::tuple(7, 10)).value(); EXPECT_OUTCOME_TRUE(ctx2, prepareCall(block_info1, "state_hash2"_hash256, @@ -171,7 +171,7 @@ TEST_F(ExecutorTest, LatestStateSwitchesCorrectly) { EXPECT_OUTCOME_TRUE(res2, executor.call(ctx2, "addTwo", 7, 10)); ASSERT_EQ(res2, 17); - enc_args = scale::encode(0, 0).value(); + enc_args = scale::encode(std::tuple(0, 0)).value(); EXPECT_OUTCOME_TRUE(ctx3, prepareCall(block_info1, "state_hash2"_hash256, @@ -180,7 +180,7 @@ TEST_F(ExecutorTest, LatestStateSwitchesCorrectly) { 0)); EXPECT_EQ(executor.call(ctx3, "addTwo", 0, 0).value(), 0); - enc_args = scale::encode(7, 10).value(); + enc_args = scale::encode(std::tuple(7, 10)).value(); EXPECT_OUTCOME_TRUE(ctx4, prepareCall(block_info1, "state_hash3"_hash256, @@ -190,7 +190,7 @@ TEST_F(ExecutorTest, LatestStateSwitchesCorrectly) { EXPECT_OUTCOME_TRUE(res4, executor.call(ctx4, "addTwo", 7, 10)); ASSERT_EQ(res4, 17); - enc_args = scale::encode(-5, 5).value(); + enc_args = scale::encode(std::tuple(-5, 5)).value(); EXPECT_OUTCOME_TRUE(ctx5, prepareCall(block_info2, "state_hash4"_hash256, @@ -199,7 +199,7 @@ TEST_F(ExecutorTest, LatestStateSwitchesCorrectly) { 0)); EXPECT_EQ(executor.call(ctx5, "addTwo", -5, 5).value(), 0); - enc_args = scale::encode(7, 10).value(); + enc_args = scale::encode(std::tuple(7, 10)).value(); EXPECT_OUTCOME_TRUE(ctx6, prepareCall(block_info2, "state_hash5"_hash256, diff --git a/test/testutil/outcome.hpp b/test/testutil/outcome.hpp index fa542e4e97..79aee0f3dd 100644 --- a/test/testutil/outcome.hpp +++ b/test/testutil/outcome.hpp @@ -10,6 +10,8 @@ #include "common/visitor.hpp" #include "outcome/outcome.hpp" +#define OUTCOME_UNIQUE QTILS_UNIQUE_NAME(outcome) + #define EXPECT_OUTCOME_TRUE_void(var, expr) \ auto &&var = expr; \ EXPECT_TRUE(var) << "Line " << __LINE__ << ": " \ diff --git a/test/testutil/scale_test_comparator.hpp b/test/testutil/scale_test_comparator.hpp index fede908b0b..17f20605c4 100644 --- a/test/testutil/scale_test_comparator.hpp +++ b/test/testutil/scale_test_comparator.hpp @@ -13,8 +13,8 @@ namespace testutil { template inline outcome::result> scaleEncodeAndCompareWithRef( - T &&...t) { - return scale::encode(std::forward(t)...); + const T &...t) { + return scale::encode(std::tie(t...)); } } // namespace testutil From 2570db6afaefd877c6d4cd11e8444ea8aa7b2b2d Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov aka xDimon Date: Tue, 4 Feb 2025 03:30:48 +0800 Subject: [PATCH 05/30] refactor: adapt for updated outcome-macros for GTest Signed-off-by: Dmitriy Khaustov aka xDimon --- core/blockchain/indexer.hpp | 2 +- .../babe/impl/babe_config_repository_impl.hpp | 5 +- .../grandpa/impl/authority_manager_impl.hpp | 8 +- core/consensus/grandpa/structs.hpp | 2 +- .../types/block_announce_handshake.hpp | 10 +- .../types/collator_messages_vstaging.hpp | 6 +- core/network/types/roles.hpp | 2 +- core/parachain/approval/approval.hpp | 2 +- core/primitives/apply_result.hpp | 2 +- core/primitives/common.hpp | 2 +- core/runtime/heap_alloc_strategy.hpp | 4 +- core/scale/encoder/primitives.hpp | 18 ++- core/scale/kagome_scale.hpp | 6 +- .../api/service/author/author_api_test.cpp | 8 +- .../api/service/chain/base_request_test.cpp | 9 +- .../core/api/service/chain/chain_api_test.cpp | 22 +-- .../child_state/child_state_api_test.cpp | 9 +- .../api/service/payment/payment_api_test.cpp | 3 +- .../core/api/service/state/state_api_test.cpp | 42 +++--- .../state/state_jrpc_processor_test.cpp | 7 +- .../api/service/system/system_api_test.cpp | 11 +- .../core/api/transport/http_listener_test.cpp | 4 +- test/core/api/transport/listener_test.hpp | 5 +- test/core/api/transport/ws_listener_test.cpp | 4 +- test/core/application/chain_spec_test.cpp | 5 +- .../authorship/block_builder_factory_test.cpp | 2 - test/core/authorship/block_builder_test.cpp | 12 +- test/core/authorship/proposer_test.cpp | 3 +- test/core/blockchain/block_storage_test.cpp | 17 ++- test/core/blockchain/block_tree_test.cpp | 19 ++- test/core/common/buffer_view_test.cpp | 5 +- .../babe/babe_block_validator_test.cpp | 31 ++-- test/core/consensus/babe/babe_test.cpp | 7 +- test/core/consensus/grandpa/chain_test.cpp | 2 +- .../grandpa/vote_graph/adjust_base_test.cpp | 6 +- .../vote_graph/duplicate_vote_test.cpp | 6 +- .../consensus/grandpa/vote_graph/fixture.hpp | 34 ++--- .../ghost_introduce_branch_test.cpp | 6 +- .../vote_graph/ghost_merge_at_node_test.cpp | 8 +- ...rge_not_at_node_one_side_weighted_test.cpp | 6 +- .../grandpa/vote_graph/graph_fork_test.cpp | 12 +- .../grandpa/vote_graph/remove_vote_test.cpp | 6 +- .../vote_graph/walk_back_at_node_test.cpp | 8 +- ...ack_from_block_in_edge_fork_below_test.cpp | 6 +- ..._back_from_fork_block_node_below_tests.cpp | 8 +- .../core/consensus/grandpa/voter_set_test.cpp | 13 +- .../timeline/block_executor_test.cpp | 7 +- .../crypto/bandersnatch/bandersnatch_test.cpp | 3 +- .../crypto/bip39/bip39_integration_test.cpp | 16 +- .../crypto/bip39/entropy_calculation_test.cpp | 12 +- .../core/crypto/ecdsa/ecdsa_provider_test.cpp | 15 +- .../crypto/ed25519/ed25519_provider_test.cpp | 23 +-- test/core/crypto/key_store/key_store_test.cpp | 58 +++---- .../secp256k1/secp256k1_provider_test.cpp | 35 +++-- .../crypto/sr25519/sr25519_provider_test.cpp | 42 +++--- .../host_api/child_storage_extension_test.cpp | 1 - test/core/host_api/crypto_extension_test.cpp | 9 +- .../core/host_api/offchain_extension_test.cpp | 3 +- test/core/host_api/storage_extension_test.cpp | 7 +- .../network/state_protocol_observer_test.cpp | 13 +- .../network/sync_protocol_observer_test.cpp | 10 +- .../network/types/block_announce_test.cpp | 3 +- .../network/types/block_attributes_test.cpp | 9 +- .../network/types/block_direction_test.cpp | 9 +- .../types/message_read_writer_test.cpp | 3 +- .../types/protobuf_block_request_test.cpp | 6 +- .../types/protobuf_block_response_test.cpp | 18 +-- .../types/protobuf_state_request_test.cpp | 6 +- .../types/protobuf_state_response_test.cpp | 5 +- test/core/network/types/uvar_adapter_test.cpp | 10 +- .../parachain/availability/recovery_test.cpp | 3 +- test/core/parachain/candidate_storage.cpp | 9 +- test/core/parachain/fragment_chain.cpp | 141 +++++++++--------- test/core/parachain/grid_tracker.cpp | 97 ++++++------ .../core/parachain/parachain_test_harness.hpp | 10 +- .../core/parachain/prospective_parachains.cpp | 16 +- test/core/parachain/pvf_test.cpp | 12 +- test/core/parachain/secure_mode.cpp | 10 +- .../core/primitives/primitives_codec_test.cpp | 71 ++++----- test/core/primitives/ss58_codec_test.cpp | 3 +- .../binaryen/block_builder_api_test.cpp | 18 ++- test/core/runtime/binaryen/metadata_test.cpp | 1 - test/core/runtime/binaryen/parachain_test.cpp | 3 +- .../tagged_transaction_queue_test.cpp | 6 +- test/core/runtime/executor_test.cpp | 83 ++++++----- test/core/runtime/instance_pool_test.cpp | 7 +- test/core/runtime/runtime_test_base.hpp | 2 - .../runtime/runtime_upgrade_tracker_test.cpp | 38 ++--- test/core/runtime/stack_limiter_test.cpp | 16 +- .../runtime/storage_code_provider_test.cpp | 11 +- .../runtime/trie_storage_provider_test.cpp | 85 +++++------ test/core/scale/big_fixed_integers_test.cpp | 7 +- .../changes_trie/changes_tracker_test.cpp | 11 +- test/core/storage/rocksdb/rocksdb_fs_test.cpp | 6 +- .../rocksdb/rocksdb_integration_test.cpp | 25 ++-- .../polkadot_trie_cursor_test.cpp | 73 ++++----- .../trie/polkadot_trie/polkadot_trie_test.cpp | 58 ++++--- .../trie_storage/ordered_trie_hash_test.cpp | 68 +++++---- .../polkadot_codec_node_decoding_test.cpp | 8 +- .../polkadot_codec_node_encoding_test.cpp | 6 +- .../trie/trie_storage/trie_batch_test.cpp | 65 ++++---- .../trie_storage_backend_test.cpp | 15 +- .../trie/trie_storage/trie_storage_test.cpp | 24 +-- .../storage/trie_pruner/trie_pruner_test.cpp | 54 ++++--- .../transaction_pool/pool_moderator_test.cpp | 1 - .../transaction_pool_test.cpp | 16 +- test/testutil/ma_generator.hpp | 5 +- test/testutil/outcome.hpp | 61 -------- 108 files changed, 937 insertions(+), 946 deletions(-) delete mode 100644 test/testutil/outcome.hpp diff --git a/core/blockchain/indexer.hpp b/core/blockchain/indexer.hpp index 4f7d195480..68af36d34a 100644 --- a/core/blockchain/indexer.hpp +++ b/core/blockchain/indexer.hpp @@ -85,7 +85,7 @@ namespace kagome::blockchain { bool inherit = false; private: - SCALE_CUSTOM_DECOMPOSING(Indexed, value, prev); + SCALE_CUSTOM_DECOMPOSITION(Indexed, value, prev); }; /** diff --git a/core/consensus/babe/impl/babe_config_repository_impl.hpp b/core/consensus/babe/impl/babe_config_repository_impl.hpp index 7e4b7bdf10..3192cd8bde 100644 --- a/core/consensus/babe/impl/babe_config_repository_impl.hpp +++ b/core/consensus/babe/impl/babe_config_repository_impl.hpp @@ -62,7 +62,10 @@ namespace kagome::consensus::babe { std::optional> next_state; private: - SCALE_CUSTOM_DECOMPOSING(BabeIndexedValue, config, state, next_state_warp); + SCALE_CUSTOM_DECOMPOSITION(BabeIndexedValue, + config, + state, + next_state_warp); }; class BabeConfigRepositoryImpl final diff --git a/core/consensus/grandpa/impl/authority_manager_impl.hpp b/core/consensus/grandpa/impl/authority_manager_impl.hpp index ed4ffd31d5..22e4af229b 100644 --- a/core/consensus/grandpa/impl/authority_manager_impl.hpp +++ b/core/consensus/grandpa/impl/authority_manager_impl.hpp @@ -48,10 +48,10 @@ namespace kagome::consensus::grandpa { std::optional> next; private: - SCALE_CUSTOM_DECOMPOSING(GrandpaIndexedValue, - next_set_id, - forced_target, - state); + SCALE_CUSTOM_DECOMPOSITION(GrandpaIndexedValue, + next_set_id, + forced_target, + state); }; class AuthorityManagerImpl final diff --git a/core/consensus/grandpa/structs.hpp b/core/consensus/grandpa/structs.hpp index a27b46108d..ff8740c4c0 100644 --- a/core/consensus/grandpa/structs.hpp +++ b/core/consensus/grandpa/structs.hpp @@ -115,7 +115,7 @@ namespace kagome::consensus::grandpa { } private: - SCALE_CUSTOM_DECOMPOSING(VoteMessage, round_number, counter, vote); + SCALE_CUSTOM_DECOMPOSITION(VoteMessage, round_number, counter, vote); }; struct TotalWeight { diff --git a/core/network/types/block_announce_handshake.hpp b/core/network/types/block_announce_handshake.hpp index fbc27a01ba..dccf13797a 100644 --- a/core/network/types/block_announce_handshake.hpp +++ b/core/network/types/block_announce_handshake.hpp @@ -28,11 +28,11 @@ namespace kagome::network { BlockHash genesis_hash; //!< Genesis block hash. private: - SCALE_CUSTOM_DECOMPOSING(BlockAnnounceHandshake, - roles, - best_block.number, - best_block.hash, - genesis_hash); + SCALE_CUSTOM_DECOMPOSITION(BlockAnnounceHandshake, + roles, + best_block.number, + best_block.hash, + genesis_hash); }; } // namespace kagome::network diff --git a/core/network/types/collator_messages_vstaging.hpp b/core/network/types/collator_messages_vstaging.hpp index 6b57b63716..9066a0d760 100644 --- a/core/network/types/collator_messages_vstaging.hpp +++ b/core/network/types/collator_messages_vstaging.hpp @@ -209,9 +209,9 @@ namespace kagome::network::vstaging { bool operator==(const StatementFilter &other) const = default; private: - SCALE_CUSTOM_DECOMPOSING(StatementFilter, - seconded_in_group, - validated_in_group); + SCALE_CUSTOM_DECOMPOSITION(StatementFilter, + seconded_in_group, + validated_in_group); public: void mask_seconded(const scale::BitVec &mask) { diff --git a/core/network/types/roles.hpp b/core/network/types/roles.hpp index 04bd6240d4..b2f777a7c4 100644 --- a/core/network/types/roles.hpp +++ b/core/network/types/roles.hpp @@ -35,7 +35,7 @@ namespace kagome::network { Roles(uint8_t v) : value(v) {} private: - SCALE_CUSTOM_DECOMPOSING(Roles, value); + SCALE_CUSTOM_DECOMPOSITION(Roles, value); public: // https://github.com/paritytech/polkadot-sdk/blob/6c3219ebe9231a0305f53c7b33cb558d46058062/substrate/client/network/common/src/role.rs#L101 diff --git a/core/parachain/approval/approval.hpp b/core/parachain/approval/approval.hpp index 6acba20954..9b5467a2fa 100644 --- a/core/parachain/approval/approval.hpp +++ b/core/parachain/approval/approval.hpp @@ -88,7 +88,7 @@ namespace kagome::parachain::approval { bool operator==(const AssignmentCertV2 &other) const = default; private: - SCALE_CUSTOM_DECOMPOSING(AssignmentCertV2, kind, vrf) + SCALE_CUSTOM_DECOMPOSITION(AssignmentCertV2, kind, vrf) }; /// An assignment criterion which refers to the candidate under which the diff --git a/core/primitives/apply_result.hpp b/core/primitives/apply_result.hpp index 21f3b1d965..06c5e42cb8 100644 --- a/core/primitives/apply_result.hpp +++ b/core/primitives/apply_result.hpp @@ -40,7 +40,7 @@ namespace kagome::primitives { /// Optional error message. std::optional message; // not currently used in rust impl, thus not scale encoded - SCALE_CUSTOM_DECOMPOSING(Module, index, error); + SCALE_CUSTOM_DECOMPOSITION(Module, index, error); }; /// At least one consumer is remaining so the account cannot be destroyed. diff --git a/core/primitives/common.hpp b/core/primitives/common.hpp index e692b1e635..f184b73833 100644 --- a/core/primitives/common.hpp +++ b/core/primitives/common.hpp @@ -41,7 +41,7 @@ namespace kagome::primitives { auto operator<=>(const BlockInfoT &o) const = default; private: - SCALE_CUSTOM_DECOMPOSING(BlockInfoT, hash, number); + SCALE_CUSTOM_DECOMPOSITION(BlockInfoT, hash, number); }; } // namespace detail diff --git a/core/runtime/heap_alloc_strategy.hpp b/core/runtime/heap_alloc_strategy.hpp index 4828bddb33..9c70ddd9aa 100644 --- a/core/runtime/heap_alloc_strategy.hpp +++ b/core/runtime/heap_alloc_strategy.hpp @@ -29,7 +29,7 @@ namespace kagome { std::optional maximum_pages; bool operator==(const HeapAllocStrategyDynamic &other) const = default; - SCALE_CUSTOM_DECOMPOSING(HeapAllocStrategyDynamic, maximum_pages); + SCALE_CUSTOM_DECOMPOSITION(HeapAllocStrategyDynamic, maximum_pages); }; /** * Allocate a static number of heap pages. @@ -46,7 +46,7 @@ namespace kagome { uint32_t extra_pages; bool operator==(const HeapAllocStrategyStatic &other) const = default; - SCALE_CUSTOM_DECOMPOSING(HeapAllocStrategyStatic, extra_pages); + SCALE_CUSTOM_DECOMPOSITION(HeapAllocStrategyStatic, extra_pages); }; /** * Defines the heap pages allocation strategy the wasm runtime should use. diff --git a/core/scale/encoder/primitives.hpp b/core/scale/encoder/primitives.hpp index b7648fc686..444af64172 100644 --- a/core/scale/encoder/primitives.hpp +++ b/core/scale/encoder/primitives.hpp @@ -26,6 +26,9 @@ #include "utils/struct_to_tuple.hpp" namespace kagome::scale { + + using ::scale::detail::decompose_and_apply; + constexpr void putByte(const Invocable auto &func, const uint8_t *const val, size_t count); @@ -91,6 +94,11 @@ namespace kagome::scale { void encode(const Invocable auto &func, const ::scale::CompactInteger &value); + template + requires ::scale::CompactCompatible> + void encode(const Invocable auto &func, + const ::scale::CompactReflection &value); + void encode(const Invocable auto &func, const ::scale::BitVec &value); void encode(const Invocable auto &func, const std::optional &value); @@ -120,7 +128,6 @@ namespace kagome::scale { const auto val = math::toLE(v); putByte(func, (uint8_t *)&val, size); } else { - // kagome::scale::encode(func, utils::to_tuple_refs(v)); if constexpr (requires { decompose_and_apply( v, [&](const auto &...tuple_elements) { @@ -131,6 +138,8 @@ namespace kagome::scale { decompose_and_apply(v, [&](const auto &...tuple_elements) { kagome::scale::encode(func, std::tie(tuple_elements...)); }); + } else { + kagome::scale::encode(func, utils::to_tuple_refs(v)); } } } @@ -365,6 +374,13 @@ namespace kagome::scale { putByte(func, result, bigIntLength + 1ull); } + template + requires ::scale::CompactCompatible> + void encode(const Invocable auto &func, + const ::scale::CompactReflection &value) { + encodeCompact(func, value.ref); + } + template < typename It, typename = std::enable_if_t< diff --git a/core/scale/kagome_scale.hpp b/core/scale/kagome_scale.hpp index b598fa12f3..6bd6214730 100644 --- a/core/scale/kagome_scale.hpp +++ b/core/scale/kagome_scale.hpp @@ -180,11 +180,7 @@ namespace kagome::scale { template constexpr void encode(const Invocable auto &func, const Tagged &c) { - if constexpr (std::is_scalar_v) { - kagome::scale::encode(func, c.template Wrapper::value); - } else { - kagome::scale::encode(func, static_cast(c)); - } + kagome::scale::encode(func, untagged(c)); } template diff --git a/test/core/api/service/author/author_api_test.cpp b/test/core/api/service/author/author_api_test.cpp index 76b1bfa286..93f3a6de05 100644 --- a/test/core/api/service/author/author_api_test.cpp +++ b/test/core/api/service/author/author_api_test.cpp @@ -8,9 +8,12 @@ #include #include -#include + #include +#include +#include + #include "common/blob.hpp" #include "common/hexutil.hpp" #include "common/optref.hpp" @@ -32,7 +35,6 @@ #include "subscription/subscription_engine.hpp" #include "testutil/lazy.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/outcome/dummy_error.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/primitives/mp_utils.hpp" @@ -146,7 +148,7 @@ struct AuthorApiTest : public ::testing::Test { store = std::make_shared(); key_store = KeyFileStorage::createAt("test_chain_43/keystore").value(); key_pair = generateSr25519Keypair(0); - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( key_store->saveKeyPair(KeyTypes::BABE, std::span(key_pair.public_key).first<32>(), std::array{1})); diff --git a/test/core/api/service/chain/base_request_test.cpp b/test/core/api/service/chain/base_request_test.cpp index 44fc486983..fdf353a029 100644 --- a/test/core/api/service/chain/base_request_test.cpp +++ b/test/core/api/service/chain/base_request_test.cpp @@ -6,9 +6,10 @@ #include +#include + #include "api/service/base_request.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" using kagome::common::Buffer; struct BaseRequestTest : public ::testing::Test { @@ -39,7 +40,7 @@ TEST_F(BaseRequestTest, Params_Int) { params.emplace_back(test_val); TestRequestInt32 tr; - ASSERT_OUTCOME_SUCCESS_TRY(tr.init(params)); + ASSERT_OUTCOME_SUCCESS(tr.init(params)); ASSERT_EQ(tr.getParam<0>(), test_val); } @@ -56,7 +57,7 @@ TEST_F(BaseRequestTest, Params_Str) { params.emplace_back(test_val); TestRequestStr tr; - ASSERT_OUTCOME_SUCCESS_TRY(tr.init(params)); + ASSERT_OUTCOME_SUCCESS(tr.init(params)); ASSERT_EQ(tr.getParam<0>(), test_val); } @@ -73,6 +74,6 @@ TEST_F(BaseRequestTest, Params_Invalid) { params.emplace_back(test_val); TestRequestInt32 tr; - auto init = [&] { ASSERT_OUTCOME_SUCCESS_TRY(tr.init(params)); }; + auto init = [&] { ASSERT_OUTCOME_SUCCESS(tr.init(params)); }; EXPECT_THROW(init(), jsonrpc::InvalidParametersFault); } diff --git a/test/core/api/service/chain/chain_api_test.cpp b/test/core/api/service/chain/chain_api_test.cpp index c6db0ef455..f32a322ef0 100644 --- a/test/core/api/service/chain/chain_api_test.cpp +++ b/test/core/api/service/chain/chain_api_test.cpp @@ -5,8 +5,11 @@ */ #include + #include +#include + #include "api/service/chain/impl/chain_api_impl.hpp" #include "api/service/chain/requests/subscribe_finalized_heads.hpp" #include "mock/core/api/service/api_service_mock.hpp" @@ -19,7 +22,6 @@ #include "primitives/extrinsic.hpp" #include "testutil/lazy.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" using kagome::api::ApiService; using kagome::api::ApiServiceMock; @@ -92,7 +94,7 @@ TEST_F(ChainApiTest, GetBlockHashNoParam) { EXPECT_CALL(*block_tree, getLastFinalized()) .WillOnce(Return(BlockInfo(42, "D"_hash256))); - EXPECT_OUTCOME_TRUE(r, api->getBlockHash()); + ASSERT_OUTCOME_SUCCESS(r, api->getBlockHash()); ASSERT_EQ(r, "D"_hash256); } @@ -105,7 +107,7 @@ TEST_F(ChainApiTest, GetBlockHashByNumber) { // kagome::primitives::BlockId did = "D"_hash256; EXPECT_CALL(*block_tree, getHashByNumber(42)).WillOnce(Return("CDE"_hash256)); - EXPECT_OUTCOME_TRUE(r, api->getBlockHash(42)); + ASSERT_OUTCOME_SUCCESS(r, api->getBlockHash(42)); ASSERT_EQ(r, "CDE"_hash256); } @@ -117,7 +119,7 @@ TEST_F(ChainApiTest, GetBlockHashByNumber) { TEST_F(ChainApiTest, GetBlockHashByHexNumber) { EXPECT_CALL(*block_tree, getHashByNumber(42)).WillOnce(Return("CDE"_hash256)); - EXPECT_OUTCOME_TRUE(r, api->getBlockHash("0x2a")); + ASSERT_OUTCOME_SUCCESS(r, api->getBlockHash("0x2a")); ASSERT_EQ(r, "CDE"_hash256); } @@ -132,7 +134,7 @@ TEST_F(ChainApiTest, GetBlockHashArray) { EXPECT_CALL(*block_tree, getHashByNumber(200)).WillOnce(Return(hash3)); std::vector> request_data = { 50, "0x64", 200}; - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( r, api->getBlockHash(std::vector>( {50, "0x64", 200}))); @@ -148,7 +150,7 @@ TEST_F(ChainApiTest, GetHeader) { BlockHash a = hash1; EXPECT_CALL(*block_tree, getBlockHeader(a)).WillOnce(Return(*data.header)); - EXPECT_OUTCOME_TRUE(r, api->getHeader(std::string("0x") + hash1.toHex())); + ASSERT_OUTCOME_SUCCESS(r, api->getHeader(std::string("0x") + hash1.toHex())); ASSERT_EQ(r, *data.header); } @@ -164,7 +166,7 @@ TEST_F(ChainApiTest, GetHeaderLats) { EXPECT_CALL(*block_tree, getBlockHeader(a)).WillOnce(Return(*data.header)); - EXPECT_OUTCOME_TRUE(r, api->getHeader()); + ASSERT_OUTCOME_SUCCESS(r, api->getHeader()); ASSERT_EQ(r, *data.header); } @@ -177,7 +179,7 @@ TEST_F(ChainApiTest, GetBlock) { BlockHash a = hash1; EXPECT_CALL(*block_storage, getBlockData(a)).WillOnce(Return(data)); - EXPECT_OUTCOME_TRUE(r, api->getBlock(std::string("0x") + hash1.toHex())); + ASSERT_OUTCOME_SUCCESS(r, api->getBlock(std::string("0x") + hash1.toHex())); ASSERT_EQ(r, data); } @@ -193,7 +195,7 @@ TEST_F(ChainApiTest, GetLastBlock) { EXPECT_CALL(*block_storage, getBlockData(a)).WillOnce(Return(data)); - EXPECT_OUTCOME_TRUE(r, api->getBlock()); + ASSERT_OUTCOME_SUCCESS(r, api->getBlock()); ASSERT_EQ(r, data); } @@ -212,7 +214,7 @@ TEST(StateApiTest, SubscribeStorage) { jsonrpc::Request::Parameters params; EXPECT_OUTCOME_SUCCESS(r, sub->init(params)); - EXPECT_OUTCOME_TRUE(result, sub->execute()); + ASSERT_OUTCOME_SUCCESS(result, sub->execute()); ASSERT_EQ(result, 55); } diff --git a/test/core/api/service/child_state/child_state_api_test.cpp b/test/core/api/service/child_state/child_state_api_test.cpp index a6d598b3d4..272f6f0118 100644 --- a/test/core/api/service/child_state/child_state_api_test.cpp +++ b/test/core/api/service/child_state/child_state_api_test.cpp @@ -6,8 +6,9 @@ #include +#include + #include "api/service/child_state/impl/child_state_api_impl.hpp" -#include "core/storage/trie/polkadot_trie_cursor_dummy.hpp" #include "mock/core/api/service/child_state/child_state_api_mock.hpp" #include "mock/core/blockchain/block_tree_mock.hpp" #include "mock/core/runtime/core_mock.hpp" @@ -16,9 +17,7 @@ #include "mock/core/storage/trie/trie_batches_mock.hpp" #include "mock/core/storage/trie/trie_storage_mock.hpp" #include "primitives/block_header.hpp" -#include "runtime/runtime_context.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" using kagome::api::ChildStateApiMock; using kagome::blockchain::BlockTreeMock; @@ -125,11 +124,11 @@ namespace kagome::api { return batch; })); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( r1, api_->getStorage( "c"_buf, "d"_buf, std::optional{"B"_hash256})); - ASSERT_EQ(r1.value(), "4"_buf); + ASSERT_EQ(r1, "4"_buf); } /** diff --git a/test/core/api/service/payment/payment_api_test.cpp b/test/core/api/service/payment/payment_api_test.cpp index 14ddffb217..7bf6493564 100644 --- a/test/core/api/service/payment/payment_api_test.cpp +++ b/test/core/api/service/payment/payment_api_test.cpp @@ -8,10 +8,11 @@ #include +#include + #include "mock/core/blockchain/block_tree_mock.hpp" #include "mock/core/runtime/transaction_payment_api_mock.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" using kagome::api::PaymentApi; using kagome::api::PaymentApiImpl; diff --git a/test/core/api/service/state/state_api_test.cpp b/test/core/api/service/state/state_api_test.cpp index b4866e3ac7..089ab30b50 100644 --- a/test/core/api/service/state/state_api_test.cpp +++ b/test/core/api/service/state/state_api_test.cpp @@ -5,6 +5,8 @@ */ #include + +#include #include #include "api/service/state/impl/state_api_impl.hpp" @@ -21,10 +23,8 @@ #include "mock/core/storage/trie/trie_storage_mock.hpp" #include "primitives/block_header.hpp" #include "runtime/executor.hpp" -#include "runtime/runtime_context.hpp" #include "testutil/lazy.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" using kagome::api::ApiServiceMock; using kagome::api::StateApiMock; @@ -104,14 +104,14 @@ namespace kagome::api { })); auto key = "a"_buf; - EXPECT_OUTCOME_TRUE(r, api_->getStorage(key.view())) - ASSERT_EQ(r.value(), "1"_buf); + ASSERT_OUTCOME_SUCCESS(r, api_->getStorage(key.view())); + ASSERT_EQ(r, "1"_buf); EXPECT_CALL(*block_tree_, getBlockHeader("B"_hash256)) .WillOnce(testing::Return(makeBlockHeaderOfStateRoot("ABC"_hash256))); - EXPECT_OUTCOME_TRUE(r1, api_->getStorageAt(key.view(), "B"_hash256)); - ASSERT_EQ(r1.value(), "1"_buf); + ASSERT_OUTCOME_SUCCESS(r1, api_->getStorageAt(key.view(), "B"_hash256)); + ASSERT_EQ(r1, "1"_buf); } class GetKeysPagedTest : public ::testing::Test { @@ -178,7 +178,7 @@ namespace kagome::api { * @then expected amount of keys from beginning of cursor are returned */ TEST_F(GetKeysPagedTest, EmptyParamsTest) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( val, api_->getKeysPaged(std::nullopt, 2, std::nullopt, std::nullopt)); ASSERT_THAT(val, ElementsAre("0102"_hex2buf, "0103"_hex2buf)); } @@ -189,7 +189,7 @@ namespace kagome::api { * @then expected amount of keys with provided prefix are returned */ TEST_F(GetKeysPagedTest, NonEmptyPrefixTest) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( val, api_->getKeysPaged("0607"_hex2buf, 3, std::nullopt, std::nullopt)); ASSERT_THAT( val, ElementsAre("0607"_hex2buf, "060708"_hex2buf, "06070801"_hex2buf)); @@ -201,7 +201,7 @@ namespace kagome::api { * @then exepected amount of keys after provided prev_key are returned */ TEST_F(GetKeysPagedTest, NonEmptyPrevKeyTest) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( val, api_->getKeysPaged("06"_hex2buf, 3, "0607"_hex2buf, std::nullopt)); ASSERT_THAT( val, @@ -216,7 +216,7 @@ namespace kagome::api { * returned */ TEST_F(GetKeysPagedTest, PrefixBiggerThanPrevkey) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( val, api_->getKeysPaged("060708"_hex2buf, 5, "06"_hex2buf, std::nullopt)); ASSERT_THAT(val, @@ -245,7 +245,7 @@ namespace kagome::api { .WillOnce(testing::Return(test_version)); { - EXPECT_OUTCOME_TRUE(result, api_->getRuntimeVersion(std::nullopt)); + ASSERT_OUTCOME_SUCCESS(result, api_->getRuntimeVersion(std::nullopt)); ASSERT_EQ(result, test_version); } @@ -254,7 +254,7 @@ namespace kagome::api { .WillOnce(testing::Return(test_version)); { - EXPECT_OUTCOME_TRUE(result, api_->getRuntimeVersion("T"_hash256)); + ASSERT_OUTCOME_SUCCESS(result, api_->getRuntimeVersion("T"_hash256)); ASSERT_EQ(result, test_version); } } @@ -283,7 +283,7 @@ namespace kagome::api { std::string("0x") + keys[1].toHex()}); EXPECT_OUTCOME_SUCCESS(r, subscribe_storage->init(params)); - EXPECT_OUTCOME_TRUE(result, subscribe_storage->execute()); + ASSERT_OUTCOME_SUCCESS(result, subscribe_storage->execute()); ASSERT_EQ(result, 55); } @@ -356,7 +356,7 @@ namespace kagome::api { EXPECT_CALL(*state_api, getMetadata()).WillOnce(testing::Return(data)); EXPECT_OUTCOME_SUCCESS(r, get_metadata->init(params)); - EXPECT_OUTCOME_TRUE(result, get_metadata->execute()); + ASSERT_OUTCOME_SUCCESS(result, get_metadata->execute()); ASSERT_EQ(result, data); } @@ -401,7 +401,7 @@ namespace kagome::api { })); } // WHEN - EXPECT_OUTCOME_TRUE(changes, api_->queryStorage(keys, from, to)) + ASSERT_OUTCOME_SUCCESS(changes, api_->queryStorage(keys, from, to)); // THEN auto current_block = block_range.begin(); @@ -425,9 +425,9 @@ namespace kagome::api { EXPECT_CALL(*block_tree_, getNumberByHash(from)).WillOnce(Return(42)); EXPECT_CALL(*block_tree_, getNumberByHash(to)) .WillOnce(Return(42 + StateApiImpl::kMaxBlockRange + 1)); - EXPECT_OUTCOME_FALSE( - error, api_->queryStorage(std::vector({"some_key"_buf}), from, to)); - ASSERT_EQ(error, StateApiImpl::Error::MAX_BLOCK_RANGE_EXCEEDED); + ASSERT_OUTCOME_ERROR( + api_->queryStorage(std::vector({"some_key"_buf}), from, to), + StateApiImpl::Error::MAX_BLOCK_RANGE_EXCEEDED); } /** @@ -438,8 +438,8 @@ namespace kagome::api { TEST_F(StateApiTest, HitsKeyRangeLimits) { std::vector keys(StateApiImpl::kMaxKeySetSize + 1); primitives::BlockHash from{"from"_hash256}, to{"to"_hash256}; - EXPECT_OUTCOME_FALSE(error, api_->queryStorage(keys, from, to)); - ASSERT_EQ(error, StateApiImpl::Error::MAX_KEY_SET_SIZE_EXCEEDED); + ASSERT_OUTCOME_ERROR(api_->queryStorage(keys, from, to), + StateApiImpl::Error::MAX_KEY_SET_SIZE_EXCEEDED); } /** @@ -470,7 +470,7 @@ namespace kagome::api { })); // WHEN - EXPECT_OUTCOME_TRUE(changes, api_->queryStorageAt(keys, at)) + ASSERT_OUTCOME_SUCCESS(changes, api_->queryStorageAt(keys, at)); // THEN ASSERT_EQ(changes.size(), 1); diff --git a/test/core/api/service/state/state_jrpc_processor_test.cpp b/test/core/api/service/state/state_jrpc_processor_test.cpp index ca5b9c9b79..c9b9537f5c 100644 --- a/test/core/api/service/state/state_jrpc_processor_test.cpp +++ b/test/core/api/service/state/state_jrpc_processor_test.cpp @@ -10,13 +10,14 @@ #include #include + #include +#include #include "api/service/state/requests/query_storage.hpp" // for makeValue #include "mock/core/api/jrpc/jrpc_server_mock.hpp" #include "mock/core/api/service/state/state_api_mock.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" using kagome::api::JRpcServer; using kagome::api::JRpcServerMock; @@ -179,7 +180,7 @@ TEST_F(StateJrpcProcessorTest, ProcessRequest) { jsonrpc::Request::Parameters params{"0x01234567"}; auto result_hex = execute(CallType::kCallType_GetStorage, params).AsString(); - EXPECT_OUTCOME_TRUE(result_vec, kagome::common::unhexWith0x(result_hex)); + ASSERT_OUTCOME_SUCCESS(result_vec, kagome::common::unhexWith0x(result_hex)); ASSERT_EQ(expected_result.asVector(), result_vec); } @@ -200,7 +201,7 @@ TEST_F(StateJrpcProcessorTest, ProcessAnotherRequest) { jsonrpc::Request::Parameters params{"0x01234567", "0x" + ("010203"_hash256).toHex()}; auto result_hex = execute(CallType::kCallType_GetStorage, params).AsString(); - EXPECT_OUTCOME_TRUE(result_vec, kagome::common::unhexWith0x(result_hex)); + ASSERT_OUTCOME_SUCCESS(result_vec, kagome::common::unhexWith0x(result_hex)); ASSERT_EQ(expected_result.asVector(), result_vec); } diff --git a/test/core/api/service/system/system_api_test.cpp b/test/core/api/service/system/system_api_test.cpp index 999978f6af..36c40b6c9b 100644 --- a/test/core/api/service/system/system_api_test.cpp +++ b/test/core/api/service/system/system_api_test.cpp @@ -8,6 +8,8 @@ #include +#include + #include "mock/core/application/chain_spec_mock.hpp" #include "mock/core/blockchain/block_tree_mock.hpp" #include "mock/core/consensus/timeline/timeline_mock.hpp" @@ -18,7 +20,6 @@ #include "scale/kagome_scale.hpp" #include "scale/scale.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/scale_test_comparator.hpp" using kagome::api::SystemApi; @@ -97,7 +98,7 @@ TEST_F(SystemApiTest, GetNonceNoPendingTxs) { .WillOnce(Return(kagome::common::Hash512{{'\035', '!'}})); EXPECT_CALL(*transaction_pool_mock_, getReadyTransactions()); - EXPECT_OUTCOME_TRUE(nonce, system_api_->getNonceFor(kSs58Account)) + ASSERT_OUTCOME_SUCCESS(nonce, system_api_->getNonceFor(kSs58Account)); ASSERT_EQ(nonce, kInitialNonce); } @@ -125,9 +126,9 @@ TEST_F(SystemApiTest, GetNonceWithPendingTxs) { std::vector>> ready_txs; for (size_t i = 0; i < kReadyTxNum; i++) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( enc_nonce, - testutil::scaleEncodeAndCompareWithRef(kAccountId, kInitialNonce + i)) + testutil::scaleEncodeAndCompareWithRef(kAccountId, kInitialNonce + i)); encoded_nonces[i] = std::move(enc_nonce); ready_txs.emplace_back( std::make_pair(Hash256{{static_cast(i)}}, @@ -138,6 +139,6 @@ TEST_F(SystemApiTest, GetNonceWithPendingTxs) { EXPECT_CALL(*transaction_pool_mock_, getReadyTransactions()) .WillOnce(Return(ready_txs)); - EXPECT_OUTCOME_TRUE(nonce, system_api_->getNonceFor(kSs58Account)); + ASSERT_OUTCOME_SUCCESS(nonce, system_api_->getNonceFor(kSs58Account)); ASSERT_EQ(nonce, kInitialNonce + kReadyTxNum); } diff --git a/test/core/api/transport/http_listener_test.cpp b/test/core/api/transport/http_listener_test.cpp index 01ff4ff7a0..261ecc3671 100644 --- a/test/core/api/transport/http_listener_test.cpp +++ b/test/core/api/transport/http_listener_test.cpp @@ -61,10 +61,10 @@ TEST_F(HttpListenerTest, EchoSuccess) { post(*local_context, [&] { auto client = std::make_shared(*local_context); - ASSERT_OUTCOME_SUCCESS_TRY(client->connect(endpoint)); + ASSERT_OUTCOME_SUCCESS(client->connect(endpoint)); client->query(request, [&](outcome::result res) { - ASSERT_OUTCOME_SUCCESS_TRY(res); + ASSERT_OUTCOME_SUCCESS(res); EXPECT_EQ(res.value(), response); client->disconnect(); time_is_out = false; diff --git a/test/core/api/transport/listener_test.hpp b/test/core/api/transport/listener_test.hpp index 8464fad37f..dd05510ea8 100644 --- a/test/core/api/transport/listener_test.hpp +++ b/test/core/api/transport/listener_test.hpp @@ -10,6 +10,8 @@ #include +#include + #include "api/jrpc/jrpc_processor.hpp" #include "api/jrpc/jrpc_server.hpp" #include "api/service/impl/api_service_impl.hpp" @@ -25,12 +27,9 @@ #include "mock/core/runtime/core_mock.hpp" #include "mock/core/storage/trie/trie_storage_mock.hpp" #include "primitives/event_types.hpp" -#include "runtime/runtime_context.hpp" #include "subscription/extrinsic_event_key_repository.hpp" #include "subscription/subscriber.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" -#include "transaction_pool/transaction_pool_error.hpp" #include "utils/watchdog.hpp" using namespace std::chrono_literals; diff --git a/test/core/api/transport/ws_listener_test.cpp b/test/core/api/transport/ws_listener_test.cpp index 3b6a5b9f30..607c512bf8 100644 --- a/test/core/api/transport/ws_listener_test.cpp +++ b/test/core/api/transport/ws_listener_test.cpp @@ -62,10 +62,10 @@ TEST_F(WsListenerTest, EchoSuccess) { post(*local_context, [&] { auto client = std::make_shared(*local_context); - ASSERT_OUTCOME_SUCCESS_TRY(client->connect(endpoint)); + ASSERT_OUTCOME_SUCCESS(client->connect(endpoint)); client->query(request, [&](outcome::result res) { - ASSERT_OUTCOME_SUCCESS_TRY(res); + ASSERT_OUTCOME_SUCCESS(res); EXPECT_EQ(res.value(), response); client->disconnect(); time_is_out = false; diff --git a/test/core/application/chain_spec_test.cpp b/test/core/application/chain_spec_test.cpp index dad7c44739..5fc74f0961 100644 --- a/test/core/application/chain_spec_test.cpp +++ b/test/core/application/chain_spec_test.cpp @@ -6,9 +6,10 @@ #include +#include + #include "application/impl/chain_spec_impl.hpp" #include "filesystem/common.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::application::ChainSpecImpl; @@ -54,7 +55,7 @@ class ConfigurationStorageTest : public ::testing::Test { TEST_F(ConfigurationStorageTest, MatchesConfig) { // given provided in set up // when - EXPECT_OUTCOME_TRUE(config_storage, ChainSpecImpl::loadFrom(path_)); + ASSERT_OUTCOME_SUCCESS(config_storage, ChainSpecImpl::loadFrom(path_)); // then ASSERT_EQ(config_storage->getGenesisTopSection(), expected_genesis_config_); diff --git a/test/core/authorship/block_builder_factory_test.cpp b/test/core/authorship/block_builder_factory_test.cpp index 786caf1d01..1ea5c4544c 100644 --- a/test/core/authorship/block_builder_factory_test.cpp +++ b/test/core/authorship/block_builder_factory_test.cpp @@ -10,8 +10,6 @@ #include "mock/core/blockchain/block_header_repository_mock.hpp" #include "mock/core/runtime/block_builder_api_mock.hpp" #include "mock/core/runtime/core_mock.hpp" -#include "runtime/runtime_context.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using ::testing::_; diff --git a/test/core/authorship/block_builder_test.cpp b/test/core/authorship/block_builder_test.cpp index 7999e78a98..1e4d90e72f 100644 --- a/test/core/authorship/block_builder_test.cpp +++ b/test/core/authorship/block_builder_test.cpp @@ -6,14 +6,16 @@ #include "authorship/impl/block_builder_impl.hpp" +#include #include + #include -#include "gmock/gmock.h" +#include + #include "mock/core/runtime/block_builder_api_mock.hpp" #include "mock/core/runtime/module_instance_mock.hpp" #include "runtime/runtime_context.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using ::testing::_; @@ -90,7 +92,7 @@ TEST_F(BlockBuilderTest, PushWhenApplyFails) { // when auto res = block_builder_->pushExtrinsic(xt); - EXPECT_OUTCOME_TRUE(block, block_builder_->bake()); + ASSERT_OUTCOME_SUCCESS(block, block_builder_->bake()); // then ASSERT_FALSE(res); @@ -115,7 +117,7 @@ TEST_F(BlockBuilderTest, PushWhenApplySucceedsWithTrue) { auto res = block_builder_->pushExtrinsic(xt); ASSERT_TRUE(res); - EXPECT_OUTCOME_TRUE(block, block_builder_->bake()); + ASSERT_OUTCOME_SUCCESS(block, block_builder_->bake()); // then ASSERT_EQ(block.header, expected_header_); @@ -141,7 +143,7 @@ TEST_F(BlockBuilderTest, PushWhenApplySucceedsWithFalse) { // then ASSERT_FALSE(res); - EXPECT_OUTCOME_TRUE(block, block_builder_->bake()); + ASSERT_OUTCOME_SUCCESS(block, block_builder_->bake()); ASSERT_EQ(block.header, expected_header_); ASSERT_THAT(block.body, IsEmpty()); } diff --git a/test/core/authorship/proposer_test.cpp b/test/core/authorship/proposer_test.cpp index eb2313f408..b1f261d497 100644 --- a/test/core/authorship/proposer_test.cpp +++ b/test/core/authorship/proposer_test.cpp @@ -8,6 +8,8 @@ #include +#include + #include "authorship/impl/block_builder_error.hpp" #include "mock/core/authorship/block_builder_factory_mock.hpp" #include "mock/core/authorship/block_builder_mock.hpp" @@ -17,7 +19,6 @@ #include "primitives/event_types.hpp" #include "subscription/extrinsic_event_key_repository.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" #include "transaction_pool/transaction_pool_error.hpp" diff --git a/test/core/blockchain/block_storage_test.cpp b/test/core/blockchain/block_storage_test.cpp index 87ad0ae0ce..3d737dd632 100644 --- a/test/core/blockchain/block_storage_test.cpp +++ b/test/core/blockchain/block_storage_test.cpp @@ -8,6 +8,8 @@ #include +#include + #include "blockchain/block_storage_error.hpp" #include "mock/core/crypto/hasher_mock.hpp" #include "mock/core/storage/generic_storage_mock.hpp" @@ -16,7 +18,6 @@ #include "scale/scale.hpp" #include "storage/database_error.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::blockchain::BlockStorageError; @@ -84,11 +85,11 @@ class BlockStorageTest : public testing::Test { ON_CALL(*hasher, blake2b_256(encoded_header.view())) .WillByDefault(Return(genesis_block_hash)); - EXPECT_OUTCOME_TRUE( + EXPECT_OUTCOME_SUCCESS( new_block_storage, BlockStorageImpl::create(root_hash, spaced_storage, hasher)); - return new_block_storage; + return new_block_storage.value(); } }; @@ -118,7 +119,7 @@ TEST_F(BlockStorageTest, CreateWithEmptyStorage) { EXPECT_CALL(*empty_storage, put(_, _)) .WillRepeatedly(Return(outcome::success())); - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( BlockStorageImpl::create(root_hash, spaced_storage, hasher)); } @@ -137,7 +138,7 @@ TEST_F(BlockStorageTest, CreateWithExistingGenesis) { // trying to get header of block number 0 (genesis block) .WillOnce(Return(Buffer{genesis_block_hash})); - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( BlockStorageImpl::create(root_hash, spaced_storage, hasher)); } @@ -170,7 +171,7 @@ TEST_F(BlockStorageTest, PutBlock) { block.header.number = 1; block.header.parent_hash = genesis_block_hash; - ASSERT_OUTCOME_SUCCESS_TRY(block_storage->putBlock(block)); + ASSERT_OUTCOME_SUCCESS(block_storage->putBlock(block)); } /* @@ -251,10 +252,10 @@ TEST_F(BlockStorageTest, Remove) { EXPECT_CALL(*(spaces[Space::kJustification]), remove(hash)) .WillOnce(Return(outcome::success())); - ASSERT_OUTCOME_SUCCESS_TRY(block_storage->removeBlock(genesis_block_hash)); + ASSERT_OUTCOME_SUCCESS(block_storage->removeBlock(genesis_block_hash)); EXPECT_CALL(*(spaces[Space::kHeader]), tryGetMock(hash)) .WillOnce(Return(std::nullopt)); - ASSERT_OUTCOME_SUCCESS_TRY(block_storage->removeBlock(genesis_block_hash)); + ASSERT_OUTCOME_SUCCESS(block_storage->removeBlock(genesis_block_hash)); } diff --git a/test/core/blockchain/block_tree_test.cpp b/test/core/blockchain/block_tree_test.cpp index befb57539f..40b7fc167f 100644 --- a/test/core/blockchain/block_tree_test.cpp +++ b/test/core/blockchain/block_tree_test.cpp @@ -3,14 +3,18 @@ * All Rights Reserved * SPDX-License-Identifier: Apache-2.0 */ + +#include "blockchain/impl/block_tree_impl.hpp" + #include #include -#include "blockchain/impl/block_tree_impl.hpp" +#include #include "blockchain/block_tree_error.hpp" #include "blockchain/impl/cached_tree.hpp" #include "common/main_thread_pool.hpp" +#include "consensus/babe/types/babe_block_header.hpp" #include "consensus/babe/types/seal.hpp" #include "crypto/hasher/hasher_impl.hpp" #include "mock/core/application/app_configuration_mock.hpp" @@ -23,7 +27,6 @@ #include "network/impl/extrinsic_observer_impl.hpp" #include "scale/scale.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using namespace kagome; @@ -383,7 +386,7 @@ TEST_F(BlockTreeTest, GetBody) { // THEN ASSERT_OUTCOME_SUCCESS(body, - block_tree_->getBlockBody(kFinalizedBlockInfo.hash)) + block_tree_->getBlockBody(kFinalizedBlockInfo.hash)); ASSERT_EQ(body, finalized_block_body_); } @@ -476,7 +479,7 @@ TEST_F(BlockTreeTest, Finalize) { .WillOnce(Return(outcome::success(false))); // WHEN - EXPECT_OUTCOME_TRUE_1(block_tree_->finalize(hash, justification)); + ASSERT_OUTCOME_SUCCESS(block_tree_->finalize(hash, justification)); // THEN ASSERT_EQ(block_tree_->getLastFinalized().hash, hash); @@ -822,7 +825,7 @@ TEST_F(BlockTreeTest, Reorganize) { shouldStoreFor(finalized_block_header_, _)) .WillOnce(Return(outcome::success(false))); - ASSERT_OUTCOME_SUCCESS_TRY(block_tree_->finalize(C2_hash, {})); + ASSERT_OUTCOME_SUCCESS(block_tree_->finalize(C2_hash, {})); // 42 43 44 45 46 47 // @@ -850,7 +853,7 @@ TEST_F(BlockTreeTest, CleanupObsoleteJustificationOnFinalized) { // remove old justification EXPECT_CALL(*storage_, removeJustification(kFinalizedBlockInfo.hash)) .WillOnce(Return(outcome::success())); - EXPECT_OUTCOME_TRUE_1(block_tree_->finalize(b56, new_justification)); + ASSERT_OUTCOME_SUCCESS(block_tree_->finalize(b56, new_justification)); } TEST_F(BlockTreeTest, KeepLastFinalizedJustificationIfItShouldBeStored) { @@ -868,7 +871,7 @@ TEST_F(BlockTreeTest, KeepLastFinalizedJustificationIfItShouldBeStored) { // store new justification EXPECT_CALL(*storage_, putJustification(new_justification, b56)) .WillOnce(Return(outcome::success())); - EXPECT_OUTCOME_TRUE_1(block_tree_->finalize(b56, new_justification)); + ASSERT_OUTCOME_SUCCESS(block_tree_->finalize(b56, new_justification)); } /** @@ -943,7 +946,7 @@ TEST_F(BlockTreeTest, GetBestBlock) { // --------------------------------------------------------------------------- - ASSERT_OUTCOME_SUCCESS_TRY(block_tree_->markAsRevertedBlocks({E3_hash})); + ASSERT_OUTCOME_SUCCESS(block_tree_->markAsRevertedBlocks({E3_hash})); // 42 43 44 45 46 47 48 49 50 // diff --git a/test/core/common/buffer_view_test.cpp b/test/core/common/buffer_view_test.cpp index ce45566109..e17f7bbbf5 100644 --- a/test/core/common/buffer_view_test.cpp +++ b/test/core/common/buffer_view_test.cpp @@ -8,8 +8,9 @@ #include -#include -#include +#include + +#include "network/notifications/encode.hpp" using namespace kagome::common; using Span = BufferView; diff --git a/test/core/consensus/babe/babe_block_validator_test.cpp b/test/core/consensus/babe/babe_block_validator_test.cpp index 4d1e796714..129161dd36 100644 --- a/test/core/consensus/babe/babe_block_validator_test.cpp +++ b/test/core/consensus/babe/babe_block_validator_test.cpp @@ -6,6 +6,8 @@ #include +#include + #include "consensus/babe/impl/babe_block_validator_impl.hpp" #include "consensus/babe/impl/babe_digests_util.hpp" #include "consensus/babe/types/seal.hpp" @@ -17,7 +19,6 @@ #include "mock/core/crypto/vrf_provider_mock.hpp" #include "mock/core/runtime/babe_api_mock.hpp" #include "testutil/lazy.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/sr25519_utils.hpp" @@ -212,8 +213,7 @@ TEST_F(BabeBlockValidatorTest, Success) { EXPECT_CALL(*vrf_provider, verifyTranscript(_, _, pubkey, _)) .WillOnce(Return(VRFVerifyOutput{.is_valid = true, .is_less = true})); - auto validate_res = block_validator->validateHeader(valid_block_.header); - EXPECT_OUTCOME_TRUE_1(validate_res); + ASSERT_OUTCOME_SUCCESS(block_validator->validateHeader(valid_block_.header)); } /** @@ -226,9 +226,8 @@ TEST_F(BabeBlockValidatorTest, LessDigestsThanNeeded) { authorities.emplace_back(authority); // for this test we can just not seal the block - it's the second digest - EXPECT_OUTCOME_FALSE(err, - block_validator->validateHeader(valid_block_.header)); - ASSERT_EQ(err, DigestError::REQUIRED_DIGESTS_NOT_FOUND); + ASSERT_OUTCOME_ERROR(block_validator->validateHeader(valid_block_.header), + DigestError::REQUIRED_DIGESTS_NOT_FOUND); } /** @@ -254,9 +253,8 @@ TEST_F(BabeBlockValidatorTest, NoBabeHeader) { authorities.emplace_back(); authorities.emplace_back(Authority{pubkey, 42}); - EXPECT_OUTCOME_FALSE(err, - block_validator->validateHeader(valid_block_.header)); - ASSERT_EQ(err, DigestError::REQUIRED_DIGESTS_NOT_FOUND); + ASSERT_OUTCOME_ERROR(block_validator->validateHeader(valid_block_.header), + DigestError::REQUIRED_DIGESTS_NOT_FOUND); } /** @@ -285,9 +283,8 @@ TEST_F(BabeBlockValidatorTest, SignatureVerificationFail) { EXPECT_CALL(*sr25519_provider, verify(_, _, _)).WillOnce(Return(false)); // WHEN-THEN - EXPECT_OUTCOME_FALSE(err, - block_validator->validateHeader(valid_block_.header)); - ASSERT_EQ(err, ValidatingError::INVALID_SIGNATURE); + ASSERT_OUTCOME_ERROR(block_validator->validateHeader(valid_block_.header), + ValidatingError::INVALID_SIGNATURE); } /** @@ -320,9 +317,8 @@ TEST_F(BabeBlockValidatorTest, VRFFail) { .WillOnce(Return(VRFVerifyOutput{.is_valid = false, .is_less = true})); // THEN - EXPECT_OUTCOME_FALSE(err, - block_validator->validateHeader(valid_block_.header)); - ASSERT_EQ(err, ValidatingError::INVALID_VRF); + ASSERT_OUTCOME_ERROR(block_validator->validateHeader(valid_block_.header), + ValidatingError::INVALID_VRF); } /** @@ -359,7 +355,6 @@ TEST_F(BabeBlockValidatorTest, ThresholdGreater) { .WillOnce(Return(VRFVerifyOutput{.is_valid = true, .is_less = false})); // THEN - EXPECT_OUTCOME_FALSE(err, - block_validator->validateHeader(valid_block_.header)); - ASSERT_EQ(err, ValidatingError::INVALID_VRF); + ASSERT_OUTCOME_ERROR(block_validator->validateHeader(valid_block_.header), + ValidatingError::INVALID_VRF); } diff --git a/test/core/consensus/babe/babe_test.cpp b/test/core/consensus/babe/babe_test.cpp index f6c9860806..7b1238de38 100644 --- a/test/core/consensus/babe/babe_test.cpp +++ b/test/core/consensus/babe/babe_test.cpp @@ -9,6 +9,7 @@ #include #include +#include #include "common/main_thread_pool.hpp" #include "common/worker_thread_pool.hpp" @@ -44,7 +45,6 @@ #include "storage/trie/serialization/ordered_trie_hash.hpp" #include "testutil/lazy.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/sr25519_utils.hpp" #include "utils/watchdog.hpp" @@ -512,7 +512,7 @@ TEST_F(BabeTest, SlotLeader) { std::latch latch(1); babe->on_proposed = [&] { latch.count_down(); }; - ASSERT_OUTCOME_SUCCESS_TRY(babe->processSlot(slot, best_block_info)); + ASSERT_OUTCOME_SUCCESS(babe->processSlot(slot, best_block_info)); latch.wait(); } @@ -563,6 +563,5 @@ TEST_F(BabeTest, EquivocationReport) { "parent"_hash256, equivocation_proof, ownership_proof)) .WillOnce(Return(outcome::success())); - ASSERT_OUTCOME_SUCCESS_TRY( - babe->reportEquivocation(first.hash(), second.hash())); + ASSERT_OUTCOME_SUCCESS(babe->reportEquivocation(first.hash(), second.hash())); } diff --git a/test/core/consensus/grandpa/chain_test.cpp b/test/core/consensus/grandpa/chain_test.cpp index ef754fb345..7e47bb86bc 100644 --- a/test/core/consensus/grandpa/chain_test.cpp +++ b/test/core/consensus/grandpa/chain_test.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "common/main_thread_pool.hpp" #include "consensus/grandpa/impl/environment_impl.hpp" @@ -26,7 +27,6 @@ #include "mock/core/runtime/parachain_host_mock.hpp" #include "testutil/lazy.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::Watchdog; diff --git a/test/core/consensus/grandpa/vote_graph/adjust_base_test.cpp b/test/core/consensus/grandpa/vote_graph/adjust_base_test.cpp index c94cc35567..1e9ebb9c18 100644 --- a/test/core/consensus/grandpa/vote_graph/adjust_base_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/adjust_base_test.cpp @@ -30,7 +30,7 @@ TEST_F(VoteGraphFixture, AdjustBase) { })"); expect_getAncestry("E"_H, "FC"_H, vec("FC"_H, "FB"_H, "FA"_H, "F"_H, "E"_H)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {9, "FC"_H}, "w5_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {9, "FC"_H}, "w5_a"_ID)); SCOPED_TRACE(2); AssertGraphCorrect(*graph, R"({ @@ -63,7 +63,7 @@ TEST_F(VoteGraphFixture, AdjustBase) { })"); expect_getAncestry("E"_H, "ED"_H, vec("ED"_H, "EC"_H, "EB"_H, "EA"_H, "E"_H)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {9, "ED"_H}, "w7_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {9, "ED"_H}, "w7_a"_ID)); SCOPED_TRACE(3); AssertGraphCorrect(*graph, R"({ @@ -242,7 +242,7 @@ TEST_F(VoteGraphFixture, AdjustBase) { expect_getAncestry( GENESIS_HASH, "4"_H, vec("4"_H, "3"_H, "2"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {4, "4"_H}, "w3_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {4, "4"_H}, "w3_a"_ID)); SCOPED_TRACE(6); AssertGraphCorrect(*graph, diff --git a/test/core/consensus/grandpa/vote_graph/duplicate_vote_test.cpp b/test/core/consensus/grandpa/vote_graph/duplicate_vote_test.cpp index f065b9248c..59b5229ab3 100644 --- a/test/core/consensus/grandpa/vote_graph/duplicate_vote_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/duplicate_vote_test.cpp @@ -38,7 +38,7 @@ TEST_F(VoteGraphFixture, DuplicateVote) { expect_getAncestry( GENESIS_HASH, "C"_H, vec("C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {3, "C"_H}, voter)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {3, "C"_H}, voter)); AssertGraphCorrect(*graph, R"( { @@ -74,7 +74,7 @@ TEST_F(VoteGraphFixture, DuplicateVote) { expect_getAncestry( GENESIS_HASH, "D"_H, vec("D"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {4, "D"_H}, voter)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {4, "D"_H}, voter)); // WHEN.1 @@ -120,7 +120,7 @@ TEST_F(VoteGraphFixture, DuplicateVote) { // WHEN.2 - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {3, "C"_H}, voter)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {3, "C"_H}, voter)); // THEN.2 diff --git a/test/core/consensus/grandpa/vote_graph/fixture.hpp b/test/core/consensus/grandpa/vote_graph/fixture.hpp index c476e2cb27..100c3efc09 100644 --- a/test/core/consensus/grandpa/vote_graph/fixture.hpp +++ b/test/core/consensus/grandpa/vote_graph/fixture.hpp @@ -9,12 +9,12 @@ #include #include +#include #include "consensus/grandpa/vote_graph/vote_graph_impl.hpp" #include "consensus/grandpa/voter_set.hpp" #include "core/consensus/grandpa/literals.hpp" #include "mock/core/consensus/grandpa/chain_mock.hpp" -#include "testutil/outcome.hpp" using namespace kagome; using namespace consensus; @@ -31,27 +31,27 @@ struct VoteGraphFixture : public testing::Test { std::shared_ptr voter_set = [] { auto vs = std::make_shared(); - EXPECT_OUTCOME_TRUE_1(vs->insert("w0_a"_ID, 0)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w0_a"_ID, 0)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w1_a"_ID, 1)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w1_b"_ID, 1)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w1_c"_ID, 1)); + EXPECT_OUTCOME_SUCCESS(x1, vs->insert("w1_a"_ID, 1)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w1_b"_ID, 1)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w1_c"_ID, 1)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w3_a"_ID, 3)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w3_b"_ID, 3)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w3_c"_ID, 3)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w3_a"_ID, 3)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w3_b"_ID, 3)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w3_c"_ID, 3)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w5_a"_ID, 5)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w5_b"_ID, 5)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w5_c"_ID, 5)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w5_a"_ID, 5)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w5_b"_ID, 5)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w5_c"_ID, 5)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w7_a"_ID, 7)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w7_b"_ID, 7)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w7_c"_ID, 7)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w7_a"_ID, 7)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w7_b"_ID, 7)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w7_c"_ID, 7)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w10_a"_ID, 10)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w10_b"_ID, 10)); - EXPECT_OUTCOME_TRUE_1(vs->insert("w10_c"_ID, 10)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w10_a"_ID, 10)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w10_b"_ID, 10)); + EXPECT_OUTCOME_SUCCESS(vs->insert("w10_c"_ID, 10)); return vs; }(); diff --git a/test/core/consensus/grandpa/vote_graph/ghost_introduce_branch_test.cpp b/test/core/consensus/grandpa/vote_graph/ghost_introduce_branch_test.cpp index 06052f9a66..d421909825 100644 --- a/test/core/consensus/grandpa/vote_graph/ghost_introduce_branch_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/ghost_introduce_branch_test.cpp @@ -39,7 +39,7 @@ TEST_F(VoteGraphFixture, GhostIntroduceBranch) { "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {9, "FC"_H}, "w5_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {9, "FC"_H}, "w5_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -88,7 +88,7 @@ TEST_F(VoteGraphFixture, GhostIntroduceBranch) { "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {9, "ED"_H}, "w7_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {9, "ED"_H}, "w7_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -162,7 +162,7 @@ TEST_F(VoteGraphFixture, GhostIntroduceBranch) { { // introduce branch in the middle // do not expect that insert is calling getAncestry - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {5, "E"_H}, "w3_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {5, "E"_H}, "w3_a"_ID)); AssertGraphCorrect(*graph, R"({ diff --git a/test/core/consensus/grandpa/vote_graph/ghost_merge_at_node_test.cpp b/test/core/consensus/grandpa/vote_graph/ghost_merge_at_node_test.cpp index 4c391df5bb..1edeae39a9 100644 --- a/test/core/consensus/grandpa/vote_graph/ghost_merge_at_node_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/ghost_merge_at_node_test.cpp @@ -28,7 +28,7 @@ TEST_F(VoteGraphFixture, GhostMergeAtNodes) { })"); expect_getAncestry(GENESIS_HASH, "B"_H, vec("B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {2, "B"_H}, "w0_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {2, "B"_H}, "w0_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -60,7 +60,7 @@ TEST_F(VoteGraphFixture, GhostMergeAtNodes) { expect_getAncestry( GENESIS_HASH, "C"_H, vec("C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {3, "C"_H}, "w5_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {3, "C"_H}, "w5_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -103,7 +103,7 @@ TEST_F(VoteGraphFixture, GhostMergeAtNodes) { expect_getAncestry(GENESIS_HASH, "E1"_H, vec("E1"_H, "D1"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {5, "E1"_H}, "w5_b"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {5, "E1"_H}, "w5_b"_ID)); AssertGraphCorrect(*graph, R"({ @@ -158,7 +158,7 @@ TEST_F(VoteGraphFixture, GhostMergeAtNodes) { GENESIS_HASH, "F2"_H, vec("F2"_H, "E2"_H, "D2"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {6, "F2"_H}, "w5_c"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {6, "F2"_H}, "w5_c"_ID)); AssertGraphCorrect(*graph, R"({ diff --git a/test/core/consensus/grandpa/vote_graph/ghost_merge_not_at_node_one_side_weighted_test.cpp b/test/core/consensus/grandpa/vote_graph/ghost_merge_not_at_node_one_side_weighted_test.cpp index b38f0abc20..d63eb30348 100644 --- a/test/core/consensus/grandpa/vote_graph/ghost_merge_not_at_node_one_side_weighted_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/ghost_merge_not_at_node_one_side_weighted_test.cpp @@ -28,7 +28,7 @@ TEST_F(VoteGraphFixture, GhostMergeNotAtNodeOneSideWeighted) { })"); expect_getAncestry(GENESIS_HASH, "B"_H, vec("B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {2, "B"_H}, "w0_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {2, "B"_H}, "w0_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -62,7 +62,7 @@ TEST_F(VoteGraphFixture, GhostMergeNotAtNodeOneSideWeighted) { GENESIS_HASH, "G1"_H, vec("G1"_H, "F"_H, "E"_H, "D"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {7, "G1"_H}, "w5_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {7, "G1"_H}, "w5_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -117,7 +117,7 @@ TEST_F(VoteGraphFixture, GhostMergeNotAtNodeOneSideWeighted) { "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {8, "H2"_H}, "w7_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {8, "H2"_H}, "w7_a"_ID)); AssertGraphCorrect(*graph, R"({ diff --git a/test/core/consensus/grandpa/vote_graph/graph_fork_test.cpp b/test/core/consensus/grandpa/vote_graph/graph_fork_test.cpp index 4fa7f4f23a..ed11e7e04f 100644 --- a/test/core/consensus/grandpa/vote_graph/graph_fork_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/graph_fork_test.cpp @@ -28,7 +28,7 @@ TEST_F(VoteGraphFixture, GraphForkAtNode) { expect_getAncestry( GENESIS_HASH, "C"_H, vec("C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {3, "C"_H}, "w5_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {3, "C"_H}, "w5_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -62,7 +62,7 @@ TEST_F(VoteGraphFixture, GraphForkAtNode) { expect_getAncestry(GENESIS_HASH, "E1"_H, vec("E1"_H, "D1"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {5, "E1"_H}, "w5_b"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {5, "E1"_H}, "w5_b"_ID)); AssertGraphCorrect(*graph, R"({ @@ -108,7 +108,7 @@ TEST_F(VoteGraphFixture, GraphForkAtNode) { GENESIS_HASH, "F2"_H, vec("F2"_H, "E2"_H, "D2"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {6, "F2"_H}, "w5_c"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {6, "F2"_H}, "w5_c"_ID)); AssertGraphCorrect(*graph, R"({ @@ -185,7 +185,7 @@ TEST_F(VoteGraphFixture, GraphForkNotAtNode) { })"); expect_getAncestry(GENESIS_HASH, "A"_H, vec("A"_H, GENESIS_HASH) /* empty */); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {1, "A"_H}, "w5_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {1, "A"_H}, "w5_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -217,7 +217,7 @@ TEST_F(VoteGraphFixture, GraphForkNotAtNode) { expect_getAncestry(GENESIS_HASH, "E1"_H, vec("E1"_H, "D1"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {5, "E1"_H}, "w5_b"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {5, "E1"_H}, "w5_b"_ID)); AssertGraphCorrect(*graph, R"({ @@ -263,7 +263,7 @@ TEST_F(VoteGraphFixture, GraphForkNotAtNode) { GENESIS_HASH, "F2"_H, vec("F2"_H, "E2"_H, "D2"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {6, "F2"_H}, "w5_c"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {6, "F2"_H}, "w5_c"_ID)); AssertGraphCorrect(*graph, R"({ diff --git a/test/core/consensus/grandpa/vote_graph/remove_vote_test.cpp b/test/core/consensus/grandpa/vote_graph/remove_vote_test.cpp index 7f71769b7d..65a43aa091 100644 --- a/test/core/consensus/grandpa/vote_graph/remove_vote_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/remove_vote_test.cpp @@ -36,7 +36,7 @@ TEST_F(VoteGraphFixture, RetractVote) { )"); expect_getAncestry(GENESIS_HASH, "A"_H, vec("A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {1, "A"_H}, "w1_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {1, "A"_H}, "w1_a"_ID)); AssertGraphCorrect(*graph, R"( { @@ -67,7 +67,7 @@ TEST_F(VoteGraphFixture, RetractVote) { )"); expect_getAncestry(GENESIS_HASH, "B"_H, vec("B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {2, "B"_H}, "w3_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {2, "B"_H}, "w3_a"_ID)); AssertGraphCorrect(*graph, R"( { @@ -109,7 +109,7 @@ TEST_F(VoteGraphFixture, RetractVote) { expect_getAncestry( GENESIS_HASH, "C"_H, vec("C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {3, "C"_H}, "w7_a"_ID)); + EXPECT_OUTCOME_SUCCESS(graph->insert(vt, {3, "C"_H}, "w7_a"_ID)); AssertGraphCorrect(*graph, R"( { diff --git a/test/core/consensus/grandpa/vote_graph/walk_back_at_node_test.cpp b/test/core/consensus/grandpa/vote_graph/walk_back_at_node_test.cpp index d047eb61cf..a11cd04df3 100644 --- a/test/core/consensus/grandpa/vote_graph/walk_back_at_node_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/walk_back_at_node_test.cpp @@ -32,7 +32,7 @@ struct WalkBackAtNode : public VoteGraphFixture, expect_getAncestry( GENESIS_HASH, "C"_H, vec("C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {3, "C"_H}, "w10_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {3, "C"_H}, "w10_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -67,7 +67,7 @@ struct WalkBackAtNode : public VoteGraphFixture, GENESIS_HASH, "F1"_H, vec("F1"_H, "E1"_H, "D1"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {6, "F1"_H}, "w5_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {6, "F1"_H}, "w5_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -114,7 +114,7 @@ struct WalkBackAtNode : public VoteGraphFixture, GENESIS_HASH, "F2"_H, vec("F2"_H, "E2"_H, "D2"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {6, "F2"_H}, "w5_b"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {6, "F2"_H}, "w5_b"_ID)); AssertGraphCorrect(*graph, R"({ @@ -181,7 +181,7 @@ struct WalkBackAtNode : public VoteGraphFixture, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {9, "I1"_H}, "w1_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {9, "I1"_H}, "w1_a"_ID)); AssertGraphCorrect(*graph, R"({ diff --git a/test/core/consensus/grandpa/vote_graph/walk_back_from_block_in_edge_fork_below_test.cpp b/test/core/consensus/grandpa/vote_graph/walk_back_from_block_in_edge_fork_below_test.cpp index 202d693fa6..18ccd30388 100644 --- a/test/core/consensus/grandpa/vote_graph/walk_back_from_block_in_edge_fork_below_test.cpp +++ b/test/core/consensus/grandpa/vote_graph/walk_back_from_block_in_edge_fork_below_test.cpp @@ -32,7 +32,7 @@ struct WalkBackFromBlockInEdgeForkBelow })"); expect_getAncestry(GENESIS_HASH, "B"_H, vec("B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {2, "B"_H}, "w10_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {2, "B"_H}, "w10_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -66,7 +66,7 @@ struct WalkBackFromBlockInEdgeForkBelow GENESIS_HASH, "F1"_H, vec("F1"_H, "E1"_H, "D1"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {6, "F1"_H}, "w5_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {6, "F1"_H}, "w5_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -113,7 +113,7 @@ struct WalkBackFromBlockInEdgeForkBelow GENESIS_HASH, "G2"_H, vec("G2"_H, "F2"_H, "E2"_H, "D2"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {7, "G2"_H}, "w5_b"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {7, "G2"_H}, "w5_b"_ID)); AssertGraphCorrect(*graph, R"({ diff --git a/test/core/consensus/grandpa/vote_graph/walk_back_from_fork_block_node_below_tests.cpp b/test/core/consensus/grandpa/vote_graph/walk_back_from_fork_block_node_below_tests.cpp index 33dfd94811..8bf7a2b464 100644 --- a/test/core/consensus/grandpa/vote_graph/walk_back_from_fork_block_node_below_tests.cpp +++ b/test/core/consensus/grandpa/vote_graph/walk_back_from_fork_block_node_below_tests.cpp @@ -30,7 +30,7 @@ struct WalkBackFromBlockNodeBelow })"); expect_getAncestry(GENESIS_HASH, "B"_H, vec("B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {2, "B"_H}, "w10_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {2, "B"_H}, "w10_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -64,7 +64,7 @@ struct WalkBackFromBlockNodeBelow GENESIS_HASH, "F1"_H, vec("F1"_H, "E1"_H, "D"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {6, "F1"_H}, "w5_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {6, "F1"_H}, "w5_a"_ID)); AssertGraphCorrect(*graph, R"({ @@ -111,7 +111,7 @@ struct WalkBackFromBlockNodeBelow GENESIS_HASH, "G2"_H, vec("G2"_H, "F2"_H, "E2"_H, "D"_H, "C"_H, "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {7, "G2"_H}, "w5_b"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {7, "G2"_H}, "w5_b"_ID)); AssertGraphCorrect(*graph, R"({ @@ -179,7 +179,7 @@ struct WalkBackFromBlockNodeBelow "B"_H, "A"_H, GENESIS_HASH)); - EXPECT_OUTCOME_TRUE_1(graph->insert(vt, {8, "H2"_H}, "w1_a"_ID)); + ASSERT_OUTCOME_SUCCESS(graph->insert(vt, {8, "H2"_H}, "w1_a"_ID)); AssertGraphCorrect(*graph, R"({ diff --git a/test/core/consensus/grandpa/voter_set_test.cpp b/test/core/consensus/grandpa/voter_set_test.cpp index bf38643d1f..47617b025a 100644 --- a/test/core/consensus/grandpa/voter_set_test.cpp +++ b/test/core/consensus/grandpa/voter_set_test.cpp @@ -6,9 +6,10 @@ #include +#include + #include "consensus/grandpa/voter_set.hpp" #include "core/consensus/grandpa/literals.hpp" -#include "testutil/outcome.hpp" using kagome::consensus::grandpa::Id; using kagome::consensus::grandpa::VoterSet; @@ -47,7 +48,7 @@ TEST_F(VoterSetTest, AddExistingVoters) { // GIVEN for (auto &[voter, weight] : voters) { - ASSERT_OUTCOME_SUCCESS_TRY(testee->insert(voter, weight)); + ASSERT_OUTCOME_SUCCESS(testee->insert(voter, weight)); } for (auto &[voter, weight] : voters) { @@ -62,7 +63,7 @@ TEST_F(VoterSetTest, GetIndex) { // GIVEN for (auto &[voter, weight] : voters) { - ASSERT_OUTCOME_SUCCESS_TRY(testee->insert(voter, weight)); + ASSERT_OUTCOME_SUCCESS(testee->insert(voter, weight)); } for (auto &[voter, weight] : voters) { @@ -78,7 +79,7 @@ TEST_F(VoterSetTest, GetWeight) { // GIVEN for (auto &[voter, weight] : voters) { - ASSERT_OUTCOME_SUCCESS_TRY(testee->insert(voter, weight)); + ASSERT_OUTCOME_SUCCESS(testee->insert(voter, weight)); } size_t index = 0; @@ -115,7 +116,7 @@ TEST_F(VoterSetTest, GetVoter) { // GIVEN for (auto &[voter, weight] : voters) { - ASSERT_OUTCOME_SUCCESS_TRY(testee->insert(voter, weight)); + ASSERT_OUTCOME_SUCCESS(testee->insert(voter, weight)); } for (size_t index = 0; index < voters.size(); ++index) { @@ -134,7 +135,7 @@ TEST_F(VoterSetTest, GetIndexAndWeight) { // GIVEN for (auto &[voter, weight] : voters) { - ASSERT_OUTCOME_SUCCESS_TRY(testee->insert(voter, weight)); + ASSERT_OUTCOME_SUCCESS(testee->insert(voter, weight)); } size_t index = 0; diff --git a/test/core/consensus/timeline/block_executor_test.cpp b/test/core/consensus/timeline/block_executor_test.cpp index 829a236e09..41007d517e 100644 --- a/test/core/consensus/timeline/block_executor_test.cpp +++ b/test/core/consensus/timeline/block_executor_test.cpp @@ -7,13 +7,17 @@ #include "consensus/timeline/impl/block_executor_impl.hpp" #include + #include #include +#include + #include "blockchain/block_tree_error.hpp" #include "common/main_thread_pool.hpp" #include "common/worker_thread_pool.hpp" #include "consensus/babe/impl/threshold_util.hpp" +#include "consensus/babe/types/babe_block_header.hpp" #include "consensus/babe/types/seal.hpp" #include "consensus/timeline/impl/block_appender_base.hpp" #include "mock/core/application/app_state_manager_mock.hpp" @@ -29,7 +33,6 @@ #include "mock/core/transaction_pool/transaction_pool_mock.hpp" #include "testutil/lazy.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" #include "utils/watchdog.hpp" @@ -308,7 +311,7 @@ TEST_F(BlockExecutorTest, JustificationFollowDigests) { block_executor_->applyBlock( Block{block_data.header.value(), block_data.body.value()}, justification, - [&](auto &&result) { ASSERT_OUTCOME_SUCCESS_TRY(result); }); + [&](auto &&result) { ASSERT_OUTCOME_SUCCESS(result); }); latch.wait(); } diff --git a/test/core/crypto/bandersnatch/bandersnatch_test.cpp b/test/core/crypto/bandersnatch/bandersnatch_test.cpp index 1ae3906f09..c046a9550e 100644 --- a/test/core/crypto/bandersnatch/bandersnatch_test.cpp +++ b/test/core/crypto/bandersnatch/bandersnatch_test.cpp @@ -8,11 +8,12 @@ #include +#include + #include "crypto/bandersnatch/bandersnatch_provider_impl.hpp" #include "crypto/bandersnatch/vrf.hpp" #include "crypto/hasher/hasher_impl.hpp" #include "crypto/random_generator/boost_generator.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::common::Blob; diff --git a/test/core/crypto/bip39/bip39_integration_test.cpp b/test/core/crypto/bip39/bip39_integration_test.cpp index 39fcb551ef..d4aaa88cf3 100644 --- a/test/core/crypto/bip39/bip39_integration_test.cpp +++ b/test/core/crypto/bip39/bip39_integration_test.cpp @@ -4,16 +4,16 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + #include -#include +#include +#include #include "crypto/bip39/impl/bip39_provider_impl.hpp" #include "crypto/bip39/mnemonic.hpp" #include "crypto/hasher/hasher_impl.hpp" #include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" -#include "testutil/outcome.hpp" - -#include #include "testutil/prepare_loggers.hpp" using namespace kagome::common; @@ -45,14 +45,14 @@ struct Bip39IntegrationTest : public ::testing::TestWithParam { TEST_P(Bip39IntegrationTest, DeriveEntropyAndSeedSuccess) { const TestItem &item = GetParam(); - EXPECT_OUTCOME_TRUE(mnemonic, Mnemonic::parse(item.mnemonic)); + ASSERT_OUTCOME_SUCCESS(mnemonic, Mnemonic::parse(item.mnemonic)); auto joined_words = boost::algorithm::join(*mnemonic.words(), " "); ASSERT_EQ(joined_words, item.mnemonic); - EXPECT_OUTCOME_TRUE(entropy, - bip39_provider->calculateEntropy(*mnemonic.words())); + ASSERT_OUTCOME_SUCCESS(entropy, + bip39_provider->calculateEntropy(*mnemonic.words())); - EXPECT_OUTCOME_TRUE(seed, bip39_provider->makeSeed(entropy, "Substrate")); + ASSERT_OUTCOME_SUCCESS(seed, bip39_provider->makeSeed(entropy, "Substrate")); ASSERT_EQ(seed, unhex(item.seed).value()); } diff --git a/test/core/crypto/bip39/entropy_calculation_test.cpp b/test/core/crypto/bip39/entropy_calculation_test.cpp index 1d906a0730..6d6fd1727f 100644 --- a/test/core/crypto/bip39/entropy_calculation_test.cpp +++ b/test/core/crypto/bip39/entropy_calculation_test.cpp @@ -7,15 +7,15 @@ #include #include -#include +#include +#include #include "common/blob.hpp" #include "common/buffer.hpp" #include "crypto/bip39/impl/bip39_provider_impl.hpp" #include "crypto/bip39/mnemonic.hpp" #include "crypto/hasher/hasher_impl.hpp" #include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using namespace kagome; @@ -57,14 +57,14 @@ struct Bip39EntropyTest : public ::testing::Test { * @then entropy and seed come up with predefined values */ TEST_F(Bip39EntropyTest, DecodeSuccess) { - EXPECT_OUTCOME_TRUE(mnemonic, Mnemonic::parse(phrase)); + ASSERT_OUTCOME_SUCCESS(mnemonic, Mnemonic::parse(phrase)); auto joined_words = boost::algorithm::join(*mnemonic.words(), " "); ASSERT_EQ(joined_words, phrase); - EXPECT_OUTCOME_TRUE(entropy, - bip39_provider->calculateEntropy(*mnemonic.words())); + ASSERT_OUTCOME_SUCCESS(entropy, + bip39_provider->calculateEntropy(*mnemonic.words())); ASSERT_EQ(common::Buffer(entropy).toHex(), entropy_hex); - EXPECT_OUTCOME_TRUE(seed, bip39_provider->makeSeed(entropy, "Substrate")); + ASSERT_OUTCOME_SUCCESS(seed, bip39_provider->makeSeed(entropy, "Substrate")); ASSERT_EQ(seed, common::unhex(seed_hex).value()); } diff --git a/test/core/crypto/ecdsa/ecdsa_provider_test.cpp b/test/core/crypto/ecdsa/ecdsa_provider_test.cpp index 791920b676..f581aa23f5 100644 --- a/test/core/crypto/ecdsa/ecdsa_provider_test.cpp +++ b/test/core/crypto/ecdsa/ecdsa_provider_test.cpp @@ -9,12 +9,13 @@ #include #include +#include + #include "crypto/bip39/impl/bip39_provider_impl.hpp" #include "crypto/ecdsa/ecdsa_provider_impl.hpp" #include "crypto/hasher/hasher_impl.hpp" #include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" #include "crypto/random_generator/boost_generator.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::crypto::Bip39ProviderImpl; @@ -77,9 +78,9 @@ TEST_F(EcdsaProviderTest, GenerateKeysNotEqual) { */ TEST_F(EcdsaProviderTest, SignVerifySuccess) { auto key_pair = generate(); - EXPECT_OUTCOME_TRUE(signature, - ecdsa_provider_->sign(message, key_pair.secret_key)); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS(signature, + ecdsa_provider_->sign(message, key_pair.secret_key)); + ASSERT_OUTCOME_SUCCESS( verify_res, ecdsa_provider_->verify(message, signature, key_pair.public_key, false)); ASSERT_EQ(verify_res, true); @@ -93,11 +94,11 @@ TEST_F(EcdsaProviderTest, SignVerifySuccess) { */ TEST_F(EcdsaProviderTest, VerifyWrongKeyFail) { auto key_pair = generate(); - EXPECT_OUTCOME_TRUE(signature, - ecdsa_provider_->sign(message, key_pair.secret_key)); + ASSERT_OUTCOME_SUCCESS(signature, + ecdsa_provider_->sign(message, key_pair.secret_key)); // generate another valid key pair and take public one auto another_keypair = generate(); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( ver_res, ecdsa_provider_->verify( message, signature, another_keypair.public_key, false)); diff --git a/test/core/crypto/ed25519/ed25519_provider_test.cpp b/test/core/crypto/ed25519/ed25519_provider_test.cpp index 51a3ea4757..27354c973b 100644 --- a/test/core/crypto/ed25519/ed25519_provider_test.cpp +++ b/test/core/crypto/ed25519/ed25519_provider_test.cpp @@ -9,12 +9,13 @@ #include #include +#include + #include "crypto/bip39/impl/bip39_provider_impl.hpp" #include "crypto/ed25519/ed25519_provider_impl.hpp" #include "crypto/hasher/hasher_impl.hpp" #include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" #include "crypto/random_generator/boost_generator.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::common::Hash256; @@ -88,8 +89,8 @@ TEST_F(Ed25519ProviderTest, GenerateKeysNotEqual) { */ TEST_F(Ed25519ProviderTest, SignVerifySuccess) { auto kp = generate(); - EXPECT_OUTCOME_TRUE(signature, ed25519_provider->sign(kp, message_span)); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS(signature, ed25519_provider->sign(kp, message_span)); + ASSERT_OUTCOME_SUCCESS( res, ed25519_provider->verify(signature, message_span, kp.public_key)); ASSERT_EQ(res, true); } @@ -106,7 +107,7 @@ TEST_F(Ed25519ProviderTest, SignVerifySuccess) { TEST_F(Ed25519ProviderTest, SignWithInvalidKeyFails) { auto kp = generate(); kp.public_key.fill(1); - EXPECT_OUTCOME_FALSE_1(ed25519_provider->sign(kp, message_span)); + EXPECT_OUTCOME_ERROR(ed25519_provider->sign(kp, message_span)); } /** @@ -118,10 +119,10 @@ TEST_F(Ed25519ProviderTest, SignWithInvalidKeyFails) { */ TEST_F(Ed25519ProviderTest, VerifyWrongKeyFail) { auto kp = generate(); - EXPECT_OUTCOME_TRUE(signature, ed25519_provider->sign(kp, message_span)); + ASSERT_OUTCOME_SUCCESS(signature, ed25519_provider->sign(kp, message_span)); // generate another valid key pair and take public one auto kp1 = generate(); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( ver_res, ed25519_provider->verify(signature, message_span, kp1.public_key)); @@ -141,10 +142,10 @@ TEST_F(Ed25519ProviderTest, VerifyWrongKeyFail) { */ TEST_F(Ed25519ProviderTest, DISABLED_VerifyInvalidKeyFail) { auto kp = generate(); - EXPECT_OUTCOME_TRUE(signature, ed25519_provider->sign(kp, message_span)); + ASSERT_OUTCOME_SUCCESS(signature, ed25519_provider->sign(kp, message_span)); // make public key invalid kp.public_key.fill(1); - EXPECT_OUTCOME_FALSE_1( + EXPECT_OUTCOME_ERROR( ed25519_provider->verify(signature, message_span, kp.public_key)); } @@ -154,12 +155,12 @@ TEST_F(Ed25519ProviderTest, DISABLED_VerifyInvalidKeyFail) { * @then public and private keys come up with predefined values */ TEST_F(Ed25519ProviderTest, GenerateBySeedSuccess) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( seed, Ed25519Seed::fromHex(SecureCleanGuard(std::string(hex_seed)))); - EXPECT_OUTCOME_TRUE(public_key, Ed25519PublicKey::fromHex(hex_public_key)); + ASSERT_OUTCOME_SUCCESS(public_key, Ed25519PublicKey::fromHex(hex_public_key)); // private key is the same as seed - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( private_key, Ed25519PrivateKey::fromHex(SecureCleanGuard(std::string(hex_seed)))); diff --git a/test/core/crypto/key_store/key_store_test.cpp b/test/core/crypto/key_store/key_store_test.cpp index 30f5c1ff37..e52cda1727 100644 --- a/test/core/crypto/key_store/key_store_test.cpp +++ b/test/core/crypto/key_store/key_store_test.cpp @@ -7,8 +7,11 @@ #include "crypto/key_store/key_store_impl.hpp" #include + #include +#include + #include "crypto/bandersnatch/bandersnatch_provider_impl.hpp" #include "crypto/bip39/impl/bip39_provider_impl.hpp" #include "crypto/ecdsa/ecdsa_provider_impl.hpp" @@ -17,10 +20,7 @@ #include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" #include "crypto/random_generator/boost_generator.hpp" #include "crypto/sr25519/sr25519_provider_impl.hpp" - #include "mock/core/application/app_state_manager_mock.hpp" - -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/storage/base_fs_test.hpp" @@ -122,19 +122,21 @@ struct KeyStoreTest : public test::BaseFS_Test { mnemonic = "ozone drill grab fiber curtain grace pudding thank cruise elder eight " "picnic"; - EXPECT_OUTCOME_TRUE(e, Buffer::fromHex("9e885d952ad362caeb4efe34a8e91bd2")); + ASSERT_OUTCOME_SUCCESS(e, + Buffer::fromHex("9e885d952ad362caeb4efe34a8e91bd2")); entropy = std::move(e); - EXPECT_OUTCOME_TRUE(s, - Blob<32>::fromHex("a4681403ba5b6a3f3bd0b0604ce439a78244" - "c7d43b127ec35cd8325602dd47fd")); + ASSERT_OUTCOME_SUCCESS( + s, + Blob<32>::fromHex("a4681403ba5b6a3f3bd0b0604ce439a78244" + "c7d43b127ec35cd8325602dd47fd")); seed = s; key_type = KeyTypes::BABE; - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( sr_publ, Sr25519PublicKey::fromHex("56a03c8afc0e7a3a8b1d53bcc875ba5b6364754f9045" "16009b57ef3adf96f61f")); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( sr_secr, Sr25519SecretKey::fromHex(SecureCleanGuard{ "ec96cb0816b67b045baae21841952a61ecb0612a109293e10c5453b950659c0a8b" @@ -169,8 +171,8 @@ TEST_F(KeyStoreTest, generateEd25519KeypairMnemonicSuccess) { auto res = key_store->ed25519().findKeypair(key_type, ed_pair.public_key); ASSERT_EQ(res, std::nullopt); - EXPECT_OUTCOME_TRUE(pair, - key_store->ed25519().generateKeypair(key_type, mnemonic)); + ASSERT_OUTCOME_SUCCESS( + pair, key_store->ed25519().generateKeypair(key_type, mnemonic)); ASSERT_EQ(pair, ed_pair); // check that created pair is now contained in memory @@ -188,8 +190,8 @@ TEST_F(KeyStoreTest, generateEd25519KeypairMnemonicSuccess) { * @and generated key pair is stored in memory */ TEST_F(KeyStoreTest, generateSr25519KeypairMnemonicSuccess) { - EXPECT_OUTCOME_TRUE(pair, - key_store->sr25519().generateKeypair(key_type, mnemonic)); + ASSERT_OUTCOME_SUCCESS( + pair, key_store->sr25519().generateKeypair(key_type, mnemonic)); ASSERT_EQ(pair, sr_pair); // check that created pair is now contained in memory @@ -209,9 +211,10 @@ TEST_F(KeyStoreTest, generateEd25519KeypairSeedSuccess) { auto res = key_store->ed25519().findKeypair(key_type, ed_pair.public_key); ASSERT_EQ(res, std::nullopt); - EXPECT_OUTCOME_TRUE(pair, - key_store->ed25519().generateKeypair( - key_type, Ed25519Seed::from(SecureCleanGuard{seed}))); + ASSERT_OUTCOME_SUCCESS( + pair, + key_store->ed25519().generateKeypair( + key_type, Ed25519Seed::from(SecureCleanGuard{seed}))); ASSERT_EQ(pair, ed_pair); // check that created pair is now contained in memory @@ -231,9 +234,10 @@ TEST_F(KeyStoreTest, generateSr25519KeypairSeedSuccess) { auto res = key_store->sr25519().findKeypair(key_type, sr_pair.public_key); ASSERT_EQ(res, std::nullopt); - EXPECT_OUTCOME_TRUE(pair, - key_store->sr25519().generateKeypair( - key_type, Sr25519Seed::from(SecureCleanGuard{seed}))); + ASSERT_OUTCOME_SUCCESS( + pair, + key_store->sr25519().generateKeypair( + key_type, Sr25519Seed::from(SecureCleanGuard{seed}))); ASSERT_EQ(pair, sr_pair); // check that created pair is now contained in memory @@ -250,8 +254,8 @@ TEST_F(KeyStoreTest, generateSr25519KeypairSeedSuccess) { * @then a new ed25519 key pair is generated and stored on disk */ TEST_F(KeyStoreTest, generateEd25519KeypairStoreSuccess) { - EXPECT_OUTCOME_TRUE(pair, - key_store->ed25519().generateKeypairOnDisk(key_type)); + ASSERT_OUTCOME_SUCCESS(pair, + key_store->ed25519().generateKeypairOnDisk(key_type)); // check that created pair is contained in the storage on disk auto found = key_store->ed25519().findKeypair(key_type, pair.public_key); @@ -267,8 +271,8 @@ TEST_F(KeyStoreTest, generateEd25519KeypairStoreSuccess) { * @then a new ed25519 key pair is generated and stored on disk */ TEST_F(KeyStoreTest, generateSr25519KeypairStoreSuccess) { - EXPECT_OUTCOME_TRUE(pair, - key_store->sr25519().generateKeypairOnDisk(key_type)); + ASSERT_OUTCOME_SUCCESS(pair, + key_store->sr25519().generateKeypairOnDisk(key_type)); // check that created pair is contained in the storage on disk auto found = key_store->sr25519().findKeypair(key_type, pair.public_key); @@ -284,9 +288,9 @@ TEST_F(KeyStoreTest, generateSr25519KeypairStoreSuccess) { * @then collection of all ed25519 public keys of provided type is returned */ TEST_F(KeyStoreTest, getEd25519PublicKeysSuccess) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( pair1, key_store->ed25519().generateKeypairOnDisk(KeyTypes::BABE)); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( pair2, key_store->ed25519().generateKeypairOnDisk(KeyTypes::BABE)); EXPECT_OUTCOME_SUCCESS( pair4, key_store->sr25519().generateKeypairOnDisk(KeyTypes::BABE)); @@ -307,9 +311,9 @@ TEST_F(KeyStoreTest, getEd25519PublicKeysSuccess) { * @then collection of all sr25519 public keys of provided type is returned */ TEST_F(KeyStoreTest, getSr25519PublicKeysSuccess) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( pair1, key_store->sr25519().generateKeypairOnDisk(KeyTypes::BABE)); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( pair2, key_store->sr25519().generateKeypairOnDisk(KeyTypes::BABE)); EXPECT_OUTCOME_SUCCESS( pair4, key_store->ed25519().generateKeypairOnDisk(KeyTypes::BABE)); diff --git a/test/core/crypto/secp256k1/secp256k1_provider_test.cpp b/test/core/crypto/secp256k1/secp256k1_provider_test.cpp index 26db5fa229..39e2be7477 100644 --- a/test/core/crypto/secp256k1/secp256k1_provider_test.cpp +++ b/test/core/crypto/secp256k1/secp256k1_provider_test.cpp @@ -6,12 +6,13 @@ #include "crypto/secp256k1/secp256k1_provider_impl.hpp" +#include + +#include + #include "common/buffer.hpp" #include "crypto/hasher/hasher_impl.hpp" -#include -#include "testutil/outcome.hpp" - using kagome::common::Blob; using kagome::common::Buffer; using kagome::crypto::Hasher; @@ -41,11 +42,12 @@ struct Secp256k1ProviderTest : public ::testing::Test { void SetUp() override { // message: "this is a message" - EXPECT_OUTCOME_TRUE(secp_message_vector, - Buffer::fromHex("746869732069732061206d657373616765")); + ASSERT_OUTCOME_SUCCESS( + secp_message_vector, + Buffer::fromHex("746869732069732061206d657373616765")); secp_message_hash = hasher->blake2s_256(secp_message_vector); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( secp_public_key_expanded_bytes, Buffer::fromHex("04f821bc128a43d9b0516969111e19a40bab417f45181d692d0519" "a3b35573cb63178403d12eb41d7702913a70ebc1c64438002a1474" @@ -53,13 +55,14 @@ struct Secp256k1ProviderTest : public ::testing::Test { secp_public_key_expanded = UncompressedPublicKey::fromSpan(secp_public_key_expanded_bytes).value(); - EXPECT_OUTCOME_TRUE(secp_public_key_compressed_bytes, - Buffer::fromHex("03f821bc128a43d9b0516969111e19a40bab41" - "7f45181d692d0519a3b35573cb63")); + ASSERT_OUTCOME_SUCCESS( + secp_public_key_compressed_bytes, + Buffer::fromHex("03f821bc128a43d9b0516969111e19a40bab41" + "7f45181d692d0519a3b35573cb63")); secp_public_key_compressed = CompressedPublicKey::fromSpan(secp_public_key_compressed_bytes).value(); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( secp_signature_bytes, Buffer::fromHex("ebdedee38bcf530f13c1b5c8717d974a6f8bd25a7e3707ca36c7ee" "7efd5aa6c557bcc67906975696cbb28a556b649e5fbf5ce5183157" @@ -109,9 +112,9 @@ TEST_F(Secp256k1ProviderTest, RecoverInvalidSignatureFailure) { * @then Recovery is successful, public key returned */ TEST_F(Secp256k1ProviderTest, RecoverUncompressedSuccess) { - EXPECT_OUTCOME_TRUE(public_key, - secp256K1_provider->recoverPublickeyUncompressed( - secp_signature, secp_message_hash, false)); + ASSERT_OUTCOME_SUCCESS(public_key, + secp256K1_provider->recoverPublickeyUncompressed( + secp_signature, secp_message_hash, false)); EXPECT_EQ(public_key, secp_public_key_expanded); } @@ -121,8 +124,8 @@ TEST_F(Secp256k1ProviderTest, RecoverUncompressedSuccess) { * @then Recovery is successful, public key is returned */ TEST_F(Secp256k1ProviderTest, RecoverCompressedSuccess) { - EXPECT_OUTCOME_TRUE(public_key, - secp256K1_provider->recoverPublickeyCompressed( - secp_signature, secp_message_hash, false)); + ASSERT_OUTCOME_SUCCESS(public_key, + secp256K1_provider->recoverPublickeyCompressed( + secp_signature, secp_message_hash, false)); EXPECT_EQ(public_key, secp_public_key_compressed); } diff --git a/test/core/crypto/sr25519/sr25519_provider_test.cpp b/test/core/crypto/sr25519/sr25519_provider_test.cpp index ad8ca72c68..4be89e5306 100644 --- a/test/core/crypto/sr25519/sr25519_provider_test.cpp +++ b/test/core/crypto/sr25519/sr25519_provider_test.cpp @@ -7,14 +7,16 @@ #include "crypto/sr25519/sr25519_provider_impl.hpp" #include -#include + #include +#include + +#include "mock/libp2p/crypto/random_generator_mock.hpp" #include "crypto/bip39/impl/bip39_provider_impl.hpp" #include "crypto/hasher/hasher_impl.hpp" #include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" #include "crypto/random_generator/boost_generator.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::crypto::Bip39ProviderImpl; @@ -78,8 +80,8 @@ struct Sr25519ProviderTest : public ::testing::Test { */ TEST_F(Sr25519ProviderTest, GenerateKeysNotEqual) { for (auto i = 0; i < 10; ++i) { - EXPECT_OUTCOME_TRUE(kp1, generate()); - EXPECT_OUTCOME_TRUE(kp2, generate()); + ASSERT_OUTCOME_SUCCESS(kp1, generate()); + ASSERT_OUTCOME_SUCCESS(kp2, generate()); ASSERT_NE(kp1.public_key, kp2.public_key); ASSERT_NE(kp1.secret_key, kp2.secret_key); } @@ -93,9 +95,9 @@ TEST_F(Sr25519ProviderTest, GenerateKeysNotEqual) { * @then verification succeeds */ TEST_F(Sr25519ProviderTest, SignVerifySuccess) { - EXPECT_OUTCOME_TRUE(kp, generate()); - EXPECT_OUTCOME_TRUE(signature, sr25519_provider->sign(kp, message_span)); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS(kp, generate()); + ASSERT_OUTCOME_SUCCESS(signature, sr25519_provider->sign(kp, message_span)); + ASSERT_OUTCOME_SUCCESS( res, sr25519_provider->verify(signature, message_span, kp.public_key)); ASSERT_EQ(res, true); } @@ -110,9 +112,9 @@ TEST_F(Sr25519ProviderTest, SignVerifySuccess) { * @then sign fails */ TEST_F(Sr25519ProviderTest, DISABLED_SignWithInvalidKeyFails) { - EXPECT_OUTCOME_TRUE(kp, generate()); + ASSERT_OUTCOME_SUCCESS(kp, generate()); kp.public_key.fill(1); - EXPECT_OUTCOME_FALSE_1(sr25519_provider->sign(kp, message_span)); + EXPECT_OUTCOME_ERROR(sr25519_provider->sign(kp, message_span)); } /** @@ -123,11 +125,11 @@ TEST_F(Sr25519ProviderTest, DISABLED_SignWithInvalidKeyFails) { * @then verification succeeds, but verification result is false */ TEST_F(Sr25519ProviderTest, VerifyWrongKeyFail) { - EXPECT_OUTCOME_TRUE(kp, generate()); - EXPECT_OUTCOME_TRUE(signature, sr25519_provider->sign(kp, message_span)); + ASSERT_OUTCOME_SUCCESS(kp, generate()); + ASSERT_OUTCOME_SUCCESS(signature, sr25519_provider->sign(kp, message_span)); // generate another valid key pair and take public one - EXPECT_OUTCOME_TRUE(kp1, generate()); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS(kp1, generate()); + ASSERT_OUTCOME_SUCCESS( ver_res, sr25519_provider->verify(signature, message_span, kp1.public_key)); @@ -146,11 +148,11 @@ TEST_F(Sr25519ProviderTest, VerifyWrongKeyFail) { * @then verification fails */ TEST_F(Sr25519ProviderTest, DISABLED_VerifyInvalidKeyFail) { - EXPECT_OUTCOME_TRUE(kp, generate()); - EXPECT_OUTCOME_TRUE(signature, sr25519_provider->sign(kp, message_span)); + ASSERT_OUTCOME_SUCCESS(kp, generate()); + ASSERT_OUTCOME_SUCCESS(signature, sr25519_provider->sign(kp, message_span)); // make public key invalid kp.public_key.fill(1); - EXPECT_OUTCOME_FALSE_1( + EXPECT_OUTCOME_ERROR( sr25519_provider->verify(signature, message_span, kp.public_key)); } @@ -160,16 +162,16 @@ TEST_F(Sr25519ProviderTest, DISABLED_VerifyInvalidKeyFail) { * @then verifying and secret keys come up with predefined values */ TEST_F(Sr25519ProviderTest, GenerateBySeedSuccess) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( seed, Sr25519Seed::fromHex(SecureCleanGuard{std::string(hex_seed)})); - EXPECT_OUTCOME_TRUE(public_key, Sr25519PublicKey::fromHex(hex_vk)); + ASSERT_OUTCOME_SUCCESS(public_key, Sr25519PublicKey::fromHex(hex_vk)); // private key is the same as seed - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( secret_key, Sr25519SecretKey::fromHex(SecureCleanGuard{std::string{hex_sk}})); - EXPECT_OUTCOME_TRUE(kp, sr25519_provider->generateKeypair(seed, {})); + ASSERT_OUTCOME_SUCCESS(kp, sr25519_provider->generateKeypair(seed, {})); ASSERT_EQ(kp.secret_key, secret_key); ASSERT_EQ(kp.public_key, public_key); diff --git a/test/core/host_api/child_storage_extension_test.cpp b/test/core/host_api/child_storage_extension_test.cpp index 58f55deaaf..b9fac0940f 100644 --- a/test/core/host_api/child_storage_extension_test.cpp +++ b/test/core/host_api/child_storage_extension_test.cpp @@ -22,7 +22,6 @@ #include "storage/trie/polkadot_trie/trie_error.hpp" #include "storage/trie/types.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/outcome/dummy_error.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/runtime/memory.hpp" diff --git a/test/core/host_api/crypto_extension_test.cpp b/test/core/host_api/crypto_extension_test.cpp index d9c1853641..1d40aca974 100644 --- a/test/core/host_api/crypto_extension_test.cpp +++ b/test/core/host_api/crypto_extension_test.cpp @@ -11,6 +11,7 @@ #include #include +#include #include "crypto/ecdsa/ecdsa_provider_impl.hpp" #include "crypto/ed25519/ed25519_provider_impl.hpp" #include "crypto/hasher/hasher_impl.hpp" @@ -20,10 +21,8 @@ #include "crypto/sr25519/sr25519_provider_impl.hpp" #include "mock/core/crypto/key_store_mock.hpp" #include "mock/core/runtime/memory_provider_mock.hpp" -#include "runtime/ptr_size.hpp" #include "scale/scale.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/runtime/memory.hpp" @@ -108,8 +107,8 @@ class CryptoExtensionTest : public ::testing::Test { hasher_, key_store_); - EXPECT_OUTCOME_TRUE(seed_tmp, - kagome::common::Blob<32>::fromHexWithPrefix(seed_hex)); + ASSERT_OUTCOME_SUCCESS( + seed_tmp, kagome::common::Blob<32>::fromHexWithPrefix(seed_hex)); std::copy_n(seed_tmp.begin(), Blob<32>::size(), seed.begin()); // scale-encoded string @@ -322,7 +321,7 @@ TEST_F(CryptoExtensionTest, Ed25519VerifySuccess) { random_generator_->fillRandomly(seed_buf); auto seed = Ed25519Seed::from(std::move(seed_buf)).value(); auto keypair = ed25519_provider_->generateKeypair(seed, {}).value(); - EXPECT_OUTCOME_TRUE(signature, ed25519_provider_->sign(keypair, input)); + ASSERT_OUTCOME_SUCCESS(signature, ed25519_provider_->sign(keypair, input)); ASSERT_EQ( crypto_ext_->ext_crypto_ed25519_verify_version_1( diff --git a/test/core/host_api/offchain_extension_test.cpp b/test/core/host_api/offchain_extension_test.cpp index 08b718e5c3..6827ea0c2e 100644 --- a/test/core/host_api/offchain_extension_test.cpp +++ b/test/core/host_api/offchain_extension_test.cpp @@ -8,6 +8,8 @@ #include +#include + #include "mock/core/offchain/offchain_persistent_storage_mock.hpp" #include "mock/core/offchain/offchain_worker_mock.hpp" #include "mock/core/offchain/offchain_worker_pool_mock.hpp" @@ -19,7 +21,6 @@ #include "runtime/ptr_size.hpp" #include "scale/encode_append.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/outcome/dummy_error.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/runtime/memory.hpp" diff --git a/test/core/host_api/storage_extension_test.cpp b/test/core/host_api/storage_extension_test.cpp index 312ff20bc2..ec3f290cb4 100644 --- a/test/core/host_api/storage_extension_test.cpp +++ b/test/core/host_api/storage_extension_test.cpp @@ -6,10 +6,12 @@ #include "host_api/impl/storage_extension.hpp" -#include - #include #include + +#include + +#include #include #include "crypto/hasher/hasher_impl.hpp" @@ -22,7 +24,6 @@ #include "scale/kagome_scale.hpp" #include "storage/predefined_keys.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/outcome/dummy_error.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/runtime/memory.hpp" diff --git a/test/core/network/state_protocol_observer_test.cpp b/test/core/network/state_protocol_observer_test.cpp index 7c2693fdfb..14889cd5cb 100644 --- a/test/core/network/state_protocol_observer_test.cpp +++ b/test/core/network/state_protocol_observer_test.cpp @@ -7,8 +7,11 @@ #include "network/impl/state_protocol_observer_impl.hpp" #include + #include +#include + #include "mock/core/blockchain/block_header_repository_mock.hpp" #include "mock/core/storage/trie_pruner/trie_pruner_mock.hpp" #include "network/types/state_request.hpp" @@ -18,10 +21,8 @@ #include "storage/trie/polkadot_trie/polkadot_trie_factory_impl.hpp" #include "storage/trie/serialization/trie_serializer_impl.hpp" #include "storage/trie/trie_batches.hpp" -#include "storage/trie/trie_storage_backend.hpp" #include "storage/trie/types.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using namespace kagome; @@ -125,10 +126,10 @@ namespace kagome::network { * @then response with 2 entries */ TEST_F(StateProtocolObserverTest, Simple) { - EXPECT_OUTCOME_TRUE(batch, persistent_empty_batch()); + ASSERT_OUTCOME_SUCCESS(batch, persistent_empty_batch()); std::ignore = batch->put("abc"_buf, "123"_buf); std::ignore = batch->put("cde"_buf, "345"_buf); - EXPECT_OUTCOME_TRUE(hash, batch->commit(storage::trie::StateVersion::V0)); + ASSERT_OUTCOME_SUCCESS(hash, batch->commit(storage::trie::StateVersion::V0)); auto header = makeBlockHeader(hash); EXPECT_CALL(*headers_, getBlockHeader({"1"_hash256})) @@ -140,8 +141,8 @@ TEST_F(StateProtocolObserverTest, Simple) { .no_proof = true, }; - EXPECT_OUTCOME_TRUE(response, - state_protocol_observer_->onStateRequest(request)); + ASSERT_OUTCOME_SUCCESS(response, + state_protocol_observer_->onStateRequest(request)); StateResponse ref = { .entries = {{ diff --git a/test/core/network/sync_protocol_observer_test.cpp b/test/core/network/sync_protocol_observer_test.cpp index 3fbf047ff1..07c7804335 100644 --- a/test/core/network/sync_protocol_observer_test.cpp +++ b/test/core/network/sync_protocol_observer_test.cpp @@ -11,15 +11,15 @@ #include #include +#include + #include "application/app_configuration.hpp" #include "mock/core/blockchain/block_header_repository_mock.hpp" #include "mock/core/blockchain/block_tree_mock.hpp" #include "mock/core/network/beefy_mock.hpp" #include "mock/libp2p/host/host_mock.hpp" #include "primitives/block.hpp" -#include "testutil/gmock_actions.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using namespace kagome; @@ -104,9 +104,9 @@ TEST_F(SyncProtocolObserverTest, ProcessRequest) { }); // WHEN - EXPECT_OUTCOME_TRUE(response, - sync_protocol_observer_->onBlocksRequest(received_request, - peer_info_.id)); + ASSERT_OUTCOME_SUCCESS(response, + sync_protocol_observer_->onBlocksRequest( + received_request, peer_info_.id)); // THEN const auto &received_blocks = response.blocks; diff --git a/test/core/network/types/block_announce_test.cpp b/test/core/network/types/block_announce_test.cpp index 361589ebf8..8e91da9a07 100644 --- a/test/core/network/types/block_announce_test.cpp +++ b/test/core/network/types/block_announce_test.cpp @@ -8,9 +8,10 @@ #include #include +#include + #include "scale/scale.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/primitives/mp_utils.hpp" using kagome::common::Buffer; diff --git a/test/core/network/types/block_attributes_test.cpp b/test/core/network/types/block_attributes_test.cpp index a0b0da45d1..78746a450e 100644 --- a/test/core/network/types/block_attributes_test.cpp +++ b/test/core/network/types/block_attributes_test.cpp @@ -7,8 +7,9 @@ #include "network/types/block_attributes.hpp" #include +#include + #include "scale/scale.hpp" -#include "testutil/outcome.hpp" #include "testutil/testparam.hpp" using kagome::network::BlockAttribute; @@ -34,10 +35,10 @@ struct BlockAttributesTest TEST_P(BlockAttributesTest, DecodeBlockAttributes) { auto [encoded_value, should_fail, value] = GetParam(); if (should_fail) { - EXPECT_EC(decode(encoded_value), - scale::DecodeError::UNEXPECTED_VALUE); + ASSERT_OUTCOME_ERROR(decode(encoded_value), + scale::DecodeError::UNEXPECTED_VALUE); } else { - EXPECT_OUTCOME_TRUE(val, decode(encoded_value)); + ASSERT_OUTCOME_SUCCESS(val, decode(encoded_value)); ASSERT_EQ(val, value); } } diff --git a/test/core/network/types/block_direction_test.cpp b/test/core/network/types/block_direction_test.cpp index 0b7b023109..b9c88f0286 100644 --- a/test/core/network/types/block_direction_test.cpp +++ b/test/core/network/types/block_direction_test.cpp @@ -7,9 +7,10 @@ #include "network/types/block_direction.hpp" #include + +#include #include -#include "testutil/outcome.hpp" #include "testutil/testparam.hpp" using kagome::network::Direction; @@ -32,10 +33,10 @@ struct DirectionTest : public ::testing::TestWithParam {}; TEST_P(DirectionTest, DecodeDirection) { auto [encoded_value, should_fail, value] = GetParam(); if (should_fail) { - EXPECT_EC(decode(encoded_value), - scale::DecodeError::INVALID_ENUM_VALUE); + ASSERT_OUTCOME_ERROR(decode(encoded_value), + scale::DecodeError::INVALID_ENUM_VALUE); } else { - EXPECT_OUTCOME_TRUE(val, decode(encoded_value)); + ASSERT_OUTCOME_SUCCESS(val, decode(encoded_value)); ASSERT_EQ(val, value); } } diff --git a/test/core/network/types/message_read_writer_test.cpp b/test/core/network/types/message_read_writer_test.cpp index 81d7fc2116..0f0b9c3771 100644 --- a/test/core/network/types/message_read_writer_test.cpp +++ b/test/core/network/types/message_read_writer_test.cpp @@ -7,8 +7,9 @@ #include +#include + #include "mock/core/network/adapter_mock.hpp" -#include "testutil/outcome.hpp" using AdapterType_0 = kagome::network::AdapterMock; using AdapterMockPtrType = std::shared_ptr; diff --git a/test/core/network/types/protobuf_block_request_test.cpp b/test/core/network/types/protobuf_block_request_test.cpp index 9e843c303d..4d49da8c05 100644 --- a/test/core/network/types/protobuf_block_request_test.cpp +++ b/test/core/network/types/protobuf_block_request_test.cpp @@ -7,7 +7,7 @@ #include -#include "testutil/outcome.hpp" +#include using kagome::network::BlockAttribute; using kagome::network::BlocksRequest; @@ -25,7 +25,7 @@ struct ProtobufBlockRequestAdapterTest : public ::testing::Test { request.direction = Direction::DESCENDING; request.fields = toBlockAttribute(0x19); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( hash_from, BlockHash::fromHex("11111403ba5b6a3f3bd0b0604ce439a78244" "c7d43b127ec35cd8325602dd47fd")); @@ -47,7 +47,7 @@ TEST_F(ProtobufBlockRequestAdapterTest, Serialization) { AdapterType::write(request, data, data.end()); BlocksRequest r2; - EXPECT_OUTCOME_TRUE(it_read, AdapterType::read(r2, data, data.begin())); + ASSERT_OUTCOME_SUCCESS(it_read, AdapterType::read(r2, data, data.begin())); ASSERT_EQ(it_read, data.end()); ASSERT_EQ(r2.max, request.max); diff --git a/test/core/network/types/protobuf_block_response_test.cpp b/test/core/network/types/protobuf_block_response_test.cpp index e067442ae2..7bcf2bd532 100644 --- a/test/core/network/types/protobuf_block_response_test.cpp +++ b/test/core/network/types/protobuf_block_response_test.cpp @@ -7,7 +7,7 @@ #include -#include "testutil/outcome.hpp" +#include using kagome::network::BlocksResponse; using kagome::network::ProtobufMessageAdapter; @@ -23,29 +23,29 @@ struct ProtobufBlockResponseAdapterTest : public ::testing::Test { using AdapterType = ProtobufMessageAdapter; void SetUp() { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( hash, BlockHash::fromHex("11111403ba5b6a3f3bd0b0604ce439a78244" "c7d43b127ec35cd8325602dd47fd")); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( parent_hash, BlockHash::fromHex("22111403ba5b6a3f3bd0b0604ce439a78244" "c7d43b127ec35cd8325602dd47fd")); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( root_hash, BlockHash::fromHex("23648236745b6a3f3bd0b0604ce439a78244" "c7d43b127ec35cd8325602dd47fd")); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( ext_hash, BlockHash::fromHex("2364823674278726578628756faad1a78244" "c7d43b127ec35cd8325602dd47fd")); - EXPECT_OUTCOME_TRUE(ext, Buffer::fromHex("11223344")); - EXPECT_OUTCOME_TRUE(receipt, Buffer::fromHex("55ffddeeaa")); - EXPECT_OUTCOME_TRUE(message_queue, Buffer::fromHex("1a2b3c4d5e6f")); + ASSERT_OUTCOME_SUCCESS(ext, Buffer::fromHex("11223344")); + ASSERT_OUTCOME_SUCCESS(receipt, Buffer::fromHex("55ffddeeaa")); + ASSERT_OUTCOME_SUCCESS(message_queue, Buffer::fromHex("1a2b3c4d5e6f")); response.blocks.emplace_back(BlockData{.hash = hash, .header = @@ -76,7 +76,7 @@ TEST_F(ProtobufBlockResponseAdapterTest, Serialization) { AdapterType::write(response, data, data.end()); BlocksResponse r2; - EXPECT_OUTCOME_TRUE(it_read, AdapterType::read(r2, data, data.begin())); + ASSERT_OUTCOME_SUCCESS(it_read, AdapterType::read(r2, data, data.begin())); ASSERT_EQ(it_read, data.end()); for (size_t ix = 0; ix < response.blocks.size(); ++ix) { diff --git a/test/core/network/types/protobuf_state_request_test.cpp b/test/core/network/types/protobuf_state_request_test.cpp index 61314ca2fe..6b1396d303 100644 --- a/test/core/network/types/protobuf_state_request_test.cpp +++ b/test/core/network/types/protobuf_state_request_test.cpp @@ -7,7 +7,7 @@ #include -#include "testutil/outcome.hpp" +#include using kagome::network::ProtobufMessageAdapter; using kagome::network::StateRequest; @@ -19,7 +19,7 @@ struct ProtobufStateRequestAdapterTest : public ::testing::Test { using AdapterType = ProtobufMessageAdapter; void SetUp() { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( hash_from, BlockHash::fromHex("11111403ba5b6a3f3bd0b0604ce439a78244" "c7d43b127ec35cd8325602dd47fd")); @@ -43,7 +43,7 @@ TEST_F(ProtobufStateRequestAdapterTest, Serialization) { AdapterType::write(request, data, data.end()); StateRequest r2; - EXPECT_OUTCOME_TRUE(it_read, AdapterType::read(r2, data, data.begin())); + ASSERT_OUTCOME_SUCCESS(it_read, AdapterType::read(r2, data, data.begin())); ASSERT_EQ(it_read, data.end()); ASSERT_EQ(r2.hash, request.hash); diff --git a/test/core/network/types/protobuf_state_response_test.cpp b/test/core/network/types/protobuf_state_response_test.cpp index fb7890b013..a4a37a5367 100644 --- a/test/core/network/types/protobuf_state_response_test.cpp +++ b/test/core/network/types/protobuf_state_response_test.cpp @@ -7,8 +7,9 @@ #include +#include + #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" using kagome::common::Buffer; using kagome::common::Hash256; @@ -42,7 +43,7 @@ TEST_F(ProtobufStateResponseAdapterTest, Serialization) { AdapterType::write(response, data, data.end()); StateResponse r2; - EXPECT_OUTCOME_TRUE(it_read, AdapterType::read(r2, data, data.begin())); + ASSERT_OUTCOME_SUCCESS(it_read, AdapterType::read(r2, data, data.begin())); ASSERT_EQ(it_read, data.end()); } diff --git a/test/core/network/types/uvar_adapter_test.cpp b/test/core/network/types/uvar_adapter_test.cpp index 4e080db4fa..5e23eecd30 100644 --- a/test/core/network/types/uvar_adapter_test.cpp +++ b/test/core/network/types/uvar_adapter_test.cpp @@ -7,7 +7,7 @@ #include -#include "testutil/outcome.hpp" +#include using kagome::network::UVarMessageAdapter; @@ -30,7 +30,7 @@ TEST_F(UVarAdapterTest, ZeroDataTest) { ASSERT_EQ(data.size() - std::distance(data.begin(), it), 1); ASSERT_EQ(*it, 0); - EXPECT_OUTCOME_TRUE(it_read, UVarMessageAdapter::read(d, data, it)); + ASSERT_OUTCOME_SUCCESS(it_read, UVarMessageAdapter::read(d, data, it)); ASSERT_EQ(it_read, data.end()); } @@ -49,7 +49,7 @@ TEST_F(UVarAdapterTest, DataSize_7f) { ASSERT_EQ(data.size() - std::distance(data.begin(), it), 0x80); ASSERT_EQ(*it, 0x7f); - EXPECT_OUTCOME_TRUE(it_read, UVarMessageAdapter::read(d, data, it)); + ASSERT_OUTCOME_SUCCESS(it_read, UVarMessageAdapter::read(d, data, it)); ASSERT_EQ(it_read.base() - data.begin().base(), (uint64_t)UVarMessageAdapter::size(Dummy{})); } @@ -70,7 +70,7 @@ TEST_F(UVarAdapterTest, DataSize_1) { ASSERT_EQ(data.size() - std::distance(data.begin(), it), 2); ASSERT_EQ(*it, 0x1); - EXPECT_OUTCOME_TRUE(it_read, UVarMessageAdapter::read(d, data, it)); + ASSERT_OUTCOME_SUCCESS(it_read, UVarMessageAdapter::read(d, data, it)); ASSERT_EQ(it_read.base() - data.begin().base(), (uint64_t)UVarMessageAdapter::size(Dummy{})); } @@ -92,7 +92,7 @@ TEST_F(UVarAdapterTest, DataSize_fd) { ASSERT_EQ(*it, 0xfd); ASSERT_EQ(*(it + 1), 0x1); - EXPECT_OUTCOME_TRUE(it_read, UVarMessageAdapter::read(d, data, it)); + ASSERT_OUTCOME_SUCCESS(it_read, UVarMessageAdapter::read(d, data, it)); ASSERT_EQ(it_read.base() - data.begin().base(), (uint64_t)UVarMessageAdapter::size(Dummy{})); } diff --git a/test/core/parachain/availability/recovery_test.cpp b/test/core/parachain/availability/recovery_test.cpp index 09db933a95..f80e425511 100644 --- a/test/core/parachain/availability/recovery_test.cpp +++ b/test/core/parachain/availability/recovery_test.cpp @@ -8,6 +8,8 @@ #include +#include + #include "crypto/random_generator/boost_generator.hpp" #include "mock/core/application/chain_spec_mock.hpp" #include "mock/core/authority_discovery/query_mock.hpp" @@ -21,7 +23,6 @@ #include "parachain/availability/chunks.hpp" #include "parachain/availability/proof.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::Buffer; diff --git a/test/core/parachain/candidate_storage.cpp b/test/core/parachain/candidate_storage.cpp index 8025b6f2a6..497d8b9f5e 100644 --- a/test/core/parachain/candidate_storage.cpp +++ b/test/core/parachain/candidate_storage.cpp @@ -82,7 +82,7 @@ TEST_F(CandidateStorageTest, candidate_storage_methods) { ASSERT_EQ(storage.head_data_by_hash(parent_head_hash), std::nullopt); // Add a valid candidate. - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( candidate_entry, fragment::CandidateEntry::create(candidate_hash, candidate, @@ -138,9 +138,10 @@ TEST_F(CandidateStorageTest, candidate_storage_methods) { make_committed_candidate(5, relay_parent, 8, {4, 5, 6}, {2, 3, 4}, 7); const Hash candidate_hash_2 = network::candidateHash(*hasher_, candidate_2); - EXPECT_OUTCOME_TRUE(candidate_entry_2, - fragment::CandidateEntry::create_seconded( - candidate_hash_2, candidate_2, pvd_2.get(), hasher_)); + ASSERT_OUTCOME_SUCCESS( + candidate_entry_2, + fragment::CandidateEntry::create_seconded( + candidate_hash_2, candidate_2, pvd_2.get(), hasher_)); std::ignore = storage.add_candidate_entry(candidate_entry_2); ASSERT_EQ(aggregate_hashes(parent_head_hash), diff --git a/test/core/parachain/fragment_chain.cpp b/test/core/parachain/fragment_chain.cpp index 094e1be714..3af6d24fb3 100644 --- a/test/core/parachain/fragment_chain.cpp +++ b/test/core/parachain/fragment_chain.cpp @@ -5,9 +5,10 @@ */ #include "parachain/validator/prospective_parachains/fragment_chain.hpp" -#include #include "core/parachain/parachain_test_harness.hpp" +#include + using namespace kagome::parachain::fragment; class FragmentChainTest : public ProspectiveParachainsTestHarness { @@ -42,17 +43,17 @@ class FragmentChainTest : public ProspectiveParachainsTestHarness { TEST_F(FragmentChainTest, init_and_populate_from_empty) { const auto base_constraints = make_constraints(0, {0}, {0x0a}); - EXPECT_OUTCOME_TRUE(scope, - Scope::with_ancestors( - RelayChainBlockInfo{ - .hash = fromNumber(1), - .number = 1, - .storage_root = fromNumber(2), - }, - base_constraints, - {}, - 4, - {})); + ASSERT_OUTCOME_SUCCESS(scope, + Scope::with_ancestors( + RelayChainBlockInfo{ + .hash = fromNumber(1), + .number = 1, + .storage_root = fromNumber(2), + }, + base_constraints, + {}, + 4, + {})); auto chain = FragmentChain::init(hasher_, scope, CandidateStorage{}); ASSERT_EQ(chain.best_chain_len(), 0); @@ -141,7 +142,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { {make_constraints( relay_parent_x_info.number, {relay_parent_x_info.number}, {0x0e}), make_constraints(relay_parent_y_info.number, {0}, {0x0a})}) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, wrong_constraints, {}, 4, ancestors)); @@ -166,7 +167,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { // Various depths { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, {}, 0, ancestors)); @@ -195,7 +196,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { } { // depth is 1, allows two candidates - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, {}, 1, ancestors)); @@ -224,7 +225,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { // depth is larger than 2, allows all three candidates for (size_t depth = 2; depth < 6; ++depth) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, {}, depth, ancestors)); @@ -256,12 +257,12 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { // be deleted since they form a chain with A. Vec ancestors_without_x = { relay_parent_y_info}; - EXPECT_OUTCOME_TRUE(scope, - Scope::with_ancestors(relay_parent_z_info, - base_constraints, - {}, - 4, - ancestors_without_x)); + ASSERT_OUTCOME_SUCCESS(scope, + Scope::with_ancestors(relay_parent_z_info, + base_constraints, + {}, + 4, + ancestors_without_x)); const auto chain = populate_chain_from_previous_storage(scope, storage); ASSERT_TRUE(chain.best_chain_vec().empty()); @@ -281,7 +282,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { { // Candidates A and B have relay parents out of scope. Candidate C will // also be deleted since it forms a chain with A and B. - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, {}, 4, {})); @@ -313,17 +314,18 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { {0x0c}, {0x0a}, relay_parent_z_info.number); - EXPECT_OUTCOME_TRUE(wrong_candidate_c_entry, - CandidateEntry::create( - network::candidateHash(*hasher_, wrong_candidate_c), - wrong_candidate_c, - wrong_pvd_c, - CandidateState::Backed, - hasher_)); + ASSERT_OUTCOME_SUCCESS( + wrong_candidate_c_entry, + CandidateEntry::create( + network::candidateHash(*hasher_, wrong_candidate_c), + wrong_candidate_c, + wrong_pvd_c, + CandidateState::Backed, + hasher_)); ASSERT_TRUE(modified_storage.add_candidate_entry(wrong_candidate_c_entry) .has_value()); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, {}, 4, ancestors)); @@ -365,18 +367,19 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { {0x0c}, {0x0d}, 0); - EXPECT_OUTCOME_TRUE(wrong_candidate_c_entry, - CandidateEntry::create( - network::candidateHash(*hasher_, wrong_candidate_c), - wrong_candidate_c, - wrong_pvd_c, - CandidateState::Backed, - hasher_)); + ASSERT_OUTCOME_SUCCESS( + wrong_candidate_c_entry, + CandidateEntry::create( + network::candidateHash(*hasher_, wrong_candidate_c), + wrong_candidate_c, + wrong_pvd_c, + CandidateState::Backed, + hasher_)); ASSERT_TRUE(modified_storage.add_candidate_entry(wrong_candidate_c_entry) .has_value()); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, {}, 4, ancestors)); @@ -410,19 +413,19 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { 0); const auto unconnected_candidate_c_hash = network::candidateHash(*hasher_, unconnected_candidate_c); - EXPECT_OUTCOME_TRUE(unconnected_candidate_c_entry, - CandidateEntry::create(unconnected_candidate_c_hash, - unconnected_candidate_c, - unconnected_pvd_c, - CandidateState::Backed, - hasher_)); + ASSERT_OUTCOME_SUCCESS(unconnected_candidate_c_entry, + CandidateEntry::create(unconnected_candidate_c_hash, + unconnected_candidate_c, + unconnected_pvd_c, + CandidateState::Backed, + hasher_)); ASSERT_TRUE( modified_storage.add_candidate_entry(unconnected_candidate_c_entry) .has_value()); { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, {}, 4, ancestors)); @@ -464,16 +467,16 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { const auto modified_candidate_a_hash = network::candidateHash(*hasher_, modified_candidate_a); - EXPECT_OUTCOME_TRUE(modified_candidate_a_entry, - CandidateEntry::create(modified_candidate_a_hash, - modified_candidate_a, - modified_pvd_a, - CandidateState::Backed, - hasher_)); + ASSERT_OUTCOME_SUCCESS(modified_candidate_a_entry, + CandidateEntry::create(modified_candidate_a_hash, + modified_candidate_a, + modified_pvd_a, + CandidateState::Backed, + hasher_)); ASSERT_TRUE(modified_storage.add_candidate_entry(modified_candidate_a_entry) .has_value()); { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors(relay_parent_z_info, base_constraints, @@ -510,12 +513,12 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { const auto wrong_candidate_c_hash = network::candidateHash(*hasher_, wrong_candidate_c); - EXPECT_OUTCOME_TRUE(wrong_candidate_c_entry, - CandidateEntry::create(wrong_candidate_c_hash, - wrong_candidate_c, - wrong_pvd_c, - CandidateState::Backed, - hasher_)); + ASSERT_OUTCOME_SUCCESS(wrong_candidate_c_entry, + CandidateEntry::create(wrong_candidate_c_hash, + wrong_candidate_c, + wrong_pvd_c, + CandidateState::Backed, + hasher_)); ASSERT_TRUE(modified_storage.add_candidate_entry(wrong_candidate_c_entry) .has_value()); @@ -524,7 +527,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { ASSERT_TRUE(FragmentChain::fork_selection_rule(wrong_candidate_c_hash, modified_candidate_a_hash)); { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors(relay_parent_z_info, base_constraints, @@ -579,7 +582,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { }}; for (const auto &pending : {test_case_0, test_case_1, test_case_2}) { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, pending, 3, ancestors)); @@ -599,7 +602,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { relay_parent_y_info}; { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors(relay_parent_z_info, base_constraints, @@ -620,7 +623,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { { // Even relay parents of pending availability candidates which are out of // scope cannot move backwards. - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, @@ -667,7 +670,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { // Check that D, F, A2 and B2 are kept as unconnected potential candidates. { { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_z_info, base_constraints, {}, 2, ancestors)); @@ -938,7 +941,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { } // Simulate the fact that candidates A, B, C are now pending availability. - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope2, Scope::with_ancestors(relay_parent_z_info, base_constraints, @@ -975,7 +978,7 @@ TEST_F(FragmentChainTest, test_populate_and_check_potential) { FragmentChainError::CANDIDATE_ALREADY_KNOWN); // Simulate the fact that candidates A, B and C have been included. - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope3, Scope::with_ancestors(relay_parent_z_info, make_constraints(0, {0}, {0x0d}), @@ -1027,7 +1030,7 @@ TEST_F(FragmentChainTest, .storage_root = fromNumber(0), }; - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_info, base_constraints, {}, max_depth, {})); @@ -1098,7 +1101,7 @@ TEST_F(FragmentChainTest, test_find_ancestor_path_and_find_backable_chain) { }; const auto base_constraints = make_constraints(0, {0}, required_parent); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope, Scope::with_ancestors( relay_parent_info, base_constraints, {}, max_depth, {})); @@ -1241,7 +1244,7 @@ TEST_F(FragmentChainTest, test_find_ancestor_path_and_find_backable_chain) { // Stop when we've found a candidate which is pending availability { - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( scope2, Scope::with_ancestors(relay_parent_info, base_constraints, diff --git a/test/core/parachain/grid_tracker.cpp b/test/core/parachain/grid_tracker.cpp index fbad8e3809..afa3b835e3 100644 --- a/test/core/parachain/grid_tracker.cpp +++ b/test/core/parachain/grid_tracker.cpp @@ -6,7 +6,6 @@ #include "parachain/backing/grid_tracker.hpp" #include "core/parachain/parachain_test_harness.hpp" -#include "utils/map.hpp" using namespace kagome::parachain::grid; @@ -917,89 +916,83 @@ TEST_F(GridTrackerTest, knowledge_rejects_conflicting_manifest) { { auto s = expected_manifest_summary; s.claimed_group_index = GroupIndex(1); - EXPECT_EC(knowledge.import_received(3, 2, fromNumber(1), s), - GridTracker::Error::CONFLICTING); + ASSERT_OUTCOME_ERROR(knowledge.import_received(3, 2, fromNumber(1), s), + GridTracker::Error::CONFLICTING); } // conflicting parent hash { auto s = expected_manifest_summary; s.claimed_parent_hash = fromNumber(3); - EXPECT_EC(knowledge.import_received(3, 2, fromNumber(1), s), - GridTracker::Error::CONFLICTING); + ASSERT_OUTCOME_ERROR(knowledge.import_received(3, 2, fromNumber(1), s), + GridTracker::Error::CONFLICTING); } // conflicting seconded statements bitfield { auto s = expected_manifest_summary; s.statement_knowledge.seconded_in_group.bits = {false, true, false}; - EXPECT_EC(knowledge.import_received(3, 2, fromNumber(1), s), - GridTracker::Error::CONFLICTING); + ASSERT_OUTCOME_ERROR(knowledge.import_received(3, 2, fromNumber(1), s), + GridTracker::Error::CONFLICTING); } // conflicting valid statements bitfield { auto s = expected_manifest_summary; s.statement_knowledge.validated_in_group.bits = {false, true, false}; - EXPECT_EC(knowledge.import_received(3, 2, fromNumber(1), s), - GridTracker::Error::CONFLICTING); + ASSERT_OUTCOME_ERROR(knowledge.import_received(3, 2, fromNumber(1), s), + GridTracker::Error::CONFLICTING); } } TEST_F(GridTrackerTest, reject_overflowing_manifests) { ReceivedManifests knowledge; - ASSERT_TRUE( - knowledge - .import_received(3, - 2, - fromNumber(1), - ManifestSummary{ - .claimed_parent_hash = fromNumber(0xA), - .claimed_group_index = GroupIndex(0), - .statement_knowledge = create_filter( - {{true, true, false}, {false, true, true}}), - }) - .has_value()); + ASSERT_OUTCOME_SUCCESS(knowledge.import_received( + 3, + 2, + fromNumber(1), + ManifestSummary{ + .claimed_parent_hash = fromNumber(0xA), + .claimed_group_index = GroupIndex(0), + .statement_knowledge = + create_filter({{true, true, false}, {false, true, true}}), + })); - ASSERT_TRUE( - knowledge - .import_received(3, - 2, - fromNumber(2), - ManifestSummary{ - .claimed_parent_hash = fromNumber(0xB), - .claimed_group_index = GroupIndex(0), - .statement_knowledge = create_filter( - {{true, false, true}, {false, true, true}}), - }) - .has_value()); + ASSERT_OUTCOME_SUCCESS(knowledge.import_received( + 3, + 2, + fromNumber(2), + ManifestSummary{ + .claimed_parent_hash = fromNumber(0xB), + .claimed_group_index = GroupIndex(0), + .statement_knowledge = + create_filter({{true, false, true}, {false, true, true}}), + })); // Reject a seconding validator that is already at the seconding limit. // Seconding counts for the validators should not be applied. - EXPECT_EC(knowledge.import_received( - 3, - 2, - fromNumber(3), - ManifestSummary{ - .claimed_parent_hash = fromNumber(0xC), - .claimed_group_index = GroupIndex(0), - .statement_knowledge = create_filter( - {{true, true, true}, {false, true, true}}), - }), - GridTracker::Error::SECONDING_OVERFLOW); - - // Don't reject validators that have seconded less than the limit so far. - ASSERT_TRUE( - knowledge - .import_received(3, + ASSERT_OUTCOME_ERROR(knowledge.import_received( + 3, 2, fromNumber(3), ManifestSummary{ .claimed_parent_hash = fromNumber(0xC), .claimed_group_index = GroupIndex(0), .statement_knowledge = create_filter( - {{false, true, true}, {false, true, true}}), - }) - .has_value()); + {{true, true, true}, {false, true, true}}), + }), + GridTracker::Error::SECONDING_OVERFLOW); + + // Don't reject validators that have seconded less than the limit so far. + ASSERT_OUTCOME_SUCCESS(knowledge.import_received( + 3, + 2, + fromNumber(3), + ManifestSummary{ + .claimed_parent_hash = fromNumber(0xC), + .claimed_group_index = GroupIndex(0), + .statement_knowledge = + create_filter({{false, true, true}, {false, true, true}}), + })); } diff --git a/test/core/parachain/parachain_test_harness.hpp b/test/core/parachain/parachain_test_harness.hpp index fdc71a7713..0e184f23fc 100644 --- a/test/core/parachain/parachain_test_harness.hpp +++ b/test/core/parachain/parachain_test_harness.hpp @@ -6,12 +6,9 @@ #include -#include "testutil/literals.hpp" -#include "testutil/outcome.hpp" -#include "testutil/prepare_loggers.hpp" +#include #include "crypto/hasher/hasher_impl.hpp" -#include "crypto/random_generator/boost_generator.hpp" #include "crypto/sr25519/sr25519_provider_impl.hpp" #include "crypto/type_hasher.hpp" #include "mock/core/blockchain/block_tree_mock.hpp" @@ -20,9 +17,8 @@ #include "parachain/validator/prospective_parachains/candidate_storage.hpp" #include "parachain/validator/signer.hpp" #include "runtime/runtime_api/parachain_host_types.hpp" -#include "scale/kagome_scale.hpp" -#include "scale/scale.hpp" -#include "testutil/scale_test_comparator.hpp" +#include "testutil/literals.hpp" +#include "testutil/prepare_loggers.hpp" using namespace kagome::primitives; using namespace kagome::parachain; diff --git a/test/core/parachain/prospective_parachains.cpp b/test/core/parachain/prospective_parachains.cpp index 80110241fd..d38b136f7e 100644 --- a/test/core/parachain/prospective_parachains.cpp +++ b/test/core/parachain/prospective_parachains.cpp @@ -241,7 +241,7 @@ class ProspectiveParachainsTest : public ProspectiveParachainsTestHarness { } } - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{ .new_head = {update.new_head}, .lost = update.lost, @@ -261,7 +261,7 @@ class ProspectiveParachainsTest : public ProspectiveParachainsTestHarness { void deactivate_leaf(const Hash &hash) { std::vector lost = {hash}; - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{ .new_head = {}, .lost = lost, @@ -1365,7 +1365,7 @@ TEST_F(ProspectiveParachainsTest, correctly_updates_leaves) { activate_leaf(leaf_b, test_state, ASYNC_BACKING_PARAMETERS); // Pass in an empty update. - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{ .new_head = std::nullopt, .lost = {}, @@ -1388,7 +1388,7 @@ TEST_F(ProspectiveParachainsTest, correctly_updates_leaves) { }; update.new_head.hash_opt = leaf_c.hash; - // ASSERT_OUTCOME_SUCCESS_TRY( + // ASSERT_OUTCOME_SUCCESS( // prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{ // .new_head = {update.new_head}, // .lost = update.lost, @@ -1398,7 +1398,7 @@ TEST_F(ProspectiveParachainsTest, correctly_updates_leaves) { } // Remove all remaining leaves. - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{ .new_head = {}, .lost = {leaf_a.hash, leaf_c.hash}, @@ -1421,7 +1421,7 @@ TEST_F(ProspectiveParachainsTest, correctly_updates_leaves) { }; update.new_head.hash_opt = leaf_a.hash; - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{ .new_head = {update.new_head}, .lost = update.lost, @@ -1430,7 +1430,7 @@ TEST_F(ProspectiveParachainsTest, correctly_updates_leaves) { // Remove the leaf again. Send some unnecessary hashes. { - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{ .new_head = {}, .lost = {leaf_a.hash, leaf_b.hash, leaf_c.hash}, @@ -1924,7 +1924,7 @@ TEST_F(ProspectiveParachainsTest, uses_ancestry_only_within_session) { }; update.new_head.hash_opt = hash; - ASSERT_OUTCOME_SUCCESS_TRY( + ASSERT_OUTCOME_SUCCESS( prospective_parachain_->onActiveLeavesUpdate(network::ExViewRef{ .new_head = {update.new_head}, .lost = update.lost, diff --git a/test/core/parachain/pvf_test.cpp b/test/core/parachain/pvf_test.cpp index 1a73d3c38f..619410aec1 100644 --- a/test/core/parachain/pvf_test.cpp +++ b/test/core/parachain/pvf_test.cpp @@ -6,10 +6,9 @@ #include -#include "gmock/gmock.h" -#include "mock/core/runtime/memory_provider_mock.hpp" -#include "mock/core/runtime/trie_storage_provider_mock.hpp" -#include "parachain/pvf/pvf_impl.hpp" +#include + +#include #include "crypto/hasher/hasher_impl.hpp" #include "mock/core/application/app_configuration_mock.hpp" @@ -26,13 +25,12 @@ #include "mock/core/runtime/runtime_properties_cache_mock.hpp" #include "mock/span.hpp" #include "parachain/pvf/pool.hpp" +#include "parachain/pvf/pvf_impl.hpp" #include "parachain/pvf/pvf_thread_pool.hpp" #include "parachain/pvf/pvf_worker_types.hpp" #include "parachain/types.hpp" #include "runtime/executor.hpp" -#include "runtime/instance_environment.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::TestThreadPool; @@ -155,7 +153,7 @@ class PvfTest : public testing::Test { scale::encode(Pvf::CandidateCommitments{}).value()); testing::MockFunction)> cb; EXPECT_CALL(cb, Call(_)).WillOnce([](outcome::result r) { - EXPECT_OUTCOME_TRUE_1(r); + EXPECT_OUTCOME_SUCCESS(r); }); pvf_->pvfValidate(pvd, pov, diff --git a/test/core/parachain/secure_mode.cpp b/test/core/parachain/secure_mode.cpp index d87c2ce649..d90cbc7ead 100644 --- a/test/core/parachain/secure_mode.cpp +++ b/test/core/parachain/secure_mode.cpp @@ -11,12 +11,12 @@ #include #include #include + #include +#include #include "parachain/pvf/secure_mode.hpp" -#include "testutil/outcome.hpp" - using namespace kagome::parachain; extern "C" int __lsan_is_turned_off(void) { @@ -36,7 +36,7 @@ void test_syscall_works(int call, Ts... args) { template void test_syscall_fails(int call, Ts... args) { EXPECT_EXIT(([=]() { - EXPECT_OUTCOME_TRUE_1(enableSeccomp()); + EXPECT_OUTCOME_SUCCESS(enableSeccomp()); std::ignore = ::syscall(call, args...); std::exit(0); }()), @@ -71,7 +71,7 @@ TEST(SecureMode, ChangeRootWorks) { auto dir = std::filesystem::temp_directory_path() / "kagome_secure_mode_test/chroot"; std::filesystem::create_directories(dir); - ASSERT_OUTCOME_SUCCESS_TRY(changeRoot(dir)); + ASSERT_OUTCOME_SUCCESS(changeRoot(dir)); ASSERT_EQ(std::filesystem::current_path(), "/"); ASSERT_EQ( std::distance(std::filesystem::directory_iterator{"/"}, @@ -131,6 +131,6 @@ TEST(SecureMode, DISABLED_LandlockWorks) { std::filesystem::create_directories(dir); std::filesystem::current_path(dir); accessFs(dir, true); - ASSERT_OUTCOME_SUCCESS_TRY(enableLandlock(dir)); + ASSERT_OUTCOME_SUCCESS(enableLandlock(dir)); accessFs(dir, false); } diff --git a/test/core/primitives/primitives_codec_test.cpp b/test/core/primitives/primitives_codec_test.cpp index d68740f01c..00a910cd2d 100644 --- a/test/core/primitives/primitives_codec_test.cpp +++ b/test/core/primitives/primitives_codec_test.cpp @@ -6,6 +6,8 @@ #include +#include + #include "common/blob.hpp" #include "primitives/block.hpp" #include "primitives/block_id.hpp" @@ -15,7 +17,6 @@ #include "primitives/transaction_validity.hpp" #include "primitives/version.hpp" #include "scale/scale.hpp" -#include "testutil/outcome.hpp" #include "testutil/primitives/mp_utils.hpp" using kagome::common::Blob; @@ -100,8 +101,8 @@ class Primitives : public testing::Test { * @then decoded block is equal to predefined block */ TEST_F(Primitives, EncodeBlockHeaderSuccess) { - EXPECT_OUTCOME_TRUE(val, encode(block_header_)); - EXPECT_OUTCOME_TRUE(decoded_header, decode(val)); + ASSERT_OUTCOME_SUCCESS(val, encode(block_header_)); + ASSERT_OUTCOME_SUCCESS(decoded_header, decode(val)); ASSERT_EQ(block_header_, decoded_header); } @@ -111,8 +112,8 @@ TEST_F(Primitives, EncodeBlockHeaderSuccess) { * @then the same expected buffer obtained {12, 1, 2, 3} */ TEST_F(Primitives, EncodeExtrinsicSuccess) { - EXPECT_OUTCOME_TRUE(val, encode(extrinsic_)); - EXPECT_OUTCOME_TRUE(decoded_extrinsic, decode(val)); + ASSERT_OUTCOME_SUCCESS(val, encode(extrinsic_)); + ASSERT_OUTCOME_SUCCESS(decoded_extrinsic, decode(val)); ASSERT_EQ(extrinsic_, decoded_extrinsic); } @@ -122,8 +123,8 @@ TEST_F(Primitives, EncodeExtrinsicSuccess) { * @then expected result obtained */ TEST_F(Primitives, EncodeBlockSuccess) { - EXPECT_OUTCOME_TRUE(res, encode(block_)); - EXPECT_OUTCOME_TRUE(decoded_block, decode(res)); + ASSERT_OUTCOME_SUCCESS(res, encode(block_)); + ASSERT_OUTCOME_SUCCESS(decoded_block, decode(res)); ASSERT_EQ(block_, decoded_block); } @@ -135,8 +136,8 @@ TEST_F(Primitives, EncodeBlockSuccess) { * @then obtained result equal to predefined match */ TEST_F(Primitives, EncodeVersionSuccess) { - EXPECT_OUTCOME_TRUE(val, encode(version_)); - EXPECT_OUTCOME_TRUE(decoded_version, decode(val)); + ASSERT_OUTCOME_SUCCESS(val, encode(version_)); + ASSERT_OUTCOME_SUCCESS(decoded_version, decode(val)); ASSERT_EQ(decoded_version, version_); } @@ -148,8 +149,8 @@ TEST_F(Primitives, EncodeVersionSuccess) { * @then obtained result matches predefined value */ TEST_F(Primitives, EncodeBlockIdHash256Success) { - EXPECT_OUTCOME_TRUE(val, encode(block_id_hash_)) - EXPECT_OUTCOME_TRUE(decoded_block_id, decode(val)); + ASSERT_OUTCOME_SUCCESS(val, encode(block_id_hash_)); + ASSERT_OUTCOME_SUCCESS(decoded_block_id, decode(val)); ASSERT_EQ(decoded_block_id, block_id_hash_); } @@ -159,8 +160,8 @@ TEST_F(Primitives, EncodeBlockIdHash256Success) { * @then obtained result matches predefined value */ TEST_F(Primitives, EncodeBlockIdBlockNumberSuccess) { - EXPECT_OUTCOME_TRUE(val, encode(block_id_number_)) - EXPECT_OUTCOME_TRUE(decoded_block_id, decode(val)); + ASSERT_OUTCOME_SUCCESS(val, encode(block_id_number_)); + ASSERT_OUTCOME_SUCCESS(decoded_block_id, decode(val)); ASSERT_EQ(decoded_block_id, block_id_number_); } @@ -173,8 +174,8 @@ TEST_F(Primitives, EncodeBlockIdBlockNumberSuccess) { */ TEST_F(Primitives, EncodeTransactionValidityInvalidSuccess) { InvalidTransaction invalid{InvalidTransaction::Call}; - EXPECT_OUTCOME_TRUE(val, encode(invalid)) - EXPECT_OUTCOME_TRUE(decoded_validity, decode(val)); + ASSERT_OUTCOME_SUCCESS(val, encode(invalid)); + ASSERT_OUTCOME_SUCCESS(decoded_validity, decode(val)); ASSERT_EQ(decoded_validity, invalid); } @@ -185,8 +186,8 @@ TEST_F(Primitives, EncodeTransactionValidityInvalidSuccess) { */ TEST_F(Primitives, EncodeTransactionValidityUnknown) { UnknownTransaction unknown{UnknownTransaction::Kind::Custom, 42}; - EXPECT_OUTCOME_TRUE(val, encode(unknown)) - EXPECT_OUTCOME_TRUE(decoded_validity, decode(val)); + ASSERT_OUTCOME_SUCCESS(val, encode(unknown)); + ASSERT_OUTCOME_SUCCESS(decoded_validity, decode(val)); ASSERT_EQ(decoded_validity, unknown); } @@ -197,8 +198,8 @@ TEST_F(Primitives, EncodeTransactionValidityUnknown) { */ TEST_F(Primitives, EncodeTransactionValiditySuccess) { ValidTransaction t = valid_transaction_; // make it variant type - EXPECT_OUTCOME_TRUE(val, encode(t)) - EXPECT_OUTCOME_TRUE(decoded_validity, decode(val)); + ASSERT_OUTCOME_SUCCESS(val, encode(t)); + ASSERT_OUTCOME_SUCCESS(decoded_validity, decode(val)); ASSERT_EQ(decoded_validity, valid_transaction_); } @@ -212,9 +213,9 @@ TEST_F(Primitives, EncodeDecodeAuthorityIdsSuccess) { id1.fill(1u); id2.fill(2u); std::vector original{id1, id2}; - EXPECT_OUTCOME_TRUE(res, encode(original)) + ASSERT_OUTCOME_SUCCESS(res, encode(original)); - EXPECT_OUTCOME_TRUE(decoded, decode>(res)) + ASSERT_OUTCOME_SUCCESS(decoded, decode>(res)); ASSERT_EQ(original, decoded); } @@ -225,19 +226,21 @@ TEST_F(Primitives, EncodeInherentSampleFromSubstrate) { 'e', 's', 't', 'i', 'n', 'h', '1', '\x10', '\a', '\0', '\0', '\0'}; - EXPECT_OUTCOME_TRUE(test_id1, InherentIdentifier::fromString("testinh0")); + ASSERT_OUTCOME_SUCCESS(test_id1, InherentIdentifier::fromString("testinh0")); std::vector data1{1, 2, 3}; - EXPECT_OUTCOME_TRUE(test_id2, InherentIdentifier::fromString("testinh1")); + ASSERT_OUTCOME_SUCCESS(test_id2, InherentIdentifier::fromString("testinh1")); uint32_t data2 = 7; auto encoded_buf = Buffer().put(encoded_str); - EXPECT_OUTCOME_TRUE(dec_data, decode(encoded_buf)); + ASSERT_OUTCOME_SUCCESS(dec_data, decode(encoded_buf)); - EXPECT_OUTCOME_TRUE(dec_data1, dec_data.getData(test_id1)); + ASSERT_OUTCOME_SUCCESS(dec_data1, + dec_data.getData(test_id1)); EXPECT_EQ(data1, dec_data1); - EXPECT_OUTCOME_TRUE(dec_data2, dec_data.getData(test_id2)); + ASSERT_OUTCOME_SUCCESS(dec_data2, + dec_data.getData(test_id2)); EXPECT_EQ(data2, dec_data2); } @@ -249,16 +252,16 @@ TEST_F(Primitives, EncodeInherentSampleFromSubstrate) { TEST_F(Primitives, EncodeInherentDataSuccess) { using array = std::array; InherentData data; - EXPECT_OUTCOME_TRUE(id1, InherentIdentifier::fromString("testinh0")); - EXPECT_OUTCOME_TRUE(id2, InherentIdentifier::fromString("testinh1")); + ASSERT_OUTCOME_SUCCESS(id1, InherentIdentifier::fromString("testinh0")); + ASSERT_OUTCOME_SUCCESS(id2, InherentIdentifier::fromString("testinh1")); InherentIdentifier id3{array{3}}; std::vector data1{1, 2, 3}; uint32_t data2 = 7; Buffer data3{1, 2, 3, 4}; - EXPECT_OUTCOME_TRUE_void(r1, data.putData(id1, data1)); - EXPECT_OUTCOME_TRUE_void(r2, data.putData(id2, data2)); - EXPECT_OUTCOME_TRUE_void(r3, data.putData(id3, data3)); - EXPECT_OUTCOME_FALSE_void(_, data.putData(id1, data2)); + ASSERT_OUTCOME_SUCCESS(data.putData(id1, data1)); + ASSERT_OUTCOME_SUCCESS(data.putData(id2, data2)); + ASSERT_OUTCOME_SUCCESS(data.putData(id3, data3)); + ASSERT_OUTCOME_ERROR(data.putData(id1, data2)); ASSERT_EQ(data.getData(id1).value(), data1); ASSERT_EQ(data.getData(id2).value(), data2); @@ -268,8 +271,8 @@ TEST_F(Primitives, EncodeInherentDataSuccess) { data.replaceData(id3, data4); ASSERT_EQ(data.getData(id3).value(), data4); - EXPECT_OUTCOME_TRUE(enc_data, encode(data)) - EXPECT_OUTCOME_TRUE(dec_data, decode(enc_data)) + ASSERT_OUTCOME_SUCCESS(enc_data, encode(data)); + ASSERT_OUTCOME_SUCCESS(dec_data, decode(enc_data)); ASSERT_EQ(dec_data.getData(id1).value(), data1); diff --git a/test/core/primitives/ss58_codec_test.cpp b/test/core/primitives/ss58_codec_test.cpp index 6eda9a879b..498be3167f 100644 --- a/test/core/primitives/ss58_codec_test.cpp +++ b/test/core/primitives/ss58_codec_test.cpp @@ -6,9 +6,10 @@ #include +#include + #include "crypto/hasher/hasher_impl.hpp" #include "primitives/ss58_codec.hpp" -#include "testutil/outcome.hpp" using kagome::crypto::HasherImpl; diff --git a/test/core/runtime/binaryen/block_builder_api_test.cpp b/test/core/runtime/binaryen/block_builder_api_test.cpp index c3ab1d339c..bbf94306ca 100644 --- a/test/core/runtime/binaryen/block_builder_api_test.cpp +++ b/test/core/runtime/binaryen/block_builder_api_test.cpp @@ -6,13 +6,14 @@ #include +#include + #include "core/runtime/binaryen/binaryen_runtime_test.hpp" #include "host_api/impl/host_api_impl.hpp" #include "mock/core/storage/trie/trie_storage_mock.hpp" #include "runtime/binaryen/memory_impl.hpp" #include "runtime/common/trie_storage_provider_impl.hpp" #include "runtime/runtime_api/impl/block_builder.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::common::Buffer; @@ -52,8 +53,8 @@ class BlockBuilderApiTest : public BinaryenRuntimeTest { TEST_F(BlockBuilderApiTest, CheckInherents) { prepareEphemeralStorageExpects(); SCOPED_TRACE("CheckInherents"); - EXPECT_OUTCOME_TRUE_1(builder_->check_inherents( - createBlock("block_42"_hash256, 42), InherentData{})) + EXPECT_OUTCOME_SUCCESS(builder_->check_inherents( + createBlock("block_42"_hash256, 42), InherentData{})); } /** @@ -68,7 +69,7 @@ TEST_F(BlockBuilderApiTest, ApplyExtrinsic) { createBlock("block_hash_43"_hash256, 43); auto ctx = ctx_factory_->persistentAt("block_hash_43"_hash256, std::nullopt).value(); - EXPECT_OUTCOME_FALSE_1( + EXPECT_OUTCOME_ERROR( builder_->apply_extrinsic(ctx, Extrinsic{Buffer{1, 2, 3}})); } @@ -78,8 +79,9 @@ TEST_F(BlockBuilderApiTest, ApplyExtrinsic) { * @then the result of the check is obtained given that the provided arguments * were valid */ -TEST_F(BlockBuilderApiTest, DISABLED_RandomSeed){ - EXPECT_OUTCOME_FALSE_1(builder_->random_seed("block_hash"_hash256))} +TEST_F(BlockBuilderApiTest, DISABLED_RandomSeed) { + EXPECT_OUTCOME_ERROR(builder_->random_seed("block_hash"_hash256)); +} /** * @given block builder @@ -93,7 +95,7 @@ TEST_F(BlockBuilderApiTest, InherentExtrinsics) { createBlock("block_hash_44"_hash256, 44); auto ctx = ctx_factory_->persistentAt("block_hash_44"_hash256, std::nullopt).value(); - EXPECT_OUTCOME_FALSE_1(builder_->inherent_extrinsics(ctx, InherentData{})); + EXPECT_OUTCOME_ERROR(builder_->inherent_extrinsics(ctx, InherentData{})); } /** @@ -107,5 +109,5 @@ TEST_F(BlockBuilderApiTest, DISABLED_FinalizeBlock) { createBlock("block_hash"_hash256, 42); auto ctx = ctx_factory_->persistentAt("block_hash"_hash256, std::nullopt).value(); - EXPECT_OUTCOME_FALSE_1(builder_->finalize_block(ctx)); + EXPECT_OUTCOME_ERROR(builder_->finalize_block(ctx)); } diff --git a/test/core/runtime/binaryen/metadata_test.cpp b/test/core/runtime/binaryen/metadata_test.cpp index 3bf9cabde9..193d48f683 100644 --- a/test/core/runtime/binaryen/metadata_test.cpp +++ b/test/core/runtime/binaryen/metadata_test.cpp @@ -13,7 +13,6 @@ #include "mock/core/runtime/runtime_upgrade_tracker_mock.hpp" #include "runtime/binaryen/memory_impl.hpp" #include "runtime/runtime_api/impl/metadata.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using ::testing::_; diff --git a/test/core/runtime/binaryen/parachain_test.cpp b/test/core/runtime/binaryen/parachain_test.cpp index ae5e04384c..c2843208ea 100644 --- a/test/core/runtime/binaryen/parachain_test.cpp +++ b/test/core/runtime/binaryen/parachain_test.cpp @@ -8,10 +8,11 @@ #include +#include + #include "core/runtime/binaryen/binaryen_runtime_test.hpp" #include "host_api/impl/host_api_impl.hpp" #include "runtime/binaryen/memory_impl.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::common::Buffer; diff --git a/test/core/runtime/binaryen/tagged_transaction_queue_test.cpp b/test/core/runtime/binaryen/tagged_transaction_queue_test.cpp index 7e5c45a2ae..84af604605 100644 --- a/test/core/runtime/binaryen/tagged_transaction_queue_test.cpp +++ b/test/core/runtime/binaryen/tagged_transaction_queue_test.cpp @@ -8,11 +8,11 @@ #include +#include + #include "core/runtime/binaryen/binaryen_runtime_test.hpp" #include "mock/core/blockchain/block_tree_mock.hpp" #include "testutil/lazy.hpp" -#include "testutil/outcome.hpp" -#include "testutil/runtime/common/basic_code_provider.hpp" using namespace testing; @@ -51,6 +51,6 @@ TEST_F(TTQTest, DISABLED_ValidateTransactionSuccess) { // we test now that the functions above are called sequentially // unfortunately, we don't have valid data for validate_transaction to succeed - EXPECT_OUTCOME_TRUE_1( + EXPECT_OUTCOME_SUCCESS( ttq_->validate_transaction(TransactionSource::External, ext)); } diff --git a/test/core/runtime/executor_test.cpp b/test/core/runtime/executor_test.cpp index e7ce2deddf..16cf86f9eb 100644 --- a/test/core/runtime/executor_test.cpp +++ b/test/core/runtime/executor_test.cpp @@ -7,8 +7,10 @@ #include "runtime/executor.hpp" #include -#include "filesystem/common.hpp" +#include + +#include "filesystem/common.hpp" #include "mock/core/blockchain/block_tree_mock.hpp" #include "mock/core/host_api/host_api_mock.hpp" #include "mock/core/runtime/memory_provider_mock.hpp" @@ -20,7 +22,6 @@ #include "mock/core/storage/trie/trie_batches_mock.hpp" #include "mock/core/storage/trie/trie_storage_mock.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" #include "testutil/runtime/common/basic_code_provider.hpp" #include "testutil/runtime/memory.hpp" @@ -152,60 +153,60 @@ TEST_F(ExecutorTest, LatestStateSwitchesCorrectly) { kagome::primitives::BlockInfo block_info3{44, "block_hash3"_hash256}; Buffer enc_args{scale::encode(std::tuple(2, 3)).value()}; - EXPECT_OUTCOME_TRUE(ctx1, - prepareCall(block_info1, - "state_hash1"_hash256, - CallType::Persistent, - enc_args, - 5)); + ASSERT_OUTCOME_SUCCESS(ctx1, + prepareCall(block_info1, + "state_hash1"_hash256, + CallType::Persistent, + enc_args, + 5)); auto res = executor.call(ctx1, "addTwo", 2, 3).value(); EXPECT_EQ(res, 5); enc_args = scale::encode(std::tuple(7, 10)).value(); - EXPECT_OUTCOME_TRUE(ctx2, - prepareCall(block_info1, - "state_hash2"_hash256, - CallType::Ephemeral, - enc_args, - 17)); - EXPECT_OUTCOME_TRUE(res2, executor.call(ctx2, "addTwo", 7, 10)); + ASSERT_OUTCOME_SUCCESS(ctx2, + prepareCall(block_info1, + "state_hash2"_hash256, + CallType::Ephemeral, + enc_args, + 17)); + ASSERT_OUTCOME_SUCCESS(res2, executor.call(ctx2, "addTwo", 7, 10)); ASSERT_EQ(res2, 17); enc_args = scale::encode(std::tuple(0, 0)).value(); - EXPECT_OUTCOME_TRUE(ctx3, - prepareCall(block_info1, - "state_hash2"_hash256, - CallType::Persistent, - enc_args, - 0)); + ASSERT_OUTCOME_SUCCESS(ctx3, + prepareCall(block_info1, + "state_hash2"_hash256, + CallType::Persistent, + enc_args, + 0)); EXPECT_EQ(executor.call(ctx3, "addTwo", 0, 0).value(), 0); enc_args = scale::encode(std::tuple(7, 10)).value(); - EXPECT_OUTCOME_TRUE(ctx4, - prepareCall(block_info1, - "state_hash3"_hash256, - CallType::Ephemeral, - enc_args, - 17)); - EXPECT_OUTCOME_TRUE(res4, executor.call(ctx4, "addTwo", 7, 10)); + ASSERT_OUTCOME_SUCCESS(ctx4, + prepareCall(block_info1, + "state_hash3"_hash256, + CallType::Ephemeral, + enc_args, + 17)); + ASSERT_OUTCOME_SUCCESS(res4, executor.call(ctx4, "addTwo", 7, 10)); ASSERT_EQ(res4, 17); enc_args = scale::encode(std::tuple(-5, 5)).value(); - EXPECT_OUTCOME_TRUE(ctx5, - prepareCall(block_info2, - "state_hash4"_hash256, - CallType::Persistent, - enc_args, - 0)); + ASSERT_OUTCOME_SUCCESS(ctx5, + prepareCall(block_info2, + "state_hash4"_hash256, + CallType::Persistent, + enc_args, + 0)); EXPECT_EQ(executor.call(ctx5, "addTwo", -5, 5).value(), 0); enc_args = scale::encode(std::tuple(7, 10)).value(); - EXPECT_OUTCOME_TRUE(ctx6, - prepareCall(block_info2, - "state_hash5"_hash256, - CallType::Ephemeral, - enc_args, - 17)); - EXPECT_OUTCOME_TRUE(res6, executor.call(ctx6, "addTwo", 7, 10)); + ASSERT_OUTCOME_SUCCESS(ctx6, + prepareCall(block_info2, + "state_hash5"_hash256, + CallType::Ephemeral, + enc_args, + 17)); + ASSERT_OUTCOME_SUCCESS(res6, executor.call(ctx6, "addTwo", 7, 10)); ASSERT_EQ(res6, 17); } diff --git a/test/core/runtime/instance_pool_test.cpp b/test/core/runtime/instance_pool_test.cpp index bb07608788..65b3524c75 100644 --- a/test/core/runtime/instance_pool_test.cpp +++ b/test/core/runtime/instance_pool_test.cpp @@ -9,8 +9,9 @@ #include #include +#include + #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" #include "runtime/common/runtime_instances_pool.hpp" @@ -82,7 +83,7 @@ TEST(InstancePoolTest, HeavilyMultithreadedCompilation) { std::vector threads; for (int i = 0; i < THREAD_NUM; i++) { threads.emplace_back([&pool, &code, i]() { - ASSERT_OUTCOME_SUCCESS_TRY(pool->instantiateFromCode( + ASSERT_OUTCOME_SUCCESS(pool->instantiateFromCode( make_code_hash(i % POOL_SIZE), [&] { return code; }, {})); }); } @@ -95,7 +96,7 @@ TEST(InstancePoolTest, HeavilyMultithreadedCompilation) { // check that all POOL_SIZE instances are in cache for (int i = 0; i < POOL_SIZE; i++) { - ASSERT_OUTCOME_SUCCESS_TRY(pool->instantiateFromCode( + ASSERT_OUTCOME_SUCCESS(pool->instantiateFromCode( make_code_hash(i), []() -> decltype(code) { throw std::logic_error{"already compiled"}; }, {})); diff --git a/test/core/runtime/runtime_test_base.hpp b/test/core/runtime/runtime_test_base.hpp index 9958135269..739546394a 100644 --- a/test/core/runtime/runtime_test_base.hpp +++ b/test/core/runtime/runtime_test_base.hpp @@ -8,7 +8,6 @@ #include -#include #include #include @@ -51,7 +50,6 @@ #include "runtime/wabt/instrument.hpp" #include "storage/in_memory/in_memory_storage.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/runtime/common/basic_code_provider.hpp" using kagome::application::AppConfigurationMock; diff --git a/test/core/runtime/runtime_upgrade_tracker_test.cpp b/test/core/runtime/runtime_upgrade_tracker_test.cpp index acc90fe7d8..e41d1a0943 100644 --- a/test/core/runtime/runtime_upgrade_tracker_test.cpp +++ b/test/core/runtime/runtime_upgrade_tracker_test.cpp @@ -8,11 +8,12 @@ #include +#include + #include "mock/core/blockchain/block_tree_mock.hpp" #include "mock/core/storage/spaced_storage_mock.hpp" #include "storage/in_memory/in_memory_storage.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::common::Hash256; @@ -107,7 +108,7 @@ class RuntimeUpgradeTrackerTest : public testing::Test { TEST_F(RuntimeUpgradeTrackerTest, NullBlockTree) { EXPECT_CALL(*block_tree_, getBlockHeader({block_42.hash})) .WillOnce(testing::Return(block_42_header)); - EXPECT_OUTCOME_TRUE(state, tracker_->getLastCodeUpdateState(block_42)); + ASSERT_OUTCOME_SUCCESS(state, tracker_->getLastCodeUpdateState(block_42)); ASSERT_EQ(state, block_42_header.state_root); } @@ -123,7 +124,7 @@ TEST_F(RuntimeUpgradeTrackerTest, EmptyUpdatesCache) { EXPECT_CALL(*block_tree_, getBlockHeader(block_42.hash)) .WillOnce(testing::Return(block_42_header)); - EXPECT_OUTCOME_TRUE(state, tracker_->getLastCodeUpdateState(block_42)); + ASSERT_OUTCOME_SUCCESS(state, tracker_->getLastCodeUpdateState(block_42)); ASSERT_EQ(state, block_42_header.state_root); } @@ -137,12 +138,12 @@ TEST_F(RuntimeUpgradeTrackerTest, AutoUpgradeAfterEmpty) { EXPECT_CALL(*block_tree_, getBlockHeader(block_2.hash)) .WillRepeatedly(testing::Return(block_2_header)); - EXPECT_OUTCOME_TRUE(state, tracker_->getLastCodeUpdateState(block_2)); + ASSERT_OUTCOME_SUCCESS(state, tracker_->getLastCodeUpdateState(block_2)); ASSERT_EQ(state, block_2_header.state_root); EXPECT_CALL(*block_tree_, getLastFinalized()) .WillRepeatedly(testing::Return(block_42)); - EXPECT_OUTCOME_TRUE(state42, tracker_->getLastCodeUpdateState(block_42)); + ASSERT_OUTCOME_SUCCESS(state42, tracker_->getLastCodeUpdateState(block_42)); // picking 2 instead of 42 because that's the latest known upgrade ASSERT_EQ(state42, block_2_header.state_root); } @@ -156,7 +157,8 @@ TEST_F(RuntimeUpgradeTrackerTest, CorrectUpgradeScenario) { EXPECT_CALL(*block_tree_, getBlockHeader(genesis_block.hash)) .WillRepeatedly(testing::Return(genesis_block_header)); - EXPECT_OUTCOME_TRUE(state1, tracker_->getLastCodeUpdateState(genesis_block)); + ASSERT_OUTCOME_SUCCESS(state1, + tracker_->getLastCodeUpdateState(genesis_block)); ASSERT_EQ(state1, genesis_block_header.state_root); // then we upgrade in block #42 @@ -167,7 +169,7 @@ TEST_F(RuntimeUpgradeTrackerTest, CorrectUpgradeScenario) { EXPECT_CALL(*block_tree_, getBlockHeader(block_42.hash)) .WillRepeatedly(testing::Return(block_42_header)); - EXPECT_OUTCOME_TRUE(state42, tracker_->getLastCodeUpdateState(block_41)); + ASSERT_OUTCOME_SUCCESS(state42, tracker_->getLastCodeUpdateState(block_41)); ASSERT_EQ(state42, genesis_block_header.state_root); // during execution of 42 we upgrade the code sub_engine_->notify( @@ -183,11 +185,11 @@ TEST_F(RuntimeUpgradeTrackerTest, CorrectUpgradeScenario) { EXPECT_CALL(*block_tree_, getBlockHeader(block_42.hash)) .WillRepeatedly(testing::Return(block_42_header)); - EXPECT_OUTCOME_TRUE(state43, tracker_->getLastCodeUpdateState(block_42)); + ASSERT_OUTCOME_SUCCESS(state43, tracker_->getLastCodeUpdateState(block_42)); ASSERT_EQ(state43, block_42_header.state_root); // then block #44 - EXPECT_OUTCOME_TRUE(state44, tracker_->getLastCodeUpdateState(block_43)); + ASSERT_OUTCOME_SUCCESS(state44, tracker_->getLastCodeUpdateState(block_43)); ASSERT_EQ(state44, block_42_header.state_root); } @@ -223,7 +225,7 @@ TEST_F(RuntimeUpgradeTrackerTest, CodeSubstituteAndStore) { .value(); tracker_->subscribeToBlockchainEvents(sub_engine_); - EXPECT_OUTCOME_TRUE(state2, tracker_->getLastCodeUpdateState(block2)); + ASSERT_OUTCOME_SUCCESS(state2, tracker_->getLastCodeUpdateState(block2)); ASSERT_EQ(state2, block2_header.state_root); // reset tracker @@ -233,7 +235,7 @@ TEST_F(RuntimeUpgradeTrackerTest, CodeSubstituteAndStore) { tracker_->subscribeToBlockchainEvents(sub_engine_); auto block3 = makeBlockInfo(5203204); - EXPECT_OUTCOME_TRUE(state3, tracker_->getLastCodeUpdateState(block3)); + ASSERT_OUTCOME_SUCCESS(state3, tracker_->getLastCodeUpdateState(block3)); ASSERT_EQ(state3, block2_header.state_root); } @@ -255,7 +257,7 @@ TEST_F(RuntimeUpgradeTrackerTest, UpgradeAfterCodeSubstitute) { EXPECT_CALL(*block_tree_, getBlockHeader(block1.hash)) .WillOnce(testing::Return(block1_header)); - EXPECT_OUTCOME_TRUE_1(tracker_->getLastCodeUpdateState(block1)); + EXPECT_OUTCOME_SUCCESS(tracker_->getLastCodeUpdateState(block1)); // @see https://polkadot.subscan.io/event?module=system&event=codeupdated auto block2 = makeBlockInfo(5661442); @@ -266,11 +268,11 @@ TEST_F(RuntimeUpgradeTrackerTest, UpgradeAfterCodeSubstitute) { kagome::primitives::events::ChainEventType::kNewRuntime, kagome::primitives::events::NewRuntimeEventParams{block2.hash}); - EXPECT_OUTCOME_TRUE(state2, tracker_->getLastCodeUpdateState(block2)); + ASSERT_OUTCOME_SUCCESS(state2, tracker_->getLastCodeUpdateState(block2)); ASSERT_EQ(state2, block2_header.state_root); auto block3 = makeBlockInfo(5661443); - EXPECT_OUTCOME_TRUE(state3, tracker_->getLastCodeUpdateState(block3)); + ASSERT_OUTCOME_SUCCESS(state3, tracker_->getLastCodeUpdateState(block3)); ASSERT_EQ(state3, block2_header.state_root); } @@ -300,8 +302,8 @@ TEST_F(RuntimeUpgradeTrackerTest, OrphanBlock) { EXPECT_CALL(*block_tree_, hasDirectChain(block_34f2.hash, block_35f1.hash)) .WillOnce(testing::Return(false)); - EXPECT_OUTCOME_TRUE(state_for_35f1, - tracker_->getLastCodeUpdateState(block_35f1)); + ASSERT_OUTCOME_SUCCESS(state_for_35f1, + tracker_->getLastCodeUpdateState(block_35f1)); // we have no information on upgrades, related to this block, so we fall back // to returning its state root @@ -318,8 +320,8 @@ TEST_F(RuntimeUpgradeTrackerTest, OrphanBlock) { .WillOnce(testing::Return(false)); EXPECT_CALL(*block_tree_, hasDirectChain(block_33f1.hash, block_35f1.hash)) .WillOnce(testing::Return(true)); - EXPECT_OUTCOME_TRUE(state_for_35f1_again, - tracker_->getLastCodeUpdateState(block_35f1)); + ASSERT_OUTCOME_SUCCESS(state_for_35f1_again, + tracker_->getLastCodeUpdateState(block_35f1)); // now we pick the runtime upgrade ASSERT_EQ(state_for_35f1_again, block_33f1_header.state_root); diff --git a/test/core/runtime/stack_limiter_test.cpp b/test/core/runtime/stack_limiter_test.cpp index 16eaf29e53..9f90453a3f 100644 --- a/test/core/runtime/stack_limiter_test.cpp +++ b/test/core/runtime/stack_limiter_test.cpp @@ -14,13 +14,13 @@ #include #include #include +#include #include "common/bytestr.hpp" #include "log/logger.hpp" #include "runtime/wabt/instrument.hpp" #include "runtime/wabt/stack_limiter.hpp" #include "runtime/wabt/util.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" static constexpr uint32_t ACTIVATION_FRAME_COST = 2; @@ -51,12 +51,12 @@ void expectWasm(const wabt::Module &actual, std::string_view expected) { uint32_t compute_cost(std::string_view data) { auto module = kagome::runtime::fromWat(data); - EXPECT_OUTCOME_TRUE(cost, - kagome::runtime::detail::compute_stack_cost( - kagome::log::createLogger("StackLimiterTest"), - *module->funcs[0], - *module)); - return cost; + EXPECT_OUTCOME_SUCCESS(cost, + kagome::runtime::detail::compute_stack_cost( + kagome::log::createLogger("StackLimiterTest"), + *module->funcs[0], + *module)); + return cost.value(); } TEST(StackLimiterTest, simple_test) { @@ -191,7 +191,7 @@ TEST_P(StackLimiterCompareTest, output_matches_expected) { auto fixture_wasm = kagome::runtime::watToWasm(fixture_wat); auto expected_module = kagome::runtime::watToModule(expected_wat); - EXPECT_OUTCOME_TRUE( + ASSERT_OUTCOME_SUCCESS( result_wasm, kagome::runtime::instrumentWithStackLimiter(fixture_wasm, 1024)); diff --git a/test/core/runtime/storage_code_provider_test.cpp b/test/core/runtime/storage_code_provider_test.cpp index e5dd1bbd59..c1480dbda4 100644 --- a/test/core/runtime/storage_code_provider_test.cpp +++ b/test/core/runtime/storage_code_provider_test.cpp @@ -8,6 +8,8 @@ #include +#include + #include "mock/core/application/chain_spec_mock.hpp" #include "mock/core/runtime/runtime_upgrade_tracker_mock.hpp" #include "mock/core/storage/trie/trie_batches_mock.hpp" @@ -15,7 +17,6 @@ #include "primitives/common.hpp" #include "storage/predefined_keys.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using namespace kagome; // NOLINT @@ -69,8 +70,8 @@ TEST_F(StorageCodeProviderTest, GetCodeWhenNoStorageUpdates) { std::make_shared()); // when - EXPECT_OUTCOME_TRUE(obtained_state_code, - wasm_provider->getCodeAt(first_state_root)); + ASSERT_OUTCOME_SUCCESS(obtained_state_code, + wasm_provider->getCodeAt(first_state_root)); // then EXPECT_EQ(*obtained_state_code, state_code_); @@ -111,8 +112,8 @@ TEST_F(StorageCodeProviderTest, GetCodeWhenStorageUpdates) { })); // when - EXPECT_OUTCOME_TRUE(obtained_state_code, - wasm_provider->getCodeAt(second_state_root)); + ASSERT_OUTCOME_SUCCESS(obtained_state_code, + wasm_provider->getCodeAt(second_state_root)); // then ASSERT_EQ(*obtained_state_code, new_state_code); diff --git a/test/core/runtime/trie_storage_provider_test.cpp b/test/core/runtime/trie_storage_provider_test.cpp index 20429dfa56..b229540e3a 100644 --- a/test/core/runtime/trie_storage_provider_test.cpp +++ b/test/core/runtime/trie_storage_provider_test.cpp @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "runtime/common/trie_storage_provider_impl.hpp" + #include -#include "runtime/common/trie_storage_provider_impl.hpp" +#include #include "common/buffer.hpp" #include "mock/core/storage/trie_pruner/trie_pruner_mock.hpp" @@ -18,7 +20,6 @@ #include "storage/trie/serialization/polkadot_codec.hpp" #include "storage/trie/serialization/trie_serializer_impl.hpp" #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" using kagome::common::Buffer; @@ -57,7 +58,7 @@ class TrieStorageProviderTest : public ::testing::Test { std::make_shared( std::move(trieDb), serializer); - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->setToPersistentAt( + ASSERT_OUTCOME_SUCCESS(storage_provider_->setToPersistentAt( serializer->getEmptyRootHash(), std::nullopt)); } @@ -67,7 +68,7 @@ class TrieStorageProviderTest : public ::testing::Test { }; TEST_F(TrieStorageProviderTest, StartTransaction) { - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->startTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->startTransaction()); } TEST_F(TrieStorageProviderTest, FinishTransactionWithoutStart) { @@ -94,16 +95,16 @@ auto checkBatchValues(const kagome::storage::trie::TrieBatch &batch, TEST_F(TrieStorageProviderTest, NestedTransactions) { /// @given batch with cells A, B, C, D, E with value '-' (means is unchanged) auto batch0 = storage_provider_->getCurrentBatch(); - ASSERT_OUTCOME_SUCCESS_TRY(batch0->put("A"_buf, "-"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(batch0->put("B"_buf, "-"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(batch0->put("C"_buf, "-"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(batch0->put("D"_buf, "-"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(batch0->put("E"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(batch0->put("A"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(batch0->put("B"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(batch0->put("C"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(batch0->put("D"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(batch0->put("E"_buf, "-"_buf)); checkBatchValues(*batch0, "-----"); /// @when 1. start tx 1 { // Transaction 1 - will be committed - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->startTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->startTransaction()); auto batch1 = storage_provider_->getCurrentBatch(); /// @that 1. top level state is not changed, tx1 state like top level state @@ -111,7 +112,7 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { checkBatchValues(*batch1, "-----"); /// @when 2. change one of values - ASSERT_OUTCOME_SUCCESS_TRY(batch1->put("A"_buf, "1"_buf)); + ASSERT_OUTCOME_SUCCESS(batch1->put("A"_buf, "1"_buf)); /// @that 2. top level state is not changed, tx1 state is changed checkBatchValues(*batch0, "-----"); @@ -119,7 +120,7 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { { /// @when 3. start tx 2 - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->startTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->startTransaction()); auto batch2 = storage_provider_->getCurrentBatch(); /// @that 3. top level and tx1 state are not changed, tx2 state like tx1 @@ -129,7 +130,7 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { checkBatchValues(*batch2, "1----"); /// @when 4. change next value - ASSERT_OUTCOME_SUCCESS_TRY(batch2->put("B"_buf, "2"_buf)); + ASSERT_OUTCOME_SUCCESS(batch2->put("B"_buf, "2"_buf)); /// @that 4. top level and tx1 state are not changed, tx2 state is changed checkBatchValues(*batch0, "-----"); @@ -138,7 +139,7 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { { /// @when 5. start tx 3 - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->startTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->startTransaction()); auto batch3 = storage_provider_->getCurrentBatch(); /// @that 5. top level, tx1, tx2 state are not changed, tx3 state like @@ -149,7 +150,7 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { checkBatchValues(*batch3, "12---"); /// @when 6. change next value - ASSERT_OUTCOME_SUCCESS_TRY(batch3->put("C"_buf, "3"_buf)); + ASSERT_OUTCOME_SUCCESS(batch3->put("C"_buf, "3"_buf)); /// @that 6. top level, tx1 and tx2 state are not changed, tx3 state is /// changed @@ -159,7 +160,7 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { checkBatchValues(*batch3, "123--"); /// @when 7. commit tx3 - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->commitTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->commitTransaction()); /// @that 7. top level and tx1 state are not changed, tx2 state became /// like tx3 @@ -170,7 +171,7 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { } /// @when 8. change next value - ASSERT_OUTCOME_SUCCESS_TRY(batch2->put("D"_buf, "2"_buf)); + ASSERT_OUTCOME_SUCCESS(batch2->put("D"_buf, "2"_buf)); /// @that 8. top level and tx1 state are not changed, tx2 state is changed checkBatchValues(*batch0, "-----"); @@ -178,7 +179,7 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { checkBatchValues(*batch2, "1232-"); /// @when 9. rollback tx2 - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->rollbackTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->rollbackTransaction()); /// @that 9. top level and tx1 state are not changed, tx2 state does not /// matter anymore @@ -187,14 +188,14 @@ TEST_F(TrieStorageProviderTest, NestedTransactions) { } /// @when 10. change next value - ASSERT_OUTCOME_SUCCESS_TRY(batch1->put("E"_buf, "1"_buf)); + ASSERT_OUTCOME_SUCCESS(batch1->put("E"_buf, "1"_buf)); /// @that 10. top level is not changed, tx1 state is changed checkBatchValues(*batch0, "-----"); checkBatchValues(*batch1, "1---1"); /// @when 11. commit tx3 - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->commitTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->commitTransaction()); /// @that 11. top level became like tx1 state checkBatchValues(*batch0, "1---1"); @@ -206,25 +207,25 @@ TEST_F(TrieStorageProviderTest, ChildTreeTransactions) { ASSERT_OUTCOME_SUCCESS( base_batch_1, storage_provider_->getMutableChildBatchAt("child_root_1"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_1.get().put("A"_buf, "1"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_1.get().put("B"_buf, "2"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_1.get().put("C"_buf, "3"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_1.get().put("D"_buf, "-"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_1.get().put("E"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_1.get().put("A"_buf, "1"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_1.get().put("B"_buf, "2"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_1.get().put("C"_buf, "3"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_1.get().put("D"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_1.get().put("E"_buf, "-"_buf)); checkBatchValues(base_batch_1, "123--"); ASSERT_OUTCOME_SUCCESS( base_batch_2, storage_provider_->getMutableChildBatchAt("child_root_2"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_2.get().put("A"_buf, "4"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_2.get().put("B"_buf, "5"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_2.get().put("C"_buf, "6"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_2.get().put("D"_buf, "-"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(base_batch_2.get().put("E"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_2.get().put("A"_buf, "4"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_2.get().put("B"_buf, "5"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_2.get().put("C"_buf, "6"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_2.get().put("D"_buf, "-"_buf)); + ASSERT_OUTCOME_SUCCESS(base_batch_2.get().put("E"_buf, "-"_buf)); checkBatchValues(base_batch_2, "456--"); // First transaction - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->startTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->startTransaction()); ASSERT_OUTCOME_SUCCESS( tr1_batch_1, storage_provider_->getMutableChildBatchAt("child_root_1"_buf)); @@ -234,15 +235,15 @@ TEST_F(TrieStorageProviderTest, ChildTreeTransactions) { checkBatchValues(tr1_batch_1, "123--"); checkBatchValues(tr1_batch_2, "456--"); - ASSERT_OUTCOME_SUCCESS_TRY(tr1_batch_1.get().put("A"_buf, "a"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(tr1_batch_2.get().put("A"_buf, "d"_buf)); + ASSERT_OUTCOME_SUCCESS(tr1_batch_1.get().put("A"_buf, "a"_buf)); + ASSERT_OUTCOME_SUCCESS(tr1_batch_2.get().put("A"_buf, "d"_buf)); checkBatchValues(tr1_batch_1, "a23--"); checkBatchValues(tr1_batch_2, "d56--"); checkBatchValues(base_batch_1, "123--"); checkBatchValues(base_batch_2, "456--"); // Nested transaction - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->startTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->startTransaction()); ASSERT_OUTCOME_SUCCESS( tr2_batch_1, storage_provider_->getMutableChildBatchAt("child_root_1"_buf)); @@ -252,8 +253,8 @@ TEST_F(TrieStorageProviderTest, ChildTreeTransactions) { checkBatchValues(tr2_batch_1, "a23--"); checkBatchValues(tr2_batch_2, "d56--"); - ASSERT_OUTCOME_SUCCESS_TRY(tr2_batch_1.get().put("A"_buf, "0"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(tr2_batch_2.get().put("A"_buf, "1"_buf)); + ASSERT_OUTCOME_SUCCESS(tr2_batch_1.get().put("A"_buf, "0"_buf)); + ASSERT_OUTCOME_SUCCESS(tr2_batch_2.get().put("A"_buf, "1"_buf)); checkBatchValues(tr2_batch_1, "023--"); checkBatchValues(tr2_batch_2, "156--"); checkBatchValues(tr1_batch_1, "a23--"); @@ -261,18 +262,18 @@ TEST_F(TrieStorageProviderTest, ChildTreeTransactions) { checkBatchValues(base_batch_1, "123--"); checkBatchValues(base_batch_2, "456--"); - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->commitTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->commitTransaction()); checkBatchValues(tr1_batch_1, "023--"); checkBatchValues(tr1_batch_2, "156--"); checkBatchValues(base_batch_1, "123--"); checkBatchValues(base_batch_2, "456--"); - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->commitTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->commitTransaction()); checkBatchValues(base_batch_1, "023--"); checkBatchValues(base_batch_2, "156--"); // Second transaction - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->startTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->startTransaction()); ASSERT_OUTCOME_SUCCESS( tr3_batch_1, storage_provider_->getMutableChildBatchAt("child_root_1"_buf)); @@ -282,14 +283,14 @@ TEST_F(TrieStorageProviderTest, ChildTreeTransactions) { checkBatchValues(tr3_batch_1, "023--"); checkBatchValues(tr3_batch_2, "156--"); - ASSERT_OUTCOME_SUCCESS_TRY(tr3_batch_1.get().put("A"_buf, "a"_buf)); - ASSERT_OUTCOME_SUCCESS_TRY(tr3_batch_2.get().put("A"_buf, "d"_buf)); + ASSERT_OUTCOME_SUCCESS(tr3_batch_1.get().put("A"_buf, "a"_buf)); + ASSERT_OUTCOME_SUCCESS(tr3_batch_2.get().put("A"_buf, "d"_buf)); checkBatchValues(tr3_batch_1, "a23--"); checkBatchValues(tr3_batch_2, "d56--"); checkBatchValues(base_batch_1, "023--"); checkBatchValues(base_batch_2, "156--"); - ASSERT_OUTCOME_SUCCESS_TRY(storage_provider_->rollbackTransaction()); + ASSERT_OUTCOME_SUCCESS(storage_provider_->rollbackTransaction()); checkBatchValues(base_batch_1, "023--"); checkBatchValues(base_batch_2, "156--"); } diff --git a/test/core/scale/big_fixed_integers_test.cpp b/test/core/scale/big_fixed_integers_test.cpp index a507d8eea8..4889bebc4e 100644 --- a/test/core/scale/big_fixed_integers_test.cpp +++ b/test/core/scale/big_fixed_integers_test.cpp @@ -7,10 +7,11 @@ #include "scale/big_fixed_integers.hpp" #include + +#include #include #include "testutil/literals.hpp" -#include "testutil/outcome.hpp" using kagome::common::Buffer; using scale::Compact; @@ -21,9 +22,9 @@ template