mock

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLostBlock is returned if a block was removed from the cache.
	ErrLostBlock = errors.New("lost block")
)

Functions

func StartMockCoordinatorServiceFromListWithConfig

func StartMockCoordinatorServiceFromListWithConfig(
	t *testing.T,
	coordService *Coordinator,
	sc *connection.ServerConfig,
) *test.GrpcServers

StartMockCoordinatorServiceFromListWithConfig starts a mock coordinator service using the given config.

func StartMockSVServiceFromListWithConfig

func StartMockSVServiceFromListWithConfig(
	t *testing.T, svs []*SigVerifier, sc []*connection.ServerConfig,
) *test.GrpcServers

StartMockSVServiceFromListWithConfig starts a specified number of mock verifier service.

func StartMockVCServiceFromListWithConfig

func StartMockVCServiceFromListWithConfig(
	t *testing.T, vcs []*VcService, sc []*connection.ServerConfig,
) *test.GrpcServers

StartMockVCServiceFromListWithConfig starts a specified number of mock vc service.

Types

type Coordinator

type Coordinator struct {
	protocoordinatorservice.CoordinatorServer
	// contains filtered or unexported fields
}

Coordinator is a mock coordinator.

func NewMockCoordinator

func NewMockCoordinator() *Coordinator

NewMockCoordinator creates a new mock coordinator.

func StartMockCoordinatorService

func StartMockCoordinatorService(t *testing.T) (
	*Coordinator, *test.GrpcServers,
)

StartMockCoordinatorService starts a mock coordinator service and registers cancellation.

func (*Coordinator) BlockProcessing

BlockProcessing processes a block.

func (*Coordinator) GetConfigTransaction

GetConfigTransaction return the latest configuration transaction.

func (*Coordinator) GetLastCommittedBlockNumber

func (c *Coordinator) GetLastCommittedBlockNumber(
	context.Context,
	*emptypb.Empty,
) (*protoblocktx.LastCommittedBlock, error)

GetLastCommittedBlockNumber returns the last committed block number.

func (*Coordinator) GetNextExpectedBlockNumber

func (c *Coordinator) GetNextExpectedBlockNumber(
	context.Context,
	*emptypb.Empty,
) (*protoblocktx.BlockInfo, error)

GetNextExpectedBlockNumber returns the next expected block number to be received by the coordinator.

func (*Coordinator) GetTransactionsStatus

GetTransactionsStatus returns the status of given set of transaction identifiers.

func (*Coordinator) IsStreamActive

func (c *Coordinator) IsStreamActive() bool

IsStreamActive returns true if the stream from the sidecar is active.

func (*Coordinator) NumberOfWaitingTransactionsForStatus

func (c *Coordinator) NumberOfWaitingTransactionsForStatus(
	context.Context,
	*emptypb.Empty,
) (*protocoordinatorservice.WaitingTransactions, error)

NumberOfWaitingTransactionsForStatus returns the number of transactions waiting to get the final status.

func (*Coordinator) RegisterService added in v0.1.5

func (c *Coordinator) RegisterService(server *grpc.Server)

RegisterService registers for the coordinator's GRPC services.

func (*Coordinator) SetConfigTransaction

func (c *Coordinator) SetConfigTransaction(data []byte)

SetConfigTransaction stores the given envelope data as the current config transaction.

func (*Coordinator) SetDelay

func (c *Coordinator) SetDelay(d time.Duration)

SetDelay sets the duration to wait before sending statuses.

func (*Coordinator) SetLastCommittedBlockNumber

func (c *Coordinator) SetLastCommittedBlockNumber(
	_ context.Context, lastBlock *protoblocktx.BlockInfo,
) (*emptypb.Empty, error)

SetLastCommittedBlockNumber sets the last committed block number.

func (*Coordinator) SetWaitingTxsCount

func (c *Coordinator) SetWaitingTxsCount(count int32)

SetWaitingTxsCount sets the waiting transactions count. The purpose of this method is to set the count manually for testing purpose.

type HoldingOrderer

type HoldingOrderer struct {
	*Orderer
	HoldFromBlock atomic.Uint64
}

HoldingOrderer allows holding a block.

func (*HoldingOrderer) Deliver

Deliver calls Orderer.Deliver, but with a holding stream.

func (*HoldingOrderer) RegisterService added in v0.1.5

func (o *HoldingOrderer) RegisterService(server *grpc.Server)

RegisterService registers for the orderer's GRPC services.

func (*HoldingOrderer) Release

func (o *HoldingOrderer) Release()

Release blocks.

type Orderer

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

Orderer supports running multiple mock-orderer services which mocks a consortium.

func NewMockOrderer

func NewMockOrderer(config *OrdererConfig) (*Orderer, error)

NewMockOrderer creates multiple orderer instances.

func StartMockOrderingServices

func StartMockOrderingServices(t *testing.T, conf *OrdererConfig) (
	*Orderer, *test.GrpcServers,
)

StartMockOrderingServices starts a specified number of mock ordering service and register cancellation.

func (*Orderer) Broadcast

func (o *Orderer) Broadcast(stream ab.AtomicBroadcast_BroadcastServer) error

