note #1 of reading source code of hyperledger fabric

111 阅读1分钟

While reading consensus part of source code of hyperledger fabric, I saw this snippet code below,


//go:generate counterfeiter -o mocks/mock_consenter_support.go . ConsenterSupport

// ConsenterSupport provides the resources available to a Consenter implementation.
type ConsenterSupport interface {
	identity.SignerSerializer
	msgprocessor.Processor

	// VerifyBlockSignature verifies a signature of a block with a given optional
	// configuration (can be nil).
	VerifyBlockSignature([]*protoutil.SignedData, *cb.ConfigEnvelope) error

	// BlockCutter returns the block cutting helper for this channel.
	BlockCutter() blockcutter.Receiver

	// SharedConfig provides the shared config from the channel's current config block.
	SharedConfig() channelconfig.Orderer

	...
	// Height returns the number of blocks in the chain this channel is associated with.
	Height() uint64

	// Append appends a new block to the ledger in its raw form,
	// unlike WriteBlock that also mutates its metadata.
	Append(block *cb.Block) error
}

which located in orderer/consensus/consensus.go. go:generate is used to generate Go files by processing source, when running go generate command in cli, the commented line //go:generate command arg1 arg2... will be executed, of course you can execute command arg1 arg2 directly to accomplish the same functionality.
then what is counterfeiter? counterfeiter is used to automatically generate mock files by processing your defined interface, to lighten you the work of coding about unit test. So next time when you define an interface and want to unit test it, first use counterfeiter to generate fake implementation of the defined interface.