aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-04-19 06:35:48 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-04-20 23:46:35 +0800
commit805345d13594b41e5dd2e4fed471c58c3775be9e (patch)
tree8abbabf321edb82ce7e93ff6c7f66bbf1ce4c56c /cmd
parentc453f1f37093445ba1d9eba5a075169ef0566c19 (diff)
downloaddexon-805345d13594b41e5dd2e4fed471c58c3775be9e.tar
dexon-805345d13594b41e5dd2e4fed471c58c3775be9e.tar.gz
dexon-805345d13594b41e5dd2e4fed471c58c3775be9e.tar.bz2
dexon-805345d13594b41e5dd2e4fed471c58c3775be9e.tar.lz
dexon-805345d13594b41e5dd2e4fed471c58c3775be9e.tar.xz
dexon-805345d13594b41e5dd2e4fed471c58c3775be9e.tar.zst
dexon-805345d13594b41e5dd2e4fed471c58c3775be9e.zip
Add block tests wrapper and fixes for tx tests
* Add fixes to parsing and converting of fields in tx tests * Correct logic in tx tests; validation of fields and correct logic for when RLP decoding works/fails and when this is expected or not * Rename files for consistency * Add block tests wrapper to run block tests with go test
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/block_go_test.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/cmd/geth/block_go_test.go b/cmd/geth/block_go_test.go
new file mode 100644
index 000000000..1980e4798
--- /dev/null
+++ b/cmd/geth/block_go_test.go
@@ -0,0 +1,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 &eth.Config{
+ DataDir: common.DefaultDataDir(),
+ LogLevel: 5,
+ Etherbase: "primary",
+ AccountManager: accounts.NewManager(ks),
+ NewDB: func(path string) (common.Database, error) { return ethdb.NewMemDatabase() },
+ }
+}