OSDN Git Service

fix rollback (#1952)
[bytom/bytom.git] / test / block_test.go
index 3953c96..d2b0a9d 100644 (file)
@@ -1,18 +1,16 @@
 // +build functional
 
 package test
-
 import (
        "os"
        "testing"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
-       "github.com/bytom/consensus"
-       "github.com/bytom/protocol/bc"
-       "github.com/bytom/protocol/bc/types"
-       "github.com/bytom/protocol/vm"
+       "github.com/bytom/bytom/consensus"
+       dbm "github.com/bytom/bytom/database/leveldb"
+       "github.com/bytom/bytom/protocol/bc"
+       "github.com/bytom/bytom/protocol/bc/types"
+       "github.com/bytom/bytom/protocol/vm"
 )
 
 func TestBlockHeader(t *testing.T) {
@@ -30,28 +28,14 @@ func TestBlockHeader(t *testing.T) {
                prevHeight func() uint64
                timestamp  func() uint64
                prevHash   func() *bc.Hash
-               bits       func() uint64
-               solve      bool
                valid      bool
        }{
                {
-                       desc:       "block version is 0",
-                       version:    func() uint64 { return 0 },
-                       prevHeight: chain.BestBlockHeight,
-                       timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
-                       prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
-                       valid:      false,
-               },
-               {
-                       desc:       "block version grater than prevBlock.Version",
-                       version:    func() uint64 { return chain.BestBlockHeader().Version + 10 },
+                       desc:       "block version is 1",
+                       version:    func() uint64 { return 1 },
                        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,
                },
                {
@@ -60,8 +44,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,
                },
                {
@@ -70,18 +52,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,
                },
                {
@@ -90,8 +60,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,
                },
                {
@@ -100,8 +68,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,
                },
                {
@@ -110,8 +76,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,
                },
                {
@@ -120,8 +84,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,
                },
        }
@@ -136,15 +98,10 @@ 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 {
@@ -191,7 +148,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")
        }
 }