-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes the bug reported at FAB-903
https://jira.hyperledger.org/browse/FAB-903 The bug was caused by an assumption in the code - that the minimum size of a block would be 8 bytes. This assumption is broken during testing when security is off and a block does not include any transaction Change-Id: Ib48ea3da2a661fbd8e4122573bac938c8b35f3d1 Signed-off-by: manish <manish.sethi@gmail.com>
- Loading branch information
1 parent
18a44d0
commit 5196359
Showing
4 changed files
with
140 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
core/ledger/blkstorage/fsblkstorage/blockfile_scan_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package fsblkstorage | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric/core/ledger/testutil" | ||
"github.com/hyperledger/fabric/core/ledger/util" | ||
"github.com/hyperledger/fabric/protos" | ||
) | ||
|
||
func TestBlockFileScanSmallTxOnly(t *testing.T) { | ||
env := newTestEnv(t) | ||
defer env.Cleanup() | ||
blkfileMgrWrapper := newTestBlockfileWrapper(t, env) | ||
blocks := []*protos.Block2{} | ||
blocks = append(blocks, testutil.ConstructTestBlock(t, 0, 0, 0)) | ||
blocks = append(blocks, testutil.ConstructTestBlock(t, 0, 0, 0)) | ||
blocks = append(blocks, testutil.ConstructTestBlock(t, 0, 0, 0)) | ||
blkfileMgrWrapper.addBlocks(blocks) | ||
blkfileMgrWrapper.close() | ||
|
||
filePath := deriveBlockfilePath(env.conf.blockfilesDir, 0) | ||
_, fileSize, err := util.FileExists(filePath) | ||
testutil.AssertNoError(t, err, "") | ||
|
||
endOffsetLastBlock, numBlocks, err := scanForLastCompleteBlock(env.conf.blockfilesDir, 0, 0) | ||
testutil.AssertNoError(t, err, "") | ||
testutil.AssertEquals(t, numBlocks, len(blocks)) | ||
testutil.AssertEquals(t, endOffsetLastBlock, fileSize) | ||
} | ||
|
||
func TestBlockFileScanSmallTxLastTxIncomplete(t *testing.T) { | ||
env := newTestEnv(t) | ||
defer env.Cleanup() | ||
blkfileMgrWrapper := newTestBlockfileWrapper(t, env) | ||
blocks := []*protos.Block2{} | ||
blocks = append(blocks, testutil.ConstructTestBlock(t, 0, 0, 0)) | ||
blocks = append(blocks, testutil.ConstructTestBlock(t, 0, 0, 0)) | ||
blocks = append(blocks, testutil.ConstructTestBlock(t, 0, 0, 0)) | ||
blkfileMgrWrapper.addBlocks(blocks) | ||
blkfileMgrWrapper.close() | ||
|
||
filePath := deriveBlockfilePath(env.conf.blockfilesDir, 0) | ||
_, fileSize, err := util.FileExists(filePath) | ||
testutil.AssertNoError(t, err, "") | ||
|
||
file, err := os.OpenFile(filePath, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660) | ||
defer file.Close() | ||
testutil.AssertNoError(t, err, "") | ||
err = file.Truncate(fileSize - 1) | ||
testutil.AssertNoError(t, err, "") | ||
|
||
_, numBlocks, err := scanForLastCompleteBlock(env.conf.blockfilesDir, 0, 0) | ||
testutil.AssertNoError(t, err, "") | ||
testutil.AssertEquals(t, numBlocks, len(blocks)-1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters