mock

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMockMarshalizer = errors.New("MarshalizerMock generic error")

ErrMockMarshalizer -

View Source
var ErrNilObjectToMarshal = errors.New("nil object to serialize from")

ErrNilObjectToMarshal -

Functions

This section is empty.

Types

type AlarmSchedulerStub

type AlarmSchedulerStub struct {
	AddCalled    func(func(alarmID string), time.Duration, string)
	CancelCalled func(string)
	CloseCalled  func()
	ResetCalled  func(string)
}

func (*AlarmSchedulerStub) Add

func (a *AlarmSchedulerStub) Add(callback func(alarmID string), duration time.Duration, alarmID string)

Add -

func (*AlarmSchedulerStub) Cancel

func (a *AlarmSchedulerStub) Cancel(alarmID string)

Cancel -

func (*AlarmSchedulerStub) Close

func (a *AlarmSchedulerStub) Close()

Close -

func (*AlarmSchedulerStub) IsInterfaceNil

func (a *AlarmSchedulerStub) IsInterfaceNil() bool

IsInterfaceNil -

func (*AlarmSchedulerStub) Reset

func (a *AlarmSchedulerStub) Reset(alarmID string)

Reset -

type AppStatusHandlerStub

type AppStatusHandlerStub struct {
	AddUint64Handler      func(key string, value uint64)
	IncrementHandler      func(key string)
	DecrementHandler      func(key string)
	SetUInt64ValueHandler func(key string, value uint64)
	SetInt64ValueHandler  func(key string, value int64)
	SetStringValueHandler func(key string, value string)
	CloseHandler          func()
}

AppStatusHandlerStub is a stub implementation of AppStatusHandler

func (*AppStatusHandlerStub) AddUint64

func (ashs *AppStatusHandlerStub) AddUint64(key string, value uint64)

AddUint64 will call the handler of the stub for incrementing

func (*AppStatusHandlerStub) Close

func (ashs *AppStatusHandlerStub) Close()

Close will call the handler of the stub for closing

func (*AppStatusHandlerStub) Decrement

func (ashs *AppStatusHandlerStub) Decrement(key string)

Decrement will call the handler of the stub for decrementing

func (*AppStatusHandlerStub) Increment

func (ashs *AppStatusHandlerStub) Increment(key string)

Increment will call the handler of the stub for incrementing

func (*AppStatusHandlerStub) IsInterfaceNil

func (ashs *AppStatusHandlerStub) IsInterfaceNil() bool

IsInterfaceNil -

func (*AppStatusHandlerStub) SetInt64Value

func (ashs *AppStatusHandlerStub) SetInt64Value(key string, value int64)

SetInt64Value will call the handler of the stub for setting an int64 value

func (*AppStatusHandlerStub) SetStringValue

func (ashs *AppStatusHandlerStub) SetStringValue(key string, value string)

SetStringValue will call the handler of the stub for setting an string value

func (*AppStatusHandlerStub) SetUInt64Value

func (ashs *AppStatusHandlerStub) SetUInt64Value(key string, value uint64)

SetUInt64Value will call the handler of the stub for setting an uint64 value

type ChainStorerMock

type ChainStorerMock struct {
	AddStorerCalled func(key dataRetriever.UnitType, s storage.Storer)
	GetStorerCalled func(unitType dataRetriever.UnitType) storage.Storer
	HasCalled       func(unitType dataRetriever.UnitType, key []byte) (bool, error)
	GetCalled       func(unitType dataRetriever.UnitType, key []byte) ([]byte, error)
	PutCalled       func(unitType dataRetriever.UnitType, key []byte, value []byte) error
	GetAllCalled    func(unitType dataRetriever.UnitType, keys [][]byte) (map[string][]byte, error)
	DestroyCalled   func() error
}

ChainStorerMock is a mock implementation of the ChainStorer interface

func (*ChainStorerMock) AddStorer

func (bc *ChainStorerMock) AddStorer(key dataRetriever.UnitType, s storage.Storer)

AddStorer will add a new storer to the chain map

func (*ChainStorerMock) Destroy

func (bc *ChainStorerMock) Destroy() error

Destroy removes the underlying files/resources used by the storage service

func (*ChainStorerMock) Get

