aboutsummaryrefslogtreecommitdiffstats
path: root/tests/block_test_util.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-06-11 00:04:56 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-06-19 04:13:42 +0800
commita67a15528aa5da902a17d49f5dad19db3975032a (patch)
treea3239cf5230a0481e85358a43c8e2eaa592f7de1 /tests/block_test_util.go
parent7b9fbb088a74de746dc3f0aa76dbbc8985c2b12c (diff)
downloadgo-tangerine-a67a15528aa5da902a17d49f5dad19db3975032a.tar
go-tangerine-a67a15528aa5da902a17d49f5dad19db3975032a.tar.gz
go-tangerine-a67a15528aa5da902a17d49f5dad19db3975032a.tar.bz2
go-tangerine-a67a15528aa5da902a17d49f5dad19db3975032a.tar.lz
go-tangerine-a67a15528aa5da902a17d49f5dad19db3975032a.tar.xz
go-tangerine-a67a15528aa5da902a17d49f5dad19db3975032a.tar.zst
go-tangerine-a67a15528aa5da902a17d49f5dad19db3975032a.zip
Split tests from helper code
Diffstat (limited to 'tests/block_test_util.go')
-rw-r--r--tests/block_test_util.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/block_test_util.go b/tests/block_test_util.go
index 200fcbd59..224c14283 100644
--- a/tests/block_test_util.go
+++ b/tests/block_test_util.go
@@ -7,17 +7,21 @@ import (
"fmt"
"io/ioutil"
"math/big"
+ "path/filepath"
"runtime"
"strconv"
"strings"
+ "testing"
"time"
+ "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
+ "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -83,6 +87,68 @@ type btTransaction struct {
Value string
}
+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
+ statedb, err := test.InsertPreState(ethereum)
+ 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)
+ }
+ t.Log("Test passed: ", name)
+}
+
+func testEthConfig() *eth.Config {
+ ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"))
+
+ return &eth.Config{
+ DataDir: common.DefaultDataDir(),
+ Verbosity: 5,
+ Etherbase: "primary",
+ AccountManager: accounts.NewManager(ks),
+ NewDB: func(path string) (common.Database, error) { return ethdb.NewMemDatabase() },
+ }
+}
+
// LoadBlockTests loads a block test JSON file.
func LoadBlockTests(file string) (map[string]*BlockTest, error) {
bt := make(map[string]*btJSON)