callbackblockchain

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: GPL-3.0 Imports: 3 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
}

Account holds the account info

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 BlockchainHookMock

type BlockchainHookMock struct {
	AcctMap          AccountMap
	CurrentTimestamp uint64
	Blockhashes      [][]byte
	// 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) AccountExists

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

AccountExists yields whether or not an account is considered to exist in the blockchain or not. Note: on Ethereum an account with Balance = 0 and Nonce = 0 is considered to not exist. In Elrond we can have existing accounts with zer obalance and nonce.

func (*BlockchainHookMock) Clear

func (b *BlockchainHookMock) Clear()

Clear resets all mock data between tests.

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) GetBalance

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

GetBalance should retrieve the balance of an account

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) GetCode

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

GetCode should return the compiled and assembled SC code. Empty byte array if the account is a wallet.

func (*BlockchainHookMock) GetNonce

func (b *BlockchainHookMock) GetNonce(address []byte) (uint64, error)

GetNonce should retrieve the nonce of an account

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) IsCodeEmpty

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

IsCodeEmpty should return whether of not an account is SC.

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, vmType []byte) ([]byte, error)

NewAddress adapts between K model and elrond function

func (*BlockchainHookMock) UpdateAccounts

func (b *BlockchainHookMock) UpdateAccounts(modifiedAccounts []*vmi.OutputAccount, accountsToDelete [][]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

Jump to

Keyboard shortcuts

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