github.com/lzy4123/fabric@v2.1.1+incompatible/core/common/validation/config_test.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package validation 8 9 import ( 10 "testing" 11 12 cb "github.com/hyperledger/fabric-protos-go/common" 13 "github.com/hyperledger/fabric-protos-go/peer" 14 "github.com/hyperledger/fabric/bccsp/sw" 15 "github.com/hyperledger/fabric/core/config/configtest" 16 "github.com/hyperledger/fabric/internal/configtxgen/encoder" 17 "github.com/hyperledger/fabric/internal/configtxgen/genesisconfig" 18 "github.com/hyperledger/fabric/protoutil" 19 "github.com/stretchr/testify/assert" 20 ) 21 22 func TestValidateConfigTx(t *testing.T) { 23 channelID := "testchannelid" 24 profile := genesisconfig.Load(genesisconfig.SampleSingleMSPChannelProfile, configtest.GetDevConfigDir()) 25 chCrtEnv, err := encoder.MakeChannelCreationTransaction(genesisconfig.SampleConsortiumName, nil, profile) 26 if err != nil { 27 t.Fatalf("MakeChannelCreationTransaction failed, err %s", err) 28 return 29 } 30 31 updateResult := &cb.Envelope{ 32 Payload: protoutil.MarshalOrPanic(&cb.Payload{Header: &cb.Header{ 33 ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{ 34 Type: int32(cb.HeaderType_CONFIG), 35 ChannelId: channelID, 36 }), 37 SignatureHeader: protoutil.MarshalOrPanic(&cb.SignatureHeader{ 38 Creator: signerSerialized, 39 Nonce: protoutil.CreateNonceOrPanic(), 40 }), 41 }, 42 Data: protoutil.MarshalOrPanic(&cb.ConfigEnvelope{ 43 LastUpdate: chCrtEnv, 44 }), 45 }), 46 } 47 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) 48 assert.NoError(t, err) 49 updateResult.Signature, _ = signer.Sign(updateResult.Payload) 50 _, txResult := ValidateTransaction(updateResult, cryptoProvider) 51 if txResult != peer.TxValidationCode_VALID { 52 t.Fatalf("ValidateTransaction failed, err %s", err) 53 return 54 } 55 }