Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "fabric-client in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'fabric-client' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

test('\n\n ** Logging utility tests - test setting an invalid external logger **\n\n', function (t) {
	// construct an invalid logger
	var logger = {
		inf: function () { console.log('info'); },
	};

	try {
		hfc.setLogger(logger);
		t.fail('Should not have allowed an invalid logger to be set');
		t.end();
	} catch (err) {
		var er1 = err.toString();
		if (er1.indexOf('debug()') > 0 &&
			er1.indexOf('info()') > 0 &&
			er1.indexOf('warn()') > 0 &&
			er1.indexOf('error()') > 0) {
			t.pass('Successfully tested thrown error for an invalid logger to set on the HFC SDK');
			t.end();
		} else {
			t.fail('Failed to catch all errors for an invalid logger missing required methods');
			t.end();
		}
	}
});
test('\n\n ** Logging utility tests - test setting an invalid external logger **\n\n', (t) => {
	console.log(' ***** logger.js - test external *****'); // eslint-disable-line

	// construct an invalid logger
	const logger = {
		inf: function () {
			t.comment('info');
		},
	};

	try {
		hfc.setLogger(logger);
		t.fail('Should not have allowed an invalid logger to be set');
		t.end();
	} catch (err) {
		const er1 = err.toString();
		if (er1.indexOf('debug()') > 0 &&
			er1.indexOf('info()') > 0 &&
			er1.indexOf('warn()') > 0 &&
			er1.indexOf('error()') > 0) {
			t.pass('Successfully tested thrown error for an invalid logger to set on the HFC SDK');
			t.end();
		} else {
			t.fail('Failed to catch all errors for an invalid logger missing required methods');
			t.end();
		}
	}
});
test('\n\n ** Logging utility tests - test setting an external logger based on log4js **\n\n', (t) => {
	console.log(' ***** logger.js - test log4js *****'); // eslint-disable-line

	const logger = log4js.getLogger();
	logger.level = 'info'; // Set level in order to output logs because by default it is OFF
	hfc.setLogger(logger);

	testLogger(t, true);
	t.end();
});
test('\n\n*** GRPC message size tests ***\n\n', async (t) => {
	testUtil.resetDefaults();
	testUtil.setupChaincodeDeploy();

	try {
		// setup client , including user and tls mutual certs
		const client = new Client();
		const channel_name = testUtil.END2END.channel;
		const channel = client.newChannel(channel_name);
		const ORGS = Client.getConfigSetting('test-network');
		const userOrg = 'org1';
		const orgName = ORGS[userOrg].name;
		const url = ORGS[userOrg].peer1.requests;
		const data = fs.readFileSync(path.join(__dirname, 'e2e', ORGS[userOrg].peer1.tls_cacerts));
		const cryptoSuite = Client.newCryptoSuite();
		cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
		client.setCryptoSuite(cryptoSuite);
		const tlsInfo = await e2eUtils.tlsEnroll(userOrg);
		client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);
		const store = await Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(orgName)});
		client.setStateStore(store);
		await testUtil.getSubmitter(client, t, userOrg, true);

		// make sure chaincode is installed that has the echo function
		const go_cc = testUtil.END2END.chaincodeId;
		const node_cc = testUtil.NODE_END2END.chaincodeId;