Broadcast receives TXs and returns ACKs.

func (*Orderer) CutBlock

func (o *Orderer) CutBlock(ctx context.Context) bool

CutBlock allows forcing block cut for testing other packages.

func (*Orderer) Deliver

func (o *Orderer) Deliver(stream ab.AtomicBroadcast_DeliverServer) error

Deliver receives a seek request and returns a stream of the orderered blocks.

func (*Orderer) GetBlock

func (o *Orderer) GetBlock(ctx context.Context, blockNum uint64) (*common.Block, error)

GetBlock allows fetching blocks directly for testing other packages.

func (*Orderer) RegisterService added in v0.1.5

func (o *Orderer) RegisterService(server *grpc.Server)

RegisterService registers for the orderer's GRPC services.

func (*Orderer) Run

func (o *Orderer) Run(ctx context.Context) error

Run collects the envelopes, cuts the blocks, and store them to the block cache.

func (*Orderer) SubmitBlock

func (o *Orderer) SubmitBlock(ctx context.Context, b *common.Block) error

SubmitBlock allows submitting blocks directly for testing other packages. The block header will be replaced with a generated header.

func (*Orderer) SubmitEnv

func (o *Orderer) SubmitEnv(ctx context.Context, e *common.Envelope) bool

SubmitEnv allows submitting envelops directly for testing other packages.

func (*Orderer) WaitForReady

func (*Orderer) WaitForReady(context.Context) bool

WaitForReady returns true when we are ready to process GRPC requests.

type OrdererConfig

type OrdererConfig struct {
	// Server and ServerConfigs sets the used serving endpoints.
	// We support both for compatibility with other services.
	Server           *connection.ServerConfig   `mapstructure:"server"`
	ServerConfigs    []*connection.ServerConfig `mapstructure:"servers"`
	NumService       int                        `mapstructure:"num-services"`
	BlockSize        int                        `mapstructure:"block-size"`
	BlockTimeout     time.Duration              `mapstructure:"block-timeout"`
	OutBlockCapacity int                        `mapstructure:"out-block-capacity"`
	PayloadCacheSize int                        `mapstructure:"payload-cache-size"`
	ConfigBlockPath  string                     `mapstructure:"config-block-path"`
	SendConfigBlock  bool                       `mapstructure:"send-config-block"`
}

OrdererConfig configuration for the mock orderer.

type OrdererTestConfig

type OrdererTestConfig struct {
	ChanID                       string
	Config                       *OrdererConfig
	NumFake                      int
	NumHolders                   int
	MetaNamespaceVerificationKey []byte
}

OrdererTestConfig describes the configuration for OrdererTestEnv.

type OrdererTestEnv

type OrdererTestEnv struct {
	Orderer        *Orderer
	Holder         *HoldingOrderer
	OrdererServers *test.GrpcServers
	FakeServers    *test.GrpcServers
	HolderServers  *test.GrpcServers
	TestConfig     *OrdererTestConfig
}

OrdererTestEnv allows starting fake and holder services in addition to the regular mock orderer services.

func NewOrdererTestEnv

func NewOrdererTestEnv(t *testing.T, conf *OrdererTestConfig) *OrdererTestEnv

NewOrdererTestEnv creates and starts a new OrdererTestEnv.

func (*OrdererTestEnv) AllEndpoints

func (e *OrdererTestEnv) AllEndpoints() []*ordererconn.Endpoint

AllEndpoints returns a list of all the endpoints (real, fake, and holders).

func (*OrdererTestEnv) AllFakeEndpoints

func (e *OrdererTestEnv) AllFakeEndpoints() []*ordererconn.Endpoint

AllFakeEndpoints returns a list of the fake orderer endpoints.

func (*OrdererTestEnv) AllHolderEndpoints

func (e *OrdererTestEnv) AllHolderEndpoints() []*ordererconn.Endpoint

AllHolderEndpoints returns a list of the holder orderer endpoints.

func (*OrdererTestEnv) AllRealOrdererEndpoints

func (e *OrdererTestEnv) AllRealOrdererEndpoints() []*ordererconn.Endpoint

AllRealOrdererEndpoints returns a list of the real orderer endpoints.

func (*OrdererTestEnv) SubmitConfigBlock

func (e *OrdererTestEnv) SubmitConfigBlock(t *testing.T, conf *workload.ConfigBlock) *common.Block

SubmitConfigBlock creates and submits a config block.

type SigVerifier

type SigVerifier struct {
	protosigverifierservice.UnimplementedVerifierServer

	// MockFaultyNodeDropSize allows mocking a faulty node by dropping some TXs.
	MockFaultyNodeDropSize int
	// contains filtered or unexported fields
}

SigVerifier is a mock implementation of the protosignverifierservice.VerifierServer. SigVerifier marks valid and invalid flag as follows: - when the tx has empty signature, it is invalid. - when the tx has non-empty signature, it is valid.

func NewMockSigVerifier

func NewMockSigVerifier() *SigVerifier

NewMockSigVerifier returns a new mock verifier.

func StartMockSVService

