OSDN Git Service

fix(remove pow): solve functional-tests error (#1888)
authorMingjing <2595400537@qq.com>
Tue, 13 Apr 2021 11:58:07 +0000 (19:58 +0800)
committerGitHub <noreply@github.com>
Tue, 13 Apr 2021 11:58:07 +0000 (19:58 +0800)
test/block_test.go
test/protocol_test.go
test/tx_test.go

index 8eaf5da..d2b0a9d 100644 (file)
@@ -7,10 +7,10 @@ import (
        "time"
 
        "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"
-       dbm "github.com/bytom/bytom/database/leveldb"
 )
 
 func TestBlockHeader(t *testing.T) {
@@ -28,8 +28,6 @@ func TestBlockHeader(t *testing.T) {
                prevHeight func() uint64
                timestamp  func() uint64
                prevHash   func() *bc.Hash
-               bits       func() uint64
-               solve      bool
                valid      bool
        }{
                {
@@ -38,8 +36,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,
                },
                {
@@ -48,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,
                },
                {
@@ -58,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,
                },
                {
@@ -78,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,
                },
                {
@@ -88,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,
                },
                {
@@ -98,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,
                },
                {
@@ -108,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,
                },
        }
@@ -124,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 {
@@ -179,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")
        }
 }
index 9336933..d582601 100644 (file)
@@ -7,9 +7,9 @@ import (
        "testing"
 
        "github.com/bytom/bytom/consensus"
+       dbm "github.com/bytom/bytom/database/leveldb"
        "github.com/bytom/bytom/protocol/bc/types"
        "github.com/bytom/bytom/protocol/vm"
-       dbm "github.com/bytom/bytom/database/leveldb"
 )
 
 // case1:           |------c1(height=7)
@@ -122,7 +122,10 @@ func TestDoubleSpentInDiffBlock(t *testing.T) {
        }
 
        newBlock, err := NewBlock(chain, []*types.Tx{tx}, []byte{byte(vm.OP_TRUE)})
-       err = SolveAndUpdate(chain, newBlock)
+       if err != nil {
+               t.Fatal(err)
+       }
+       _, err = chain.ProcessBlock(newBlock)
        if err != nil {
                t.Fatal(err)
        }
@@ -189,7 +192,7 @@ func TestDoubleSpentInSameBlock(t *testing.T) {
                t.Fatal(err)
        }
 
-       if err := SolveAndUpdate(chain, block); err == nil {
+       if _, err := chain.ProcessBlock(block); err == nil {
                t.Fatalf("process double spent tx success")
        }
 }
@@ -242,7 +245,7 @@ func TestTxPoolDependencyTx(t *testing.T) {
                t.Fatal(err)
        }
 
-       if err := SolveAndUpdate(chain, block); err != nil {
+       if _, err = chain.ProcessBlock(block); err != nil {
                t.Fatal("process dependency tx failed")
        }
 }
index 4c381ee..9b4caad 100644 (file)
@@ -15,11 +15,11 @@ import (
        "github.com/bytom/bytom/asset"
        "github.com/bytom/bytom/blockchain/pseudohsm"
        "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/validation"
        "github.com/bytom/bytom/protocol/vm"
-       dbm "github.com/bytom/bytom/database/leveldb"
 )
 
 func init() {
@@ -200,14 +200,14 @@ func TestCoinbaseMature(t *testing.T) {
                if err != nil {
                        t.Fatal(err)
                }
-               if err := SolveAndUpdate(chain, block); err == nil {
+               if _, err = chain.ProcessBlock(block); err == nil {
                        t.Fatal("spent immature coinbase output success")
                }
                block, err = NewBlock(chain, nil, defaultCtrlProg)
                if err != nil {
                        t.Fatal(err)
                }
-               if err := SolveAndUpdate(chain, block); err != nil {
+               if _, err := chain.ProcessBlock(block); err != nil {
                        t.Fatal(err)
                }
        }
@@ -216,7 +216,7 @@ func TestCoinbaseMature(t *testing.T) {
        if err != nil {
                t.Fatal(err)
        }
-       if err := SolveAndUpdate(chain, block); err != nil {
+       if _, err = chain.ProcessBlock(block); err != nil {
                t.Fatalf("spent mature coinbase output failed: %s", err)
        }
 }
@@ -257,7 +257,7 @@ func TestCoinbaseTx(t *testing.T) {
                        t.Fatal(err)
                }
 
-               if err := SolveAndUpdate(chain, block); err == nil {
+               if _, err = chain.ProcessBlock(block); err == nil {
                        t.Fatalf("invalid coinbase tx validate success")
                }
        }