fabric-sdk-go: github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/mocks Index | Files

package mocks

import "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/mocks"

Index

Package Files

blockproducer.go blockwrapper.go fblockwrapper.go mockevents.go mockledger.go mockproducer.go

Variables

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

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

func NewBlock Uses

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

NewBlock returns a new mock block initialized with the given channel

func NewFilteredBlock Uses

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 Uses

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

NewFilteredTx returns a new mock filtered transaction

func NewFilteredTxWithCCEvent Uses

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

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

type Block Uses

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

Block is n abstract block

type BlockEvent Uses

type BlockEvent interface{}

BlockEvent is an abstract event

type BlockProducer Uses

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

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

func NewBlockProducer Uses

func NewBlockProducer() *BlockProducer

NewBlockProducer returns a new block producer

func (*BlockProducer) NewBlock Uses

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

NewBlock returns a new block

func (*BlockProducer) NewFilteredBlock Uses

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

NewFilteredBlock returns a new filtered block

type BlockWrapper Uses

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

BlockWrapper wraps the Block and conforms to the Block interface

func NewBlockWrapper Uses

func NewBlockWrapper(block *cb.Block) *BlockWrapper

NewBlockWrapper returns a new Block wrapper

func (*BlockWrapper) Block Uses

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

Block returns the block

func (*BlockWrapper) Number Uses

func (w *BlockWrapper) Number() uint64

Number returns the block number

func (*BlockWrapper) SetNumber Uses

func (w *BlockWrapper) SetNumber(number uint64)

SetNumber sets the block number

type Consumer Uses

type Consumer chan interface{}

Consumer is a consumer of a BlockEvent

type EventFactory Uses

type EventFactory func(block Block, sourceURL string) BlockEvent

EventFactory creates block events

type FilteredBlockWrapper Uses

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

FilteredBlockWrapper wraps the FilteredBlock and conforms to the Block interface

func NewFilteredBlockWrapper Uses

func NewFilteredBlockWrapper(block *pb.FilteredBlock) *FilteredBlockWrapper

NewFilteredBlockWrapper returns a new Filtered Block wrapper

func (*FilteredBlockWrapper) Block Uses

func (w *FilteredBlockWrapper) Block() *pb.FilteredBlock

Block returns the filtered block

func (*FilteredBlockWrapper) Number Uses

func (w *FilteredBlockWrapper) Number() uint64

Number returns the block number

func (*FilteredBlockWrapper) SetNumber Uses

func (w *FilteredBlockWrapper) SetNumber(number uint64)

SetNumber sets the block number

type Ledger Uses

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 Uses

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

MockLedger is a mock ledger that stores blocks sequentially

func NewMockLedger Uses

func NewMockLedger(eventFactory EventFactory, sourceURL string) *MockLedger

NewMockLedger creates a new MockLedger

func (*MockLedger) BlockProducer Uses

func (l *MockLedger) BlockProducer() *BlockProducer

BlockProducer returns the block producer

func (*MockLedger) NewBlock Uses

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

NewBlock stores a new block on the ledger

func (*MockLedger) NewFilteredBlock Uses

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

NewFilteredBlock stores a new filtered block on the ledger

func (*MockLedger) Register Uses

func (l *MockLedger) Register(consumer Consumer)

Register registers an event consumer

func (*MockLedger) SendFrom Uses

func (l *MockLedger) SendFrom(blockNum uint64)

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

func (*MockLedger) Store Uses

func (l *MockLedger) Store(block Block)

Store stores the given block to the ledger

func (*MockLedger) Unregister Uses

func (l *MockLedger) Unregister(Consumer Consumer)

Unregister unregisters the given consumer

type MockProducer Uses

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

MockProducer produces events for unit testing

func NewMockProducer Uses

func NewMockProducer(ledger Ledger) *MockProducer

NewMockProducer returns a new MockProducer

func (*MockProducer) Close Uses

func (c *MockProducer) Close()

Close closes the event producer

func (*MockProducer) Ledger Uses

func (c *MockProducer) Ledger() Ledger

Ledger returns the mock ledger

func (*MockProducer) Register Uses

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

Register registers an event channel

func (*MockProducer) Unregister Uses

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

Unregister unregisters an event channel

type TxInfo Uses

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 Uses

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

NewTransaction creates a new transaction

func NewTransactionWithCCEvent Uses

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

NewTransactionWithCCEvent creates a new transaction with the given chaincode event

Package mocks imports 9 packages (graph) and is imported by 3 packages. Updated 2019-08-31. Refresh now. Tools for package owners.