@@ -47,7 +47,7 @@ const MIN_WORDS: usize = 12;
47
47
const MAX_WORDS : usize = 24 ;
48
48
49
49
/// A BIP39 error
50
- #[ derive( Debug ) ]
50
+ #[ derive( Debug , PartialEq ) ]
51
51
pub enum Error {
52
52
/// Mnemonic has a word count that is not a multiple of 6 and between 12 and 24
53
53
InvalidWordCount ( usize ) ,
@@ -87,6 +87,7 @@ pub enum WordCount {
87
87
}
88
88
89
89
/// A mnemonic is group of easy to remember words used in the generation of deterministic wallets
90
+ #[ derive( Debug , PartialEq ) ]
90
91
pub struct Mnemonic {
91
92
/// The language this mnemoic belongs to
92
93
language : Language ,
@@ -370,7 +371,7 @@ impl<Ctx: ScriptContext> GeneratableKey<Ctx> for Mnemonic {
370
371
371
372
#[ cfg( test) ]
372
373
mod test {
373
- use super :: { Language , Mnemonic } ;
374
+ use super :: { Error , Language , Mnemonic } ;
374
375
use crate :: keys:: { any_network, bip39:: WordCount , GeneratableKey , GeneratedKey } ;
375
376
use bitcoin:: { hashes:: hex:: FromHex , util:: bip32} ;
376
377
use std:: str:: FromStr ;
@@ -821,4 +822,25 @@ mod test {
821
822
Mnemonic :: generate ( ( Some ( WordCount :: Words24 ) , Language :: English ) ) . unwrap ( ) ;
822
823
assert_eq ! ( generated_mnemonic. valid_networks, any_network( ) ) ;
823
824
}
825
+
826
+ #[ test]
827
+ fn test_invalid_entropies ( ) {
828
+ //testing with entropy less than 128 bits
829
+ assert_eq ! (
830
+ Mnemonic :: from_entropy_in( Language :: English , & vec![ b'0' ; 15 ] ) ,
831
+ Err ( Error :: InvalidEntropyLength ( 120 ) )
832
+ ) ;
833
+
834
+ //testing with entropy greater than 256 bits
835
+ assert_eq ! (
836
+ Mnemonic :: from_entropy_in( Language :: English , & vec![ b'0' ; 33 ] ) ,
837
+ Err ( Error :: InvalidEntropyLength ( 264 ) )
838
+ ) ;
839
+
840
+ //testing entropy which is not a multiple of 32 bits
841
+ assert_eq ! (
842
+ Mnemonic :: from_entropy_in( Language :: English , & vec![ b'0' ; 31 ] ) ,
843
+ Err ( Error :: InvalidEntropyLength ( 248 ) )
844
+ ) ;
845
+ }
824
846
}
0 commit comments