1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
package main
import (
"path"
"testing"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/tests"
)
// TODO: refactor test setup & execution to better align with vm and tx tests
// TODO: refactor to avoid duplication with cmd/geth/blocktest.go
func TestBcValidBlockTests(t *testing.T) {
runBlockTestsInFile("../../tests/files/BlockTests/bcValidBlockTest.json", t)
}
/*
func TestBcUncleTests(t *testing.T) {
runBlockTestsInFile("../../tests/files/BlockTests/bcUncleTest.json", t)
}
*/
func runBlockTestsInFile(filepath string, t *testing.T) {
bt, err := tests.LoadBlockTests(filepath)
if err != nil {
t.Fatal(err)
}
for name, test := range bt {
runTest(name, test, t)
}
}
func runTest(name string, test *tests.BlockTest, t *testing.T) {
t.Log("Running test: ", name)
cfg := testEthConfig()
ethereum, err := eth.New(cfg)
if err != nil {
t.Fatalf("%v", err)
}
err = ethereum.Start()
if err != nil {
t.Fatalf("%v", err)
}
// import the genesis block
ethereum.ResetWithGenesisBlock(test.Genesis)
// import pre accounts
statedb, err := test.InsertPreState(ethereum.StateDb())
if err != nil {
t.Fatalf("InsertPreState: %v", err)
}
// insert the test blocks, which will execute all transactions
if err := test.InsertBlocks(ethereum.ChainManager()); err != nil {
t.Fatalf("Block Test load error: %v %T", err, err)
}
if err := test.ValidatePostState(statedb); err != nil {
t.Fatal("post state validation failed: %v", err)
}
t.Log("Test passed: ", name)
}
func testEthConfig() *eth.Config {
ks := crypto.NewKeyStorePassphrase(path.Join(common.DefaultDataDir(), "keys"))
return ð.Config{
DataDir: common.DefaultDataDir(),
LogLevel: 5,
Etherbase: "primary",
AccountManager: accounts.NewManager(ks),
NewDB: func(path string) (common.Database, error) { return ethdb.NewMemDatabase() },
}
}
|