worldmock

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const SCAddressNumLeadingZeros = 8

SCAddressNumLeadingZeros is the number of zero bytes every smart contract address begins with.

Variables

DCDTNonceKeyPrefix is the prefix of storage keys belonging to DCDT nonces.

DCDTRoleKeyPrefix is the prefix of storage keys belonging to DCDT roles.

DCDTTokenKeyPrefix is the prefix of storage keys belonging to DCDT tokens.

View Source
var ErrBuiltinFuncWrapperNotInitialized = errors.New("builtin function not found or container not initialized")

ErrBuiltinFuncWrapperNotInitialized means that the builtin function wrapper was used before initialization.

View Source
var ErrInsufficientFunds = errors.New("insufficient funds")

ErrInsufficientFunds signals the funds are insufficient for the move balance operation but the transaction fee is covered by the current balance.

View Source
var ErrInvalidAddressLength = errors.New("invalid address length")

ErrInvalidAddressLength indicates an incorrect length given for an address.

View Source
var ErrMarshallingProto = errors.New("can not serialize the object")

ErrMarshallingProto is raised when the object does not implement proto.Message

View Source
var ErrNegativeValue = errors.New("negative value")

ErrNegativeValue signals that a negative value has been detected and it is not allowed

View Source
var ErrNilWorldMock = errors.New("nil worldmock")

ErrNilWorldMock signals that the WorldMock is nil but shouldn't be.

View Source
var ErrOperationNotPermitted = errors.New("operation not permitted")

ErrOperationNotPermitted indicates an operation rejected due to insufficient permissions.

View Source
var ErrTrieHandlingNotImplemented = errors.New("trie handling not implemented")

ErrTrieHandlingNotImplemented indicates that no trie-related operations are currently implemented.

View Source
var ErrUnmarshallingProto = errors.New("obj does not implement proto.Message")

ErrUnmarshallingProto is raised when the object that needs to be unmarshaled does not implement proto.Message

View Source
var WorldMarshalizer = &GogoProtoMarshalizer{}

WorldMarshalizer is the global marshalizer to be used by the components of the BuiltinFunctionsWrapper.

Functions

func GenerateMockAddress

func GenerateMockAddress(creatorAddress []byte, creatorNonce uint64) []byte

GenerateMockAddress simulates creation of a new address by the protocol.

func GetTokenNameFromKey

func GetTokenNameFromKey(key []byte) []byte

GetTokenNameFromKey extracts the token name from the given storage key; it does not check whether the key is indeed a token key or not.

func IsDCDTKey

func IsDCDTKey(key []byte) bool

IsDCDTKey returns true if the given storage key is DCDT-related

func IsNonceKey

func IsNonceKey(key []byte) bool

IsNonceKey returns true if the given storage key belongs to an DCDT nonce.

func IsRoleKey

func IsRoleKey(key []byte) bool

IsRoleKey returns true if the given storage key belongs to an DCDT role.

func IsSmartContractAddress

func IsSmartContractAddress(address []byte) bool

IsSmartContractAddress verifies the address format. Smart contract addresses start with 8 bytes of 0.

func IsTokenKey

func IsTokenKey(key []byte) bool

IsTokenKey returns true if the given storage key belongs to an DCDT token.

func MakeLastNonceKey

func MakeLastNonceKey(tokenName []byte) []byte

MakeLastNonceKey creates the storage key corresponding to the last nonce of the given tokenName.

func MakeTokenKey

func MakeTokenKey(tokenName []byte, nonce uint64) []byte

MakeTokenKey creates the storage key corresponding to the given tokenName.

func MakeTokenRolesKey

func MakeTokenRolesKey(tokenName []byte) []byte

MakeTokenRolesKey creates the storage key corresponding to the roles for the given tokenName.

Types

type Account

type Account struct {
	Exists          bool
	Address         []byte
	Nonce           uint64
	Balance         *big.Int
	BalanceDelta    *big.Int
	Storage         map[string][]byte
	RootHash        []byte
	Code            []byte
	CodeHash        []byte
	CodeMetadata    []byte
	OwnerAddress    []byte
	AsyncCallData   string
	Username        []byte
	DeveloperReward *big.Int
	ShardID         uint32
	IsSmartContract bool
	MockWorld       *MockWorld
}

Account holds the account info

func (*Account) AccountDataHandler

func (a *Account) AccountDataHandler() vmcommon.AccountDataHandler

