@@ -4,7 +4,7 @@ use super::{ReceiveSession, SessionContext};
44use crate :: error:: { InternalReplayError , ReplayError } ;
55use crate :: output_substitution:: OutputSubstitution ;
66use crate :: persist:: SessionPersister ;
7- use crate :: receive:: v2:: { extract_err_req, InternalSessionError , SessionError } ;
7+ use crate :: receive:: v2:: { extract_err_req, SessionError } ;
88use crate :: receive:: { common, InputPair , JsonReply , OriginalPayload , PsbtContext } ;
99use crate :: { ImplementationError , IntoUrl , PjUri , Request } ;
1010
@@ -44,27 +44,15 @@ where
4444 let history = SessionHistory :: new ( session_events. clone ( ) ) ;
4545 let ctx = history. session_context ( ) ;
4646 if ctx. expiration . elapsed ( ) {
47- // Session has expired: close the session and persist a fatal error
48- let err = SessionError ( InternalSessionError :: Expired ( ctx. expiration ) ) ;
49- persister
50- . save_event ( SessionEvent :: SessionInvalid ( err. to_string ( ) , None ) . into ( ) )
51- . map_err ( |e| InternalReplayError :: PersistenceFailure ( ImplementationError :: new ( e) ) ) ?;
52- persister
53- . close ( )
54- . map_err ( |e| InternalReplayError :: PersistenceFailure ( ImplementationError :: new ( e) ) ) ?;
55-
56- session_events. push ( SessionEvent :: SessionInvalid ( err. to_string ( ) , None ) ) ;
57- let history = SessionHistory :: new ( session_events) ;
58-
59- return Ok ( ( ReceiveSession :: TerminalFailure , history) ) ;
47+ return Err ( InternalReplayError :: Expired ( ctx. expiration ) . into ( ) ) ;
6048 }
6149
6250 Ok ( ( receiver, history) )
6351}
6452
6553/// A collection of events that have occurred during a receiver's session.
6654/// It is obtained by calling [replay_event_log].
67- #[ derive( Clone ) ]
55+ #[ derive( Debug , Clone ) ]
6856pub struct SessionHistory {
6957 events : Vec < SessionEvent > ,
7058}
@@ -372,21 +360,16 @@ mod tests {
372360
373361 #[ test]
374362 fn test_replaying_session_creation_with_expired_session ( ) -> Result < ( ) , BoxError > {
375- let session_context = SessionContext {
376- expiration : ( SystemTime :: now ( ) - Duration :: from_secs ( 1 ) ) . try_into ( ) . unwrap ( ) ,
377- ..SHARED_CONTEXT . clone ( )
378- } ;
379- let test = SessionHistoryTest {
380- events : vec ! [ SessionEvent :: Created ( session_context. clone( ) ) ] ,
381- expected_session_history : SessionHistoryExpectedOutcome {
382- psbt_with_fee_contributions : None ,
383- fallback_tx : None ,
384- expected_status : SessionStatus :: Expired ,
385- } ,
386- expected_receiver_state : ReceiveSession :: TerminalFailure ,
387- } ;
388- // TODO: should check for the expired error message off the session history
389- run_session_history_test ( test)
363+ let expiration = ( SystemTime :: now ( ) - Duration :: from_secs ( 1 ) ) . try_into ( ) . unwrap ( ) ;
364+ let session_context = SessionContext { expiration, ..SHARED_CONTEXT . clone ( ) } ;
365+ let persister = InMemoryTestPersister :: < SessionEvent > :: default ( ) ;
366+ persister. save_event ( SessionEvent :: Created ( session_context) ) ?;
367+
368+ let err = replay_event_log ( & persister) . expect_err ( "session should be expired" ) ;
369+ let expected_err: ReplayError < ReceiveSession , SessionEvent > =
370+ InternalReplayError :: Expired ( expiration) . into ( ) ;
371+ assert_eq ! ( err. to_string( ) , expected_err. to_string( ) ) ;
372+ Ok ( ( ) )
390373 }
391374
392375 #[ test]
0 commit comments