Skip to content

Commit

Permalink
fix: test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
tbraun96 committed Dec 11, 2024
1 parent 747c73d commit 30c8a51
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 74 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,10 @@ jobs:
with:
cache-on-failure: "true"

- uses: taiki-e/install-action@v2
with:
tool: nextest

- name: Forge build
run: forge update && forge build

- uses: taiki-e/github-actions/free-device-space@main

- name: Download Tangle Manual Sealing
run: |
wget https://github.com/tangle-network/tangle/releases/download/v1.2.3/tangle-testnet-manual-seal-linux-amd64
chmod +x tangle-testnet-manual-seal-linux-amd64
- name: tests
run: TANGLE_NODE=$(pwd)/tangle-testnet-manual-seal-linux-amd64 cargo nextest run
run: cargo test
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ auto_detect_remappings = true

[dependencies]
forge-std = "1.9.4"
tnt-core = { version = "0.1.0", git = "https://github.com/tangle-network/tnt-core.git", rev = "df6d5d6da3c82217405c408d3c0b11369bb3e5c2" }
tnt-core = "0.1.0"

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
12 changes: 0 additions & 12 deletions soldeer.lock

This file was deleted.

2 changes: 1 addition & 1 deletion src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub async fn keygen(t: u16, context: WstsContext) -> Result<Vec<u8>, GadgetError
parties.clone(),
);

let state = protocol(n as _, i as _, t as _, k as _, network).await?;
let state = protocol(n as _, i as _, k as _, t as _, network).await?;

