fake

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMultiStore

func NewMultiStore() sdk.MultiStore

NewMultiStore returns a new Multistore instance used for testing

func NewRouter

func NewRouter() sdk.Router

NewRouter returns a new Router that deals with handler routing

func NewTestKVStore

func NewTestKVStore() interfaces.KVStore

NewTestKVStore returns a new kv store instance for testing

Types

type BlockChain

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

BlockChain is a fake that emulates the behaviour of a full blockchain network (consensus and message dissemination) for testing

func NewBlockchain

func NewBlockchain() *BlockChain

NewBlockchain returns a faked blockchain with default parameters. Use the With* functions to specify different parameters. By default, the blockchain does not time out, so a block will only be disseminated once the specified block size is reached.

func (*BlockChain) AddNodes

func (bc *BlockChain) AddNodes(nodes ...*Node)

AddNodes adds a node to the blockchain. This node will receive blocks from the blockchain.

func (BlockChain) CurrentHeight

func (bc BlockChain) CurrentHeight() int64

CurrentHeight returns the current block height.

func (*BlockChain) Start

func (bc *BlockChain) Start()

Start starts the block dissemination. Only call once all parameters and nodes are fully set up.

func (*BlockChain) Submit

func (bc *BlockChain) Submit(msg sdk.Msg) <-chan *Result

Submit sends a message to the blockchain. It returns a channel with the result.

func (*BlockChain) WaitNBlocks

func (bc *BlockChain) WaitNBlocks(n int64)

WaitNBlocks waits for n blocks to be disseminated before returning. Do not use without setting a block timeout or the test will deadlock.

func (BlockChain) WithBlockSize

func (bc BlockChain) WithBlockSize(size int) *BlockChain

WithBlockSize returns a blockchain with blocks of at most the specified size.

func (BlockChain) WithBlockTimeOut

func (bc BlockChain) WithBlockTimeOut(timeOut time.Duration) *BlockChain

WithBlockTimeOut returns a blockchain with a timeout. The timeout resets whenever a message is received. When the timer runs out it disseminates the next block regardless of its size.

type MultiStore

type MultiStore struct {
	*mock.MultiStoreMock
	// contains filtered or unexported fields
}

MultiStore is a simple multistore used for testing

type Node

type Node struct {
	Ctx     sdk.Context
	Moniker string
	// contains filtered or unexported fields
}

Node is a fake that emulates the behaviour of a Cosmos node by retrieving blocks from the network, unpacking the messages and routing them to the correct modules

func NewNode

func NewNode(moniker string, ctx sdk.Context, router sdk.Router, queriers map[string]sdk.Querier) *Node

NewNode creates a new node that can be added to the blockchain. The moniker is used to differentiate nodes for logging purposes. The context will be passed on to the registered handlers.

func (Node) Query

func (n Node) Query(path []string, query abci.RequestQuery) ([]byte, error)

Query allows to query a node. Returns a serialized response

func (*Node) RegisterEventListener

func (n *Node) RegisterEventListener(predicate func(event abci.Event) bool) <-chan abci.Event

RegisterEventListener registers a listener for events that satisfy the predicate. Events will be dropped if the event channel fills up

func (*Node) WithEndBlockers

func (n *Node) WithEndBlockers(endBlockers ...func(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate) *Node

WithEndBlockers returns a node with the specified EndBlocker functions. They are executed in the order they are provided.

type Result

type Result struct {
	*sdk.Result
	Error error
}

Result contains either the result of a successful message execution or the error that occurred

type Router

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

Router is a fake that is used by the Node to route messages to the correct module handlers

func (Router) AddRoute

func (r Router) AddRoute(route sdk.Route) sdk.Router

AddRoute adds a new handler route

func (Router) Route

func (r Router) Route(_ sdk.Context, path string) sdk.Handler

Route tries to route the given path to a registered handler. Returns nil when the path is not found.

type TestKVStore

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

TestKVStore is a kv store for testing

func (TestKVStore) CacheWrap

func (t TestKVStore) CacheWrap() sdk.CacheWrap

CacheWrap is not implemented

func (TestKVStore) CacheWrapWithListeners

func (t TestKVStore) CacheWrapWithListeners(storeKey types.StoreKey, listeners []types.WriteListener) types.CacheWrap

CacheWrapWithListeners is not implemented

func (TestKVStore) CacheWrapWithTrace

func (t TestKVStore) CacheWrapWithTrace(_ io.Writer, _ sdk.TraceContext) sdk.CacheWrap

CacheWrapWithTrace is not implemented

func (TestKVStore) Delete

func (t TestKVStore) Delete(key []byte)

Delete deletes a key if it exists

func (TestKVStore) Get

func (t TestKVStore) Get(key []byte) []byte

Get returns the value of the given key, nil if it does not exist

func (TestKVStore) GetStoreType

func (t TestKVStore) GetStoreType() sdk.StoreType

GetStoreType is not implemented

func (TestKVStore) Has

func (t TestKVStore) Has(key []byte) bool

Has checks if an entry for the given key exists

func (TestKVStore) Iterator

func (t TestKVStore) Iterator(start, end []byte) sdk.Iterator

Iterator returns an interator over the given key domain

func (TestKVStore) ReverseIterator

func (t TestKVStore) ReverseIterator(start, end []byte) sdk.Iterator

ReverseIterator returns an iterator that iterates over all keys in the given domain in reverse order

func (TestKVStore) Set

func (t TestKVStore) Set(key, value []byte)

Set stores the given key value pair

type Tofnd

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

Tofnd is a thread-safe fake that emulates the external tofnd process

func NewTofnd

func NewTofnd() *Tofnd

NewTofnd returns a new Tofnd instance

func (*Tofnd) HasKey

func (t *Tofnd) HasKey(keyID string) bool

HasKey returns true if it holds the key associated with the specified ID

func (*Tofnd) KeyGen

func (t *Tofnd) KeyGen(keyID string) []byte

KeyGen simulates a distributed key generation. Only the first call with the same keyID creates a new key, every consecutive call returns the same one

func (*Tofnd) Sign

func (t *Tofnd) Sign(sigID string, keyID string, msg []byte) []byte

Sign simulates a distributed signature generation. Only the first call with the same sigID creates a new signature from the given key, every consecutive call returns the same one

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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