@@ -101,22 +101,39 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
101101 let ( external_desc, internal_desc) = get_test_tr_single_sig_xprv_and_change_desc ( ) ;
102102
103103 // create new wallet
104- let wallet_spk_index = {
104+ {
105105 let mut db = create_db ( & file_path) ?;
106- let mut wallet = Wallet :: create ( external_desc, internal_desc)
106+ let wallet = Wallet :: create ( external_desc, internal_desc)
107107 . network ( Network :: Testnet )
108108 . use_spk_cache ( true )
109109 . create_wallet ( & mut db) ?;
110110
111- wallet. reveal_next_address ( KeychainKind :: External ) ;
111+ assert ! (
112+ wallet. staged( ) . is_none( ) ,
113+ "persisted wallet creation should write the initial changeset"
114+ ) ;
115+ }
116+
117+ // reload immediately to ensure the initial cached SPKs were persisted at creation time
118+ let wallet_spk_index = {
119+ let mut db = open_db ( & file_path) ?;
120+ let mut wallet = Wallet :: load ( )
121+ . check_network ( Network :: Testnet )
122+ . use_spk_cache ( true )
123+ . load_wallet ( & mut db) ?
124+ . expect ( "wallet must exist" ) ;
125+
126+ assert ! ( wallet. staged( ) . is_none( ) ) ;
127+
128+ let revealed_external_addr = wallet. reveal_next_address ( KeychainKind :: External ) ;
112129
113130 check_cache_cs (
114131 & staged_cache ( & wallet) ,
115- [
116- ( KeychainKind :: External , 0 .. DEFAULT_LOOKAHEAD + 1 ) ,
117- ( KeychainKind :: Internal , 0 .. DEFAULT_LOOKAHEAD ) ,
118- ] ,
119- "cache cs must return initial set + the external index that was just derived " ,
132+ [ (
133+ KeychainKind :: External ,
134+ [ revealed_external_addr . index + DEFAULT_LOOKAHEAD ] ,
135+ ) ] ,
136+ "initial cached SPKs should already be persisted at wallet creation " ,
120137 ) ;
121138
122139 // persist new wallet changes
0 commit comments