Skip to content

Commit 73c0779

Browse files
committed
Test cases for display_secret
1 parent 8966783 commit 73c0779

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/key.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,11 +689,10 @@ mod test {
689689
let pk = PublicKey::from_slice(&[0x02, 0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d, 0x06, 0x83, 0x7f, 0x30, 0xaa, 0x0c, 0xd0, 0x54, 0x4a, 0xc8, 0x87, 0xfe, 0x91, 0xdd, 0xd1, 0x66]).expect("pk");
690690
let mut buf = [0u8; constants::SECRET_KEY_SIZE * 2];
691691

692-
#[allow(deprecated)] {
693692
assert_eq!(
694693
to_hex(&sk[..], &mut buf).unwrap(),
695694
"01010101010101010001020304050607ffff0000ffff00006363636363636363"
696-
) };
695+
);
697696
assert_eq!(
698697
SecretKey::from_str("01010101010101010001020304050607ffff0000ffff00006363636363636363").unwrap(),
699698
sk

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,8 @@ fn from_hex(hex: &str, target: &mut [u8]) -> Result<usize, ()> {
853853
}
854854

855855
/// Utility function used to encode hex into a target u8 buffer. Returns
856-
/// a reference to the target buffer as an str.
857-
// it returns an error if the target buffer isn't big enough
856+
/// a reference to the target buffer as an str. Returns an error if the target
857+
/// buffer isn't big enough
858858
#[inline]
859859
fn to_hex<'a>(src: &[u8], target: &'a mut [u8]) -> Result<&'a str, ()> {
860860
let hex_len = src.len() * 2;

src/secret.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ macro_rules! impl_display_secret {
5858
/// ```
5959
/// use secp256k1::key::ONE_KEY;
6060
/// let key = ONE_KEY;
61-
/// println!("{}", key.display_secret());
62-
/// println!("{:?}", key.display_secret());
61+
/// assert_eq!(
62+
/// "0000000000000000000000000000000000000000000000000000000000000001",
63+
/// format!("{}", key.display_secret())
64+
/// );
65+
/// assert_eq!(
66+
/// "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]",
67+
/// format!("{:?}", key.display_secret())
68+
/// );
6369
/// ```
6470
///
6571
/// [`Display`]: fmt::Display
@@ -119,3 +125,24 @@ impl KeyPair {
119125
}
120126
}
121127
*/
128+
129+
#[cfg(test)]
130+
mod test {
131+
use key::ONE_KEY;
132+
133+
#[test]
134+
pub fn secret_key_display() {
135+
assert_eq!(
136+
ONE_KEY.display_secret().to_string(),
137+
"0000000000000000000000000000000000000000000000000000000000000001"
138+
);
139+
}
140+
141+
#[test]
142+
pub fn secret_key_debug() {
143+
assert_eq!(
144+
&format!("{:?}", ONE_KEY.display_secret()),
145+
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]"
146+
);
147+
}
148+
}

0 commit comments

Comments
 (0)