OSDN Git Service

:art:Refine code (#1315)
[bytom/bytom.git] / test / block_test.go
index 6d1d31c..3953c96 100644 (file)
@@ -38,7 +38,7 @@ func TestBlockHeader(t *testing.T) {
                        desc:       "block version is 0",
                        version:    func() uint64 { return 0 },
                        prevHeight: chain.BestBlockHeight,
-                       timestamp:  func() uint64 { return uint64(time.Now().Unix()) },
+                       timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
                        prevHash:   chain.BestBlockHash,
                        bits:       func() uint64 { return chain.BestBlockHeader().Bits },
                        solve:      true,
@@ -48,7 +48,7 @@ func TestBlockHeader(t *testing.T) {
                        desc:       "block version grater than prevBlock.Version",
                        version:    func() uint64 { return chain.BestBlockHeader().Version + 10 },
                        prevHeight: chain.BestBlockHeight,
-                       timestamp:  func() uint64 { return uint64(time.Now().Unix()) },
+                       timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
                        prevHash:   chain.BestBlockHash,
                        bits:       func() uint64 { return chain.BestBlockHeader().Bits },
                        solve:      true,
@@ -58,7 +58,7 @@ func TestBlockHeader(t *testing.T) {
                        desc:       "invalid block, misorder block height",
                        version:    func() uint64 { return chain.BestBlockHeader().Version },
                        prevHeight: func() uint64 { return chain.BestBlockHeight() + 1 },
-                       timestamp:  func() uint64 { return uint64(time.Now().Unix()) },
+                       timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
                        prevHash:   chain.BestBlockHash,
                        bits:       func() uint64 { return chain.BestBlockHeader().Bits },
                        solve:      true,
@@ -68,7 +68,7 @@ func TestBlockHeader(t *testing.T) {
                        desc:       "invalid prev hash, prev hash dismatch",
                        version:    func() uint64 { return chain.BestBlockHeader().Version },
                        prevHeight: chain.BestBlockHeight,
-                       timestamp:  func() uint64 { return uint64(time.Now().Unix()) },
+                       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,
@@ -78,7 +78,7 @@ func TestBlockHeader(t *testing.T) {
                        desc:       "invalid bits",
                        version:    func() uint64 { return chain.BestBlockHeader().Version },
                        prevHeight: chain.BestBlockHeight,
-                       timestamp:  func() uint64 { return uint64(time.Now().Unix()) },
+                       timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
                        prevHash:   chain.BestBlockHash,
                        bits:       func() uint64 { return chain.BestBlockHeader().Bits + 100 },
                        solve:      true,