How to use the fabric-shim/lib/stub.js.RESPONSE_CODE function in fabric-shim

To help you get started, we’ve selected a few fabric-shim 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 / fabric-chaincode-node / test / unit / handler.js View on Github external
payload: 'some payload',
		proposal: 'some proposal'
	};
	let expectedResponse = {
		type: serviceProto.ChaincodeMessage.Type.COMPLETED,
		payload: 'a buffered payload',
		channel_id: 'theChannelID',
		txid: msg.txid,
		chaincode_event: undefined
	};

	chaincodeProto.ChaincodeInput.decode.returns('decoded payload');
	mockHandler.chaincode.Init.resolves({status: Stub.RESPONSE_CODE.OK, toBuffer: () => {
		return 'a buffered payload';
	}});
	mockHandler.chaincode.Invoke.resolves({status: Stub.RESPONSE_CODE.OK, toBuffer: () => {
		return 'a buffered invoke payload';
	}});

	await handleMessage(msg, mockHandler, 'init');
	t.true(mockHandler._stream.write.calledOnce, 'Test init a response is written to a stream');
	t.deepEqual(mockHandler._stream.write.firstCall.args, [expectedResponse], 'Test init a correct response written to stream');


	mockHandler._stream.write.reset();
	expectedResponse = {
		type: serviceProto.ChaincodeMessage.Type.COMPLETED,
		payload: 'a buffered invoke payload',
		channel_id: 'theChannelID',
		txid: msg.txid,
		chaincode_event: undefined
	};
github hyperledger / fabric-chaincode-node / test / unit / handler.js View on Github external
let msg = {
		channel_id: 'theChannelID',
		txid: 'aTX',
		payload: 'some payload',
		proposal: 'some proposal'
	};
	let expectedResponse = {
		type: serviceProto.ChaincodeMessage.Type.COMPLETED,
		payload: 'a buffered payload',
		channel_id: 'theChannelID',
		txid: msg.txid,
		chaincode_event: undefined
	};

	chaincodeProto.ChaincodeInput.decode.returns('decoded payload');
	mockHandler.chaincode.Init.resolves({status: Stub.RESPONSE_CODE.OK, toBuffer: () => {
		return 'a buffered payload';
	}});
	mockHandler.chaincode.Invoke.resolves({status: Stub.RESPONSE_CODE.OK, toBuffer: () => {
		return 'a buffered invoke payload';
	}});

	await handleMessage(msg, mockHandler, 'init');
	t.true(mockHandler._stream.write.calledOnce, 'Test init a response is written to a stream');
	t.deepEqual(mockHandler._stream.write.firstCall.args, [expectedResponse], 'Test init a correct response written to stream');


	mockHandler._stream.write.reset();
	expectedResponse = {
		type: serviceProto.ChaincodeMessage.Type.COMPLETED,
		payload: 'a buffered invoke payload',
		channel_id: 'theChannelID',