mocks

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoopLogger = zerolog.New(io.Discard)

	GenericError = errors.New("dummy error")

	GenericHeight = uint64(42)

	GenericBytes = []byte(`test`)

	GenericHeader = &flow.Header{
		ChainID:   dps.FlowTestnet,
		Height:    GenericHeight,
		ParentID:  GenericIdentifier(15),
		Timestamp: time.Date(1972, 11, 12, 13, 14, 15, 16, time.UTC),
	}

	GenericLedgerKey = ledger.NewKey([]ledger.KeyPart{
		ledger.NewKeyPart(0, []byte(`owner`)),
		ledger.NewKeyPart(1, []byte(`controller`)),
		ledger.NewKeyPart(2, []byte(`key`)),
	})

	GenericTrieUpdate = &ledger.TrieUpdate{
		RootHash: ledger.RootHash{
			0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
			0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
			0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
			0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
		},
		Paths:    GenericLedgerPaths(6),
		Payloads: GenericLedgerPayloads(6),
	}

	// GenericRootNode Visual Representation:
	//           6 (root)
	//          / \
	//         3   5
	//        / \   \
	//       1   2   4
	GenericRootNode = node.NewNode(
		256,
		node.NewNode(
			256,
			node.NewLeaf(GenericLedgerPath(0), GenericLedgerPayload(0), 42),
			node.NewLeaf(GenericLedgerPath(1), GenericLedgerPayload(1), 42),
			GenericLedgerPath(2),
			GenericLedgerPayload(2),
			hash.DummyHash,
			64,
			64,
		),
		node.NewNode(
			256,
			node.NewLeaf(GenericLedgerPath(3), GenericLedgerPayload(3), 42),
			nil,
			GenericLedgerPath(4),
			GenericLedgerPayload(4),
			hash.DummyHash,
			64,
			64,
		),
		GenericLedgerPath(5),
		GenericLedgerPayload(5),
		hash.DummyHash,
		64,
		64,
	)

	GenericTrie, _ = trie.NewMTrie(GenericRootNode)

	GenericCurrency = identifier.Currency{
		Symbol:   dps.FlowSymbol,
		Decimals: dps.FlowDecimals,
	}
	GenericAccount = flow.Account{
		Address: GenericAddress(0),
		Balance: 84,
	}

	GenericBlockQualifier = identifier.Block{
		Index: &GenericHeight,
		Hash:  GenericHeader.ID().String(),
	}
)

Global variables that can be used for testing. They are non-nil valid values for the types commonly needed test DPS components.

Functions

func ByteSlice

func ByteSlice(v interface{}) []byte

func GenericAccountID

func GenericAccountID(index int) identifier.Account

func GenericAddress

func GenericAddress(index int) flow.Address

func GenericAddresses

func GenericAddresses(number int) []flow.Address

func GenericAmount

func GenericAmount(delta int) cadence.Value

func GenericCadenceEvent

func GenericCadenceEvent(index int) cadence.Event

func GenericCadenceEventType

func GenericCadenceEventType(index int) *cadence.EventType

func GenericCadenceEventTypes

func GenericCadenceEventTypes(number int) []*cadence.EventType

func GenericCadenceEvents

func GenericCadenceEvents(number int) []cadence.Event

func GenericCollection

func GenericCollection(index int) *flow.LightCollection

func GenericCollections

func GenericCollections(number int) []*flow.LightCollection

func GenericCommit

func GenericCommit(index int) flow.StateCommitment

func GenericCommits

func GenericCommits(number int) []flow.StateCommitment

func GenericEventType

func GenericEventType(index int) flow.EventType

func GenericEventTypes

func GenericEventTypes(number int) []flow.EventType

func GenericEvents

func GenericEvents(number int) []flow.Event

func GenericGuarantee added in v1.1.0

func GenericGuarantee(index int) *flow.CollectionGuarantee

func GenericGuarantees added in v1.1.0

func GenericGuarantees(number int) []*flow.CollectionGuarantee

func GenericIdentifier

