testutil

package
v1.1.0-rc02 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 44 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// DefaultBatchSize is the default batch size for testing
	DefaultBatchSize = 5
	// BlockVersion is the default block version for testing
	BlockVersion = 1
	// AppVersion is the default app version for testing
	AppVersion = 2
)
View Source
const (
	DefaultTestBatchSize = 5
)

Variables

View Source
var UnsetMockFn = func(call *mock.Call) {
	if call != nil {
		var newList []*mock.Call
		for _, c := range call.Parent.ExpectedCalls {
			if c.Method != call.Method {
				newList = append(newList, c)
			}
		}
		call.Parent.ExpectedCalls = newList
	}
}

Functions

func CountMockCalls added in v1.1.0

func CountMockCalls(totalCalls []mock.Call, methodName string) int

CountMockCalls returns the number of times a mock specific function was called

func CreateLocalServer added in v1.1.0

func CreateLocalServer(t *testing.T) (*rpc.Server, net.Listener)

func CreateNode added in v1.1.0

func CreateNode(isAggregator bool, blockManagerConfig *config.BlockManagerConfig) (*node.Node, error)

func GenerateBatch

func GenerateBatch(startHeight uint64, endHeight uint64, proposerKey crypto.PrivKey) (*types.Batch, error)

GenerateBatch generates a batch out of random blocks

func GenerateBlocks

func GenerateBlocks(startHeight uint64, num uint64, proposerKey crypto.PrivKey) ([]*types.Block, error)

GenerateBlocks generates random blocks.

func GenerateBlocksWithTxs added in v1.1.0

func GenerateBlocksWithTxs(startHeight uint64, num uint64, proposerKey crypto.PrivKey, nTxs int) ([]*types.Block, error)

func GenerateCommits

func GenerateCommits(blocks []*types.Block, proposerKey crypto.PrivKey) ([]*types.Commit, error)

GenerateCommits generates commits based on passed blocks.

func GenerateGenesis

func GenerateGenesis(initialHeight int64) *tmtypes.GenesisDoc

GenerateGenesis generates a genesis for testing.

func GenerateRandomValidatorSet

func GenerateRandomValidatorSet() *tmtypes.ValidatorSet

GenerateRandomValidatorSet generates random validator sets

func GenerateState

func GenerateState(initialHeight int64, lastBlockHeight int64) types.State

GenerateState generates an initial state for testing.

func GetABCIProxyAppMock

func GetABCIProxyAppMock(logger log.Logger) proxy.AppConns

GetABCIProxyAppMock returns a dummy abci proxy app mock for testing

func GetAppMock

func GetAppMock(excludeMethods ...ABCIMethod) *mocks.Application

GetAppMock returns a dummy abci app mock for testing

func GetManager added in v1.1.0

func GetManager(conf config.BlockManagerConfig, settlementlc settlement.LayerI, dalc da.DataAvailabilityLayerClient, genesisHeight int64, storeInitialHeight int64, storeLastBlockHeight int64, proxyAppConns proxy.AppConns, mockStore store.Store) (*block.Manager, error)

func GetManagerConfig added in v1.1.0

func GetManagerConfig() config.BlockManagerConfig

func GetManagerWithProposerKey added in v1.1.0

func GetManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypto.PrivKey, settlementlc settlement.LayerI, dalc da.DataAvailabilityLayerClient, genesisHeight int64, storeInitialHeight int64, storeLastBlockHeight int64, proxyAppConns proxy.AppConns, mockStore store.Store) (*block.Manager, error)

--------------------------------------------------------------------------

utils

--------------------------------------------------------------------------

func GetMockDALC added in v1.1.0

func GetMockDALC(logger log.Logger) da.DataAvailabilityLayerClient

func GetRandomBlock added in v1.1.0

func GetRandomBlock(height uint64, nTxs int) *types.Block

func GetRandomBytes added in v1.1.0

func GetRandomBytes(n int) []byte

func GetRandomTx added in v1.1.0

func GetRandomTx() types.Tx

func GetRandomValidatorSet added in v1.1.0

func GetRandomValidatorSet() *tmtypes.ValidatorSet

Types

type ABCIMethod

type ABCIMethod string

ABCIMethod is a string representing an ABCI method

const (
	// InitChain is the string representation of the InitChain ABCI method
	InitChain ABCIMethod = "InitChain"
	// CheckTx is the string representation of the CheckTx ABCI method
	CheckTx ABCIMethod = "CheckTx"
	// BeginBlock is the string representation of the BeginBlockMethod ABCI method
	BeginBlock ABCIMethod = "BeginBlock"
	// DeliverTx is the string representation of the DeliverTx ABCI method
	DeliverTx ABCIMethod = "DeliverTx"
	// EndBlock is the string representation of the EndBlock ABCI method
	EndBlock ABCIMethod = "EndBlock"
	// Commit is the string representation of the Commit ABCI method
	Commit ABCIMethod = "Commit"
	// Info is the string representation of the Info ABCI method
	Info ABCIMethod = "Info"
)

