OSDN Git Service

try to fix ban peer bug (#273)
[bytom/vapor.git] / test / block_test_util.go
index e609d85..890d680 100644 (file)
@@ -1,16 +1,11 @@
 package test
 
 import (
-       "github.com/vapor/consensus"
-       "github.com/vapor/crypto"
-       "github.com/vapor/crypto/ed25519/chainkd"
-       "github.com/vapor/errors"
        "github.com/vapor/protocol"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
        "github.com/vapor/protocol/validation"
        "github.com/vapor/protocol/vm"
-       "github.com/vapor/protocol/vm/vmutil"
 )
 
 // NewBlock create block according to the current status of chain
@@ -24,7 +19,6 @@ func NewBlock(chain *protocol.Chain, txs []*types.Tx, controlProgram []byte) (*t
        }
 
        preBlockHeader := chain.BestBlockHeader()
-
        b := &types.Block{
                BlockHeader: types.BlockHeader{
                        Version:           1,
@@ -67,29 +61,9 @@ func NewBlock(chain *protocol.Chain, txs []*types.Tx, controlProgram []byte) (*t
        }
 
        b.TransactionStatusHash, err = types.TxStatusMerkleRoot(txStatus.VerifyStatus)
-       proof, err := generateProof(*b)
-       if err != nil {
-               return nil, err
-       }
-       b.Proof = proof
        return b, err
 }
 
-func generateProof(block types.Block) (types.Proof, error) {
-       var xPrv chainkd.XPrv
-       if consensus.ActiveNetParams.Signer == "" {
-               return types.Proof{}, errors.New("Signer is empty")
-       }
-       xPrv.UnmarshalText([]byte(consensus.ActiveNetParams.Signer))
-       sign := xPrv.Sign(block.BlockCommitment.TransactionsMerkleRoot.Bytes())
-       pubHash := crypto.Ripemd160(xPrv.XPub().PublicKey())
-       control, err := vmutil.P2WPKHProgram([]byte(pubHash))
-       if err != nil {
-               return types.Proof{}, err
-       }
-       return types.Proof{Sign: sign, ControlProgram: control}, nil
-}
-
 // ReplaceCoinbase replace the coinbase tx of block with coinbaseTx
 func ReplaceCoinbase(block *types.Block, coinbaseTx *types.Tx) (err error) {
        block.Transactions[0] = coinbaseTx
@@ -109,15 +83,9 @@ func AppendBlocks(chain *protocol.Chain, num uint64) error {
                if err != nil {
                        return err
                }
-               if err := SolveAndUpdate(chain, block); err != nil {
+               if _, err := chain.ProcessBlock(block); err != nil {
                        return err
                }
        }
        return nil
 }
-
-// SolveAndUpdate solve difficulty and update chain status
-func SolveAndUpdate(chain *protocol.Chain, block *types.Block) error {
-       _, err := chain.ProcessBlock(block)
-       return err
-}