@@ -27,10 +27,13 @@ import (
27
27
"strings"
28
28
"testing"
29
29
30
+ "github.com/ethereum/go-ethereum/common"
30
31
"github.com/ethereum/go-ethereum/core"
31
32
"github.com/ethereum/go-ethereum/core/rawdb"
33
+ "github.com/ethereum/go-ethereum/core/state"
32
34
"github.com/ethereum/go-ethereum/core/types"
33
35
"github.com/ethereum/go-ethereum/core/vm"
36
+ "github.com/ethereum/go-ethereum/crypto"
34
37
"github.com/ethereum/go-ethereum/eth/tracers/logger"
35
38
)
36
39
@@ -252,3 +255,54 @@ func runBenchmark(b *testing.B, t *StateTest) {
252
255
})
253
256
}
254
257
}
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---------------------- \n address: %s \n balance: %d \n nonce: %d \n " , coinbase .Hex (), db .GetBalance (coinbase ).Int64 (), db .GetNonce (coinbase ))
294
+ for addr , acc := range test .json .Pre {
295
+ t .Logf ("--------------------Account---------------------- \n address: %s \n pre balance: %d \n balance: %d \n nonce: %d \n code 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---------------------- \n address: %s \n balance: %d \n nonce: %d \n code 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
+ }
0 commit comments