func (bc *ChainStorerMock) Get(unitType dataRetriever.UnitType, key []byte) ([]byte, error)

Get returns the value for the given key if found in the selected storage unit, nil otherwise. It can return an error if the provided unit type is not supported or if the storage unit underlying implementation reports an error

func (*ChainStorerMock) GetAll

func (bc *ChainStorerMock) GetAll(unitType dataRetriever.UnitType, keys [][]byte) (map[string][]byte, error)

GetAll gets all the elements with keys in the keys array, from the selected storage unit It can report an error if the provided unit type is not supported, if there is a missing key in the unit, or if the underlying implementation of the storage unit reports an error.

func (*ChainStorerMock) GetStorer

func (bc *ChainStorerMock) GetStorer(unitType dataRetriever.UnitType) storage.Storer

GetStorer returns the storer from the chain map or nil if the storer was not found

func (*ChainStorerMock) Has

func (bc *ChainStorerMock) Has(unitType dataRetriever.UnitType, key []byte) (bool, error)

Has returns true if the key is found in the selected Unit or false otherwise It can return an error if the provided unit type is not supported or if the underlying implementation of the storage unit reports an error.

func (*ChainStorerMock) Put

func (bc *ChainStorerMock) Put(unitType dataRetriever.UnitType, key []byte, value []byte) error

Put stores the key, value pair in the selected storage unit It can return an error if the provided unit type is not supported or if the storage unit underlying implementation reports an error

type ConnectedAddressesMock

type ConnectedAddressesMock struct {
}

ConnectedAddressesMock represents a mock implementation of the ConnectedAddresses

func (*ConnectedAddressesMock) ConnectedAddresses

func (cam *ConnectedAddressesMock) ConnectedAddresses() []string

ConnectedAddresses returns an empty slice of string

type DatabaseWriterStub

type DatabaseWriterStub struct {
	DoRequestCalled     func(req *esapi.IndexRequest) error
	DoBulkRequestCalled func(buff *bytes.Buffer, index string) error
}

DatabaseWriterStub --

func (*DatabaseWriterStub) CheckAndCreateIndex

func (dwm *DatabaseWriterStub) CheckAndCreateIndex(_ string, _ io.Reader) error

CheckAndCreateIndex --

func (*DatabaseWriterStub) DoBulkRequest

func (dwm *DatabaseWriterStub) DoBulkRequest(buff *bytes.Buffer, index string) error

DoBulkRequest --

func (*DatabaseWriterStub) DoMultiGet

func (dwm *DatabaseWriterStub) DoMultiGet(_ map[string]interface{}, _ string) (map[string]interface{}, error)

DoMultiGet --

func (*DatabaseWriterStub) DoRequest

func (dwm *DatabaseWriterStub) DoRequest(req *esapi.IndexRequest) error

DoRequest --

type EpochStartNotifierStub

type EpochStartNotifierStub struct {
	RegisterHandlerCalled   func(handler epochStart.ActionHandler)
	UnregisterHandlerCalled func(handler epochStart.ActionHandler)
	NotifyAllCalled         func(hdr data.HeaderHandler)
	NotifyAllPrepareCalled  func(hdr data.HeaderHandler)
	// contains filtered or unexported fields
}

EpochStartNotifierStub -

func (*EpochStartNotifierStub) IsInterfaceNil

func (esnm *EpochStartNotifierStub) IsInterfaceNil() bool

IsInterfaceNil -

func (*EpochStartNotifierStub) NotifyAll

func (esnm *EpochStartNotifierStub) NotifyAll(hdr data.HeaderHandler)

NotifyAll -

func (*EpochStartNotifierStub) NotifyAllPrepare

func (esnm *EpochStartNotifierStub) NotifyAllPrepare(metaHeader data.HeaderHandler, body data.BodyHandler)

NotifyAllPrepare -

func (*EpochStartNotifierStub) RegisterHandler

func (esnm *EpochStartNotifierStub) RegisterHandler(handler epochStart.ActionHandler)

RegisterHandler -

func (*EpochStartNotifierStub) UnregisterHandler

func (esnm *EpochStartNotifierStub) UnregisterHandler(handler epochStart.ActionHandler)

