Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('Chaincode command line arguments tests', (t) => {
Chaincode = rewire('fabric-shim/lib/chaincode.js');
let opts = Chaincode.__get__('opts');
t.deepEqual(opts['peer.address'], undefined, 'Test zero argument');
process.argv.push('--peer.address');
process.argv.push('localhost:7051');
delete require.cache[require.resolve('fabric-shim/lib/chaincode.js')];
Chaincode = rewire('fabric-shim/lib/chaincode.js');
opts = Chaincode.__get__('opts');
t.deepEqual(opts['peer.address'], 'localhost:7051', 'Test passing only --peer.address argument is correctly picked up');
t.equal(opts['grpc.max_send_message_length'], -1, 'Test grpc.max_send_message_length defaults to -1');
t.equal(opts['grpc.max_receive_message_length'], -1, 'Test grpc.max_receive_message_length defaults to -1');
t.equal(opts['grpc.keepalive_time_ms'], 110000, 'Test grpc.keepalive_time_ms defaults to 110000');
t.equal(opts['grpc.http2.min_time_between_pings_ms'], 110000, 'Test grpc.http2.min_time_between_pings_ms defaults to 110000');
t.equal(opts['grpc.keepalive_timeout_ms'], 20000, 'Test grpc.keepalive_timeout_ms defaults to 20000');
t.equal(opts['grpc.http2.max_pings_without_data'], 0, 'Test grpc.http2.max_pings_without_data defaults to 0');
t.equal(opts['grpc.keepalive_permit_without_calls'], 1, 'Test grpc.keepalive_permit_without_calls defaults to 1');
process.argv.push('--test.another');
process.argv.push('dummyValue9');
delete require.cache[require.resolve('fabric-shim/lib/chaincode.js')];
Chaincode = rewire('fabric-shim/lib/chaincode.js');
opts = Chaincode.__get__('opts');
t.deepEqual(opts['peer.address'], 'localhost:7051', 'Test passing two arguments and one is in the parsing definition');
t.deepEqual(opts['test.another'], undefined, 'Test passing two arguments and one is NOT in the parsing definition');
process.argv.pop(); // remove dummyValu9
process.argv.pop(); // remove test.another
process.argv.push('--grpc.max_send_message_length');
process.argv.push('101');
'grpc.keepalive_time_ms': 3,
'grpc.http2.min_time_between_pings_ms': 5,
'grpc.keepalive_timeout_ms': 8,
'grpc.http2.max_pings_without_data': 13,
'grpc.keepalive_permit_without_calls': 21
});
t.equal(handler._options['grpc.ssl_target_name_override'], 'dummyHost', 'Test converting opts.ssl-target-name-override to grpc.ssl_target_name_override');
t.equal(handler._options['grpc.default_authority'], 'dummyHost', 'Test converting opts.ssl-target-name-override to grpc.default_authority');
t.equal(handler._options['request-timeout'], 12345, 'Test processing request-time option');
t.equal(handler._options['another-property'], 'dummyValue7', 'Test processing another-property option');
t.equal(handler._options['grpc.max_send_message_length'], 1, 'Test grpc.max_send_message_length set to 1');
t.equal(handler._options['grpc.max_receive_message_length'], 2, 'Test grpc.max_receive_message_length set to 2');
t.equal(handler._options['grpc.keepalive_time_ms'], 3, 'Test grpc.keepalive_time_ms set to 3');
t.equal(handler._options['grpc.http2.min_time_between_pings_ms'], 5, 'Test grpc.http2.min_time_between_pings_ms set to 5');
t.equal(handler._options['grpc.keepalive_timeout_ms'], 8, 'Test grpc.keepalive_timeout_ms set to 8');
t.equal(handler._options['grpc.http2.max_pings_without_data'], 13, 'Test grpc.http2.max_pings_without_data set to 13');
t.equal(handler._options['grpc.keepalive_permit_without_calls'], 21, 'Test grpc.keepalive_permit_without_calls set to 21');
// The DNS can be case sensitive in some cases (eg Docker DNS)
handler = new Handler(chaincodeObj, 'grpc://Peer.Example.com:7051');
t.equal(handler._endpoint.addr, 'Peer.Example.com:7051', 'Test handler.addr value preserves casing');
t.end();
});
private credentials: ChannelCredentials
) {
// Build user-agent string.
this.userAgent = [
options['grpc.primary_user_agent'],
`grpc-node-js/${clientVersion}`,
options['grpc.secondary_user_agent'],
]
.filter(e => e)
.join(' '); // remove falsey values first
if ('grpc.keepalive_time_ms' in options) {
this.keepaliveTimeMs = options['grpc.keepalive_time_ms']!;
}
if ('grpc.keepalive_timeout_ms' in options) {
this.keepaliveTimeoutMs = options['grpc.keepalive_timeout_ms']!;
}
this.keepaliveIntervalId = setTimeout(() => {}, 0);
clearTimeout(this.keepaliveIntervalId);
this.keepaliveTimeoutId = setTimeout(() => {}, 0);
clearTimeout(this.keepaliveTimeoutId);
const backoffOptions: BackoffOptions = {
initialDelay: options['grpc.initial_reconnect_backoff_ms'],
maxDelay: options['grpc.max_reconnect_backoff_ms']
};
this.backoffTimeout = new BackoffTimeout(() => {
if (this.continueConnecting) {
this.transitionToState(
[ConnectivityState.TRANSIENT_FAILURE, ConnectivityState.CONNECTING],
ConnectivityState.CONNECTING
);
} else {
* Tracks channels and subchannel pools with references to this subchannel
*/
this.refcount = 0;
// Build user-agent string.
this.userAgent = [
options['grpc.primary_user_agent'],
`grpc-node-js/${clientVersion}`,
options['grpc.secondary_user_agent'],
]
.filter(e => e)
.join(' '); // remove falsey values first
if ('grpc.keepalive_time_ms' in options) {
this.keepaliveTimeMs = options['grpc.keepalive_time_ms'];
}
if ('grpc.keepalive_timeout_ms' in options) {
this.keepaliveTimeoutMs = options['grpc.keepalive_timeout_ms'];
}
this.keepaliveIntervalId = setTimeout(() => { }, 0);
clearTimeout(this.keepaliveIntervalId);
this.keepaliveTimeoutId = setTimeout(() => { }, 0);
clearTimeout(this.keepaliveTimeoutId);
const backoffOptions = {
initialDelay: options['grpc.initial_reconnect_backoff_ms'],
maxDelay: options['grpc.max_reconnect_backoff_ms']
};
this.backoffTimeout = new backoff_timeout_1.BackoffTimeout(() => {
if (this.continueConnecting) {
this.transitionToState([channel_1.ConnectivityState.TRANSIENT_FAILURE, channel_1.ConnectivityState.CONNECTING], channel_1.ConnectivityState.CONNECTING);
}
else {
this.transitionToState([channel_1.ConnectivityState.TRANSIENT_FAILURE, channel_1.ConnectivityState.CONNECTING], channel_1.ConnectivityState.IDLE);
}
});
this.session.on('error', () => {
this.stopKeepalivePings();
this.emit('close');
});
this.session.on('goaway', () => {
this.stopKeepalivePings();
this.emit('close');
});
this.userAgent = userAgent;
if (channelArgs['grpc.keepalive_time_ms']) {
this.keepaliveTimeMs = channelArgs['grpc.keepalive_time_ms']!;
}
if (channelArgs['grpc.keepalive_timeout_ms']) {
this.keepaliveTimeoutMs = channelArgs['grpc.keepalive_timeout_ms']!;
}
this.keepaliveIntervalId = setTimeout(() => {}, 0);
clearTimeout(this.keepaliveIntervalId);
this.keepaliveTimeoutId = setTimeout(() => {}, 0);
clearTimeout(this.keepaliveTimeoutId);
}
constructor (options = {}) {
if (options === null || typeof options !== 'object') {
throw new TypeError('options must be an object');
}
this[kServer] = null;
this[kHandlers] = new Map();
this[kSessions] = new Set();
this[kStarted] = false;
this[kOptions] = { ...defaultServerOptions, ...options };
this[kSessionOptions] = {
keepaliveTimeMs: this[kOptions]['grpc.keepalive_time_ms'],
keepaliveTimeoutMs: this[kOptions]['grpc.keepalive_timeout_ms']
};
}