How to use @hyperledger/caliper-core - 10 common examples

To help you get started, we’ve selected a few @hyperledger/caliper-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / caliper / packages / caliper-iroha / lib / iroha.js View on Github external
async init() {
        // TODO: How to judge Iroha service's status elegantly?
        return CaliperUtils.sleep(10000); // Wait for Iroha network to start up
    }
github hyperledger / caliper / packages / caliper-fabric / lib / fabric.js View on Github external
let channelObject = this.networkUtil.getNetworkObject().channels[channel];

            if (CaliperUtils.checkProperty(channelObject, 'created') && channelObject.created) {
                logger.info(`Channel '${channel}' is configured as created, skipping creation`);
                continue;
            }

            if (ConfigUtil.get(ConfigUtil.keys.Fabric.SkipCreateChannelPrefix + channel, false)) {
                logger.info(`Creation of Channel '${channel}' is configured to skip`);
                continue;
            }

            channelCreated = true;

            let configUpdate;
            if (CaliperUtils.checkProperty(channelObject, 'configBinary')) {
                logger.info(`Channel '${channel}' definiton being retrieved from file`);
                configUpdate = this._getChannelConfigFromFile(channelObject, channel);
            }
            else {
                logger.info(`Channel '${channel}' definiton being generated from description`);
                const channelTx = this._createChannelTxEnvelope(channelObject.definition, channel);
                const payload = common.Payload.decode(channelTx.getPayload().toBuffer());
                const configtx = common.ConfigUpdateEnvelope.decode(payload.getData().toBuffer());
                configUpdate =  configtx.getConfigUpdate().toBuffer();
            }

            // NOTE: without knowing the system channel policies, signing with every org admin is a safe bet
            let orgs = this.networkUtil.getOrganizationsOfChannel(channel);
            let admin; // declared here to keep the admin of the last org of the channel
            let signatures = [];
            for (let org of orgs) {
github hyperledger / caliper / packages / caliper-fabric / lib / fabric.js View on Github external
if (ccObject.language !== 'golang') {
                    if (ccObject.language === 'node' && this.networkUtil.isInCompatibilityMode()) {
                        throw new Error(`${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel}: Node.js chaincodes are supported starting from Fabric v1.1`);
                    }

                    if (ccObject.language === 'java' && this.version.lessThan('1.3.0')) {
                        throw new Error(`${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel}: Java chaincodes are supported starting from Fabric v1.3`);
                    }

                    if (!['golang', 'node', 'java'].includes(ccObject.language)) {
                        throw new Error(`${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel}: unknown chaincode type ${ccObject.language}`);
                    }
                }

                // check private collection configuration
                if (CaliperUtils.checkProperty(ccObject, 'collections-config')) {
                    if (this.version.lessThan('1.2.0')) {
                        throw new Error(`${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel}: private collections are supported from Fabric v1.2`);
                    }

                    request['collections-config'] = ccObject['collections-config'];
                }

                /** @link{ProposalResponseObject} */
                let response;
                try {
                    response = await admin.getChannel(channel, true).sendInstantiateProposal(request, this.configChaincodeInstantiateTimeout);
                } catch (err) {
                    throw new Error(`Couldn't endorse ${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel} on peers [${targetPeers.toString()}]: ${err.message}`);
                }

                CaliperUtils.assertDefined(response);
github hyperledger / caliper / packages / caliper-fabric / lib / fabricNetwork.js View on Github external
let results = new Set();
        let peers = this.network.channels[channel].peers;
        for (let key in peers) {
            if (!peers.hasOwnProperty(key)) {
                continue;
            }

            let peer = peers[key];
            // if only the peer name is present in the config, then it is a target based on the default values
            if (!CaliperUtils.checkDefined(peer)) {
                results.add(key.toString());
            }

            // the default value of 'endorsingPeer' is true, or it's explicitly set to true
            if (!CaliperUtils.checkProperty(peer, 'endorsingPeer') ||
                (CaliperUtils.checkProperty(peer, 'endorsingPeer') && peer.endorsingPeer)) {
                results.add(key.toString());
                continue;
            }

            // the default value of 'chaincodeQuery' is true, or it's explicitly set to true
            if (!CaliperUtils.checkProperty(peer, 'chaincodeQuery') ||
                (CaliperUtils.checkProperty(peer, 'chaincodeQuery') && peer.chaincodeQuery)) {
                results.add(key.toString());
            }
        }

        return results;
    }
