OSDN Git Service
(root)
/
bytom
/
vapor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
netsync add test case (#365)
[bytom/vapor.git]
/
test
/
mock
/
chain.go
diff --git
a/test/mock/chain.go
b/test/mock/chain.go
index
700891f
..
69ef7c4
100644
(file)
--- a/
test/mock/chain.go
+++ b/
test/mock/chain.go
@@
-4,10
+4,16
@@
import (
"errors"
"math/rand"
"errors"
"math/rand"
+ "github.com/vapor/protocol"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
)
"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)
}
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 {
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
}
}
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 {
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
}
}
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) {
}
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
if c.bestBlockHeader.Hash() == block.PreviousBlockHash {
c.heightMap[block.Height] = block
c.blockMap[block.Hash()] = block