AccountDataHandler -

func (*Account) AddToBalance

func (a *Account) AddToBalance(value *big.Int) error

AddToBalance -

func (*Account) AddToDeveloperReward

func (a *Account) AddToDeveloperReward(value *big.Int)

AddToDeveloperReward -

func (*Account) AddressBytes

func (a *Account) AddressBytes() []byte

AddressBytes -

func (*Account) ChangeOwnerAddress

func (a *Account) ChangeOwnerAddress(sender []byte, newAddress []byte) error

ChangeOwnerAddress -

func (*Account) ClaimDeveloperRewards

func (a *Account) ClaimDeveloperRewards(sender []byte) (*big.Int, error)

ClaimDeveloperRewards -

func (*Account) ClearDataCaches

func (a *Account) ClearDataCaches()

ClearDataCaches -

func (*Account) Clone

func (a *Account) Clone() *Account

Clone -

func (*Account) DirtyData

func (a *Account) DirtyData() map[string][]byte

DirtyData -

func (*Account) GetBalance

func (a *Account) GetBalance() *big.Int

GetBalance -

func (*Account) GetCode

func (a *Account) GetCode() []byte

GetCode -

func (*Account) GetCodeHash

func (a *Account) GetCodeHash() []byte

GetCodeHash -

func (*Account) GetCodeMetadata

func (a *Account) GetCodeMetadata() []byte

GetCodeMetadata -

func (*Account) GetDeveloperReward

func (a *Account) GetDeveloperReward() *big.Int

GetDeveloperReward -

func (*Account) GetFullMockDCDTData

func (a *Account) GetFullMockDCDTData() (map[string]*MockDCDTData, error)

GetFullMockDCDTData returns the information about all the DCDT tokens held by the account.

func (*Account) GetNonce

func (a *Account) GetNonce() uint64

GetNonce -

func (*Account) GetOwnerAddress

func (a *Account) GetOwnerAddress() []byte

GetOwnerAddress -

func (*Account) GetRootHash

func (a *Account) GetRootHash() []byte

GetRootHash -

func (*Account) GetTokenBalance

func (a *Account) GetTokenBalance(tokenKey []byte) (*big.Int, error)

GetTokenBalance returns the DCDT balance of the account, specified by the token key.

func (*Account) GetTokenBalanceByName

func (a *Account) GetTokenBalanceByName(tokenName string) (*big.Int, error)

GetTokenBalanceByName returns the DCDT balance of the account, specified by the token name.

func (*Account) GetTokenBalanceUint64

func (a *Account) GetTokenBalanceUint64(tokenKey []byte) (uint64, error)

GetTokenBalanceUint64 returns the DCDT balance of the account, specified by the token key.

func (*Account) GetTokenData

func (a *Account) GetTokenData(tokenKey []byte) (*dcdt.DCDigitalToken, error)

GetTokenData gets the DCDT information related to a token from the storage of the account.

func (*Account) GetTokenKeys

func (a *Account) GetTokenKeys() [][]byte

GetTokenKeys returns the storage keys of all the DCDT tokens owned by the account.

func (*Account) GetTokenRoles

func (a *Account) GetTokenRoles(tokenName []byte) ([][]byte, error)

GetTokenRoles returns the roles of the account for the specified tokenName.

func (*Account) GetUserName

func (a *Account) GetUserName() []byte

GetUserName -

func (*Account) IncreaseNonce

func (a *Account) IncreaseNonce(nonce uint64)

IncreaseNonce -

func (*Account) IsInterfaceNil

func (a *Account) IsInterfaceNil() bool

IsInterfaceNil -

func (*Account) MigrateDataTrieLeaves

func (a *Account) MigrateDataTrieLeaves(_ vmcommon.ArgsMigrateDataTrieLeaves) error

MigrateDataTrieLeaves -

func (*Account) RetrieveValue

func (a *Account) RetrieveValue(key []byte) ([]byte, uint32, error)

RetrieveValue -

func (*Account) SaveKeyValue

func (a *Account) SaveKeyValue(key []byte, value []byte) error

SaveKeyValue -

func (*Account) SetBalance

func (a *Account) SetBalance(balance int64)

SetBalance -

func (*Account) SetCode

func (a *Account) SetCode(code []byte)

SetCode -

func (*Account) SetCodeAndMetadata

func (a *Account) SetCodeAndMetadata(code []byte, codeMetadata *vmcommon.CodeMetadata)

