OSDN Git Service

fix the protol level test
authorColt <colt@ColtdeMBP.lan>
Thu, 17 Aug 2017 08:42:13 +0000 (16:42 +0800)
committerColt <colt@ColtdeMBP.lan>
Thu, 17 Aug 2017 08:42:13 +0000 (16:42 +0800)
protocol/block.go
protocol/block_test.go
protocol/recover_test.go
protocol/tx.go

index ae2a6fe..0a3404f 100644 (file)
@@ -5,14 +5,14 @@ import (
        "fmt"
        "time"
 
-//     "github.com/blockchain/crypto/ed25519"
+       //      "github.com/blockchain/crypto/ed25519"
        "github.com/bytom/errors"
        "github.com/bytom/log"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/legacy"
        "github.com/bytom/protocol/state"
        "github.com/bytom/protocol/validation"
-//     "github.com/blockchain/protocol/vm/vmutil"
+       //      "github.com/blockchain/protocol/vm/vmutil"
 )
 
 // maxBlockTxs limits the number of transactions
@@ -68,9 +68,7 @@ func (c *Chain) GenerateBlock(ctx context.Context, prev *legacy.Block, snapshot
                        Height:            prev.Height + 1,
                        PreviousBlockHash: prev.Hash(),
                        TimestampMS:       timestampMS,
-                       BlockCommitment: legacy.BlockCommitment{
-                               ConsensusProgram: prev.ConsensusProgram,
-                       },
+                       BlockCommitment:   legacy.BlockCommitment{},
                },
        }
 
@@ -132,9 +130,6 @@ func (c *Chain) ValidateBlock(block, prev *legacy.Block) error {
        if err != nil {
                return errors.Sub(ErrBadBlock, err)
        }
-       if block.Height > 1 {
-               err = validation.ValidateBlockSig(blockEnts, prevEnts.NextConsensusProgram)
-       }
        return errors.Sub(ErrBadBlock, err)
 }
 
@@ -241,32 +236,23 @@ func (c *Chain) ValidateBlockForSig(ctx context.Context, block *legacy.Block) er
        return errors.Sub(ErrBadBlock, err)
 }
 
-func NewInitialBlock(/*pubkeys []ed25519.PublicKey, nSigs int, timestamp time.Time*/) (*legacy.Block, error) {
+func NewInitialBlock(timestamp time.Time) (*legacy.Block, error) {
        // TODO(kr): move this into a lower-level package (e.g. chain/protocol/bc)
        // so that other packages (e.g. chain/protocol/validation) unit tests can
        // call this function.
-
-/*
-       script, err := vmutil.BlockMultiSigProgram(pubkeys, nSigs)
-       if err != nil {
-               return nil, err
-       }
-
        root, err := bc.MerkleRoot(nil) // calculate the zero value of the tx merkle root
        if err != nil {
                return nil, errors.Wrap(err, "calculating zero value of tx merkle root")
        }
-    */
 
        b := &legacy.Block{
                BlockHeader: legacy.BlockHeader{
                        Version:     1,
                        Height:      1,
-                       //TimestampMS: bc.Millis(timestamp),
-                       /*BlockCommitment: legacy.BlockCommitment{
+                       TimestampMS: bc.Millis(timestamp),
+                       BlockCommitment: legacy.BlockCommitment{
                                TransactionsMerkleRoot: root,
-                               ConsensusProgram:       script,
-                       },*/
+                       },
                },
        }
        return b, nil
index f027851..5b15278 100644 (file)
@@ -182,7 +182,6 @@ func TestGenerateBlock(t *testing.T) {
                        BlockCommitment: legacy.BlockCommitment{
                                TransactionsMerkleRoot: wantTxRoot,
                                AssetsMerkleRoot:       wantAssetsRoot,
-                               ConsensusProgram:       b1.ConsensusProgram,
                        },
                },
                Transactions: txs,
@@ -194,7 +193,7 @@ func TestGenerateBlock(t *testing.T) {
 }
 
 func TestValidateBlockForSig(t *testing.T) {
-       initialBlock, err := NewInitialBlock(testutil.TestPubs, 1, time.Now())
+       initialBlock, err := NewInitialBlock(time.Now())
        if err != nil {
                t.Fatal("unexpected error ", err)
        }
@@ -219,7 +218,7 @@ func newTestChain(tb testing.TB, ts time.Time) (c *Chain, b1 *legacy.Block) {
 
        var err error
 
-       b1, err = NewInitialBlock(nil, 0, ts)
+       b1, err = NewInitialBlock(ts)
        if err != nil {
                testutil.FatalErr(tb, err)
        }
index 52a6a28..b2149b7 100644 (file)
@@ -15,7 +15,7 @@ import (
 
 func TestRecoverSnapshotNoAdditionalBlocks(t *testing.T) {
        store := memstore.New()
-       b, err := NewInitialBlock(nil, 0, time.Now().Add(-time.Minute))
+       b, err := NewInitialBlock(time.Now().Add(-time.Minute))
        if err != nil {
                testutil.FatalErr(t, err)
        }
@@ -72,7 +72,6 @@ func createEmptyBlock(block *legacy.Block, snapshot *state.Snapshot) *legacy.Blo
                        BlockCommitment: legacy.BlockCommitment{
                                TransactionsMerkleRoot: root,
                                AssetsMerkleRoot:       snapshot.Tree.RootHash(),
-                               ConsensusProgram:       block.ConsensusProgram,
                        },
                },
        }
index 15c2b24..ef0c919 100644 (file)
@@ -24,7 +24,7 @@ func (c *Chain) ValidateTx(tx *bc.Tx) error {
        var ok bool
        err, ok = c.prevalidated.lookup(tx.ID)
        if !ok {
-               err = validation.ValidateTx(tx, c.InitialBlockHash)
+               _, err = validation.ValidateTx(tx, c.InitialBlockHash)
                c.prevalidated.cache(tx.ID, err)
        }
        return errors.Sub(ErrBadTx, err)