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

Added agent_info call #105

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ holochain_serialized_bytes = "0.0.55"
holochain_types = "0.4.0-dev.20"
holochain_nonce = "0.4.0-dev.6"
holochain_zome_types = { workspace = true }
kitsune_p2p_types = "0.4.0-dev"

lair_keystore_api = { version = "0.4.5", optional = true }

Expand Down
25 changes: 25 additions & 0 deletions src/admin_websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use holochain_zome_types::{
capability::GrantedFunctions,
prelude::{DnaDef, GrantZomeCallCapabilityPayload, Record},
};
use kitsune_p2p_types::agent_info::AgentInfoSigned;
use serde::{Deserialize, Serialize};
use std::{net::ToSocketAddrs, sync::Arc};
use tokio::task::JoinHandle;
Expand Down Expand Up @@ -319,6 +320,30 @@ impl AdminWebsocket {
}
}

pub async fn agent_info(
&self,
cell_id: Option<CellId>,
) -> ConductorApiResult<Vec<AgentInfoSigned>> {
let msg = AdminRequest::AgentInfo { cell_id };
let response = self.send(msg).await?;
match response {
AdminResponse::AgentInfo(agent_info) => Ok(agent_info),
_ => unreachable!("Unexpected response {:?}", response),
}
}

pub async fn add_agent_info(
&self,
agent_infos: Vec<AgentInfoSigned>,
) -> ConductorApiResult<()> {
let msg = AdminRequest::AddAgentInfo { agent_infos };
let response = self.send(msg).await?;
match response {
AdminResponse::AgentInfoAdded => Ok(()),
_ => unreachable!("Unexpected response {:?}", response),
}
}

pub async fn authorize_signing_credentials(
&self,
request: AuthorizeSigningCredentialsPayload,
Expand Down
38 changes: 38 additions & 0 deletions tests/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use holochain_client::{
use holochain_conductor_api::{CellInfo, StorageBlob};
use holochain_types::websocket::AllowedOrigins;
use holochain_zome_types::prelude::ExternIO;
use kitsune_p2p_types::fixt::AgentInfoSignedFixturator;
use std::collections::BTreeSet;
use std::net::Ipv4Addr;
use std::{collections::HashMap, path::PathBuf};
Expand Down Expand Up @@ -257,3 +258,40 @@ async fn revoke_agent_key() {
};
assert!(matches!(&response[0], (cell, error) if *cell == cell_id && error.contains("invalid")));
}

#[tokio::test(flavor = "multi_thread")]
async fn agent_info() {
let conductor = SweetConductor::from_standard_config().await;
let admin_port = conductor.get_arbitrary_admin_websocket_port().unwrap();
let admin_ws = AdminWebsocket::connect(format!("127.0.0.1:{}", admin_port))
.await
.unwrap();
let app_id: InstalledAppId = "test-app".into();
let agent_key = admin_ws.generate_agent_pub_key().await.unwrap();
admin_ws
.install_app(InstallAppPayload {
agent_key: Some(agent_key.clone()),
installed_app_id: Some(app_id.clone()),
existing_cells: HashMap::new(),
membrane_proofs: Some(HashMap::new()),
network_seed: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
})
.await
.unwrap();
admin_ws.enable_app(app_id.clone()).await.unwrap();

let agent_infos = admin_ws.agent_info(None).await.unwrap();
assert_eq!(agent_infos.len(), 1);

let other_agent = ::fixt::fixt!(AgentInfoSigned);
admin_ws
.add_agent_info(vec![other_agent.clone()])
.await
.unwrap();

let agent_infos = admin_ws.agent_info(None).await.unwrap();
assert_eq!(agent_infos.len(), 2);
assert!(agent_infos.contains(&other_agent));
}
Loading