X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=test%2Fmock%2Fchain.go;fp=test%2Fmock%2Fchain.go;h=69ef7c43a3784184fd5ac38da9c5a8483d374888;hp=700891f59d61c23b95ac1c4dc9c127ddd637c79f;hb=669d176c004324fe81a26261a6e41ddea95b6f17;hpb=bc213b29d91743bb9cb23c043f2856f47b34bb3e diff --git a/test/mock/chain.go b/test/mock/chain.go index 700891f5..69ef7c43 100644 --- a/test/mock/chain.go +++ b/test/mock/chain.go @@ -4,10 +4,16 @@ import ( "errors" "math/rand" + "github.com/vapor/protocol" "github.com/vapor/protocol/bc" "github.com/vapor/protocol/bc/types" ) +var ( + ErrFoundHeaderByHash = errors.New("can't find header by hash") + ErrFoundHeaderByHeight = errors.New("can't find header by height") +) + type mempool interface { AddTx(tx *types.Tx) } @@ -64,7 +70,7 @@ func (c *Chain) GetBlockByHeight(height uint64) (*types.Block, error) { func (c *Chain) GetHeaderByHash(hash *bc.Hash) (*types.BlockHeader, error) { block, ok := c.blockMap[*hash] if !ok { - return nil, errors.New("can't find block") + return nil, ErrFoundHeaderByHash } return &block.BlockHeader, nil } @@ -72,7 +78,7 @@ func (c *Chain) GetHeaderByHash(hash *bc.Hash) (*types.BlockHeader, error) { func (c *Chain) GetHeaderByHeight(height uint64) (*types.BlockHeader, error) { block, ok := c.heightMap[height] if !ok { - return nil, errors.New("can't find block") + return nil, ErrFoundHeaderByHeight } return &block.BlockHeader, nil } @@ -107,6 +113,10 @@ func (c *Chain) InMainChain(hash bc.Hash) bool { } func (c *Chain) ProcessBlock(block *types.Block) (bool, error) { + if block.TransactionsMerkleRoot == bc.NewHash([32]byte{0x1}) { + return false, protocol.ErrBadStateRoot + } + if c.bestBlockHeader.Hash() == block.PreviousBlockHash { c.heightMap[block.Height] = block c.blockMap[block.Hash()] = block