Skip to content

Commit

Permalink
Merge pull request fedimint#5067 from m1sterc001guy/fed_admin
Browse files Browse the repository at this point in the history
chore: create admin federation client in fedimint-testing
  • Loading branch information
m1sterc001guy authored Apr 23, 2024
2 parents 5cb0c79 + dc3b443 commit 4cdf7df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 20 additions & 2 deletions fedimint-testing/src/federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use fedimint_client::module::init::ClientModuleInitRegistry;
use fedimint_client::secret::{PlainRootSecretStrategy, RootSecretStrategy};
use fedimint_client::{Client, ClientHandleArc};
use fedimint_client::{AdminCreds, Client, ClientHandleArc};
use fedimint_core::admin_client::{ConfigGenParamsConsensus, PeerServerParams};
use fedimint_core::config::{
ClientConfig, FederationId, ServerModuleConfigGenParamsRegistry, ServerModuleInitRegistry,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl FederationTest {
.to_client_config(&self.server_init)
.unwrap();

self.new_client_with(client_config, MemDatabase::new().into())
self.new_client_with(client_config, MemDatabase::new().into(), None)
.await
}

Expand All @@ -67,19 +67,37 @@ impl FederationTest {
RocksDb::open(tempfile::tempdir().expect("Couldn't create temp dir"))
.expect("Couldn't open DB")
.into(),
None,
)
.await
}

/// Create a new admin client connected to this fed
pub async fn new_admin_client(&self, peer_id: PeerId, auth: ApiAuth) -> ClientHandleArc {
let client_config = self.configs[&PeerId::from(0)]
.consensus
.to_client_config(&self.server_init)
.unwrap();

let admin_creds = AdminCreds { peer_id, auth };

self.new_client_with(client_config, MemDatabase::new().into(), Some(admin_creds))
.await
}

pub async fn new_client_with(
&self,
client_config: ClientConfig,
db: Database,
admin_creds: Option<AdminCreds>,
) -> ClientHandleArc {
info!(target: LOG_TEST, "Setting new client with config");
let mut client_builder = Client::builder(db);
client_builder.with_module_inits(self.client_init.clone());
client_builder.with_primary_module(self.primary_client);
if let Some(admin_creds) = admin_creds {
client_builder.set_admin_creds(admin_creds);
}
let client_secret = Client::load_or_generate_client_secret(client_builder.db_no_decoders())
.await
.unwrap();
Expand Down
4 changes: 3 additions & 1 deletion modules/fedimint-dummy-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ async fn client_ignores_unknown_module() {
cfg.modules.insert(2142, extra_mod);

// Test that building the client worked
let _client = fed.new_client_with(cfg, MemDatabase::new().into()).await;
let _client = fed
.new_client_with(cfg, MemDatabase::new().into(), None)
.await;
}

#[tokio::test(flavor = "multi_thread")]
Expand Down

0 comments on commit 4cdf7df

Please sign in to comment.