UnregisterHandler -

type HasherMock

type HasherMock struct {
}

HasherMock that will be used for testing

func (HasherMock) Compute

func (sha HasherMock) Compute(s string) []byte

Compute will output the SHA's equivalent of the input string

func (HasherMock) EmptyHash

func (sha HasherMock) EmptyHash() []byte

EmptyHash will return the equivalent of empty string SHA's

func (HasherMock) IsInterfaceNil

func (sha HasherMock) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (HasherMock) Size

func (HasherMock) Size() int

Size returns the required size in bytes

type IntRandomizerStub

type IntRandomizerStub struct {
	IntnCalled func(n int) int
}

IntRandomizerStub -

func (*IntRandomizerStub) Intn

func (irs *IntRandomizerStub) Intn(n int) int

Intn -

func (*IntRandomizerStub) IsInterfaceNil

func (irs *IntRandomizerStub) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

type MarshalizerMock

type MarshalizerMock struct {
	Fail bool
}

MarshalizerMock that will be used for testing

func (*MarshalizerMock) IsInterfaceNil

func (mm *MarshalizerMock) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*MarshalizerMock) Marshal

func (mm *MarshalizerMock) Marshal(obj interface{}) ([]byte, error)

Marshal converts the input object in a slice of bytes

func (*MarshalizerMock) Unmarshal

func (mm *MarshalizerMock) Unmarshal(obj interface{}, buff []byte) error

Unmarshal applies the serialized values over an instantiated object

type NodesCoordinatorMock

type NodesCoordinatorMock struct {
	Validators                               map[uint32][]sharding.Validator
	ShardConsensusSize                       uint32
	MetaConsensusSize                        uint32
	ShardId                                  uint32
	NbShards                                 uint32
	GetSelectedPublicKeysCalled              func(selection []byte, shardId uint32, epoch uint32) (publicKeys []string, err error)
	GetValidatorsPublicKeysCalled            func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error)
	GetValidatorsRewardsAddressesCalled      func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error)
	SetNodesPerShardsCalled                  func(nodes map[uint32][]sharding.Validator, epoch uint32) error
	ComputeValidatorsGroupCalled             func(randomness []byte, round uint64, shardId uint32, epoch uint32) (validatorsGroup []sharding.Validator, err error)
	GetValidatorWithPublicKeyCalled          func(publicKey []byte) (validator sharding.Validator, shardId uint32, err error)
	GetAllEligibleValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error)
	GetAllWaitingValidatorsPublicKeysCalled  func() (map[uint32][][]byte, error)
	ConsensusGroupSizeCalled                 func(uint32) int
}

NodesCoordinatorMock defines the behaviour of a struct able to do validator group selection

func (*NodesCoordinatorMock) ComputeAdditionalLeaving

func (ncm *NodesCoordinatorMock) ComputeAdditionalLeaving(_ []*state.ShardValidatorInfo) (map[uint32][]sharding.Validator, error)

ComputeAdditionalLeaving -

func (*NodesCoordinatorMock) ComputeConsensusGroup

func (ncm *NodesCoordinatorMock) ComputeConsensusGroup(
	randomess []byte,
	round uint64,
	shardId uint32,
	epoch uint32,
) ([]sharding.Validator, error)

ComputeConsensusGroup -

func (*NodesCoordinatorMock) ConsensusGroupSize

func (ncm *NodesCoordinatorMock) ConsensusGroupSize(shardId uint32) int

ConsensusGroupSize -

func (*NodesCoordinatorMock) GetAllEligibleValidatorsPublicKeys

func (ncm *NodesCoordinatorMock) GetAllEligibleValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)

GetAllEligibleValidatorsPublicKeys -

func (*NodesCoordinatorMock) GetAllLeavingValidatorsPublicKeys

func (ncm *NodesCoordinatorMock) GetAllLeavingValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error)

GetAllLeavingValidatorsPublicKeys -

func (*NodesCoordinatorMock) GetAllWaitingValidatorsPublicKeys

func (ncm *NodesCoordinatorMock) GetAllWaitingValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error)

GetAllWaitingValidatorsPublicKeys -

func (*NodesCoordinatorMock) GetChance

