diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index f564932b6..9896fcabd 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -18,7 +18,7 @@ use base64::prelude::{Engine, BASE64_STANDARD}; use bip39::{Language, Mnemonic}; use blake3::hash; use entropy_client::{ - client::{sign, store_program, update_programs}, + client::{register, sign, store_program, update_programs}, user::get_signers_from_chain, }; use entropy_kvdb::{ @@ -1561,6 +1561,81 @@ async fn test_new_registration_flow() { clean_tests(); } + +#[tokio::test] +#[serial] +async fn test_client_register_and_sign() { + clean_tests(); + let account_owner = AccountKeyring::Ferdie.pair(); + let signature_request_author = AccountKeyring::One; + + let add_parent_key = true; + let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key).await; + + let force_authoring = true; + let substrate_context = test_node_process_testing_state(force_authoring).await; + let api = get_api(&substrate_context.ws_url).await.unwrap(); + let rpc = get_rpc(&substrate_context.ws_url).await.unwrap(); + + // Jumpstart the network + jump_start_network(&api, &rpc).await; + + // Store a program + let program_pointer = store_program( + &api, + &rpc, + &account_owner, + TEST_PROGRAM_WASM_BYTECODE.to_owned(), + vec![], + vec![], + vec![], + ) + .await + .unwrap(); + + // Register, using that program + let (verifying_key, _registered_info) = { + let register_on_chain = true; + let mut registrations = register( + &api, + &rpc, + account_owner.clone(), + subxtAccountId32(account_owner.public().0), + BoundedVec(vec![ProgramInstance { program_pointer, program_config: vec![] }]), + register_on_chain, + ) + .await + .unwrap(); + + registrations.pop().unwrap() + }; + + // Sign a message + let recoverable_signature = sign( + &api, + &rpc, + signature_request_author.pair(), + verifying_key, + PREIMAGE_SHOULD_SUCCEED.to_vec(), + Some(AUXILARY_DATA_SHOULD_SUCCEED.to_vec()), + ) + .await + .unwrap(); + + // Check the signature + let message_should_succeed_hash = Hasher::keccak(PREIMAGE_SHOULD_SUCCEED); + let recovery_key_from_sig = VerifyingKey::recover_from_prehash( + &message_should_succeed_hash, + &recoverable_signature.signature, + recoverable_signature.recovery_id, + ) + .unwrap(); + assert_eq!( + verifying_key.to_vec(), + recovery_key_from_sig.to_encoded_point(true).to_bytes().to_vec() + ); +} + #[tokio::test] #[serial] async fn test_mutiple_confirm_done() {