diff --git a/.gitmodules b/.gitmodules index 241c169c4772..1611cbc99737 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "tests"] path = tests/testdata - url = https://github.com/ethereum/tests + url = https://github.com/QuarkChain/tests shallow = true [submodule "evm-benchmarks"] path = tests/evm-benchmarks diff --git a/tests/state_test.go b/tests/state_test.go index d2c92b211cd1..4595bcee9079 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -27,10 +27,13 @@ import ( "strings" "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/rawdb" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth/tracers/logger" ) @@ -252,3 +255,54 @@ func runBenchmark(b *testing.B, t *StateTest) { }) } } + +var web3QStateTestDir = filepath.Join(baseDir, "Web3QTest") + +func TestWeb3QState(t *testing.T) { + t.Parallel() + st := new(testMatcher) + + //st.fails("TestWeb3QState/Stake/StakeFor25kCode.json/London0/trie", "insufficient staking for code") + for _, dir := range []string{ + web3QStateTestDir, + } { + st.walk(t, dir, func(t *testing.T, name string, test *StateTest) { + for _, subtest := range test.Subtests() { + subtest := subtest + key := fmt.Sprintf("%s%d", subtest.Fork, subtest.Index) + t.Run(key+"/trie", func(t *testing.T) { + config := vm.Config{} + _, db, err := test.Run(subtest, config, false) + err = st.checkFailure(t, err) + if err != nil { + printStateTrie(db, test, t) + t.Error(err) + } + }) + } + }) + } +} + +func printStateTrie(db *state.StateDB, test *StateTest, t *testing.T) { + noContractCreation := test.json.Tx.To != "" + + t.Log("--------------------StateInfo---------------------") + + coinbase := test.json.Env.Coinbase + t.Logf("--------------------CoinBase---------------------- \naddress: %s \nbalance: %d \nnonce: %d \n", coinbase.Hex(), db.GetBalance(coinbase).Int64(), db.GetNonce(coinbase)) + for addr, acc := range test.json.Pre { + t.Logf("--------------------Account---------------------- \naddress: %s \npre balance: %d \n balance: %d \nnonce: %d \ncode len: %d \n", addr.Hex(), acc.Balance.Int64(), db.GetBalance(addr).Int64(), db.GetNonce(addr), len(db.GetCode(addr))) + } + + if !noContractCreation { + caller := common.HexToAddress("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b") + contract := getCreateContractAddr(caller, test.json.Tx.Nonce) + t.Logf("--------------------Account---------------------- \naddress: %s \nbalance: %d \nnonce: %d \ncode len: %d \n", contract.Hex(), db.GetBalance(contract).Int64(), db.GetNonce(contract), len(db.GetCode(contract))) + } + t.Log("-------------------END-------------------------") +} + +func getCreateContractAddr(caller common.Address, nonce uint64) common.Address { + return crypto.CreateAddress(caller, nonce) +} diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 4fd3cf76b210..97a3a9ae0362 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -230,10 +230,10 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh snapshot := statedb.Snapshot() gaspool := new(core.GasPool) gaspool.AddGas(block.GasLimit()) - if _, err := core.ApplyMessage(evm, msg, gaspool); err != nil { + if res, err := core.ApplyMessage(evm, msg, gaspool); err != nil { statedb.RevertToSnapshot(snapshot) + fmt.Println("evm result:", res) } - // Commit block statedb.Commit(config.IsEIP158(block.Number())) // Add 0-value mining reward. This only makes a difference in the cases diff --git a/tests/testdata b/tests/testdata index 092a8834dc44..4028eb68971b 160000 --- a/tests/testdata +++ b/tests/testdata @@ -1 +1 @@ -Subproject commit 092a8834dc445e683103689d6f0e75a5d380a190 +Subproject commit 4028eb68971bf2f0765400c1fa3b71e9f91b4846