@@ -17,21 +17,21 @@ limitations under the License.
17
17
package endorser
18
18
19
19
import (
20
+ "encoding/hex"
21
+ "errors"
20
22
"flag"
21
23
"fmt"
22
24
"io/ioutil"
23
25
"net"
24
26
"os"
27
+ "path/filepath"
25
28
"runtime"
26
29
"strings"
27
30
"testing"
28
31
"time"
29
32
30
- "path/filepath"
31
-
32
- "errors"
33
-
34
33
"github.com/golang/protobuf/proto"
34
+ "github.com/hyperledger/fabric/bccsp"
35
35
"github.com/hyperledger/fabric/bccsp/factory"
36
36
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
37
37
"github.com/hyperledger/fabric/common/policies"
@@ -50,10 +50,9 @@ import (
50
50
pb "github.com/hyperledger/fabric/protos/peer"
51
51
pbutils "github.com/hyperledger/fabric/protos/utils"
52
52
"github.com/spf13/viper"
53
+ "github.com/stretchr/testify/assert"
53
54
"golang.org/x/net/context"
54
55
"google.golang.org/grpc"
55
-
56
- "github.com/stretchr/testify/assert"
57
56
"google.golang.org/grpc/credentials"
58
57
)
59
58
@@ -629,6 +628,20 @@ func TestWritersACLFail(t *testing.T) {
629
628
chaincode .GetChain ().Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : & pb.ChaincodeSpec {ChaincodeId : chaincodeID }})
630
629
}
631
630
631
+ func TestHeaderExtensionNoChaincodeID (t * testing.T ) {
632
+ creator , _ := signer .Serialize ()
633
+ nonce := []byte {1 , 2 , 3 }
634
+ digest , err := factory .GetDefault ().Hash (append (nonce , creator ... ), & bccsp.SHA256Opts {})
635
+ txID := hex .EncodeToString (digest )
636
+ spec := & pb.ChaincodeSpec {Type : 1 , ChaincodeId : nil , Input : & pb.ChaincodeInput {Args : util .ToChaincodeArgs ()}}
637
+ invocation := & pb.ChaincodeInvocationSpec {ChaincodeSpec : spec }
638
+ prop , _ , _ := pbutils .CreateChaincodeProposalWithTxIDNonceAndTransient (txID , common .HeaderType_ENDORSER_TRANSACTION , util .GetTestChainID (), invocation , []byte {1 , 2 , 3 }, creator , nil )
639
+ signedProp , _ := getSignedProposal (prop , signer )
640
+ _ , err = endorserServer .ProcessProposal (context .Background (), signedProp )
641
+ assert .Error (t , err )
642
+ assert .Contains (t , err .Error (), "ChaincodeHeaderExtension.ChaincodeId is nil" )
643
+ }
644
+
632
645
// TestAdminACLFail deploys tried to deploy a chaincode;
633
646
// however we inject a special policy for admins to simulate
634
647
// the scenario in which the creator of this proposal is not among
0 commit comments