runtime_utils

package
v1.0.0-preview.22 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTestInterpreterConfig = runtime.Config{
	AtreeValidationEnabled: true,
}

Functions

func MultipleIdentifierLocationResolver

func MultipleIdentifierLocationResolver(
	identifiers []ast.Identifier,
	location common.Location,
) (
	result []sema.ResolvedLocation,
	err error,
)

func NewLocationGenerator

func NewLocationGenerator[T ~[32]byte]() func() T

func NewScriptLocationGenerator

func NewScriptLocationGenerator() func() common.ScriptLocation

func NewSingleIdentifierLocationResolver

func NewSingleIdentifierLocationResolver(t testing.TB) func(
	identifiers []runtime.Identifier,
	location runtime.Location,
) (
	[]runtime.ResolvedLocation,
	error,
)

func NewTestInterpreter

func NewTestInterpreter(tb testing.TB) *interpreter.Interpreter

func NewTransactionLocationGenerator

func NewTransactionLocationGenerator() func() common.TransactionLocation

func NewUnmeteredInMemoryStorage

func NewUnmeteredInMemoryStorage() interpreter.Storage

Types

type TestInterpreterRuntime

type TestInterpreterRuntime struct {
	runtime.Runtime
}

func NewTestInterpreterRuntime

func NewTestInterpreterRuntime() TestInterpreterRuntime

func NewTestInterpreterRuntimeWithAttachments

func NewTestInterpreterRuntimeWithAttachments() TestInterpreterRuntime

func NewTestInterpreterRuntimeWithConfig

func NewTestInterpreterRuntimeWithConfig(config runtime.Config) TestInterpreterRuntime

func (TestInterpreterRuntime) ExecuteScript

func (r TestInterpreterRuntime) ExecuteScript(script runtime.Script, context runtime.Context) (cadence.Value, error)

func (TestInterpreterRuntime) ExecuteTransaction

func (r TestInterpreterRuntime) ExecuteTransaction(script runtime.Script, context runtime.Context) error

type TestLedger

type TestLedger struct {
	StoredValues           map[string][]byte
	OnValueExists          func(owner, key []byte) (exists bool, err error)
	OnGetValue             func(owner, key []byte) (value []byte, err error)
	OnSetValue             func(owner, key, value []byte) (err error)
	OnAllocateStorageIndex func(owner []byte) (atree.StorageIndex, error)
}

func NewTestLedger

func NewTestLedger(
	onRead func(owner, key, value []byte),
	onWrite func(owner, key, value []byte),
) TestLedger

func (TestLedger) AllocateStorageIndex

func (s TestLedger) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error)

func (TestLedger) Dump

func (s TestLedger) Dump()

func (TestLedger) GetValue

func (s TestLedger) GetValue(owner, key []byte) (value []byte, err error)

func (TestLedger) SetValue

func (s TestLedger) SetValue(owner, key, value []byte) (err error)

func (TestLedger) ValueExists

func (s TestLedger) ValueExists(owner, key []byte) (exists bool, err error)

type TestRuntimeInterface

type TestRuntimeInterface struct {
	Storage TestLedger

	OnResolveLocation func(
		identifiers []runtime.Identifier,
		location runtime.Location,
	) (
		[]runtime.ResolvedLocation,
		error,
	)
	OnGetCode          func(_ runtime.Location) ([]byte, error)
	OnGetAndSetProgram func(
		location runtime.Location,
		load func() (*interpreter.Program, error),
	) (*interpreter.Program, error)
	OnSetInterpreterSharedState func(state *interpreter.SharedState)
	OnGetInterpreterSharedState func() *interpreter.SharedState
	OnCreateAccount             func(payer runtime.Address) (address runtime.Address, err error)
	OnAddEncodedAccountKey      func(address runtime.Address, publicKey []byte) error
	OnRemoveEncodedAccountKey   func(address runtime.Address, index int) (publicKey []byte, err error)
	OnAddAccountKey             func(
		address runtime.Address,
		publicKey *stdlib.PublicKey,
		hashAlgo runtime.HashAlgorithm,
		weight int,
	) (*stdlib.AccountKey, error)
	OnGetAccountKey             func(address runtime.Address, index int) (*stdlib.AccountKey, error)
	OnRemoveAccountKey          func(address runtime.Address, index int) (*stdlib.AccountKey, error)
	OnAccountKeysCount          func(address runtime.Address) (uint64, error)
	OnUpdateAccountContractCode func(location common.AddressLocation, code []byte) error
	OnGetAccountContractCode    func(location common.AddressLocation) (code []byte, err error)
	OnRemoveAccountContractCode func(location common.AddressLocation) (err error)
	OnGetSigningAccounts        func() ([]runtime.Address, error)
	OnProgramLog                func(string)
	OnEmitEvent                 func(cadence.Event) error
	OnResourceOwnerChanged      func(
		interpreter *interpreter.Interpreter,
		resource *interpreter.CompositeValue,
		oldAddress common.Address,
		newAddress common.Address,
	)
	OnGenerateUUID       func() (uint64, error)
	OnMeterComputation   func(compKind common.ComputationKind, intensity uint) error
	OnDecodeArgument     func(b []byte, t cadence.Type) (cadence.Value, error)
	OnProgramParsed      func(location runtime.Location, duration time.Duration)
	OnProgramChecked     func(location runtime.Location, duration time.Duration)
	OnProgramInterpreted func(location runtime.Location, duration time.Duration)
	OnReadRandom         func([]byte) error
	OnVerifySignature    func(
		signature []byte,
		tag string,
		signedData []byte,
		publicKey []byte,
		signatureAlgorithm runtime.SignatureAlgorithm,
		hashAlgorithm runtime.HashAlgorithm,
	) (bool, error)
	OnHash func(
		data []byte,
		tag string,
		hashAlgorithm runtime.HashAlgorithm,
	) ([]byte, error)
	OnSetCadenceValue            func(owner runtime.Address, key string, value cadence.Value) (err error)
	OnGetAccountBalance          func(_ runtime.Address) (uint64, error)
	OnGetAccountAvailableBalance func(_ runtime.Address) (uint64, error)
	OnGetStorageUsed             func(_ runtime.Address) (uint64, error)
	OnGetStorageCapacity         func(_ runtime.Address) (uint64, error)
	Programs                     map[runtime.Location]*interpreter.Program
	OnImplementationDebugLog     func(message string) error
	OnValidatePublicKey          func(publicKey *stdlib.PublicKey) error
	OnBLSVerifyPOP               func(pk *stdlib.PublicKey, s []byte) (bool, error)
	OnBLSAggregateSignatures     func(sigs [][]byte) ([]byte, error)
	OnBLSAggregatePublicKeys     func(keys []*stdlib.PublicKey) (*stdlib.PublicKey, error)
	OnGetAccountContractNames    func(address runtime.Address) ([]string, error)
	OnRecordTrace                func(
		operation string,
		location runtime.Location,
		duration time.Duration,
		attrs []attribute.KeyValue,
	)
	OnMeterMemory       func(usage common.MemoryUsage) error
	OnComputationUsed   func() (uint64, error)
	OnMemoryUsed        func() (uint64, error)
	OnInteractionUsed   func() (uint64, error)
	OnGenerateAccountID func(address common.Address) (uint64, error)
	// contains filtered or unexported fields
}

func (*TestRuntimeInterface) AccountKeysCount

func (i *TestRuntimeInterface) AccountKeysCount(address runtime.Address) (uint64, error)

func (*TestRuntimeInterface) AddAccountKey

func (i *TestRuntimeInterface) AddAccountKey(
	address runtime.Address,
	publicKey *stdlib.PublicKey,
	hashAlgo runtime.HashAlgorithm,
	weight int,
) (*stdlib.AccountKey, error)

func (*TestRuntimeInterface) AddEncodedAccountKey

func (i *TestRuntimeInterface) AddEncodedAccountKey(address runtime.Address, publicKey []byte) error

func (*TestRuntimeInterface) AllocateStorageIndex

func (i *TestRuntimeInterface) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error)

func (*TestRuntimeInterface) BLSAggregatePublicKeys

