tests_utils

package
v0.0.0-...-91d38f8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2020 License: GPL-3.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTestConfig = &tendermint.Config{
	ProposerPolicy:        tendermint.RoundRobin,
	Epoch:                 30000,
	BlockPeriod:           1,
	TimeoutPropose:        30 * time.Millisecond,
	TimeoutProposeDelta:   50 * time.Millisecond,
	TimeoutPrevote:        100 * time.Millisecond,
	TimeoutPrevoteDelta:   50 * time.Millisecond,
	TimeoutPrecommit:      100 * time.Millisecond,
	TimeoutPrecommitDelta: 50 * time.Millisecond,
	TimeoutCommit:         100 * time.Millisecond,
	FaultyMode:            tendermint.Disabled.Uint64(),
}

DefaultTestConfig with time is smaller than DefaultConfig for speed-up

Functions

func AppendCommitedSealByPkKeys

func AppendCommitedSealByPkKeys(header *types.Header, pks []*ecdsa.PrivateKey)

func AppendCommittedSeal

func AppendCommittedSeal(header *types.Header, committedSeal []byte)

AppendCommittedSeal

func AppendSeal

func AppendSeal(header *types.Header, be tendermint.Backend)

AppendSeal sign the header with the engine's key and write the seal to the input header's extra data

func AppendSealByPkKey

func AppendSealByPkKey(header *types.Header, pk *ecdsa.PrivateKey)

func GeneratePrivateKey

func GeneratePrivateKey() (*ecdsa.PrivateKey, error)

func GetAddress

func GetAddress() common.Address

func MakeBlockWithSeal

func MakeBlockWithSeal(be tendermint.Backend, pHeader *types.Header) *types.Block

func MakeBlockWithoutSeal

func MakeBlockWithoutSeal(pHeader *types.Header) *types.Block

func MakeGenesisHeader

func MakeGenesisHeader(validators []common.Address) *types.Header

func MakeNodeKey

func MakeNodeKey() *ecdsa.PrivateKey

func MustCreateAndStartNewBackend

func MustCreateAndStartNewBackend(t *testing.T, nodePrivateKey *ecdsa.PrivateKey, genesisHeader *types.Header, validators []common.Address) (tendermint.Backend, *core.TxPool)

func MustCreateStateDB

func MustCreateStateDB(t *testing.T) *state.StateDB

func MustGeneratePrivateKey

func MustGeneratePrivateKey(key string) *ecdsa.PrivateKey

func MustMakeBlockWithCommittedSeal

func MustMakeBlockWithCommittedSeal(be tendermint.Backend, pHeader *types.Header) *types.Block

func MustMakeBlockWithCommittedSealInvalid

func MustMakeBlockWithCommittedSealInvalid(be tendermint.Backend, pHeader *types.Header) *types.Block

func NewHeadersMockChainReader

func NewHeadersMockChainReader(headers []*types.Header) consensus.ChainReader

func NewMockBackend

func NewMockBackend(privateKey *ecdsa.PrivateKey, blockchain *MockChainReader, validators []common.Address) tendermint.Backend

func PrepareExtra

func PrepareExtra(header *types.Header) ([]byte, error)

PrepareExtra returns a extra-data of the given header and validators

Types

type MockBackend

type MockBackend struct {

	// SendEventMux is used for receiving output msg from core
	SendEventMux *event.TypeMux
	// contains filtered or unexported fields
}

func (*MockBackend) Address

func (mb *MockBackend) Address() common.Address

Address implements tendermint.Backend.Address

func (*MockBackend) Broadcast

func (mb *MockBackend) Broadcast(valSet tendermint.ValidatorSet, blockNumber *big.Int, round int64, msgType uint64, payload []byte) error

Broadcast implements tendermint.Backend.Broadcast It sends message to its validator by calling gossiping, and send message to itself by eventMux

func (*MockBackend) Cancel

func (mb *MockBackend) Cancel(block *types.Block)

func (*MockBackend) Commit

func (mb *MockBackend) Commit(block *types.Block)

Commit implement tendermint.Backend.Commit()

func (*MockBackend) CurrentHeadBlock

func (mb *MockBackend) CurrentHeadBlock() *types.Block

func (*MockBackend) EventMux

func (mb *MockBackend) EventMux() *event.TypeMux

EventMux implements tendermint.Backend.EventMux

func (*MockBackend) FindExistingPeers

