Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleaning up TestContext #309

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions integration-tests/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod mpc;

use curv::elliptic::curves::{Ed25519, Point};
use futures::future::BoxFuture;
use hyper::StatusCode;
use mpc_recovery::{
firewall::allowed::DelegateActionRelayer,
Expand All @@ -20,15 +19,15 @@ const GCP_PROJECT_ID: &str = "mpc-recovery-gcp-project";
// TODO: figure out how to instantiate and use a local firebase deployment
pub const FIREBASE_AUDIENCE_ID: &str = "test_audience";

pub struct TestContext<'a> {
leader_node: &'a containers::LeaderNodeApi,
pk_set: &'a Vec<Point<Ed25519>>,
worker: &'a Worker<Sandbox>,
signer_nodes: &'a Vec<containers::SignerNodeApi>,
pub struct TestContext {
leader_node: containers::LeaderNodeApi,
pk_set: Vec<Point<Ed25519>>,
worker: Worker<Sandbox>,
signer_nodes: Vec<containers::SignerNodeApi>,
gcp_datastore_url: String,
}

impl<'a> TestContext<'a> {
impl TestContext {
pub async fn gcp_service(&self) -> anyhow::Result<GcpService> {
GcpService::new(
"dev".into(),
Expand All @@ -39,9 +38,10 @@ impl<'a> TestContext<'a> {
}
}

async fn with_nodes<F>(nodes: usize, f: F) -> anyhow::Result<()>
async fn with_nodes<Task, Fut, Val>(nodes: usize, f: Task) -> anyhow::Result<()>
where
F: for<'a> FnOnce(TestContext<'a>) -> BoxFuture<'a, anyhow::Result<()>>,
Task: FnOnce(TestContext) -> Fut,
Fut: core::future::Future<Output = anyhow::Result<Val>>,
{
let docker_client = containers::DockerClient::default();
docker_client.create_network(NETWORK).await?;
Expand Down Expand Up @@ -95,16 +95,16 @@ where
.await?;

f(TestContext {
leader_node: &leader_node.api(
leader_node: leader_node.api(
&relayer_ctx.sandbox.local_address,
&DelegateActionRelayer {
url: relayer_ctx.relayer.local_address.clone(),
api_key: None,
},
),
pk_set: &pk_set,
signer_nodes: &signer_nodes.iter().map(|n| n.api()).collect(),
worker: &relayer_ctx.worker,
pk_set,
signer_nodes: signer_nodes.iter().map(|n| n.api()).collect(),
worker: relayer_ctx.worker.clone(),
gcp_datastore_url: datastore.local_address,
})
.await?;
Expand Down Expand Up @@ -177,7 +177,7 @@ mod check {
use workspaces::AccountId;

pub async fn access_key_exists(
ctx: &TestContext<'_>,
ctx: &TestContext,
account_id: &AccountId,
public_key: &PublicKey,
) -> anyhow::Result<()> {
Expand All @@ -196,7 +196,7 @@ mod check {
}

pub async fn access_key_does_not_exists(
ctx: &TestContext<'_>,
ctx: &TestContext,
account_id: &AccountId,
public_key: &str,
) -> anyhow::Result<()> {
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/tests/mpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod negative;
mod positive;

pub async fn register_account(
ctx: &TestContext<'_>,
ctx: &TestContext,
user_id: &AccountId,
user_sk: &SecretKey,
user_pk: &PublicKey,
Expand Down Expand Up @@ -45,10 +45,10 @@ pub async fn register_account(
}

pub async fn new_random_account(
ctx: &TestContext<'_>,
ctx: &TestContext,
user_lak: Option<LimitedAccessKey>,
) -> anyhow::Result<(AccountId, SecretKey, OidcToken)> {
let account_id = account::random(ctx.worker)?;
let account_id = account::random(&ctx.worker)?;
let user_secret_key = key::random_sk();
let user_public_key = user_secret_key.public_key();
let oidc_token = OidcToken::random();
Expand All @@ -66,7 +66,7 @@ pub async fn new_random_account(
}

pub async fn fetch_recovery_pk(
ctx: &TestContext<'_>,
ctx: &TestContext,
user_sk: &SecretKey,
user_oidc: &OidcToken,
) -> anyhow::Result<PublicKey> {
Expand All @@ -84,7 +84,7 @@ pub async fn fetch_recovery_pk(

/// Add a new random public key or a supplied public key.
pub async fn add_pk_and_check_validity(
ctx: &TestContext<'_>,
ctx: &TestContext,
user_id: &AccountId,
user_sk: &SecretKey,
user_oidc: &OidcToken,
Expand Down
Loading