testframework

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package testframework is consensus test framework

Index

Constants

This section is empty.

Variables

View Source
var (

	// BlockchainId block chain id
	BlockchainId = "chain1"
	// NodeNums default node Nums
	NodeNums = 4
	// CoreEngines core engines
	CoreEngines = []protocol.CoreEngine{}
	// ListenAddrs listen addrs
	ListenAddrs = []string{
		"/ip4/0.0.0.0/tcp/11301",
		"/ip4/0.0.0.0/tcp/11302",
		"/ip4/0.0.0.0/tcp/11303",
		"/ip4/0.0.0.0/tcp/11304",
	}
	// Seeds seeds
	Seeds = []string{
		"/ip4/127.0.0.1/tcp/11301/p2p/QmV9wyvnGXtKauR2MV4bLndwfS4hnHkN6RhXMmEyLyRwqq",
		"/ip4/127.0.0.1/tcp/11302/p2p/QmYjXpS5RtSiScjJVxzJNUo2XdfDbSoE1BaaSQG2BWLhej",
		"/ip4/127.0.0.1/tcp/11303/p2p/QmYhNgL59EQriiojax98a8HQnB4DPqdN44eRy3RCdgbNPn",
		"/ip4/127.0.0.1/tcp/11304/p2p/Qmd6RRKw83sQrf4oZJEhuhouz48eu9BT1nLKNGqKcpD6LL",
	}
)

Functions

func ConsensusTypeFromInt

func ConsensusTypeFromInt(configType int32) (consensusPb.ConsensusType, error)

ConsensusTypeFromInt 将配置文件int类型转化为ConsensusType类型

func GetBlockFromMockCache

func GetBlockFromMockCache(blockHash string, height uint64) *common.Block

GetBlockFromMockCache 从Mock的Block缓存中获取Block

func InConsensusSlice

func InConsensusSlice(need consensus.ConsensusType, typeArr []consensus.ConsensusType) bool

InConsensusSlice 判断共识类型是否在列表内

func InitChainConfig

func InitChainConfig(chainId string, consensusType consensusPb.ConsensusType, nodeNum int) *configPb.ChainConfig

InitChainConfig init chain config

func InitLocalConfig

func InitLocalConfig(nodeNum int)

InitLocalConfig init local config

func InitLocalConfigs

func InitLocalConfigs() error

InitLocalConfigs init local configs

func NewCache

func NewCache(chainId string) protocol.LedgerCache

NewCache NewLedgerCache get a ledger cache. One ledger cache for one chain.

func NewNet

func NewNet(keyPath, certPath string, config *TestNodeConfig) (protocol.Net, error)

NewNet create protocol.Net

func NewNetService

func NewNetService(net protocol.Net,
	chainId string,
	ac protocol.AccessControlProvider,
	chainConf protocol.ChainConf,
	msgBus msgbus.MessageBus) (protocol.NetService, error)

NewNetService create protocol.NetService

func NewNetServiceForTest

func NewNetServiceForTest() protocol.NetService

NewNetServiceForTest new net service

func NewProposalCache

func NewProposalCache(chainConf protocol.ChainConf, ledgerCache protocol.LedgerCache) protocol.ProposalCache

NewProposalCache get a ProposalCache. One ProposalCache for one chain.

func RemoveLocalConfigs

func RemoveLocalConfigs()

RemoveLocalConfigs remove configs

func SetBlockToMockCache

func SetBlockToMockCache(block *common.Block, blockHash string, height uint64)

SetBlockToMockCache 将Block缓存到Mock缓存中

func SetTxSizeAndTxNum

func SetTxSizeAndTxNum(size, num int)

SetTxSizeAndTxNum set tx size and tx num

Types

type Cache

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

Cache is used for cache current block info

func (*Cache) CurrentHeight

func (c *Cache) CurrentHeight() (uint64, error)

CurrentHeight get current block height

func (*Cache) GetLastCommittedBlock

func (c *Cache) GetLastCommittedBlock() *commonPb.Block