func GenericIdentifier(index int) flow.Identifier

func GenericIdentifiers

func GenericIdentifiers(number int) []flow.Identifier

func GenericLedgerPath

func GenericLedgerPath(index int) ledger.Path

func GenericLedgerPaths

func GenericLedgerPaths(number int) []ledger.Path

func GenericLedgerPayload

func GenericLedgerPayload(index int) *ledger.Payload

func GenericLedgerPayloads

func GenericLedgerPayloads(number int) []*ledger.Payload

func GenericLedgerValue

func GenericLedgerValue(index int) ledger.Value

func GenericLedgerValues

func GenericLedgerValues(number int) []ledger.Value

func GenericOperation

func GenericOperation(index int) object.Operation

func GenericOperations

func GenericOperations(number int) []object.Operation

func GenericResult

func GenericResult(index int) *flow.TransactionResult

func GenericResults

func GenericResults(number int) []*flow.TransactionResult

func GenericSeal added in v1.1.0

func GenericSeal(index int) *flow.Seal

func GenericSeals added in v1.1.0

func GenericSeals(number int) []*flow.Seal

func GenericTransaction

func GenericTransaction(index int) *flow.TransactionBody

func GenericTransactionQualifier

func GenericTransactionQualifier(index int) identifier.Transaction

func GenericTransactions

func GenericTransactions(number int) []*flow.TransactionBody

Types

type Cache added in v1.1.0

type Cache struct {
	GetFunc func(key interface{}) (interface{}, bool)
	SetFunc func(key, value interface{}, cost int64) bool
}

func BaselineCache added in v1.1.0

func BaselineCache(t *testing.T) *Cache

func (*Cache) Get added in v1.1.0

func (c *Cache) Get(key interface{}) (interface{}, bool)

func (*Cache) Set added in v1.1.0

func (c *Cache) Set(key, value interface{}, cost int64) bool

type Chain

type Chain struct {
	RootFunc         func() (uint64, error)
	HeaderFunc       func(height uint64) (*flow.Header, error)
	CommitFunc       func(height uint64) (flow.StateCommitment, error)
	CollectionsFunc  func(height uint64) ([]*flow.LightCollection, error)
	GuaranteesFunc   func(height uint64) ([]*flow.CollectionGuarantee, error)
	TransactionsFunc func(height uint64) ([]*flow.TransactionBody, error)
	ResultsFunc      func(height uint64) ([]*flow.TransactionResult, error)
	EventsFunc       func(height uint64) ([]flow.Event, error)
	SealsFunc        func(height uint64) ([]*flow.Seal, error)
}

func BaselineChain

func BaselineChain(t *testing.T) *Chain

func (*Chain) Collections

func (c *Chain) Collections(height uint64) ([]*flow.LightCollection, error)

func (*Chain) Commit

func (c *Chain) Commit(height uint64) (flow.StateCommitment, error)

func (*Chain) Events

func (c *Chain) Events(height uint64) ([]flow.Event, error)

func (*Chain) Guarantees added in v1.1.0

func (c *Chain) Guarantees(height uint64) ([]*flow.CollectionGuarantee, error)

func (*Chain) Header

func (c *Chain) Header(height uint64) (*flow.Header, error)

func (*Chain) Results added in v1.1.0

func (c *Chain) Results(height uint64) ([]*flow.TransactionResult, error)

func (*Chain) Root

func (c *Chain) Root() (uint64, error)

func (*Chain) Seals added in v1.1.0

func (c *Chain) Seals(height uint64) ([]*flow.Seal, error)

func (*Chain) Transactions

func (c *Chain) Transactions(height uint64) ([]*flow.TransactionBody, error)

type Codec

type Codec struct {
	EncodeFunc     func(value interface{}) ([]byte, error)
	DecodeFunc     func(data []byte, value interface{}) error
	CompressFunc   func(data []byte) ([]byte, error)
	DecompressFunc func(compressed []byte) ([]byte, error)
	MarshalFunc    func(value interface{}) ([]byte, error)
	UnmarshalFunc  func(compressed []byte, value interface{}) error
}

func BaselineCodec

func BaselineCodec(t *testing.T) *Codec

func (*Codec) Compress

func (c *Codec) Compress(data []byte) ([]byte, error)

func (*Codec) Decode

func (c *Codec) Decode(data []byte, value interface{}) error

func (*Codec) Decompress

func (c *Codec) Decompress(data []byte) ([]byte, error)

func (*Codec) Encode

func (c *Codec) Encode(value interface{}) ([]byte, error)

func (*Codec) Marshal

func (c *Codec) Marshal(v interface{}) ([]byte, error)

func (*Codec) Unmarshal

func (c *Codec) Unmarshal(b []byte, v interface{}) error

type Converter

type Converter struct {
	EventToOperationFunc func(event flow.Event) (*object.Operation, error)
}

func BaselineConverter

func BaselineConverter(t *testing.T) *Converter

func (*Converter) EventToOperation

func (c *Converter) EventToOperation(event flow.Event) (transaction *object.Operation, err error)

type Feeder

type Feeder struct {
	UpdateFunc func() (*ledger.TrieUpdate, error)
}

func BaselineFeeder

func BaselineFeeder(t *testing.T) *Feeder

func (*Feeder) Update

func (f *Feeder) Update() (*ledger.TrieUpdate, error)

type Forest

type Forest struct {
	SaveFunc   func(tree *trie.MTrie, paths []ledger.Path, parent flow.StateCommitment)
	HasFunc    func(commit flow.StateCommitment) bool
	TreeFunc   func(commit flow.StateCommitment) (*trie.MTrie, bool)
	PathsFunc  func(commit flow.StateCommitment) ([]ledger.Path, bool)
	ParentFunc func(commit flow.StateCommitment) (flow.StateCommitment, bool)
	ResetFunc  func(finalized flow.StateCommitment)
	SizeFunc   func() uint
}

func BaselineForest

func BaselineForest(t *testing.T, hasCommit bool) *Forest

func (*Forest) Has

func (f *Forest) Has(commit flow.StateCommitment) bool

func (*Forest) Parent

func (f *Forest) Parent(commit flow.StateCommitment) (flow.StateCommitment, bool)

func (*Forest) Paths

func (f *Forest) Paths(commit flow.StateCommitment) ([]ledger.Path, bool)

func (*Forest) Reset

func (f *Forest) Reset(finalized flow.StateCommitment)

func (*Forest) Save

func (f *Forest) Save(tree *trie.MTrie, paths []ledger.Path, parent flow.StateCommitment)

func (*Forest) Size

func (f *Forest) Size() uint

func (*Forest) Tree

func (f *Forest) Tree(commit flow.StateCommitment) (*trie.MTrie, bool)

type Generator

type Generator struct {
	GetBalanceFunc      func(symbol string) ([]byte, error)
	TokensDepositedFunc func(symbol string) (string, error)
	TokensWithdrawnFunc func(symbol string) (string, error)
}

func BaselineGenerator

func BaselineGenerator(t *testing.T) *Generator

func (*Generator) GetBalance

func (g *Generator) GetBalance(symbol string) ([]byte, error)

func (*Generator) TokensDeposited

func (g *Generator) TokensDeposited(symbol string) (string, error)

func (*Generator) TokensWithdrawn

func (g *Generator) TokensWithdrawn(symbol string) (string, error)

type Invoker

type Invoker struct {
	KeyFunc     func(height uint64, address flow.Address, index int) (*flow.AccountPublicKey, error)
	AccountFunc func(height uint64, address flow.Address) (*flow.Account, error)
	ScriptFunc  func(height uint64, script []byte, parameters []cadence.Value) (cadence.Value, error)
}

func BaselineInvoker

func BaselineInvoker(t *testing.T) *Invoker

func (*Invoker) Account added in v1.2.0

func (i *Invoker) Account(height uint64, address flow.Address) (*flow.Account, error)

func (*Invoker) Key added in v1.2.0

