@@ -17,21 +17,21 @@ limitations under the License.
1717package endorser
1818
1919import (
20+ "encoding/hex"
21+ "errors"
2022 "flag"
2123 "fmt"
2224 "io/ioutil"
2325 "net"
2426 "os"
27+ "path/filepath"
2528 "runtime"
2629 "strings"
2730 "testing"
2831 "time"
2932
30- "path/filepath"
31-
32- "errors"
33-
3433 "github.com/golang/protobuf/proto"
34+ "github.com/hyperledger/fabric/bccsp"
3535 "github.com/hyperledger/fabric/bccsp/factory"
3636 mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
3737 "github.com/hyperledger/fabric/common/policies"
@@ -50,10 +50,9 @@ import (
5050 pb "github.com/hyperledger/fabric/protos/peer"
5151 pbutils "github.com/hyperledger/fabric/protos/utils"
5252 "github.com/spf13/viper"
53+ "github.com/stretchr/testify/assert"
5354 "golang.org/x/net/context"
5455 "google.golang.org/grpc"
55-
56- "github.com/stretchr/testify/assert"
5756 "google.golang.org/grpc/credentials"
5857)
5958
@@ -629,6 +628,20 @@ func TestWritersACLFail(t *testing.T) {
629628 chaincode .GetChain ().Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : & pb.ChaincodeSpec {ChaincodeId : chaincodeID }})
630629}
631630
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+
632645// TestAdminACLFail deploys tried to deploy a chaincode;
633646// however we inject a special policy for admins to simulate
634647// the scenario in which the creator of this proposal is not among
0 commit comments