app

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2023 License: AGPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultGenesis

func DefaultGenesis() (genesis types.GenesisDoc)

DefaultGenesis returns a genesis doc using configuration from the local net with a genesis time equivalent to unix epoch + 1 nanosecond. We specifically use non-zero because stateful orders validate that block time is non-zero (https://github.com/dydxprotocol/v4-chain/protocol/blob/ 84a046554ab1b4725475500d94a0b3179fdd18c2/x/clob/keeper/stateful_order_state.go#L237).

func DefaultTestApp

func DefaultTestApp(customFlags map[string]interface{}) *app.App

Create an instance of app.App with default settings, suitable for unit testing, with the option to override specific flags.

func MustMakeCheckTx

func MustMakeCheckTx(
	ctx sdk.Context,
	app *app.App,
	options MustMakeCheckTxOptions,
	messages ...sdk.Msg,
) abcitypes.RequestCheckTx

MustMakeCheckTx creates a signed RequestCheckTx for the provided message. The message must use one of the hard-coded well known subaccount owners otherwise this will panic.

func MustMakeCheckTxWithPrivKeySupplier

func MustMakeCheckTxWithPrivKeySupplier(
	ctx sdk.Context,
	app *app.App,
	options MustMakeCheckTxOptions,
	privKeySupplier func(accAddress string) cryptotypes.PrivKey,
	messages ...sdk.Msg,
) abcitypes.RequestCheckTx

MustMakeCheckTxWithPrivKeySupplier creates a signed RequestCheckTx for the provided message. The `privKeySupplier` must provide a valid private key that matches the supplied account address.

func MustMakeCheckTxsWithClobMsg

func MustMakeCheckTxsWithClobMsg[T clobtypes.MsgPlaceOrder | clobtypes.MsgCancelOrder](
	ctx sdk.Context,
	app *app.App,
	messages ...T,
) []abcitypes.RequestCheckTx

MustMakeCheckTxsWithClobMsg creates one signed RequestCheckTx for each msg passed in. The messsage must use one of the hard-coded well known subaccount owners otherwise this will panic.

func MustMakeCheckTxsWithSdkMsg

func MustMakeCheckTxsWithSdkMsg(
	ctx sdk.Context,
	app *app.App,
	options MustMakeCheckTxOptions,
	messages ...sdk.Msg,
) (checkTxs []abcitypes.RequestCheckTx)

MustMakeCheckTxsWithSdkMsg creates one signed RequestCheckTx for each msg passed in. The messsage must use one of the hard-coded well known subaccount owners otherwise this will panic.

func UpdateGenesisDocWithAppStateForModule

func UpdateGenesisDocWithAppStateForModule[T GenesisStates](genesisDoc *types.GenesisDoc, fn func(genesisState *T))

UpdateGenesisDocWithAppStateForModule updates the supplied genesis doc using the provided function. The function type (any one of the well known GenesisStates) is used to derive which module will be updated. Will panic if there is an error in marshalling or unmarshalling the app state.

Types

type AdvanceToBlockOptions

type AdvanceToBlockOptions struct {
	// The time associated with the block. If left at the default value then block time will be left unchanged.
	BlockTime time.Time

	// RequestPrepareProposalTxsOverride allows overriding the txs that gets passed into the
	// PrepareProposalHandler. This is useful for testing scenarios where unintended msg txs
	// end up in the mempool (i.e. CheckTx failed to filter bad msg txs out).
	RequestPrepareProposalTxsOverride [][]byte

	// RequestProcessProposalTxsOverride allows overriding the txs that gets passed into the
	// ProcessProposalHandler. This is useful for testing scenarios where bad validators end
	// up proposing an invalid block proposal.
	RequestProcessProposalTxsOverride [][]byte

	// DeliverTxsOverride allows overriding the TestApp from being the block proposer and
	// allows simulating transactions that were agreed to upon consensus to be delivered.
	// This skips the PrepareProposal and ProcessProposal phase.
	DeliverTxsOverride [][]byte

	ValidateRespPrepare ValidateResponsePrepareProposalFn
	ValidateRespProcess ValidateResponseProcessProposalFn
	ValidateDeliverTxs  ValidateDeliverTxsFn
}

AdvanceToBlockOptions is a struct containing options for AdvanceToBlock.* functions.

type AppCreatorFn

type AppCreatorFn func() *app.App

Used to instantiate new instances of the App.

func DefaultTestAppCreatorFn

func DefaultTestAppCreatorFn(customFlags map[string]interface{}) AppCreatorFn

DefaultTestAppCreatorFn is a wrapper function around DefaultTestApp using the specified custom flags.

type ExecuteCheckTxs

type ExecuteCheckTxs func(ctx sdk.Context, app *app.App) (stop bool)

ExecuteCheckTxs is invoked once per block. Returning true will halt execution. The provided context will be a new CheckTx context using the last committed block height.

type GenesisDocCreatorFn

type GenesisDocCreatorFn func() (genesis types.GenesisDoc)

Used to instantiate new instances of the genesis doc.

type MustMakeCheckTxOptions

type MustMakeCheckTxOptions struct {
	// AccAddressForSigning is the account that's used to sign the transaction.
	AccAddressForSigning string
	// AccSequenceNumberForSigning is the account sequence number that's used to sign the transaction.
	AccSequenceNumberForSigning uint64
	// Amount of Gas for the transaction.
	Gas uint64
}

MustMakeCheckTxOptions is a struct containing options for MustMakeCheckTx.* functions.

type TestApp

type TestApp struct {
	// Should only be used to fetch read only state, all mutations should preferrably happen through Genesis state,
	// TestApp.CheckTx, and block proposals.
	// TODO(CLOB-545): Hide App and copy the pointers to keepers to be prevent incorrect usage of App.CheckTx over
	// TestApp.CheckTx.
	App *app.App
	// contains filtered or unexported fields
}

A TestApp used to executed ABCI++ flows. Note that callers should invoke `TestApp.CheckTx` over `TestApp.App.CheckTx` to ensure that the transaction is added to a "mempool" that will be considered during the Prepare/Process proposal phase.

Note that TestApp.CheckTx is thread safe. All other methods are not thread safe.

func (*TestApp) AdvanceToBlock

func (tApp *TestApp) AdvanceToBlock(
	block uint32,
	options AdvanceToBlockOptions,
) sdk.Context

AdvanceToBlock advances the chain to the specified block and block time. If the specified block is the current block, simply returns the current context. For example, block = 10, t = 90 will advance to a block with height 10 and with a time of 90.

func (*TestApp) Builder

func (tApp *TestApp) Builder() TestAppBuilder

func (*TestApp) CheckTx

CheckTx adds the transaction to a test specific "mempool" that will be used to deliver the transaction during Prepare/Process proposal. Note that this must be invoked over TestApp.App.CheckTx as the transaction will not be added to the "mempool" causing the transaction to not be supplied during the Prepare/Process proposal phase.

This method is thread-safe.

func (*TestApp) GetBlockHeight

func (tApp *TestApp) GetBlockHeight() int64

GetBlockHeight fetches the current block height of the test app.

func (*TestApp) GetHalted

func (tApp *TestApp) GetHalted() bool

GetHalted fetches the halted flag.

func (*TestApp) GetHeader

func (tApp *TestApp) GetHeader() tmproto.Header

GetHeader fetches the current header of the test app.

func (*TestApp) InitChain

func (tApp *TestApp) InitChain() sdk.Context

InitChain initializes the chain. Will panic if initialized more than once.

func (*TestApp) PrepareProposal

func (tApp *TestApp) PrepareProposal() abcitypes.ResponsePrepareProposal

PrepareProposal creates an abci `RequestPrepareProposal` using the current state of the chain and calls the PrepareProposal handler to return an abci `ResponsePrepareProposal`.

func (*TestApp) Reset

func (tApp *TestApp) Reset()

Reset resets the chain such that it can be initialized and executed again.

type TestAppBuilder

type TestAppBuilder struct {
	// contains filtered or unexported fields
}

A builder containing fields necessary for the TestApp.

Note that we specifically use value receivers for the With... methods because we want to make the builder instances immutable.

func NewTestAppBuilder

func NewTestAppBuilder() TestAppBuilder

NewTestAppBuilder returns a new builder for TestApp.

The default instance will return a builder using:

  • DefaultGenesis
  • DefaultTestAppCreatorFn with no custom flags
  • an ExecuteCheckTxs function that will stop on after the first block

func (TestAppBuilder) Build

func (tApp TestAppBuilder) Build() TestApp

Build returns a new TestApp capable of being executed.

func (TestAppBuilder) WithAppCreatorFn

func (tApp TestAppBuilder) WithAppCreatorFn(fn AppCreatorFn) TestAppBuilder

WithAppCreatorFn returns a builder like this one with the specified function that will be used to create the application.

func (TestAppBuilder) WithGenesisDocFn

func (tApp TestAppBuilder) WithGenesisDocFn(fn GenesisDocCreatorFn) TestAppBuilder

WithGenesisDocFn returns a builder like this one with specified function that will be used to create the genesis doc.

func (TestAppBuilder) WithTesting

func (tApp TestAppBuilder) WithTesting(t *testing.T) TestAppBuilder

WithTesting returns a builder like this one with the specified testing environment being specified.

type ValidateDeliverTxsFn

type ValidateDeliverTxsFn func(
	ctx sdk.Context,
	request abcitypes.RequestDeliverTx,
	response abcitypes.ResponseDeliverTx,
) (haltchain bool)

ValidateDeliverTxsFn is a function that validates the response from each transaction that is delivered.

type ValidateResponsePrepareProposalFn

type ValidateResponsePrepareProposalFn func(sdk.Context, abcitypes.ResponsePrepareProposal) (haltChain bool)

ValidateResponsePrepareProposal is a function that validates the response from the PrepareProposalHandler.

type ValidateResponseProcessProposalFn

type ValidateResponseProcessProposalFn func(sdk.Context, abcitypes.ResponseProcessProposal) (haltChain bool)

ValidateResponseProcessProposal is a function that validates the response from the ProcessProposalHandler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL