Documentation ¶
Overview ¶
- Flow Emulator *
- Copyright 2019 Dapper Labs, Inc. *
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at *
- http://www.apache.org/licenses/LICENSE-2.0 *
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Package emulator provides an emulated version of the Flow blockchain that can be used for development purposes.
This package can be used as a library or as a standalone application.
When used as a library, this package provides tools to write programmatic tests for Flow applications.
When used as a standalone application, this package implements the Flow Access API and is fully-compatible with Flow gRPC client libraries.
Index ¶
- Constants
- type AccountNotFoundError
- type AccountStorage
- type BlockNotFoundByHeightError
- type BlockNotFoundByIDError
- type BlockNotFoundError
- type Blockchain
- func (b *Blockchain) AddTransaction(tx sdk.Transaction) error
- func (b *Blockchain) CommitBlock() (*flowgo.Block, error)
- func (b *Blockchain) CreateAccount(publicKeys []*sdk.AccountKey, contracts []templates.Contract) (sdk.Address, error)
- func (b *Blockchain) ExecuteAndCommitBlock() (*flowgo.Block, []*types.TransactionResult, error)
- func (b *Blockchain) ExecuteBlock() ([]*types.TransactionResult, error)
- func (b *Blockchain) ExecuteNextTransaction() (*types.TransactionResult, error)
- func (b *Blockchain) ExecuteScript(script []byte, arguments [][]byte) (*types.ScriptResult, error)
- func (b *Blockchain) ExecuteScriptAtBlock(script []byte, arguments [][]byte, blockHeight uint64) (*types.ScriptResult, error)
- func (b *Blockchain) GetAccount(address sdk.Address) (*sdk.Account, error)
- func (b *Blockchain) GetAccountAtBlock(address sdk.Address, blockHeight uint64) (*sdk.Account, error)
- func (b *Blockchain) GetAccountStorage(address sdk.Address) (*AccountStorage, error)
- func (b *Blockchain) GetBlockByHeight(height uint64) (*flowgo.Block, error)
- func (b *Blockchain) GetBlockByID(id sdk.Identifier) (*flowgo.Block, error)
- func (b *Blockchain) GetChain() flowgo.Chain
- func (b *Blockchain) GetCollection(colID sdk.Identifier) (*sdk.Collection, error)
- func (b *Blockchain) GetEventsByHeight(blockHeight uint64, eventType string) ([]sdk.Event, error)
- func (b *Blockchain) GetLatestBlock() (*flowgo.Block, error)
- func (b *Blockchain) GetTransaction(id sdk.Identifier) (*sdk.Transaction, error)
- func (b *Blockchain) GetTransactionResult(ID sdk.Identifier) (*sdk.TransactionResult, error)
- func (b *Blockchain) PendingBlockID() flowgo.Identifier
- func (b *Blockchain) PendingBlockTimestamp() time.Time
- func (b *Blockchain) PendingBlockView() uint64
- func (b *Blockchain) ResetPendingBlock() error
- func (b *Blockchain) ServiceKey() ServiceKey
- type CollectionNotFoundError
- type DuplicateTransactionError
- type ExecutionError
- type ExpiredTransactionError
- type IncompleteTransactionError
- type IndexedTransactionResult
- type InvalidStateVersionError
- type InvalidTransactionGasLimitError
- type InvalidTransactionScriptError
- type NotFoundError
- type Option
- func WithChainID(chainID flowgo.ChainID) Option
- func WithGenesisTokenSupply(supply cadence.UFix64) Option
- func WithLogger(logger zerolog.Logger) Option
- func WithMinimumStorageReservation(minimumStorageReservation cadence.UFix64) Option
- func WithScriptGasLimit(limit uint64) Option
- func WithServicePrivateKey(privateKey sdkcrypto.PrivateKey, sigAlgo sdkcrypto.SignatureAlgorithm, ...) Option
- func WithServicePublicKey(servicePublicKey sdkcrypto.PublicKey, sigAlgo sdkcrypto.SignatureAlgorithm, ...) Option
- func WithSimpleAddresses() Option
- func WithStorageLimitEnabled(enabled bool) Option
- func WithStorageMBPerFLOW(storageMBPerFLOW cadence.UFix64) Option
- func WithStore(store storage.Store) Option
- func WithTransactionExpiry(expiry uint) Option
- func WithTransactionFeesEnabled(enabled bool) Option
- func WithTransactionMaxGasLimit(maxLimit uint64) Option
- func WithTransactionValidationEnabled(enabled bool) Option
- type PendingBlockCommitBeforeExecutionError
- type PendingBlockMidExecutionError
- type PendingBlockTransactionsExhaustedError
- type ServiceKey
- type StorageError
- type StorageItem
- type TransactionNotFoundError
- type TransactionValidationError
Constants ¶
const DefaultServiceKeyHashAlgo = sdkcrypto.SHA3_256
const DefaultServiceKeySigAlgo = sdkcrypto.ECDSA_P256
const MaxViewIncrease = 3
MaxViewIncrease represents the largest difference in view number between two consecutive blocks. The minimum view increment is 1.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountNotFoundError ¶
An AccountNotFoundError indicates that an account could not be found.
func (*AccountNotFoundError) Error ¶
func (e *AccountNotFoundError) Error() string
type AccountStorage ¶ added in v0.34.0
type AccountStorage struct { Address sdk.Address Private StorageItem Public StorageItem Storage StorageItem Account *flow.Account }
func NewAccountStorage ¶ added in v0.34.0
func NewAccountStorage( address sdk.Address, account *flow.Account, storage *runtime.Storage, inter *interpreter.Interpreter, ) (*AccountStorage, error)
NewAccountStorage creates an instance of the storage that holds the values for each storage path.
type BlockNotFoundByHeightError ¶
type BlockNotFoundByHeightError struct {
Height uint64
}
A BlockNotFoundByHeightError indicates that a block could not be found at the specified height.
func (*BlockNotFoundByHeightError) Error ¶
func (e *BlockNotFoundByHeightError) Error() string
type BlockNotFoundByIDError ¶
type BlockNotFoundByIDError struct {
ID flowsdk.Identifier
}
A BlockNotFoundByIDError indicates that a block with the specified ID could not be found.
func (*BlockNotFoundByIDError) Error ¶
func (e *BlockNotFoundByIDError) Error() string
type BlockNotFoundError ¶
type BlockNotFoundError interface {
// contains filtered or unexported methods
}
A BlockNotFoundError indicates that a block could not be found.
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain emulates the functionality of the Flow blockchain.
func NewBlockchain ¶
func NewBlockchain(opts ...Option) (*Blockchain, error)
NewBlockchain instantiates a new emulated blockchain with the provided options.
func (*Blockchain) AddTransaction ¶
func (b *Blockchain) AddTransaction(tx sdk.Transaction) error
AddTransaction validates a transaction and adds it to the current pending block.
func (*Blockchain) CommitBlock ¶
func (b *Blockchain) CommitBlock() (*flowgo.Block, error)
CommitBlock seals the current pending block and saves it to storage.
This function clears the pending transaction pool and resets the pending block.
func (*Blockchain) CreateAccount ¶
func (b *Blockchain) CreateAccount(publicKeys []*sdk.AccountKey, contracts []templates.Contract) (sdk.Address, error)
CreateAccount submits a transaction to create a new account with the given account keys and contracts. The transaction is paid by the service account.
func (*Blockchain) ExecuteAndCommitBlock ¶
func (b *Blockchain) ExecuteAndCommitBlock() (*flowgo.Block, []*types.TransactionResult, error)
ExecuteAndCommitBlock is a utility that combines ExecuteBlock with CommitBlock.
func (*Blockchain) ExecuteBlock ¶
func (b *Blockchain) ExecuteBlock() ([]*types.TransactionResult, error)
ExecuteBlock executes the remaining transactions in pending block.
func (*Blockchain) ExecuteNextTransaction ¶
func (b *Blockchain) ExecuteNextTransaction() (*types.TransactionResult, error)
ExecuteNextTransaction executes the next indexed transaction in pending block.
func (*Blockchain) ExecuteScript ¶
func (b *Blockchain) ExecuteScript(script []byte, arguments [][]byte) (*types.ScriptResult, error)
ExecuteScript executes a read-only script against the world state and returns the result.
func (*Blockchain) ExecuteScriptAtBlock ¶
func (b *Blockchain) ExecuteScriptAtBlock(script []byte, arguments [][]byte, blockHeight uint64) (*types.ScriptResult, error)
func (*Blockchain) GetAccount ¶
GetAccount returns the account for the given address.
func (*Blockchain) GetAccountAtBlock ¶
func (b *Blockchain) GetAccountAtBlock(address sdk.Address, blockHeight uint64) (*sdk.Account, error)
GetAccountAtBlock returns the account for the given address at specified block height.
func (*Blockchain) GetAccountStorage ¶ added in v0.34.0
func (b *Blockchain) GetAccountStorage(address sdk.Address) (*AccountStorage, error)
func (*Blockchain) GetBlockByHeight ¶
func (b *Blockchain) GetBlockByHeight(height uint64) (*flowgo.Block, error)
GetBlockByHeight gets a block by height.
func (*Blockchain) GetBlockByID ¶
func (b *Blockchain) GetBlockByID(id sdk.Identifier) (*flowgo.Block, error)
GetBlockByID gets a block by ID.
func (*Blockchain) GetChain ¶ added in v0.14.2
func (b *Blockchain) GetChain() flowgo.Chain
func (*Blockchain) GetCollection ¶
func (b *Blockchain) GetCollection(colID sdk.Identifier) (*sdk.Collection, error)
func (*Blockchain) GetEventsByHeight ¶
GetEventsByHeight returns the events in the block at the given height, optionally filtered by type.
func (*Blockchain) GetLatestBlock ¶
func (b *Blockchain) GetLatestBlock() (*flowgo.Block, error)
GetLatestBlock gets the latest sealed block.
func (*Blockchain) GetTransaction ¶
func (b *Blockchain) GetTransaction(id sdk.Identifier) (*sdk.Transaction, error)
GetTransaction gets an existing transaction by ID.
The function first looks in the pending block, then the current blockchain state.
func (*Blockchain) GetTransactionResult ¶
func (b *Blockchain) GetTransactionResult(ID sdk.Identifier) (*sdk.TransactionResult, error)
func (*Blockchain) PendingBlockID ¶
func (b *Blockchain) PendingBlockID() flowgo.Identifier
PendingBlockID returns the ID of the pending block.
func (*Blockchain) PendingBlockTimestamp ¶
func (b *Blockchain) PendingBlockTimestamp() time.Time
PendingBlockTimestamp returns the Timestamp of the pending block.
func (*Blockchain) PendingBlockView ¶ added in v0.17.2
func (b *Blockchain) PendingBlockView() uint64
PendingBlockView returns the view of the pending block.
func (*Blockchain) ResetPendingBlock ¶
func (b *Blockchain) ResetPendingBlock() error
ResetPendingBlock clears the transactions in pending block.
func (*Blockchain) ServiceKey ¶
func (b *Blockchain) ServiceKey() ServiceKey
ServiceKey returns the service private key for this blockchain.
type CollectionNotFoundError ¶
type CollectionNotFoundError struct {
ID flowsdk.Identifier
}
A CollectionNotFoundError indicates that a collection could not be found.
func (*CollectionNotFoundError) Error ¶
func (e *CollectionNotFoundError) Error() string
type DuplicateTransactionError ¶
type DuplicateTransactionError struct {
TxID flowgo.Identifier
}
A DuplicateTransactionError indicates that a transaction has already been submitted.
func (*DuplicateTransactionError) Error ¶
func (e *DuplicateTransactionError) Error() string
type ExecutionError ¶
An ExecutionError occurs when a transaction fails to execute.
func (*ExecutionError) Error ¶
func (e *ExecutionError) Error() string
type ExpiredTransactionError ¶
type ExpiredTransactionError struct {
RefHeight, FinalHeight uint64
}
ExpiredTransactionError indicates that a transaction has expired.
func (*ExpiredTransactionError) Error ¶
func (e *ExpiredTransactionError) Error() string
type IncompleteTransactionError ¶
type IncompleteTransactionError struct {
MissingFields []string
}
IncompleteTransactionError indicates that a transaction is missing one or more required fields.
func (*IncompleteTransactionError) Error ¶
func (e *IncompleteTransactionError) Error() string
type IndexedTransactionResult ¶
type IndexedTransactionResult struct { Transaction *fvm.TransactionProcedure Index uint32 }
type InvalidStateVersionError ¶
An InvalidStateVersionError indicates that a state version hash provided is invalid.
func (*InvalidStateVersionError) Error ¶
func (e *InvalidStateVersionError) Error() string
type InvalidTransactionGasLimitError ¶
InvalidTransactionGasLimitError indicates that a transaction specifies a gas limit that exceeds the maximum.
func (*InvalidTransactionGasLimitError) Error ¶
func (e *InvalidTransactionGasLimitError) Error() string
type InvalidTransactionScriptError ¶
type InvalidTransactionScriptError struct {
ParserErr error
}
InvalidTransactionScriptError indicates that a transaction contains an invalid Cadence script.
func (*InvalidTransactionScriptError) Error ¶
func (e *InvalidTransactionScriptError) Error() string
func (*InvalidTransactionScriptError) Unwrap ¶
func (e *InvalidTransactionScriptError) Unwrap() error
type NotFoundError ¶
type NotFoundError interface {
// contains filtered or unexported methods
}
A NotFoundError indicates that an entity could not be found.
type Option ¶
type Option func(*config)
Option is a function applying a change to the emulator config.
func WithChainID ¶ added in v0.36.0
WithChainID sets chain type for address generation The default is emulator.
func WithGenesisTokenSupply ¶
WithGenesisTokenSupply sets the genesis token supply.
func WithLogger ¶ added in v0.33.4
WithLogger sets the logger
func WithMinimumStorageReservation ¶ added in v0.23.0
WithMinimumStorageReservation sets the minimum account balance.
The cost of creating new accounts is also set to this value. The default is taken from fvm.DefaultMinimumStorageReservation
func WithScriptGasLimit ¶
WithScriptGasLimit sets the gas limit for scripts.
This limit does not affect transactions, which declare their own limit. Use WithTransactionMaxGasLimit to set the maximum gas limit for transactions.
func WithServicePrivateKey ¶ added in v0.27.3
func WithServicePrivateKey( privateKey sdkcrypto.PrivateKey, sigAlgo sdkcrypto.SignatureAlgorithm, hashAlgo sdkcrypto.HashAlgorithm, ) Option
WithServicePrivateKey sets the service key from private key.
func WithServicePublicKey ¶
func WithServicePublicKey( servicePublicKey sdkcrypto.PublicKey, sigAlgo sdkcrypto.SignatureAlgorithm, hashAlgo sdkcrypto.HashAlgorithm, ) Option
WithServicePublicKey sets the service key from a public key.
func WithSimpleAddresses ¶
func WithSimpleAddresses() Option
WithSimpleAddresses enables simple addresses, which are sequential starting with 0x01.
func WithStorageLimitEnabled ¶ added in v0.14.0
WithStorageLimitEnabled enables/disables limiting account storage used to their storage capacity.
If set to false, accounts can store any amount of data, otherwise they can only store as much as their storage capacity. The default is true.
func WithStorageMBPerFLOW ¶ added in v0.23.0
WithStorageMBPerFLOW sets the cost of a megabyte of storage in FLOW
the default is taken from fvm.DefaultStorageMBPerFLOW
func WithTransactionExpiry ¶
WithTransactionExpiry sets the transaction expiry measured in blocks.
If set to zero, transaction expiry is disabled and the reference block ID field is not required.
func WithTransactionFeesEnabled ¶ added in v0.14.2
WithTransactionFeesEnabled enables/disables transaction fees.
If set to false transactions don't cost any flow. The default is false.
func WithTransactionMaxGasLimit ¶ added in v0.12.4
WithTransactionMaxGasLimit sets the maximum gas limit for transactions.
Individual transactions will still be bounded by the limit they declare. This function sets the maximum limit that any transaction can declare.
This limit does not affect script executions. Use WithScriptGasLimit to set the gas limit for script executions.
func WithTransactionValidationEnabled ¶ added in v0.34.0
WithTransactionValidationEnabled enables/disables transaction validation.
If set to false, the emulator will not verify transaction signatures or validate sequence numbers.
The default is true.
type PendingBlockCommitBeforeExecutionError ¶
type PendingBlockCommitBeforeExecutionError struct {
BlockID flowgo.Identifier
}
A PendingBlockCommitBeforeExecutionError indicates that the current pending block has not been executed (cannot commit).
func (*PendingBlockCommitBeforeExecutionError) Error ¶
func (e *PendingBlockCommitBeforeExecutionError) Error() string
type PendingBlockMidExecutionError ¶
type PendingBlockMidExecutionError struct {
BlockID flowgo.Identifier
}
A PendingBlockMidExecutionError indicates that the current pending block is mid-execution.
func (*PendingBlockMidExecutionError) Error ¶
func (e *PendingBlockMidExecutionError) Error() string
type PendingBlockTransactionsExhaustedError ¶
type PendingBlockTransactionsExhaustedError struct {
BlockID flowgo.Identifier
}
A PendingBlockTransactionsExhaustedError indicates that the current pending block has finished executing (no more transactions to execute).
func (*PendingBlockTransactionsExhaustedError) Error ¶
func (e *PendingBlockTransactionsExhaustedError) Error() string
type ServiceKey ¶
type ServiceKey struct { Index int Address sdk.Address SequenceNumber uint64 PrivateKey sdkcrypto.PrivateKey PublicKey sdkcrypto.PublicKey HashAlgo sdkcrypto.HashAlgorithm SigAlgo sdkcrypto.SignatureAlgorithm Weight int }
func DefaultServiceKey ¶
func DefaultServiceKey() ServiceKey
func GenerateDefaultServiceKey ¶
func GenerateDefaultServiceKey( sigAlgo sdkcrypto.SignatureAlgorithm, hashAlgo sdkcrypto.HashAlgorithm, ) ServiceKey
func (ServiceKey) AccountKey ¶
func (s ServiceKey) AccountKey() *sdk.AccountKey
type StorageError ¶
type StorageError struct {
// contains filtered or unexported fields
}
A StorageError indicates that an error occurred in the storage provider.
func (*StorageError) Error ¶
func (e *StorageError) Error() string
func (*StorageError) Unwrap ¶
func (e *StorageError) Unwrap() error
type StorageItem ¶ added in v0.34.0
type TransactionNotFoundError ¶
type TransactionNotFoundError struct {
ID flowgo.Identifier
}
A TransactionNotFoundError indicates that a transaction could not be found.
func (*TransactionNotFoundError) Error ¶
func (e *TransactionNotFoundError) Error() string
type TransactionValidationError ¶
type TransactionValidationError interface {
// contains filtered or unexported methods
}
A TransactionValidationError indicates that a submitted transaction is invalid.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
backend/mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
Package storage defines the interface and implementations for interacting with persistent chain state.
|
Package storage defines the interface and implementations for interacting with persistent chain state. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
utils
|
|