func (i *Invoker) Key(height uint64, address flow.Address, index int) (*flow.AccountPublicKey, error)

func (*Invoker) Script

func (i *Invoker) Script(height uint64, script []byte, parameters []cadence.Value) (cadence.Value, error)

type Loader

type Loader struct {
	CheckpointFunc func() (*trie.MTrie, error)
}

func BaselineLoader

func BaselineLoader(t *testing.T) *Loader

func (*Loader) Checkpoint

func (l *Loader) Checkpoint() (*trie.MTrie, error)

type Reader

type Reader struct {
	FirstFunc                func() (uint64, error)
	LastFunc                 func() (uint64, error)
	HeightForBlockFunc       func(blockID flow.Identifier) (uint64, error)
	CommitFunc               func(height uint64) (flow.StateCommitment, error)
	HeaderFunc               func(height uint64) (*flow.Header, error)
	EventsFunc               func(height uint64, types ...flow.EventType) ([]flow.Event, error)
	ValuesFunc               func(height uint64, paths []ledger.Path) ([]ledger.Value, error)
	CollectionFunc           func(collID flow.Identifier) (*flow.LightCollection, error)
	CollectionsByHeightFunc  func(height uint64) ([]flow.Identifier, error)
	GuaranteeFunc            func(collID flow.Identifier) (*flow.CollectionGuarantee, error)
	TransactionFunc          func(txID flow.Identifier) (*flow.TransactionBody, error)
	HeightForTransactionFunc func(txID flow.Identifier) (uint64, error)
	TransactionsByHeightFunc func(height uint64) ([]flow.Identifier, error)
	ResultFunc               func(txID flow.Identifier) (*flow.TransactionResult, error)
	SealFunc                 func(sealID flow.Identifier) (*flow.Seal, error)
	SealsByHeightFunc        func(height uint64) ([]flow.Identifier, error)
}

func BaselineReader

func BaselineReader(t *testing.T) *Reader

func (*Reader) Collection added in v1.1.0

func (r *Reader) Collection(collID flow.Identifier) (*flow.LightCollection, error)

func (*Reader) CollectionsByHeight added in v1.1.0

func (r *Reader) CollectionsByHeight(height uint64) ([]flow.Identifier, error)

func (*Reader) Commit

func (r *Reader) Commit(height uint64) (flow.StateCommitment, error)

func (*Reader) Events

func (r *Reader) Events(height uint64, types ...flow.EventType) ([]flow.Event, error)

func (*Reader) First

func (r *Reader) First() (uint64, error)

func (*Reader) Guarantee added in v1.1.0

func (r *Reader) Guarantee(collID flow.Identifier) (*flow.CollectionGuarantee, error)

func (*Reader) Header

func (r *Reader) Header(height uint64) (*flow.Header, error)

func (*Reader) HeightForBlock

func (r *Reader) HeightForBlock(blockID flow.Identifier) (uint64, error)

func (*Reader) HeightForTransaction added in v1.1.0

func (r *Reader) HeightForTransaction(txID flow.Identifier) (uint64, error)

func (*Reader) Last

func (r *Reader) Last() (uint64, error)

func (*Reader) Result added in v1.1.0

func (r *Reader) Result(txID flow.Identifier) (*flow.TransactionResult, error)

func (*Reader) Seal added in v1.1.0

func (r *Reader) Seal(sealID flow.Identifier) (*flow.Seal, error)

func (*Reader) SealsByHeight added in v1.1.0

func (r *Reader) SealsByHeight(height uint64) ([]flow.Identifier, error)

func (*Reader) Transaction

func (r *Reader) Transaction(txID flow.Identifier) (*flow.TransactionBody, error)

func (*Reader) TransactionsByHeight

func (r *Reader) TransactionsByHeight(height uint64) ([]flow.Identifier, error)

func (*Reader) Values

func (r *Reader) Values(height uint64, paths []ledger.Path) ([]ledger.Value, error)

type Validator