SetCodeAndMetadata changes the account code, as well as all fields depending on it: CodeHash, IsSmartContract, CodeMetadata. The code metadata must be given explicitly.

func (*Account) SetCodeHash

func (a *Account) SetCodeHash(hash []byte)

SetCodeHash -

func (*Account) SetCodeMetadata

func (a *Account) SetCodeMetadata(codeMetadata []byte)

SetCodeMetadata -

func (*Account) SetLastNonce

func (a *Account) SetLastNonce(tokenName []byte, lastNonce uint64) error

SetLastNonce writes the last nonce of a specified DCDT into the storage.

func (*Account) SetLastNonces

func (a *Account) SetLastNonces(lastNonces map[string]uint64) error

SetLastNonces writes the last nonces of each specified DCDT into the storage.

func (*Account) SetOwnerAddress

func (a *Account) SetOwnerAddress(address []byte)

SetOwnerAddress -

func (*Account) SetRootHash

func (a *Account) SetRootHash(hash []byte)

SetRootHash -

func (*Account) SetTokenBalance

func (a *Account) SetTokenBalance(tokenKey []byte, balance *big.Int) error

SetTokenBalance sets the DCDT balance of the account, specified by the token key.

func (*Account) SetTokenBalanceUint64

func (a *Account) SetTokenBalanceUint64(tokenKey []byte, balance uint64) error

SetTokenBalanceUint64 sets the DCDT balance of the account, specified by the token key.

func (*Account) SetTokenData

func (a *Account) SetTokenData(tokenKey []byte, tokenData *dcdt.DCDigitalToken) error

SetTokenData sets the DCDT information related to a token into the storage of the account.

func (*Account) SetTokenRoles

func (a *Account) SetTokenRoles(tokenName []byte, roles [][]byte) error

SetTokenRoles sets the specified roles to the account, corresponding to the given tokenName.

func (*Account) SetTokenRolesAsStrings

func (a *Account) SetTokenRolesAsStrings(tokenName []byte, rolesAsStrings []string) error

SetTokenRolesAsStrings sets the specified roles to the account, corresponding to the given tokenName.

func (*Account) SetUserName

func (a *Account) SetUserName(userName []byte)

SetUserName -

func (*Account) StorageValue

func (a *Account) StorageValue(key string) []byte

StorageValue yields the storage value for key, default 0

func (*Account) SubFromBalance

func (a *Account) SubFromBalance(value *big.Int) error

SubFromBalance -

func (*Account) Validate

func (a *Account) Validate() error

type AccountMap

type AccountMap map[string]*Account

AccountMap is a map from address to Account, also implementing the AccountsAdapter interface

func NewAccountMap

func NewAccountMap() AccountMap

NewAccountMap creates a new AccountMap instance.

func (AccountMap) Clone

func (am AccountMap) Clone() AccountMap

Clone creates a deep clone of the entire AccountMap.

func (AccountMap) CreateAccount

func (am AccountMap) CreateAccount(address []byte, world *MockWorld) *Account

CreateAccount instantiates an empty account for the given address.

func (AccountMap) CreateSmartContractAccount

func (am AccountMap) CreateSmartContractAccount(owner []byte, address []byte, code []byte, world *MockWorld) *Account

CreateSmartContractAccount instantiates an account for a smart contract with the given address and WASM bytecode.

func (AccountMap) DeleteAccount

func (am AccountMap) DeleteAccount(address []byte)

DeleteAccount removes account based on address

func (AccountMap) GetAccount

func (am AccountMap) GetAccount(address []byte) *Account

GetAccount retrieves account based on address

func (AccountMap) LoadAccountStorageFrom

func (am AccountMap) LoadAccountStorageFrom(otherAM AccountMap) error

LoadAccountStorageFrom reassigns the storage of the accounts to the storage of the accounts found in otherAM; it only does a reference change, not a deep copy.

func (AccountMap) PutAccount

func (am AccountMap) PutAccount(account *Account)

PutAccount inserts account based on address.

func (AccountMap) PutAccounts

func (am AccountMap) PutAccounts(accounts []*Account)

PutAccounts inserts multiple accounts based on address.

type BlockInfo

type BlockInfo struct {
	BlockTimestamp uint64
	BlockNonce     uint64
	BlockRound     uint64
	BlockEpoch     uint32
	RandomSeed     *[48]byte
}

BlockInfo contains metadata about a mocked block

