From fe93e35be28dc1a91e1144a3ce58fadb03594aa4 Mon Sep 17 00:00:00 2001 From: peg Date: Tue, 20 Aug 2024 12:17:39 +0200 Subject: [PATCH] Fix test --- .../src/attestation/api.rs | 7 ++++--- .../src/attestation/tests.rs | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/threshold-signature-server/src/attestation/api.rs b/crates/threshold-signature-server/src/attestation/api.rs index 9850b380b..81bce6038 100644 --- a/crates/threshold-signature-server/src/attestation/api.rs +++ b/crates/threshold-signature-server/src/attestation/api.rs @@ -60,11 +60,12 @@ pub async fn attest( let block_number = rpc.chain_get_header(None).await?.ok_or_else(|| AttestationErr::BlockNumber)?.number; - let quote = create_quote(block_number, nonce, &signer, &x25519_secret).await?; + // We add 1 to the block number as this will be processed in the next block + let quote = create_quote(block_number + 1, nonce, &signer, &x25519_secret).await?; + // Submit the quote let attest_tx = entropy::tx().attestation().attest(quote.clone()); - let res = submit_transaction(&api, &rpc, &signer, &attest_tx, None).await; - println!("Succesfully submitted tx {:?}", res); + submit_transaction(&api, &rpc, &signer, &attest_tx, None).await?; Ok(StatusCode::OK) } diff --git a/crates/threshold-signature-server/src/attestation/tests.rs b/crates/threshold-signature-server/src/attestation/tests.rs index d4ebee77c..fb31117b9 100644 --- a/crates/threshold-signature-server/src/attestation/tests.rs +++ b/crates/threshold-signature-server/src/attestation/tests.rs @@ -48,12 +48,17 @@ async fn test_attest() { }; assert_eq!(nonce, [0; 32]); - // Wait a few blocks for hopefully something to happen - let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number; - run_to_block(&rpc, block_number + 10).await; + // Wait for the attestation to be handled + for _ in 0..10 { + let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number; + run_to_block(&rpc, block_number + 1).await; - // There should be no more pending attestation as the attestation has been handled - let pending_attestation_query = - entropy::storage().attestation().pending_attestations(&TSS_ACCOUNTS[0]); - assert!(query_chain(&api, &rpc, pending_attestation_query, None).await.unwrap().is_none()); + // There should be no more pending attestation as the attestation has been handled + let pending_attestation_query = + entropy::storage().attestation().pending_attestations(&TSS_ACCOUNTS[0]); + if query_chain(&api, &rpc, pending_attestation_query, None).await.unwrap().is_none() { + return; + } + } + panic!("Waited 10 blocks and attestation is still pending"); }