core: added basic chain configuration

Added chain configuration options and write out during genesis database
insertion. If no "config" was found, nothing is written to the database.

Configurations are written on a per genesis base. This means
that any chain (which is identified by it's genesis hash) can have their
own chain settings.
This commit is contained in:
Jeffrey Wilcke
2016-03-01 23:32:43 +01:00
committed by Jeffrey Wilcke
parent 10d3466c93
commit f0cbebb19f
55 changed files with 732 additions and 431 deletions

View File

@ -20,77 +20,66 @@ import (
"math/big"
"path/filepath"
"testing"
"github.com/ethereum/go-ethereum/params"
)
func TestBcValidBlockTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcValidBlockTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcValidBlockTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcUncleHeaderValidityTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcUncleHeaderValiditiy.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcUncleHeaderValiditiy.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcUncleTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcUncleTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcUncleTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcForkUncleTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcForkUncle.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcForkUncle.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcInvalidHeaderTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcInvalidHeaderTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcInvalidHeaderTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcInvalidRLPTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcInvalidRLPTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcInvalidRLPTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcRPCAPITests(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcRPC_API_Test.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcRPC_API_Test.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcForkBlockTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcForkBlockTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcForkBlockTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcForkStress(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcForkStressTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcForkStressTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
@ -100,24 +89,21 @@ func TestBcTotalDifficulty(t *testing.T) {
// skip because these will fail due to selfish mining fix
t.Skip()
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcTotalDifficultyTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcTotalDifficultyTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcWallet(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcWalletTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcWalletTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcGasPricer(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcGasPricerTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcGasPricerTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
@ -125,8 +111,7 @@ func TestBcGasPricer(t *testing.T) {
// TODO: iterate over files once we got more than a few
func TestBcRandom(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "RandomTests/bl201507071825GO.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "RandomTests/bl201507071825GO.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
@ -136,16 +121,14 @@ func TestBcMultiChain(t *testing.T) {
// skip due to selfish mining
t.Skip()
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcMultiChainTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcMultiChainTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestBcState(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
err := RunBlockTest(filepath.Join(blockTestDir, "bcStateTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcStateTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
@ -153,88 +136,77 @@ func TestBcState(t *testing.T) {
// Homestead tests
func TestHomesteadBcValidBlockTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcValidBlockTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcValidBlockTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcUncleHeaderValidityTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcUncleHeaderValiditiy.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcUncleHeaderValiditiy.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcUncleTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcUncleTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcUncleTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcInvalidHeaderTests(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcInvalidHeaderTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcInvalidHeaderTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcRPCAPITests(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcRPC_API_Test.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcRPC_API_Test.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcForkStress(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcForkStressTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcForkStressTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcTotalDifficulty(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcTotalDifficultyTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcTotalDifficultyTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcWallet(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcWalletTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcWalletTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcGasPricer(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcGasPricerTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcGasPricerTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcMultiChain(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcMultiChainTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcMultiChainTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}
}
func TestHomesteadBcState(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
err := RunBlockTest(filepath.Join(blockTestDir, "Homestead", "bcStateTest.json"), BlockSkipTests)
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcStateTest.json"), BlockSkipTests)
if err != nil {
t.Fatal(err)
}

View File

@ -108,7 +108,7 @@ type btTransaction struct {
Value string
}
func RunBlockTestWithReader(r io.Reader, skipTests []string) error {
func RunBlockTestWithReader(homesteadBlock *big.Int, r io.Reader, skipTests []string) error {
btjs := make(map[string]*btJSON)
if err := readJson(r, &btjs); err != nil {
return err
@ -119,13 +119,13 @@ func RunBlockTestWithReader(r io.Reader, skipTests []string) error {
return err
}
if err := runBlockTests(bt, skipTests); err != nil {
if err := runBlockTests(homesteadBlock, bt, skipTests); err != nil {
return err
}
return nil
}
func RunBlockTest(file string, skipTests []string) error {
func RunBlockTest(homesteadBlock *big.Int, file string, skipTests []string) error {
btjs := make(map[string]*btJSON)
if err := readJsonFile(file, &btjs); err != nil {
return err
@ -135,13 +135,13 @@ func RunBlockTest(file string, skipTests []string) error {
if err != nil {
return err
}
if err := runBlockTests(bt, skipTests); err != nil {
if err := runBlockTests(homesteadBlock, bt, skipTests); err != nil {
return err
}
return nil
}
func runBlockTests(bt map[string]*BlockTest, skipTests []string) error {
func runBlockTests(homesteadBlock *big.Int, bt map[string]*BlockTest, skipTests []string) error {
skipTest := make(map[string]bool, len(skipTests))
for _, name := range skipTests {
skipTest[name] = true
@ -153,7 +153,7 @@ func runBlockTests(bt map[string]*BlockTest, skipTests []string) error {
continue
}
// test the block
if err := runBlockTest(test); err != nil {
if err := runBlockTest(homesteadBlock, test); err != nil {
return fmt.Errorf("%s: %v", name, err)
}
glog.Infoln("Block test passed: ", name)
@ -162,7 +162,7 @@ func runBlockTests(bt map[string]*BlockTest, skipTests []string) error {
return nil
}
func runBlockTest(test *BlockTest) error {
func runBlockTest(homesteadBlock *big.Int, test *BlockTest) error {
ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"), crypto.StandardScryptN, crypto.StandardScryptP)
am := accounts.NewManager(ks)
db, _ := ethdb.NewMemDatabase()
@ -174,6 +174,7 @@ func runBlockTest(test *BlockTest) error {
}
cfg := &eth.Config{
ChainConfig: &core.ChainConfig{HomesteadBlock: homesteadBlock},
TestGenesisState: db,
TestGenesisBlock: test.Genesis,
Etherbase: common.Address{},

View File

@ -21,18 +21,8 @@ import (
"os"
"path/filepath"
"testing"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
)
func init() {
if os.Getenv("JITVM") == "true" {
vm.ForceJit = true
vm.EnableJit = true
}
}
func BenchmarkStateCall1024(b *testing.B) {
fn := filepath.Join(stateTestDir, "stCallCreateCallCodeTest.json")
if err := BenchVmTest(fn, bconf{"Call1024BalanceTooLow", true, os.Getenv("JITVM") == "true"}, b); err != nil {
@ -41,188 +31,228 @@ func BenchmarkStateCall1024(b *testing.B) {
}
func TestStateSystemOperations(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stSystemOperationsTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateExample(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stExample.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStatePreCompiledContracts(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stPreCompiledContracts.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateRecursiveCreate(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stRecursiveCreate.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateSpecial(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stSpecialTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateRefund(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stRefundTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateBlockHash(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stBlockHashTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateInitCode(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stInitCodeTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateLog(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stLogTests.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateTransaction(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stTransactionTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateTransition(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stTransitionTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestCallCreateCallCode(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stCallCreateCallCodeTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestCallCodes(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stCallCodes.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestDelegateCall(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stDelegatecallTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestMemory(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stMemoryTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestMemoryStress(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
if os.Getenv("TEST_VM_COMPLEX") == "" {
t.Skip()
}
fn := filepath.Join(stateTestDir, "stMemoryStressTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestQuadraticComplexity(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
if os.Getenv("TEST_VM_COMPLEX") == "" {
t.Skip()
}
fn := filepath.Join(stateTestDir, "stQuadraticComplexityTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestSolidity(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stSolidityTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestWallet(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fn := filepath.Join(stateTestDir, "stWalletTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateTestsRandom(t *testing.T) {
params.HomesteadBlock = big.NewInt(1000000)
ruleSet := RuleSet{
HomesteadBlock: big.NewInt(1000000),
}
fns, _ := filepath.Glob("./files/StateTests/RandomTests/*")
for _, fn := range fns {
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
@ -230,151 +260,172 @@ func TestStateTestsRandom(t *testing.T) {
// homestead tests
func TestHomesteadStateSystemOperations(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stSystemOperationsTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStatePreCompiledContracts(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stPreCompiledContracts.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateRecursiveCreate(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
fn := filepath.Join(stateTestDir, "Homestead", "stRecursiveCreate.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
t.Error(err)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
}
func TestHomesteadStateSpecial(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
fn := filepath.Join(stateTestDir, "Homestead", "stSpecialTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateRefund(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stRefundTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateInitCode(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stInitCodeTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateLog(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stLogTests.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateTransaction(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stTransactionTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadCallCreateCallCode(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stCallCreateCallCodeTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadCallCodes(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stCallCodes.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadMemory(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stMemoryTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadMemoryStress(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
if os.Getenv("TEST_VM_COMPLEX") == "" {
t.Skip()
}
fn := filepath.Join(stateTestDir, "Homestead", "stMemoryStressTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadQuadraticComplexity(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
if os.Getenv("TEST_VM_COMPLEX") == "" {
t.Skip()
}
fn := filepath.Join(stateTestDir, "Homestead", "stQuadraticComplexityTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadWallet(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stWalletTest.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadDelegateCodes(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stCallDelegateCodes.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadDelegateCodesCallCode(t *testing.T) {
params.HomesteadBlock = big.NewInt(0)
ruleSet := RuleSet{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stCallDelegateCodesCallCode.json")
if err := RunStateTest(fn, StateSkipTests); err != nil {
if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
t.Error(err)
}
}

View File

@ -34,26 +34,26 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
)
func RunStateTestWithReader(r io.Reader, skipTests []string) error {
func RunStateTestWithReader(ruleSet RuleSet, r io.Reader, skipTests []string) error {
tests := make(map[string]VmTest)
if err := readJson(r, &tests); err != nil {
return err
}
if err := runStateTests(tests, skipTests); err != nil {
if err := runStateTests(ruleSet, tests, skipTests); err != nil {
return err
}
return nil
}
func RunStateTest(p string, skipTests []string) error {
func RunStateTest(ruleSet RuleSet, p string, skipTests []string) error {
tests := make(map[string]VmTest)
if err := readJsonFile(p, &tests); err != nil {
return err
}
if err := runStateTests(tests, skipTests); err != nil {
if err := runStateTests(ruleSet, tests, skipTests); err != nil {
return err
}
@ -61,7 +61,7 @@ func RunStateTest(p string, skipTests []string) error {
}
func BenchStateTest(p string, conf bconf, b *testing.B) error {
func BenchStateTest(ruleSet RuleSet, p string, conf bconf, b *testing.B) error {
tests := make(map[string]VmTest)
if err := readJsonFile(p, &tests); err != nil {
return err
@ -71,11 +71,6 @@ func BenchStateTest(p string, conf bconf, b *testing.B) error {
return fmt.Errorf("test not found: %s", conf.name)
}
pJit := vm.EnableJit
vm.EnableJit = conf.jit
pForceJit := vm.ForceJit
vm.ForceJit = conf.precomp
// XXX Yeah, yeah...
env := make(map[string]string)
env["currentCoinbase"] = test.Env.CurrentCoinbase
@ -91,16 +86,13 @@ func BenchStateTest(p string, conf bconf, b *testing.B) error {
b.ResetTimer()
for i := 0; i < b.N; i++ {
benchStateTest(test, env, b)
benchStateTest(ruleSet, test, env, b)
}
vm.EnableJit = pJit
vm.ForceJit = pForceJit
return nil
}
func benchStateTest(test VmTest, env map[string]string, b *testing.B) {
func benchStateTest(ruleSet RuleSet, test VmTest, env map[string]string, b *testing.B) {
b.StopTimer()
db, _ := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, db)
@ -113,10 +105,10 @@ func benchStateTest(test VmTest, env map[string]string, b *testing.B) {
}
b.StartTimer()
RunState(statedb, env, test.Exec)
RunState(ruleSet, statedb, env, test.Exec)
}
func runStateTests(tests map[string]VmTest, skipTests []string) error {
func runStateTests(ruleSet RuleSet, tests map[string]VmTest, skipTests []string) error {
skipTest := make(map[string]bool, len(skipTests))
for _, name := range skipTests {
skipTest[name] = true
@ -129,7 +121,7 @@ func runStateTests(tests map[string]VmTest, skipTests []string) error {
}
//fmt.Println("StateTest:", name)
if err := runStateTest(test); err != nil {
if err := runStateTest(ruleSet, test); err != nil {
return fmt.Errorf("%s: %s\n", name, err.Error())
}
@ -140,7 +132,7 @@ func runStateTests(tests map[string]VmTest, skipTests []string) error {
}
func runStateTest(test VmTest) error {
func runStateTest(ruleSet RuleSet, test VmTest) error {
db, _ := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, db)
for addr, account := range test.Pre {
@ -171,7 +163,7 @@ func runStateTest(test VmTest) error {
logs vm.Logs
)
ret, logs, _, _ = RunState(statedb, env, test.Transaction)
ret, logs, _, _ = RunState(ruleSet, statedb, env, test.Transaction)
// Compare expected and actual return
rexp := common.FromHex(test.Out)
@ -219,7 +211,7 @@ func runStateTest(test VmTest) error {
return nil
}
func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) {
func RunState(ruleSet RuleSet, statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) {
var (
data = common.FromHex(tx["data"])
gas = common.Big(tx["gasLimit"])
@ -241,7 +233,7 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Log
key, _ := hex.DecodeString(tx["secretKey"])
addr := crypto.PubkeyToAddress(crypto.ToECDSA(key).PublicKey)
message := NewMessage(addr, to, data, value, gas, price, nonce)
vmenv := NewEnvFromMap(statedb, env, tx)
vmenv := NewEnvFromMap(ruleSet, statedb, env, tx)
vmenv.origin = addr
ret, _, err := core.ApplyMessage(vmenv, message, gaspool)
if core.IsNonceErr(err) || core.IsInvalidTxErr(err) || core.IsGasLimitErr(err) {

View File

@ -21,10 +21,10 @@ import (
"errors"
"fmt"
"io"
"math/big"
"runtime"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/params"
@ -91,8 +91,6 @@ func RunTransactionTests(file string, skipTests []string) error {
}
func runTransactionTests(tests map[string]TransactionTest, skipTests []string) error {
params.HomesteadBlock = big.NewInt(900000)
skipTest := make(map[string]bool, len(skipTests))
for _, name := range skipTests {
skipTest[name] = true
@ -166,7 +164,8 @@ func verifyTxFields(txTest TransactionTest, decodedTx *types.Transaction) (err e
decodedSender common.Address
)
if params.IsHomestead(common.String2Big(txTest.Blocknumber)) {
chainConfig := &core.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock}
if chainConfig.IsHomestead(common.String2Big(txTest.Blocknumber)) {
decodedSender, err = decodedTx.From()
} else {
decodedSender, err = decodedTx.FromFrontier()

View File

@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"math/big"
"os"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
@ -31,8 +32,17 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
)
var (
ForceJit bool
EnableJit bool
)
func init() {
glog.SetV(0)
if os.Getenv("JITVM") == "true" {
ForceJit = true
EnableJit = true
}
}
func checkLogs(tlog []Log, logs vm.Logs) error {
@ -129,7 +139,16 @@ type VmTest struct {
PostStateRoot string
}
type RuleSet struct {
HomesteadBlock *big.Int
}
func (r RuleSet) IsHomestead(n *big.Int) bool {
return n.Cmp(r.HomesteadBlock) >= 0
}
type Env struct {
ruleSet RuleSet
depth int
state *state.StateDB
skipTransfer bool
@ -152,9 +171,10 @@ type Env struct {
evm *vm.EVM
}
func NewEnv(state *state.StateDB) *Env {
func NewEnv(ruleSet RuleSet, state *state.StateDB) *Env {
env := &Env{
state: state,
ruleSet: ruleSet,
state: state,
}
return env
}
@ -167,8 +187,8 @@ func (self *Env) AddStructLog(log vm.StructLog) {
self.logs = append(self.logs, log)
}
func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues map[string]string) *Env {
env := NewEnv(state)
func NewEnvFromMap(ruleSet RuleSet, state *state.StateDB, envValues map[string]string, exeValues map[string]string) *Env {
env := NewEnv(ruleSet, state)
env.origin = common.HexToAddress(exeValues["caller"])
env.parent = common.HexToHash(envValues["previousHash"])
@ -179,11 +199,15 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
env.gasLimit = common.Big(envValues["currentGasLimit"])
env.Gas = new(big.Int)
env.evm = vm.New(env, nil)
env.evm = vm.New(env, vm.Config{
EnableJit: EnableJit,
ForceJit: ForceJit,
})
return env
}
func (self *Env) RuleSet() vm.RuleSet { return self.ruleSet }
func (self *Env) Vm() vm.Vm { return self.evm }
func (self *Env) Origin() common.Address { return self.origin }
func (self *Env) BlockNumber() *big.Int { return self.number }

View File

@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/params"
)
func RunVmTestWithReader(r io.Reader, skipTests []string) error {
@ -67,11 +68,6 @@ func BenchVmTest(p string, conf bconf, b *testing.B) error {
return fmt.Errorf("test not found: %s", conf.name)
}
pJit := vm.EnableJit
vm.EnableJit = conf.jit
pForceJit := vm.ForceJit
vm.ForceJit = conf.precomp
env := make(map[string]string)
env["currentCoinbase"] = test.Env.CurrentCoinbase
env["currentDifficulty"] = test.Env.CurrentDifficulty
@ -99,9 +95,6 @@ func BenchVmTest(p string, conf bconf, b *testing.B) error {
benchVmTest(test, env, b)
}
vm.EnableJit = pJit
vm.ForceJit = pForceJit
return nil
}
@ -248,7 +241,7 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, vm.Logs,
caller := state.GetOrNewStateObject(from)
vmenv := NewEnvFromMap(state, env, exec)
vmenv := NewEnvFromMap(RuleSet{params.MainNetHomesteadBlock}, state, env, exec)
vmenv.vmTest = true
vmenv.skipTransfer = true
vmenv.initial = true