tests

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2016 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package tests implements execution of Ethereum JSON tests.

Index

Constants

This section is empty.

Variables

View Source
var (
	BlockSkipTests = []string{

		"BLOCK__RandomByteAtTheEnd",
		"TRANSCT__RandomByteAtTheEnd",
		"BLOCK__ZeroByteAtTheEnd",
		"TRANSCT__ZeroByteAtTheEnd",

		"ChainAtoChainB_blockorder2",
		"ChainAtoChainB_blockorder1",

		"GasLimitHigherThan2p63m1",
		"SuicideIssue",
	}

	/* Go client does not support transaction (account) nonces above 2^64. This
	technically breaks consensus but is regarded as "reasonable
	engineering constraint" as accounts cannot easily reach such high
	nonce values in practice
	*/
	TransSkipTests = []string{
		"TransactionWithHihghNonce256",
	}
	StateSkipTests = []string{}
	VmSkipTests    = []string{}
)
View Source
var (
	ForceJit  bool
	EnableJit bool
)

Functions

func BenchStateTest added in v1.1.0

func BenchStateTest(chainConfig *params.ChainConfig, p string, conf bconf, b *testing.B) error

func BenchVmTest added in v1.1.0

func BenchVmTest(p string, conf bconf, b *testing.B) error

func LoadBlockTests

func LoadBlockTests(file string) (map[string]*BlockTest, error)

func RunBlockTest

func RunBlockTest(homesteadBlock, daoForkBlock, gasPriceFork *big.Int, file string, skipTests []string) error

func RunBlockTestWithReader

func RunBlockTestWithReader(homesteadBlock, daoForkBlock, gasPriceFork *big.Int, r io.Reader, skipTests []string) error

func RunRLPTest

func RunRLPTest(file string, skip []string) error

RunRLPTest runs the tests in the given file, skipping tests by name.

func RunRLPTestWithReader

func RunRLPTestWithReader(r io.Reader, skip []string) error

RunRLPTest runs the tests encoded in r, skipping tests by name.

func RunState

func RunState(chainConfig *params.ChainConfig, statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error)

func RunStateTest

func RunStateTest(chainConfig *params.ChainConfig, p string, skipTests []string) error

func RunStateTestWithReader

func RunStateTestWithReader(chainConfig *params.ChainConfig, r io.Reader, skipTests []string) error

func RunTransactionTests

func RunTransactionTests(config *params.ChainConfig, file string, skipTests []string) error

func RunTransactionTestsWithReader

func RunTransactionTestsWithReader(config *params.ChainConfig, r io.Reader, skipTests []string) error

func RunVm

func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, vm.Logs, *big.Int, error)

func RunVmTest

func RunVmTest(p string, skipTests []string) error

func RunVmTestWithReader

func RunVmTestWithReader(r io.Reader, skipTests []string) error

Types

type Account

type Account struct {
	Balance string
	Code    string
	Nonce   string
	Storage map[string]string
}

type BlockTest

type BlockTest struct {
	Genesis *types.Block

	Json *btJSON
	// contains filtered or unexported fields
}

Block Test JSON Format

func (*BlockTest) InsertPreState

func (t *BlockTest) InsertPreState(db ethdb.Database) (*state.StateDB, error)

InsertPreState populates the given database with the genesis accounts defined by the test.

func (*BlockTest) TryBlocksInsert

func (t *BlockTest) TryBlocksInsert(blockchain *core.BlockChain) ([]btBlock, error)

See https://github.com/ethereum/tests/wiki/Blockchain-Tests-II

Whether a block is valid or not is a bit subtle, it's defined by presence of
blockHeader, transactions and uncleHeaders fields. If they are missing, the block is
invalid and we must verify that we do not accept it.

Since some tests mix valid and invalid blocks we need to check this for every block.

If a block is invalid it does not necessarily fail the test, if it's invalidness is
expected we are expected to ignore it and continue processing and then validate the
post state.

func (*BlockTest) ValidateImportedHeaders added in v1.2.2

func (test *BlockTest) ValidateImportedHeaders(cm *core.BlockChain, validBlocks []btBlock) error

func (*BlockTest) ValidatePostState

func (t *BlockTest) ValidatePostState(statedb *state.StateDB) error

type Env

