Skip to content

Commit

Permalink
WIP test helper fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Aug 30, 2024
1 parent b5cd90a commit c49f981
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 23 deletions.
42 changes: 42 additions & 0 deletions crates/threshold-signature-server/src/helpers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,45 @@ pub async fn jump_start_network_with_signer(
submit_transaction(api, rpc, &tss_signer, &jump_start_confirm_request, None).await.unwrap();
}
}

/// Helper to store a program and register a user. Returns the verify key
#[cfg(test)]
pub async fn store_program_and_register(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
user: &sr25519::Pair,
deployer: &sr25519::Pair,
) -> ([u8; 33], sp_core::H256) {
use entropy_client::{
self as test_client,
chain_api::entropy::runtime_types::pallet_registry::pallet::ProgramInstance,
};
use entropy_testing_utils::constants::TEST_PROGRAM_WASM_BYTECODE;
use sp_core::Pair;

let program_hash = test_client::store_program(
&api,
&rpc,
deployer, // This is our program deployer
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
vec![],
)
.await
.unwrap();

println!("Program hash {:?}", program_hash);

let (verifying_key, _registered_info) = test_client::register(
&api,
&rpc,
user.clone(),
SubxtAccountId32(deployer.public().0), // Program modification account
BoundedVec(vec![ProgramInstance { program_pointer: program_hash, program_config: vec![] }]),
)
.await
.unwrap();

(verifying_key, program_hash)
}
50 changes: 27 additions & 23 deletions crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ use crate::{
substrate::{get_oracle_data, query_chain, submit_transaction},
tests::{
create_clients, initialize_test_logger, jump_start_network_with_signer, remove_program,
run_to_block, setup_client, spawn_testing_validators, unsafe_get,
run_to_block, setup_client, spawn_testing_validators, store_program_and_register,
unsafe_get,
},
user::compute_hash,
validator::get_signer_and_x25519_secret_from_mnemonic,
Expand Down Expand Up @@ -182,28 +183,31 @@ async fn test_signature_requests_fail_on_different_conditions() {
// for later
jump_start_network(&entropy_api, &rpc).await;

// We need to store a program in order to be able to register succesfully
let program_hash = test_client::store_program(
&entropy_api,
&rpc,
&two.pair(), // This is our program deployer
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
vec![],
)
.await
.unwrap();

let (verifying_key, _registered_info) = test_client::register(
&entropy_api,
&rpc,
one.clone().into(), // This is our program modification account
subxtAccountId32(two.public().0), // This is our signature request account
BoundedVec(vec![ProgramInstance { program_pointer: program_hash, program_config: vec![] }]),
)
.await
.unwrap();
// Register the user with a test program
let (verifying_key, program_hash) =
store_program_and_register(&entropy_api, &rpc, &one.pair(), &two.pair()).await;
// // We need to store a program in order to be able to register succesfully
// let program_hash = test_client::store_program(
// &entropy_api,
// &rpc,
// &two.pair(), // This is our program deployer
// TEST_PROGRAM_WASM_BYTECODE.to_owned(),
// vec![],
// vec![],
// vec![],
// )
// .await
// .unwrap();
//
// let (verifying_key, _registered_info) = test_client::register(
// &entropy_api,
// &rpc,
// one.clone().into(), // This is our program modification account
// subxtAccountId32(two.public().0), // This is our signature request account
// BoundedVec(vec![ProgramInstance { program_pointer: program_hash, program_config: vec![] }]),
// )
// .await
// .unwrap();

// Test: We check that an account with a program succeeds in submiting a signature request
let (validators_info, mut signature_request, validator_ips_and_keys) =
Expand Down

0 comments on commit c49f981

Please sign in to comment.