Skip to content

Commit

Permalink
test: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexD10S committed Dec 2, 2024
1 parent fd0d6a6 commit 6d7ea24
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
18 changes: 9 additions & 9 deletions crates/pop-cli/src/commands/call/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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()),
]
Expand Down
10 changes: 7 additions & 3 deletions crates/pop-parachains/src/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ pub fn encode_call_data(
api: &OnlineClient<SubstrateConfig>,
tx: &DynamicPayload,
) -> Result<String, Error> {
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)))
}

Expand All @@ -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(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-parachains/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down

0 comments on commit 6d7ea24

Please sign in to comment.