func StartMockSVService(t *testing.T, numService int) (
	[]*SigVerifier, *test.GrpcServers,
)

StartMockSVService starts a specified number of mock verifier service and register cancellation.

func (*SigVerifier) ClearPolicies

func (m *SigVerifier) ClearPolicies()

ClearPolicies allows resetting the known policies to mimic a new instance.

func (*SigVerifier) GetNumBlocksReceived

func (m *SigVerifier) GetNumBlocksReceived() uint32

GetNumBlocksReceived returns the number of blocks received by the mock verifier.

func (*SigVerifier) GetPolicyUpdateCounter

func (m *SigVerifier) GetPolicyUpdateCounter() uint64

GetPolicyUpdateCounter returns the number of policy updates to check progress.

func (*SigVerifier) GetUpdates

func (m *SigVerifier) GetUpdates() []*protosigverifierservice.Update

GetUpdates returns the updates received.

func (*SigVerifier) RegisterService added in v0.1.5

func (m *SigVerifier) RegisterService(server *grpc.Server)

RegisterService registers for the verifier's GRPC services.

func (*SigVerifier) SendRequestBatchWithoutStream

func (m *SigVerifier) SendRequestBatchWithoutStream(
	ctx context.Context,
	requestBatch *protosigverifierservice.Batch,
) bool

SendRequestBatchWithoutStream allows the caller to bypass the stream to send a request batch. Returns true if successful.

func (*SigVerifier) SetReturnErrorForUpdatePolicies

func (m *SigVerifier) SetReturnErrorForUpdatePolicies(setError bool)

SetReturnErrorForUpdatePolicies configures the SigVerifier to return an error during policy updates. When setError is true, the verifier will signal an error during the update policies process. It is a one time event, after which the flag will return to false.

func (*SigVerifier) StartStream

StartStream is a mock implementation of the [protosignverifierservice.VerifierServer].

type VcService

type VcService struct {
	protovcservice.ValidationAndCommitServiceServer

	// MockFaultyNodeDropSize allows mocking a faulty node by dropping some TXs.
	MockFaultyNodeDropSize int
	// contains filtered or unexported fields
}

VcService implements the protovcservice.ValidationAndCommitServiceServer interface. It is used for testing the client which is the coordinator service.

func NewMockVcService

func NewMockVcService() *VcService

NewMockVcService returns a new VcService.

func StartMockVCService

func StartMockVCService(t *testing.T, numService int) (
	[]*VcService, *test.GrpcServers,
)

StartMockVCService starts a specified number of mock VC service and register cancellation.

func (*VcService) GetConfigTransaction

func (*VcService) GetConfigTransaction(
	context.Context,
	*emptypb.Empty,
) (*protoblocktx.ConfigTransaction, error)

GetConfigTransaction is a mock implementation of the protovcservice.GetConfigTransaction.

func (*VcService) GetLastCommittedBlockNumber

func (v *VcService) GetLastCommittedBlockNumber(
	context.Context,
	*emptypb.Empty,
) (*protoblocktx.LastCommittedBlock, error)

GetLastCommittedBlockNumber get the last committed block number in the database/ledger.

func (*VcService) GetNamespacePolicies

func (*VcService) GetNamespacePolicies(
	context.Context,
	*emptypb.Empty,
) (*protoblocktx.NamespacePolicies, error)

GetNamespacePolicies is a mock implementation of the protovcservice.GetNamespacePolicies.

func (*VcService) GetNumBatchesReceived

func (v *VcService) GetNumBatchesReceived() uint32

GetNumBatchesReceived returns the number of batches received by VcService.

func (*VcService) GetTransactionsStatus

func (v *VcService) GetTransactionsStatus(
	_ context.Context,
	query *protoblocktx.QueryStatus,
) (*protoblocktx.TransactionsStatus, error)

GetTransactionsStatus get the status for a given set of transactions IDs.

func (*VcService) RegisterService added in v0.1.5

func (v *VcService) RegisterService(server *grpc.Server)

RegisterService registers for the validator-committer's GRPC services.

func (*VcService) SetLastCommittedBlockNumber

func (v *VcService) SetLastCommittedBlockNumber(
	_ context.Context,
	lastBlock *protoblocktx.BlockInfo,
) (*emptypb.Empty, error)

SetLastCommittedBlockNumber set the last committed block number in the database/ledger.

func (*VcService) SetupSystemTablesAndNamespaces

func (*VcService) SetupSystemTablesAndNamespaces(
	context.Context,
	*emptypb.Empty,
) (*emptypb.Empty, error)

SetupSystemTablesAndNamespaces creates the required system tables and namespaces.

func (*VcService) StartValidateAndCommitStream

StartValidateAndCommitStream is the mock implementation of the protovcservice.ValidationAndCommitServiceServer interface.

func (*VcService) SubmitTransactions

func (v *VcService) SubmitTransactions(ctx context.Context, txsBatch *protovcservice.Batch)

SubmitTransactions enqueues the given transactions to a queue read by status sending goroutine. This methods helps the test code to bypass the stream to submit transactions to the mock vcservice.

Jump to

Keyboard shortcuts

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