func (ncm *NodesCoordinatorMock) GetChance(uint32) uint32

GetChance -

func (*NodesCoordinatorMock) GetConsensusValidatorsPublicKeys

func (ncm *NodesCoordinatorMock) GetConsensusValidatorsPublicKeys(
	randomness []byte,
	round uint64,
	shardId uint32,
	epoch uint32,
) ([]string, error)

GetConsensusValidatorsPublicKeys -

func (*NodesCoordinatorMock) GetConsensusWhitelistedNodes

func (ncm *NodesCoordinatorMock) GetConsensusWhitelistedNodes(
	_ uint32,
) (map[string]struct{}, error)

GetConsensusWhitelistedNodes return the whitelisted nodes allowed to send consensus messages, for each of the shards

func (*NodesCoordinatorMock) GetNumTotalEligible

func (ncm *NodesCoordinatorMock) GetNumTotalEligible() uint64

GetNumTotalEligible -

func (*NodesCoordinatorMock) GetOwnPublicKey

func (ncm *NodesCoordinatorMock) GetOwnPublicKey() []byte

GetOwnPublicKey -

func (*NodesCoordinatorMock) GetSavedStateKey

func (ncm *NodesCoordinatorMock) GetSavedStateKey() []byte

GetSavedStateKey -

func (*NodesCoordinatorMock) GetSelectedPublicKeys

func (ncm *NodesCoordinatorMock) GetSelectedPublicKeys(selection []byte, shardId uint32, epoch uint32) (publicKeys []string, err error)

GetSelectedPublicKeys -

func (*NodesCoordinatorMock) GetValidatorWithPublicKey

func (ncm *NodesCoordinatorMock) GetValidatorWithPublicKey(publicKey []byte) (sharding.Validator, uint32, error)

GetValidatorWithPublicKey -

func (*NodesCoordinatorMock) GetValidatorsIndexes

func (ncm *NodesCoordinatorMock) GetValidatorsIndexes(_ []string, _ uint32) ([]uint64, error)

GetValidatorsIndexes -

func (*NodesCoordinatorMock) IsInterfaceNil

func (ncm *NodesCoordinatorMock) IsInterfaceNil() bool

IsInterfaceNil -

func (*NodesCoordinatorMock) LoadState

func (ncm *NodesCoordinatorMock) LoadState(_ []byte) error

LoadState -

func (*NodesCoordinatorMock) SetNodesPerShards

func (ncm *NodesCoordinatorMock) SetNodesPerShards(
	eligible map[uint32][]sharding.Validator,
	_ map[uint32][]sharding.Validator,
	epoch uint32,
) error

SetNodesPerShards -

func (*NodesCoordinatorMock) ShardIdForEpoch

func (ncm *NodesCoordinatorMock) ShardIdForEpoch(_ uint32) (uint32, error)

ShardIdForEpoch returns the nodesCoordinator configured ShardId for specified epoch if epoch configuration exists, otherwise error

func (*NodesCoordinatorMock) ShuffleOutForEpoch

func (ncm *NodesCoordinatorMock) ShuffleOutForEpoch(_ uint32)

ShuffleOutForEpoch verifies if the shards changed in the new epoch and calls the shuffleOutHandler

func (*NodesCoordinatorMock) ValidatorsWeights

func (ncm *NodesCoordinatorMock) ValidatorsWeights(validators []sharding.Validator) ([]uint32, error)

ValidatorsWeights -

type PubkeyConverterMock

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

PubkeyConverterMock -

func NewPubkeyConverterMock

func NewPubkeyConverterMock(addressLen int) *PubkeyConverterMock

NewPubkeyConverterMock -

func (*PubkeyConverterMock) Decode

func (pcm *PubkeyConverterMock) Decode(humanReadable string) ([]byte, error)

Decode -

func (*PubkeyConverterMock) Encode

func (pcm *PubkeyConverterMock) Encode(pkBytes []byte) string

Encode -

func (*PubkeyConverterMock) IsInterfaceNil

func (pcm *PubkeyConverterMock) IsInterfaceNil() bool

IsInterfaceNil -

func (*PubkeyConverterMock) Len

func (pcm *PubkeyConverterMock) Len() int

Len -

type ShardCoordinatorMock