type BuiltinFunctionsWrapper

type BuiltinFunctionsWrapper struct {
	Container       vmcommon.BuiltInFunctionContainer
	MapDNSAddresses map[string]struct{}
	World           *MockWorld
	Marshalizer     vmcommon.Marshalizer
}

BuiltinFunctionsWrapper manages and initializes a BuiltInFunctionContainer along with its dependencies

func NewBuiltinFunctionsWrapper

func NewBuiltinFunctionsWrapper(
	world *MockWorld,
	gasMap config.GasScheduleMap,
) (*BuiltinFunctionsWrapper, error)

NewBuiltinFunctionsWrapper creates a new BuiltinFunctionsWrapper with default dependencies.

func (*BuiltinFunctionsWrapper) GetBuiltinFunctionNames

func (bf *BuiltinFunctionsWrapper) GetBuiltinFunctionNames() vmcommon.FunctionNames

GetBuiltinFunctionNames returns the list of defined builtin-in functions.

func (*BuiltinFunctionsWrapper) GetTokenBalance

func (bf *BuiltinFunctionsWrapper) GetTokenBalance(address []byte, tokenKey []byte) (*big.Int, error)

GetTokenBalance returns the DCDT balance of an account for the given token key (token keys are built from the token identifier using MakeTokenKey).

func (*BuiltinFunctionsWrapper) GetTokenData

func (bf *BuiltinFunctionsWrapper) GetTokenData(address []byte, tokenKey []byte) (*dcdt.DCDigitalToken, error)

GetTokenData gets the DCDT information related to a token from the storage of an account (token keys are built from the token identifier using MakeTokenKey).

func (*BuiltinFunctionsWrapper) PerformDirectDCDTTransfer

func (bf *BuiltinFunctionsWrapper) PerformDirectDCDTTransfer(
	sender []byte,
	receiver []byte,
	token []byte,
	nonce uint64,
	value *big.Int,
	callType vm.CallType,
	gasLimit uint64,
	gasPrice uint64,
) (uint64, error)

PerformDirectDCDTTransfer calls the real DCDTTransfer function immediately; only works for in-shard transfers for now, but it will be expanded to cross-shard. TODO rewrite to simulate what the SCProcessor does when executing a tx with data "DCDTTransfer@token@value@contractfunc@contractargs..." TODO this function duplicates code from host.ExecuteDCDTTransfer(), must refactor

func (*BuiltinFunctionsWrapper) ProcessBuiltInFunction

func (bf *BuiltinFunctionsWrapper) ProcessBuiltInFunction(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)

ProcessBuiltInFunction delegates the execution of a real builtin function to the inner BuiltInFunctionContainer.

func (*BuiltinFunctionsWrapper) SetTokenBalance

func (bf *BuiltinFunctionsWrapper) SetTokenBalance(address []byte, tokenKey []byte, balance *big.Int) error

SetTokenBalance sets the DCDT balance of an account for the given token key (token keys are built from the token identifier using MakeTokenKey).

func (*BuiltinFunctionsWrapper) SetTokenData

func (bf *BuiltinFunctionsWrapper) SetTokenData(address []byte, tokenKey []byte, tokenData *dcdt.DCDigitalToken) error

SetTokenData sets the DCDT information related to a token from the storage of an account (token keys are built from the token identifier using MakeTokenKey).

type GogoProtoMarshalizer

type GogoProtoMarshalizer struct {
}

GogoProtoMarshalizer implements marshaling with protobuf

func (*GogoProtoMarshalizer) IsInterfaceNil

func (x *GogoProtoMarshalizer) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*GogoProtoMarshalizer) Marshal

func (x *GogoProtoMarshalizer) Marshal(obj interface{}) ([]byte, error)

Marshal does the actual serialization of an object The object to be serialized must implement the gogoProtoObj interface

func (*GogoProtoMarshalizer) Unmarshal

func (x *GogoProtoMarshalizer) Unmarshal(obj interface{}, buff []byte) error

Unmarshal does the actual deserialization of an object The object to be deserialized must implement the gogoProtoObj interface

type GogoProtoObj

type GogoProtoObj interface {
	gproto.Marshaler
	gproto.Unmarshaler
	proto.Message
}

GogoProtoObj groups the necessary of a gogo protobuf marshalizeble object

type MockAccountsAdapter

type MockAccountsAdapter struct {
	World     *MockWorld
	Snapshots []AccountMap
}

