@@ -7,17 +7,21 @@ import (
77 "fmt"
88 "io/ioutil"
99 "math/big"
10+ "path/filepath"
1011 "runtime"
1112 "strconv"
1213 "strings"
14+ "testing"
1315 "time"
1416
17+ "github.com/ethereum/go-ethereum/accounts"
1518 "github.com/ethereum/go-ethereum/common"
1619 "github.com/ethereum/go-ethereum/core"
1720 "github.com/ethereum/go-ethereum/core/state"
1821 "github.com/ethereum/go-ethereum/core/types"
1922 "github.com/ethereum/go-ethereum/crypto"
2023 "github.com/ethereum/go-ethereum/eth"
24+ "github.com/ethereum/go-ethereum/ethdb"
2125 "github.com/ethereum/go-ethereum/rlp"
2226)
2327
@@ -83,6 +87,68 @@ type btTransaction struct {
8387 Value string
8488}
8589
90+ func runBlockTestsInFile (filepath string , snafus []string , t * testing.T ) {
91+ bt , err := LoadBlockTests (filepath )
92+ if err != nil {
93+ t .Fatal (err )
94+ }
95+
96+ notWorking := make (map [string ]bool , 100 )
97+ for _ , name := range snafus {
98+ notWorking [name ] = true
99+ }
100+
101+ for name , test := range bt {
102+ if ! notWorking [name ] {
103+ runBlockTest (name , test , t )
104+ }
105+ }
106+ }
107+
108+ func runBlockTest (name string , test * BlockTest , t * testing.T ) {
109+ cfg := testEthConfig ()
110+ ethereum , err := eth .New (cfg )
111+ if err != nil {
112+ t .Fatalf ("%v" , err )
113+ }
114+
115+ err = ethereum .Start ()
116+ if err != nil {
117+ t .Fatalf ("%v" , err )
118+ }
119+
120+ // import the genesis block
121+ ethereum .ResetWithGenesisBlock (test .Genesis )
122+
123+ // import pre accounts
124+ statedb , err := test .InsertPreState (ethereum )
125+ if err != nil {
126+ t .Fatalf ("InsertPreState: %v" , err )
127+ }
128+
129+ err = test .TryBlocksInsert (ethereum .ChainManager ())
130+ if err != nil {
131+ t .Fatal (err )
132+ }
133+
134+ if err = test .ValidatePostState (statedb ); err != nil {
135+ t .Fatal ("post state validation failed: %v" , err )
136+ }
137+ t .Log ("Test passed: " , name )
138+ }
139+
140+ func testEthConfig () * eth.Config {
141+ ks := crypto .NewKeyStorePassphrase (filepath .Join (common .DefaultDataDir (), "keystore" ))
142+
143+ return & eth.Config {
144+ DataDir : common .DefaultDataDir (),
145+ Verbosity : 5 ,
146+ Etherbase : "primary" ,
147+ AccountManager : accounts .NewManager (ks ),
148+ NewDB : func (path string ) (common.Database , error ) { return ethdb .NewMemDatabase () },
149+ }
150+ }
151+
86152// LoadBlockTests loads a block test JSON file.
87153func LoadBlockTests (file string ) (map [string ]* BlockTest , error ) {
88154 bt := make (map [string ]* btJSON )
0 commit comments