Skip to content

Commit ec239c7

Browse files
committed
modify blockchain test and del fork map
1 parent 1d74d5d commit ec239c7

24 files changed

+292
-311
lines changed

blockchain/blockstore.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ func NewBlockStore(chain *BlockChain, db dbm.DB, client queue.Client) *BlockStor
152152
blockStore.saveSequence = chain.isRecordBlockSequence
153153
blockStore.isParaChain = chain.isParaChain
154154
}
155-
tycfg := chain.client.GetConfig()
155+
cfg := chain.client.GetConfig()
156156
if height == -1 {
157157
chainlog.Info("load block height error, may be init database", "height", height)
158-
if tycfg.IsEnable("quickIndex") {
158+
if cfg.IsEnable("quickIndex") {
159159
blockStore.saveQuickIndexFlag()
160160
}
161161
} else {
@@ -169,7 +169,7 @@ func NewBlockStore(chain *BlockChain, db dbm.DB, client queue.Client) *BlockStor
169169
if err != nil {
170170
panic(err)
171171
}
172-
if tycfg.IsEnable("quickIndex") {
172+
if cfg.IsEnable("quickIndex") {
173173
if flag == 0 {
174174
blockStore.initQuickIndex(height)
175175
}

blockchain/blockstore_test.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ import (
1212
"github.com/33cn/chain33/types"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
15+
"github.com/33cn/chain33/queue"
16+
"github.com/33cn/chain33/util"
1517
)
1618

19+
func InitEnv() *BlockChain {
20+
cfg := types.NewChain33Config(util.GetDefaultCfgstring())
21+
q := queue.New("channel")
22+
q.SetConfig(cfg)
23+
chain := New(cfg)
24+
chain.client = q.Client()
25+
return chain
26+
}
27+
1728
func TestGetStoreUpgradeMeta(t *testing.T) {
1829
dir, err := ioutil.TempDir("", "example")
1930
assert.Nil(t, err)
@@ -22,7 +33,8 @@ func TestGetStoreUpgradeMeta(t *testing.T) {
2233

2334
blockStoreDB := dbm.NewDB("blockchain", "leveldb", dir, 100)
2435

25-
blockStore := NewBlockStore(nil, blockStoreDB, nil)
36+
chain := InitEnv()
37+
blockStore := NewBlockStore(chain, blockStoreDB, nil)
2638
require.NotNil(t, blockStore)
2739

2840
meta, err := blockStore.GetStoreUpgradeMeta()
@@ -45,7 +57,8 @@ func TestSeqSaveAndGet(t *testing.T) {
4557

4658
blockStoreDB := dbm.NewDB("blockchain", "leveldb", dir, 100)
4759

48-
blockStore := NewBlockStore(nil, blockStoreDB, nil)
60+
chain := InitEnv()
61+
blockStore := NewBlockStore(chain, blockStoreDB, nil)
4962
assert.NotNil(t, blockStore)
5063
blockStore.saveSequence = true
5164
blockStore.isParaChain = false
@@ -85,7 +98,8 @@ func TestParaSeqSaveAndGet(t *testing.T) {
8598

8699
blockStoreDB := dbm.NewDB("blockchain", "leveldb", dir, 100)
87100

88-
blockStore := NewBlockStore(nil, blockStoreDB, nil)
101+
bchain := InitEnv()
102+
blockStore := NewBlockStore(bchain, blockStoreDB, nil)
89103
assert.NotNil(t, blockStore)
90104
blockStore.saveSequence = true
91105
blockStore.isParaChain = true
@@ -147,7 +161,8 @@ func TestSeqCreateAndDelete(t *testing.T) {
147161

148162
blockStoreDB := dbm.NewDB("blockchain", "leveldb", dir, 100)
149163

150-
blockStore := NewBlockStore(nil, blockStoreDB, nil)
164+
chain := InitEnv()
165+
blockStore := NewBlockStore(chain, blockStoreDB, nil)
151166
assert.NotNil(t, blockStore)
152167
blockStore.saveSequence = false
153168
blockStore.isParaChain = true

blockchain/chain.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type BlockChain struct {
120120

121121
//New new
122122
func New(cfg *types.Chain33Config) *BlockChain {
123-
mcfg := cfg.GetMConfig().BlockChain
123+
mcfg := cfg.GetModuleConfig().BlockChain
124124
futureBlocks, err := lru.New(maxFutureBlocks)
125125
if err != nil {
126126
panic("when New BlockChain lru.New return err")
@@ -164,7 +164,7 @@ func New(cfg *types.Chain33Config) *BlockChain {
164164
}
165165

166166
func (chain *BlockChain) initConfig(cfg *types.Chain33Config) {
167-
mcfg := cfg.GetMConfig().BlockChain
167+
mcfg := cfg.GetModuleConfig().BlockChain
168168
if cfg.IsEnable("TxHeight") && chain.DefCacheSize <= (types.LowAllowPackHeight+types.HighAllowPackHeight+1) {
169169
panic("when Enable TxHeight DefCacheSize must big than types.LowAllowPackHeight")
170170
}

0 commit comments

Comments
 (0)