mocks

package
v1.0.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BlockEventFactory = func(block Block, sourceURL string) BlockEvent {
	b, ok := block.(*BlockWrapper)
	if !ok {
		panic(fmt.Sprintf("Invalid block type: %T", block))
	}
	return &fab.BlockEvent{Block: b.Block(), SourceURL: sourceURL}
}

BlockEventFactory creates block events

View Source
var FilteredBlockEventFactory = func(block Block, sourceURL string) BlockEvent {
	b, ok := block.(*FilteredBlockWrapper)
	if !ok {
		panic(fmt.Sprintf("Invalid block type: %T", block))
	}
	return &fab.FilteredBlockEvent{FilteredBlock: b.Block(), SourceURL: sourceURL}
}

FilteredBlockEventFactory creates filtered block events

Functions

func NewBlock

func NewBlock(channelID string, transactions ...*TxInfo) *cb.Block

NewBlock returns a new mock block initialized with the given channel

func NewFilteredBlock

func NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction) *pb.FilteredBlock

NewFilteredBlock returns a new mock filtered block initialized with the given channel and filtered transactions

func NewFilteredTx

func NewFilteredTx(txID string, txValidationCode pb.TxValidationCode) *pb.FilteredTransaction

NewFilteredTx returns a new mock filtered transaction

func NewFilteredTxWithCCEvent

func NewFilteredTxWithCCEvent(txID, ccID, event string) *pb.FilteredTransaction

NewFilteredTxWithCCEvent returns a new mock filtered transaction with the given chaincode event

Types

type Block

type Block interface {
	Number() uint64
	SetNumber(blockNum uint64)
}

Block is n abstract block

type BlockEvent

type BlockEvent interface{}

BlockEvent is an abstract event

type BlockProducer

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

BlockProducer is a block BlockProducer that ensures the block number is set sequencially

func NewBlockProducer

func NewBlockProducer() *BlockProducer

NewBlockProducer returns a new block producer

func (*BlockProducer) NewBlock

func (p *BlockProducer) NewBlock(channelID string, transactions ...*TxInfo) *cb.Block

NewBlock returns a new block

func (*BlockProducer) NewFilteredBlock

func (p *BlockProducer) NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction) *pb.FilteredBlock

NewFilteredBlock returns a new filtered block

type BlockWrapper

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

BlockWrapper wraps the Block and conforms to the Block interface

func NewBlockWrapper

func NewBlockWrapper(block *cb.Block) *BlockWrapper

NewBlockWrapper returns a new Block wrapper

func (*BlockWrapper) Block

func (w *BlockWrapper) Block() *cb.Block

Block returns the block

func (*BlockWrapper) Number

func (w *BlockWrapper) Number() uint64

Number returns the block number

func (*BlockWrapper) SetNumber

func (w *BlockWrapper) SetNumber(number uint64)

SetNumber sets the block number

type Consumer

type Consumer chan interface{}

Consumer is a consumer of a BlockEvent

type EventFactory

type EventFactory func(block Block, sourceURL string) BlockEvent

EventFactory creates block events

type FilteredBlockWrapper

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

FilteredBlockWrapper wraps the FilteredBlock and conforms to the Block interface

func NewFilteredBlockWrapper

func NewFilteredBlockWrapper(block *pb.FilteredBlock) *FilteredBlockWrapper

NewFilteredBlockWrapper returns a new Filtered Block wrapper

func (*FilteredBlockWrapper) Block

Block returns the filtered block

func (*FilteredBlockWrapper) Number

func (w *FilteredBlockWrapper) Number() uint64

Number returns the block number

func (*FilteredBlockWrapper) SetNumber

func (w *FilteredBlockWrapper) SetNumber(number uint64)

SetNumber sets the block number

type Ledger

type Ledger interface {
	// Register registers an event consumer
	Register(consumer Consumer)

	// Unregister unregisters the given consumer
	Unregister(consumer Consumer)

	// NewBlock creates a new block
	NewBlock(channelID string, transactions ...*TxInfo) Block

	// NewFilteredBlock returns a new filtered block
	NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction)

	// SendFrom sends block events to all registered consumers from the
	// given block number
	SendFrom(blockNum uint64)
}

Ledger is a MockLedger

type MockLedger

type MockLedger struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MockLedger is a mock ledger that stores blocks sequentially

func NewMockLedger

func NewMockLedger(eventFactory EventFactory, sourceURL string) *MockLedger

NewMockLedger creates a new MockLedger

func (*MockLedger) BlockProducer

func (l *MockLedger) BlockProducer() *BlockProducer

BlockProducer returns the block producer

func (*MockLedger) NewBlock

func (l *MockLedger) NewBlock(channelID string, transactions ...*TxInfo) Block

NewBlock stores a new block on the ledger

func (*MockLedger) NewFilteredBlock

func (l *MockLedger) NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction)

NewFilteredBlock stores a new filtered block on the ledger

func (*MockLedger) Register

func (l *MockLedger) Register(consumer Consumer)

Register registers an event consumer

func (*MockLedger) SendFrom

func (l *MockLedger) SendFrom(blockNum uint64)

SendFrom sends block events to all registered consumers from the given block number

func (*MockLedger) Store

func (l *MockLedger) Store(block Block)

Store stores the given block to the ledger

func (*MockLedger) Unregister

func (l *MockLedger) Unregister(Consumer Consumer)

Unregister unregisters the given consumer

type MockProducer

type MockProducer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MockProducer produces events for unit testing

func NewMockProducer

func NewMockProducer(ledger Ledger) *MockProducer

NewMockProducer returns a new MockProducer

func (*MockProducer) Close

func (c *MockProducer) Close()

Close closes the event producer

func (*MockProducer) Ledger

func (c *MockProducer) Ledger() Ledger

Ledger returns the mock ledger

func (*MockProducer) Register

func (c *MockProducer) Register() <-chan interface{}

Register registers an event channel

func (*MockProducer) Unregister

func (c *MockProducer) Unregister(eventch chan<- interface{})

Unregister unregisters an event channel

type TxInfo

type TxInfo struct {
	TxID             string
	TxValidationCode pb.TxValidationCode
	HeaderType       cb.HeaderType
	ChaincodeID      string
	EventName        string
	Payload          []byte
}

TxInfo contains the data necessary to construct a mock transaction

func NewTransaction

func NewTransaction(txID string, txValidationCode pb.TxValidationCode, headerType cb.HeaderType) *TxInfo

NewTransaction creates a new transaction

func NewTransactionWithCCEvent

func NewTransactionWithCCEvent(txID string, txValidationCode pb.TxValidationCode, ccID string, eventName string, payload []byte) *TxInfo

NewTransactionWithCCEvent creates a new transaction with the given chaincode event

Jump to

Keyboard shortcuts

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