Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateMockAddress(creatorAddress []byte, creatorNonce uint64) []byte
- type Account
- func (a *Account) AddressBytes() []byte
- func (a *Account) GetBalance() *big.Int
- func (a *Account) GetCode() []byte
- func (a *Account) GetCodeHash() []byte
- func (a *Account) GetCodeMetadata() []byte
- func (a *Account) GetDeveloperReward() *big.Int
- func (a *Account) GetNonce() uint64
- func (a *Account) GetOwnerAddress() []byte
- func (a *Account) GetRootHash() []byte
- func (a *Account) GetUserName() []byte
- func (a *Account) IsInterfaceNil() bool
- func (a *Account) SetBalance(balance int64)
- func (a *Account) SetCode(code []byte, codeMetadata *vmcommon.CodeMetadata)
- func (a *Account) StorageValue(key string) []byte
- type AccountMap
- func (am AccountMap) CreateAccount(address []byte) *Account
- func (am AccountMap) CreateSmartContractAccount(owner []byte, address []byte, code []byte) *Account
- func (am AccountMap) DeleteAccount(address []byte)
- func (am AccountMap) GetAccount(address []byte) *Account
- func (am AccountMap) PutAccount(account *Account)
- func (am AccountMap) PutAccounts(accounts []*Account)
- type BlockInfo
- type ESDTData
- type MockWorld
- func (b *MockWorld) Clear()
- func (b *MockWorld) ClearCompiledCodes()
- func (b *MockWorld) CurrentEpoch() uint32
- func (b *MockWorld) CurrentNonce() uint64
- func (b *MockWorld) CurrentRandomSeed() []byte
- func (b *MockWorld) CurrentRound() uint64
- func (b *MockWorld) CurrentTimeStamp() uint64
- func (b *MockWorld) GetAllState(accountAddress []byte) (map[string][]byte, error)
- func (b *MockWorld) GetBlockhash(nonce uint64) ([]byte, error)
- func (b *MockWorld) GetBuiltinFunctionNames() vmcommon.FunctionNames
- func (b *MockWorld) GetCode(acc vmcommon.UserAccountHandler) []byte
- func (b *MockWorld) GetCompiledCode(codeHash []byte) (bool, []byte)
- func (b *MockWorld) GetESDTToken(_ []byte, _ []byte, _ uint64) (*esdt.ESDigitalToken, error)
- func (b *MockWorld) GetShardOfAddress(address []byte) uint32
- func (b *MockWorld) GetStateRootHash() []byte
- func (b *MockWorld) GetStorageData(accountAddress []byte, key []byte) ([]byte, error)
- func (b *MockWorld) GetUserAccount(address []byte) (vmcommon.UserAccountHandler, error)
- func (b *MockWorld) IsInterfaceNil() bool
- func (b *MockWorld) IsPayable(address []byte) (bool, error)
- func (b *MockWorld) IsSmartContract(address []byte) bool
- func (b *MockWorld) LastEpoch() uint32
- func (b *MockWorld) LastNonce() uint64
- func (b *MockWorld) LastRandomSeed() []byte
- func (b *MockWorld) LastRound() uint64
- func (b *MockWorld) LastTimeStamp() uint64
- func (b *MockWorld) NewAddress(creatorAddress []byte, creatorNonce uint64, _ []byte) ([]byte, error)
- func (b *MockWorld) ProcessBuiltInFunction(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)
- func (b *MockWorld) RollbackChanges()
- func (b *MockWorld) SaveCompiledCode(codeHash []byte, code []byte)
- func (b *MockWorld) SetCurrentBlockHash(blockHash []byte)
- func (b *MockWorld) StartTransferESDT(from, to []byte, tokenName string, amount *big.Int) (bool, error)
- func (b *MockWorld) UpdateAccountFromOutputAccount(modAcct *vmcommon.OutputAccount)
- func (b *MockWorld) UpdateAccounts(outputAccounts map[string]*vmcommon.OutputAccount, accountsToDelete [][]byte) error
- func (b *MockWorld) UpdateBalance(address []byte, newBalance *big.Int) error
- func (b *MockWorld) UpdateBalanceWithDelta(address []byte, balanceDelta *big.Int) error
- func (b *MockWorld) UpdateWorldStateBefore(fromAddr []byte, gasLimit uint64, gasPrice uint64) error
- type NewAddressMock
Constants ¶
const BuiltInFunctionESDTTransfer = "ESDTTransfer"
BuiltInFunctionESDTTransfer is the key for the elrond standard digital token transfer built-in function
Variables ¶
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
Functions ¶
func GenerateMockAddress ¶
/ GenerateMockAddress simulates creation of a new address by the protocol.
Types ¶
type Account ¶
type Account struct { Exists bool Address []byte Nonce uint64 Balance *big.Int BalanceDelta *big.Int Storage map[string][]byte Code []byte CodeHash []byte CodeMetadata []byte AsyncCallData string OwnerAddress []byte Username []byte ShardID uint32 IsSmartContract bool ESDTData map[string]*ESDTData }
Account holds the account info
func (*Account) GetDeveloperReward ¶
GetDeveloperReward -
func (*Account) SetBalance ¶ added in v1.1.2
SetBalance -
func (*Account) SetCode ¶ added in v1.1.2
func (a *Account) SetCode(code []byte, codeMetadata *vmcommon.CodeMetadata)
SetCode changes the account code, as well as all fields depending on it: CodeHash, IsSmartContract, CodeMetadata. The code metadata must be given explicitly.
func (*Account) StorageValue ¶
StorageValue yields the storage value for key, default 0
type AccountMap ¶
AccountMap is a map from address to account
func NewAccountMap ¶
func NewAccountMap() AccountMap
NewAccountMap creates a new AccountMap instance.
func (AccountMap) CreateAccount ¶ added in v1.1.2
func (am AccountMap) CreateAccount(address []byte) *Account
CreateAccount instantiates an empty account for the given address.
func (AccountMap) CreateSmartContractAccount ¶ added in v1.1.2
func (am AccountMap) CreateSmartContractAccount(owner []byte, address []byte, code []byte) *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) 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 MockWorld ¶
type MockWorld struct { AcctMap AccountMap PreviousBlockInfo *BlockInfo CurrentBlockInfo *BlockInfo Blockhashes [][]byte NewAddressMocks []*NewAddressMock StateRootHash []byte Err error LastCreatedContractAddress []byte CompiledCode map[string][]byte }
MockWorld provides a mock representation of the blockchain to be used in VM tests.
func (*MockWorld) ClearCompiledCodes ¶
func (b *MockWorld) ClearCompiledCodes()
func (*MockWorld) CurrentEpoch ¶
CurrentEpoch returns the current epoch
func (*MockWorld) CurrentNonce ¶
CurrentNonce returns the nonce from the current block
func (*MockWorld) CurrentRandomSeed ¶
CurrentRandomSeed returns the random seed from the current header
func (*MockWorld) CurrentRound ¶
CurrentRound returns the round from the current block
func (*MockWorld) CurrentTimeStamp ¶
CurrentTimeStamp return the timestamp from the current block
func (*MockWorld) GetAllState ¶
GetAllState simply returns the storage as-is.
func (*MockWorld) GetBlockhash ¶
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 ¶ added in v1.0.2
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 (*MockWorld) GetESDTToken ¶ added in v1.2.0
GetESDTToken -
func (*MockWorld) GetShardOfAddress ¶
GetShardOfAddress -
func (*MockWorld) GetStateRootHash ¶
GetStateRootHash returns the state root hash from the last committed block
func (*MockWorld) GetStorageData ¶
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) IsInterfaceNil ¶
IsInterfaceNil returns true if underlying implementation is nil
func (*MockWorld) IsSmartContract ¶
IsSmartContract -
func (*MockWorld) LastRandomSeed ¶
LastRandomSeed returns the random seed from the last committed block
func (*MockWorld) LastTimeStamp ¶
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) ProcessBuiltInFunction ¶
func (b *MockWorld) ProcessBuiltInFunction(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)
ProcessBuiltInFunction -
func (*MockWorld) RollbackChanges ¶
func (b *MockWorld) RollbackChanges()
RollbackChanges should be called after the VM test has run, if the tx has failed
func (*MockWorld) SaveCompiledCode ¶
func (*MockWorld) SetCurrentBlockHash ¶
func (*MockWorld) StartTransferESDT ¶
func (b *MockWorld) StartTransferESDT(from, to []byte, tokenName string, amount *big.Int) (bool, error)
StartTransferESDT updates ESDT balance deltas, without changing the actual balances. The deltas need to be committed afterwards.
func (*MockWorld) UpdateAccountFromOutputAccount ¶ added in v1.1.2
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 ¶
UpdateBalance sets a new balance to an account
func (*MockWorld) UpdateBalanceWithDelta ¶
UpdateBalanceWithDelta changes balance of an account by a given amount
type NewAddressMock ¶
NewAddressMock allows tests to specify what new addresses to generate