github.com/ledgerwatch/erigon-lib@v1.0.0/txpool/mocks_test.go (about)

     1  // Code generated by moq; DO NOT EDIT.
     2  // github.com/matryer/moq
     3  
     4  package txpool
     5  
     6  import (
     7  	"context"
     8  	"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
     9  	"github.com/ledgerwatch/erigon-lib/kv"
    10  	"github.com/ledgerwatch/erigon-lib/txpool/txpoolcfg"
    11  	types2 "github.com/ledgerwatch/erigon-lib/types"
    12  	"sync"
    13  )
    14  
    15  // Ensure, that PoolMock does implement Pool.
    16  // If this is not the case, regenerate this file with moq.
    17  var _ Pool = &PoolMock{}
    18  
    19  // PoolMock is a mock implementation of Pool.
    20  //
    21  //	func TestSomethingThatUsesPool(t *testing.T) {
    22  //
    23  //		// make and configure a mocked Pool
    24  //		mockedPool := &PoolMock{
    25  //			AddLocalTxsFunc: func(ctx context.Context, newTxs types2.TxSlots, tx kv.Tx) ([]txpoolcfg.DiscardReason, error) {
    26  //				panic("mock out the AddLocalTxs method")
    27  //			},
    28  //			AddNewGoodPeerFunc: func(peerID types2.PeerID)  {
    29  //				panic("mock out the AddNewGoodPeer method")
    30  //			},
    31  //			AddRemoteTxsFunc: func(ctx context.Context, newTxs types2.TxSlots)  {
    32  //				panic("mock out the AddRemoteTxs method")
    33  //			},
    34  //			FilterKnownIdHashesFunc: func(tx kv.Tx, hashes types2.Hashes) (types2.Hashes, error) {
    35  //				panic("mock out the FilterKnownIdHashes method")
    36  //			},
    37  //			GetKnownBlobTxnFunc: func(tx kv.Tx, hash []byte) (*metaTx, error) {
    38  //				panic("mock out the GetKnownBlobTxn method")
    39  //			},
    40  //			GetRlpFunc: func(tx kv.Tx, hash []byte) ([]byte, error) {
    41  //				panic("mock out the GetRlp method")
    42  //			},
    43  //			IdHashKnownFunc: func(tx kv.Tx, hash []byte) (bool, error) {
    44  //				panic("mock out the IdHashKnown method")
    45  //			},
    46  //			OnNewBlockFunc: func(ctx context.Context, stateChanges *remote.StateChangeBatch, unwindTxs types2.TxSlots, minedTxs types2.TxSlots, tx kv.Tx) error {
    47  //				panic("mock out the OnNewBlock method")
    48  //			},
    49  //			StartedFunc: func() bool {
    50  //				panic("mock out the Started method")
    51  //			},
    52  //			ValidateSerializedTxnFunc: func(serializedTxn []byte) error {
    53  //				panic("mock out the ValidateSerializedTxn method")
    54  //			},
    55  //		}
    56  //
    57  //		// use mockedPool in code that requires Pool
    58  //		// and then make assertions.
    59  //
    60  //	}
    61  type PoolMock struct {
    62  	// AddLocalTxsFunc mocks the AddLocalTxs method.
    63  	AddLocalTxsFunc func(ctx context.Context, newTxs types2.TxSlots, tx kv.Tx) ([]txpoolcfg.DiscardReason, error)
    64  
    65  	// AddNewGoodPeerFunc mocks the AddNewGoodPeer method.
    66  	AddNewGoodPeerFunc func(peerID types2.PeerID)
    67  
    68  	// AddRemoteTxsFunc mocks the AddRemoteTxs method.
    69  	AddRemoteTxsFunc func(ctx context.Context, newTxs types2.TxSlots)
    70  
    71  	// FilterKnownIdHashesFunc mocks the FilterKnownIdHashes method.
    72  	FilterKnownIdHashesFunc func(tx kv.Tx, hashes types2.Hashes) (types2.Hashes, error)
    73  
    74  	// GetKnownBlobTxnFunc mocks the GetKnownBlobTxn method.
    75  	GetKnownBlobTxnFunc func(tx kv.Tx, hash []byte) (*metaTx, error)
    76  
    77  	// GetRlpFunc mocks the GetRlp method.
    78  	GetRlpFunc func(tx kv.Tx, hash []byte) ([]byte, error)
    79  
    80  	// IdHashKnownFunc mocks the IdHashKnown method.
    81  	IdHashKnownFunc func(tx kv.Tx, hash []byte) (bool, error)
    82  
    83  	// OnNewBlockFunc mocks the OnNewBlock method.
    84  	OnNewBlockFunc func(ctx context.Context, stateChanges *remote.StateChangeBatch, unwindTxs types2.TxSlots, minedTxs types2.TxSlots, tx kv.Tx) error
    85  
    86  	// StartedFunc mocks the Started method.
    87  	StartedFunc func() bool
    88  
    89  	// ValidateSerializedTxnFunc mocks the ValidateSerializedTxn method.
    90  	ValidateSerializedTxnFunc func(serializedTxn []byte) error
    91  
    92  	// calls tracks calls to the methods.
    93  	calls struct {
    94  		// AddLocalTxs holds details about calls to the AddLocalTxs method.
    95  		AddLocalTxs []struct {
    96  			// Ctx is the ctx argument value.
    97  			Ctx context.Context
    98  			// NewTxs is the newTxs argument value.
    99  			NewTxs types2.TxSlots
   100  			// Tx is the tx argument value.
   101  			Tx kv.Tx
   102  		}
   103  		// AddNewGoodPeer holds details about calls to the AddNewGoodPeer method.
   104  		AddNewGoodPeer []struct {
   105  			// PeerID is the peerID argument value.
   106  			PeerID types2.PeerID
   107  		}
   108  		// AddRemoteTxs holds details about calls to the AddRemoteTxs method.
   109  		AddRemoteTxs []struct {
   110  			// Ctx is the ctx argument value.
   111  			Ctx context.Context
   112  			// NewTxs is the newTxs argument value.
   113  			NewTxs types2.TxSlots
   114  		}
   115  		// FilterKnownIdHashes holds details about calls to the FilterKnownIdHashes method.
   116  		FilterKnownIdHashes []struct {
   117  			// Tx is the tx argument value.
   118  			Tx kv.Tx
   119  			// Hashes is the hashes argument value.
   120  			Hashes types2.Hashes
   121  		}
   122  		// GetKnownBlobTxn holds details about calls to the GetKnownBlobTxn method.
   123  		GetKnownBlobTxn []struct {
   124  			// Tx is the tx argument value.
   125  			Tx kv.Tx
   126  			// Hash is the hash argument value.
   127  			Hash []byte
   128  		}
   129  		// GetRlp holds details about calls to the GetRlp method.
   130  		GetRlp []struct {
   131  			// Tx is the tx argument value.
   132  			Tx kv.Tx
   133  			// Hash is the hash argument value.
   134  			Hash []byte
   135  		}
   136  		// IdHashKnown holds details about calls to the IdHashKnown method.
   137  		IdHashKnown []struct {
   138  			// Tx is the tx argument value.
   139  			Tx kv.Tx
   140  			// Hash is the hash argument value.
   141  			Hash []byte
   142  		}
   143  		// OnNewBlock holds details about calls to the OnNewBlock method.
   144  		OnNewBlock []struct {
   145  			// Ctx is the ctx argument value.
   146  			Ctx context.Context
   147  			// StateChanges is the stateChanges argument value.
   148  			StateChanges *remote.StateChangeBatch
   149  			// UnwindTxs is the unwindTxs argument value.
   150  			UnwindTxs types2.TxSlots
   151  			// MinedTxs is the minedTxs argument value.
   152  			MinedTxs types2.TxSlots
   153  			// Tx is the tx argument value.
   154  			Tx kv.Tx
   155  		}
   156  		// Started holds details about calls to the Started method.
   157  		Started []struct {
   158  		}
   159  		// ValidateSerializedTxn holds details about calls to the ValidateSerializedTxn method.
   160  		ValidateSerializedTxn []struct {
   161  			// SerializedTxn is the serializedTxn argument value.
   162  			SerializedTxn []byte
   163  		}
   164  	}
   165  	lockAddLocalTxs           sync.RWMutex
   166  	lockAddNewGoodPeer        sync.RWMutex
   167  	lockAddRemoteTxs          sync.RWMutex
   168  	lockFilterKnownIdHashes   sync.RWMutex
   169  	lockGetKnownBlobTxn       sync.RWMutex
   170  	lockGetRlp                sync.RWMutex
   171  	lockIdHashKnown           sync.RWMutex
   172  	lockOnNewBlock            sync.RWMutex
   173  	lockStarted               sync.RWMutex
   174  	lockValidateSerializedTxn sync.RWMutex
   175  }
   176  
   177  // AddLocalTxs calls AddLocalTxsFunc.
   178  func (mock *PoolMock) AddLocalTxs(ctx context.Context, newTxs types2.TxSlots, tx kv.Tx) ([]txpoolcfg.DiscardReason, error) {
   179  	callInfo := struct {
   180  		Ctx    context.Context
   181  		NewTxs types2.TxSlots
   182  		Tx     kv.Tx
   183  	}{
   184  		Ctx:    ctx,
   185  		NewTxs: newTxs,
   186  		Tx:     tx,
   187  	}
   188  	mock.lockAddLocalTxs.Lock()
   189  	mock.calls.AddLocalTxs = append(mock.calls.AddLocalTxs, callInfo)
   190  	mock.lockAddLocalTxs.Unlock()
   191  	if mock.AddLocalTxsFunc == nil {
   192  		var (
   193  			discardReasonsOut []txpoolcfg.DiscardReason
   194  			errOut            error
   195  		)
   196  		return discardReasonsOut, errOut
   197  	}
   198  	return mock.AddLocalTxsFunc(ctx, newTxs, tx)
   199  }
   200  
   201  // AddLocalTxsCalls gets all the calls that were made to AddLocalTxs.
   202  // Check the length with:
   203  //
   204  //	len(mockedPool.AddLocalTxsCalls())
   205  func (mock *PoolMock) AddLocalTxsCalls() []struct {
   206  	Ctx    context.Context
   207  	NewTxs types2.TxSlots
   208  	Tx     kv.Tx
   209  } {
   210  	var calls []struct {
   211  		Ctx    context.Context
   212  		NewTxs types2.TxSlots
   213  		Tx     kv.Tx
   214  	}
   215  	mock.lockAddLocalTxs.RLock()
   216  	calls = mock.calls.AddLocalTxs
   217  	mock.lockAddLocalTxs.RUnlock()
   218  	return calls
   219  }
   220  
   221  // AddNewGoodPeer calls AddNewGoodPeerFunc.
   222  func (mock *PoolMock) AddNewGoodPeer(peerID types2.PeerID) {
   223  	callInfo := struct {
   224  		PeerID types2.PeerID
   225  	}{
   226  		PeerID: peerID,
   227  	}
   228  	mock.lockAddNewGoodPeer.Lock()
   229  	mock.calls.AddNewGoodPeer = append(mock.calls.AddNewGoodPeer, callInfo)
   230  	mock.lockAddNewGoodPeer.Unlock()
   231  	if mock.AddNewGoodPeerFunc == nil {
   232  		return
   233  	}
   234  	mock.AddNewGoodPeerFunc(peerID)
   235  }
   236  
   237  // AddNewGoodPeerCalls gets all the calls that were made to AddNewGoodPeer.
   238  // Check the length with:
   239  //
   240  //	len(mockedPool.AddNewGoodPeerCalls())
   241  func (mock *PoolMock) AddNewGoodPeerCalls() []struct {
   242  	PeerID types2.PeerID
   243  } {
   244  	var calls []struct {
   245  		PeerID types2.PeerID
   246  	}
   247  	mock.lockAddNewGoodPeer.RLock()
   248  	calls = mock.calls.AddNewGoodPeer
   249  	mock.lockAddNewGoodPeer.RUnlock()
   250  	return calls
   251  }
   252  
   253  // AddRemoteTxs calls AddRemoteTxsFunc.
   254  func (mock *PoolMock) AddRemoteTxs(ctx context.Context, newTxs types2.TxSlots) {
   255  	callInfo := struct {
   256  		Ctx    context.Context
   257  		NewTxs types2.TxSlots
   258  	}{
   259  		Ctx:    ctx,
   260  		NewTxs: newTxs,
   261  	}
   262  	mock.lockAddRemoteTxs.Lock()
   263  	mock.calls.AddRemoteTxs = append(mock.calls.AddRemoteTxs, callInfo)
   264  	mock.lockAddRemoteTxs.Unlock()
   265  	if mock.AddRemoteTxsFunc == nil {
   266  		return
   267  	}
   268  	mock.AddRemoteTxsFunc(ctx, newTxs)
   269  }
   270  
   271  // AddRemoteTxsCalls gets all the calls that were made to AddRemoteTxs.
   272  // Check the length with:
   273  //
   274  //	len(mockedPool.AddRemoteTxsCalls())
   275  func (mock *PoolMock) AddRemoteTxsCalls() []struct {
   276  	Ctx    context.Context
   277  	NewTxs types2.TxSlots
   278  } {
   279  	var calls []struct {
   280  		Ctx    context.Context
   281  		NewTxs types2.TxSlots
   282  	}
   283  	mock.lockAddRemoteTxs.RLock()
   284  	calls = mock.calls.AddRemoteTxs
   285  	mock.lockAddRemoteTxs.RUnlock()
   286  	return calls
   287  }
   288  
   289  // FilterKnownIdHashes calls FilterKnownIdHashesFunc.
   290  func (mock *PoolMock) FilterKnownIdHashes(tx kv.Tx, hashes types2.Hashes) (types2.Hashes, error) {
   291  	callInfo := struct {
   292  		Tx     kv.Tx
   293  		Hashes types2.Hashes
   294  	}{
   295  		Tx:     tx,
   296  		Hashes: hashes,
   297  	}
   298  	mock.lockFilterKnownIdHashes.Lock()
   299  	mock.calls.FilterKnownIdHashes = append(mock.calls.FilterKnownIdHashes, callInfo)
   300  	mock.lockFilterKnownIdHashes.Unlock()
   301  	if mock.FilterKnownIdHashesFunc == nil {
   302  		var (
   303  			unknownHashesOut types2.Hashes
   304  			errOut           error
   305  		)
   306  		return unknownHashesOut, errOut
   307  	}
   308  	return mock.FilterKnownIdHashesFunc(tx, hashes)
   309  }
   310  
   311  // FilterKnownIdHashesCalls gets all the calls that were made to FilterKnownIdHashes.
   312  // Check the length with:
   313  //
   314  //	len(mockedPool.FilterKnownIdHashesCalls())
   315  func (mock *PoolMock) FilterKnownIdHashesCalls() []struct {
   316  	Tx     kv.Tx
   317  	Hashes types2.Hashes
   318  } {
   319  	var calls []struct {
   320  		Tx     kv.Tx
   321  		Hashes types2.Hashes
   322  	}
   323  	mock.lockFilterKnownIdHashes.RLock()
   324  	calls = mock.calls.FilterKnownIdHashes
   325  	mock.lockFilterKnownIdHashes.RUnlock()
   326  	return calls
   327  }
   328  
   329  // GetKnownBlobTxn calls GetKnownBlobTxnFunc.
   330  func (mock *PoolMock) GetKnownBlobTxn(tx kv.Tx, hash []byte) (*metaTx, error) {
   331  	callInfo := struct {
   332  		Tx   kv.Tx
   333  		Hash []byte
   334  	}{
   335  		Tx:   tx,
   336  		Hash: hash,
   337  	}
   338  	mock.lockGetKnownBlobTxn.Lock()
   339  	mock.calls.GetKnownBlobTxn = append(mock.calls.GetKnownBlobTxn, callInfo)
   340  	mock.lockGetKnownBlobTxn.Unlock()
   341  	if mock.GetKnownBlobTxnFunc == nil {
   342  		var (
   343  			metaTxMoqParamOut *metaTx
   344  			errOut            error
   345  		)
   346  		return metaTxMoqParamOut, errOut
   347  	}
   348  	return mock.GetKnownBlobTxnFunc(tx, hash)
   349  }
   350  
   351  // GetKnownBlobTxnCalls gets all the calls that were made to GetKnownBlobTxn.
   352  // Check the length with:
   353  //
   354  //	len(mockedPool.GetKnownBlobTxnCalls())
   355  func (mock *PoolMock) GetKnownBlobTxnCalls() []struct {
   356  	Tx   kv.Tx
   357  	Hash []byte
   358  } {
   359  	var calls []struct {
   360  		Tx   kv.Tx
   361  		Hash []byte
   362  	}
   363  	mock.lockGetKnownBlobTxn.RLock()
   364  	calls = mock.calls.GetKnownBlobTxn
   365  	mock.lockGetKnownBlobTxn.RUnlock()
   366  	return calls
   367  }
   368  
   369  // GetRlp calls GetRlpFunc.
   370  func (mock *PoolMock) GetRlp(tx kv.Tx, hash []byte) ([]byte, error) {
   371  	callInfo := struct {
   372  		Tx   kv.Tx
   373  		Hash []byte
   374  	}{
   375  		Tx:   tx,
   376  		Hash: hash,
   377  	}
   378  	mock.lockGetRlp.Lock()
   379  	mock.calls.GetRlp = append(mock.calls.GetRlp, callInfo)
   380  	mock.lockGetRlp.Unlock()
   381  	if mock.GetRlpFunc == nil {
   382  		var (
   383  			bytesOut []byte
   384  			errOut   error
   385  		)
   386  		return bytesOut, errOut
   387  	}
   388  	return mock.GetRlpFunc(tx, hash)
   389  }
   390  
   391  // GetRlpCalls gets all the calls that were made to GetRlp.
   392  // Check the length with:
   393  //
   394  //	len(mockedPool.GetRlpCalls())
   395  func (mock *PoolMock) GetRlpCalls() []struct {
   396  	Tx   kv.Tx
   397  	Hash []byte
   398  } {
   399  	var calls []struct {
   400  		Tx   kv.Tx
   401  		Hash []byte
   402  	}
   403  	mock.lockGetRlp.RLock()
   404  	calls = mock.calls.GetRlp
   405  	mock.lockGetRlp.RUnlock()
   406  	return calls
   407  }
   408  
   409  // IdHashKnown calls IdHashKnownFunc.
   410  func (mock *PoolMock) IdHashKnown(tx kv.Tx, hash []byte) (bool, error) {
   411  	callInfo := struct {
   412  		Tx   kv.Tx
   413  		Hash []byte
   414  	}{
   415  		Tx:   tx,
   416  		Hash: hash,
   417  	}
   418  	mock.lockIdHashKnown.Lock()
   419  	mock.calls.IdHashKnown = append(mock.calls.IdHashKnown, callInfo)
   420  	mock.lockIdHashKnown.Unlock()
   421  	if mock.IdHashKnownFunc == nil {
   422  		var (
   423  			bOut   bool
   424  			errOut error
   425  		)
   426  		return bOut, errOut
   427  	}
   428  	return mock.IdHashKnownFunc(tx, hash)
   429  }
   430  
   431  // IdHashKnownCalls gets all the calls that were made to IdHashKnown.
   432  // Check the length with:
   433  //
   434  //	len(mockedPool.IdHashKnownCalls())
   435  func (mock *PoolMock) IdHashKnownCalls() []struct {
   436  	Tx   kv.Tx
   437  	Hash []byte
   438  } {
   439  	var calls []struct {
   440  		Tx   kv.Tx
   441  		Hash []byte
   442  	}
   443  	mock.lockIdHashKnown.RLock()
   444  	calls = mock.calls.IdHashKnown
   445  	mock.lockIdHashKnown.RUnlock()
   446  	return calls
   447  }
   448  
   449  // OnNewBlock calls OnNewBlockFunc.
   450  func (mock *PoolMock) OnNewBlock(ctx context.Context, stateChanges *remote.StateChangeBatch, unwindTxs types2.TxSlots, minedTxs types2.TxSlots, tx kv.Tx) error {
   451  	callInfo := struct {
   452  		Ctx          context.Context
   453  		StateChanges *remote.StateChangeBatch
   454  		UnwindTxs    types2.TxSlots
   455  		MinedTxs     types2.TxSlots
   456  		Tx           kv.Tx
   457  	}{
   458  		Ctx:          ctx,
   459  		StateChanges: stateChanges,
   460  		UnwindTxs:    unwindTxs,
   461  		MinedTxs:     minedTxs,
   462  		Tx:           tx,
   463  	}
   464  	mock.lockOnNewBlock.Lock()
   465  	mock.calls.OnNewBlock = append(mock.calls.OnNewBlock, callInfo)
   466  	mock.lockOnNewBlock.Unlock()
   467  	if mock.OnNewBlockFunc == nil {
   468  		var (
   469  			errOut error
   470  		)
   471  		return errOut
   472  	}
   473  	return mock.OnNewBlockFunc(ctx, stateChanges, unwindTxs, minedTxs, tx)
   474  }
   475  
   476  // OnNewBlockCalls gets all the calls that were made to OnNewBlock.
   477  // Check the length with:
   478  //
   479  //	len(mockedPool.OnNewBlockCalls())
   480  func (mock *PoolMock) OnNewBlockCalls() []struct {
   481  	Ctx          context.Context
   482  	StateChanges *remote.StateChangeBatch
   483  	UnwindTxs    types2.TxSlots
   484  	MinedTxs     types2.TxSlots
   485  	Tx           kv.Tx
   486  } {
   487  	var calls []struct {
   488  		Ctx          context.Context
   489  		StateChanges *remote.StateChangeBatch
   490  		UnwindTxs    types2.TxSlots
   491  		MinedTxs     types2.TxSlots
   492  		Tx           kv.Tx
   493  	}
   494  	mock.lockOnNewBlock.RLock()
   495  	calls = mock.calls.OnNewBlock
   496  	mock.lockOnNewBlock.RUnlock()
   497  	return calls
   498  }
   499  
   500  // Started calls StartedFunc.
   501  func (mock *PoolMock) Started() bool {
   502  	callInfo := struct {
   503  	}{}
   504  	mock.lockStarted.Lock()
   505  	mock.calls.Started = append(mock.calls.Started, callInfo)
   506  	mock.lockStarted.Unlock()
   507  	if mock.StartedFunc == nil {
   508  		var (
   509  			bOut bool
   510  		)
   511  		return bOut
   512  	}
   513  	return mock.StartedFunc()
   514  }
   515  
   516  // StartedCalls gets all the calls that were made to Started.
   517  // Check the length with:
   518  //
   519  //	len(mockedPool.StartedCalls())
   520  func (mock *PoolMock) StartedCalls() []struct {
   521  } {
   522  	var calls []struct {
   523  	}
   524  	mock.lockStarted.RLock()
   525  	calls = mock.calls.Started
   526  	mock.lockStarted.RUnlock()
   527  	return calls
   528  }
   529  
   530  // ValidateSerializedTxn calls ValidateSerializedTxnFunc.
   531  func (mock *PoolMock) ValidateSerializedTxn(serializedTxn []byte) error {
   532  	callInfo := struct {
   533  		SerializedTxn []byte
   534  	}{
   535  		SerializedTxn: serializedTxn,
   536  	}
   537  	mock.lockValidateSerializedTxn.Lock()
   538  	mock.calls.ValidateSerializedTxn = append(mock.calls.ValidateSerializedTxn, callInfo)
   539  	mock.lockValidateSerializedTxn.Unlock()
   540  	if mock.ValidateSerializedTxnFunc == nil {
   541  		var (
   542  			errOut error
   543  		)
   544  		return errOut
   545  	}
   546  	return mock.ValidateSerializedTxnFunc(serializedTxn)
   547  }
   548  
   549  // ValidateSerializedTxnCalls gets all the calls that were made to ValidateSerializedTxn.
   550  // Check the length with:
   551  //
   552  //	len(mockedPool.ValidateSerializedTxnCalls())
   553  func (mock *PoolMock) ValidateSerializedTxnCalls() []struct {
   554  	SerializedTxn []byte
   555  } {
   556  	var calls []struct {
   557  		SerializedTxn []byte
   558  	}
   559  	mock.lockValidateSerializedTxn.RLock()
   560  	calls = mock.calls.ValidateSerializedTxn
   561  	mock.lockValidateSerializedTxn.RUnlock()
   562  	return calls
   563  }