Skip to content

Commit

Permalink
verify tx are well formed - fixed
Browse files Browse the repository at this point in the history
Signed-off-by: May Rosenbaum <[email protected]>
  • Loading branch information
MayRosenbaum committed Nov 5, 2023
1 parent bb1843c commit ca4e1e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion common/ledger/blkstorage/block_serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ func TestBlockSerialization(t *testing.T) {

// malformed Payload
block.Data.Data[1] = protoutil.MarshalOrPanic(&common.Envelope{
Payload: []byte("Malformed Payload"),
Signature: []byte{1, 2, 3},
Payload: []byte("Malformed Payload"),
})

// empty TxID
block.Data.Data[2] = protoutil.MarshalOrPanic(&common.Envelope{
Signature: []byte{1, 2, 3},
Payload: protoutil.MarshalOrPanic(&common.Payload{
Header: &common.Header{
ChannelHeader: protoutil.MarshalOrPanic(&common.ChannelHeader{
Expand Down
4 changes: 4 additions & 0 deletions common/ledger/testutil/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func ConstructBlockWithTxidHeaderType(
if err != nil {
t.Fatalf("ConstructTestTransaction failed, err %s", err)
}
env.Signature = []byte{1, 2, 3}
envs = append(envs, env)
}
return NewBlock(envs, blockNum, previousHash)
Expand All @@ -262,6 +263,9 @@ func ConstructBlock(
if err != nil {
t.Fatalf("ConstructTestTransaction failed, err %s", err)
}
if !sign {
env.Signature = []byte{1, 2, 3}
}
envs = append(envs, env)
}
return NewBlock(envs, blockNum, previousHash)
Expand Down
14 changes: 10 additions & 4 deletions protoutil/blockutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"math"
"testing"

"github.com/pkg/errors"

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
Expand Down Expand Up @@ -608,11 +610,15 @@ func TestVerifyTransactionsAreWellFormed(t *testing.T) {
},
} {
t.Run(tst.name, func(t *testing.T) {
err := protoutil.VerifyTransactionsAreWellFormed(tst.block.Data)
if tst.expectedError == "" {
require.NoError(t, err)
if tst.block == nil || tst.block.Data == nil {
require.Error(t, errors.New("empty block"))
} else {
require.Contains(t, err.Error(), tst.expectedError)
err := protoutil.VerifyTransactionsAreWellFormed(tst.block.Data)
if tst.expectedError == "" {
require.NoError(t, err)
} else {
require.Contains(t, err.Error(), tst.expectedError)
}
}
})
}
Expand Down

0 comments on commit ca4e1e6

Please sign in to comment.