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