Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
};
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',