Skip to content

Commit

Permalink
[FAB-8329]Fix parameter in transaction proposal request
Browse files Browse the repository at this point in the history
Some transaction proposal requests have unnecessary or missing
parameters.

1. fabric-sdk-node/fabric-client/lib/Channel.js

The following functions have “chainId” in request objects.
However, “chainId” is not used to call sendTransactionProposal.
This parameter should be removed.
- queryInfo
- queryBlockByHash
- queryBlock
- queryTransaction
- queryInstantiatedChaincodes
- queryByChaincode

In addition, queryBlock doesn’t have the value of “signer” in
ChaincodeInvokeRequest. Signer generated by previous step should
be added to the request object.

2. fabric-sdk-node/test/integration/events.js
   fabric-sdk-node/test/integration/eventutil.js

createRequest has unnecessary parameters - “channel” and “user”.
These parameters should be removed.

This CR fixes parameters in request objects correctly.

Change-Id: I243984c7479d3a1e3a3cfdd2e1f8005983f5ab6f
Signed-off-by: Yuki Kondo <[email protected]>
  • Loading branch information
yuki-kon committed Feb 15, 2018
1 parent 0ace8d1 commit 5b9b75e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
8 changes: 1 addition & 7 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,6 @@ var Channel = class {
var request = {
targets: targets,
chaincodeId: Constants.QSCC,
chainId: '',
txId: tx_id,
signer: signer,
fcn: 'GetChainInfo',
Expand Down Expand Up @@ -893,7 +892,6 @@ var Channel = class {
var request = {
targets: targets,
chaincodeId: Constants.QSCC,
chainId: '',
txId: txId,
signer: signer,
fcn: 'GetBlockByHash',
Expand Down Expand Up @@ -957,9 +955,8 @@ var Channel = class {
var request = {
targets: targets,
chaincodeId: Constants.QSCC,
chainId: '',
txId: txId,
signer,
signer: signer,
fcn: 'GetBlockByNumber',
args: [this._name, block_number]
};
Expand Down Expand Up @@ -1019,7 +1016,6 @@ var Channel = class {
var request = {
targets: targets,
chaincodeId: Constants.QSCC,
chainId: '',
txId: txId,
signer: signer,
fcn: 'GetTransactionByID',
Expand Down Expand Up @@ -1077,7 +1073,6 @@ var Channel = class {
const request = {
targets: targets,
chaincodeId: Constants.LSCC,
chainId: this._name,
txId: txId,
signer: signer,
fcn: 'getchaincodes',
Expand Down Expand Up @@ -1609,7 +1604,6 @@ var Channel = class {
var trans_request = {
targets: targets,
chaincodeId: request.chaincodeId,
chainId: request.channelId,
fcn: request.fcn,
args: request.args,
transientMap: request.transientMap,
Expand Down
15 changes: 6 additions & 9 deletions test/integration/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var ORGS;
var chaincode_id = testUtil.getUniqueVersion('events_unit_test');
var chaincode_version = testUtil.getUniqueVersion();
var request = null;
var the_user = null;

test('Test chaincode instantiate with event, transaction invocation with chaincode event, and query number of chaincode events', (t) => {
testUtil.resetDefaults();
Expand Down Expand Up @@ -119,8 +118,6 @@ test('Test chaincode instantiate with event, transaction invocation with chainco
// setup event hub to get notified when transactions are committed
tls_data = fs.readFileSync(path.join(__dirname, 'e2e', ORGS[org].peer1['tls_cacerts']));

the_user = admin;

eh = client.newEventHub();

// first do one that fails
Expand Down Expand Up @@ -190,7 +187,7 @@ test('Test chaincode instantiate with event, transaction invocation with chainco
eh.connect();
eventhubs.push(eh);

request = eputil.createRequest(client, channel, the_user, chaincode_id, targets, '', '');
request = eputil.createRequest(client, chaincode_id, targets, '', '');
request.chaincodePath = 'github.com/events_cc';
request.chaincodeVersion = chaincode_version;
Client.setConfigSetting('request-timeout', 60000);
Expand All @@ -209,7 +206,7 @@ test('Test chaincode instantiate with event, transaction invocation with chainco
}
}).then((success) => {
t.pass('Successfully initialized the channel');
request = eputil.createRequest(client, channel, the_user, chaincode_id, targets, 'init', []);
request = eputil.createRequest(client, chaincode_id, targets, 'init', []);
request.chaincodePath = 'github.com/events_cc';
request.chaincodeVersion = chaincode_version;

Expand All @@ -227,7 +224,7 @@ test('Test chaincode instantiate with event, transaction invocation with chainco
}).then((results) => {
t.pass('Successfully instantiated chaincode.');

request = eputil.createRequest(client, channel, the_user, chaincode_id, targets, 'invoke', ['invoke', 'SEVERE']);
request = eputil.createRequest(client, chaincode_id, targets, 'invoke', ['invoke', 'SEVERE']);

return channel.sendTransactionProposal(request);
}).then((results) => {
Expand All @@ -240,7 +237,7 @@ test('Test chaincode instantiate with event, transaction invocation with chainco
}).then((results) => {
t.pass('Successfully received chaincode event.');

request = eputil.createRequest(client, channel, the_user, chaincode_id, targets, 'invoke', ['query']);
request = eputil.createRequest(client, chaincode_id, targets, 'invoke', ['query']);

return channel.queryByChaincode(request);
}).then((response_payloads) => {
Expand All @@ -257,8 +254,8 @@ test('Test chaincode instantiate with event, transaction invocation with chainco
// create 2 invoke requests in quick succession that modify
// the same state variable which should cause one invoke to
// be invalid
req1 = eputil.createRequest(client, channel, the_user, chaincode_id, targets, 'invoke', ['invoke', 'SEVERE']);
req2 = eputil.createRequest(client, channel, the_user, chaincode_id, targets, 'invoke', ['invoke', 'SEVERE']);
req1 = eputil.createRequest(client, chaincode_id, targets, 'invoke', ['invoke', 'SEVERE']);
req2 = eputil.createRequest(client, chaincode_id, targets, 'invoke', ['invoke', 'SEVERE']);
return Promise.all([channel.sendTransactionProposal(req1),
channel.sendTransactionProposal(req2)]);
}).then(([results1, results2]) => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/eventutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports.registerCCEvent = function(eh, ccid, enregex, timeout) {
});
};

module.exports.createRequest = function(client, channel, user, chaincode_id, targets, fcn, args) {
module.exports.createRequest = function(client, chaincode_id, targets, fcn, args) {
var tx_id = client.newTransactionID();
var request = {
targets : targets,
Expand Down

0 comments on commit 5b9b75e

Please sign in to comment.