type ShardCoordinatorMock struct {
}

ShardCoordinatorMock -

func (ShardCoordinatorMock) CommunicationIdentifier

func (scm ShardCoordinatorMock) CommunicationIdentifier(destShardID uint32) string

CommunicationIdentifier -

func (ShardCoordinatorMock) ComputeId

func (scm ShardCoordinatorMock) ComputeId(_ []byte) uint32

ComputeId -

func (ShardCoordinatorMock) IsInterfaceNil

func (scm ShardCoordinatorMock) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (ShardCoordinatorMock) NumberOfShards

func (scm ShardCoordinatorMock) NumberOfShards() uint32

NumberOfShards -

func (ShardCoordinatorMock) SameShard

func (scm ShardCoordinatorMock) SameShard(_, _ []byte) bool

SameShard -

func (ShardCoordinatorMock) SelfId

func (scm ShardCoordinatorMock) SelfId() uint32

SelfId -

func (ShardCoordinatorMock) SetSelfId

func (scm ShardCoordinatorMock) SetSelfId(_ uint32) error

SetSelfId -

type StableTagProviderStub

type StableTagProviderStub struct {
	FetchTagVersionCalled func() (string, error)
}

StableTagProviderStub --

func (*StableTagProviderStub) FetchTagVersion

func (s *StableTagProviderStub) FetchTagVersion() (string, error)

FetchTagVersion --

func (*StableTagProviderStub) IsInterfaceNil

func (s *StableTagProviderStub) IsInterfaceNil() bool

IsInterfaceNil --

type StorerStub added in v0.0.2

type StorerStub struct {
	PutCalled              func(key, data []byte) error
	GetCalled              func(key []byte) ([]byte, error)
	GetFromEpochCalled     func(key []byte, epoch uint32) ([]byte, error)
	HasCalled              func(key []byte) error
	HasInEpochCalled       func(key []byte, epoch uint32) error
	SearchFirstCalled      func(key []byte) ([]byte, error)
	RemoveCalled           func(key []byte) error
	ClearCacheCalled       func()
	DestroyUnitCalled      func() error
	RangeKeysCalled        func(handler func(key []byte, val []byte) bool)
	GetBulkFromEpochCalled func(keys [][]byte, epoch uint32) (map[string][]byte, error)
}

StorerStub -

func (*StorerStub) ClearCache added in v0.0.2

func (ss *StorerStub) ClearCache()

ClearCache -

func (*StorerStub) Close added in v0.0.2

func (ss *StorerStub) Close() error

Close -

func (*StorerStub) DestroyUnit added in v0.0.2

func (ss *StorerStub) DestroyUnit() error

DestroyUnit -

func (*StorerStub) Get added in v0.0.2

func (ss *StorerStub) Get(key []byte) ([]byte, error)

Get -

func (*StorerStub) GetBulkFromEpoch added in v0.0.2

func (ss *StorerStub) GetBulkFromEpoch(keys [][]byte, epoch uint32) (map[string][]byte, error)

GetBulkFromEpoch -

func (*StorerStub) GetFromEpoch added in v0.0.2

func (ss *StorerStub) GetFromEpoch(key []byte, epoch uint32) ([]byte, error)

GetFromEpoch -

func (*StorerStub) Has added in v0.0.2

func (ss *StorerStub) Has(key []byte) error

Has -

func (*StorerStub) HasInEpoch added in v0.0.2

func (ss *StorerStub) HasInEpoch(key []byte, epoch uint32) error

HasInEpoch -

func (*StorerStub) IsInterfaceNil added in v0.0.2

func (ss *StorerStub) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*StorerStub) Put added in v0.0.2

func (ss *StorerStub) Put(key, data []byte) error

Put -

func (*StorerStub) RangeKeys added in v0.0.2

func (ss *StorerStub) RangeKeys(handler func(key []byte, val []byte) bool)

RangeKeys -

func (*StorerStub) Remove added in v0.0.2

func (ss *StorerStub) Remove(key []byte) error

Remove -

func (*StorerStub) SearchFirst added in v0.0.2

func (ss *StorerStub) SearchFirst(key []byte) ([]byte, error)

SearchFirst -

Jump to

Keyboard shortcuts

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