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.

175 lines
4.5 KiB

  1. package mocks
  2. import (
  3. types "github.com/tendermint/tendermint/abci/types"
  4. )
  5. // BaseMock provides a wrapper around the generated Application mock and a BaseApplication.
  6. // BaseMock first tries to use the mock's implementation of the method.
  7. // If no functionality was provided for the mock by the user, BaseMock dispatches
  8. // to the BaseApplication and uses its functionality.
  9. // BaseMock allows users to provide mocked functionality for only the methods that matter
  10. // for their test while avoiding a panic if the code calls Application methods that are
  11. // not relevant to the test.
  12. type BaseMock struct {
  13. base *types.BaseApplication
  14. *Application
  15. }
  16. func NewBaseMock() BaseMock {
  17. return BaseMock{
  18. base: types.NewBaseApplication(),
  19. Application: new(Application),
  20. }
  21. }
  22. // Info/Query Connection
  23. // Return application info
  24. func (m BaseMock) Info(input types.RequestInfo) (ret types.ResponseInfo) {
  25. defer func() {
  26. if r := recover(); r != nil {
  27. ret = m.base.Info(input)
  28. }
  29. }()
  30. ret = m.Application.Info(input)
  31. return ret
  32. }
  33. func (m BaseMock) Query(input types.RequestQuery) (ret types.ResponseQuery) {
  34. defer func() {
  35. if r := recover(); r != nil {
  36. ret = m.base.Query(input)
  37. }
  38. }()
  39. ret = m.Application.Query(input)
  40. return ret
  41. }
  42. // Mempool Connection
  43. // Validate a tx for the mempool
  44. func (m BaseMock) CheckTx(input types.RequestCheckTx) (ret types.ResponseCheckTx) {
  45. defer func() {
  46. if r := recover(); r != nil {
  47. ret = m.base.CheckTx(input)
  48. }
  49. }()
  50. ret = m.Application.CheckTx(input)
  51. return ret
  52. }
  53. // Consensus Connection
  54. // Initialize blockchain w validators/other info from TendermintCore
  55. func (m BaseMock) InitChain(input types.RequestInitChain) (ret types.ResponseInitChain) {
  56. defer func() {
  57. if r := recover(); r != nil {
  58. ret = m.base.InitChain(input)
  59. }
  60. }()
  61. ret = m.Application.InitChain(input)
  62. return ret
  63. }
  64. func (m BaseMock) PrepareProposal(input types.RequestPrepareProposal) (ret types.ResponsePrepareProposal) {
  65. defer func() {
  66. if r := recover(); r != nil {
  67. ret = m.base.PrepareProposal(input)
  68. }
  69. }()
  70. ret = m.Application.PrepareProposal(input)
  71. return ret
  72. }
  73. func (m BaseMock) ProcessProposal(input types.RequestProcessProposal) (ret types.ResponseProcessProposal) {
  74. defer func() {
  75. if r := recover(); r != nil {
  76. ret = m.base.ProcessProposal(input)
  77. }
  78. }()
  79. ret = m.Application.ProcessProposal(input)
  80. return ret
  81. }
  82. // Commit the state and return the application Merkle root hash
  83. func (m BaseMock) Commit() (ret types.ResponseCommit) {
  84. defer func() {
  85. if r := recover(); r != nil {
  86. ret = m.base.Commit()
  87. }
  88. }()
  89. ret = m.Application.Commit()
  90. return ret
  91. }
  92. // Create application specific vote extension
  93. func (m BaseMock) ExtendVote(input types.RequestExtendVote) (ret types.ResponseExtendVote) {
  94. defer func() {
  95. if r := recover(); r != nil {
  96. ret = m.base.ExtendVote(input)
  97. }
  98. }()
  99. ret = m.Application.ExtendVote(input)
  100. return ret
  101. }
  102. // Verify application's vote extension data
  103. func (m BaseMock) VerifyVoteExtension(input types.RequestVerifyVoteExtension) (ret types.ResponseVerifyVoteExtension) {
  104. defer func() {
  105. if r := recover(); r != nil {
  106. ret = m.base.VerifyVoteExtension(input)
  107. }
  108. }()
  109. ret = m.Application.VerifyVoteExtension(input)
  110. return ret
  111. }
  112. // State Sync Connection
  113. // List available snapshots
  114. func (m BaseMock) ListSnapshots(input types.RequestListSnapshots) (ret types.ResponseListSnapshots) {
  115. defer func() {
  116. if r := recover(); r != nil {
  117. ret = m.base.ListSnapshots(input)
  118. }
  119. }()
  120. ret = m.Application.ListSnapshots(input)
  121. return ret
  122. }
  123. func (m BaseMock) OfferSnapshot(input types.RequestOfferSnapshot) (ret types.ResponseOfferSnapshot) {
  124. defer func() {
  125. if r := recover(); r != nil {
  126. ret = m.base.OfferSnapshot(input)
  127. }
  128. }()
  129. ret = m.Application.OfferSnapshot(input)
  130. return ret
  131. }
  132. func (m BaseMock) LoadSnapshotChunk(input types.RequestLoadSnapshotChunk) (ret types.ResponseLoadSnapshotChunk) {
  133. defer func() {
  134. if r := recover(); r != nil {
  135. ret = m.base.LoadSnapshotChunk(input)
  136. }
  137. }()
  138. ret = m.Application.LoadSnapshotChunk(input)
  139. return ret
  140. }
  141. func (m BaseMock) ApplySnapshotChunk(input types.RequestApplySnapshotChunk) (ret types.ResponseApplySnapshotChunk) {
  142. defer func() {
  143. if r := recover(); r != nil {
  144. ret = m.base.ApplySnapshotChunk(input)
  145. }
  146. }()
  147. ret = m.Application.ApplySnapshotChunk(input)
  148. return ret
  149. }
  150. func (m BaseMock) FinalizeBlock(input types.RequestFinalizeBlock) (ret types.ResponseFinalizeBlock) {
  151. defer func() {
  152. if r := recover(); r != nil {
  153. ret = m.base.FinalizeBlock(input)
  154. }
  155. }()
  156. ret = m.Application.FinalizeBlock(input)
  157. return ret
  158. }