X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=test%2Fmock%2Fchain.go;h=69ef7c43a3784184fd5ac38da9c5a8483d374888;hb=refs%2Fheads%2Fblock_fetcher;hp=2b85ff0347e2921c8fc9046c51fa996dbedb96a9;hpb=4607cea3c6d3b1501ae1edb2c078b9ae0ee4bc79;p=bytom%2Fvapor.git diff --git a/test/mock/chain.go b/test/mock/chain.go index 2b85ff03..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) } @@ -37,7 +43,7 @@ func (c *Chain) BestBlockHeight() uint64 { return c.bestBlockHeader.Height } -func (c *Chain) BestIrreversibleHeader() *types.BlockHeader { +func (c *Chain) LastIrreversibleHeader() *types.BlockHeader { return c.bestBlockHeader } @@ -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