2015-04-20 11:14:57 -05:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2015-05-12 07:24:11 -05:00
|
|
|
"path/filepath"
|
2015-04-20 11:14:57 -05:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: refactor test setup & execution to better align with vm and tx tests
|
|
|
|
func TestBcValidBlockTests(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcValidBlockTest.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBcUncleTests(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcUncleTest.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBcUncleHeaderValidityTests(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcUncleHeaderValiditiy.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBcInvalidHeaderTests(t *testing.T) {
|
2015-04-22 08:28:04 -05:00
|
|
|
runBlockTestsInFile("files/BlockTests/bcInvalidHeaderTest.json", []string{}, t)
|
2015-04-20 11:14:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBcInvalidRLPTests(t *testing.T) {
|
2015-04-22 16:15:52 -05:00
|
|
|
runBlockTestsInFile("files/BlockTests/bcInvalidRLPTest.json", []string{}, t)
|
2015-04-20 11:14:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBcJSAPITests(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcJS_API_Test.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBcRPCAPITests(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcRPC_API_Test.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBcForkBlockTests(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcForkBlockTest.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
2015-05-07 06:03:22 -05:00
|
|
|
func TestBcTotalDifficulty(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcTotalDifficultyTest.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
2015-04-20 11:14:57 -05:00
|
|
|
func runBlockTestsInFile(filepath string, snafus []string, t *testing.T) {
|
|
|
|
bt, err := LoadBlockTests(filepath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
notWorking := make(map[string]bool, 100)
|
|
|
|
for _, name := range snafus {
|
|
|
|
notWorking[name] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, test := range bt {
|
|
|
|
if !notWorking[name] {
|
|
|
|
runBlockTest(name, test, t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runBlockTest(name string, test *BlockTest, t *testing.T) {
|
|
|
|
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
|
2015-04-27 12:32:45 -05:00
|
|
|
statedb, err := test.InsertPreState(ethereum)
|
2015-04-20 11:14:57 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("InsertPreState: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = test.TryBlocksInsert(ethereum.ChainManager())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = test.ValidatePostState(statedb); err != nil {
|
|
|
|
t.Fatal("post state validation failed: %v", err)
|
|
|
|
}
|
2015-05-05 01:34:29 -05:00
|
|
|
t.Log("Test passed: ", name)
|
2015-04-20 11:14:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func testEthConfig() *eth.Config {
|
2015-05-12 11:33:04 -05:00
|
|
|
ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"))
|
2015-04-20 11:14:57 -05:00
|
|
|
|
|
|
|
return ð.Config{
|
|
|
|
DataDir: common.DefaultDataDir(),
|
2015-05-09 05:51:40 -05:00
|
|
|
Verbosity: 5,
|
2015-04-20 11:14:57 -05:00
|
|
|
Etherbase: "primary",
|
|
|
|
AccountManager: accounts.NewManager(ks),
|
|
|
|
NewDB: func(path string) (common.Database, error) { return ethdb.NewMemDatabase() },
|
|
|
|
}
|
|
|
|
}
|