@@ -61,15 +61,15 @@ func TestUpsertE2EWithDB(t *testing.T) {
6161 TxType : fftypes .TransactionTypeNone ,
6262 },
6363 Hash : fftypes .NewRandB32 (),
64- State : fftypes .MessageStateReady ,
64+ State : fftypes .MessageStateStaged ,
6565 Confirmed : nil ,
6666 Data : []* fftypes.DataRef {
6767 {ID : dataID1 , Hash : rand1 },
6868 {ID : dataID2 , Hash : rand2 },
6969 },
7070 }
7171
72- s .callbacks .On ("OrderedUUIDCollectionNSEvent" , database .CollectionMessages , fftypes .ChangeEventTypeCreated , "ns12345" , msgID , mock .Anything ).Return ()
72+ s .callbacks .On ("OrderedUUIDCollectionNSEvent" , database .CollectionMessages , fftypes .ChangeEventTypeCreated , "ns12345" , msgID , mock .Anything ).Return (). Twice ()
7373 s .callbacks .On ("OrderedUUIDCollectionNSEvent" , database .CollectionMessages , fftypes .ChangeEventTypeUpdated , "ns12345" , msgID , mock .Anything ).Return ()
7474
7575 err := s .UpsertMessage (ctx , msg , database .UpsertOptimizationNew )
@@ -205,6 +205,15 @@ func TestUpsertE2EWithDB(t *testing.T) {
205205 assert .Equal (t , 1 , len (msgs ))
206206 assert .Equal (t , * bid2 , * msgs [0 ].BatchID )
207207
208+ // Bump and Update - this is for a ready transition
209+ msgUpdated .State = fftypes .MessageStateReady
210+ err = s .ReplaceMessage (context .Background (), msgUpdated )
211+ assert .NoError (t , err )
212+ msgRead , err = s .GetMessageByID (ctx , msgUpdated .Header .ID )
213+ msgJson , _ = json .Marshal (& msgUpdated )
214+ msgReadJson , _ = json .Marshal (msgRead )
215+ assert .Equal (t , string (msgJson ), string (msgReadJson ))
216+
208217 s .callbacks .AssertExpectations (t )
209218}
210219
@@ -276,6 +285,38 @@ func TestUpsertMessageFailCommit(t *testing.T) {
276285 assert .NoError (t , mock .ExpectationsWereMet ())
277286}
278287
288+ func TestReplaceMessageFailBegin (t * testing.T ) {
289+ s , mock := newMockProvider ().init ()
290+ mock .ExpectBegin ().WillReturnError (fmt .Errorf ("pop" ))
291+ msgID := fftypes .NewUUID ()
292+ err := s .ReplaceMessage (context .Background (), & fftypes.Message {Header : fftypes.MessageHeader {ID : msgID }})
293+ assert .Regexp (t , "FF10114" , err )
294+ assert .NoError (t , mock .ExpectationsWereMet ())
295+ }
296+
297+ func TestReplaceMessageFailDelete (t * testing.T ) {
298+ s , mock := newMockProvider ().init ()
299+ mock .ExpectBegin ()
300+ mock .ExpectExec ("DELETE .*" ).WillReturnError (fmt .Errorf ("pop" ))
301+ mock .ExpectRollback ()
302+ msgID := fftypes .NewUUID ()
303+ err := s .ReplaceMessage (context .Background (), & fftypes.Message {Header : fftypes.MessageHeader {ID : msgID }})
304+ assert .Regexp (t , "FF10118" , err )
305+ assert .NoError (t , mock .ExpectationsWereMet ())
306+ }
307+
308+ func TestReplaceMessageFailInsert (t * testing.T ) {
309+ s , mock := newMockProvider ().init ()
310+ mock .ExpectBegin ()
311+ mock .ExpectExec ("DELETE .*" ).WillReturnResult (sqlmock .NewResult (1 , 1 ))
312+ mock .ExpectExec ("INSERT .*" ).WillReturnError (fmt .Errorf ("pop" ))
313+ mock .ExpectRollback ()
314+ msgID := fftypes .NewUUID ()
315+ err := s .ReplaceMessage (context .Background (), & fftypes.Message {Header : fftypes.MessageHeader {ID : msgID }})
316+ assert .Regexp (t , "FF10116" , err )
317+ assert .NoError (t , mock .ExpectationsWereMet ())
318+ }
319+
279320func TestUpdateMessageDataRefsNilID (t * testing.T ) {
280321 s , mock := newMockProvider ().init ()
281322 msgID := fftypes .NewUUID ()
0 commit comments