Skip to content

Commit

Permalink
Integration oracle test
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Nov 5, 2024
1 parent 2e6418f commit c9cfb75
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
Binary file added crates/testing-utils/oracle_example.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions crates/testing-utils/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub const TEST_PROGRAM_WASM_BYTECODE: &[u8] =
pub const FAUCET_PROGRAM: &[u8] = include_bytes!("../faucet_program.wasm");
/// `infinite_loop.wasm` from the `programs` repo.
pub const TEST_INFINITE_LOOP_BYTECODE: &[u8] = include_bytes!("../infinite_loop.wasm");
/// `infinite_loop.wasm` from the `programs` repo.
pub const TEST_ORACLE_BYTECODE: &[u8] = include_bytes!("../oracle_example.wasm");
/// `template_basic_transaction.wasm` from the `programs` repo.
pub const TEST_BASIC_TRANSACTION: &[u8] = include_bytes!("../template_basic_transaction.wasm");
/// `example_custom_hash.wasm` from the `programs` repo.
Expand Down
66 changes: 65 additions & 1 deletion crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use entropy_testing_utils::{
},
constants::{
AUXILARY_DATA_SHOULD_SUCCEED, FAUCET_PROGRAM, FERDIE_X25519_SECRET_KEY,
PREIMAGE_SHOULD_SUCCEED, TEST_BASIC_TRANSACTION, TEST_INFINITE_LOOP_BYTECODE,
PREIMAGE_SHOULD_SUCCEED, TEST_BASIC_TRANSACTION, TEST_INFINITE_LOOP_BYTECODE, TEST_ORACLE_BYTECODE,
TEST_PROGRAM_CUSTOM_HASH, TEST_PROGRAM_WASM_BYTECODE, X25519_PUBLIC_KEYS,
},
substrate_context::{
Expand Down Expand Up @@ -1117,6 +1117,70 @@ async fn test_fail_infinite_program() {
);
}

#[tokio::test]
#[serial]
async fn test_oracle_program() {
initialize_test_logger().await;
clean_tests();

let one = AccountKeyring::One;
let two = AccountKeyring::Two;

let (_validator_ips, _validator_ids) =
spawn_testing_validators(ChainSpecType::Integration).await;

let mnemonic = development_mnemonic(&Some(ValidatorName::Alice));
let (tss_signer, _static_secret) =
get_signer_and_x25519_secret_from_mnemonic(&mnemonic.to_string()).unwrap();

let force_authoring = true;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];

let api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

let non_signer = jump_start_network(&api, &rpc).await.unwrap();
let (relayer_ip_and_key, _) = validator_name_to_relayer_info(non_signer, &api, &rpc).await;

let program_hash = test_client::store_program(
&api,
&rpc,
&two.pair(),
TEST_ORACLE_BYTECODE.to_owned(),
vec![],
vec![],
"block_number_entropy".encode(),
0u8,
)
.await
.unwrap();

let (verifying_key, _registered_info) = test_client::register(
&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();

// Now we'll send off a signature request using the new program
let (_validators_info, signature_request, _validator_ips_and_keys) =
get_sign_tx_data(&api, &rpc, hex::encode(PREIMAGE_SHOULD_SUCCEED), verifying_key).await;

let test_user_res =
submit_transaction_request(relayer_ip_and_key.clone(), signature_request.clone(), one)
.await;

let message_hash = Hasher::keccak(PREIMAGE_SHOULD_SUCCEED);
let decoded_verifying_key =
decode_verifying_key(verifying_key.as_slice().try_into().unwrap()).unwrap();
let all_signers_info = get_all_signers_from_chain(&api, &rpc).await.unwrap();
verify_signature(test_user_res, message_hash, &decoded_verifying_key, &all_signers_info).await;

}

#[tokio::test]
#[serial]
async fn test_device_key_proxy() {
Expand Down

0 comments on commit c9cfb75

Please sign in to comment.