GetLastCommittedBlock get the latest committed block

func (*Cache) SetLastCommittedBlock

func (c *Cache) SetLastCommittedBlock(b *commonPb.Block)

SetLastCommittedBlock set the latest committed block

type ChainConfImplForTest

type ChainConfImplForTest struct {
	ChainConf *configPb.ChainConfig
	// contains filtered or unexported fields
}

ChainConfImplForTest chain config impl

func (*ChainConfImplForTest) AddVmWatch

func (cc *ChainConfImplForTest) AddVmWatch(w protocol.VmWatcher)

AddVmWatch add vm watcher

func (*ChainConfImplForTest) AddWatch

func (cc *ChainConfImplForTest) AddWatch(w protocol.Watcher)

AddWatch add watcher

func (*ChainConfImplForTest) ChainConfig

func (cc *ChainConfImplForTest) ChainConfig() *configPb.ChainConfig

ChainConfig get chain config

func (*ChainConfImplForTest) CompleteBlock

func (cc *ChainConfImplForTest) CompleteBlock(block *commonPb.Block) error

CompleteBlock complete block

func (*ChainConfImplForTest) GetChainConfigAt

func (cc *ChainConfImplForTest) GetChainConfigAt(blockHeight uint64) (*configPb.ChainConfig, error)

GetChainConfigAt get chain config at

func (*ChainConfImplForTest) GetChainConfigFromFuture

func (cc *ChainConfImplForTest) GetChainConfigFromFuture(blockHeight uint64) (*configPb.ChainConfig, error)

GetChainConfigFromFuture get chainconfig

func (*ChainConfImplForTest) GetConsensusNodeIdList

func (cc *ChainConfImplForTest) GetConsensusNodeIdList() ([]string, error)

GetConsensusNodeIdList get consensus node id list

func (*ChainConfImplForTest) Init

func (cc *ChainConfImplForTest) Init() error

Init init

func (*ChainConfImplForTest) SetChainConfig

func (cc *ChainConfImplForTest) SetChainConfig(chainConf *configPb.ChainConfig) error

SetChainConfig set new chainconfig

type ClusterTestNode

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

ClusterTestNode struct

func NewClusterTestNode

func NewClusterTestNode(
	consensusType consensusPb.ConsensusType,
	config *TestNodeConfig,
	ce protocol.ConsensusEngine,
	core protocol.CoreEngine,
	tf *TestClusterFramework) (*ClusterTestNode, error)

NewClusterTestNode for cluster mode

func (*ClusterTestNode) Start

func (tn *ClusterTestNode) Start()

Start ClusterTestNode

func (*ClusterTestNode) Stop

func (tn *ClusterTestNode) Stop()

Stop ClusterTestNode

type ConfigData

type ConfigData struct {
	Path string
	Data string
}

ConfigData config data struct

type ConsensusArgs

type ConsensusArgs func(cfg *configPb.ChainConfig) []byte

ConsensusArgs epoch configuration of maxbft consensus is generated from the chainConfig and serialized content is returned, while the registrar can also customize the incoming chain configuration

type CoreEngineForTest

type CoreEngineForTest struct {
	sync.Mutex
	// contains filtered or unexported fields
}

CoreEngineForTest struct

func NewCoreEngineForTest

func NewCoreEngineForTest(tnc *TestNodeConfig, log protocol.Logger) *CoreEngineForTest

NewCoreEngineForTest new core engine

func (*CoreEngineForTest) CalcTime

func (ce *CoreEngineForTest) CalcTime()

CalcTime for engine

func (*CoreEngineForTest) CalcTimeForMaxbft

func (ce *CoreEngineForTest) CalcTimeForMaxbft()

CalcTimeForMaxbft statistics on maxbft performance indicators

func (*CoreEngineForTest) GetBlockCommitter

func (ce *CoreEngineForTest) GetBlockCommitter() protocol.BlockCommitter

GetBlockCommitter get block committer

func (*CoreEngineForTest) GetBlockProposer

