Commit 29d7fc03 authored by Ruslan Kryukov's avatar Ruslan Kryukov Committed by denyeart
Browse files

[FAB-2243] Replace Tx Validation bit-array by flags

https://jira.hyperledger.org/browse/FAB-2243



Switch valid flag from a boolean to an enum, so that we can indicate the reason
for the invalidation (txid already exists, vscc validation failure
(endorsement policy failure), mvcc validation failure, etc)

This change adds invalidation reason codes, sets them in the block as a uint8
(byte) array, and returns validation result in GetTransactionById.

Change-Id: I3593bf6aa4f35bb01b14f8fb3d9950b405f84660
Signed-off-by: default avatarRuslan Kryukov <ruslan.kryukov@ru.ibm.com>
parent 9a09ac07
......@@ -21,6 +21,7 @@ import (
"github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
)
// IndexableAttr represents an indexable attribute
......@@ -28,11 +29,12 @@ type IndexableAttr string
// constants for indexable attributes
const (
IndexableAttrBlockNum = IndexableAttr("BlockNum")
IndexableAttrBlockHash = IndexableAttr("BlockHash")
IndexableAttrTxID = IndexableAttr("TxID")
IndexableAttrBlockNumTranNum = IndexableAttr("BlockNumTranNum")
IndexableAttrBlockTxID = IndexableAttr("BlockTxID")
IndexableAttrBlockNum = IndexableAttr("BlockNum")
IndexableAttrBlockHash = IndexableAttr("BlockHash")
IndexableAttrTxID = IndexableAttr("TxID")
IndexableAttrBlockNumTranNum = IndexableAttr("BlockNumTranNum")
IndexableAttrBlockTxID = IndexableAttr("BlockTxID")
IndexableAttrTxValidationCode = IndexableAttr("TxValidationCode")
)
// IndexConfig - a configuration that includes a list of attributes that should be indexed
......@@ -68,5 +70,6 @@ type BlockStore interface {
RetrieveTxByID(txID string) (*common.Envelope, error)
RetrieveTxByBlockNumTranNum(blockNum uint64, tranNum uint64) (*common.Envelope, error)
RetrieveBlockByTxID(txID string) (*common.Block, error)
RetrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error)
Shutdown()
}
......@@ -28,6 +28,7 @@ import (
type serializedBlockInfo struct {
blockHeader *common.BlockHeader
txOffsets []*txindexInfo
metadata *common.BlockMetadata
}
//The order of the transactions must be maintained for history
......@@ -41,6 +42,7 @@ func serializeBlock(block *common.Block) ([]byte, *serializedBlockInfo, error) {
var err error
info := &serializedBlockInfo{}
info.blockHeader = block.Header
info.metadata = block.Metadata
if err = addHeaderBytes(block.Header, buf); err != nil {
return nil, nil, err
}
......@@ -84,6 +86,12 @@ func extractSerializedBlockInfo(serializedBlockBytes []byte) (*serializedBlockIn
if err != nil {
return nil, err
}
info.metadata, err = extractMetadata(b)
if err != nil {
return nil, err
}
return info, nil
}
......
......@@ -27,6 +27,7 @@ import (
"github.com/hyperledger/fabric/common/ledger/util"
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
putil "github.com/hyperledger/fabric/protos/utils"
"github.com/op/go-logging"
)
......@@ -314,7 +315,7 @@ func (mgr *blockfileMgr) addBlock(block *common.Block) error {
//save the index in the database
mgr.index.indexBlock(&blockIdxInfo{
blockNum: block.Header.Number, blockHash: blockHash,
flp: blockFLP, txOffsets: txOffsets})
flp: blockFLP, txOffsets: txOffsets, metadata: block.Metadata})
//update the checkpoint info (for storage) and the blockchain info (for APIs) in the manager
mgr.updateCheckpoint(newCPInfo)
......@@ -399,6 +400,8 @@ func (mgr *blockfileMgr) syncIndex() error {
blockIdxInfo.flp = &fileLocPointer{fileSuffixNum: blockPlacementInfo.fileNum,
locPointer: locPointer{offset: int(blockPlacementInfo.blockStartOffset)}}
blockIdxInfo.txOffsets = info.txOffsets
blockIdxInfo.metadata = info.metadata
logger.Debugf("syncIndex() indexing block [%d]", blockIdxInfo.blockNum)
if err = mgr.index.indexBlock(blockIdxInfo); err != nil {
return err
......@@ -465,6 +468,11 @@ func (mgr *blockfileMgr) retrieveBlockByTxID(txID string) (*common.Block, error)
return mgr.fetchBlock(loc)
}
func (mgr *blockfileMgr) retrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) {
logger.Debugf("retrieveTxValidationCodeByTxID() - txID = [%s]", txID)
return mgr.index.getTxValidationCodeByTxID(txID)
}
func (mgr *blockfileMgr) retrieveBlockHeaderByNumber(blockNum uint64) (*common.BlockHeader, error) {
logger.Debugf("retrieveBlockHeaderByNumber() - blockNum = [%d]", blockNum)
loc, err := mgr.index.getBlockLocByBlockNum(blockNum)
......
......@@ -25,15 +25,19 @@ import (
"github.com/hyperledger/fabric/common/ledger/blkstorage"
"github.com/hyperledger/fabric/common/ledger/util"
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
ledgerUtil "github.com/hyperledger/fabric/core/ledger/util"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
)
const (
blockNumIdxKeyPrefix = 'n'
blockHashIdxKeyPrefix = 'h'
txIDIdxKeyPrefix = 't'
blockNumTranNumIdxKeyPrefix = 'a'
blockTxIDIdxKeyPrefix = 'b'
indexCheckpointKeyStr = "indexCheckpointKey"
blockNumIdxKeyPrefix = 'n'
blockHashIdxKeyPrefix = 'h'
txIDIdxKeyPrefix = 't'
blockNumTranNumIdxKeyPrefix = 'a'
blockTxIDIdxKeyPrefix = 'b'
txValidationResultIdxKeyPrefix = 'v'
indexCheckpointKeyStr = "indexCheckpointKey"
)
var indexCheckpointKey = []byte(indexCheckpointKeyStr)
......@@ -47,6 +51,7 @@ type index interface {
getTxLoc(txID string) (*fileLocPointer, error)
getTXLocByBlockNumTranNum(blockNum uint64, tranNum uint64) (*fileLocPointer, error)
getBlockLocByTxID(txID string) (*fileLocPointer, error)
getTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error)
}
type blockIdxInfo struct {
......@@ -54,6 +59,7 @@ type blockIdxInfo struct {
blockHash []byte
flp *fileLocPointer
txOffsets []*txindexInfo
metadata *common.BlockMetadata
}
type blockIndex struct {
......@@ -92,6 +98,7 @@ func (index *blockIndex) indexBlock(blockIdxInfo *blockIdxInfo) error {
logger.Debugf("Indexing block [%s]", blockIdxInfo)
flp := blockIdxInfo.flp
txOffsets := blockIdxInfo.txOffsets
txsfltr := ledgerUtil.TxValidationFlags(blockIdxInfo.metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
batch := leveldbhelper.NewUpdateBatch()
flpBytes, err := flp.marshal()
if err != nil {
......@@ -141,6 +148,13 @@ func (index *blockIndex) indexBlock(blockIdxInfo *blockIdxInfo) error {
}
}
// Index6 - Store transaction validation result by transaction id
if _, ok := index.indexItemsMap[blkstorage.IndexableAttrTxValidationCode]; ok {
for idx, txoffset := range txOffsets {
batch.Put(constructTxValidationCodeIDKey(txoffset.txID), []byte{byte(txsfltr.Flag(idx))})
}
}
batch.Put(indexCheckpointKey, encodeBlockNum(blockIdxInfo.blockNum))
if err := index.db.WriteBatch(batch, false); err != nil {
return err
......@@ -228,6 +242,26 @@ func (index *blockIndex) getTXLocByBlockNumTranNum(blockNum uint64, tranNum uint
return txFLP, nil
}
func (index *blockIndex) getTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) {
if _, ok := index.indexItemsMap[blkstorage.IndexableAttrTxValidationCode]; !ok {
return peer.TxValidationCode(-1), blkstorage.ErrAttrNotIndexed
}
raw, err := index.db.Get(constructTxValidationCodeIDKey(txID))
if err != nil {
return peer.TxValidationCode(-1), err
} else if raw == nil {
return peer.TxValidationCode(-1), blkstorage.ErrAttrNotIndexed
} else if len(raw) != 1 {
return peer.TxValidationCode(-1), errors.New("Invalid value in indexItems")
}
result := peer.TxValidationCode(int32(raw[0]))
return result, nil
}
func constructBlockNumKey(blockNum uint64) []byte {
blkNumBytes := util.EncodeOrderPreservingVarUint64(blockNum)
return append([]byte{blockNumIdxKeyPrefix}, blkNumBytes...)
......@@ -245,6 +279,10 @@ func constructBlockTxIDKey(txID string) []byte {
return append([]byte{blockTxIDIdxKeyPrefix}, []byte(txID)...)
}
func constructTxValidationCodeIDKey(txID string) []byte {
return append([]byte{txValidationResultIdxKeyPrefix}, []byte(txID)...)
}
func constructBlockNumTranNumKey(blockNum uint64, txNum uint64) []byte {
blkNumBytes := util.EncodeOrderPreservingVarUint64(blockNum)
tranNumBytes := util.EncodeOrderPreservingVarUint64(txNum)
......
......@@ -22,6 +22,9 @@ import (
"github.com/hyperledger/fabric/common/ledger/blkstorage"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/util"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
putil "github.com/hyperledger/fabric/protos/utils"
)
......@@ -51,6 +54,10 @@ func (i *noopIndex) getBlockLocByTxID(txID string) (*fileLocPointer, error) {
return nil, nil
}
func (i *noopIndex) getTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) {
return peer.TxValidationCode(-1), nil
}
func TestBlockIndexSync(t *testing.T) {
testBlockIndexSync(t, 10, 5, false)
testBlockIndexSync(t, 10, 5, true)
......@@ -119,6 +126,7 @@ func TestBlockIndexSelectiveIndexing(t *testing.T) {
testBlockIndexSelectiveIndexing(t, []blkstorage.IndexableAttr{blkstorage.IndexableAttrBlockHash, blkstorage.IndexableAttrBlockNum})
testBlockIndexSelectiveIndexing(t, []blkstorage.IndexableAttr{blkstorage.IndexableAttrTxID, blkstorage.IndexableAttrBlockNumTranNum})
testBlockIndexSelectiveIndexing(t, []blkstorage.IndexableAttr{blkstorage.IndexableAttrBlockTxID})
testBlockIndexSelectiveIndexing(t, []blkstorage.IndexableAttr{blkstorage.IndexableAttrTxValidationCode})
}
func testBlockIndexSelectiveIndexing(t *testing.T, indexItems []blkstorage.IndexableAttr) {
......@@ -192,5 +200,26 @@ func testBlockIndexSelectiveIndexing(t *testing.T, indexItems []blkstorage.Index
} else {
testutil.AssertSame(t, err, blkstorage.ErrAttrNotIndexed)
}
for _, block := range blocks {
flags := util.TxValidationFlags(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
for idx, d := range block.Data.Data {
txid, err = extractTxID(d)
testutil.AssertNoError(t, err, "")
reason, err := blockfileMgr.retrieveTxValidationCodeByTxID(txid)
if testutil.Contains(indexItems, blkstorage.IndexableAttrTxValidationCode) {
testutil.AssertNoError(t, err, "Error while retrieving tx validation code by txID")
reasonFromFlags := flags.Flag(idx)
testutil.AssertEquals(t, reason, reasonFromFlags)
} else {
testutil.AssertSame(t, err, blkstorage.ErrAttrNotIndexed)
}
}
}
})
}
......@@ -22,6 +22,7 @@ import (
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
)
// fsBlockStore - filesystem based implementation for `BlockStore`
......@@ -81,6 +82,10 @@ func (store *fsBlockStore) RetrieveBlockByTxID(txID string) (*common.Block, erro
return store.fileMgr.retrieveBlockByTxID(txID)
}
func (store *fsBlockStore) RetrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) {
return store.fileMgr.retrieveTxValidationCodeByTxID(txID)
}
// Shutdown shuts down the block store
func (store *fsBlockStore) Shutdown() {
logger.Debugf("closing fs blockStore:%s", store.id)
......
......@@ -49,6 +49,7 @@ func newTestEnv(t testing.TB, conf *Conf) *testEnv {
blkstorage.IndexableAttrTxID,
blkstorage.IndexableAttrBlockNumTranNum,
blkstorage.IndexableAttrBlockTxID,
blkstorage.IndexableAttrTxValidationCode,
}
return newTestEnvSelectiveIndexing(t, conf, attrsToIndex)
}
......
......@@ -21,8 +21,10 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/util"
lutils "github.com/hyperledger/fabric/core/ledger/util"
"github.com/hyperledger/fabric/protos/common"
ptestutils "github.com/hyperledger/fabric/protos/testutils"
"github.com/hyperledger/fabric/protos/utils"
)
//BlockGenerator generates a series of blocks for testing
......@@ -90,7 +92,7 @@ func ConstructTestBlocks(t *testing.T, numBlocks int) []*common.Block {
}
// ConstructTransaction constructs a transaction for testing
func ConstructTransaction(t *testing.T, simulationResults []byte, sign bool) (*common.Envelope, string, error) {
func ConstructTransaction(_ *testing.T, simulationResults []byte, sign bool) (*common.Envelope, string, error) {
ccName := "foo"
//response := &pb.Response{Status: 200}
var txID string
......@@ -111,5 +113,9 @@ func newBlock(env []*common.Envelope, blockNum uint64, previousHash []byte) *com
block.Data.Data = append(block.Data.Data, txEnvBytes)
}
block.Header.DataHash = block.Data.Hash()
utils.InitBlockMetadata(block)
block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER] = lutils.NewTxValidationFlags(len(env))
return block
}
This diff is collapsed.
......@@ -27,19 +27,20 @@ import (
mocktxvalidator "github.com/hyperledger/fabric/core/mocks/txvalidator"
"github.com/hyperledger/fabric/core/mocks/validator"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
func TestKVLedgerBlockStorage(t *testing.T) {
func TestFirstBlockValidation(t *testing.T) {
viper.Set("peer.fileSystemPath", "/tmp/fabric/txvalidatortest")
ledgermgmt.InitializeTestEnv()
defer ledgermgmt.CleanupTestEnv()
ledger, _ := ledgermgmt.CreateLedger("TestLedger")
defer ledger.Close()
validator := &txValidator{&mocktxvalidator.Support{LedgerVal: ledger}, &validator.MockVsccValidator{}}
tValidator := &txValidator{&mocktxvalidator.Support{LedgerVal: ledger}, &validator.MockVsccValidator{}}
bcInfo, _ := ledger.GetBlockchainInfo()
testutil.AssertEquals(t, bcInfo, &common.BlockchainInfo{
......@@ -54,13 +55,10 @@ func TestKVLedgerBlockStorage(t *testing.T) {
simRes, _ := simulator.GetTxSimulationResults()
block := testutil.ConstructBlock(t, [][]byte{simRes}, true)
validator.Validate(block)
tValidator.Validate(block)
txsfltr := util.NewFilterBitArrayFromBytes(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
assert.True(t, !txsfltr.IsSet(uint(0)))
assert.True(t, !txsfltr.IsSet(uint(1)))
assert.True(t, !txsfltr.IsSet(uint(2)))
txsfltr := util.TxValidationFlags(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
assert.True(t, txsfltr.IsSetTo(0, peer.TxValidationCode_VALID))
}
func TestNewTxValidator_DuplicateTransactions(t *testing.T) {
......@@ -70,7 +68,7 @@ func TestNewTxValidator_DuplicateTransactions(t *testing.T) {
ledger, _ := ledgermgmt.CreateLedger("TestLedger")
defer ledger.Close()
validator := &txValidator{&mocktxvalidator.Support{LedgerVal: ledger}, &validator.MockVsccValidator{}}
tValidator := &txValidator{&mocktxvalidator.Support{LedgerVal: ledger}, &validator.MockVsccValidator{}}
// Create simeple endorsement transaction
payload := &common.Payload{
......@@ -107,7 +105,7 @@ func TestNewTxValidator_DuplicateTransactions(t *testing.T) {
}
block.Header = &common.BlockHeader{
Number: 1,
Number: 0,
DataHash: block.Data.Hash(),
}
......@@ -118,9 +116,8 @@ func TestNewTxValidator_DuplicateTransactions(t *testing.T) {
// Validation should invalidate transaction,
// because it's already committed
validator.Validate(block)
txsfltr := util.NewFilterBitArrayFromBytes(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
tValidator.Validate(block)
assert.True(t, txsfltr.IsSet(0))
txsfltr := util.TxValidationFlags(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
assert.True(t, txsfltr.IsInvalid(0))
}
......@@ -30,6 +30,7 @@ import (
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
"github.com/op/go-logging"
)
......@@ -96,14 +97,13 @@ func (v *txValidator) chainExists(chain string) bool {
func (v *txValidator) Validate(block *common.Block) error {
logger.Debug("START Block Validation")
defer logger.Debug("END Block Validation")
txsfltr := ledgerUtil.NewFilterBitArray(uint(len(block.Data.Data)))
// Initialize trans as valid here, then set invalidation reason code upon invalidation below
txsfltr := ledgerUtil.NewTxValidationFlags(len(block.Data.Data))
for tIdx, d := range block.Data.Data {
// Start by marking transaction as invalid, before
// doing any validation checks.
txsfltr.Set(uint(tIdx))
if d != nil {
if env, err := utils.GetEnvelopeFromBlock(d); err != nil {
logger.Warningf("Error getting tx from block(%s)", err)
txsfltr.SetFlag(tIdx, peer.TxValidationCode_INVALID_OTHER_REASON)
} else if env != nil {
// validate the transaction: here we check that the transaction
// is properly formed, properly signed and that the security
......@@ -113,14 +113,18 @@ func (v *txValidator) Validate(block *common.Block) error {
logger.Debug("Validating transaction peer.ValidateTransaction()")
var payload *common.Payload
var err error
if payload, err = validation.ValidateTransaction(env); err != nil {
var txResult peer.TxValidationCode
if payload, txResult = validation.ValidateTransaction(env); txResult != peer.TxValidationCode_VALID {
logger.Errorf("Invalid transaction with index %d, error %s", tIdx, err)
txsfltr.SetFlag(tIdx, txResult)
continue
}
chdr, err := utils.UnmarshalChannelHeader(payload.Header.ChannelHeader)
if err != nil {
logger.Warning("Could not unmarshal channel header, err %s, skipping", err)
txsfltr.SetFlag(tIdx, peer.TxValidationCode_INVALID_OTHER_REASON)
continue
}
......@@ -129,6 +133,7 @@ func (v *txValidator) Validate(block *common.Block) error {
if !v.chainExists(channel) {
logger.Errorf("Dropping transaction for non-existent chain %s", channel)
txsfltr.SetFlag(tIdx, peer.TxValidationCode_TARGET_CHAIN_NOT_FOUND)
continue
}
......@@ -136,7 +141,8 @@ func (v *txValidator) Validate(block *common.Block) error {
// Check duplicate transactions
txID := chdr.TxId
if _, err := v.support.Ledger().GetTransactionByID(txID); err == nil {
logger.Warning("Duplicate transaction found, ", txID, ", skipping")
logger.Error("Duplicate transaction found, ", txID, ", skipping")
txsfltr.SetFlag(tIdx, peer.TxValidationCode_DUPLICATE_TXID)
continue
}
......@@ -145,6 +151,7 @@ func (v *txValidator) Validate(block *common.Block) error {
if err = v.vscc.VSCCValidateTx(payload, d); err != nil {
txID := txID
logger.Errorf("VSCCValidateTx for transaction txId = %s returned error %s", txID, err)
txsfltr.SetFlag(tIdx, peer.TxValidationCode_ENDORSEMENT_POLICY_FAILURE)
continue
}
} else if common.HeaderType(chdr.Type) == common.HeaderType_CONFIG {
......@@ -165,20 +172,21 @@ func (v *txValidator) Validate(block *common.Block) error {
if _, err := proto.Marshal(env); err != nil {
logger.Warningf("Cannot marshal transaction due to %s", err)
txsfltr.SetFlag(tIdx, peer.TxValidationCode_MARSHAL_TX_ERROR)
continue
}
// Succeeded to pass down here, transaction is valid,
// just unset the filter bit array flag.
txsfltr.Unset(uint(tIdx))
// Succeeded to pass down here, transaction is valid
txsfltr.SetFlag(tIdx, peer.TxValidationCode_VALID)
} else {
logger.Warning("Nil tx from block")
txsfltr.SetFlag(tIdx, peer.TxValidationCode_NIL_ENVELOPE)
}
}
}
// Initialize metadata structure
utils.InitBlockMetadata(block)
// Serialize invalid transaction bit array into block metadata field
block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER] = txsfltr.ToBytes()
block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER] = txsfltr
return nil
}
......
......@@ -23,6 +23,7 @@ import (
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
"github.com/hyperledger/fabric/common/util"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
)
......@@ -51,8 +52,8 @@ func TestValidateConfigTx(t *testing.T) {
}),
}
updateResult.Signature, _ = signer.Sign(updateResult.Payload)
_, err = ValidateTransaction(updateResult)
if err != nil {
_, txResult := ValidateTransaction(updateResult)
if txResult != peer.TxValidationCode_VALID {
t.Fatalf("ValidateTransaction failed, err %s", err)
return
}
......
......@@ -17,13 +17,12 @@ limitations under the License.
package validation
import (
"fmt"
"math/rand"
"os"
"testing"
"time"
"fmt"
"os"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/msp"
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
......@@ -83,8 +82,8 @@ func TestGoodPath(t *testing.T) {
}
// validate the transaction
payl, err := ValidateTransaction(tx)
if err != nil {
payl, txResult := ValidateTransaction(tx)
if txResult != peer.TxValidationCode_VALID {
t.Fatalf("ValidateTransaction failed, err %s", err)
return
}
......@@ -112,7 +111,7 @@ func TestGoodPath(t *testing.T) {
// compare it to the original action and expect it to be equal
if string(simRes) != string(simResBack.Results) {
t.Fatalf("Simulation results are different")
t.Fatal("Simulation results are different")
return
}
}
......@@ -148,7 +147,7 @@ func TestBadProp(t *testing.T) {
// validate it - it should fail
_, _, _, err = ValidateProposalMessage(sProp)
if err == nil {
t.Fatalf("ValidateProposalMessage should have failed")
t.Fatal("ValidateProposalMessage should have failed")
return
}
......@@ -165,14 +164,14 @@ func TestBadProp(t *testing.T) {
// validate it - it should fail
_, _, _, err = ValidateProposalMessage(sProp)
if err == nil {
t.Fatalf("ValidateProposalMessage should have failed")
t.Fatal("ValidateProposalMessage should have failed")
return
}
// get a bad signing identity
badSigner, err := msp.NewNoopMsp().GetDefaultSigningIdentity()
if err != nil {
t.Fatalf("Couldn't get noop signer")
t.Fatal("Couldn't get noop signer")
return
}
......@@ -186,7 +185,7 @@ func TestBadProp(t *testing.T) {
// validate it - it should fail
_, _, _, err = ValidateProposalMessage(sProp)
if err == nil {
t.Fatalf("ValidateProposalMessage should have failed")
t.Fatal("ValidateProposalMessage should have failed")
return
}
}
......@@ -220,9 +219,9 @@ func TestBadTx(t *testing.T) {
corrupt(tx.Payload)
// validate the transaction it should fail
_, err = ValidateTransaction(tx)
if err == nil {
t.Fatalf("ValidateTransaction should have failed")
_, txResult := ValidateTransaction(tx)
if txResult == peer.TxValidationCode_VALID {
t.Fatal("ValidateTransaction should have failed")
return
}
......@@ -237,9 +236,9 @@ func TestBadTx(t *testing.T) {
corrupt(tx.Signature)
// validate the transaction it should fail
_, err = ValidateTransaction(tx)
if err == nil {
t.Fatalf("ValidateTransaction should have failed")
_, txResult = ValidateTransaction(tx)
if txResult == peer.TxValidationCode_VALID {
t.Fatal("ValidateTransaction should have failed")
return
}
}
......@@ -280,8 +279,8 @@ func Test2EndorsersAgree(t *testing.T) {
}
// validate the transaction
_, err = ValidateTransaction(tx)
if err != nil {
_, txResult := ValidateTransaction(tx)
if txResult != peer.TxValidationCode_VALID {