func (i *TestRuntimeInterface) BLSAggregatePublicKeys(keys []*stdlib.PublicKey) (*stdlib.PublicKey, error)

func (*TestRuntimeInterface) BLSAggregateSignatures

func (i *TestRuntimeInterface) BLSAggregateSignatures(sigs [][]byte) ([]byte, error)

func (*TestRuntimeInterface) BLSVerifyPOP

func (i *TestRuntimeInterface) BLSVerifyPOP(key *stdlib.PublicKey, s []byte) (bool, error)

func (*TestRuntimeInterface) ComputationUsed

func (i *TestRuntimeInterface) ComputationUsed() (uint64, error)

func (*TestRuntimeInterface) CreateAccount

func (i *TestRuntimeInterface) CreateAccount(payer runtime.Address) (address runtime.Address, err error)

func (*TestRuntimeInterface) DecodeArgument

func (i *TestRuntimeInterface) DecodeArgument(b []byte, t cadence.Type) (cadence.Value, error)

func (*TestRuntimeInterface) EmitEvent

func (i *TestRuntimeInterface) EmitEvent(event cadence.Event) error

func (*TestRuntimeInterface) GenerateAccountID

func (i *TestRuntimeInterface) GenerateAccountID(address common.Address) (uint64, error)

func (*TestRuntimeInterface) GenerateUUID

func (i *TestRuntimeInterface) GenerateUUID() (uint64, error)

func (*TestRuntimeInterface) GetAccountAvailableBalance

func (i *TestRuntimeInterface) GetAccountAvailableBalance(address runtime.Address) (uint64, error)

func (*TestRuntimeInterface) GetAccountBalance

func (i *TestRuntimeInterface) GetAccountBalance(address runtime.Address) (uint64, error)

func (*TestRuntimeInterface) GetAccountContractCode

func (i *TestRuntimeInterface) GetAccountContractCode(location common.AddressLocation) (code []byte, err error)

func (*TestRuntimeInterface) GetAccountContractNames

func (i *TestRuntimeInterface) GetAccountContractNames(address runtime.Address) ([]string, error)

func (*TestRuntimeInterface) GetAccountKey

func (i *TestRuntimeInterface) GetAccountKey(address runtime.Address, index int) (*stdlib.AccountKey, error)

func (*TestRuntimeInterface) GetBlockAtHeight

func (i *TestRuntimeInterface) GetBlockAtHeight(height uint64) (block stdlib.Block, exists bool, err error)

func (*TestRuntimeInterface) GetCode

func (i *TestRuntimeInterface) GetCode(location runtime.Location) ([]byte, error)

func (*TestRuntimeInterface) GetCurrentBlockHeight

func (i *TestRuntimeInterface) GetCurrentBlockHeight() (uint64, error)

func (*TestRuntimeInterface) GetInterpreterSharedState

func (i *TestRuntimeInterface) GetInterpreterSharedState() *interpreter.SharedState

func (*TestRuntimeInterface) GetOrLoadProgram

func (i *TestRuntimeInterface) GetOrLoadProgram(
	location runtime.Location,
	load func() (*interpreter.Program, error),
) (
	program *interpreter.Program,
	err error,
)

func (*TestRuntimeInterface) GetSigningAccounts

func (i *TestRuntimeInterface) GetSigningAccounts() ([]runtime.Address, error)

func (*TestRuntimeInterface) GetStorageCapacity

func (i *TestRuntimeInterface) GetStorageCapacity(address runtime.Address) (uint64, error)

func (*TestRuntimeInterface) GetStorageUsed

func (i *TestRuntimeInterface) GetStorageUsed(address runtime.Address) (uint64, error)

func (*TestRuntimeInterface) GetValue

func (i *TestRuntimeInterface) GetValue(owner, key []byte) (value []byte, err error)

func (*TestRuntimeInterface) Hash

func (i *TestRuntimeInterface) Hash(data []byte, tag string, hashAlgorithm runtime.HashAlgorithm) ([]byte, error)

func (*TestRuntimeInterface) ImplementationDebugLog

func (i *TestRuntimeInterface) ImplementationDebugLog(message string) error

