<commit_before>/**
 * Copyright 2016 IBM All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an 'AS IS' BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
'use strict';

var utils = require('fabric-client/lib/utils.js');
utils.setConfigSetting('hfc-logging', '{"debug":"console"}');
var logger = utils.getLogger('E2E create-channel');

var tape = require('tape');
var _test = require('tape-promise');
var test = _test(tape);

var hfc = require('fabric-client');
var util = require('util');
var fs = require('fs');
var path = require('path');

var testUtil = require('../../unit/util.js');

var the_user = null;

hfc.addConfigFile(path.join(__dirname, './config.json'));
var ORGS = hfc.getConfigSetting('test-network');

//
//Attempt to send a request to the orderer with the sendCreateChain method
//
test('\n\n***** End-to-end flow: create channel *****\n\n', function(t) {
	//
	// Create and configure the test chain
	//
	var client = new hfc();

	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,
			'ssl-target-name-override': ORGS.orderer['server-hostname']
		}
	);

	// Acting as a client in org1 when creating the channel
	var org = ORGS.org1.name;

	utils.setConfigSetting('key-value-store', 'fabric-client/lib/impl/FileKeyValueStore.js');
	return hfc.newDefaultKeyValueStore({
		path: testUtil.storePathForOrg(org)
	}).then((store) => {
		client.setStateStore(store);
		return testUtil.getSubmitter(client, t, 'org1');
	})
	.then((admin) => {
		t.pass('Successfully enrolled user \'admin\'');
		the_user = admin;

		// readin the envelope to send to the orderer
		data = fs.readFileSync('./test/fixtures/channel/mychannel.tx');
		var request = {
			envelope : data,
			name : 'mychannel',
			orderer : orderer
		};
		// send to orderer
		return client.createChannel(request);
	}, (err) => {
		t.fail('Failed to enroll user \'admin\'. ' + err);
		t.end();
	})
	.then((chain) => {
		logger.debug(' response ::%j',chain);

		if (chain) {
			var test_orderers = chain.getOrderers();
			if(test_orderers) {
				var test_orderer = test_orderers[0];
				if(test_orderer === orderer) {
					t.pass('Successfully created the channel.');
				}
				else {
					t.fail('Chain did not have the orderer.');
				}
			}
			return sleep(5000);
		} else {<commit_msg>node-SDK FAB-2994 make e2d test run from any directory<commit_after>/**
 * Copyright 2016 IBM All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an 'AS IS' BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
'use strict';

var utils = require('fabric-client/lib/utils.js');
utils.setConfigSetting('hfc-logging', '{"debug":"console"}');
var logger = utils.getLogger('E2E create-channel');

var tape = require('tape');
var _test = require('tape-promise');
var test = _test(tape);

var hfc = require('fabric-client');
var util = require('util');
var fs = require('fs');
var path = require('path');

var testUtil = require('../../unit/util.js');

var the_user = null;

hfc.addConfigFile(path.join(__dirname, './config.json'));
var ORGS = hfc.getConfigSetting('test-network');

//
//Attempt to send a request to the orderer with the sendCreateChain method
//
test('\n\n***** End-to-end flow: create channel *****\n\n', function(t) {
	//
	// Create and configure the test chain
	//
	var client = new hfc();

	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,
			'ssl-target-name-override': ORGS.orderer['server-hostname']
		}
	);

	// Acting as a client in org1 when creating the channel
	var org = ORGS.org1.name;

	utils.setConfigSetting('key-value-store', 'fabric-client/lib/impl/FileKeyValueStore.js');
	return hfc.newDefaultKeyValueStore({
		path: testUtil.storePathForOrg(org)
	}).then((store) => {
		client.setStateStore(store);
		return testUtil.getSubmitter(client, t, 'org1');
	})
	.then((admin) => {
		t.pass('Successfully enrolled user \'admin\'');
		the_user = admin;

		// readin the envelope to send to the orderer
		let normalPath = path.normalize(
			path.join(__dirname, '../../fixtures/channel/mychannel.tx'));
		t.comment('normalPath=' + normalPath);
		data = fs.readFileSync(normalPath);
		var request = {
			envelope : data,
			name : 'mychannel',
			orderer : orderer
		};
		// send to orderer
		return client.createChannel(request);
	}, (err) => {
		t.fail('Failed to enroll user \'admin\'. ' + err);
		t.end();
	})
	.then((chain) => {
		logger.debug(' response ::%j',chain);

		if (chain) {
			var test_orderers = chain.getOrderers();
			if(test_orderers) {
				var test_orderer = test_orderers[0];
				if(test_orderer === orderer) {
					t.pass('Successfully created the channel.');
				}
				else {
					t.fail('Chain did not have the orderer.');
				}
			}
			return sleep(5000);
		} else {
{'fraction_non_alphanumeric': 0.15055202408832385, 'fraction_numerical': 0.006523921043827367, 'mean_word_length': 3.7793764988009593, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7305783', 'n_tokens_mistral': 2104, 'n_tokens_neox': 1953, 'n_words': 549}