@@ -28,14 +28,14 @@ import (
28
28
)
29
29
30
30
func TestBlockfileMgrBlockReadWrite (t * testing.T ) {
31
- env := newTestEnv (t , NewConf (testPath , 0 ))
31
+ env := newTestEnv (t , NewConf (testPath () , 0 ))
32
32
defer env .Cleanup ()
33
33
blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
34
34
defer blkfileMgrWrapper .close ()
35
35
blocks := testutil .ConstructTestBlocks (t , 10 )
36
36
blkfileMgrWrapper .addBlocks (blocks )
37
37
blkfileMgrWrapper .testGetBlockByHash (blocks )
38
- blkfileMgrWrapper .testGetBlockByNumber (blocks , 1 )
38
+ blkfileMgrWrapper .testGetBlockByNumber (blocks , 0 )
39
39
}
40
40
41
41
func TestBlockfileMgrCrashDuringWriting (t * testing.T ) {
@@ -47,7 +47,7 @@ func TestBlockfileMgrCrashDuringWriting(t *testing.T) {
47
47
48
48
func testBlockfileMgrCrashDuringWriting (t * testing.T , numBlocksBeforeCheckpoint int ,
49
49
numBlocksAfterCheckpoint int , numLastBlockBytes int , numPartialBytesToWrite int ) {
50
- env := newTestEnv (t , NewConf (testPath , 0 ))
50
+ env := newTestEnv (t , NewConf (testPath () , 0 ))
51
51
defer env .Cleanup ()
52
52
ledgerid := "testLedger"
53
53
blkfileMgrWrapper := newTestBlockfileWrapper (env , ledgerid )
@@ -58,6 +58,7 @@ func testBlockfileMgrCrashDuringWriting(t *testing.T, numBlocksBeforeCheckpoint
58
58
cpInfo1 := & checkpointInfo {
59
59
currentCPInfo .latestFileChunkSuffixNum ,
60
60
currentCPInfo .latestFileChunksize ,
61
+ currentCPInfo .isChainEmpty ,
61
62
currentCPInfo .lastBlockNumber }
62
63
63
64
blocksAfterCP := bg .NextTestBlocks (numBlocksAfterCheckpoint )
@@ -88,17 +89,17 @@ func testBlockfileMgrCrashDuringWriting(t *testing.T, numBlocksBeforeCheckpoint
88
89
allBlocks = append (allBlocks , blocksBeforeCP ... )
89
90
allBlocks = append (allBlocks , blocksAfterCP ... )
90
91
allBlocks = append (allBlocks , blocksAfterRestart ... )
91
- testBlockfileMgrBlockIterator (t , blkfileMgrWrapper .blockfileMgr , 1 , len (allBlocks ), allBlocks )
92
+ testBlockfileMgrBlockIterator (t , blkfileMgrWrapper .blockfileMgr , 0 , len (allBlocks )- 1 , allBlocks )
92
93
}
93
94
94
95
func TestBlockfileMgrBlockIterator (t * testing.T ) {
95
- env := newTestEnv (t , NewConf (testPath , 0 ))
96
+ env := newTestEnv (t , NewConf (testPath () , 0 ))
96
97
defer env .Cleanup ()
97
98
blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
98
99
defer blkfileMgrWrapper .close ()
99
100
blocks := testutil .ConstructTestBlocks (t , 10 )
100
101
blkfileMgrWrapper .addBlocks (blocks )
101
- testBlockfileMgrBlockIterator (t , blkfileMgrWrapper .blockfileMgr , 1 , 8 , blocks [0 :8 ])
102
+ testBlockfileMgrBlockIterator (t , blkfileMgrWrapper .blockfileMgr , 0 , 7 , blocks [0 :8 ])
102
103
}
103
104
104
105
func testBlockfileMgrBlockIterator (t * testing.T , blockfileMgr * blockfileMgr ,
@@ -120,7 +121,7 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr,
120
121
}
121
122
122
123
func TestBlockfileMgrBlockchainInfo (t * testing.T ) {
123
- env := newTestEnv (t , NewConf (testPath , 0 ))
124
+ env := newTestEnv (t , NewConf (testPath () , 0 ))
124
125
defer env .Cleanup ()
125
126
blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
126
127
defer blkfileMgrWrapper .close ()
@@ -135,7 +136,7 @@ func TestBlockfileMgrBlockchainInfo(t *testing.T) {
135
136
}
136
137
137
138
func TestBlockfileMgrGetTxById (t * testing.T ) {
138
- env := newTestEnv (t , NewConf (testPath , 0 ))
139
+ env := newTestEnv (t , NewConf (testPath () , 0 ))
139
140
defer env .Cleanup ()
140
141
blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
141
142
defer blkfileMgrWrapper .close ()
@@ -156,7 +157,7 @@ func TestBlockfileMgrGetTxById(t *testing.T) {
156
157
}
157
158
158
159
func TestBlockfileMgrGetTxByBlockNumTranNum (t * testing.T ) {
159
- env := newTestEnv (t , NewConf (testPath , 0 ))
160
+ env := newTestEnv (t , NewConf (testPath () , 0 ))
160
161
defer env .Cleanup ()
161
162
blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
162
163
defer blkfileMgrWrapper .close ()
@@ -165,7 +166,7 @@ func TestBlockfileMgrGetTxByBlockNumTranNum(t *testing.T) {
165
166
for blockIndex , blk := range blocks {
166
167
for tranIndex , txEnvelopeBytes := range blk .Data .Data {
167
168
// blockNum starts with 1, tranNum starts with 1
168
- txEnvelopeFromFileMgr , err := blkfileMgrWrapper .blockfileMgr .retrieveTransactionByBlockNumTranNum (uint64 (blockIndex + 1 ), uint64 (tranIndex + 1 ))
169
+ txEnvelopeFromFileMgr , err := blkfileMgrWrapper .blockfileMgr .retrieveTransactionByBlockNumTranNum (uint64 (blockIndex ), uint64 (tranIndex + 1 ))
169
170
testutil .AssertNoError (t , err , "Error while retrieving tx from blkfileMgr" )
170
171
txEnvelope , err := putil .GetEnvelopeFromBlock (txEnvelopeBytes )
171
172
testutil .AssertNoError (t , err , "Error while unmarshalling tx" )
@@ -175,24 +176,27 @@ func TestBlockfileMgrGetTxByBlockNumTranNum(t *testing.T) {
175
176
}
176
177
177
178
func TestBlockfileMgrRestart (t * testing.T ) {
178
- env := newTestEnv (t , NewConf (testPath , 0 ))
179
+ env := newTestEnv (t , NewConf (testPath () , 0 ))
179
180
defer env .Cleanup ()
180
181
ledgerid := "testLedger"
181
182
blkfileMgrWrapper := newTestBlockfileWrapper (env , ledgerid )
182
183
blocks := testutil .ConstructTestBlocks (t , 10 )
183
184
blkfileMgrWrapper .addBlocks (blocks )
185
+ expectedHeight := uint64 (10 )
186
+ testutil .AssertEquals (t , blkfileMgrWrapper .blockfileMgr .getBlockchainInfo ().Height , expectedHeight )
184
187
blkfileMgrWrapper .close ()
185
188
186
189
blkfileMgrWrapper = newTestBlockfileWrapper (env , ledgerid )
187
190
defer blkfileMgrWrapper .close ()
188
- testutil .AssertEquals (t , int (blkfileMgrWrapper .blockfileMgr .cpInfo .lastBlockNumber ), 10 )
191
+ testutil .AssertEquals (t , int (blkfileMgrWrapper .blockfileMgr .cpInfo .lastBlockNumber ), 9 )
189
192
blkfileMgrWrapper .testGetBlockByHash (blocks )
193
+ testutil .AssertEquals (t , blkfileMgrWrapper .blockfileMgr .getBlockchainInfo ().Height , expectedHeight )
190
194
}
191
195
192
196
func TestBlockfileMgrFileRolling (t * testing.T ) {
193
- blocks := testutil .ConstructTestBlocks (t , 100 )
197
+ blocks := testutil .ConstructTestBlocks (t , 200 )
194
198
size := 0
195
- for _ , block := range blocks {
199
+ for _ , block := range blocks [: 100 ] {
196
200
by , _ , err := serializeBlock (block )
197
201
testutil .AssertNoError (t , err , "Error while serializing block" )
198
202
blockBytesSize := len (by )
@@ -201,31 +205,31 @@ func TestBlockfileMgrFileRolling(t *testing.T) {
201
205
}
202
206
203
207
maxFileSie := int (0.75 * float64 (size ))
204
- env := newTestEnv (t , NewConf (testPath , maxFileSie ))
208
+ env := newTestEnv (t , NewConf (testPath () , maxFileSie ))
205
209
defer env .Cleanup ()
206
210
ledgerid := "testLedger"
207
211
blkfileMgrWrapper := newTestBlockfileWrapper (env , ledgerid )
208
- blkfileMgrWrapper .addBlocks (blocks )
212
+ blkfileMgrWrapper .addBlocks (blocks [: 100 ] )
209
213
testutil .AssertEquals (t , blkfileMgrWrapper .blockfileMgr .cpInfo .latestFileChunkSuffixNum , 1 )
210
- blkfileMgrWrapper .testGetBlockByHash (blocks )
214
+ blkfileMgrWrapper .testGetBlockByHash (blocks [: 100 ] )
211
215
blkfileMgrWrapper .close ()
212
216
213
217
blkfileMgrWrapper = newTestBlockfileWrapper (env , ledgerid )
214
218
defer blkfileMgrWrapper .close ()
215
- blkfileMgrWrapper .addBlocks (blocks )
219
+ blkfileMgrWrapper .addBlocks (blocks [ 100 :] )
216
220
testutil .AssertEquals (t , blkfileMgrWrapper .blockfileMgr .cpInfo .latestFileChunkSuffixNum , 2 )
217
- blkfileMgrWrapper .testGetBlockByHash (blocks )
221
+ blkfileMgrWrapper .testGetBlockByHash (blocks [ 100 :] )
218
222
}
219
223
220
224
func TestBlockfileMgrGetBlockByTxID (t * testing.T ) {
221
- env := newTestEnv (t , NewConf (testPath , 0 ))
225
+ env := newTestEnv (t , NewConf (testPath () , 0 ))
222
226
defer env .Cleanup ()
223
227
blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
224
228
defer blkfileMgrWrapper .close ()
225
229
blocks := testutil .ConstructTestBlocks (t , 10 )
226
230
blkfileMgrWrapper .addBlocks (blocks )
227
231
for _ , blk := range blocks {
228
- for j , _ := range blk .Data .Data {
232
+ for j := range blk .Data .Data {
229
233
// blockNum starts with 1
230
234
txID , err := extractTxID (blk .Data .Data [j ])
231
235
testutil .AssertNoError (t , err , "" )
0 commit comments