Skip to content

Commit 5548def

Browse files
Jason Yellickguoger
authored andcommitted
FAB-16353 Remove dead ComputeProposalBinding
Change-Id: I6e79a7f35f35c733f15c164d95cd2e94f3f98c77 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 856ce49 commit 5548def

File tree

2 files changed

+0
-122
lines changed

2 files changed

+0
-122
lines changed

protoutil/proputils.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package protoutil
88

99
import (
1010
"crypto/sha256"
11-
"encoding/binary"
1211
"encoding/hex"
1312
"time"
1413

@@ -382,39 +381,3 @@ func CheckTxID(txid string, nonce, creator []byte) error {
382381

383382
return nil
384383
}
385-
386-
// ComputeProposalBinding computes the binding of a proposal
387-
func ComputeProposalBinding(proposal *peer.Proposal) ([]byte, error) {
388-
if proposal == nil {
389-
return nil, errors.New("proposal is nil")
390-
}
391-
if len(proposal.Header) == 0 {
392-
return nil, errors.New("proposal's header is nil")
393-
}
394-
395-
h, err := UnmarshalHeader(proposal.Header)
396-
if err != nil {
397-
return nil, err
398-
}
399-
400-
chdr, err := UnmarshalChannelHeader(h.ChannelHeader)
401-
if err != nil {
402-
return nil, err
403-
}
404-
shdr, err := UnmarshalSignatureHeader(h.SignatureHeader)
405-
if err != nil {
406-
return nil, err
407-
}
408-
409-
return computeProposalBindingInternal(shdr.Nonce, shdr.Creator, chdr.Epoch)
410-
}
411-
412-
func computeProposalBindingInternal(nonce, creator []byte, epoch uint64) ([]byte, error) {
413-
epochBytes := make([]byte, 8)
414-
binary.LittleEndian.PutUint64(epochBytes, epoch)
415-
416-
// TODO: add to genesis block the hash function used for
417-
// the binding computation
418-
digest := sha256.Sum256(append(append(nonce, creator...), epochBytes...))
419-
return digest[:], nil
420-
}

protoutil/proputils_test.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -32,70 +32,6 @@ func createCIS() *pb.ChaincodeInvocationSpec {
3232
Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("arg1"), []byte("arg2")}}}}
3333
}
3434

35-
func TestNilProposal(t *testing.T) {
36-
// pass nil to all function which accept *peer.Proposal
37-
_, err := protoutil.ComputeProposalBinding(nil)
38-
assert.Error(t, err, "Expected error with nil proposal")
39-
}
40-
41-
func TestBadProposalHeaders(t *testing.T) {
42-
// NOTE: There is a lot of repetitive proposal validation code
43-
// in multiple functions which should be refactored in the future.
44-
// For now, simply consolidating the test cases
45-
46-
// empty header
47-
prop := &pb.Proposal{
48-
Header: []byte{},
49-
}
50-
_, err := protoutil.ComputeProposalBinding(prop)
51-
assert.Error(t, err, "Expected error with empty proposal header")
52-
53-
// empty payload
54-
prop = &pb.Proposal{
55-
Header: []byte("header"),
56-
}
57-
58-
// malformed proposal header
59-
prop = &pb.Proposal{
60-
Header: []byte("bad header"),
61-
Payload: []byte("payload"),
62-
}
63-
_, err = protoutil.UnmarshalHeader(prop.Header)
64-
assert.Error(t, err, "Expected error with malformed proposal header")
65-
_, err = protoutil.ComputeProposalBinding(prop)
66-
assert.Error(t, err, "Expected error with malformed proposal header")
67-
68-
// malformed signature header
69-
chdr, _ := proto.Marshal(&common.ChannelHeader{
70-
Type: int32(common.HeaderType_ENDORSER_TRANSACTION),
71-
})
72-
hdr := &common.Header{
73-
ChannelHeader: chdr,
74-
SignatureHeader: []byte("bad signature header"),
75-
}
76-
_, err = protoutil.UnmarshalSignatureHeader(hdr.SignatureHeader)
77-
assert.Error(t, err, "Expected error with malformed signature header")
78-
hdrBytes, _ := proto.Marshal(hdr)
79-
prop.Header = hdrBytes
80-
_, err = protoutil.ComputeProposalBinding(prop)
81-
assert.Error(t, err, "Expected error with malformed signature header")
82-
83-
// wrong channel header type
84-
chdr, _ = proto.Marshal(&common.ChannelHeader{
85-
Type: int32(common.HeaderType_DELIVER_SEEK_INFO),
86-
})
87-
88-
// malformed channel header
89-
hdr.ChannelHeader = []byte("bad channel header")
90-
hdrBytes, _ = proto.Marshal(hdr)
91-
prop.Header = hdrBytes
92-
_, err = protoutil.UnmarshalChaincodeHeaderExtension([]byte("bad header extension"))
93-
assert.Error(t, err, "Expected error with malformed channel header")
94-
_, err = protoutil.ComputeProposalBinding(prop)
95-
assert.Error(t, err, "Expected error with malformed channel header")
96-
97-
}
98-
9935
func TestGetChaincodeDeploymentSpec(t *testing.T) {
10036
_, err := protoutil.UnmarshalChaincodeDeploymentSpec([]byte("bad spec"))
10137
assert.Error(t, err, "Expected error with malformed spec")
@@ -144,27 +80,6 @@ func TestCDSProposals(t *testing.T) {
14480

14581
}
14682

147-
func TestComputeProposalBinding(t *testing.T) {
148-
expectedDigestHex := "5093dd4f4277e964da8f4afbde0a9674d17f2a6a5961f0670fc21ae9b67f2983"
149-
expectedDigest, _ := hex.DecodeString(expectedDigestHex)
150-
chdr, _ := proto.Marshal(&common.ChannelHeader{
151-
Epoch: uint64(10),
152-
})
153-
shdr, _ := proto.Marshal(&common.SignatureHeader{
154-
Nonce: []byte("nonce"),
155-
Creator: []byte("creator"),
156-
})
157-
hdr, _ := proto.Marshal(&common.Header{
158-
ChannelHeader: chdr,
159-
SignatureHeader: shdr,
160-
})
161-
prop := &pb.Proposal{
162-
Header: hdr,
163-
}
164-
binding, _ := protoutil.ComputeProposalBinding(prop)
165-
assert.Equal(t, expectedDigest, binding, "Binding does not match expected digest")
166-
}
167-
16883
func TestProposal(t *testing.T) {
16984
// create a proposal from a ChaincodeInvocationSpec
17085
prop, _, err := protoutil.CreateChaincodeProposalWithTransient(

0 commit comments

Comments
 (0)