Documentation ¶
Overview ¶
Package testframework is consensus test framework
Index ¶
- Variables
- func ConsensusTypeFromInt(configType int32) (consensusPb.ConsensusType, error)
- func GetBlockFromMockCache(blockHash string, height uint64) *common.Block
- func InConsensusSlice(need consensus.ConsensusType, typeArr []consensus.ConsensusType) bool
- func InitChainConfig(chainId string, consensusType consensusPb.ConsensusType, nodeNum int) *configPb.ChainConfig
- func InitLocalConfig(nodeNum int)
- func InitLocalConfigs() error
- func NewCache(chainId string) protocol.LedgerCache
- func NewNet(keyPath, certPath string, config *TestNodeConfig) (protocol.Net, error)
- func NewNetService(net protocol.Net, chainId string, ac protocol.AccessControlProvider, ...) (protocol.NetService, error)
- func NewNetServiceForTest() protocol.NetService
- func NewProposalCache(chainConf protocol.ChainConf, ledgerCache protocol.LedgerCache) protocol.ProposalCache
- func RemoveLocalConfigs()
- func SetBlockToMockCache(block *common.Block, blockHash string, height uint64)
- func SetTxSizeAndTxNum(size, num int)
- type Cache
- type ChainConfImplForTest
- func (cc *ChainConfImplForTest) AddVmWatch(w protocol.VmWatcher)
- func (cc *ChainConfImplForTest) AddWatch(w protocol.Watcher)
- func (cc *ChainConfImplForTest) ChainConfig() *configPb.ChainConfig
- func (cc *ChainConfImplForTest) CompleteBlock(block *commonPb.Block) error
- func (cc *ChainConfImplForTest) GetChainConfigAt(blockHeight uint64) (*configPb.ChainConfig, error)
- func (cc *ChainConfImplForTest) GetChainConfigFromFuture(blockHeight uint64) (*configPb.ChainConfig, error)
- func (cc *ChainConfImplForTest) GetConsensusNodeIdList() ([]string, error)
- func (cc *ChainConfImplForTest) Init() error
- func (cc *ChainConfImplForTest) SetChainConfig(chainConf *configPb.ChainConfig) error
- type ClusterTestNode
- type ConfigData
- type CoreEngineForTest
- func (ce *CoreEngineForTest) CalcTime()
- func (ce *CoreEngineForTest) GetBlockCommitter() protocol.BlockCommitter
- func (ce *CoreEngineForTest) GetBlockProposer() protocol.BlockProposer
- func (ce *CoreEngineForTest) GetBlockVerifier() protocol.BlockVerifier
- func (ce *CoreEngineForTest) GetHotStuffHelper() protocol.MaxbftHelper
- func (ce *CoreEngineForTest) GetMaxbftHelper() protocol.MaxbftHelper
- func (ce *CoreEngineForTest) OnMessage(message *msgbus.Message)
- func (ce *CoreEngineForTest) OnQuit()
- func (ce *CoreEngineForTest) Start()
- func (ce *CoreEngineForTest) Stop()
- type GetConsensusArg
- type MaxbftHelper
- type NetEngineForTest
- type ProposalCache
- func (pc *ProposalCache) ClearProposedBlockAt(height uint64)
- func (pc *ProposalCache) ClearTheBlock(block *commonpb.Block)
- func (pc *ProposalCache) DiscardBlocks(baseHeight uint64) []*commonpb.Block
- func (pc *ProposalCache) GetProposedBlock(b *commonpb.Block) (*commonpb.Block, map[string]*commonpb.TxRWSet, ...)
- func (pc *ProposalCache) GetProposedBlockByHashAndHeight(hash []byte, height uint64) (*commonpb.Block, map[string]*commonpb.TxRWSet)
- func (pc *ProposalCache) GetProposedBlocksAt(height uint64) []*commonpb.Block
- func (pc *ProposalCache) GetSelfProposedBlockAt(height uint64) *commonpb.Block
- func (pc *ProposalCache) HasProposedBlockAt(height uint64) bool
- func (pc *ProposalCache) IsProposedAt(height uint64) bool
- func (pc *ProposalCache) KeepProposedBlock(hash []byte, height uint64) []*commonpb.Block
- func (pc *ProposalCache) ResetProposedAt(height uint64)
- func (pc *ProposalCache) SetProposedAt(height uint64)
- func (pc *ProposalCache) SetProposedBlock(b *commonpb.Block, rwSetMap map[string]*commonpb.TxRWSet, ...) error
- type TestClusterFramework
- type TestFramework
- type TestNode
- type TestNodeConfig
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 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 SetBlockToMockCache ¶
SetBlockToMockCache 将Block缓存到Mock缓存中
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is used for cache current block info
func (*Cache) CurrentHeight ¶
CurrentHeight get current block height
func (*Cache) GetLastCommittedBlock ¶
GetLastCommittedBlock get 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) SetChainConfig ¶ added in v2.3.3
func (cc *ChainConfImplForTest) SetChainConfig(chainConf *configPb.ChainConfig) error
SetChainConfig set new chain config
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
type CoreEngineForTest ¶
CoreEngineForTest struct
func NewCoreEngineForTest ¶
func NewCoreEngineForTest(tnc *TestNodeConfig, log protocol.Logger) *CoreEngineForTest
NewCoreEngineForTest new core engine
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) GetHotStuffHelper ¶
func (ce *CoreEngineForTest) GetHotStuffHelper() protocol.MaxbftHelper
GetHotStuffHelper get hotStuff helper
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
type GetConsensusArg ¶
type GetConsensusArg func(cfg *configPb.ChainConfig) []byte
GetConsensusArg func
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) *NetEngineForTest
NewNetEngineForTest new net engine
func (*NetEngineForTest) OnMessage ¶
func (ne *NetEngineForTest) OnMessage(message *msgbus.Message)
OnMessage NetEngineForTest
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 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
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
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
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 }
TestNodeConfig Test Node Config
func CreateTestNodeConfig ¶
func CreateTestNodeConfig(ctrl *gomock.Controller, chainId string, consensusType consensus.ConsensusType, nodeNums int, listenAddrs, seeds []string, fn GetConsensusArg) ([]*TestNodeConfig, error)
CreateTestNodeConfig create config