Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getMoveRequest() {
// Get the invoke arguments from the appropriate payload generation files
ccFuncInst.getInvokeArgs(txIDVar);
// Set the approprate signing identity for this function based on access policy
// If the function has no access control, we can use any signing identity
var orgsForAccess = ccFunctionAccessPolicy[ccDfnPtr.invoke.move.fcn];
if (orgsForAccess && Array.isArray(orgsForAccess) && orgsForAccess.length > 0 && orgAdmins[orgsForAccess[0]]) {
client.setUserContext(orgAdmins[orgsForAccess[0]], false); // Just pick the first organization that satisfies the policy
}
tx_id = client.newTransactionID();
hfc.setConfigSetting('E2E_TX_ID', tx_id.getTransactionID());
//logger.info('[Nid:chan:org:id=%d:%s:%s:%d getMoveRequest] tx id= %s', Nid, channelName, org, pid, tx_id.getTransactionID().toString());
request_invoke = {
chaincodeId : chaincode_id,
fcn: ccDfnPtr.invoke.move.fcn,
args: ccFuncInst.testInvokeArgs,
txId: tx_id
};
if ( (transMode == 'MIX') && (mixQuery) ) {
logger.info('[Nid:chan:org:id=%d:%s:%s:%d getMoveRequest] request_invoke: %j', Nid, channel.getName(), org, pid, request_invoke);
} else if ( (inv_m == nRequest) && (nRequest>0) ) {
if (invokeCheck) {
logger.info('[Nid:chan:org:id=%d:%s:%s:%d getMoveRequest] request_invoke: %j', Nid, channel.getName(), org, pid, request_invoke);
}
}
// now do one that works
eh.setPeerAddr(
ORGS[org].peer1.events,
{
pem: Buffer.from(tls_data).toString(),
'clientCert': tlsInfo.certificate,
'clientKey': tlsInfo.key,
'ssl-target-name-override': ORGS[org].peer1['server-hostname']
});
eh.connect();
eventhubs.push(eh);
request = eputil.createRequest(client, chaincode_id, targets, '', '');
request.chaincodePath = 'github.com/events_cc';
request.chaincodeVersion = chaincode_version;
Client.setConfigSetting('request-timeout', 60000);
return client.installChaincode(request);
}).then((results) => {
if ( eputil.checkProposal(results)) {
// conditionally add metadata path
if (fs.existsSync(metadataPath)) {
request.metadataPath = metadataPath;
}
// Package
BaseUtils.logMsg(`About to package ${contractType} smart contract named ${contractName}`);
try {
await chaincode.package(request);
BaseUtils.logMsg(`Successfully packaged ${contractType} smart contract named ${contractName}`);
} catch (error) {
BaseUtils.logAndThrow('Package Error :: ' + error);
}
// save it for later use
Client.setConfigSetting(contractSaveName, {value: chaincode});
}
fs.writeFileSync(logPath, '');
}
}
} else {
t.fail('Can not create an empty file to prepare for the rest of this test. ' + err.stack ? err.stack : err);
t.end();
}
}
};
let debugPath = '/tmp/hfc-log/debug.log';
let errorPath = '/tmp/hfc-log/error.log';
prepareEmptyFile(debugPath);
prepareEmptyFile(errorPath);
hfc.setConfigSetting('hfc-logging', util.format('{"debug": "%s", "error": "%s"}', debugPath, errorPath));
// internal call. clearing the cached logger.
global.hfc.logger = undefined;
var log1 = utils.getLogger('testlogger');
log1.error('Test logger - error');
log1.warn('Test logger - warn');
log1.info('Test logger - info');
log1.debug('Test logger - debug');
setTimeout(function () {
var data = fs.readFileSync(debugPath);
if (data.indexOf('Test logger - error') > 0 &&
data.indexOf('Test logger - warn') > 0 &&
data.indexOf('Test logger - info') > 0 &&
data.indexOf('Test logger - debug') > 0) {
t.pass('Successfully tested logging to debug file');
var util = require('util');
var path = require('path');
var hfc = require('fabric-client');
var file = 'network-config%s.yaml';
var env = process.env.TARGET_NETWORK;
if (env)
file = util.format(file, '-' + env);
else
file = util.format(file, '');
// indicate to the application where the setup file is located so it able
// to have the hfc load it to initalize the fabric client instance
hfc.setConfigSetting('network-connection-profile-path',path.join(__dirname, '../artifacts', file));
hfc.setConfigSetting('Org1-connection-profile-path',path.join(__dirname, '../artifacts', 'org1.yaml'));
hfc.setConfigSetting('Org2-connection-profile-path',path.join(__dirname, '../artifacts', 'org2.yaml'));
// some other settings the application might need to know
hfc.addConfigFile(path.join(__dirname, 'config.json'));
() => {
new PKCS11(256, 'sha2');
},
/PKCS11 PIN must be set/,
'Checking: PKCS11 slot must be set to a number'
);
Client.setConfigSetting('crypto-pkcs11-pin', 'PIN');
testing = 'Checking: for valid PIN in config';
try {
new PKCS11(256, 'sha2');
t.fail(testing);
} catch (error) {
checkError(error, testing);
}
Client.setConfigSetting('crypto-pkcs11-usertype', 'not');
t.throws(
() => {
new PKCS11(256, 'sha2');
},
/usertype number invalid/,
'Checking: for valid usertype'
);
Client.setConfigSetting('crypto-pkcs11-usertype', 1.2);
t.throws(
() => {
new PKCS11(256, 'sha2');
},
/usertype number invalid/,
'Checking: for valid usertype'
);
Client.setConfigSetting('crypto-pkcs11-usertype', 2);
testing = 'Checking: for valid readwrite in config';
try {
new PKCS11(256, 'sha2');
t.fail(testing);
} catch (error) {
checkError(error, testing);
}
Client.setConfigSetting('crypto-pkcs11-readwrite', 'True');
testing = 'Checking: for valid readwrite in config';
try {
new PKCS11(256, 'sha2');
t.fail(testing);
} catch (error) {
checkError(error, testing);
}
Client.setConfigSetting('crypto-pkcs11-readwrite', false);
testing = 'Checking: for valid readwrite in config';
try {
new PKCS11(256, 'sha2');
t.fail(testing);
} catch (error) {
checkError(error, testing);
}
Client.setConfigSetting('crypto-pkcs11-readwrite', true);
testing = 'Checking: for valid readwrite in config';
try {
new PKCS11(256, 'sha2');
t.fail(testing);
} catch (error) {
checkError(error, testing);
}
function resetDefaults() {
var defaultSettings = require('fabric-client/config/default.json');
for (var setting in defaultSettings) {
hfc.setConfigSetting(setting, defaultSettings[setting]);
}
}