Skip to content

Commit 0381b48

Browse files
authored
add state test for w3q (ethereum#50)
* add state test for w3q * fix go_import format
1 parent c621b5c commit 0381b48

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "tests"]
22
path = tests/testdata
3-
url = https://github.com/ethereum/tests
3+
url = https://github.com/QuarkChain/tests
44
shallow = true
55
[submodule "evm-benchmarks"]
66
path = tests/evm-benchmarks

tests/state_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ import (
2727
"strings"
2828
"testing"
2929

30+
"github.com/ethereum/go-ethereum/common"
3031
"github.com/ethereum/go-ethereum/core"
3132
"github.com/ethereum/go-ethereum/core/rawdb"
33+
"github.com/ethereum/go-ethereum/core/state"
3234
"github.com/ethereum/go-ethereum/core/types"
3335
"github.com/ethereum/go-ethereum/core/vm"
36+
"github.com/ethereum/go-ethereum/crypto"
3437
"github.com/ethereum/go-ethereum/eth/tracers/logger"
3538
)
3639

@@ -252,3 +255,54 @@ func runBenchmark(b *testing.B, t *StateTest) {
252255
})
253256
}
254257
}
258+
259+
var web3QStateTestDir = filepath.Join(baseDir, "Web3QTest")
260+
261+
func TestWeb3QState(t *testing.T) {
262+
t.Parallel()
263+
st := new(testMatcher)
264+
265+
//st.fails("TestWeb3QState/Stake/StakeFor25kCode.json/London0/trie", "insufficient staking for code")
266+
for _, dir := range []string{
267+
web3QStateTestDir,
268+
} {
269+
st.walk(t, dir, func(t *testing.T, name string, test *StateTest) {
270+
for _, subtest := range test.Subtests() {
271+
subtest := subtest
272+
key := fmt.Sprintf("%s%d", subtest.Fork, subtest.Index)
273+
t.Run(key+"/trie", func(t *testing.T) {
274+
config := vm.Config{}
275+
_, db, err := test.Run(subtest, config, false)
276+
err = st.checkFailure(t, err)
277+
if err != nil {
278+
printStateTrie(db, test, t)
279+
t.Error(err)
280+
}
281+
})
282+
}
283+
})
284+
}
285+
}
286+
287+
func printStateTrie(db *state.StateDB, test *StateTest, t *testing.T) {
288+
noContractCreation := test.json.Tx.To != ""
289+
290+
t.Log("--------------------StateInfo---------------------")
291+
292+
coinbase := test.json.Env.Coinbase
293+
t.Logf("--------------------CoinBase---------------------- \naddress: %s \nbalance: %d \nnonce: %d \n", coinbase.Hex(), db.GetBalance(coinbase).Int64(), db.GetNonce(coinbase))
294+
for addr, acc := range test.json.Pre {
295+
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)))
296+
}
297+
298+
if !noContractCreation {
299+
caller := common.HexToAddress("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")
300+
contract := getCreateContractAddr(caller, test.json.Tx.Nonce)
301+
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)))
302+
}
303+
t.Log("-------------------END-------------------------")
304+
}
305+
306+
func getCreateContractAddr(caller common.Address, nonce uint64) common.Address {
307+
return crypto.CreateAddress(caller, nonce)
308+
}

tests/state_test_util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
230230
snapshot := statedb.Snapshot()
231231
gaspool := new(core.GasPool)
232232
gaspool.AddGas(block.GasLimit())
233-
if _, err := core.ApplyMessage(evm, msg, gaspool); err != nil {
233+
if res, err := core.ApplyMessage(evm, msg, gaspool); err != nil {
234234
statedb.RevertToSnapshot(snapshot)
235+
fmt.Println("evm result:", res)
235236
}
236-
237237
// Commit block
238238
statedb.Commit(config.IsEIP158(block.Number()))
239239
// Add 0-value mining reward. This only makes a difference in the cases

0 commit comments

Comments
 (0)