Skip to content

Commit

Permalink
adding bls runtime tests and other runtime tests for crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
coax1d committed Dec 2, 2024
1 parent 547695f commit 22694e4
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion substrate/test-utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use scale_info::TypeInfo;
use sp_application_crypto::Ss58Codec;
use sp_keyring::AccountKeyring;

use sp_application_crypto::{ecdsa, ed25519, sr25519, RuntimeAppPublic};
use sp_application_crypto::{ecdsa, ed25519, sr25519, blsRuntimeAppPublic, bls381};
use sp_core::{OpaqueMetadata, RuntimeDebug};
use sp_trie::{
trie_types::{TrieDBBuilder, TrieDBMutBuilderV1},
Expand Down Expand Up @@ -219,6 +219,11 @@ decl_runtime_apis! {
///
/// Returns the signature generated for the message `ecdsa`.
fn test_ecdsa_crypto() -> (ecdsa::AppSignature, ecdsa::AppPublic);
/// Test that 'bls381' crypto works in the runtime
///
/// Returns the signature generated for the message `bls381`.
#[cfg(feature = "bls-experimental")]
fn test_bls381_crypto() -> (bls381::AppSignature, bls381::AppPublic);
/// Run various tests against storage.
fn test_storage();
/// Check a witness.
Expand Down Expand Up @@ -580,6 +585,11 @@ impl_runtime_apis! {
test_ecdsa_crypto()
}

#[cfg(feature = "bls-experimental")]
fn test_bls381_crypto() -> (bls381::AppSignature, bls381::AppPublic) {
test_bls381_crypto()
}

fn test_storage() {
test_read_storage();
test_read_child_storage();
Expand Down Expand Up @@ -805,6 +815,23 @@ fn test_ecdsa_crypto() -> (ecdsa::AppSignature, ecdsa::AppPublic) {
(signature, public0)
}

#[cfg(feature = "bls-experimental")]
fn test_bls381_crypto() -> (bls381::AppSignature, bls381::AppPublic) {
let public0 = bls381::AppPublic::generate_pair(None);
let public1 = bls381::AppPublic::generate_pair(None);
let public2 = bls381::AppPublic::generate_pair(None);

let all = bls381::AppPublic::all();
assert!(all.contains(&public0));
assert!(all.contains(&public1));
assert!(all.contains(&public2));

let signature = public0.sign(&"bls381").expect("Generates a valid `bls381` signature.");

assert!(public0.verify(&"bls381", &signature));
(signature, public0)
}

fn test_read_storage() {
const KEY: &[u8] = b":read_storage";
sp_io::storage::set(KEY, b"test");
Expand Down

0 comments on commit 22694e4

Please sign in to comment.