Skip to content

Commit

Permalink
feat(admin): add list cell ids call (#107)
Browse files Browse the repository at this point in the history
* Add agent info

* Fixed build

* build: add fixt dep

* fix formatting

* fix test & bump deps

* Add list-cell-ids

* fix test

* revert cargo toml

---------

Co-authored-by: Jost Schulte <[email protected]>
  • Loading branch information
guillemcordoba and jost-s authored Aug 30, 2024
1 parent ef96641 commit 080bf82
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/admin_websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ impl AdminWebsocket {
}
}

pub async fn list_cell_ids(&self) -> ConductorApiResult<Vec<CellId>> {
let response = self.send(AdminRequest::ListCellIds).await?;
match response {
AdminResponse::CellIdsListed(cell_ids) => Ok(cell_ids),
_ => unreachable!("Unexpected response {:?}", response),
}
}

pub async fn get_dna_definition(&self, hash: DnaHash) -> ConductorApiResult<DnaDef> {
let msg = AdminRequest::GetDnaDefinition(Box::new(hash));
let response = self.send(msg).await?;
Expand Down
35 changes: 35 additions & 0 deletions tests/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,38 @@ async fn agent_info() {
assert_eq!(agent_infos.len(), 3);
assert!(agent_infos.contains(&other_agent));
}

#[tokio::test(flavor = "multi_thread")]
async fn list_cell_ids() {
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();
let app_info = admin_ws
.install_app(InstallAppPayload {
agent_key: Some(agent_key),
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).await.unwrap();
let cell_id =
if let CellInfo::Provisioned(cell) = &app_info.cell_info.get(ROLE_NAME).unwrap()[0] {
cell.cell_id.clone()
} else {
panic!("expected provisioned cell");
};

let cell_ids = admin_ws.list_cell_ids().await.unwrap();
// Check if list includes cell id. Not checking for equality to a vector of just the one cell id,
// because the DPKI cell is included too.
assert!(cell_ids.contains(&cell_id));
}

0 comments on commit 080bf82

Please sign in to comment.