Skip to content

Commit

Permalink
Merge pull request Kalapaja#7 from Vovke/new-api-mend-vovke
Browse files Browse the repository at this point in the history
test progress, currencies ugly build
  • Loading branch information
Slesarew authored May 27, 2024
2 parents f42370e + a3304e8 commit a6f36f8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion chopsticks/pd-ah.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
endpoint: wss://polkadot-asset-hub-rpc.polkadot.io
endpoint: wss://statemint.api.onfinality.io/public-ws

import-storage:
System:
Expand Down
2 changes: 1 addition & 1 deletion configs/chopsticks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ debug = true
in-memory-db = true

[[chain]]
name = "chop-assethub-polkadot"
name = "statemint"
endpoints = [
"ws://localhost:8000"
]
Expand Down
6 changes: 3 additions & 3 deletions src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub mod api_v2 {
pub rpc_url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub asset_id: Option<AssetId>,
#[serde(skip_serializing)]
// #[serde(skip_serializing)]
pub ss58: u16,
}

Expand All @@ -228,7 +228,7 @@ pub mod api_v2 {
pub rpc_url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub asset_id: Option<AssetId>,
#[serde(skip_serializing)]
// #[serde(skip_serializing)]
pub ss58: u16,
}

Expand All @@ -246,7 +246,7 @@ pub mod api_v2 {
}
}

#[derive(Clone, Copy, Debug, Serialize, Decode, Encode, Deserialize)]
#[derive(Clone, Copy, Debug, Serialize, Decode, Encode, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum TokenKind {
Asset,
Expand Down
53 changes: 29 additions & 24 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ensure you have chopsticks installed: npm install -g @acala-network/chopsticks
// if running locally, ensure that you have no dangling processes (kalatori daemon, chopsticks)
// pkill -f kalatori; pkill -f chopsticks

Expand All @@ -16,13 +17,9 @@ lazy_static! {

async fn start_chopsticks() -> std::io::Result<Child> {
let mut command = Command::new("npx");
command.args(&[
"@acala-network/chopsticks@latest",
"-c",
"chopsticks/pd-ah.yml",
]);
command.args(&["@acala-network/chopsticks@latest", "-c", "chopsticks/pd-ah.yml"]);
let chopsticks = command.spawn()?;
sleep(Duration::from_secs(3)).await; // Give Chopsticks some time to start
sleep(Duration::from_secs(10)).await; // Give Chopsticks some time to start
Ok(chopsticks)
}

Expand Down Expand Up @@ -54,7 +51,7 @@ fn load_chain_config() {

async fn start_daemon() -> std::io::Result<Child> {
let daemon = Command::new("target/debug/kalatori").spawn()?;
sleep(Duration::from_secs(3)).await; // Give the daemon some time to start
sleep(Duration::from_secs(10)).await; // Give the daemon some time to start
Ok(daemon)
}

Expand Down Expand Up @@ -117,26 +114,34 @@ async fn test_daemon_status_call() {
assert!(resp.status().is_success());

let body = resp
.json::<ServerStatus>()
.json::<serde_json::Value>()
.await
.expect("Failed to parse response");

// Check that all required fields are present
assert_eq!(body.server_info.version, KALATORI_CARGO_PACKAGE_VERSION);
assert!(!body.server_info.instance_id.is_empty());
assert_eq!(body.server_info.debug, true);
assert_eq!(body.server_info.kalatori_remark, KALATORI_REMARK);

// Check that supported currencies are present
// assert!(!body.supported_currencies.is_empty());
// for (currency, properties) in body.supported_currencies {
// assert!(!currency.is_empty());
// assert!(!properties.chain_name.is_empty());
// assert!(!properties.kind.is_empty());
// assert!(properties.decimals > 0);
// assert!(!properties.rpc_url.is_empty());
// // asset_id is optional, so no need to assert on it
// }
let body_str = body.to_string();
let server_status: ServerStatus = serde_json::from_str(&body_str).expect("Failed to deserialize ServerStatus");

assert_eq!(server_status.server_info.version, KALATORI_CARGO_PACKAGE_VERSION);
assert!(!server_status.server_info.instance_id.is_empty());
assert_eq!(server_status.server_info.debug, true);
assert_eq!(server_status.server_info.kalatori_remark, KALATORI_REMARK);

assert!(!server_status.supported_currencies.is_empty());
for (currency, properties) in server_status.supported_currencies {
assert!(!currency.is_empty());
assert!(!properties.chain_name.is_empty());
assert!(matches!(properties.kind, TokenKind::Balances | TokenKind::Asset));
assert!(properties.decimals > 0);
assert!(!properties.rpc_url.is_empty());

if currency == "DOT" {
assert_eq!(properties.chain_name, "statemint");
assert_eq!(properties.kind, TokenKind::Balances);
assert_eq!(properties.decimals, 10);
assert_eq!(properties.rpc_url, "ws://localhost:8000");
// those are wrong atm
}
}

context.drop_async().await;
}
Expand Down

0 comments on commit a6f36f8

Please sign in to comment.