github.com/Finschia/finschia-sdk@v0.48.1/baseapp/test_helpers.go (about) 1 package baseapp 2 3 import ( 4 tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 5 6 sdk "github.com/Finschia/finschia-sdk/types" 7 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 8 ) 9 10 func (app *BaseApp) Check(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, error) { 11 // runTx expects tx bytes as argument, so we encode the tx argument into 12 // bytes. Note that runTx will actually decode those bytes again. But since 13 // this helper is only used in tests/simulation, it's fine. 14 txBytes, err := txEncoder(tx) 15 if err != nil { 16 return sdk.GasInfo{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) 17 } 18 return app.checkTx(txBytes, tx, false) 19 } 20 21 func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) { 22 tx, err := app.txDecoder(txBytes) 23 if err != nil { 24 return sdk.GasInfo{}, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) 25 } 26 27 gasInfo, result, _, err := app.runTx(txBytes, tx, true) 28 return gasInfo, result, err 29 } 30 31 func (app *BaseApp) Deliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { 32 // See comment for Check(). 33 txBytes, err := txEncoder(tx) 34 if err != nil { 35 return sdk.GasInfo{}, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) 36 } 37 gasInfo, result, _, err := app.runTx(txBytes, tx, false) 38 return gasInfo, result, err 39 } 40 41 // Context with current {check, deliver}State of the app used by tests. 42 func (app *BaseApp) NewContext(isCheckTx bool, header tmproto.Header) sdk.Context { 43 if isCheckTx { 44 ctx := sdk.NewContext(app.checkState.ms, header, true, app.logger). 45 WithMinGasPrices(app.minGasPrices) 46 return ctx.WithConsensusParams(app.GetConsensusParams(ctx)) 47 } 48 49 return sdk.NewContext(app.deliverState.ms, header, false, app.logger) 50 } 51 52 func (app *BaseApp) NewUncachedContext(isCheckTx bool, header tmproto.Header) sdk.Context { 53 return sdk.NewContext(app.cms, header, isCheckTx, app.logger) 54 } 55 56 func (app *BaseApp) GetContextForDeliverTx(txBytes []byte) sdk.Context { 57 return app.getContextForTx(app.deliverState, txBytes) 58 }