1+ // SPDX-License-Identifier: CC0-1.0
2+
3+ //! Macros for implementing test methods on a JSON-RPC client.
4+ //!
5+ //! Specifically this is methods found under the `== Wallet ==` section of the
6+ //! API docs of `bitcoind v0.17.1`.
7+
18/// Requires `Client` to be in scope and to implement `createwallet`.
29#[ macro_export]
310macro_rules! impl_test_v17__createwallet {
@@ -31,7 +38,8 @@ macro_rules! impl_test_v17__unloadwallet {
3138 let bitcoind = $crate:: bitcoind_no_wallet( ) ;
3239 let wallet = format!( "wallet-{}" , rand:: random:: <u32 >( ) ) . to_string( ) ;
3340 bitcoind. client. create_wallet( & wallet) . expect( "failed to create wallet" ) ;
34- let _ = bitcoind. client. unload_wallet( & wallet) . expect( "unloadwallet" ) ;
41+ let json = bitcoind. client. unload_wallet( & wallet) . expect( "unloadwallet" ) ;
42+ assert!( json. into_model( ) . is_ok( ) )
3543 }
3644 } ;
3745}
@@ -45,13 +53,26 @@ macro_rules! impl_test_v17__getnewaddress {
4553 use bitcoind:: AddressType ;
4654
4755 let bitcoind = $crate:: bitcoind_with_default_wallet( ) ;
48- let _ = bitcoind. client. get_new_address( ) . expect( "getnewaddress" ) ;
4956
50- let addr = bitcoind
57+ let json = bitcoind. client. get_new_address( ) . expect( "getnewaddress" ) ;
58+ assert!( json. into_model( ) . is_ok( ) ) ;
59+
60+ // Test the helper as well just for good measure.
61+ let _ = bitcoind. client. new_address( ) . unwrap( ) ;
62+
63+ // Exhaustively test address types with helper.
64+ let _ = bitcoind
65+ . client
66+ . new_address_with_type( AddressType :: Legacy )
67+ . unwrap( ) ;
68+ let _ = bitcoind
69+ . client
70+ . new_address_with_type( AddressType :: P2shSegwit )
71+ . unwrap( ) ;
72+ let _ = bitcoind
5173 . client
5274 . new_address_with_type( AddressType :: Bech32 )
5375 . unwrap( ) ;
54-
5576 }
5677 } ;
5778}
@@ -66,7 +87,7 @@ macro_rules! impl_test_v17__getbalance {
6687
6788 let bitcoind = $crate:: bitcoind_with_default_wallet( ) ;
6889 let json = bitcoind. client. get_balance( ) . expect( "getbalance" ) ;
69- let _ : model :: GetBalance = json. try_into ( ) . unwrap ( ) ;
90+ assert! ( json. into_model ( ) . is_ok ( ) )
7091 }
7192 } ;
7293}
@@ -85,10 +106,11 @@ macro_rules! impl_test_v17__sendtoaddress {
85106 let address = bitcoind. client. new_address( ) . expect( "failed to create new address" ) ;
86107 let _ = bitcoind. client. generate_to_address( 101 , & address) . expect( "generatetoaddress" ) ;
87108
88- let _ = bitcoind
109+ let json = bitcoind
89110 . client
90111 . send_to_address( & address, Amount :: from_sat( 10_000 ) )
91- . expect( "sendtoaddress" ) ;
112+ . expect( "sendtddress" ) ;
113+ json. into_model( ) . unwrap( ) ;
92114 }
93115 } ;
94116}
@@ -112,10 +134,12 @@ macro_rules! impl_test_v17__gettransaction {
112134 let txid = bitcoind
113135 . client
114136 . send_to_address( & address, Amount :: from_sat( 10_000 ) )
115- . expect( "sendtoaddress" ) ;
137+ . expect( "sendtoaddress" )
138+ . txid( )
139+ . unwrap( ) ;
116140
117141 let json = bitcoind. client. get_transaction( txid) . expect( "gettransaction" ) ;
118- let _ : model :: GetTransaction = json. try_into ( ) . unwrap( ) ;
142+ json. into_model ( ) . unwrap( ) ;
119143 }
120144 } ;
121145}
0 commit comments