Skip to content

Commit

Permalink
Improve test for mock attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Aug 12, 2024
1 parent 5881b0e commit 5c73ab4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/threshold-signature-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ ethers-core ="2.0.14"
schnorrkel ={ version="0.11.4", default-features=false, features=["std"] }
schemars ={ version="0.8.21" }
subxt-signer="0.35.3"
tdx-quote ={ git="https://github.com/entropyxyz/tdx-quote", features=["mock"] }

# Note: We don't specify versions here because otherwise we run into a cyclical dependency between
# `entropy-tss` and `entropy-testing-utils` when we try and publish the `entropy-tss` crate.
Expand Down
4 changes: 2 additions & 2 deletions crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ pub async fn attest(
pub async fn attest(
State(app_state): State<AppState>,
input: Bytes,
) -> Result<(StatusCode, String), ValidatorErr> {
) -> Result<(StatusCode, Bytes), ValidatorErr> {
let nonce = input[..].try_into()?;

let rpc = get_rpc(&app_state.configuration.endpoint).await?;
Expand All @@ -401,5 +401,5 @@ pub async fn attest(
let quote = tdx_quote::Quote::mock(signing_key.clone(), input_data.0);
// Here we would submit an attest extrinsic to the chain - but for now we just include it in the
// response
Ok((StatusCode::OK, format!("{:?}", quote)))
Ok((StatusCode::OK, Bytes::from(quote.as_bytes().to_vec())))
}
15 changes: 11 additions & 4 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,18 @@ async fn test_attest() {
initialize_test_logger().await;
clean_tests();

// let cxt = test_node_process_testing_state(false).await;
let _cxt = test_node_process_testing_state(false).await;
let (_validator_ips, _validator_ids) = spawn_testing_validators(false).await;

let client = reqwest::Client::new();
let res =
client.post(format!("http://127.0.0.1:3001/attest")).body(Vec::new()).send().await.unwrap();
println!("{:?}", res.text().await);
let res = client
.post(format!("http://127.0.0.1:3001/attest"))
.body([0; 32].to_vec())
.send()
.await
.unwrap();
assert_eq!(res.status(), 200);
let quote = res.bytes().await.unwrap();
// This verifies the signature in the quote
tdx_quote::Quote::from_bytes(&quote).unwrap();
}

0 comments on commit 5c73ab4

Please sign in to comment.