You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.7 KiB

  1. package consensus
  2. import (
  3. abci "github.com/tendermint/tendermint/abci/types"
  4. "github.com/tendermint/tendermint/internal/libs/clist"
  5. mempl "github.com/tendermint/tendermint/mempool"
  6. tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
  7. "github.com/tendermint/tendermint/proxy"
  8. "github.com/tendermint/tendermint/types"
  9. )
  10. //-----------------------------------------------------------------------------
  11. type emptyMempool struct{}
  12. var _ mempl.Mempool = emptyMempool{}
  13. func (emptyMempool) Lock() {}
  14. func (emptyMempool) Unlock() {}
  15. func (emptyMempool) Size() int { return 0 }
  16. func (emptyMempool) CheckTx(_ types.Tx, _ func(*abci.Response), _ mempl.TxInfo) error {
  17. return nil
  18. }
  19. func (emptyMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs { return types.Txs{} }
  20. func (emptyMempool) ReapMaxTxs(n int) types.Txs { return types.Txs{} }
  21. func (emptyMempool) Update(
  22. _ int64,
  23. _ types.Txs,
  24. _ []*abci.ResponseDeliverTx,
  25. _ mempl.PreCheckFunc,
  26. _ mempl.PostCheckFunc,
  27. ) error {
  28. return nil
  29. }
  30. func (emptyMempool) Flush() {}
  31. func (emptyMempool) FlushAppConn() error { return nil }
  32. func (emptyMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
  33. func (emptyMempool) EnableTxsAvailable() {}
  34. func (emptyMempool) SizeBytes() int64 { return 0 }
  35. func (emptyMempool) TxsFront() *clist.CElement { return nil }
  36. func (emptyMempool) TxsWaitChan() <-chan struct{} { return nil }
  37. func (emptyMempool) InitWAL() error { return nil }
  38. func (emptyMempool) CloseWAL() {}
  39. //-----------------------------------------------------------------------------
  40. // mockProxyApp uses ABCIResponses to give the right results.
  41. //
  42. // Useful because we don't want to call Commit() twice for the same block on
  43. // the real app.
  44. func newMockProxyApp(appHash []byte, abciResponses *tmstate.ABCIResponses) proxy.AppConnConsensus {
  45. clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{
  46. appHash: appHash,
  47. abciResponses: abciResponses,
  48. })
  49. cli, _ := clientCreator.NewABCIClient()
  50. err := cli.Start()
  51. if err != nil {
  52. panic(err)
  53. }
  54. return proxy.NewAppConnConsensus(cli)
  55. }
  56. type mockProxyApp struct {
  57. abci.BaseApplication
  58. appHash []byte
  59. txCount int
  60. abciResponses *tmstate.ABCIResponses
  61. }
  62. func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
  63. r := mock.abciResponses.DeliverTxs[mock.txCount]
  64. mock.txCount++
  65. if r == nil {
  66. return abci.ResponseDeliverTx{}
  67. }
  68. return *r
  69. }
  70. func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
  71. mock.txCount = 0
  72. return *mock.abciResponses.EndBlock
  73. }
  74. func (mock *mockProxyApp) Commit() abci.ResponseCommit {
  75. return abci.ResponseCommit{Data: mock.appHash}
  76. }