@@ -44,13 +44,14 @@ pub fn to_dehexified_json<T: serde::Serialize>(
4444// TODO: add tests that create blocks, and ensure the replacement in json works properly.
4545#[ cfg( test) ]
4646mod tests {
47+ use rstest:: rstest;
48+ use strum:: { EnumCount , EnumDiscriminants , EnumIter , IntoEnumIterator } ;
49+
4750 use crypto:: {
4851 key:: { KeyKind , PrivateKey } ,
4952 vrf:: { VRFKeyKind , VRFPrivateKey , VRFPublicKey } ,
5053 } ;
51- use rstest:: rstest;
52- use strum:: { EnumCount , EnumDiscriminants , EnumIter , IntoEnumIterator } ;
53- use test_utils:: random:: { make_seedable_rng, Rng , Seed } ;
54+ use test_utils:: random:: { gen_random_alnum_string, make_seedable_rng, Seed } ;
5455
5556 use crate :: {
5657 address:: { hexified:: HexifiedAddress , pubkeyhash:: PublicKeyHash , Address } ,
@@ -61,13 +62,6 @@ mod tests {
6162 primitives:: H256 ,
6263 } ;
6364
64- fn random_string ( length : usize , rng : & mut impl Rng ) -> String {
65- rng. sample_iter ( & randomness:: distributions:: Alphanumeric )
66- . take ( length)
67- . map ( char:: from)
68- . collect ( )
69- }
70-
7165 #[ derive( PartialEq , Eq , PartialOrd , Ord , EnumCount , EnumDiscriminants ) ]
7266 #[ strum_discriminants( name( HexifiableTag ) , derive( EnumIter ) ) ]
7367 enum Hexifiable {
@@ -90,51 +84,44 @@ mod tests {
9084 let chain_config = create_regtest ( ) ;
9185
9286 let strings = ( 0 ..100 )
93- . map ( |_| {
94- let size = rng. gen :: < usize > ( ) % 50 ;
95- random_string ( size, & mut rng)
96- } )
87+ . map ( |_| gen_random_alnum_string ( & mut rng, 0 , 50 ) )
9788 . collect :: < Vec < String > > ( ) ;
9889
9990 let keys = ( 0 ..strings. len ( ) )
100- . map ( |_| {
101- //
102-
103- match HexifiableTag :: iter ( ) . choose ( & mut rng) . unwrap ( ) {
104- HexifiableTag :: Destination => {
105- let dest = match DestinationTag :: iter ( ) . choose ( & mut rng) . unwrap ( ) {
106- DestinationTag :: AnyoneCanSpend => Destination :: AnyoneCanSpend ,
107- DestinationTag :: PublicKey => {
108- let ( _private_key, public_key) =
109- PrivateKey :: new_from_rng ( & mut rng, KeyKind :: Secp256k1Schnorr ) ;
110- Destination :: PublicKey ( public_key)
111- }
112- DestinationTag :: PublicKeyHash => {
113- let ( _private_key, public_key) =
114- PrivateKey :: new_from_rng ( & mut rng, KeyKind :: Secp256k1Schnorr ) ;
115- Destination :: PublicKeyHash ( PublicKeyHash :: from ( & public_key) )
116- }
117- DestinationTag :: ScriptHash => Destination :: ScriptHash (
118- crate :: primitives:: Id :: new ( H256 :: random_using ( & mut rng) ) ,
119- ) ,
120- DestinationTag :: ClassicMultisig => {
121- let ( _private_key, public_key) =
122- PrivateKey :: new_from_rng ( & mut rng, KeyKind :: Secp256k1Schnorr ) ;
123- Destination :: ClassicMultisig ( PublicKeyHash :: from ( & public_key) )
124- }
125- } ;
126- Hexifiable :: Destination ( dest)
127- }
128- HexifiableTag :: PoolId => Hexifiable :: PoolId ( PoolId :: random_using ( & mut rng) ) ,
129- HexifiableTag :: DelegationId => {
130- Hexifiable :: DelegationId ( DelegationId :: random_using ( & mut rng) )
131- }
132- HexifiableTag :: TokenId => Hexifiable :: TokenId ( TokenId :: random_using ( & mut rng) ) ,
133- HexifiableTag :: OrderId => Hexifiable :: OrderId ( OrderId :: random_using ( & mut rng) ) ,
134- HexifiableTag :: VRFPublicKey => Hexifiable :: VRFPublicKey (
135- VRFPrivateKey :: new_from_rng ( & mut rng, VRFKeyKind :: Schnorrkel ) . 1 ,
136- ) ,
91+ . map ( |_| match HexifiableTag :: iter ( ) . choose ( & mut rng) . unwrap ( ) {
92+ HexifiableTag :: Destination => {
93+ let dest = match DestinationTag :: iter ( ) . choose ( & mut rng) . unwrap ( ) {
94+ DestinationTag :: AnyoneCanSpend => Destination :: AnyoneCanSpend ,
95+ DestinationTag :: PublicKey => {
96+ let ( _private_key, public_key) =
97+ PrivateKey :: new_from_rng ( & mut rng, KeyKind :: Secp256k1Schnorr ) ;
98+ Destination :: PublicKey ( public_key)
99+ }
100+ DestinationTag :: PublicKeyHash => {
101+ let ( _private_key, public_key) =
102+ PrivateKey :: new_from_rng ( & mut rng, KeyKind :: Secp256k1Schnorr ) ;
103+ Destination :: PublicKeyHash ( PublicKeyHash :: from ( & public_key) )
104+ }
105+ DestinationTag :: ScriptHash => Destination :: ScriptHash (
106+ crate :: primitives:: Id :: new ( H256 :: random_using ( & mut rng) ) ,
107+ ) ,
108+ DestinationTag :: ClassicMultisig => {
109+ let ( _private_key, public_key) =
110+ PrivateKey :: new_from_rng ( & mut rng, KeyKind :: Secp256k1Schnorr ) ;
111+ Destination :: ClassicMultisig ( PublicKeyHash :: from ( & public_key) )
112+ }
113+ } ;
114+ Hexifiable :: Destination ( dest)
115+ }
116+ HexifiableTag :: PoolId => Hexifiable :: PoolId ( PoolId :: random_using ( & mut rng) ) ,
117+ HexifiableTag :: DelegationId => {
118+ Hexifiable :: DelegationId ( DelegationId :: random_using ( & mut rng) )
137119 }
120+ HexifiableTag :: TokenId => Hexifiable :: TokenId ( TokenId :: random_using ( & mut rng) ) ,
121+ HexifiableTag :: OrderId => Hexifiable :: OrderId ( OrderId :: random_using ( & mut rng) ) ,
122+ HexifiableTag :: VRFPublicKey => Hexifiable :: VRFPublicKey (
123+ VRFPrivateKey :: new_from_rng ( & mut rng, VRFKeyKind :: Schnorrkel ) . 1 ,
124+ ) ,
138125 } )
139126 . collect :: < Vec < _ > > ( ) ;
140127
0 commit comments