type Validator struct {
	AccountFunc     func(rosAccountID identifier.Account) (flow.Address, error)
	BlockFunc       func(rosBlockID identifier.Block) (uint64, flow.Identifier, error)
	TransactionFunc func(rosTxID identifier.Transaction) (flow.Identifier, error)
	CurrencyFunc    func(rosCurrencies identifier.Currency) (string, uint, error)
}

func BaselineValidator

func BaselineValidator(t *testing.T) *Validator

func (*Validator) Account

func (v *Validator) Account(rosAccountID identifier.Account) (flow.Address, error)

func (*Validator) Block

func (v *Validator) Block(rosBlockID identifier.Block) (uint64, flow.Identifier, error)

func (*Validator) Currency

func (v *Validator) Currency(rosCurrency identifier.Currency) (string, uint, error)

func (*Validator) Transaction

func (v *Validator) Transaction(rosTxID identifier.Transaction) (flow.Identifier, error)

type VirtualMachine added in v1.1.0

type VirtualMachine struct {
	GetAccountFunc func(ctx fvm.Context, address flow.Address, v state.View, programs *programs.Programs) (*flow.Account, error)
	RunFunc        func(ctx fvm.Context, proc fvm.Procedure, v state.View, programs *programs.Programs) error
}

func BaselineVirtualMachine added in v1.1.0

func BaselineVirtualMachine(t *testing.T) *VirtualMachine

func (*VirtualMachine) GetAccount added in v1.1.0

func (v *VirtualMachine) GetAccount(ctx fvm.Context, address flow.Address, view state.View, programs *programs.Programs) (*flow.Account, error)

func (*VirtualMachine) Run added in v1.1.0

func (v *VirtualMachine) Run(ctx fvm.Context, proc fvm.Procedure, view state.View, programs *programs.Programs) error

type Writer

type Writer struct {
	FirstFunc        func(height uint64) error
	LastFunc         func(height uint64) error
	HeaderFunc       func(height uint64, header *flow.Header) error
	CommitFunc       func(height uint64, commit flow.StateCommitment) error
	PayloadsFunc     func(height uint64, paths []ledger.Path, value []*ledger.Payload) error
	HeightFunc       func(blockID flow.Identifier, height uint64) error
	CollectionsFunc  func(height uint64, collections []*flow.LightCollection) error
	GuaranteesFunc   func(height uint64, guarantees []*flow.CollectionGuarantee) error
	TransactionsFunc func(height uint64, transactions []*flow.TransactionBody) error
	ResultsFunc      func(results []*flow.TransactionResult) error
	EventsFunc       func(height uint64, events []flow.Event) error
	SealsFunc        func(height uint64, seals []*flow.Seal) error
}

func BaselineWriter

func BaselineWriter(t *testing.T) *Writer

func (*Writer) Collections

func (w *Writer) Collections(height uint64, collections []*flow.LightCollection) error

func (*Writer) Commit

func (w *Writer) Commit(height uint64, commit flow.StateCommitment) error

func (*Writer) Events

func (w *Writer) Events(height uint64, events []flow.Event) error

func (*Writer) First

func (w *Writer) First(height uint64) error

func (*Writer) Guarantees added in v1.1.0

func (w *Writer) Guarantees(height uint64, guarantees []*flow.CollectionGuarantee) error

func (*Writer) Header

func (w *Writer) Header(height uint64, header *flow.Header) error

func (*Writer) Height

func (w *Writer) Height(blockID flow.Identifier, height uint64) error

func (*Writer) Last

func (w *Writer) Last(height uint64) error

func (*Writer) Payloads

func (w *Writer) Payloads(height uint64, paths []ledger.Path, values []*ledger.Payload) error

func (*Writer) Results added in v1.1.0

func (w *Writer) Results(results []*flow.TransactionResult) error

func (*Writer) Seals added in v1.1.0

func (w *Writer) Seals(height uint64, seals []*flow.Seal) error

func (*Writer) Transactions

func (w *Writer) Transactions(height uint64, transactions []*flow.TransactionBody) error

Jump to

Keyboard shortcuts

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