type Env struct {
	Gas *big.Int
	// contains filtered or unexported fields
}

func NewEnv

func NewEnv(chainConfig *params.ChainConfig, state *state.StateDB) *Env

func NewEnvFromMap

func NewEnvFromMap(chainConfig *params.ChainConfig, state *state.StateDB, envValues map[string]string, exeValues map[string]string) *Env

func (*Env) AddLog

func (self *Env) AddLog(log *vm.Log)

func (*Env) BlockNumber

func (self *Env) BlockNumber() *big.Int

func (*Env) Call

func (self *Env) Call(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error)

func (*Env) CallCode

func (self *Env) CallCode(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error)

func (*Env) CanTransfer added in v1.1.0

func (self *Env) CanTransfer(from common.Address, balance *big.Int) bool

func (*Env) ChainConfig added in v1.4.19

func (self *Env) ChainConfig() *params.ChainConfig

func (*Env) Coinbase

func (self *Env) Coinbase() common.Address

func (*Env) Create

func (self *Env) Create(caller vm.ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error)

func (*Env) Db added in v1.3.1

func (self *Env) Db() vm.Database

func (*Env) DelegateCall added in v1.3.4

func (self *Env) DelegateCall(caller vm.ContractRef, addr common.Address, data []byte, gas, price *big.Int) ([]byte, error)

func (*Env) Depth

func (self *Env) Depth() int

func (*Env) Difficulty

func (self *Env) Difficulty() *big.Int

func (*Env) GasLimit

func (self *Env) GasLimit() *big.Int

func (*Env) GetHash

func (self *Env) GetHash(n uint64) common.Hash

func (*Env) Origin

func (self *Env) Origin() common.Address

func (*Env) RevertToSnapshot added in v1.4.16

func (self *Env) RevertToSnapshot(snapshot int)

func (*Env) SetDepth

func (self *Env) SetDepth(i int)

func (*Env) SnapshotDatabase added in v1.4.16

func (self *Env) SnapshotDatabase() int

func (*Env) Time

func (self *Env) Time() *big.Int

func (*Env) Transfer

func (self *Env) Transfer(from, to vm.Account, amount *big.Int)

func (*Env) Vm added in v1.4.0

func (self *Env) Vm() vm.Vm

func (*Env) VmType

func (self *Env) VmType() vm.Type

type Log

type Log struct {
	AddressF string   `json:"address"`
	DataF    string   `json:"data"`
	TopicsF  []string `json:"topics"`
	BloomF   string   `json:"bloom"`
}

func (Log) Address

func (self Log) Address() []byte

func (Log) Data

func (self Log) Data() []byte

func (Log) RlpData

func (self Log) RlpData() interface{}

func (Log) Topics

func (self Log) Topics() [][]byte

type RLPTest

type RLPTest struct {
	// If the value of In is "INVALID" or "VALID", the test
	// checks whether Out can be decoded into a value of
	// type interface{}.
	//
	// For other JSON values, In is treated as a driver for
	// calls to rlp.Stream. The test also verifies that encoding
	// In produces the bytes in Out.
	In interface{}

	// Out is a hex-encoded RLP value.
	Out string
}

RLPTest is the JSON structure of a single RLP test.

func (*RLPTest) Run

func (t *RLPTest) Run() error

Run executes the test.

type TransactionTest

type TransactionTest struct {
	Blocknumber string
	Rlp         string
	Sender      string
	Transaction TtTransaction
}

type TtTransaction

type TtTransaction struct {
	Data     string
	GasLimit string
	GasPrice string
	Nonce    string
	R        string
	S        string
	To       string
	V        string
	Value    string
}

Transaction Test JSON Format

type VmEnv

type VmEnv struct {
	CurrentCoinbase   string
	CurrentDifficulty string
	CurrentGasLimit   string
	CurrentNumber     string
	CurrentTimestamp  interface{}
	PreviousHash      string
}

type VmTest

type VmTest struct {
	Callcreates interface{}
	//Env         map[string]string
	Env           VmEnv
	Exec          map[string]string
	Transaction   map[string]string
	Logs          []Log
	Gas           string
	Out           string
	Post          map[string]Account
	Pre           map[string]Account
	PostStateRoot string
}

Jump to

Keyboard shortcuts

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