-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use iota_sdk::{client::Error as ClientError, wallet::Error as WalletError}; | ||
use crypto::keys::bip44::Bip44; | ||
use iota_sdk::{ | ||
client::{constants::SHIMMER_COIN_TYPE, Error as ClientError}, | ||
wallet::Error as WalletError, | ||
}; | ||
use iota_sdk_bindings_core::Error; | ||
use pretty_assertions::assert_eq; | ||
|
||
#[test] | ||
fn custom_error_serialization() { | ||
// testing a unit-type-like error | ||
let error = Error::Client(ClientError::HealthyNodePoolEmpty); | ||
assert_eq!( | ||
serde_json::to_string(&error).unwrap(), | ||
"{\"type\":\"client\",\"error\":\"no healthy node available\"}" | ||
); | ||
let error = Error::Wallet(WalletError::MissingBipPath); | ||
// testing a tuple-like error | ||
let error = Error::Wallet(WalletError::InvalidMnemonic("nilly willy".to_string())); | ||
assert_eq!( | ||
serde_json::to_string(&error).unwrap(), | ||
"{\"type\":\"wallet\",\"error\":\"missing BIP path\"}" | ||
"{\"type\":\"wallet\",\"error\":\"invalid mnemonic: nilly willy\"}" | ||
); | ||
// testing a struct-like error | ||
let error = Error::Wallet(WalletError::BipPathMismatch { | ||
old_bip_path: None, | ||
new_bip_path: Some(Bip44::new(SHIMMER_COIN_TYPE)), | ||
}); | ||
assert_eq!( | ||
serde_json::to_string(&error).unwrap(), | ||
"{\"type\":\"wallet\",\"error\":\"BIP44 mismatch: Some(Bip44 { coin_type: 4219, account: 0, change: 0, address_index: 0 }), existing bip path is: None\"}" | ||
); | ||
} |