func (mb *MockBackend) FindExistingPeers(valSet tendermint.ValidatorSet) map[common.Address]consensus.Peer

FindExistingPeers check validator peers exist or not by address

func (*MockBackend) Gossip

func (mb *MockBackend) Gossip(valSet tendermint.ValidatorSet, _ *big.Int, _ int64, _ uint64, payload []byte) error

Gossip implements tendermint.Backend.Gossip It sends message to its validators only, not itself. The validators must be able to connected through Peer. It will return MockBackend.ErrNoBroadcaster if no broadcaster is set for MockBackend

func (*MockBackend) Multicast

func (mb *MockBackend) Multicast(targets map[common.Address]bool, payload []byte) error

Multicast implements tendermint.Backend.Multicast

func (*MockBackend) Sign

func (mb *MockBackend) Sign(data []byte) ([]byte, error)

Sign implements tendermint.Backend.Sign

func (*MockBackend) Validators

func (mb *MockBackend) Validators(blockNumber *big.Int) tendermint.ValidatorSet

Validators return validator set for a block number TODO: revise this function once auth vote is implemented

func (*MockBackend) VerifyProposalBlock

func (mb *MockBackend) VerifyProposalBlock(block *types.Block) error

func (*MockBackend) VerifyProposalHeader

func (mb *MockBackend) VerifyProposalHeader(header *types.Header) error

type MockBlockChain

type MockBlockChain struct {
	Statedb          *state.StateDB
	GasLimit         uint64
	ChainHeadFeed    *event.Feed
	MockCurrentBlock *types.Block
}

MockBlockChain is mock struct for block chain

func (*MockBlockChain) CurrentBlock

func (bc *MockBlockChain) CurrentBlock() *types.Block

func (*MockBlockChain) GetBlock

func (bc *MockBlockChain) GetBlock(hash common.Hash, number uint64) *types.Block

func (*MockBlockChain) StateAt

func (bc *MockBlockChain) StateAt(common.Hash) (*state.StateDB, error)

func (*MockBlockChain) SubscribeChainHeadEvent

func (bc *MockBlockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription

type MockChainReader

type MockChainReader struct {
	GenesisHeader *types.Header
	*MockBlockChain
	Address common.Address
	Trigger *bool
}

MockChainReader is mock struct for chain reader, it serves basic block/ state reading for testing purposes

func (*MockChainReader) Config

func (c *MockChainReader) Config() *params.ChainConfig

func (*MockChainReader) CurrentHeader

func (c *MockChainReader) CurrentHeader() *types.Header

func (*MockChainReader) GetHeader

func (c *MockChainReader) GetHeader(hash common.Hash, blockNumber uint64) *types.Header

GetHeader implement a mock version of chainReader.GetHeader It returns correctParentHeader with Number set to input blockNumber

func (*MockChainReader) GetHeaderByHash

func (c *MockChainReader) GetHeaderByHash(hash common.Hash) *types.Header

func (*MockChainReader) GetHeaderByNumber

func (c *MockChainReader) GetHeaderByNumber(blockNumber uint64) *types.Header

GetHeaderByNumber implement a mock version of chainReader.GetHeaderByNumber It returns genesis Header if blockNumber is 0, else return an empty Header

func (*MockChainReader) State

func (c *MockChainReader) State() (*state.StateDB, error)

State is used multiple times to reset the pending state. when simulate is true it will create a state that indicates that tx0 and tx1 are included in the chain.

type MockPeer

type MockPeer struct {
	SendFn func(data interface{}) error
}

MockPeer implements consensus/protocol/Peers

func (*MockPeer) Address

func (p *MockPeer) Address() common.Address

func (*MockPeer) Send

func (p *MockPeer) Send(msgCode uint64, data interface{}) error

type MockProtocolManager

type MockProtocolManager struct{}

func (*MockProtocolManager) Enqueue

func (pm *MockProtocolManager) Enqueue(id string, block *types.Block)

Enqueue adds a block into fetcher queue

func (*MockProtocolManager) FindPeers

func (pm *MockProtocolManager) FindPeers(targets map[common.Address]bool) map[common.Address]consensus.Peer

FindPeers retrives peers by addresses

type SentMsgEvent

type SentMsgEvent struct {
	Target  common.Address
	Payload []byte
}

SentMsgEvent represents an action send to an peer

Jump to

Keyboard shortcuts

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