-
Notifications
You must be signed in to change notification settings - Fork 4
/
blockchain_utils4test.go
50 lines (38 loc) · 1.45 KB
/
blockchain_utils4test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package chain
import (
"github.com/LemoFoundationLtd/lemochain-go/chain/account"
"github.com/LemoFoundationLtd/lemochain-go/chain/deputynode"
"github.com/LemoFoundationLtd/lemochain-go/chain/types"
"github.com/LemoFoundationLtd/lemochain-go/common"
"github.com/LemoFoundationLtd/lemochain-go/store"
)
type EngineTestForChain struct{}
func (engine *EngineTestForChain) VerifyHeader(block *types.Block) error { return nil }
func (engine *EngineTestForChain) Seal(header *types.Header, txs []*types.Transaction, changeLog []*types.ChangeLog, events []*types.Event) (*types.Block, error) {
return nil, nil
}
func (engine *EngineTestForChain) Finalize(header *types.Header, am *account.Manager) {}
func broadcastStableBlock(block *types.Block) {}
func broadcastConfirmInfo(hash common.Hash, height uint32) {}
func NewBlockChainForTest() (*BlockChain, chan *types.Block, error) {
chainId := uint16(99)
db, err := store.NewCacheChain(store.GetStorePath())
if err != nil {
return nil, nil, err
}
genesis := DefaultGenesisBlock()
_, err = SetupGenesisBlock(db, genesis)
if err != nil {
return nil, nil, err
}
var engine EngineTestForChain
ch := make(chan *types.Block)
blockChain, err := NewBlockChain(chainId, &engine, db, nil)
if err != nil {
return nil, nil, err
}
blockChain.BroadcastStableBlock = broadcastStableBlock
blockChain.BroadcastConfirmInfo = broadcastConfirmInfo
deputynode.Instance().Add(0, DefaultDeputyNodes)
return blockChain, ch, nil
}