MockAccountsAdapter is an implementation of AccountsAdapter based on MockWorld and the accounts within it.

func NewMockAccountsAdapter

func NewMockAccountsAdapter(world *MockWorld) *MockAccountsAdapter

NewMockAccountsAdapter instantiates a new MockAccountsAdapter.

func (*MockAccountsAdapter) Commit

func (m *MockAccountsAdapter) Commit() ([]byte, error)

Commit -

func (*MockAccountsAdapter) GetCode

func (m *MockAccountsAdapter) GetCode(codeHash []byte) []byte

GetCode -

func (*MockAccountsAdapter) GetExistingAccount

func (m *MockAccountsAdapter) GetExistingAccount(address []byte) (vmcommon.AccountHandler, error)

GetExistingAccount -

func (*MockAccountsAdapter) GetNumCheckpoints

func (m *MockAccountsAdapter) GetNumCheckpoints() uint32

GetNumCheckpoints -

func (*MockAccountsAdapter) IsInterfaceNil

func (m *MockAccountsAdapter) IsInterfaceNil() bool

IsInterfaceNil -

func (*MockAccountsAdapter) IsPruningEnabled

func (m *MockAccountsAdapter) IsPruningEnabled() bool

IsPruningEnabled -

func (*MockAccountsAdapter) JournalLen

func (m *MockAccountsAdapter) JournalLen() int

JournalLen -

func (*MockAccountsAdapter) LoadAccount

func (m *MockAccountsAdapter) LoadAccount(address []byte) (vmcommon.AccountHandler, error)

LoadAccount -

func (*MockAccountsAdapter) RecreateTrie

func (m *MockAccountsAdapter) RecreateTrie(_ []byte) error

RecreateTrie -

func (*MockAccountsAdapter) RemoveAccount

func (m *MockAccountsAdapter) RemoveAccount(address []byte) error

RemoveAccount -

func (*MockAccountsAdapter) RevertToSnapshot

func (m *MockAccountsAdapter) RevertToSnapshot(snapshotIndex int) error

RevertToSnapshot -

func (*MockAccountsAdapter) RootHash

func (m *MockAccountsAdapter) RootHash() ([]byte, error)

RootHash -

func (*MockAccountsAdapter) SaveAccount

func (m *MockAccountsAdapter) SaveAccount(account vmcommon.AccountHandler) error

SaveAccount -

func (*MockAccountsAdapter) SetStateCheckpoint

func (m *MockAccountsAdapter) SetStateCheckpoint(_ []byte, _ context.Context)

SetStateCheckpoint -

func (*MockAccountsAdapter) SnapshotState

func (m *MockAccountsAdapter) SnapshotState(_ []byte, _ context.Context)

SnapshotState -

type MockDCDTData

type MockDCDTData struct {
	TokenIdentifier []byte
	Instances       []*dcdt.DCDigitalToken
	LastNonce       uint64
	Roles           [][]byte
}

MockDCDTData groups together all instances of a token (same token name, different nonces).

type MockGuardedAccountHandler

type MockGuardedAccountHandler struct{}

MockGuardedAccountHandler -

func NewMockGuardedAccountHandler

func NewMockGuardedAccountHandler() *MockGuardedAccountHandler

NewMockGuardedAccountHandler -

func (*MockGuardedAccountHandler) CleanOtherThanActive

func (mah *MockGuardedAccountHandler) CleanOtherThanActive(_ vmcommon.UserAccountHandler)

CleanOtherThanActive -

func (*MockGuardedAccountHandler) GetActiveGuardian

func (mah *MockGuardedAccountHandler) GetActiveGuardian(_ vmcommon.UserAccountHandler) ([]byte, error)

GetActiveGuardian -

func (*MockGuardedAccountHandler) IsInterfaceNil

func (mah *MockGuardedAccountHandler) IsInterfaceNil() bool

IsInterfaceNil -

func (*MockGuardedAccountHandler) SetGuardian

func (mah *MockGuardedAccountHandler) SetGuardian(_ vmcommon.UserAccountHandler, _ []byte, _ []byte, _ []byte) error

SetGuardian -

type MockWorld