github hyperledger / caliper / packages / caliper-fabric / lib / fabric.js View on Github external
let admin = this.adminProfiles.get(org);

                    let txId = admin.newTransactionID(true);
                    /** @{ChaincodeInstallRequest} */
                    let request = {
                        targets: orgPeerTargets,
                        chaincodePath: ccObject.language === 'golang' ? ccObject.path : CaliperUtils.resolvePath(ccObject.path, this.workspaceRoot),
                        chaincodeId: ccObject.id,
                        chaincodeVersion: ccObject.version,
                        chaincodeType: ccObject.language,
                        txId: txId
                    };

                    // metadata (like CouchDB indices) are only supported since Fabric v1.1
                    if (CaliperUtils.checkProperty(ccObject, 'metadataPath')) {
                        if (!this.networkUtil.isInCompatibilityMode()) {
                            request.metadataPath = CaliperUtils.resolvePath(ccObject.metadataPath, this.workspaceRoot);
                        } else {
                            throw new Error(`Installing ${chaincodeInfo.id}@${chaincodeInfo.version} with metadata is not supported in Fabric v1.0`);
                        }
                    }

                    // install to necessary peers of org and process the results
                    try {
                        /** @link{ProposalResponseObject} */
                        let propRespObject = await admin.installChaincode(request);
                        CaliperUtils.assertDefined(propRespObject);

                        /** Array of @link{ProposalResponse} objects */
                        let proposalResponses = propRespObject[0];
                        CaliperUtils.assertDefined(proposalResponses);
github hyperledger / caliper / packages / caliper-fabric / lib / fabricNetwork.js View on Github external
getAdminCryptoContentOfOrganization(org) {
        let orgObject = this.network.organizations[org];

        // if either is missing, the result is undefined
        if (!CaliperUtils.checkAllProperties(orgObject, 'adminPrivateKey', 'signedCert')) {
            return undefined;
        }

        let privateKey = orgObject.adminPrivateKey;
        let signedCert = orgObject.signedCert;

        let privateKeyPEM;
        let signedCertPEM;

        if (CaliperUtils.checkProperty(privateKey, 'path')) {
            privateKeyPEM = fs.readFileSync(privateKey.path);
        } else {
            privateKeyPEM = privateKey.pem;
        }

        if (CaliperUtils.checkProperty(signedCert, 'path')) {
            signedCertPEM = fs.readFileSync(signedCert.path);
        } else {
            signedCertPEM = signedCert.pem;
        }

        // if either is missing, the result is undefined
        if (!privateKeyPEM || !signedCertPEM) {
            return undefined;
        }
github hyperledger / caliper / packages / caliper-fabric / lib / fabricNetwork.js View on Github external
// based on their provided functionality (endorsing and cc query)
        let results = new Set();
        let peers = this.network.channels[channel].peers;
        for (let key in peers) {
            if (!peers.hasOwnProperty(key)) {
                continue;
            }

            let peer = peers[key];
            // if only the peer name is present in the config, then it is a target based on the default values
            if (!CaliperUtils.checkDefined(peer)) {
                results.add(key.toString());
            }

            // the default value of 'endorsingPeer' is true, or it's explicitly set to true
            if (!CaliperUtils.checkProperty(peer, 'endorsingPeer') ||
                (CaliperUtils.checkProperty(peer, 'endorsingPeer') && peer.endorsingPeer)) {
                results.add(key.toString());
                continue;
            }

            // the default value of 'chaincodeQuery' is true, or it's explicitly set to true
            if (!CaliperUtils.checkProperty(peer, 'chaincodeQuery') ||
                (CaliperUtils.checkProperty(peer, 'chaincodeQuery') && peer.chaincodeQuery)) {
                results.add(key.toString());
            }
        }

        return results;
    }
github hyperledger / caliper / packages / caliper-fabric / lib / fabricNetwork.js View on Github external
let peer = peers[key];
            // if only the peer name is present in the config, then it is a target based on the default values
            if (!CaliperUtils.checkDefined(peer)) {
                results.add(key.toString());
            }

            // the default value of 'endorsingPeer' is true, or it's explicitly set to true
            if (!CaliperUtils.checkProperty(peer, 'endorsingPeer') ||
                (CaliperUtils.checkProperty(peer, 'endorsingPeer') && peer.endorsingPeer)) {
                results.add(key.toString());
                continue;
            }

            // the default value of 'chaincodeQuery' is true, or it's explicitly set to true
            if (!CaliperUtils.checkProperty(peer, 'chaincodeQuery') ||
                (CaliperUtils.checkProperty(peer, 'chaincodeQuery') && peer.chaincodeQuery)) {
                results.add(key.toString());
            }
        }

        return results;
    }
github hyperledger / caliper / packages / caliper-fabric / lib / fabric.js View on Github external
async _installChaincodes() {
        if (this.configOverwriteGopath) {
            process.env.GOPATH = CaliperUtils.resolvePath('.', this.workspaceRoot);
        }

        let errors = [];

        let channels = this.networkUtil.getChannels();
        for (let channel of channels) {
            logger.info(`Installing chaincodes for ${channel}...`);

            // proceed cc by cc for the channel
            let chaincodeInfos = this.networkUtil.getChaincodesOfChannel(channel);
            for (let chaincodeInfo of chaincodeInfos) {
                let ccObject = this.networkUtil.getNetworkObject().channels[channel].chaincodes.find(
                    cc => cc.id === chaincodeInfo.id && cc.version === chaincodeInfo.version);

                let targetPeers = this.networkUtil.getTargetPeersOfChaincodeOfChannel(chaincodeInfo, channel);
                if (targetPeers.size < 1) {