func (ce *CoreEngineForTest) GetBlockProposer() protocol.BlockProposer

GetBlockProposer func

func (*CoreEngineForTest) GetBlockVerifier

func (ce *CoreEngineForTest) GetBlockVerifier() protocol.BlockVerifier

GetBlockVerifier get block verifier

func (*CoreEngineForTest) GetMaxbftHelper

func (ce *CoreEngineForTest) GetMaxbftHelper() protocol.MaxbftHelper

GetMaxbftHelper maxbft helper

func (*CoreEngineForTest) OnMessage

func (ce *CoreEngineForTest) OnMessage(message *msgbus.Message)

OnMessage message buss

func (*CoreEngineForTest) OnQuit

func (ce *CoreEngineForTest) OnQuit()

OnQuit on quit

func (*CoreEngineForTest) Start

func (ce *CoreEngineForTest) Start()

Start core engine

func (*CoreEngineForTest) Stop

func (ce *CoreEngineForTest) Stop()

Stop core engine

type MaxbftHelper

type MaxbftHelper struct{}

MaxbftHelper struct

func (*MaxbftHelper) DiscardBlocks

func (mh *MaxbftHelper) DiscardBlocks(baseHeight uint64)

DiscardBlocks DiscardAboveHeight

type NetEngineForTest

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

NetEngineForTest struct

func NewNetEngineForTest

func NewNetEngineForTest(chainId, nodeId string,
	msgBus msgbus.MessageBus, tf *TestClusterFramework, log protocol.Logger) *NetEngineForTest

NewNetEngineForTest new net engine

func (*NetEngineForTest) OnMessage

func (ne *NetEngineForTest) OnMessage(message *msgbus.Message)

OnMessage NetEngineForTest

func (*NetEngineForTest) OnQuit

func (ne *NetEngineForTest) OnQuit()

OnQuit NetEngineForTest

func (*NetEngineForTest) Start

func (ne *NetEngineForTest) Start()

Start engine

func (*NetEngineForTest) Stop

func (ne *NetEngineForTest) Stop()

Stop engine

type ProposalCache

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

ProposalCache is used for cache proposal blocks

func (*ProposalCache) ClearProposedBlockAt

func (pc *ProposalCache) ClearProposedBlockAt(height uint64)

ClearProposedBlockAt clear proposed blocks with height.

func (*ProposalCache) ClearTheBlock

func (pc *ProposalCache) ClearTheBlock(block *commonpb.Block)

ClearTheBlock f

func (*ProposalCache) DiscardBlocks

func (pc *ProposalCache) DiscardBlocks(baseHeight uint64) []*commonpb.Block

DiscardBlocks DiscardAboveHeight

func (*ProposalCache) GetProposedBlock

func (pc *ProposalCache) GetProposedBlock(b *commonpb.Block) (
	*commonpb.Block, map[string]*commonpb.TxRWSet, map[string][]*commonpb.ContractEvent)

GetProposedBlock get proposed block with specific block hash in current consensus height.

func (*ProposalCache) GetProposedBlockByHashAndHeight

func (pc *ProposalCache) GetProposedBlockByHashAndHeight(hash []byte, height uint64) (
	*commonpb.Block, map[string]*commonpb.TxRWSet)

GetProposedBlockByHashAndHeight get proposed block by block hash and block height.

func (*ProposalCache) GetProposedBlocksAt

func (pc *ProposalCache) GetProposedBlocksAt(height uint64) []*commonpb.Block

GetProposedBlocksAt get all proposed blocks at a specific height. It is possible that generate several proposal blocks in one height because of some unpredictable situation of consensus.

func (*ProposalCache) GetSelfProposedBlockAt

func (pc *ProposalCache) GetSelfProposedBlockAt(height uint64) *commonpb.Block

GetSelfProposedBlockAt get proposed block that is proposed by node itself.

func (*ProposalCache) HasProposedBlockAt

func (pc *ProposalCache) HasProposedBlockAt(height uint64) bool

HasProposedBlockAt return if a proposed block has cached in current consensus height.

