testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFaultyEngine = errors.New("unknown error: engine must be faulty")

ErrFaultyEngine is the error returned by a FaultyEngine.

View Source
var ErrProcessingFailed = errors.New("processing failed")

ErrProcessingFailed is the error returned by FaultyProcessor.

View Source
var (
	// ErrRejected is the error returns by Rejector.
	ErrRejected = errors.New("rejected")
)

Functions

func NewDummyGossip

func NewDummyGossip(t *testing.T) gossip.Gossip

NewDummyGossip returns a gossip mock that does nothing.

func NewDummyP2P

func NewDummyP2P(t *testing.T) p2p.P2P

NewDummyP2P returns a p2p mock that does nothing.

func NewSimpleState

func NewSimpleState(t *testing.T, opts ...state.Opt) state.State

NewSimpleState returns a SimpleState ready to use in tests.

Types

type DummyEngine

type DummyEngine struct{}

DummyEngine is an engine that does nothing.

func (*DummyEngine) Finalize

func (e *DummyEngine) Finalize(ctx context.Context, chain chain.Reader, header *pb.Header, state state.Reader, txs []*pb.Transaction) (*pb.Block, error)

Finalize returns an empty block with the given header.

func (*DummyEngine) Prepare

func (e *DummyEngine) Prepare(chain chain.Reader, header *pb.Header) error

Prepare does nothing.

func (*DummyEngine) VerifyHeader

func (e *DummyEngine) VerifyHeader(chain chain.Reader, header *pb.Header) error

VerifyHeader does nothing.

type DummyPoW

type DummyPoW struct {
	InstrumentedEngine
	// contains filtered or unexported fields
}

DummyPoW is a dummy proof-of-work engine.

func NewDummyPoW

func NewDummyPoW(e engine.Engine, difficulty, reward uint64) *DummyPoW

NewDummyPoW creates a new DummyPoW.

func (*DummyPoW) Difficulty

func (e *DummyPoW) Difficulty() uint64

Difficulty returns a configurable difficulty.

func (*DummyPoW) DifficultyCount

func (e *DummyPoW) DifficultyCount() uint32

DifficultyCount returns the number of calls to Difficulty.

func (*DummyPoW) Reward

func (e *DummyPoW) Reward() uint64

Reward returns the statically configured miner reward.

type DummyProcessor

type DummyProcessor struct{}

DummyProcessor is a dummy processor that always returns nil as if processing ended correctly.

func (*DummyProcessor) Process

func (p *DummyProcessor) Process(ctx context.Context, block *pb.Block, state state.State, chain chain.Chain) error

Process returns nil to simulate a processing success.

type DummyProofOfWait

type DummyProofOfWait struct {
	InstrumentedEngine
	// contains filtered or unexported fields
}

DummyProofOfWait is a dummy proof-of-wait © engine.

func NewDummyProofOfWait

func NewDummyProofOfWait(e engine.Engine, min, max int) *DummyProofOfWait

NewDummyProofOfWait creates a new DummyProofOfWait.

func (*DummyProofOfWait) Interval

func (e *DummyProofOfWait) Interval() (int, int)

Interval increments a counter and returns a configurable interval for the proof-of-wait.

func (*DummyProofOfWait) IntervalCount

func (e *DummyProofOfWait) IntervalCount() uint32

IntervalCount returns the number of calls to Interval.

type DummyValidator

type DummyValidator struct{}

DummyValidator is a validator that always returns nil (valid).

func (*DummyValidator) MaxTxPerBlock

func (v *DummyValidator) MaxTxPerBlock() uint32

MaxTxPerBlock always returns 1.

func (*DummyValidator) ValidateBlock

func (v *DummyValidator) ValidateBlock(block *pb.Block, _ state.Reader) error

ValidateBlock always returns nil (valid block).

func (*DummyValidator) ValidateTransactions

func (v *DummyValidator) ValidateTransactions(transactions []*pb.Transaction, _ state.Reader) error

ValidateTransactions always returns nil (valid block).

func (*DummyValidator) ValidateTx

func (v *DummyValidator) ValidateTx(tx *pb.Transaction, state state.Reader) error

ValidateTx always returns nil (valid tx).

type FaultyEngine

type FaultyEngine struct{}

FaultyEngine always returns an ErrFaultyEngine error.

func (*FaultyEngine) Finalize

func (e *FaultyEngine) Finalize(ctx context.Context, chain chain.Reader, header *pb.Header, state state.Reader, txs []*pb.Transaction) (*pb.Block, error)

Finalize does nothing.

func (*FaultyEngine) Prepare

func (e *FaultyEngine) Prepare(chain chain.Reader, header *pb.Header) error

Prepare does nothing.

func (*FaultyEngine) VerifyHeader