test('Use FabricCAServices wih a Cloudant CouchDB KeyValueStore', (t) => {
	testUtil.resetDefaults();
	Client.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
	ORGS = Client.getConfigSetting('test-network');
	const fabricCAEndpoint = ORGS[userOrg].ca.url;

	Client.addConfigFile('test/fixtures/credentials/cloudant.json');
	const keyValueStore = Client.getConfigSetting('key-value-store');
	logger.debug('cloudant Key Value Store = ' + keyValueStore);

	// override t.end function so it'll always clear the config settings
	t.end = ((context, f) => {
		return function() {
			if (global && global.hfc) {
				global.hfc.config = undefined;
			}
			require('nconf').reset();

			f.apply(context, arguments);
		};
orderersCPFList = testUtil.getNodetypeFromConnProfilesSubmitter(cpList, 'orderers');

// set org connection profile
var cpf=testUtil.findOrgConnProfileSubmitter(cpList, org);
if ( 0 === testUtil.getConnProfilePropCntSubmitter(cpf, 'orderers') ) {
    logger.error('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] no orderer found in the connection profile', Nid, channel.getName(), org, pid);
    process.exit(1);
}
if ( 0 === testUtil.getConnProfilePropCntSubmitter(cpf, 'peers') ) {
    logger.error('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] no peer found in the connection profile', Nid, channel.getName(), org, pid);
    process.exit(1);
}
var cpOrgs = cpf['organizations'];
var cpPeers = cpf['peers'];

var users =  hfc.getConfigSetting('users');

//user parameters
var transMode = txCfgPtr.transMode.toUpperCase();
var transType = txCfgPtr.transType.toUpperCase();
var invokeType = txCfgPtr.invokeType.toUpperCase();
var nRequest = parseInt(txCfgPtr.nRequest);

if ( transType == 'DISCOVERY' && TLS != testUtil.TLSCLIENTAUTH ) {
    logger.error('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] invalid configuration: transType (%s) requires mutual TLS (clientauth)', Nid, channelName, org, pid, transType);
    process.exit(1);
}

logger.info('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] transMode: %s, transType: %s, invokeType: %s, nRequest: %d', Nid, channel.getName(), org, pid,  transMode, transType, invokeType, nRequest);


// orderer parameters
test('\n\n ** Config **\n\n', function (t) {
	// setup the environment
	process.argv.push('--test-4=argv');
	process.argv.push('--test-5=argv');
	process.env.TEST_3 = 'env';
	process.env.test_6 = 'mapped';
	// internal call. clearing the cached config.
	global.hfc.config = undefined;
	t.equals(hfc.getConfigSetting('request-timeout', 'notfound'), 3000, 'checking that able to get "request-timeout" value from an additional configuration file');
	//try adding another config file
	hfc.addConfigFile('test/fixtures/local.json');
	t.equals(hfc.getConfigSetting('test-2', 'notfound'), 'local', 'checking that able to test-2 value from an additional configuration file');
	t.equals(hfc.getConfigSetting('test-3', 'notfound'), 'env', 'checking that test-3 environment values are used');
	t.equals(hfc.getConfigSetting('test-4', 'notfound'), 'argv', 'checking that test-4 argument values are used');
	hfc.setConfigSetting('test-5', 'program');
	t.equals(hfc.getConfigSetting('test-5', 'notfound'), 'program', 'checking that test-5 program values are used');
	t.equals(hfc.getConfigSetting('test-6', 'notfound'), 'mapped', 'checking that test-6 is enviroment mapped value');
	t.end();
});
logger.error('[queryBlockchainInfo] no connection profile is found for org(%s)', org);
            process.exit(1);
        }

        var username = testUtil.getOrgEnrollIdSubmitter(cpf, org);
        var secret = testUtil.getOrgEnrollSecretSubmitter(cpf, org);

        sBlock = txCfgPtr.queryBlockOpt.startBlock;
        eBlock = txCfgPtr.queryBlockOpt.endBlock;
        qOrg = txCfgPtr.queryBlockOpt.org;
        qPeer = txCfgPtr.queryBlockOpt.peer;
        logger.info('[queryBlockchainInfo] query block info org:peer:start:end=%s:%s:%d:%d', qOrg, qPeer, sBlock, eBlock);

        hfc.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');
        var cryptoSuite = hfc.newCryptoSuite();
        cryptoSuite.setCryptoKeyStore(hfc.newCryptoKeyStore({ path: testUtil.storePathForOrg(Nid, orgName) }));
        client.setCryptoSuite(cryptoSuite);

        // get client key
        if (TLS == testUtil.TLSCLIENTAUTH) {
            await testUtil.tlsEnroll(client, org, cpf);
            logger.debug('[queryBlockchainInfo] got user private key: org= %s', org);
        }

        chainAddOrderer(channel, client, org);

        channelAddQIPeer(channel, client, qOrg, qPeer);

        return hfc.newDefaultKeyValueStore({
            path: testUtil.storePathForOrg(orgName)
        }).then(function (store) {
            client.setStateStore(store);
test('\n\n*** GRPC message size tests ***\n\n', async (t) => {
	testUtil.resetDefaults();
	testUtil.setupChaincodeDeploy();

	try {
		// setup client , including user and tls mutual certs
		const client = new Client();
		const channel_name = testUtil.END2END.channel;
		const channel = client.newChannel(channel_name);
		const ORGS = Client.getConfigSetting('test-network');
		const userOrg = 'org1';
		const orgName = ORGS[userOrg].name;
		const url = ORGS[userOrg].peer1.requests;
		const data = fs.readFileSync(path.join(__dirname, 'e2e', ORGS[userOrg].peer1.tls_cacerts));
		const cryptoSuite = Client.newCryptoSuite();
		cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
		client.setCryptoSuite(cryptoSuite);
		const tlsInfo = await e2eUtils.tlsEnroll(userOrg);
		client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);
		const store = await Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(orgName)});
		client.setStateStore(store);
		await testUtil.getSubmitter(client, t, userOrg, true);

		// make sure chaincode is installed that has the echo function
		const go_cc = testUtil.END2END.chaincodeId;
		const node_cc = testUtil.NODE_END2END.chaincodeId;
		const version = 'v' + (new Date()).getTime();
		await e2eUtils.installChaincode(userOrg, testUtil.CHAINCODE_UPGRADE_PATH, testUtil.METADATA_PATH, version, 'golang', t, true);
		await e2eUtils.installChaincode('org2', testUtil.CHAINCODE_UPGRADE_PATH, testUtil.METADATA_PATH, version, 'golang', t, true);
		await e2eUtils.instantiateChaincode(userOrg, testUtil.CHAINCODE_UPGRADE_PATH, version, 'golang', true, false, t);
		await e2eUtils.installChaincode(userOrg, testUtil.NODE_CHAINCODE_UPGRADE_PATH, testUtil.METADATA_PATH, version, 'node', t, true);
		await e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_UPGRADE_PATH, testUtil.METADATA_PATH, version, 'node', t, true);
test('\n\n***** U P D A T E C H A N N E L flow: update channel *****\n\n', (t) => {
	testUtil.resetDefaults();
	Client.addConfigFile(path.join(__dirname, './config.json'));
	ORGS = Client.getConfigSetting('test-network');

	//
	// Create and configure the test channel
	//
	var channel_name = 'mychannel';
	var client = new Client();

	var caRootsPath = ORGS.orderer.tls_cacerts;
	let data = fs.readFileSync(path.join(__dirname, caRootsPath));
	let caroots = Buffer.from(data).toString();

	var orderer = client.newOrderer(
		ORGS.orderer.url,
		{
			'pem': caroots,

Is your System Free of Underlying Vulnerabilities?
Find Out Now