From 32b11f0e7f52dea39e443ad348ca22885d94c1f8 Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Mon, 6 Jun 2022 10:01:51 -0700 Subject: [PATCH] #4418: repaired a few other tests that weren't mocking out TransactionByHash/PreFilteredTransactionByHash --- services/horizon/internal/txsub/system_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/services/horizon/internal/txsub/system_test.go b/services/horizon/internal/txsub/system_test.go index 2efc45034c..0bc5856e2d 100644 --- a/services/horizon/internal/txsub/system_test.go +++ b/services/horizon/internal/txsub/system_test.go @@ -161,6 +161,8 @@ func (suite *SystemTestSuite) TestTimeoutDuringSequnceLoop() { suite.db.On("Rollback").Return(nil).Once() suite.db.On("PreFilteredTransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). Return(sql.ErrNoRows).Once() + suite.db.On("TransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). + Return(sql.ErrNoRows).Once() suite.db.On("NoRows", sql.ErrNoRows).Return(true).Once() suite.db.On("GetSequenceNumbers", suite.ctx, []string{suite.unmuxedSource.Address()}). Return(map[string]uint64{suite.unmuxedSource.Address(): 0}, nil) @@ -188,6 +190,8 @@ func (suite *SystemTestSuite) TestClientDisconnectedDuringSequnceLoop() { suite.db.On("Rollback").Return(nil).Once() suite.db.On("PreFilteredTransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). Return(sql.ErrNoRows).Once() + suite.db.On("TransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). + Return(sql.ErrNoRows).Once() suite.db.On("NoRows", sql.ErrNoRows).Return(true).Once() suite.db.On("GetSequenceNumbers", suite.ctx, []string{suite.unmuxedSource.Address()}). Return(map[string]uint64{suite.unmuxedSource.Address(): 0}, nil). @@ -229,6 +233,8 @@ func (suite *SystemTestSuite) TestSubmit_NotFoundError() { suite.db.On("Rollback").Return(nil).Once() suite.db.On("PreFilteredTransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). Return(sql.ErrNoRows).Once() + suite.db.On("TransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). + Return(sql.ErrNoRows).Once() suite.db.On("NoRows", sql.ErrNoRows).Return(true).Once() suite.db.On("GetSequenceNumbers", suite.ctx, []string{suite.unmuxedSource.Address()}). Return(map[string]uint64{suite.unmuxedSource.Address(): 0}, nil). @@ -257,8 +263,6 @@ func (suite *SystemTestSuite) TestSubmit_BadSeq() { ReadOnly: true, }).Return(nil).Once() suite.db.On("Rollback").Return(nil).Once() - suite.db.On("PreFilteredTransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). - Return(sql.ErrNoRows).Once() suite.db.On("NoRows", sql.ErrNoRows).Return(true).Once() suite.db.On("GetSequenceNumbers", suite.ctx, []string{suite.unmuxedSource.Address()}). Return(map[string]uint64{suite.unmuxedSource.Address(): 0}, nil). @@ -267,6 +271,10 @@ func (suite *SystemTestSuite) TestSubmit_BadSeq() { Return(map[string]uint64{suite.unmuxedSource.Address(): 1}, nil). Once() suite.db.On("PreFilteredTransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). + Return(sql.ErrNoRows).Twice() + suite.db.On("TransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). + Return(sql.ErrNoRows).Once() + suite.db.On("TransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). Run(func(args mock.Arguments) { ptr := args.Get(1).(*history.Transaction) *ptr = suite.successTx.Transaction @@ -295,6 +303,8 @@ func (suite *SystemTestSuite) TestSubmit_BadSeqNotFound() { suite.db.On("Rollback").Return(nil).Once() suite.db.On("PreFilteredTransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). Return(sql.ErrNoRows).Twice() + suite.db.On("TransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). + Return(sql.ErrNoRows).Twice() suite.db.On("NoRows", sql.ErrNoRows).Return(true).Twice() suite.db.On("GetSequenceNumbers", suite.ctx, []string{suite.unmuxedSource.Address()}). Return(map[string]uint64{suite.unmuxedSource.Address(): 0}, nil). @@ -327,6 +337,8 @@ func (suite *SystemTestSuite) TestSubmit_OpenTransactionList() { suite.db.On("Rollback").Return(nil).Once() suite.db.On("PreFilteredTransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). Return(sql.ErrNoRows).Once() + suite.db.On("TransactionByHash", suite.ctx, mock.Anything, suite.successTx.Transaction.TransactionHash). + Return(sql.ErrNoRows).Once() suite.db.On("NoRows", sql.ErrNoRows).Return(true).Once() suite.db.On("GetSequenceNumbers", suite.ctx, []string{suite.unmuxedSource.Address()}). Return(map[string]uint64{suite.unmuxedSource.Address(): 0}, nil). @@ -442,6 +454,8 @@ func (suite *SystemTestSuite) TestTickFinishFeeBumpTransaction() { suite.db.On("Rollback").Return(nil).Once() suite.db.On("PreFilteredTransactionByHash", suite.ctx, mock.Anything, innerHash). Return(sql.ErrNoRows).Once() + suite.db.On("TransactionByHash", suite.ctx, mock.Anything, innerHash). + Return(sql.ErrNoRows).Once() suite.db.On("NoRows", sql.ErrNoRows).Return(true).Once() suite.db.On("GetSequenceNumbers", suite.ctx, []string{"GABQGAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2MX"}). Return(map[string]uint64{"GABQGAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2MX": 96}, nil).