diff --git a/core/api/service/author/impl/author_api_impl.cpp b/core/api/service/author/impl/author_api_impl.cpp index ba72c665bf..0af259282b 100644 --- a/core/api/service/author/impl/author_api_impl.cpp +++ b/core/api/service/author/impl/author_api_impl.cpp @@ -25,10 +25,10 @@ #include "transaction_pool/transaction_pool.hpp" namespace kagome::api { - const std::vector kKeyTypes{ - crypto::KEY_TYPE_BABE, - crypto::KEY_TYPE_GRAN, - crypto::KEY_TYPE_AUDI, + const std::vector kKeyTypes{ + crypto::KeyType::BABE, + crypto::KeyType::GRANDPA, + crypto::KeyType::AUTHORITY_DISCOVERY, }; AuthorApiImpl::AuthorApiImpl(sptr key_api, @@ -61,43 +61,43 @@ namespace kagome::api { } outcome::result AuthorApiImpl::insertKey( - crypto::KeyTypeId key_type, + crypto::KeyTypeId key_type_id, const gsl::span &seed, const gsl::span &public_key) { - if (std::find(kKeyTypes.begin(), kKeyTypes.end(), key_type) + if (std::find(kKeyTypes.begin(), kKeyTypes.end(), key_type_id) == kKeyTypes.end()) { std::string types; for (auto &type : kKeyTypes) { - types.append(encodeKeyTypeIdToStr(type)); + types.append(crypto::encodeKeyTypeIdToStr(type)); types.push_back(' '); } types.pop_back(); SL_INFO(logger_, "Unsupported key type, only [{}] are accepted", types); return outcome::failure(crypto::CryptoStoreError::UNSUPPORTED_KEY_TYPE); }; - if (crypto::KEY_TYPE_BABE == key_type - or crypto::KEY_TYPE_AUDI == key_type) { + if (crypto::KeyType::BABE == key_type_id + or crypto::KeyType::AUTHORITY_DISCOVERY == key_type_id) { OUTCOME_TRY(seed_typed, crypto::Sr25519Seed::fromSpan(seed)); OUTCOME_TRY(public_key_typed, crypto::Sr25519PublicKey::fromSpan(public_key)); OUTCOME_TRY(keypair, - store_->generateSr25519Keypair(key_type, seed_typed)); + store_->generateSr25519Keypair(key_type_id, seed_typed)); if (public_key_typed != keypair.public_key) { return outcome::failure(crypto::CryptoStoreError::WRONG_PUBLIC_KEY); } } - if (crypto::KEY_TYPE_GRAN == key_type) { + if (crypto::KeyType::GRANDPA == key_type_id) { OUTCOME_TRY(seed_typed, crypto::Ed25519Seed::fromSpan(seed)); OUTCOME_TRY(public_key_typed, crypto::Ed25519PublicKey::fromSpan(public_key)); OUTCOME_TRY( keypair, - store_->generateEd25519Keypair(crypto::KEY_TYPE_GRAN, seed_typed)); + store_->generateEd25519Keypair(crypto::KeyType::GRANDPA, seed_typed)); if (public_key_typed != keypair.public_key) { return outcome::failure(crypto::CryptoStoreError::WRONG_PUBLIC_KEY); } } - auto res = key_store_->saveKeyPair(key_type, public_key, seed); + auto res = key_store_->saveKeyPair(key_type_id, public_key, seed); return res; } @@ -124,7 +124,7 @@ namespace kagome::api { } stream >> key; if (store_->findEd25519Keypair( - crypto::KEY_TYPE_GRAN, + crypto::KeyType::GRANDPA, crypto::Ed25519PublicKey(common::Blob<32>(key)))) { unsigned count = 1; while (stream.currentIndex() < keys.size()) { diff --git a/core/api/service/author/impl/author_api_impl.hpp b/core/api/service/author/impl/author_api_impl.hpp index 9be60e32d1..717d400cc0 100644 --- a/core/api/service/author/impl/author_api_impl.hpp +++ b/core/api/service/author/impl/author_api_impl.hpp @@ -83,7 +83,7 @@ namespace kagome::api { const primitives::Extrinsic &extrinsic) override; outcome::result insertKey( - crypto::KeyTypeId key_type, + crypto::KeyTypeId key_type_id, const gsl::span &seed, const gsl::span &public_key) override; diff --git a/core/authority_discovery/query/query_impl.cpp b/core/authority_discovery/query/query_impl.cpp index 1bb5ee8b92..615d2e9546 100644 --- a/core/authority_discovery/query/query_impl.cpp +++ b/core/authority_discovery/query/query_impl.cpp @@ -99,7 +99,7 @@ namespace kagome::authority_discovery { authority_discovery_api_->authorities(block_tree_->bestBlock().hash)); OUTCOME_TRY(local_keys, crypto_store_->getSr25519PublicKeys( - crypto::KnownKeyTypeId::KEY_TYPE_AUDI)); + crypto::KeyType::AUTHORITY_DISCOVERY)); authorities.erase( std::remove_if(authorities.begin(), authorities.end(), diff --git a/core/authorship/impl/block_builder_factory_impl.cpp b/core/authorship/impl/block_builder_factory_impl.cpp index 3d6523fe31..e4924e122a 100644 --- a/core/authorship/impl/block_builder_factory_impl.cpp +++ b/core/authorship/impl/block_builder_factory_impl.cpp @@ -32,11 +32,11 @@ namespace kagome::authorship { BOOST_ASSERT(parent_number == parent.number); auto number = parent.number + 1; - primitives::BlockHeader header; - header.number = number; - header.parent_hash = parent.hash; - header.digest = std::move(inherent_digest); - + primitives::BlockHeader header{ + .number = number, + .parent_hash = parent.hash, + .digest = std::move(inherent_digest), + }; if (auto res = r_core_->initialize_block(header, std::move(changes_tracker)); not res) { diff --git a/core/crypto/crypto_store/key_file_storage.cpp b/core/crypto/crypto_store/key_file_storage.cpp index 7f272e2ac0..65f01e4ae5 100644 --- a/core/crypto/crypto_store/key_file_storage.cpp +++ b/core/crypto/crypto_store/key_file_storage.cpp @@ -55,7 +55,7 @@ namespace kagome::crypto { KeyFileStorage::parseKeyFileName(std::string_view file_name) const { OUTCOME_TRY(info, decodeKeyFileName(file_name)); auto key_type_str = file_name.substr(0, 8); - if (not isSupportedKeyType(info.first)) { + if (not KeyType::is_supported(info.first)) { auto ascii_res = common::unhex(key_type_str); if (ascii_res.has_value()) { std::string_view ascii( @@ -64,10 +64,10 @@ namespace kagome::crypto { logger_->warn( "key type is not officially supported", ascii, - info.first); + (KeyTypeId)info.first); } else { logger_->warn("key type is not officially supported", - info.first); + (KeyTypeId)info.first); } } return info; diff --git a/core/crypto/crypto_store/key_type.cpp b/core/crypto/crypto_store/key_type.cpp index 2df6cbf1be..393bf6e512 100644 --- a/core/crypto/crypto_store/key_type.cpp +++ b/core/crypto/crypto_store/key_type.cpp @@ -12,36 +12,20 @@ namespace kagome::crypto { - bool isSupportedKeyType(KeyTypeId k) { - static const std::unordered_set supported_types = { - KEY_TYPE_GRAN, - KEY_TYPE_BABE, - KEY_TYPE_IMON, - KEY_TYPE_PARA, - KEY_TYPE_ASGN, - KEY_TYPE_AUDI, - KEY_TYPE_ACCO, - KEY_TYPE_BEEF, - }; - - return supported_types.count(k) > 0; - } - - std::string encodeKeyTypeIdToStr(KeyTypeId key_type_id) { - const auto *p = reinterpret_cast(&key_type_id); - std::string res(p, p + sizeof(KeyTypeId)); - return res; + std::string encodeKeyTypeIdToStr(KeyType key_type) { + const auto *p = reinterpret_cast(&key_type); + return {p, p + sizeof(KeyTypeId)}; } - KeyTypeId decodeKeyTypeIdFromStr(std::string_view str) { - kagome::crypto::KeyTypeId res = 0; + KeyType decodeKeyTypeIdFromStr(std::string_view str) { + KeyTypeId res = 0; if (str.size() == sizeof(KeyTypeId)) { // string's data is aligned as KeyTypeId if (reinterpret_cast(str.data()) % std::alignment_of_v == 0) { - res = *reinterpret_cast(str.data()); + res = *reinterpret_cast(str.data()); } else { memcpy(&res, str.data(), sizeof(KeyTypeId)); } @@ -50,12 +34,12 @@ namespace kagome::crypto { return res; } - std::string encodeKeyFileName(KeyTypeId type, common::BufferView key) { + std::string encodeKeyFileName(KeyType type, common::BufferView key) { return common::hex_lower(str2byte(encodeKeyTypeIdToStr(type))) + key.toHex(); } - outcome::result> decodeKeyFileName( + outcome::result> decodeKeyFileName( std::string_view name) { std::string_view type_str = name; std::string_view key_str; diff --git a/core/crypto/crypto_store/key_type.hpp b/core/crypto/crypto_store/key_type.hpp index b418a182f3..73482f38fd 100644 --- a/core/crypto/crypto_store/key_type.hpp +++ b/core/crypto/crypto_store/key_type.hpp @@ -16,26 +16,80 @@ namespace kagome::crypto { UNSUPPORTED_KEY_TYPE_ID, }; - /** - * @brief Key type identifier - */ + /// Key type identifier using KeyTypeId = uint32_t; /** - * Types are 32bit integers, which represent encoded 4-char strings + * Makes 32bit integer KeyTypeId which represent encoded 4-char strings * Little-endian byte order is used */ - enum KnownKeyTypeId : KeyTypeId { - // clang-format off - KEY_TYPE_BABE = 0x65626162u, // BABE, sr25519 - KEY_TYPE_GRAN = 0x6e617267u, // GRANDPA, ed25519 - KEY_TYPE_ACCO = 0x6f636361u, // Account control [sr25519, ed25519, secp256k1] - KEY_TYPE_IMON = 0x6e6f6d69u, // I'm Online, sr25519 - KEY_TYPE_AUDI = 0x69647561u, // Account discovery [sr25519, ed25519, secp256k1] - KEY_TYPE_ASGN = 0x6e677361u, // ASGN - KEY_TYPE_PARA = 0x61726170u, // PARA - KEY_TYPE_BEEF = 0x66656562u, // Beefy, secp256k1 - // clang-format on + constexpr KeyTypeId operator""_key(const char *s, std::size_t size) { + return (static_cast(s[0]) << (CHAR_BIT * 0)) + | (static_cast(s[1]) << (CHAR_BIT * 1)) + | (static_cast(s[2]) << (CHAR_BIT * 2)) + | (static_cast(s[3]) << (CHAR_BIT * 3)); + } + + class KeyType { + public: + /// Key type for Babe module, built-in. + static constexpr KeyTypeId BABE = "babe"_key; + /// Key type for Sassafras module, built-in. + static constexpr KeyTypeId SASSAFRAS = "sass"_key; + /// Key type for Grandpa module, built-in. + static constexpr KeyTypeId GRANDPA = "gran"_key; + /// Key type for controlling an account in a Substrate runtime, built-in. + static constexpr KeyTypeId ACCOUNT = "acco"_key; + /// Key type for Aura module, built-in. + static constexpr KeyTypeId AURA = "aura"_key; + /// Key type for BEEFY module. + static constexpr KeyTypeId BEEFY = "beef"_key; + /// Key type for ImOnline module, built-in. + static constexpr KeyTypeId IM_ONLINE = "imon"_key; + /// Key type for AuthorityDiscovery module, built-in. + static constexpr KeyTypeId AUTHORITY_DISCOVERY = "audi"_key; + /// Key type for staking, built-in. + static constexpr KeyTypeId STAKING = "stak"_key; + /// A key type for signing statements + static constexpr KeyTypeId STATEMENT = "stmt"_key; + /// A key type ID useful for tests. + static constexpr KeyTypeId DUMMY = "dumy"_key; + + static constexpr KeyTypeId KEY_TYPE_ASGN = "asgn"_key; + static constexpr KeyTypeId KEY_TYPE_PARA = "para"_key; + + constexpr KeyType(KeyTypeId id) : id_(id){}; + + constexpr operator KeyTypeId() const { + return id_; + } + + static constexpr bool is_supported(KeyTypeId id) { + switch (id) { + case BABE: + case SASSAFRAS: + case GRANDPA: + case ACCOUNT: + case AURA: + case BEEFY: + case IM_ONLINE: + case AUTHORITY_DISCOVERY: + case STAKING: + case STATEMENT: + case DUMMY: + case KEY_TYPE_ASGN: + case KEY_TYPE_PARA: + return true; + } + return false; + } + + inline constexpr bool is_supported() const { + return is_supported(id_); + } + + private: + KeyTypeId id_; }; /** @@ -43,25 +97,18 @@ namespace kagome::crypto { * @param key_type_id KeyTypeId * @return string representation of KeyTypeId */ - std::string encodeKeyTypeIdToStr(KeyTypeId key_type_id); + std::string encodeKeyTypeIdToStr(KeyType key_type); /** * @brief restores KeyTypeId from its string representation * @param param string representation of key type * @return KeyTypeId */ - KeyTypeId decodeKeyTypeIdFromStr(std::string_view str); - - /** - * @brief checks whether key type value is supported - * @param k key type value - * @return true if supported, false otherwise - */ - bool isSupportedKeyType(KeyTypeId k); + KeyType decodeKeyTypeIdFromStr(std::string_view str); - std::string encodeKeyFileName(KeyTypeId type, common::BufferView key); + std::string encodeKeyFileName(KeyType type, common::BufferView key); - outcome::result> decodeKeyFileName( + outcome::result> decodeKeyFileName( std::string_view name); } // namespace kagome::crypto diff --git a/core/crypto/crypto_store/session_keys.cpp b/core/crypto/crypto_store/session_keys.cpp index b5892210a2..ca648dde7e 100644 --- a/core/crypto/crypto_store/session_keys.cpp +++ b/core/crypto/crypto_store/session_keys.cpp @@ -16,7 +16,7 @@ namespace kagome::crypto { typename Eq> SessionKeys::KeypairWithIndexOpt SessionKeysImpl::find( KeypairWithIndexOpt &cache, - KeyTypeId type, + KeyType type, const std::vector &authorities, const Eq &eq) { if (not roles_.flags.authority) { @@ -64,13 +64,14 @@ namespace kagome::crypto { const application::AppConfiguration &config) : roles_(config.roles()), store_(store) { if (auto dev = config.devMnemonicPhrase()) { - store_->generateEd25519Keypair(KEY_TYPE_GRAN, *dev).value(); - store_->generateSr25519Keypair(KEY_TYPE_BABE, *dev).value(); - store_->generateSr25519Keypair(KEY_TYPE_IMON, *dev).value(); - store_->generateSr25519Keypair(KEY_TYPE_AUDI, *dev).value(); - store_->generateSr25519Keypair(KEY_TYPE_ASGN, *dev).value(); - store_->generateSr25519Keypair(KEY_TYPE_PARA, *dev).value(); - store_->generateEcdsaKeypair(KEY_TYPE_BEEF, *dev).value(); + store_->generateEd25519Keypair(KeyType::GRANDPA, *dev).value(); + store_->generateSr25519Keypair(KeyType::BABE, *dev).value(); + store_->generateSr25519Keypair(KeyType::IM_ONLINE, *dev).value(); + store_->generateSr25519Keypair(KeyType::AUTHORITY_DISCOVERY, *dev) + .value(); + store_->generateSr25519Keypair(KeyType::KEY_TYPE_ASGN, *dev).value(); + store_->generateSr25519Keypair(KeyType::KEY_TYPE_PARA, *dev).value(); + store_->generateEcdsaKeypair(KeyType::BEEFY, *dev).value(); } } @@ -81,7 +82,21 @@ namespace kagome::crypto { &CryptoStore::getSr25519PublicKeys, &CryptoStore::findSr25519Keypair>( babe_key_pair_, - KEY_TYPE_BABE, + KeyType::BABE, + authorities, + [](const Sr25519PublicKey &l, const primitives::Authority &r) { + return l == r.id.id; + }); + } + + SessionKeys::KeypairWithIndexOpt + SessionKeysImpl::getSassafrasKeyPair( + const primitives::AuthorityList &authorities) { + return find( + babe_key_pair_, + KeyType::SASSAFRAS, authorities, [](const Sr25519PublicKey &l, const primitives::Authority &r) { return l == r.id.id; @@ -94,7 +109,7 @@ namespace kagome::crypto { &CryptoStore::getEd25519PublicKeys, &CryptoStore::findEd25519Keypair>( gran_key_pair_, - KEY_TYPE_GRAN, + KeyType::GRANDPA, authorities.authorities, [](const Ed25519PublicKey &l, const primitives::Authority &r) { return l == r.id.id; @@ -110,15 +125,18 @@ namespace kagome::crypto { return find( - para_key_pair_, KEY_TYPE_PARA, authorities, std::equal_to{}); + para_key_pair_, KeyType::KEY_TYPE_PARA, authorities, std::equal_to{}); } std::shared_ptr SessionKeysImpl::getAudiKeyPair( const std::vector &authorities) { - if (auto res = find( - audi_key_pair_, KEY_TYPE_AUDI, authorities, std::equal_to{})) { + if (auto res = + find(audi_key_pair_, + KeyType::AUTHORITY_DISCOVERY, + authorities, + std::equal_to{})) { return std::move(res->first); } return nullptr; @@ -130,6 +148,6 @@ namespace kagome::crypto { return find( - beef_key_pair_, KEY_TYPE_BEEF, authorities, std::equal_to{}); + beef_key_pair_, KeyType::BEEFY, authorities, std::equal_to{}); } } // namespace kagome::crypto diff --git a/core/crypto/crypto_store/session_keys.hpp b/core/crypto/crypto_store/session_keys.hpp index 4e029a29d8..88cbfb6080 100644 --- a/core/crypto/crypto_store/session_keys.hpp +++ b/core/crypto/crypto_store/session_keys.hpp @@ -28,12 +28,14 @@ namespace kagome::crypto { // otherwise it could be read from chainspec palletSession/keys // nevertheless they are hardcoded in polkadot // https://github.com/paritytech/polkadot/blob/634520cd3cf4b2b850db807daaaa32e480099981/node/service/src/chain_spec.rs#L230 - constexpr KnownKeyTypeId polkadot_key_order[6]{KEY_TYPE_GRAN, - KEY_TYPE_BABE, - KEY_TYPE_IMON, - KEY_TYPE_PARA, - KEY_TYPE_ASGN, - KEY_TYPE_AUDI}; + constexpr KeyType polkadot_key_order[6] = { + KeyType::GRANDPA, + KeyType::BABE, + KeyType::IM_ONLINE, + KeyType::KEY_TYPE_PARA, + KeyType::KEY_TYPE_ASGN, + KeyType::AUTHORITY_DISCOVERY, + }; class SessionKeys { public: @@ -49,6 +51,12 @@ namespace kagome::crypto { virtual KeypairWithIndexOpt getBabeKeyPair( const primitives::AuthorityList &authorities) = 0; + /** + * @return current SASSAFRAS session key pair + */ + virtual KeypairWithIndexOpt getSassafrasKeyPair( + const primitives::AuthorityList &authorities) = 0; + /** * @return current GRANDPA session key pair */ @@ -95,7 +103,7 @@ namespace kagome::crypto { typename A, typename Eq> KeypairWithIndexOpt find(KeypairWithIndexOpt &cache, - KeyTypeId type, + KeyType type, const std::vector &authorities, const Eq &eq); @@ -106,6 +114,9 @@ namespace kagome::crypto { KeypairWithIndexOpt getBabeKeyPair( const primitives::AuthorityList &authorities) override; + KeypairWithIndexOpt getSassafrasKeyPair( + const primitives::AuthorityList &authorities) override; + std::shared_ptr getGranKeyPair( const primitives::AuthoritySet &authorities) override; diff --git a/core/host_api/impl/crypto_extension.cpp b/core/host_api/impl/crypto_extension.cpp index b4930e2f85..c41325d17a 100644 --- a/core/host_api/impl/crypto_extension.cpp +++ b/core/host_api/impl/crypto_extension.cpp @@ -37,7 +37,7 @@ namespace { void checkIfKeyIsSupported(kagome::crypto::KeyTypeId key_type, kagome::log::Logger log) { - if (not kagome::crypto::isSupportedKeyType(key_type)) { + if (not kagome::crypto::KeyType::is_supported(key_type)) { const auto *p = reinterpret_cast(&key_type); std::string key_type_str(p, p + sizeof(key_type)); diff --git a/core/parachain/approval/approval_distribution.cpp b/core/parachain/approval/approval_distribution.cpp index ed1f0caf23..eb786d6330 100644 --- a/core/parachain/approval/approval_distribution.cpp +++ b/core/parachain/approval/approval_distribution.cpp @@ -641,7 +641,7 @@ namespace kagome::parachain { for (size_t ix = 0; ix < config.assignment_keys.size(); ++ix) { const auto &pk = config.assignment_keys[ix]; if (auto res = keystore->findSr25519Keypair( - crypto::KEY_TYPE_ASGN, + crypto::KeyType::KEY_TYPE_ASGN, crypto::Sr25519PublicKey::fromSpan(pk).value()); res.has_value()) { return std::make_pair((ValidatorIndex)ix, std::move(res.value())); @@ -2316,7 +2316,7 @@ namespace kagome::parachain { SessionIndex session_index, const CandidateHash &candidate_hash) { auto key_pair = - keystore_->findSr25519Keypair(crypto::KEY_TYPE_PARA, pubkey); + keystore_->findSr25519Keypair(crypto::KeyType::KEY_TYPE_PARA, pubkey); if (key_pair.has_error()) { logger_->warn("No key pair in store for {}", pubkey); return std::nullopt; diff --git a/test/core/api/service/author/author_api_test.cpp b/test/core/api/service/author/author_api_test.cpp index 5021ddeb65..e1151eac12 100644 --- a/test/core/api/service/author/author_api_test.cpp +++ b/test/core/api/service/author/author_api_test.cpp @@ -45,6 +45,7 @@ using namespace kagome::runtime; using kagome::application::AppConfigurationMock; using kagome::blockchain::BlockTree; using kagome::blockchain::BlockTreeMock; +using kagome::crypto::KeyType; using kagome::network::TransactionsTransmitterMock; using kagome::primitives::BlockId; using kagome::primitives::BlockInfo; @@ -142,7 +143,7 @@ struct AuthorApiTest : public ::testing::Test { key_store = KeyFileStorage::createAt("test_chain_43/keystore").value(); key_pair = generateSr25519Keypair(); ASSERT_OUTCOME_SUCCESS_TRY(key_store->saveKeyPair( - KEY_TYPE_BABE, + KeyType::BABE, gsl::make_span(key_pair.public_key.data(), 32), gsl::make_span(std::array({1}).begin(), 1))); role.flags.authority = 1; @@ -220,10 +221,10 @@ TEST_F(AuthorApiTest, InsertKeyUnsupported) { TEST_F(AuthorApiTest, InsertKeyBabe) { Sr25519Seed seed; Sr25519PublicKey public_key; - EXPECT_CALL(*store, generateSr25519Keypair(KEY_TYPE_BABE, seed)) + EXPECT_CALL(*store, generateSr25519Keypair(KeyType::BABE, seed)) .WillOnce(Return(Sr25519Keypair{{}, public_key})); EXPECT_OUTCOME_SUCCESS( - res, author_api->insertKey(KEY_TYPE_BABE, seed, public_key)); + res, author_api->insertKey(KeyType::BABE, seed, public_key)); } /** @@ -234,10 +235,12 @@ TEST_F(AuthorApiTest, InsertKeyBabe) { TEST_F(AuthorApiTest, InsertKeyAudi) { Sr25519Seed seed; Sr25519PublicKey public_key; - EXPECT_CALL(*store, generateSr25519Keypair(KEY_TYPE_AUDI, seed)) + EXPECT_CALL(*store, + generateSr25519Keypair(KeyType::AUTHORITY_DISCOVERY, seed)) .WillOnce(Return(Sr25519Keypair{{}, public_key})); EXPECT_OUTCOME_SUCCESS( - res, author_api->insertKey(KEY_TYPE_AUDI, seed, public_key)); + res, + author_api->insertKey(KeyType::AUTHORITY_DISCOVERY, seed, public_key)); } /** @@ -248,10 +251,10 @@ TEST_F(AuthorApiTest, InsertKeyAudi) { TEST_F(AuthorApiTest, InsertKeyGran) { Ed25519Seed seed; Ed25519PublicKey public_key; - EXPECT_CALL(*store, generateEd25519Keypair(KEY_TYPE_GRAN, seed)) + EXPECT_CALL(*store, generateEd25519Keypair(KeyType::GRANDPA, seed)) .WillOnce(Return(Ed25519Keypair{{}, public_key})); EXPECT_OUTCOME_SUCCESS( - res, author_api->insertKey(KEY_TYPE_GRAN, seed, public_key)); + res, author_api->insertKey(KeyType::GRANDPA, seed, public_key)); } /** @@ -324,22 +327,22 @@ TEST_F(AuthorApiTest, HasSessionKeysSuccess6Keys) { outcome::result edOk = Ed25519Keypair{}; outcome::result srOk = Sr25519Keypair{}; InSequence s; - EXPECT_CALL(*store, findEd25519Keypair(KEY_TYPE_GRAN, _)) + EXPECT_CALL(*store, findEd25519Keypair(KeyType::GRANDPA, _)) .Times(1) .WillOnce(Return(edOk)); - EXPECT_CALL(*store, findSr25519Keypair(KEY_TYPE_BABE, _)) + EXPECT_CALL(*store, findSr25519Keypair(KeyType::BABE, _)) .Times(1) .WillOnce(Return(srOk)); - EXPECT_CALL(*store, findSr25519Keypair(KEY_TYPE_IMON, _)) + EXPECT_CALL(*store, findSr25519Keypair(KeyType::IM_ONLINE, _)) .Times(1) .WillOnce(Return(srOk)); - EXPECT_CALL(*store, findSr25519Keypair(KEY_TYPE_PARA, _)) + EXPECT_CALL(*store, findSr25519Keypair(KeyType::KEY_TYPE_PARA, _)) .Times(1) .WillOnce(Return(srOk)); - EXPECT_CALL(*store, findSr25519Keypair(KEY_TYPE_ASGN, _)) + EXPECT_CALL(*store, findSr25519Keypair(KeyType::KEY_TYPE_ASGN, _)) .Times(1) .WillOnce(Return(srOk)); - EXPECT_CALL(*store, findSr25519Keypair(KEY_TYPE_AUDI, _)) + EXPECT_CALL(*store, findSr25519Keypair(KeyType::AUTHORITY_DISCOVERY, _)) .Times(1) .WillOnce(Return(srOk)); EXPECT_OUTCOME_SUCCESS( @@ -357,7 +360,7 @@ TEST_F(AuthorApiTest, HasSessionKeysSuccess1Keys) { Buffer keys; keys.resize(32); outcome::result edOk = Ed25519Keypair{}; - EXPECT_CALL(*store, findEd25519Keypair(KEY_TYPE_GRAN, _)) + EXPECT_CALL(*store, findEd25519Keypair(KeyType::GRANDPA, _)) .Times(1) .WillOnce(Return(edOk)); EXPECT_OUTCOME_SUCCESS( @@ -395,7 +398,7 @@ TEST_F(AuthorApiTest, HasKeySuccess) { EXPECT_OUTCOME_SUCCESS( res, author_api->hasKey(gsl::make_span(key_pair.public_key.data(), 32), - KEY_TYPE_BABE)); + KeyType::BABE)); EXPECT_EQ(res.value(), true); } @@ -405,7 +408,7 @@ TEST_F(AuthorApiTest, HasKeySuccess) { * @then call succeeds, false result */ TEST_F(AuthorApiTest, HasKeyFail) { - EXPECT_OUTCOME_SUCCESS(res, author_api->hasKey({}, KEY_TYPE_BABE)); + EXPECT_OUTCOME_SUCCESS(res, author_api->hasKey({}, KeyType::BABE)); EXPECT_EQ(res.value(), false); } diff --git a/test/core/crypto/crypto_store/crypto_store_test.cpp b/test/core/crypto/crypto_store/crypto_store_test.cpp index d5a6975e7d..8416c124d6 100644 --- a/test/core/crypto/crypto_store/crypto_store_test.cpp +++ b/test/core/crypto/crypto_store/crypto_store_test.cpp @@ -41,8 +41,8 @@ using kagome::crypto::Ed25519PublicKey; using kagome::crypto::Ed25519Seed; using kagome::crypto::Ed25519Suite; using kagome::crypto::HasherImpl; +using kagome::crypto::KeyType; using kagome::crypto::KeyTypeId; -using kagome::crypto::KnownKeyTypeId; using kagome::crypto::Pbkdf2Provider; using kagome::crypto::Pbkdf2ProviderImpl; using kagome::crypto::Sr25519Keypair; @@ -91,7 +91,7 @@ struct CryptoStoreTest : public test::BaseFS_Test { Blob<32>::fromHex("a4681403ba5b6a3f3bd0b0604ce439a78244" "c7d43b127ec35cd8325602dd47fd")); seed = s; - key_type = KnownKeyTypeId::KEY_TYPE_BABE; + key_type = KeyType::BABE; EXPECT_OUTCOME_TRUE( ed_publ, @@ -264,25 +264,20 @@ TEST_F(CryptoStoreTest, generateSr25519KeypairStoreSuccess) { * @then collection of all ed25519 public keys of provided type is returned */ TEST_F(CryptoStoreTest, getEd25519PublicKeysSuccess) { - EXPECT_OUTCOME_TRUE(pair1, - crypto_store->generateEd25519KeypairOnDisk( - KnownKeyTypeId::KEY_TYPE_BABE)); - EXPECT_OUTCOME_TRUE(pair2, - crypto_store->generateEd25519KeypairOnDisk( - KnownKeyTypeId::KEY_TYPE_BABE)); - EXPECT_OUTCOME_SUCCESS(pair4, - crypto_store->generateSr25519KeypairOnDisk( - KnownKeyTypeId::KEY_TYPE_BABE)); - EXPECT_OUTCOME_SUCCESS(pair5, - crypto_store->generateSr25519KeypairOnDisk( - KnownKeyTypeId::KEY_TYPE_ACCO)); + EXPECT_OUTCOME_TRUE( + pair1, crypto_store->generateEd25519KeypairOnDisk(KeyType::BABE)); + EXPECT_OUTCOME_TRUE( + pair2, crypto_store->generateEd25519KeypairOnDisk(KeyType::BABE)); + EXPECT_OUTCOME_SUCCESS( + pair4, crypto_store->generateSr25519KeypairOnDisk(KeyType::BABE)); + EXPECT_OUTCOME_SUCCESS( + pair5, crypto_store->generateSr25519KeypairOnDisk(KeyType::ACCOUNT)); std::set ed_babe_keys_set = {pair1.public_key, pair2.public_key}; std::vector ed_babe_keys(ed_babe_keys_set.begin(), ed_babe_keys_set.end()); - auto keys = - crypto_store->getEd25519PublicKeys(KnownKeyTypeId::KEY_TYPE_BABE).value(); + auto keys = crypto_store->getEd25519PublicKeys(KeyType::BABE).value(); ASSERT_THAT(keys, testing::UnorderedElementsAreArray(ed_babe_keys)); } @@ -292,26 +287,21 @@ TEST_F(CryptoStoreTest, getEd25519PublicKeysSuccess) { * @then collection of all sr25519 public keys of provided type is returned */ TEST_F(CryptoStoreTest, getSr25519PublicKeysSuccess) { - EXPECT_OUTCOME_TRUE(pair1, - crypto_store->generateSr25519KeypairOnDisk( - KnownKeyTypeId::KEY_TYPE_BABE)); - EXPECT_OUTCOME_TRUE(pair2, - crypto_store->generateSr25519KeypairOnDisk( - KnownKeyTypeId::KEY_TYPE_BABE)); - EXPECT_OUTCOME_SUCCESS(pair4, - crypto_store->generateEd25519KeypairOnDisk( - KnownKeyTypeId::KEY_TYPE_BABE)); - EXPECT_OUTCOME_SUCCESS(pair5, - crypto_store->generateEd25519KeypairOnDisk( - KnownKeyTypeId::KEY_TYPE_ACCO)); + EXPECT_OUTCOME_TRUE( + pair1, crypto_store->generateSr25519KeypairOnDisk(KeyType::BABE)); + EXPECT_OUTCOME_TRUE( + pair2, crypto_store->generateSr25519KeypairOnDisk(KeyType::BABE)); + EXPECT_OUTCOME_SUCCESS( + pair4, crypto_store->generateEd25519KeypairOnDisk(KeyType::BABE)); + EXPECT_OUTCOME_SUCCESS( + pair5, crypto_store->generateEd25519KeypairOnDisk(KeyType::ACCOUNT)); std::set sr_babe_keys_set = {pair1.public_key, pair2.public_key}; std::vector sr_babe_keys(sr_babe_keys_set.begin(), sr_babe_keys_set.end()); - auto keys = - crypto_store->getSr25519PublicKeys(KnownKeyTypeId::KEY_TYPE_BABE).value(); + auto keys = crypto_store->getSr25519PublicKeys(KeyType::BABE).value(); ASSERT_THAT(keys, testing::UnorderedElementsAreArray(sr_babe_keys)); } @@ -330,7 +320,7 @@ TEST(CryptoStoreCompatibilityTest, DISABLED_SubkeyCompat) { auto bip39_provider = std::make_shared(std::move(pbkdf2_provider), hasher); auto keystore_path = kagome::filesystem::path(__FILE__).parent_path() - / "subkey_keys" / "keystore"; + / "subkey_keys" / "keystore"; auto crypto_store = std::make_shared( std::make_shared(std::move(ecdsa_provider)), std::make_shared(std::move(ed25519_provider)), @@ -338,7 +328,6 @@ TEST(CryptoStoreCompatibilityTest, DISABLED_SubkeyCompat) { bip39_provider, csprng, kagome::crypto::KeyFileStorage::createAt(keystore_path).value()); - EXPECT_OUTCOME_TRUE( - keys, crypto_store->getEd25519PublicKeys(KnownKeyTypeId::KEY_TYPE_BABE)); + EXPECT_OUTCOME_TRUE(keys, crypto_store->getEd25519PublicKeys(KeyType::BABE)); ASSERT_EQ(keys.size(), 1); } diff --git a/test/core/crypto/crypto_store/key_type_test.cpp b/test/core/crypto/crypto_store/key_type_test.cpp index 83c0fc920c..f0610ce6bb 100644 --- a/test/core/crypto/crypto_store/key_type_test.cpp +++ b/test/core/crypto/crypto_store/key_type_test.cpp @@ -9,25 +9,18 @@ #include "crypto/crypto_store/key_type.hpp" -using kagome::crypto::KEY_TYPE_ACCO; -using kagome::crypto::KEY_TYPE_ASGN; -using kagome::crypto::KEY_TYPE_AUDI; -using kagome::crypto::KEY_TYPE_BABE; -using kagome::crypto::KEY_TYPE_GRAN; -using kagome::crypto::KEY_TYPE_IMON; -using kagome::crypto::KEY_TYPE_PARA; - using kagome::crypto::decodeKeyTypeIdFromStr; using kagome::crypto::encodeKeyTypeIdToStr; +using kagome::crypto::KeyType; using kagome::crypto::KeyTypeId; namespace { - std::tuple good(KeyTypeId id, + std::tuple good(KeyType id, std::string_view v) { return {id, v, true}; } - std::tuple bad(KeyTypeId id, + std::tuple bad(KeyType id, std::string_view v) { return {id, v, false}; } @@ -59,14 +52,26 @@ TEST_P(KeyTypeTest, EncodeSuccess) { } } +TEST_P(KeyTypeTest, CheckIfKnown) { + auto [repr, key_type_str, should_succeed] = GetParam(); + auto is_supported = KeyType::is_supported(repr); + + if (should_succeed) { + ASSERT_TRUE(is_supported); + } else { + ASSERT_FALSE(is_supported); + } +} + INSTANTIATE_TEST_SUITE_P(KeyTypeTestCases, KeyTypeTest, - ::testing::Values(good(KEY_TYPE_BABE, "babe"), - good(KEY_TYPE_GRAN, "gran"), - good(KEY_TYPE_ACCO, "acco"), - good(KEY_TYPE_IMON, "imon"), - good(KEY_TYPE_AUDI, "audi"), - good(KEY_TYPE_ASGN, "asgn"), - good(KEY_TYPE_PARA, "para"), - bad(KEY_TYPE_BABE - 5, "babe"), - bad(KEY_TYPE_BABE + 1000, "babe"))); + ::testing::Values(good(KeyType::BABE, "babe"), + good(KeyType::GRANDPA, "gran"), + good(KeyType::ACCOUNT, "acco"), + good(KeyType::IM_ONLINE, "imon"), + good(KeyType::AUTHORITY_DISCOVERY, + "audi"), + good(KeyType::KEY_TYPE_ASGN, "asgn"), + good(KeyType::KEY_TYPE_PARA, "para"), + bad((KeyType)0, "babe"), + bad((KeyType)666, "babe"))); diff --git a/test/core/crypto/crypto_store/session_keys_test.cpp b/test/core/crypto/crypto_store/session_keys_test.cpp index 371578933b..693fcf073a 100644 --- a/test/core/crypto/crypto_store/session_keys_test.cpp +++ b/test/core/crypto/crypto_store/session_keys_test.cpp @@ -47,10 +47,10 @@ struct SessionKeysTest : public ::testing::Test { TEST_F(SessionKeysTest, SessionKeys) { outcome::result ed_keys_empty = Ed25519Keys{}; outcome::result sr_keys_empty = Sr25519Keys{}; - EXPECT_CALL(*store, getSr25519PublicKeys(KEY_TYPE_BABE)) + EXPECT_CALL(*store, getSr25519PublicKeys(KeyType::BABE)) .Times(1) .WillOnce(Return(sr_keys_empty)); - EXPECT_CALL(*store, getEd25519PublicKeys(KEY_TYPE_GRAN)) + EXPECT_CALL(*store, getEd25519PublicKeys(KeyType::GRANDPA)) .Times(1) .WillOnce(Return(ed_keys_empty)); ASSERT_FALSE(session_keys->getBabeKeyPair({})); @@ -69,10 +69,10 @@ TEST_F(SessionKeysTest, SessionKeys) { outcome::result ed_keys = Ed25519Keys{ed_key}; outcome::result sr_keys = Sr25519Keys{sr_key}; - EXPECT_CALL(*store, getSr25519PublicKeys(KEY_TYPE_BABE)) + EXPECT_CALL(*store, getSr25519PublicKeys(KeyType::BABE)) .Times(1) .WillOnce(Return(sr_keys)); - EXPECT_CALL(*store, getEd25519PublicKeys(KEY_TYPE_GRAN)) + EXPECT_CALL(*store, getEd25519PublicKeys(KeyType::GRANDPA)) .Times(1) .WillOnce(Return(ed_keys)); @@ -90,10 +90,10 @@ TEST_F(SessionKeysTest, SessionKeys) { outcome::result ed_pair = Ed25519Keypair{ed_priv, ed_key}; outcome::result sr_pair = Sr25519Keypair{sr_priv, sr_key}; - EXPECT_CALL(*store, findSr25519Keypair(KEY_TYPE_BABE, _)) + EXPECT_CALL(*store, findSr25519Keypair(KeyType::BABE, _)) .Times(1) .WillOnce(Return(sr_pair)); - EXPECT_CALL(*store, findEd25519Keypair(KEY_TYPE_GRAN, _)) + EXPECT_CALL(*store, findEd25519Keypair(KeyType::GRANDPA, _)) .Times(1) .WillOnce(Return(ed_pair)); ASSERT_TRUE(session_keys->getBabeKeyPair({{{sr_key}, {}}})); diff --git a/test/core/host_api/crypto_extension_test.cpp b/test/core/host_api/crypto_extension_test.cpp index 772b770a8e..82632de0a7 100644 --- a/test/core/host_api/crypto_extension_test.cpp +++ b/test/core/host_api/crypto_extension_test.cpp @@ -49,6 +49,7 @@ using kagome::crypto::Ed25519Seed; using kagome::crypto::Ed25519Signature; using kagome::crypto::Hasher; using kagome::crypto::HasherImpl; +using kagome::crypto::KeyType; using kagome::crypto::Secp256k1Provider; using kagome::crypto::Secp256k1ProviderImpl; using kagome::crypto::Sr25519Keypair; @@ -677,8 +678,8 @@ TEST_F(CryptoExtensionTest, Secp256k1RecoverCompressedFailure) { TEST_F(CryptoExtensionTest, Ed25519GetPublicKeysSuccess) { WasmSpan res = PtrSize(1, 2).combine(); - auto key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; + auto key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; EXPECT_CALL(*crypto_store_, getEd25519PublicKeys(key_type)) .WillOnce(Return(ed_public_keys)); @@ -701,7 +702,7 @@ TEST_F(CryptoExtensionTest, Sr25519GetPublicKeysSuccess) { WasmSpan res = PtrSize(1, 2).combine(); auto key_type_ptr = 42u; - auto key_type = kagome::crypto::KEY_TYPE_BABE; + auto key_type = KeyType::BABE; EXPECT_CALL(*crypto_store_, getSr25519PublicKeys(key_type)) .WillOnce(Return(sr_public_keys)); @@ -721,9 +722,9 @@ TEST_F(CryptoExtensionTest, Sr25519GetPublicKeysSuccess) { * @then we get a valid signature */ TEST_F(CryptoExtensionTest, Ed25519SignSuccess) { - kagome::runtime::WasmSize key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; - kagome::runtime::WasmPointer key = 2; + WasmSize key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; + WasmPointer key = 2; auto msg = PtrSize(3, 4).combine(); auto res = PtrSize(5, 6).combine(); @@ -753,9 +754,9 @@ TEST_F(CryptoExtensionTest, Ed25519SignSuccess) { * @then we get a valid serialized error */ TEST_F(CryptoExtensionTest, Ed25519SignFailure) { - kagome::runtime::WasmSize key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; - kagome::runtime::WasmPointer key = 2; + WasmSize key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; + WasmPointer key = 2; auto msg = PtrSize(3, 4).combine(); auto res = PtrSize(5, 6).combine(); @@ -786,9 +787,9 @@ TEST_F(CryptoExtensionTest, Ed25519SignFailure) { * @then we get a valid signature */ TEST_F(CryptoExtensionTest, Sr25519SignSuccess) { - kagome::runtime::WasmSize key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; - kagome::runtime::WasmPointer key = 2; + WasmSize key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; + WasmPointer key = 2; auto msg = PtrSize(3, 4).combine(); auto res = PtrSize(5, 6).combine(); @@ -822,9 +823,9 @@ TEST_F(CryptoExtensionTest, Sr25519SignSuccess) { * @then we get a valid serialized error */ TEST_F(CryptoExtensionTest, Sr25519SignFailure) { - kagome::runtime::WasmSize key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; - kagome::runtime::WasmPointer key = 2; + WasmSize key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; + WasmPointer key = 2; auto msg = PtrSize(3, 4).combine(); auto res = PtrSize(5, 6).combine(); @@ -855,9 +856,9 @@ TEST_F(CryptoExtensionTest, Sr25519SignFailure) { * @then a new ed25519 keypair is successfully generated and stored */ TEST_F(CryptoExtensionTest, Ed25519GenerateByHexSeedSuccess) { - kagome::runtime::WasmSize key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; - kagome::runtime::WasmPointer res = 2; + WasmSize key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; + WasmPointer res = 2; auto seed_ptr = PtrSize(3, 4).combine(); EXPECT_CALL(*crypto_store_, @@ -879,9 +880,9 @@ TEST_F(CryptoExtensionTest, Ed25519GenerateByHexSeedSuccess) { * @then a new ed25519 keypair is successfully generated and stored */ TEST_F(CryptoExtensionTest, Ed25519GenerateByMnemonicSuccess) { - kagome::runtime::WasmSize key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; - kagome::runtime::WasmPointer res = 2; + WasmSize key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; + WasmPointer res = 2; auto seed_ptr = PtrSize(3, 4).combine(); EXPECT_CALL(*memory_, loadN(3, 4)).WillOnce(Return(mnemonic_buffer)); @@ -903,9 +904,9 @@ TEST_F(CryptoExtensionTest, Ed25519GenerateByMnemonicSuccess) { * @then a new sr25519 keypair is successfully generated and stored */ TEST_F(CryptoExtensionTest, Sr25519GenerateByHexSeedSuccess) { - kagome::runtime::WasmSize key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; - kagome::runtime::WasmPointer res = 2; + WasmSize key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; + WasmPointer res = 2; auto seed_ptr = PtrSize(3, 4).combine(); EXPECT_CALL(*memory_, loadN(3, 4)).WillOnce(Return(mnemonic_buffer)); @@ -928,9 +929,9 @@ TEST_F(CryptoExtensionTest, Sr25519GenerateByHexSeedSuccess) { * @then a new sr25519 keypair is successfully generated and stored */ TEST_F(CryptoExtensionTest, Sr25519GenerateByMnemonicSuccess) { - kagome::runtime::WasmSize key_type = kagome::crypto::KEY_TYPE_BABE; - kagome::runtime::WasmSize key_type_ptr = 42; - kagome::runtime::WasmPointer res = 2; + WasmSize key_type = KeyType::BABE; + WasmSize key_type_ptr = 42; + WasmPointer res = 2; auto seed_ptr = PtrSize(3, 4).combine(); EXPECT_CALL(*memory_, loadN(3, 4)).WillOnce(Return(mnemonic_buffer)); diff --git a/test/core/parachain/assignments.cpp b/test/core/parachain/assignments.cpp index d6e7cbe765..c7bbc5a4b0 100644 --- a/test/core/parachain/assignments.cpp +++ b/test/core/parachain/assignments.cpp @@ -47,18 +47,18 @@ struct AssignmentsTest : public test::BaseFS_Test { size_t random) { for (const auto &acc : accounts) { [[maybe_unused]] auto _ = - cs->generateSr25519Keypair(KnownKeyTypeId::KEY_TYPE_ASGN, + cs->generateSr25519Keypair(KeyType::KEY_TYPE_ASGN, std::string_view{acc}) .value(); } for (size_t ix = 0ull; ix < random; ++ix) { auto seed = std::to_string(ix); [[maybe_unused]] auto _ = - cs->generateSr25519Keypair(KnownKeyTypeId::KEY_TYPE_ASGN, + cs->generateSr25519Keypair(KeyType::KEY_TYPE_ASGN, std::string_view{seed}) .value(); } - return cs->getSr25519PublicKeys(KnownKeyTypeId::KEY_TYPE_ASGN).value(); + return cs->getSr25519PublicKeys(KeyType::KEY_TYPE_ASGN).value(); } auto create_crypto_store() { @@ -270,4 +270,4 @@ TEST_F(AssignmentsTest, assignments_produced_for_non_backing) { memcmp(&our_assignment.cert.vrf.output, vrf_output, kagome::crypto::constants::sr25519::vrf::OUTPUT_SIZE)); -} \ No newline at end of file +} diff --git a/test/core/runtime/binaryen/runtime_external_interface_test.cpp b/test/core/runtime/binaryen/runtime_external_interface_test.cpp index 5d49cf4450..56aa8dfc1c 100644 --- a/test/core/runtime/binaryen/runtime_external_interface_test.cpp +++ b/test/core/runtime/binaryen/runtime_external_interface_test.cpp @@ -29,7 +29,7 @@ using ::testing::Invoke; using ::testing::Return; using kagome::blockchain::BlockHeaderRepositoryMock; -using kagome::crypto::KEY_TYPE_BABE; +using kagome::crypto::KeyType; using kagome::host_api::HostApi; using kagome::host_api::HostApiFactoryMock; using kagome::host_api::HostApiMock; @@ -328,7 +328,7 @@ TEST_F(REITest, ext_logging_max_level_version_1_Test) { } TEST_F(REITest, ext_ed25519_public_keys_v1_Test) { - WasmSize key_type = KEY_TYPE_BABE; + WasmSize key_type = KeyType::BABE; WasmSpan res = PtrSize(1, 2).combine(); EXPECT_CALL(*host_api_, ext_crypto_ed25519_public_keys_version_1(key_type)) @@ -348,7 +348,7 @@ TEST_F(REITest, ext_ed25519_public_keys_v1_Test) { } TEST_F(REITest, ext_ed25519_generate_v1_Test) { - WasmSize key_type = KEY_TYPE_BABE; + WasmSize key_type = KeyType::BABE; WasmSpan seed = PtrSize(1, 2).combine(); WasmPointer res = 4; @@ -371,7 +371,7 @@ TEST_F(REITest, ext_ed25519_generate_v1_Test) { } TEST_F(REITest, ext_ed25519_sign_v1_Test) { - WasmSize key_type = KEY_TYPE_BABE; + WasmSize key_type = KeyType::BABE; WasmPointer key = 1; WasmSpan msg = PtrSize(33, 2).combine(); WasmSpan res = PtrSize(35, 25).combine(); @@ -423,7 +423,7 @@ TEST_F(REITest, ext_ed25519_verify_v1_Test) { } TEST_F(REITest, ext_sr25519_public_keys_v1_Test) { - WasmSize key_type = KEY_TYPE_BABE; + WasmSize key_type = KeyType::BABE; WasmSpan res = PtrSize(1, 2).combine(); @@ -444,7 +444,7 @@ TEST_F(REITest, ext_sr25519_public_keys_v1_Test) { } TEST_F(REITest, ext_sr25519_generate_v1_Test) { - WasmSize key_type = KEY_TYPE_BABE; + WasmSize key_type = KeyType::BABE; WasmSpan seed = PtrSize(1, 2).combine(); WasmPointer res = 4; @@ -467,7 +467,7 @@ TEST_F(REITest, ext_sr25519_generate_v1_Test) { } TEST_F(REITest, ext_sr25519_sign_v1_Test) { - WasmSize key_type = KEY_TYPE_BABE; + WasmSize key_type = KeyType::BABE; WasmPointer key = 1; WasmSpan msg = PtrSize(33, 2).combine(); WasmSpan res = PtrSize(35, 25).combine(); @@ -750,7 +750,7 @@ TEST_F(REITest, ext_storage_set_version_1_Test) { } TEST_F(REITest, ext_storage_get_version_1_Test) { - WasmSize key_type = KEY_TYPE_BABE; + WasmSize key_type = KeyType::BABE; WasmSpan res = PtrSize(1, 2).combine(); EXPECT_CALL(*host_api_, ext_storage_get_version_1(key_type)) @@ -840,7 +840,7 @@ TEST_F(REITest, ext_storage_clear_prefix_version_1_Test) { } TEST_F(REITest, ext_storage_changes_root_version_1_Test) { - WasmSize key_type = KEY_TYPE_BABE; + WasmSize key_type = KeyType::BABE; WasmSpan res = 2; EXPECT_CALL(*host_api_, ext_storage_changes_root_version_1(key_type)) diff --git a/test/mock/core/crypto/session_keys_mock.hpp b/test/mock/core/crypto/session_keys_mock.hpp index 82e4e09c3b..4ad2c6a1a3 100644 --- a/test/mock/core/crypto/session_keys_mock.hpp +++ b/test/mock/core/crypto/session_keys_mock.hpp @@ -23,6 +23,11 @@ namespace kagome::crypto { (const primitives::AuthorityList &), (override)); + MOCK_METHOD(KeypairWithIndexOpt, + getSassafrasKeyPair, + (const primitives::AuthorityList &), + (override)); + MOCK_METHOD(std::shared_ptr, getGranKeyPair, (const primitives::AuthoritySet &),