From 6d7ea24e2d21254c0679b90d5d4d91bca322211c Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Mon, 2 Dec 2024 17:46:23 +0100 Subject: [PATCH] test: fix unit tests --- crates/pop-cli/src/commands/call/parachain.rs | 18 +++++++++--------- crates/pop-parachains/src/call/mod.rs | 10 +++++++--- crates/pop-parachains/src/errors.rs | 4 ++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/pop-cli/src/commands/call/parachain.rs b/crates/pop-cli/src/commands/call/parachain.rs index 0117ad0d..68b08bb1 100644 --- a/crates/pop-cli/src/commands/call/parachain.rs +++ b/crates/pop-cli/src/commands/call/parachain.rs @@ -556,11 +556,11 @@ mod tests { true, Some( [ - ("Transfer Balance".to_string(), "Balances".to_string()), + ("Transfer balance".to_string(), "Balances".to_string()), ("Purchase on-demand coretime".to_string(), "OnDemand".to_string()), - ("Reserve para id".to_string(), "Registrar".to_string()), + ("Reserve a parachain ID".to_string(), "Registrar".to_string()), ( - "Register para id with genesis state and code".to_string(), + "Register a parachain ID with genesis state and code".to_string(), "Registrar".to_string(), ), ("All".to_string(), "Explore all pallets and extrinsics".to_string()), @@ -605,13 +605,13 @@ mod tests { let mut cli = MockCli::new(); // Error, wrong name of the pallet. assert!( - matches!(call_config.prepare_extrinsic(&api, &mut cli).await, Err(message) if message.to_string().contains("Metadata Error: Pallet with name WrongName not found")) + matches!(call_config.prepare_extrinsic(&api, &mut cli).await, Err(message) if message.to_string().contains("Failed to encode call data. Metadata Error: Pallet with name WrongName not found")) ); let pallets = parse_chain_metadata(&api).await?; call_config.pallet = find_pallet_by_name(&pallets, "System").await?; // Error, wrong name of the extrinsic. assert!( - matches!(call_config.prepare_extrinsic(&api, &mut cli).await, Err(message) if message.to_string().contains("Metadata Error: Call with name WrongName not found")) + matches!(call_config.prepare_extrinsic(&api, &mut cli).await, Err(message) if message.to_string().contains("Failed to encode call data. Metadata Error: Call with name WrongName not found")) ); // Success, extrinsic and pallet specified. cli = MockCli::new().expect_info("Encoded call data: 0x00000411"); @@ -698,10 +698,10 @@ mod tests { true, Some( [ - ("Transfer Balance".to_string(), "Balances".to_string()), - ("Create an Asset".to_string(), "Assets".to_string()), - ("Mint an Asset".to_string(), "Assets".to_string()), - ("Create an NFT Collection".to_string(), "Nfts".to_string()), + ("Transfer balance".to_string(), "Balances".to_string()), + ("Create an asset".to_string(), "Assets".to_string()), + ("Mint an asset".to_string(), "Assets".to_string()), + ("Create an NFT collection".to_string(), "Nfts".to_string()), ("Mint an NFT".to_string(), "Nfts".to_string()), ("All".to_string(), "Explore all pallets and extrinsics".to_string()), ] diff --git a/crates/pop-parachains/src/call/mod.rs b/crates/pop-parachains/src/call/mod.rs index d42bb5a0..73a35166 100644 --- a/crates/pop-parachains/src/call/mod.rs +++ b/crates/pop-parachains/src/call/mod.rs @@ -68,8 +68,9 @@ pub fn encode_call_data( api: &OnlineClient, tx: &DynamicPayload, ) -> Result { - let call_data = - tx.encode_call_data(&api.metadata()).map_err(|_| Error::CallDataEncodingError)?; + let call_data = tx + .encode_call_data(&api.metadata()) + .map_err(|e| Error::CallDataEncodingError(e.to_string()))?; Ok(format!("0x{}", hex::encode(call_data))) } @@ -82,7 +83,10 @@ mod tests { #[tokio::test] async fn set_up_api_works() -> Result<()> { - assert!(matches!(set_up_api("wss://wronguri.xyz").await, Err(Error::SubxtError(_)))); + assert!(matches!( + set_up_api("wss://wronguri.xyz").await, + Err(Error::ApiConnectionFailure(_)) + )); set_up_api("wss://rpc1.paseo.popnetwork.xyz").await?; Ok(()) } diff --git a/crates/pop-parachains/src/errors.rs b/crates/pop-parachains/src/errors.rs index 585e9f78..cadc8572 100644 --- a/crates/pop-parachains/src/errors.rs +++ b/crates/pop-parachains/src/errors.rs @@ -11,8 +11,8 @@ pub enum Error { AnyhowError(#[from] anyhow::Error), #[error("Failed to establish a connection to the API: {0}")] ApiConnectionFailure(String), - #[error("Failed to encode call data for the extrinsic.")] - CallDataEncodingError, + #[error("Failed to encode call data. {0}")] + CallDataEncodingError(String), #[error("{0}")] CommonError(#[from] pop_common::Error), #[error("Configuration error: {0}")]