type DALayerClientRetrieveBatchesError added in v1.1.0

type DALayerClientRetrieveBatchesError struct {
	localda.DataAvailabilityLayerClient
}

DALayerClientRetrieveBatchesError is a mock data availability layer client that can be used to test error handling

func (*DALayerClientRetrieveBatchesError) RetrieveBatches added in v1.1.0

RetrieveBatches retrieves batches from the data availability layer

type DALayerClientSubmitBatchError added in v1.1.0

type DALayerClientSubmitBatchError struct {
	localda.DataAvailabilityLayerClient
}

DALayerClientSubmitBatchError is a mock data availability layer client that can be used to test error handling

func (*DALayerClientSubmitBatchError) SubmitBatch added in v1.1.0

SubmitBatch submits a batch to the data availability layer

type HostDescr added in v1.1.0

type HostDescr struct {
	ChainID string
	Conns   []int
	RealKey bool
}

type Logger added in v1.1.0

type Logger struct {
	T *testing.T
	// contains filtered or unexported fields
}

Logger is a simple, yet thread-safe, logger intended for use in unit tests.

func NewLogger added in v1.1.0

func NewLogger(t *testing.T) *Logger

NewLogger create a Logger that outputs data using given testing.T instance.

func (*Logger) Debug added in v1.1.0

func (t *Logger) Debug(msg string, keyvals ...interface{})

Debug prints a debug message.

func (*Logger) Error added in v1.1.0

func (t *Logger) Error(msg string, keyvals ...interface{})

Error prints an error message.

func (*Logger) Info added in v1.1.0

func (t *Logger) Info(msg string, keyvals ...interface{})

Info prints an info message.

type MockLogger added in v1.1.0

type MockLogger struct {
	DebugLines, InfoLines, ErrLines []string
}

MockLogger is a fake logger that accumulates all the inputs.

It can be used in tests to ensure that certain messages was logged with correct severity.

func (*MockLogger) Debug added in v1.1.0

func (t *MockLogger) Debug(msg string, keyvals ...interface{})

Debug saves a debug message.

func (*MockLogger) Error added in v1.1.0

func (t *MockLogger) Error(msg string, keyvals ...interface{})

Error saves an error message.

func (*MockLogger) Info added in v1.1.0

func (t *MockLogger) Info(msg string, keyvals ...interface{})

Info saves an info message.

type MockStore added in v1.1.0

type MockStore struct {
	ShouldFailSetHeight            bool
	ShoudFailUpdateState           bool
	ShouldFailUpdateStateWithBatch bool
	*store.DefaultStore
	// contains filtered or unexported fields
}

MockStore is a mock store for testing

func NewMockStore added in v1.1.0

func NewMockStore() *MockStore

NewMockStore returns a new mock store

func (*MockStore) Height added in v1.1.0

func (m *MockStore) Height() uint64

func (*MockStore) NextHeight added in v1.1.0

func (m *MockStore) NextHeight() uint64

func (*MockStore) SetHeight added in v1.1.0

func (m *MockStore) SetHeight(height uint64) bool

SetHeight sets the height of the mock store Don't set the height to mock failure in setting the height

func (*MockStore) UpdateState added in v1.1.0

func (m *MockStore) UpdateState(state types.State, batch store.Batch) (store.Batch, error)

UpdateState updates the state of the mock store

type SubscribeMock added in v1.1.0

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

SubscribeMock is a mock to provide a subscription like behavior for testing

func NewSubscribeMock added in v1.1.0

func NewSubscribeMock(messageCh chan interface{}) *SubscribeMock

func (*SubscribeMock) Chan added in v1.1.0

func (s *SubscribeMock) Chan() <-chan interface{}

func (*SubscribeMock) Unsubscribe added in v1.1.0

func (s *SubscribeMock) Unsubscribe()

type TestNet added in v1.1.0

type TestNet []*p2p.Client

func StartTestNetwork added in v1.1.0

func StartTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]HostDescr, validators []p2p.GossipValidator, logger types.Logger) TestNet

func (TestNet) Close added in v1.1.0

func (tn TestNet) Close() (err error)

func (TestNet) WaitForDHT added in v1.1.0

func (tn TestNet) WaitForDHT()

Jump to

Keyboard shortcuts

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