OSDN Git Service

init delete the pow related (#55)
[bytom/vapor.git] / test / block_test.go
index eb3602c..deb5474 100644 (file)
@@ -17,7 +17,11 @@ import (
 func TestBlockHeader(t *testing.T) {
        db := dbm.NewDB("block_test_db", "leveldb", "block_test_db")
        defer os.RemoveAll("block_test_db")
-       chain, _, _, _ := MockChain(db)
+       chain, _, _, err := MockChain(db)
+       if err != nil {
+               t.Fatal(err)
+       }
+
        genesisHeader := chain.BestBlockHeader()
        if err := AppendBlocks(chain, 1); err != nil {
                t.Fatal(err)
@@ -29,8 +33,6 @@ func TestBlockHeader(t *testing.T) {
                prevHeight func() uint64
                timestamp  func() uint64
                prevHash   func() *bc.Hash
-               bits       func() uint64
-               solve      bool
                valid      bool
        }{
                {
@@ -39,8 +41,6 @@ func TestBlockHeader(t *testing.T) {
                        prevHeight: chain.BestBlockHeight,
                        timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
                        prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
                        valid:      true,
                },
                {
@@ -49,8 +49,6 @@ func TestBlockHeader(t *testing.T) {
                        prevHeight: func() uint64 { return chain.BestBlockHeight() + 1 },
                        timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
                        prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
                        valid:      false,
                },
                {
@@ -59,18 +57,6 @@ func TestBlockHeader(t *testing.T) {
                        prevHeight: chain.BestBlockHeight,
                        timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
                        prevHash:   func() *bc.Hash { hash := genesisHeader.Hash(); return &hash },
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
-                       valid:      false,
-               },
-               {
-                       desc:       "invalid bits",
-                       version:    func() uint64 { return chain.BestBlockHeader().Version },
-                       prevHeight: chain.BestBlockHeight,
-                       timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
-                       prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits + 100 },
-                       solve:      true,
                        valid:      false,
                },
                {
@@ -79,8 +65,6 @@ func TestBlockHeader(t *testing.T) {
                        prevHeight: chain.BestBlockHeight,
                        timestamp:  func() uint64 { return uint64(time.Now().Unix()) + consensus.MaxTimeOffsetSeconds + 60 },
                        prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
                        valid:      false,
                },
                {
@@ -89,8 +73,6 @@ func TestBlockHeader(t *testing.T) {
                        prevHeight: chain.BestBlockHeight,
                        timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 3 },
                        prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
                        valid:      true,
                },
                {
@@ -99,8 +81,6 @@ func TestBlockHeader(t *testing.T) {
                        prevHeight: chain.BestBlockHeight,
                        timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp - 1 },
                        prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
                        valid:      true,
                },
                {
@@ -109,8 +89,6 @@ func TestBlockHeader(t *testing.T) {
                        prevHeight: chain.BestBlockHeight,
                        timestamp:  func() uint64 { return genesisHeader.Timestamp },
                        prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
                        valid:      false,
                },
        }
@@ -125,15 +103,7 @@ func TestBlockHeader(t *testing.T) {
                block.Height = c.prevHeight() + 1
                block.Timestamp = c.timestamp()
                block.PreviousBlockHash = *c.prevHash()
-               block.Bits = c.bits()
-               seed, err := chain.CalcNextSeed(&block.PreviousBlockHash)
-               if err != nil && c.valid {
-                       t.Fatal(err)
-               }
 
-               if c.solve {
-                       Solve(seed, block)
-               }
                _, err = chain.ProcessBlock(block)
                result := err == nil
                if result != c.valid {
@@ -180,7 +150,7 @@ func TestMaxBlockGas(t *testing.T) {
                t.Fatal(err)
        }
 
-       if err := SolveAndUpdate(chain, block); err == nil {
+       if _, err := chain.ProcessBlock(block); err == nil {
                t.Fatalf("test max block gas failed")
        }
 }