github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/core/common/validation/config_test.go (about)

     1  /*
     2  Copyright hechain. 2022 All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package validation
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/hechain20/hechain/bccsp/sw"
    13  	"github.com/hechain20/hechain/core/config/configtest"
    14  	"github.com/hechain20/hechain/internal/configtxgen/encoder"
    15  	"github.com/hechain20/hechain/internal/configtxgen/genesisconfig"
    16  	"github.com/hechain20/hechain/protoutil"
    17  	cb "github.com/hyperledger/fabric-protos-go/common"
    18  	"github.com/hyperledger/fabric-protos-go/peer"
    19  	"github.com/stretchr/testify/require"
    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{
    33  			Header: &cb.Header{
    34  				ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{
    35  					Type:      int32(cb.HeaderType_CONFIG),
    36  					ChannelId: channelID,
    37  				}),
    38  				SignatureHeader: protoutil.MarshalOrPanic(&cb.SignatureHeader{
    39  					Creator: signerSerialized,
    40  					Nonce:   protoutil.CreateNonceOrPanic(),
    41  				}),
    42  			},
    43  			Data: protoutil.MarshalOrPanic(&cb.ConfigEnvelope{
    44  				LastUpdate: chCrtEnv,
    45  			}),
    46  		}),
    47  	}
    48  	cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())
    49  	require.NoError(t, err)
    50  	updateResult.Signature, _ = signer.Sign(updateResult.Payload)
    51  	_, txResult := ValidateTransaction(updateResult, cryptoProvider)
    52  	if txResult != peer.TxValidationCode_VALID {
    53  		t.Fatalf("ValidateTransaction failed, err %s", err)
    54  		return
    55  	}
    56  }