runtime_utils

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 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,
}
View Source
var LedgerOnWriteCounter = func(counter *int) LedgerOnWrite {
	return func(_, _, _ []byte) {
		(*counter)++
	}
}
View Source
var LedgerOnWriteEntries = func(entries *[]OwnerKeyValue) LedgerOnWrite {
	return func(owner, key, value []byte) {
		*entries = append(
			*entries,
			OwnerKeyValue{Owner: owner, Key: key, Value: value})
	}
}

Functions

func CheckAtreeStorageHealth added in v1.3.0

func CheckAtreeStorageHealth(tb testing.TB, storage atree.SlabStorage, expectedRootSlabIDs []atree.SlabID)

func DeploymentTransaction

func DeploymentTransaction(name string, contract []byte) []byte

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) sema.LocationHandlerFunc

func NewTransactionLocationGenerator

func NewTransactionLocationGenerator() func() common.TransactionLocation

func RemovalTransaction

func RemovalTransaction(name string) []byte

func TestStorageKey

func TestStorageKey(owner, key string) string

func UpdateTransaction

func UpdateTransaction(name string, contract []byte) []byte

Types

type LedgerOnRead added in v1.3.0

type LedgerOnRead func(owner, key, value []byte)

type LedgerOnWrite added in v1.3.0

type LedgerOnWrite func(owner, key, value []byte)

type OwnerKeyValue added in v1.3.0

type OwnerKeyValue struct {
	Owner, Key, Value []byte
}

type TestLedger

type TestLedger struct {
	StoredValues        map[string][]byte
	StorageIndices      map[string]uint64
	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)
	OnAllocateSlabIndex func(owner []byte) (atree.SlabIndex, error)
}

func NewTestLedger

func NewTestLedger(
	onRead LedgerOnRead,
	onWrite LedgerOnWrite,
) TestLedger

func NewTestLedgerWithData

func NewTestLedgerWithData(
	onRead func(owner, key, value []byte),
	onWrite func(owner, key, value []byte),
	storedValues map[string][]byte,
	storageIndices map[string]uint64,
) TestLedger

func (TestLedger) AllocateSlabIndex

func (s TestLedger) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error)

func (TestLedger) Dump

func (s TestLedger) Dump()

func (TestLedger) ForEach

func (s TestLedger) ForEach(f func(owner, key, value []byte) error) error

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 TestRuntime added in v1.7.0

type TestRuntime struct {
	runtime.Runtime
}

func NewTestRuntime added in v1.7.0

func NewTestRuntime() TestRuntime

func NewTestRuntimeWithConfig added in v1.7.0

func NewTestRuntimeWithConfig(config runtime.Config) TestRuntime

func (TestRuntime) ExecuteScript added in v1.7.0

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

func (TestRuntime) ExecuteTransaction added in v1.7.0

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

type TestRuntimeInterface

type TestRuntimeInterface struct {
	Storage TestLedger

	OnResolveLocation  sema.LocationHandlerFunc
	OnGetCode          func(_ runtime.Location) ([]byte, error)
	OnGetOrLoadProgram func(
		location runtime.Location,
		load func() (*runtime.Program, error),
	) (*runtime.Program, error)
	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 uint32) (*stdlib.AccountKey, error)
	OnRemoveAccountKey          func(address runtime.Address, index uint32) (*stdlib.AccountKey, error)
	OnAccountKeysCount          func(address runtime.Address) (uint32, 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)
	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]*runtime.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,
		duration time.Duration,
		attrs []attribute.KeyValue,
	)
	OnGenerateAccountID              func(address common.Address) (uint64, error)
	OnRecoverProgram                 func(program *ast.Program, location common.Location) ([]byte, error)
	OnValidateAccountCapabilitiesGet func(
		context interpreter.AccountCapabilityGetValidationContext,
		address interpreter.AddressValue,
		path interpreter.PathValue,
		wantedBorrowType *sema.ReferenceType,
		capabilityBorrowType *sema.ReferenceType,
	) (bool, error)
	OnValidateAccountCapabilitiesPublish func(
		context interpreter.AccountCapabilityPublishValidationContext,
		address interpreter.AddressValue,
		path interpreter.PathValue,
		capabilityBorrowType *interpreter.ReferenceStaticType,
	) (bool, error)
	OnMinimumRequiredVersion func() (string, error)
	// contains filtered or unexported fields
}

func (*TestRuntimeInterface) AccountKeysCount

func (i *TestRuntimeInterface) AccountKeysCount(address runtime.Address) (uint32, 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) AllocateSlabIndex

func (i *TestRuntimeInterface) AllocateSlabIndex(owner []byte) (atree.SlabIndex, 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) 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 uint32) (*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) GetOrLoadProgram

func (i *TestRuntimeInterface) GetOrLoadProgram(
	location runtime.Location,
	load func() (*runtime.Program, error),
) (
	program *runtime.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) InvalidateUpdatedPrograms

func (i *TestRuntimeInterface) InvalidateUpdatedPrograms()

func (*TestRuntimeInterface) MinimumRequiredVersion

func (i *TestRuntimeInterface) MinimumRequiredVersion() (string, 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,
	duration time.Duration,
	attrs []attribute.KeyValue,
)

func (*TestRuntimeInterface) RecoverProgram

func (i *TestRuntimeInterface) RecoverProgram(program *ast.Program, location common.Location) ([]byte, error)

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 uint32) (*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) 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) ValidateAccountCapabilitiesGet

func (i *TestRuntimeInterface) ValidateAccountCapabilitiesGet(
	context interpreter.AccountCapabilityGetValidationContext,
	address interpreter.AddressValue,
	path interpreter.PathValue,
	wantedBorrowType *sema.ReferenceType,
	capabilityBorrowType *sema.ReferenceType,
) (bool, error)

func (*TestRuntimeInterface) ValidateAccountCapabilitiesPublish

func (i *TestRuntimeInterface) ValidateAccountCapabilitiesPublish(
	context interpreter.AccountCapabilityPublishValidationContext,
	address interpreter.AddressValue,
	path interpreter.PathValue,
	capabilityBorrowType *interpreter.ReferenceStaticType,
) (bool, 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