diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index cd780ce01..fc0b8305a 100644 Binary files a/crates/client/entropy_metadata.scale and b/crates/client/entropy_metadata.scale differ diff --git a/crates/threshold-signature-server/src/attestation/api.rs b/crates/threshold-signature-server/src/attestation/api.rs index 081c69c1f..366e81a79 100644 --- a/crates/threshold-signature-server/src/attestation/api.rs +++ b/crates/threshold-signature-server/src/attestation/api.rs @@ -24,11 +24,11 @@ use crate::{ AppState, }; use axum::{body::Bytes, extract::State, http::StatusCode}; -use entropy_kvdb::kv_manager::{KvManager}; +use entropy_kvdb::kv_manager::KvManager; use entropy_shared::OcwMessageAttestationRequest; use parity_scale_codec::Decode; use sp_core::Pair; -use subxt::{tx::PairSigner}; +use subxt::tx::PairSigner; use x25519_dalek::StaticSecret; /// HTTP POST endpoint to initiate a TDX attestation. diff --git a/crates/threshold-signature-server/src/attestation/tests.rs b/crates/threshold-signature-server/src/attestation/tests.rs index f9883fcca..54ee6de57 100644 --- a/crates/threshold-signature-server/src/attestation/tests.rs +++ b/crates/threshold-signature-server/src/attestation/tests.rs @@ -13,15 +13,22 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . use crate::{ + attestation::api::validate_new_attest, chain_api::{entropy, get_api, get_rpc}, helpers::{ substrate::query_chain, - tests::{initialize_test_logger, run_to_block, spawn_testing_validators, ChainSpecType}, + tests::{ + initialize_test_logger, run_to_block, setup_client, spawn_testing_validators, + ChainSpecType, + }, }, + launch::LATEST_BLOCK_NUMBER_ATTEST, }; use entropy_kvdb::clean_tests; +use entropy_shared::OcwMessageAttestationRequest; use entropy_testing_utils::{ - constants::TSS_ACCOUNTS, substrate_context::test_node_process_stationary, + constants::TSS_ACCOUNTS, + substrate_context::{test_context_stationary, test_node_process_stationary}, }; use serial_test::serial; @@ -64,3 +71,31 @@ async fn test_attest() { } panic!("Waited 10 blocks and attestation is still pending"); } + +#[tokio::test] +#[serial] +async fn test_attest_validation_fail() { + initialize_test_logger().await; + clean_tests(); + + let cxt = test_context_stationary().await; + let rpc = get_rpc(&cxt.node_proc.ws_url).await.unwrap(); + let kv = setup_client().await; + + let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; + let ocw_message = OcwMessageAttestationRequest { tss_account_ids: vec![], block_number }; + let err_stale_data = + validate_new_attest(block_number, &ocw_message, &kv).await.map_err(|e| e.to_string()); + assert_eq!(err_stale_data, Err("Data is stale".to_string())); + run_to_block(&rpc, block_number).await; + + // manipulates kvdb to get to repeated data error + kv.kv().delete(LATEST_BLOCK_NUMBER_ATTEST).await.unwrap(); + let reservation = kv.kv().reserve_key(LATEST_BLOCK_NUMBER_ATTEST.to_string()).await.unwrap(); + kv.kv().put(reservation, (block_number + 5).to_be_bytes().to_vec()).await.unwrap(); + + let err_repeated_data = + validate_new_attest(block_number, &ocw_message, &kv).await.map_err(|e| e.to_string()); + assert_eq!(err_repeated_data, Err("Data is repeated".to_string())); + clean_tests(); +} diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index 7366c2fc5..111efb54f 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -29,7 +29,7 @@ use entropy_protocol::{ }; use entropy_shared::{ HashingAlgorithm, DAVE_VERIFYING_KEY, DEFAULT_VERIFYING_KEY_NOT_REGISTERED, DEVICE_KEY_HASH, - EVE_VERIFYING_KEY, NETWORK_PARENT_KEY, + NETWORK_PARENT_KEY, }; use entropy_testing_utils::{ chain_api::{