func (*TestRuntimeInterface) InteractionUsed

func (i *TestRuntimeInterface) InteractionUsed() (uint64, error)

func (*TestRuntimeInterface) InvalidateUpdatedPrograms

func (i *TestRuntimeInterface) InvalidateUpdatedPrograms()

func (*TestRuntimeInterface) MemoryUsed

func (i *TestRuntimeInterface) MemoryUsed() (uint64, error)

func (*TestRuntimeInterface) MeterComputation

func (i *TestRuntimeInterface) MeterComputation(compKind common.ComputationKind, intensity uint) error

func (*TestRuntimeInterface) MeterMemory

func (i *TestRuntimeInterface) MeterMemory(usage common.MemoryUsage) error

func (*TestRuntimeInterface) ProgramChecked

func (i *TestRuntimeInterface) ProgramChecked(location runtime.Location, duration time.Duration)

func (*TestRuntimeInterface) ProgramInterpreted

func (i *TestRuntimeInterface) ProgramInterpreted(location runtime.Location, duration time.Duration)

func (*TestRuntimeInterface) ProgramLog

func (i *TestRuntimeInterface) ProgramLog(message string) error

func (*TestRuntimeInterface) ProgramParsed

func (i *TestRuntimeInterface) ProgramParsed(location runtime.Location, duration time.Duration)

func (*TestRuntimeInterface) ReadRandom

func (i *TestRuntimeInterface) ReadRandom(buffer []byte) error

func (*TestRuntimeInterface) RecordTrace

func (i *TestRuntimeInterface) RecordTrace(
	operation string,
	location runtime.Location,
	duration time.Duration,
	attrs []attribute.KeyValue,
)

func (*TestRuntimeInterface) RemoveAccountContractCode

func (i *TestRuntimeInterface) RemoveAccountContractCode(location common.AddressLocation) (err error)

func (*TestRuntimeInterface) ResolveLocation

func (i *TestRuntimeInterface) ResolveLocation(
	identifiers []runtime.Identifier,
	location runtime.Location,
) ([]runtime.ResolvedLocation, error)

func (*TestRuntimeInterface) ResourceOwnerChanged

func (i *TestRuntimeInterface) ResourceOwnerChanged(
	interpreter *interpreter.Interpreter,
	resource *interpreter.CompositeValue,
	oldOwner common.Address,
	newOwner common.Address,
)

func (*TestRuntimeInterface) RevokeAccountKey

func (i *TestRuntimeInterface) RevokeAccountKey(address runtime.Address, index int) (*stdlib.AccountKey, error)

func (*TestRuntimeInterface) RevokeEncodedAccountKey

func (i *TestRuntimeInterface) RevokeEncodedAccountKey(address runtime.Address, index int) ([]byte, error)

func (*TestRuntimeInterface) SetCadenceValue

func (i *TestRuntimeInterface) SetCadenceValue(owner common.Address, key string, value cadence.Value) (err error)

func (*TestRuntimeInterface) SetInterpreterSharedState

func (i *TestRuntimeInterface) SetInterpreterSharedState(state *interpreter.SharedState)

func (*TestRuntimeInterface) SetValue

func (i *TestRuntimeInterface) SetValue(owner, key, value []byte) (err error)

func (*TestRuntimeInterface) UpdateAccountContractCode

func (i *TestRuntimeInterface) UpdateAccountContractCode(location common.AddressLocation, code []byte) (err error)

func (*TestRuntimeInterface) ValidatePublicKey

func (i *TestRuntimeInterface) ValidatePublicKey(key *stdlib.PublicKey) error

func (*TestRuntimeInterface) ValueExists

func (i *TestRuntimeInterface) ValueExists(owner, key []byte) (exists bool, err error)

func (*TestRuntimeInterface) VerifySignature

func (i *TestRuntimeInterface) VerifySignature(
	signature []byte,
	tag string,
	signedData []byte,
	publicKey []byte,
	signatureAlgorithm runtime.SignatureAlgorithm,
	hashAlgorithm runtime.HashAlgorithm,
) (bool, error)

Jump to

Keyboard shortcuts

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