gadget_sdk::info!(
"Ending WSTS Keygen for party {i}, n={n}, eid={}",
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ async fn main() {

let tangle_config = TangleConfig::default();
let keygen = wsts_blueprint::keygen::KeygenEventHandler::new(&env, context.clone()).await?;
let signing = wsts_blueprint::signing::SignEventHandler::new(&env, context.clone()).await?;

BlueprintRunner::new(tangle_config, env.clone())
.job(keygen)
.job(signing)
.run()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use gadget_sdk::Error;
pub fn validate_parameters(n: u32, k: u32, t: u32) -> Result<(), Error> {
if k % n != 0 {
return Err(Error::Job {
reason: "K % N != 0".to_string(),
reason: format!("K({k} % N({n} != 0"),
});
}

Expand Down
105 changes: 56 additions & 49 deletions tests/wsts.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#[cfg(test)]
mod e2e {
use std::sync::atomic::AtomicU64;

use ::blueprint_test_utils::test_ext::new_test_ext_blueprint_manager;
pub use ::blueprint_test_utils::{
run_test_blueprint_manager, setup_log, submit_job, wait_for_completion_of_tangle_job, Job,
};
use blueprint_test_utils::tangle::NodeConfig;
use blueprint_test_utils::*;
use wsts_blueprint::keygen::KEYGEN_JOB_ID;
use wsts_blueprint::signing::SIGN_JOB_ID;

const N: usize = 3;
const T: usize = 2;

// The macro takes this variable as an argument, and will update it so that
// when we pass the signing arguments, we can pass the associated keygen call id
static KEYGEN_CALL_ID: AtomicU64 = AtomicU64::new(0);

use ::blueprint_test_utils::test_ext::new_test_ext_blueprint_manager;
pub use ::blueprint_test_utils::{
run_test_blueprint_manager, setup_log, submit_job, wait_for_completion_of_tangle_job, Job,
};
#[tokio::test(flavor = "multi_thread")]
async fn test_blueprint() {
setup_log();
Expand All @@ -26,16 +22,17 @@ mod e2e {
new_test_ext_blueprint_manager::<N, 1, String, _, _>(
tmp_dir_path,
run_test_blueprint_manager,
NodeConfig::new(false),
)
.await
.execute_with_async(|client, handles, blueprint| async move {
.execute_with_async(|client, handles, blueprint, _| async move {
let keypair = handles[0].sr25519_id().clone();
let service = &blueprint.services[KEYGEN_JOB_ID as usize];

let service_id = service.id;
gadget_sdk::info!(
"Submitting KEYGEN job {} with service ID {service_id}" , KEYGEN_JOB_ID
);
"Submitting KEYGEN job {KEYGEN_JOB_ID} with service ID {service_id}",
);

let job_args = vec![(InputValue::Uint16(T as u16))];
let call_id = get_next_call_id(client)
Expand All @@ -46,19 +43,19 @@ mod e2e {
client,
&keypair,
service_id,
Job::from(0),
Job::from(KEYGEN_JOB_ID),
job_args,
call_id,
)
.await
.expect("Failed to submit job");

let keygen_call_id = job.call_id;
KEYGEN_CALL_ID.store(keygen_call_id, std::sync::atomic::Ordering::Relaxed);

gadget_sdk::info!(
"Submitted KEYGEN job {} with service ID {service_id} has call id {keygen_call_id}" , KEYGEN_JOB_ID ,
);
"Submitted KEYGEN job {} with service ID {service_id} has call id {keygen_call_id}",
KEYGEN_JOB_ID
);

let job_results = wait_for_completion_of_tangle_job(client, service_id, keygen_call_id, T)
.await
Expand All @@ -69,68 +66,78 @@ mod e2e {

let expected_outputs = vec![];
if !expected_outputs.is_empty() {
assert_eq!(job_results.result.len(), expected_outputs.len(), "Number of keygen outputs doesn't match expected");

for (result, expected) in job_results.result.into_iter().zip(expected_outputs.into_iter()) {
assert_eq!(
job_results.result.len(),
expected_outputs.len(),
"Number of keygen outputs doesn't match expected"
);

for (result, expected) in job_results
.result
.into_iter()
.zip(expected_outputs.into_iter())
{
assert_eq!(result, expected);
}
} else {
gadget_sdk::info!( "No expected outputs specified, skipping keygen verification" );
gadget_sdk::info!("No expected outputs specified, skipping keygen verification");
}

log::info!( "Keygen job completed successfully! Moving on to signing ..." );

gadget_sdk::info!("Keygen job completed successfully! Moving on to signing ...");

let service = &blueprint.services[0];

let service_id = service.id;
gadget_sdk::info!(
"Submitting SIGNING job {} with service ID {service_id}" , SIGN_JOB_ID
"Submitting SIGNING job {} with service ID {service_id}",
SIGN_JOB_ID
);

let job_args = vec![
InputValue::Uint64(keygen_call_id),
InputValue::List(BoundedVec(vec![
InputValue::Uint8(1),
InputValue::Uint8(2),
InputValue::Uint8(3),
])),
];

let job_args = vec![(InputValue::Uint64(KEYGEN_CALL_ID.load(std::sync::atomic::Ordering::SeqCst))), (InputValue::List(BoundedVec(vec![
InputValue::Uint8(1),
InputValue::Uint8(2),
InputValue::Uint8(3),
]))
)];

let call_id = get_next_call_id(client)
.await
.expect("Failed to get next job id")
.saturating_sub(1);
let job = submit_job(
client,
&keypair,
service_id,
Job::from(0),
Job::from(SIGN_JOB_ID),
job_args,
call_id,
call_id + 1,
)
.await
.expect("Failed to submit job");

let signing_call_id = job.call_id;

gadget_sdk::info!(
"Submitted SIGNING job {} with service ID {service_id} has call id {signing_call_id}" , SIGN_JOB_ID
);
"Submitted SIGNING job {SIGN_JOB_ID} with service ID {service_id} has call id {signing_call_id}",
);

let job_results =
wait_for_completion_of_tangle_job(client, service_id, signing_call_id, T)
.await
.expect("Failed to wait for job completion");
let job_results = wait_for_completion_of_tangle_job(client, service_id, signing_call_id, T)
.await
.expect("Failed to wait for job completion");

let expected_outputs = vec![];
if !expected_outputs.is_empty() {
assert_eq!(job_results.result.len(), expected_outputs.len(), "Number of signing outputs doesn't match expected");

for (result, expected) in job_results.result.into_iter().zip(expected_outputs.into_iter()) {
assert_eq!(
job_results.result.len(),
expected_outputs.len(),
"Number of signing outputs doesn't match expected"
);

for (result, expected) in job_results
.result
.into_iter()
.zip(expected_outputs.into_iter())
{
assert_eq!(result, expected);
}
} else {
gadget_sdk::info!( "No expected outputs specified, skipping signing verification" );
gadget_sdk::info!("No expected outputs specified, skipping signing verification");
}
})
.await
Expand Down

0 comments on commit 30c8a51

Please sign in to comment.