callbackblockchain

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: GPL-3.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountAddress

func AccountAddress(i *big.Int) []byte

AccountAddress converts to account address bytes from big.Int

func StorageKey added in v0.0.5

func StorageKey(address []byte) string

StorageKey builds a key for the mock

Types

type Account

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

Account holds the account info

func (*Account) AddressBytes added in v0.3.2

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

AddressBytes -

func (*Account) GetBalance added in v0.3.2

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

GetBalance -

func (*Account) GetCode added in v0.3.2

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

GetCode -

func (*Account) GetCodeHash added in v0.3.2

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

GetCodeHash -

func (*Account) GetCodeMetadata added in v0.3.2

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

GetCodeMetadata -

func (*Account) GetDeveloperReward added in v0.3.2

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

GetDeveloperReward -

func (*Account) GetNonce added in v0.3.2

func (a *Account) GetNonce() uint64

GetNonce -

func (*Account) GetOwnerAddress added in v0.3.2

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

GetOwnerAddress -

func (*Account) GetRootHash added in v0.3.2

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

GetRootHash -

func (*Account) GetUserName added in v0.3.2

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

GetOwnerAddress -

func (*Account) IsInterfaceNil added in v0.3.2

func (a *Account) IsInterfaceNil() bool

IsInterfaceNil -

func (*Account) StorageValue

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

StorageValue yields the storage value for key, default 0

type AccountMap

type AccountMap map[string]*Account

AccountMap is a map from address to account

func NewAccountMap

func NewAccountMap() AccountMap

NewAccountMap creates a new AccountMap instance

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(acct *Account)

PutAccount inserts account based on address

type BlockInfo added in v0.2.5

type BlockInfo struct {
	BlockTimestamp uint64
	BlockNonce     uint64
	BlockRound     uint64
	BlockEpoch     uint32
}

BlockInfo contains mock data about the corent block

type BlockchainHookMock

type BlockchainHookMock struct {
	AcctMap           AccountMap
	PreviousBlockInfo *BlockInfo
	CurrentBlockInfo  *BlockInfo
	Blockhashes       [][]byte

	NewAddressMocks []*NewAddressMock
	// contains filtered or unexported fields
}

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

func NewMock

func NewMock() *BlockchainHookMock

NewMock creates a new mock instance

func (*BlockchainHookMock) Clear

func (b *BlockchainHookMock) Clear()

Clear resets all mock data between tests.

func (*BlockchainHookMock) ClearCompiledCodes added in v0.4.4

func (b *BlockchainHookMock) ClearCompiledCodes()

func (*BlockchainHookMock) CurrentEpoch added in v0.0.4

func (b *BlockchainHookMock) CurrentEpoch() uint32

CurrentEpoch returns the current epoch

func (*BlockchainHookMock) CurrentNonce added in v0.0.4

func (b *BlockchainHookMock) CurrentNonce() uint64

CurrentNonce returns the nonce from the current block

func (*BlockchainHookMock) CurrentRandomSeed added in v0.0.4

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

CurrentRandomSeed returns the random seed from the current header

func (*BlockchainHookMock) CurrentRound added in v0.0.4

func (b *BlockchainHookMock) CurrentRound() uint64

CurrentRound returns the round from the current block

func (*BlockchainHookMock) CurrentTimeStamp added in v0.0.4

func (b *BlockchainHookMock) CurrentTimeStamp() uint64

CurrentTimeStamp return the timestamp from the current block

func (*BlockchainHookMock) EnableMockAddressGeneration added in v0.0.5

func (b *BlockchainHookMock) EnableMockAddressGeneration()

EnableMockAddressGeneration causes the mock to generate its own new addresses.

func (*BlockchainHookMock) GetAllState added in v0.2.3

func (b *BlockchainHookMock) GetAllState(_ []byte) (map[string][]byte, error)

GetAllState -

func (*BlockchainHookMock) GetBlockhash

func (b *BlockchainHookMock) 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 (*BlockchainHookMock) GetBuiltinFunctionNames added in v0.1.8

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

GetBuiltinFunctionNames -

func (*BlockchainHookMock) GetCompiledCode added in v0.4.3

func (b *BlockchainHookMock) GetCompiledCode(_ []byte) (bool, []byte)

func (*BlockchainHookMock) GetShardOfAddress added in v0.3.2

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

GetShardOfAddress -

func (*BlockchainHookMock) GetStateRootHash added in v0.0.4

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

GetStateRootHash returns the state root hash from the last committed block

func (*BlockchainHookMock) GetStorageData

func (b *BlockchainHookMock) GetStorageData(accountAddress []byte, index []byte) ([]byte, error)

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

func (*BlockchainHookMock) GetUserAccount added in v0.3.2

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

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

func (*BlockchainHookMock) IsPayable added in v0.3.5

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

func (*BlockchainHookMock) IsSmartContract added in v0.3.2

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

IsSmartContract -

func (*BlockchainHookMock) LastEpoch added in v0.0.4

func (b *BlockchainHookMock) LastEpoch() uint32

LastEpoch returns the epoch from the last committed block

func (*BlockchainHookMock) LastNonce added in v0.0.4

func (b *BlockchainHookMock) LastNonce() uint64

LastNonce returns the nonce from from the last committed block

func (*BlockchainHookMock) LastRandomSeed added in v0.0.4

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

LastRandomSeed returns the random seed from the last committed block

func (*BlockchainHookMock) LastRound added in v0.0.4

func (b *BlockchainHookMock) LastRound() uint64

LastRound returns the round from the last committed block

func (*BlockchainHookMock) LastTimeStamp added in v0.0.4

func (b *BlockchainHookMock) LastTimeStamp() uint64

LastTimeStamp returns the timeStamp from the last committed block

func (*BlockchainHookMock) NewAddress

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

NewAddress adapts between K model and elrond function

func (*BlockchainHookMock) ProcessBuiltInFunction added in v0.1.6

func (b *BlockchainHookMock) ProcessBuiltInFunction(_ *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)

ProcessBuiltInFunction -

func (*BlockchainHookMock) SaveCompiledCode added in v0.4.3

func (b *BlockchainHookMock) SaveCompiledCode(_ []byte, _ []byte)

func (*BlockchainHookMock) UpdateAccounts

func (b *BlockchainHookMock) UpdateAccounts(
	modifiedAccounts []*vmi.OutputAccount,
	accountsToDelete [][]byte,
	callerAddress []byte) error

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

func (*BlockchainHookMock) UpdateBalance

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

UpdateBalance sets a new balance to an account

func (*BlockchainHookMock) UpdateBalanceWithDelta added in v0.0.3

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

UpdateBalanceWithDelta changes balance of an account by a given amount

func (*BlockchainHookMock) UpdateWorldStateBefore

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

UpdateWorldStateBefore performs gas payment, before transaction

type NewAddressMock added in v0.2.2

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