-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new registration flow test to TSS side #997
Changes from all commits
008fab6
9dce852
8f4b951
fa6eff0
8db5b01
eb04176
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ use subxt::{ | |
Config, OnlineClient, | ||
}; | ||
use subxt_signer::ecdsa::PublicKey as EcdsaPublicKey; | ||
use synedrion::{ecdsa::VerifyingKey as SynedrionVerifyingKey, DeriveChildKey}; | ||
use synedrion::{ | ||
k256::ecdsa::{RecoveryId, Signature as k256Signature, VerifyingKey}, | ||
AuxInfo, ThresholdKeyShare, | ||
|
@@ -828,6 +829,32 @@ pub async fn put_register_request_on_chain( | |
submit_transaction(api, rpc, &sig_req_account, ®istering_tx, None).await.unwrap(); | ||
} | ||
|
||
/// Registers an account on-chain using the new registration flow. | ||
pub async fn put_new_register_request_on_chain( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
signature_request_account: &Sr25519Keyring, | ||
program_modification_account: subxtAccountId32, | ||
program_instance: BoundedVec<ProgramInstance>, | ||
) -> Result<entropy::registry::events::AccountRegistered, entropy_client::substrate::SubstrateError> | ||
{ | ||
let signature_request_account = | ||
PairSigner::<EntropyConfig, sp_core::sr25519::Pair>::new(signature_request_account.pair()); | ||
|
||
let registering_tx = | ||
entropy::tx().registry().register_on_chain(program_modification_account, program_instance); | ||
|
||
let events = | ||
submit_transaction(api, rpc, &signature_request_account, ®istering_tx, None).await?; | ||
|
||
// Since we're only submitting one request above, looking for the first event as opposed to | ||
// say, all events, should be fine. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nice. But in our actual production client code we will still need a loop to filter out the events of other users, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that is correct |
||
let registered_event = | ||
events.find_first::<entropy::registry::events::AccountRegistered>()?.unwrap(); | ||
|
||
Ok(registered_event) | ||
} | ||
|
||
pub async fn put_jumpstart_request_on_chain( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
|
@@ -1297,6 +1324,107 @@ async fn test_faucet() { | |
clean_tests(); | ||
} | ||
|
||
#[tokio::test] | ||
#[serial] | ||
async fn test_new_registration_flow() { | ||
initialize_test_logger().await; | ||
clean_tests(); | ||
|
||
let alice = AccountKeyring::Alice; | ||
let bob = AccountKeyring::Bob; | ||
let charlie = AccountKeyring::Charlie; | ||
|
||
let add_parent_key_to_kvdb = true; | ||
let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key_to_kvdb).await; | ||
|
||
// Here we need to use `--chain=integration-tests` force authoring otherwise we won't be able | ||
// to get our chain in the right state to be jump started. | ||
let force_authoring = true; | ||
let substrate_context = test_node_process_testing_state(force_authoring).await; | ||
let entropy_api = get_api(&substrate_context.ws_url).await.unwrap(); | ||
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap(); | ||
|
||
// We first need to jump start the network and grab the resulting network wide verifying key | ||
// for later | ||
jump_start_network(&entropy_api, &rpc).await; | ||
|
||
let jump_start_progress_query = entropy::storage().staking_extension().jump_start_progress(); | ||
let jump_start_progress = | ||
query_chain(&entropy_api, &rpc, jump_start_progress_query, None).await.unwrap().unwrap(); | ||
|
||
let network_verifying_key = jump_start_progress.verifying_key.unwrap().0; | ||
|
||
// We need to store a program in order to be able to register succesfully | ||
let program_hash = store_program( | ||
&entropy_api, | ||
&rpc, | ||
&bob.pair(), // This is our program deployer | ||
TEST_PROGRAM_WASM_BYTECODE.to_owned(), | ||
vec![], | ||
vec![], | ||
vec![], | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
let registration_request = put_new_register_request_on_chain( | ||
&entropy_api, | ||
&rpc, | ||
&alice, // This is our signature request account | ||
charlie.to_account_id().into(), // This is our program modification account | ||
BoundedVec(vec![ProgramInstance { program_pointer: program_hash, program_config: vec![] }]), | ||
) | ||
.await; | ||
|
||
assert!( | ||
matches!(registration_request, Ok(_)), | ||
"We expect our registration request to succeed." | ||
); | ||
|
||
let entropy::registry::events::AccountRegistered( | ||
_actual_signature_request_account, | ||
actual_verifying_key, | ||
) = registration_request.unwrap(); | ||
|
||
// This is slightly more convenient to work with later one | ||
let actual_verifying_key = actual_verifying_key.0; | ||
|
||
// Next we want to check that the info that's on-chain is what we actually expect | ||
let registered_info = crate::helpers::substrate::get_registered_details( | ||
&entropy_api, | ||
&rpc, | ||
actual_verifying_key.to_vec(), | ||
) | ||
.await; | ||
|
||
assert!( | ||
matches!(registered_info, Ok(_)), | ||
"We expect that the verifying key we got back matches registration entry in storage." | ||
); | ||
|
||
assert_eq!( | ||
registered_info.unwrap().program_modification_account, | ||
charlie.to_account_id().into() | ||
); | ||
|
||
// Next, let's check that the child verifying key matches | ||
let network_verifying_key = | ||
SynedrionVerifyingKey::try_from(network_verifying_key.as_slice()).unwrap(); | ||
|
||
// We hardcode the derivation path here since we know that there's only been one registration | ||
// request (ours). | ||
let derivation_path = "m/0/0".parse().unwrap(); | ||
let expected_verifying_key = | ||
network_verifying_key.derive_verifying_key_bip32(&derivation_path).unwrap(); | ||
let expected_verifying_key = expected_verifying_key.to_encoded_point(true).as_bytes().to_vec(); | ||
|
||
assert_eq!( | ||
expected_verifying_key, actual_verifying_key, | ||
"The derived child key doesn't match our registered verifying key." | ||
); | ||
|
||
clean_tests(); | ||
} | ||
#[tokio::test] | ||
#[serial] | ||
async fn test_mutiple_confirm_done() { | ||
|
@@ -1471,3 +1599,25 @@ pub async fn get_sign_tx_data( | |
|
||
(validators_info, generic_msg, validator_ips_and_keys) | ||
} | ||
|
||
pub async fn jump_start_network( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was gonna say 'don't we already have something like this?' but +1 for making it generic |
||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
) { | ||
let alice = AccountKeyring::Alice; | ||
let signer = PairSigner::<EntropyConfig, sr25519::Pair>::new(alice.clone().into()); | ||
|
||
let jump_start_request = entropy::tx().registry().jump_start_network(); | ||
let _result = submit_transaction(api, rpc, &signer, &jump_start_request, None).await.unwrap(); | ||
|
||
let validators_names = vec![ValidatorName::Bob, ValidatorName::Charlie, ValidatorName::Dave]; | ||
for validator_name in validators_names { | ||
let mnemonic = development_mnemonic(&Some(validator_name)); | ||
let (tss_signer, _static_secret) = | ||
get_signer_and_x25519_secret_from_mnemonic(&mnemonic.to_string()).unwrap(); | ||
let jump_start_confirm_request = | ||
entropy::tx().registry().confirm_jump_start(BoundedVec(EVE_VERIFYING_KEY.to_vec())); | ||
|
||
submit_transaction(api, rpc, &tss_signer, &jump_start_confirm_request, None).await.unwrap(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,15 +143,6 @@ pub mod pallet { | |
version_number: T::KeyVersionNumber::get(), | ||
}, | ||
); | ||
|
||
RegisteredOnChain::<T>::insert( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So no more pre-registered accounts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the moment no. I wrote a little thing out in the commit message removing this why it doesn't make sense to have them. tl;dr registration requires a jumpstarted network as a pre-req and that's a bit of a tricky setup using the Genesis config code. It's something we might want to look at in the future if we find that manually setting everything up with extrinsics becomes cumbersome |
||
verifying_key.clone(), | ||
RegisteredInfo { | ||
programs_data: BoundedVec::default(), | ||
program_modification_account: account_id.clone(), | ||
version_number: T::KeyVersionNumber::get(), | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know this is just copied from the fn above, but i feel like this should be called
program_instances
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I'm not running the CI again to fix it in this PR though lol. Will do in a different one