github.com/suchongming/fabric@v2.1.1+incompatible/integration/lifecycle/ccenv14_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package lifecycle
     8  
     9  import (
    10  	"io/ioutil"
    11  	"os"
    12  	"path/filepath"
    13  	"syscall"
    14  
    15  	docker "github.com/fsouza/go-dockerclient"
    16  	"github.com/hyperledger/fabric/integration/nwo"
    17  	. "github.com/onsi/ginkgo"
    18  	. "github.com/onsi/gomega"
    19  	"github.com/tedsuo/ifrit"
    20  )
    21  
    22  var _ = Describe("solo network using ccenv-1.4", func() {
    23  	var (
    24  		client  *docker.Client
    25  		testDir string
    26  		network *nwo.Network
    27  		process ifrit.Process
    28  	)
    29  
    30  	BeforeEach(func() {
    31  		var err error
    32  		testDir, err = ioutil.TempDir("", "lifecycle")
    33  		Expect(err).NotTo(HaveOccurred())
    34  
    35  		client, err = docker.NewClientFromEnv()
    36  		Expect(err).NotTo(HaveOccurred())
    37  
    38  		network = nwo.New(nwo.BasicSolo(), testDir, client, StartPort(), components)
    39  		network.GenerateConfigTree()
    40  		for _, peer := range network.PeersWithChannel("testchannel") {
    41  			core := network.ReadPeerConfig(peer)
    42  			core.Chaincode.Builder = "$(DOCKER_NS)/fabric-ccenv:1.4"
    43  			network.WritePeerConfig(peer, core)
    44  		}
    45  		network.Bootstrap()
    46  
    47  		networkRunner := network.NetworkGroupRunner()
    48  		process = ifrit.Invoke(networkRunner)
    49  		Eventually(process.Ready(), network.EventuallyTimeout).Should(BeClosed())
    50  	})
    51  
    52  	AfterEach(func() {
    53  		// Shutdown processes and cleanup
    54  		process.Signal(syscall.SIGTERM)
    55  		Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())
    56  		network.Cleanup()
    57  
    58  		os.RemoveAll(testDir)
    59  	})
    60  
    61  	It("deploys and executes chaincode (simple)", func() {
    62  		By("deploying the chaincode using LSCC on a channel with V1_4 application capabilities")
    63  		orderer := network.Orderer("orderer")
    64  		endorsers := []*nwo.Peer{
    65  			network.Peer("Org1", "peer0"),
    66  			network.Peer("Org2", "peer0"),
    67  		}
    68  
    69  		cwd, err := os.Getwd()
    70  		Expect(err).NotTo(HaveOccurred())
    71  
    72  		// The chaincode in the CDS file for this test was packaged using
    73  		// the cli container created via the docker-compose.yaml in this directory.
    74  		// At the time of packaging, hyperledger/fabric-tools:1.4 had
    75  		// image id '18ed4db0cd57'.
    76  		//
    77  		// It was packaged using the following command:
    78  		// peer chaincode package --name mycc --version 0.0 --lang golang --path github.com/chaincode/simple-v14 mycc-0_0-v14.cds
    79  		chaincode := nwo.Chaincode{
    80  			Name:        "mycc",
    81  			Version:     "0.0",
    82  			PackageFile: filepath.Join(cwd, "testdata/mycc-0_0-v14.cds"),
    83  			Ctor:        `{"Args":["init","a","100","b","200"]}`,
    84  			Policy:      `AND ('Org1MSP.member','Org2MSP.member')`,
    85  		}
    86  
    87  		network.CreateAndJoinChannels(orderer)
    88  		nwo.DeployChaincodeLegacy(network, "testchannel", orderer, chaincode)
    89  		RunQueryInvokeQuery(network, orderer, "mycc", 100, endorsers...)
    90  	})
    91  })