2015-04-20 19:14:57 +03:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2015-05-12 15:24:11 +03:00
|
|
|
"path/filepath"
|
2015-04-20 19:14:57 +03: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 16:28:04 +03:00
|
|
|
runBlockTestsInFile("files/BlockTests/bcInvalidHeaderTest.json", []string{}, t)
|
2015-04-20 19:14:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBcInvalidRLPTests(t *testing.T) {
|
2015-04-23 00:15:52 +03:00
|
|
|
runBlockTestsInFile("files/BlockTests/bcInvalidRLPTest.json", []string{}, t)
|
2015-04-20 19:14:57 +03: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 14:03:22 +03:00
|
|
|
func TestBcTotalDifficulty(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcTotalDifficultyTest.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
2015-05-18 17:28:54 +03:00
|
|
|
func TestBcWallet(t *testing.T) {
|
|
|
|
runBlockTestsInFile("files/BlockTests/bcWalletTest.json", []string{}, t)
|
|
|
|
}
|
|
|
|
|
2015-04-20 19:14:57 +03: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 20:32:45 +03:00
|
|
|
statedb, err := test.InsertPreState(ethereum)
|
2015-04-20 19:14:57 +03: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 09:34:29 +03:00
|
|
|
t.Log("Test passed: ", name)
|
2015-04-20 19:14:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testEthConfig() *eth.Config {
|
2015-05-12 19:33:04 +03:00
|
|
|
ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"))
|
2015-04-20 19:14:57 +03:00
|
|
|
|
|
|
|
return ð.Config{
|
|
|
|
DataDir: common.DefaultDataDir(),
|
2015-05-09 13:51:40 +03:00
|
|
|
Verbosity: 5,
|
2015-04-20 19:14:57 +03:00
|
|
|
Etherbase: "primary",
|
|
|
|
AccountManager: accounts.NewManager(ks),
|
|
|
|
NewDB: func(path string) (common.Database, error) { return ethdb.NewMemDatabase() },
|
|
|
|
}
|
|
|
|
}
|