func (*ProposalCache) IsProposedAt

func (pc *ProposalCache) IsProposedAt(height uint64) bool

IsProposedAt return if this node has proposed a block as proposer.

func (*ProposalCache) KeepProposedBlock

func (pc *ProposalCache) KeepProposedBlock(hash []byte, height uint64) []*commonpb.Block

KeepProposedBlock Remove proposed block in height except the specific block.

func (*ProposalCache) ResetProposedAt

func (pc *ProposalCache) ResetProposedAt(height uint64)

ResetProposedAt reset propose status of this node.

func (*ProposalCache) SetProposedAt

func (pc *ProposalCache) SetProposedAt(height uint64)

SetProposedAt to mark this node has proposed a block as proposer.

func (*ProposalCache) SetProposedBlock

func (pc *ProposalCache) SetProposedBlock(b *commonpb.Block, rwSetMap map[string]*commonpb.TxRWSet,
	contractEventMap map[string][]*commonpb.ContractEvent, selfPropose bool) error

SetProposedBlock set porposed block in current consensus height, after it's generated or verified.

type ProposerForTest

type ProposerForTest struct {
	protocol.BlockProposer // only used for placeholder
	// contains filtered or unexported fields
}

ProposerForTest propose block for maxbft

func (*ProposerForTest) ProposeBlock

func (p *ProposerForTest) ProposeBlock(proposal *maxbft.BuildProposal) (*consensusPb.ProposalBlock, error)

ProposeBlock propose block

type TestClusterFramework

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

TestClusterFramework struct

func NewTestClusterFramework

func NewTestClusterFramework(chainId string, consensusType consensusPb.ConsensusType,
	nodeNum int, tnc []*TestNodeConfig, consensusEngines []protocol.ConsensusEngine,
	coreEngines []protocol.CoreEngine) (*TestClusterFramework, error)

NewTestClusterFramework new cluster framework

func (*TestClusterFramework) Start

func (tf *TestClusterFramework) Start()

Start framework

func (*TestClusterFramework) Stop

func (tf *TestClusterFramework) Stop()

Stop framework

type TestFramework

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

TestFramework struct

func NewTestFramework

func NewTestFramework(chainId string, index int, consensusType consensusPb.ConsensusType, tnc *TestNodeConfig,
	consensusEngines protocol.ConsensusEngine, coreEngine protocol.CoreEngine) (*TestFramework, error)

NewTestFramework new framework

func (*TestFramework) Start

func (tf *TestFramework) Start()

Start testFramework

func (*TestFramework) Stop

func (tf *TestFramework) Stop()

Stop testFramework

type TestNode

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

TestNode struct

func NewTestNode

func NewTestNode(consensusType consensusPb.ConsensusType, config *TestNodeConfig,
	ce protocol.ConsensusEngine, core protocol.CoreEngine) (*TestNode, error)

NewTestNode new test node

func (*TestNode) Start

func (tn *TestNode) Start()

Start TestNode

func (*TestNode) Stop

func (tn *TestNode) Stop()

Stop TestNode

type TestNodeConfig

type TestNodeConfig struct {
	ChainID         string
	NodeId          string
	ConsensusType   consensusPb.ConsensusType
	GenesisBlock    *commonPb.Block
	Signer          protocol.SigningMember
	Ac              protocol.AccessControlProvider
	LedgerCache     protocol.LedgerCache
	ChainConf       protocol.ChainConf
	MsgBus          msgbus.MessageBus
	BlockchainStore protocol.BlockchainStore
	ProposalCache   protocol.ProposalCache
	ListenAddr      string
	Seeds           []string
	Log             protocol.Logger
}

TestNodeConfig Test Node Config

func CreateTestNodeConfig

func CreateTestNodeConfig(ctrl *gomock.Controller, chainId string, consensusType consensus.ConsensusType,
	nodeNums int, listenAddrs, seeds []string, fn ConsensusArgs) ([]*TestNodeConfig, error)

CreateTestNodeConfig create config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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