type MockWorld struct {
	SelfShardID                uint32
	AcctMap                    AccountMap
	AccountsAdapter            vmcommon.AccountsAdapter
	PreviousBlockInfo          *BlockInfo
	CurrentBlockInfo           *BlockInfo
	Blockhashes                [][]byte
	NewAddressMocks            []*NewAddressMock
	StateRootHash              []byte
	Err                        error
	LastCreatedContractAddress []byte
	CompiledCode               map[string][]byte
	BuiltinFuncs               *BuiltinFunctionsWrapper
	GuardedAccountHandler      vmcommon.GuardedAccountHandler
}

MockWorld provides a mock representation of the blockchain to be used in VM tests.

func NewMockWorld

func NewMockWorld() *MockWorld

NewMockWorld creates a new MockWorld instance

func (*MockWorld) Clear

func (b *MockWorld) Clear()

Clear resets all mock data between tests.

func (*MockWorld) ClearCompiledCodes

func (b *MockWorld) ClearCompiledCodes()

ClearCompiledCodes -

func (*MockWorld) CommitChanges

func (b *MockWorld) CommitChanges() error

CommitChanges -

func (*MockWorld) CommunicationIdentifier

func (b *MockWorld) CommunicationIdentifier(destShardID uint32) string

CommunicationIdentifier -

func (*MockWorld) ComputeId

func (b *MockWorld) ComputeId(address []byte) uint32

ComputeId -

func (*MockWorld) CreateStateBackup

func (b *MockWorld) CreateStateBackup()

CreateStateBackup -

func (*MockWorld) CurrentEpoch

func (b *MockWorld) CurrentEpoch() uint32

CurrentEpoch returns the current epoch

func (*MockWorld) CurrentNonce

func (b *MockWorld) CurrentNonce() uint64

CurrentNonce returns the nonce from the current block

func (*MockWorld) CurrentRandomSeed

func (b *MockWorld) CurrentRandomSeed() []byte

CurrentRandomSeed returns the random seed from the current header

func (*MockWorld) CurrentRound

func (b *MockWorld) CurrentRound() uint64

CurrentRound returns the round from the current block

func (*MockWorld) CurrentTimeStamp

func (b *MockWorld) CurrentTimeStamp() uint64

CurrentTimeStamp return the timestamp from the current block

func (*MockWorld) ExecuteSmartContractCallOnOtherVM

func (b *MockWorld) ExecuteSmartContractCallOnOtherVM(_ *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)

ExecuteSmartContractCallOnOtherVM -

func (*MockWorld) GetAllState

func (b *MockWorld) GetAllState(accountAddress []byte) (map[string][]byte, error)

GetAllState simply returns the storage as-is.

func (*MockWorld) GetBlockhash

func (b *MockWorld) GetBlockhash(nonce uint64) ([]byte, error)

GetBlockhash should return the hash of the nth previous blockchain. Offset specifies how many blocks we need to look back.

func (*MockWorld) GetBuiltinFunctionNames

func (b *MockWorld) GetBuiltinFunctionNames() vmcommon.FunctionNames

GetBuiltinFunctionNames -

func (*MockWorld) GetCode

func (b *MockWorld) GetCode(acc vmcommon.UserAccountHandler) []byte

GetCode retrieves the code from the given account, or nil if not found

func (*MockWorld) GetCompiledCode

func (b *MockWorld) GetCompiledCode(codeHash []byte) (bool, []byte)

GetCompiledCode -

func (*MockWorld) GetDCDTToken

func (b *MockWorld) GetDCDTToken(address []byte, tokenName []byte, nonce uint64) (*dcdt.DCDigitalToken, error)

GetDCDTToken -

func (*MockWorld) GetShardOfAddress

func (b *MockWorld) GetShardOfAddress(address []byte) uint32

GetShardOfAddress -

func (*MockWorld) GetSnapshot

func (b *MockWorld) GetSnapshot() int

GetSnapshot -

func (*MockWorld) GetStateRootHash

func (b *MockWorld) GetStateRootHash() []byte

GetStateRootHash returns the state root hash from the last committed block

func (*MockWorld) GetStorageData

func (b *MockWorld) GetStorageData(accountAddress []byte, key []byte) ([]byte, uint32, error)

GetStorageData yields the storage value for a certain account and storage key. Should return an empty byte array if the key is missing from the account storage

func (*MockWorld) GetUserAccount

func (b *MockWorld) GetUserAccount(address []byte) (vmcommon.UserAccountHandler, error)

GetUserAccount retrieves account info from map, or error if not found.

func (*MockWorld) InitBuiltinFunctions

func (b *MockWorld) InitBuiltinFunctions(gasMap config.GasScheduleMap) error

