aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-10-20 19:36:29 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-11-13 17:44:04 +0800
commit445feaeef58bd89a113743dccf6fd5df55cde6fa (patch)
tree6c692a0989800f005a94bde2d372fcbe1f7630a1 /tests
parent932d973e36ff0d41a6005b93d2d4ff1b4430fb04 (diff)
downloaddexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.gz
dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.zst
dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.zip
core, core/state, trie: EIP158, reprice & skip empty account write
This commit implements EIP158 part 1, 2, 3 & 4 1. If an account is empty it's no longer written to the trie. An empty account is defined as (balance=0, nonce=0, storage=0, code=0). 2. Delete an empty account if it's touched 3. An empty account is redefined as either non-existent or empty. 4. Zero value calls and zero value suicides no longer consume the 25k reation costs. params: moved core/config to params Signed-off-by: Jeffrey Wilcke <jeffrey@ethereum.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/block_test_util.go5
-rw-r--r--tests/state_test.go325
-rw-r--r--tests/state_test_util.go33
-rw-r--r--tests/transaction_test_util.go3
-rw-r--r--tests/util.go51
-rw-r--r--tests/vm_test_util.go2
6 files changed, 215 insertions, 204 deletions
diff --git a/tests/block_test_util.go b/tests/block_test_util.go
index 010c8d4c0..f04329546 100644
--- a/tests/block_test_util.go
+++ b/tests/block_test_util.go
@@ -35,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -170,7 +171,7 @@ func runBlockTest(homesteadBlock, daoForkBlock, gasPriceFork *big.Int, test *Blo
core.WriteCanonicalHash(db, test.Genesis.Hash(), test.Genesis.NumberU64())
core.WriteHeadBlockHash(db, test.Genesis.Hash())
evmux := new(event.TypeMux)
- config := &core.ChainConfig{HomesteadBlock: homesteadBlock, DAOForkBlock: daoForkBlock, DAOForkSupport: true, HomesteadGasRepriceBlock: gasPriceFork}
+ config := &params.ChainConfig{HomesteadBlock: homesteadBlock, DAOForkBlock: daoForkBlock, DAOForkSupport: true, EIP150Block: gasPriceFork}
chain, err := core.NewBlockChain(db, config, ethash.NewShared(), evmux)
if err != nil {
return err
@@ -228,7 +229,7 @@ func (t *BlockTest) InsertPreState(db ethdb.Database) (*state.StateDB, error) {
}
}
- root, err := statedb.Commit()
+ root, err := statedb.Commit(false)
if err != nil {
return nil, fmt.Errorf("error writing state: %v", err)
}
diff --git a/tests/state_test.go b/tests/state_test.go
index 1e848ab4e..b266c2215 100644
--- a/tests/state_test.go
+++ b/tests/state_test.go
@@ -21,6 +21,8 @@ import (
"os"
"path/filepath"
"testing"
+
+ "github.com/ethereum/go-ethereum/params"
)
func BenchmarkStateCall1024(b *testing.B) {
@@ -31,172 +33,172 @@ func BenchmarkStateCall1024(b *testing.B) {
}
func TestStateSystemOperations(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stSystemOperationsTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateExample(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stExample.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStatePreCompiledContracts(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stPreCompiledContracts.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateRecursiveCreate(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stRecursiveCreate.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateSpecial(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stSpecialTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateRefund(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stRefundTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateBlockHash(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stBlockHashTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateInitCode(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stInitCodeTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateLog(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stLogTests.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateTransaction(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stTransactionTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateTransition(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stTransitionTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestCallCreateCallCode(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stCallCreateCallCodeTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestCallCodes(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stCallCodes.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestDelegateCall(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stDelegatecallTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestMemory(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stMemoryTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestMemoryStress(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
@@ -204,13 +206,13 @@ func TestMemoryStress(t *testing.T) {
t.Skip()
}
fn := filepath.Join(stateTestDir, "stMemoryStressTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestQuadraticComplexity(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
@@ -218,41 +220,41 @@ func TestQuadraticComplexity(t *testing.T) {
t.Skip()
}
fn := filepath.Join(stateTestDir, "stQuadraticComplexityTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestSolidity(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stSolidityTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestWallet(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fn := filepath.Join(stateTestDir, "stWalletTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestStateTestsRandom(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: big.NewInt(1150000),
}
fns, _ := filepath.Glob("./files/StateTests/RandomTests/*")
for _, fn := range fns {
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(fn, err)
}
}
@@ -260,117 +262,117 @@ func TestStateTestsRandom(t *testing.T) {
// homestead tests
func TestHomesteadStateSystemOperations(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stSystemOperationsTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStatePreCompiledContracts(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stPreCompiledContracts.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateRecursiveCreate(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stSpecialTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateRefund(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stRefundTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateInitCode(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stInitCodeTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateLog(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stLogTests.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadStateTransaction(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stTransactionTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadCallCreateCallCode(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stCallCreateCallCodeTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadCallCodes(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stCallCodes.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadMemory(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stMemoryTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadMemoryStress(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
@@ -378,13 +380,13 @@ func TestHomesteadMemoryStress(t *testing.T) {
t.Skip()
}
fn := filepath.Join(stateTestDir, "Homestead", "stMemoryStressTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadQuadraticComplexity(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
@@ -392,286 +394,313 @@ func TestHomesteadQuadraticComplexity(t *testing.T) {
t.Skip()
}
fn := filepath.Join(stateTestDir, "Homestead", "stQuadraticComplexityTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadWallet(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stWalletTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadDelegateCodes(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stCallDelegateCodes.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadDelegateCodesCallCode(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stCallDelegateCodesCallCode.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestHomesteadBounds(t *testing.T) {
- ruleSet := RuleSet{
+ chainConfig := &params.ChainConfig{
HomesteadBlock: new(big.Int),
}
fn := filepath.Join(stateTestDir, "Homestead", "stBoundsTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
// EIP150 tests
func TestEIP150Specific(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "stEIPSpecificTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150SingleCodeGasPrice(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "stEIPSingleCodeGasPrices.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150MemExpandingCalls(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "stMemExpandingEIPCalls.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadStateSystemOperations(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stSystemOperationsTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadStatePreCompiledContracts(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stPreCompiledContracts.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadStateRecursiveCreate(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stSpecialTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadStateRefund(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stRefundTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadStateInitCode(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stInitCodeTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadStateLog(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stLogTests.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadStateTransaction(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stTransactionTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadCallCreateCallCode(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stCallCreateCallCodeTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadCallCodes(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stCallCodes.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadMemory(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stMemoryTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadMemoryStress(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
if os.Getenv("TEST_VM_COMPLEX") == "" {
t.Skip()
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stMemoryStressTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadQuadraticComplexity(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
if os.Getenv("TEST_VM_COMPLEX") == "" {
t.Skip()
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stQuadraticComplexityTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadWallet(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stWalletTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadDelegateCodes(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stCallDelegateCodes.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadDelegateCodesCallCode(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stCallDelegateCodesCallCode.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
func TestEIP150HomesteadBounds(t *testing.T) {
- ruleSet := RuleSet{
- HomesteadBlock: new(big.Int),
- HomesteadGasRepriceBlock: big.NewInt(2457000),
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
}
fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stBoundsTest.json")
- if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil {
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
+ t.Error(err)
+ }
+}
+
+// EIP158 tests
+func TestEIP158Create(t *testing.T) {
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
+ EIP158Block: big.NewInt(3500000),
+ }
+
+ fn := filepath.Join(stateTestDir, "EIP158", "stCreateTest.json")
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
+ t.Error(err)
+ }
+}
+
+func TestEIP158Specific(t *testing.T) {
+ chainConfig := &params.ChainConfig{
+ HomesteadBlock: new(big.Int),
+ EIP150Block: big.NewInt(2457000),
+ EIP158Block: big.NewInt(3500000),
+ }
+
+ fn := filepath.Join(stateTestDir, "EIP158", "stEIP158SpecificTest.json")
+ if err := RunStateTest(chainConfig, fn, StateSkipTests); err != nil {
t.Error(err)
}
}
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index 985271500..6427537b4 100644
--- a/tests/state_test_util.go
+++ b/tests/state_test_util.go
@@ -33,28 +33,29 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/params"
)
-func RunStateTestWithReader(ruleSet RuleSet, r io.Reader, skipTests []string) error {
+func RunStateTestWithReader(chainConfig *params.ChainConfig, r io.Reader, skipTests []string) error {
tests := make(map[string]VmTest)
if err := readJson(r, &tests); err != nil {
return err
}
- if err := runStateTests(ruleSet, tests, skipTests); err != nil {
+ if err := runStateTests(chainConfig, tests, skipTests); err != nil {
return err
}
return nil
}
-func RunStateTest(ruleSet RuleSet, p string, skipTests []string) error {
+func RunStateTest(chainConfig *params.ChainConfig, p string, skipTests []string) error {
tests := make(map[string]VmTest)
if err := readJsonFile(p, &tests); err != nil {
return err
}
- if err := runStateTests(ruleSet, tests, skipTests); err != nil {
+ if err := runStateTests(chainConfig, tests, skipTests); err != nil {
return err
}
@@ -62,7 +63,7 @@ func RunStateTest(ruleSet RuleSet, p string, skipTests []string) error {
}
-func BenchStateTest(ruleSet RuleSet, p string, conf bconf, b *testing.B) error {
+func BenchStateTest(chainConfig *params.ChainConfig, p string, conf bconf, b *testing.B) error {
tests := make(map[string]VmTest)
if err := readJsonFile(p, &tests); err != nil {
return err
@@ -87,22 +88,22 @@ func BenchStateTest(ruleSet RuleSet, p string, conf bconf, b *testing.B) error {
b.ResetTimer()
for i := 0; i < b.N; i++ {
- benchStateTest(ruleSet, test, env, b)
+ benchStateTest(chainConfig, test, env, b)
}
return nil
}
-func benchStateTest(ruleSet RuleSet, test VmTest, env map[string]string, b *testing.B) {
+func benchStateTest(chainConfig *params.ChainConfig, test VmTest, env map[string]string, b *testing.B) {
b.StopTimer()
db, _ := ethdb.NewMemDatabase()
statedb := makePreState(db, test.Pre)
b.StartTimer()
- RunState(ruleSet, statedb, env, test.Exec)
+ RunState(chainConfig, statedb, env, test.Exec)
}
-func runStateTests(ruleSet RuleSet, tests map[string]VmTest, skipTests []string) error {
+func runStateTests(chainConfig *params.ChainConfig, tests map[string]VmTest, skipTests []string) error {
skipTest := make(map[string]bool, len(skipTests))
for _, name := range skipTests {
skipTest[name] = true
@@ -115,7 +116,7 @@ func runStateTests(ruleSet RuleSet, tests map[string]VmTest, skipTests []string)
}
//fmt.Println("StateTest:", name)
- if err := runStateTest(ruleSet, test); err != nil {
+ if err := runStateTest(chainConfig, test); err != nil {
return fmt.Errorf("%s: %s\n", name, err.Error())
}
@@ -126,7 +127,7 @@ func runStateTests(ruleSet RuleSet, tests map[string]VmTest, skipTests []string)
}
-func runStateTest(ruleSet RuleSet, test VmTest) error {
+func runStateTest(chainConfig *params.ChainConfig, test VmTest) error {
db, _ := ethdb.NewMemDatabase()
statedb := makePreState(db, test.Pre)
@@ -150,7 +151,7 @@ func runStateTest(ruleSet RuleSet, test VmTest) error {
logs vm.Logs
)
- ret, logs, _, _ = RunState(ruleSet, statedb, env, test.Transaction)
+ ret, logs, _, _ = RunState(chainConfig, statedb, env, test.Transaction)
// Compare expected and actual return
var rexp []byte
@@ -189,7 +190,7 @@ func runStateTest(ruleSet RuleSet, test VmTest) error {
}
}
- root, _ := statedb.Commit()
+ root, _ := statedb.Commit(false)
if common.HexToHash(test.PostStateRoot) != root {
return fmt.Errorf("Post state root error. Expected: %s have: %x", test.PostStateRoot, root)
}
@@ -204,7 +205,7 @@ func runStateTest(ruleSet RuleSet, test VmTest) error {
return nil
}
-func RunState(ruleSet RuleSet, statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) {
+func RunState(chainConfig *params.ChainConfig, 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"])
@@ -226,13 +227,13 @@ func RunState(ruleSet RuleSet, statedb *state.StateDB, env, tx map[string]string
key, _ := hex.DecodeString(tx["secretKey"])
addr := crypto.PubkeyToAddress(crypto.ToECDSA(key).PublicKey)
message := NewMessage(addr, to, data, value, gas, price, nonce)
- vmenv := NewEnvFromMap(ruleSet, statedb, env, tx)
+ vmenv := NewEnvFromMap(chainConfig, statedb, env, tx)
vmenv.origin = addr
ret, _, err := core.ApplyMessage(vmenv, message, gaspool)
if core.IsNonceErr(err) || core.IsInvalidTxErr(err) || core.IsGasLimitErr(err) {
statedb.RevertToSnapshot(snapshot)
}
- statedb.Commit()
+ statedb.Commit(chainConfig.IsEIP158(vmenv.BlockNumber()))
return ret, vmenv.state.Logs(), vmenv.Gas, err
}
diff --git a/tests/transaction_test_util.go b/tests/transaction_test_util.go
index 178f90284..be3514737 100644
--- a/tests/transaction_test_util.go
+++ b/tests/transaction_test_util.go
@@ -24,7 +24,6 @@ import (
"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"
@@ -164,7 +163,7 @@ func verifyTxFields(txTest TransactionTest, decodedTx *types.Transaction) (err e
decodedSender common.Address
)
- chainConfig := &core.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock}
+ chainConfig := &params.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock}
if chainConfig.IsHomestead(common.String2Big(txTest.Blocknumber)) {
decodedSender, err = decodedTx.From()
} else {
diff --git a/tests/util.go b/tests/util.go
index 8359e46fd..5296bb54b 100644
--- a/tests/util.go
+++ b/tests/util.go
@@ -148,27 +148,8 @@ type VmTest struct {
PostStateRoot string
}
-type RuleSet struct {
- HomesteadBlock *big.Int
- DAOForkBlock *big.Int
- DAOForkSupport bool
- HomesteadGasRepriceBlock *big.Int
-}
-
-func (r RuleSet) IsHomestead(n *big.Int) bool {
- return n.Cmp(r.HomesteadBlock) >= 0
-}
-
-func (r RuleSet) GasTable(num *big.Int) params.GasTable {
- if r.HomesteadGasRepriceBlock == nil || num == nil || num.Cmp(r.HomesteadGasRepriceBlock) < 0 {
- return params.GasTableHomestead
- }
-
- return params.GasTableHomesteadGasRepriceFork
-}
-
type Env struct {
- ruleSet RuleSet
+ chainConfig *params.ChainConfig
depth int
state *state.StateDB
skipTransfer bool
@@ -189,16 +170,16 @@ type Env struct {
evm *vm.EVM
}
-func NewEnv(ruleSet RuleSet, state *state.StateDB) *Env {
+func NewEnv(chainConfig *params.ChainConfig, state *state.StateDB) *Env {
env := &Env{
- ruleSet: ruleSet,
- state: state,
+ chainConfig: chainConfig,
+ state: state,
}
return env
}
-func NewEnvFromMap(ruleSet RuleSet, state *state.StateDB, envValues map[string]string, exeValues map[string]string) *Env {
- env := NewEnv(ruleSet, state)
+func NewEnvFromMap(chainConfig *params.ChainConfig, state *state.StateDB, envValues map[string]string, exeValues map[string]string) *Env {
+ env := NewEnv(chainConfig, state)
env.origin = common.HexToAddress(exeValues["caller"])
env.parent = common.HexToHash(envValues["previousHash"])
@@ -217,16 +198,16 @@ func NewEnvFromMap(ruleSet RuleSet, state *state.StateDB, envValues map[string]s
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 }
-func (self *Env) Coinbase() common.Address { return self.coinbase }
-func (self *Env) Time() *big.Int { return self.time }
-func (self *Env) Difficulty() *big.Int { return self.difficulty }
-func (self *Env) Db() vm.Database { return self.state }
-func (self *Env) GasLimit() *big.Int { return self.gasLimit }
-func (self *Env) VmType() vm.Type { return vm.StdVmTy }
+func (self *Env) ChainConfig() *params.ChainConfig { return self.chainConfig }
+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 }
+func (self *Env) Coinbase() common.Address { return self.coinbase }
+func (self *Env) Time() *big.Int { return self.time }
+func (self *Env) Difficulty() *big.Int { return self.difficulty }
+func (self *Env) Db() vm.Database { return self.state }
+func (self *Env) GasLimit() *big.Int { return self.gasLimit }
+func (self *Env) VmType() vm.Type { return vm.StdVmTy }
func (self *Env) GetHash(n uint64) common.Hash {
return common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String())))
}
diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go
index ea683a8d3..f00af87b9 100644
--- a/tests/vm_test_util.go
+++ b/tests/vm_test_util.go
@@ -225,7 +225,7 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, vm.Logs,
caller := state.GetOrNewStateObject(from)
- vmenv := NewEnvFromMap(RuleSet{params.MainNetHomesteadBlock, params.MainNetDAOForkBlock, true, nil}, state, env, exec)
+ vmenv := NewEnvFromMap(&params.ChainConfig{params.MainNetHomesteadBlock, params.MainNetDAOForkBlock, true, nil, common.Hash{}, nil}, state, env, exec)
vmenv.vmTest = true
vmenv.skipTransfer = true
vmenv.initial = true