func (e *FaultyEngine) VerifyHeader(chain chain.Reader, header *pb.Header) error

VerifyHeader records that header was verified.

type FaultyProcessor

type FaultyProcessor struct{}

FaultyProcessor is a dummy processor that always returns an error as if processing failed.

func (*FaultyProcessor) Process

func (p *FaultyProcessor) Process(ctx context.Context, block *pb.Block, state state.State, chain chain.Chain) error

Process returns an error to simulate a processing failure.

type HeaderMatcher

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

HeaderMatcher matches headers.

func NewHeaderMatcher

func NewHeaderMatcher(expectedHeader *pb.Header) HeaderMatcher

NewHeaderMatcher creates a HeaderMatcher.

func (HeaderMatcher) Matches

func (m HeaderMatcher) Matches(x interface{}) bool

Matches returns whether x is a match. For unit tests, matching on block number should be enough.

func (HeaderMatcher) String

func (m HeaderMatcher) String() string

String describes what the matcher matches.

type InMemoryTxPool

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

InMemoryTxPool is a basic txpool implementation that stores transactions in RAM.

func (*InMemoryTxPool) AddTransaction

func (m *InMemoryTxPool) AddTransaction(tx *pb.Transaction) error

AddTransaction adds transaction to the txpool.

func (*InMemoryTxPool) Contains

func (m *InMemoryTxPool) Contains(tx *pb.Transaction) bool

Contains returns true if the txpool contains the given transaction.

func (*InMemoryTxPool) Peek

func (m *InMemoryTxPool) Peek(n uint32) []*pb.Transaction

Peek returns the n first transactions from the pool.

func (*InMemoryTxPool) Pending

func (m *InMemoryTxPool) Pending() uint64

Pending returns the number of transactions.

func (*InMemoryTxPool) PopCount

func (m *InMemoryTxPool) PopCount() uint32

PopCount returns the number of times PopTransaction was called.

func (*InMemoryTxPool) PopTransaction

func (m *InMemoryTxPool) PopTransaction() *pb.Transaction

PopTransaction pops the oldest transaction from the txpool.

func (*InMemoryTxPool) TxCount

func (m *InMemoryTxPool) TxCount() int

TxCount returns the number of transactions in the txpool.

type InstrumentedEngine

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

InstrumentedEngine adds method calls instrumentation to an engine.

func NewInstrumentedEngine

func NewInstrumentedEngine(e engine.Engine) *InstrumentedEngine

NewInstrumentedEngine wraps an engine with instrumentation.

func (*InstrumentedEngine) Finalize

func (e *InstrumentedEngine) Finalize(ctx context.Context, chain chain.Reader, header *pb.Header, state state.Reader, txs []*pb.Transaction) (*pb.Block, error)

Finalize records the call.

func (*InstrumentedEngine) FinalizeCount

func (e *InstrumentedEngine) FinalizeCount() uint32

FinalizeCount returns the number of calls to Finalize.

func (*InstrumentedEngine) Prepare

func (e *InstrumentedEngine) Prepare(chain chain.Reader, header *pb.Header) error

Prepare records the call.

func (*InstrumentedEngine) PrepareCount

func (e *InstrumentedEngine) PrepareCount() uint32

PrepareCount returns the number of calls to Prepare.

func (*InstrumentedEngine) VerifiedHeader

func (e *InstrumentedEngine) VerifiedHeader(header *pb.Header) bool

VerifiedHeader checks if the input header was verified by the engine.

func (*InstrumentedEngine) VerifyCount

func (e *InstrumentedEngine) VerifyCount() uint32

VerifyCount returns the number of calls to VerifyHeader.

func (*InstrumentedEngine) VerifyHeader

func (e *InstrumentedEngine) VerifyHeader(chain chain.Reader, header *pb.Header) error

VerifyHeader records that header was verified.

type InstrumentedProcessor

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

InstrumentedProcessor adds method calls instrumentation to a processor.

func NewInstrumentedProcessor

func NewInstrumentedProcessor(p processor.Processor) *InstrumentedProcessor

NewInstrumentedProcessor wraps a processor with instrumentation.

func (*InstrumentedProcessor) Process

func (p *InstrumentedProcessor) Process(ctx context.Context, block *pb.Block, state state.State, chain chain.Chain) error

Process records the call.

func (*InstrumentedProcessor) ProcessedCount

func (p *InstrumentedProcessor) ProcessedCount() uint32

ProcessedCount returns the number of blocks processed.

type InstrumentedValidator

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

InstrumentedValidator adds method calls instrumentation to a validator.

func NewInstrumentedValidator

func NewInstrumentedValidator(validator validator.Validator) *InstrumentedValidator

NewInstrumentedValidator wraps a validator with instrumentation.