InitBuiltinFunctions initializes the inner BuiltinFunctionsWrapper, required for calling builtin functions.

func (*MockWorld) IsInterfaceNil

func (b *MockWorld) IsInterfaceNil() bool

IsInterfaceNil returns true if underlying implementation is nil

func (*MockWorld) IsLimitedTransfer

func (b *MockWorld) IsLimitedTransfer(_ []byte) bool

IsLimitedTransfer -

func (*MockWorld) IsPaused

func (b *MockWorld) IsPaused(_ []byte) bool

IsPaused -

func (*MockWorld) IsPayable

func (b *MockWorld) IsPayable(_, address []byte) (bool, error)

IsPayable -

func (*MockWorld) IsSmartContract

func (b *MockWorld) IsSmartContract(address []byte) bool

IsSmartContract -

func (*MockWorld) LastEpoch

func (b *MockWorld) LastEpoch() uint32

LastEpoch returns the epoch from the last committed block

func (*MockWorld) LastNonce

func (b *MockWorld) LastNonce() uint64

LastNonce returns the nonce from from the last committed block

func (*MockWorld) LastRandomSeed

func (b *MockWorld) LastRandomSeed() []byte

LastRandomSeed returns the random seed from the last committed block

func (*MockWorld) LastRound

func (b *MockWorld) LastRound() uint64

LastRound returns the round from the last committed block

func (*MockWorld) LastTimeStamp

func (b *MockWorld) LastTimeStamp() uint64

LastTimeStamp returns the timeStamp from the last committed block

func (*MockWorld) NewAddress

func (b *MockWorld) NewAddress(creatorAddress []byte, creatorNonce uint64, _ []byte) ([]byte, error)

NewAddress provides the address for a new account. It looks up the explicit new address mocks, if none found generates one using a fake but realistic algorithm.

func (*MockWorld) NumberOfShards

func (b *MockWorld) NumberOfShards() uint32

NumberOfShards -

func (*MockWorld) ProcessBuiltInFunction

func (b *MockWorld) ProcessBuiltInFunction(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)

ProcessBuiltInFunction -

func (*MockWorld) RevertToSnapshot

func (b *MockWorld) RevertToSnapshot(snapshot int) error

RevertToSnapshot -

func (*MockWorld) RollbackChanges

func (b *MockWorld) RollbackChanges() error

RollbackChanges should be called after the VM test has run, if the tx has failed

func (*MockWorld) SameShard

func (b *MockWorld) SameShard(firstAddress []byte, secondAddress []byte) bool

SameShard -

func (*MockWorld) SaveCompiledCode

func (b *MockWorld) SaveCompiledCode(codeHash []byte, code []byte)

SaveCompiledCode -

func (*MockWorld) SelfId

func (b *MockWorld) SelfId() uint32

SelfId -

func (*MockWorld) SetCurrentBlockHash

func (b *MockWorld) SetCurrentBlockHash(blockHash []byte)

SetCurrentBlockHash -

func (*MockWorld) UpdateAccountFromOutputAccount

func (b *MockWorld) UpdateAccountFromOutputAccount(modAcct *vmcommon.OutputAccount)

UpdateAccountFromOutputAccount updates a single account from a transaction output.

func (*MockWorld) UpdateAccounts

func (b *MockWorld) UpdateAccounts(
	outputAccounts map[string]*vmcommon.OutputAccount,
	accountsToDelete [][]byte) error

UpdateAccounts should be called after the VM test has run, to update world state

func (*MockWorld) UpdateBalance

func (b *MockWorld) UpdateBalance(address []byte, newBalance *big.Int) error

UpdateBalance sets a new balance to an account

func (*MockWorld) UpdateBalanceWithDelta

func (b *MockWorld) UpdateBalanceWithDelta(address []byte, balanceDelta *big.Int) error

UpdateBalanceWithDelta changes balance of an account by a given amount

func (*MockWorld) UpdateWorldStateBefore

func (b *MockWorld) UpdateWorldStateBefore(
	fromAddr []byte,
	gasLimit uint64,
	gasPrice uint64) error

UpdateWorldStateBefore performs gas payment, before transaction

type NewAddressMock

type NewAddressMock struct {
	CreatorAddress []byte
	CreatorNonce   uint64
	NewAddress     []byte
}

NewAddressMock allows tests to specify what new addresses to generate

Jump to

Keyboard shortcuts

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