func (*InstrumentedValidator) MaxTxPerBlock

func (r *InstrumentedValidator) MaxTxPerBlock() uint32

MaxTxPerBlock returns the maximum number of transactions allowed in a block.

func (*InstrumentedValidator) ValidateBlock

func (r *InstrumentedValidator) ValidateBlock(block *pb.Block, state state.Reader) error

ValidateBlock records the incoming block.

func (*InstrumentedValidator) ValidateTransactions

func (r *InstrumentedValidator) ValidateTransactions(transactions []*pb.Transaction, state state.Reader) error

ValidateTransactions records the incoming block.

func (*InstrumentedValidator) ValidateTx

func (r *InstrumentedValidator) ValidateTx(tx *pb.Transaction, state state.Reader) error

ValidateTx records the incoming tx.

func (*InstrumentedValidator) ValidatedBlock

func (r *InstrumentedValidator) ValidatedBlock(block *pb.Block) bool

ValidatedBlock returns true if the validator saw the given block.

func (*InstrumentedValidator) ValidatedTx

func (r *InstrumentedValidator) ValidatedTx(tx *pb.Transaction) bool

ValidatedTx returns true if the validator saw the given transaction.

type Rejector

type Rejector struct{}

Rejector implements the Validator interface and rejects incoming transactions and blocks.

func (*Rejector) MaxTxPerBlock

func (r *Rejector) MaxTxPerBlock() uint32

MaxTxPerBlock always returns 1.

func (*Rejector) ValidateBlock

func (r *Rejector) ValidateBlock(block *pb.Block, _ state.Reader) error

ValidateBlock records the incoming block and rejects it.

func (*Rejector) ValidateTransactions

func (r *Rejector) ValidateTransactions(transactions []*pb.Transaction, _ state.Reader) error

ValidateTransactions records the incoming block and rejects it.

func (*Rejector) ValidateTx

func (r *Rejector) ValidateTx(tx *pb.Transaction, state state.Reader) error

ValidateTx records the incoming tx and rejects it.

type SimpleChain

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

SimpleChain can be used in tests to inject arbitrary blocks.

func (*SimpleChain) AddBlock

func (c *SimpleChain) AddBlock(block *pb.Block) error

AddBlock adds a block to the chain without any validation. It also sets the given block as current block.

func (*SimpleChain) Config

func (c *SimpleChain) Config() *chain.Config

Config returns nothing.

func (*SimpleChain) CurrentBlock

func (c *SimpleChain) CurrentBlock() (*pb.Block, error)

CurrentBlock returns the header of the last block added.

func (*SimpleChain) CurrentHeader

func (c *SimpleChain) CurrentHeader() (*pb.Header, error)

CurrentHeader returns the header of the last block added.

func (*SimpleChain) GetBlock

func (c *SimpleChain) GetBlock(hash []byte, _ uint64) (*pb.Block, error)

GetBlock returns the first block with the given header hash.

func (*SimpleChain) GetBlockByHash

func (c *SimpleChain) GetBlockByHash(hash []byte) (*pb.Block, error)

GetBlockByHash returns the first block with the given header hash.

func (*SimpleChain) GetBlockByNumber

func (c *SimpleChain) GetBlockByNumber(number uint64) (*pb.Block, error)

GetBlockByNumber retrieves a header from the main branch by number.

func (*SimpleChain) GetHeaderByHash

func (c *SimpleChain) GetHeaderByHash(hash []byte) (*pb.Header, error)

GetHeaderByHash returns the first header of the block with the given hash.

func (*SimpleChain) GetHeaderByNumber

func (c *SimpleChain) GetHeaderByNumber(number uint64) (*pb.Header, error)

GetHeaderByNumber retrieves a header from the main branch by number.

func (*SimpleChain) GetHeadersByNumber

func (c *SimpleChain) GetHeadersByNumber(number uint64) ([]*pb.Header, error)

GetHeadersByNumber returns all headers that have the input BlockNumber.

func (*SimpleChain) GetParentBlock

func (c *SimpleChain) GetParentBlock(header *pb.Header) (*pb.Block, error)

GetParentBlock retrieves the block's parent block.

func (*SimpleChain) SetHead

func (c *SimpleChain) SetHead(block *pb.Block) error

SetHead sets the given block as chain head.

type TxMatcher

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

TxMatcher matches transactions.

func NewTxMatcher

func NewTxMatcher(expectedTx *pb.Transaction) TxMatcher

NewTxMatcher creates a TxMatcher.

func (TxMatcher) Matches

func (m TxMatcher) Matches(x interface{}) bool

Matches returns whether x is a match. For unit tests, matching on value and nonce should be enough.

func (TxMatcher) String

func (m TxMatcher) String() string

String describes what the matcher matches.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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