Skip to content

Commit

Permalink
nodeSDK Fix test failures
Browse files Browse the repository at this point in the history
Need to add sendInstallProposal to endorser-tests
and fix require for ../unit/utils as well as some
other minor fixes.

Change-Id: I1987d9ce05d9e7af7b85f0cd4bf4646175506d74
Signed-off-by: cdaughtr <[email protected]>
  • Loading branch information
cdaughtr committed Feb 20, 2017
1 parent 084d3b5 commit 0344555
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 17 deletions.
2 changes: 1 addition & 1 deletion fabric-client/lib/Chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ var Chain = class {
if (request) {
// Verify that data is being passed in
if (!request.proposalResponses) {
errorMsg = 'Missing "proposalResponse" parameter in transaction request';
errorMsg = 'Missing "proposalResponses" parameter in transaction request';
}
if (!request.proposal) {
errorMsg = 'Missing "proposal" parameter in transaction request';
Expand Down
82 changes: 74 additions & 8 deletions test/integration/endorser-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,26 @@ var tape = require('tape');
var _test = require('tape-promise');
var test = _test(tape);

var log4js = require('log4js');
var logger = log4js.getLogger('E2E');
logger.setLevel('DEBUG');

var Client = require('fabric-client');
Client.setLogger(logger);
var Peer = require('fabric-client/lib/Peer');
var copService = require('fabric-ca-client');
var util = require('util');
var fs = require('fs');
var testUtil = require('./util.js');
var testUtil = require('../unit/util.js');
var utils = require('fabric-client/lib/utils.js');

var keyValStorePath = testUtil.KVS;
var chaincode_id = 'end2end';
var chaincode_version = 'endorser-v0';
var chain_id = 'testchainid';
var tx_id = null;
var nonce = null;
var the_user = null;

testUtil.setupChaincodeDeploy();

Expand Down Expand Up @@ -61,25 +72,80 @@ test('\n\n** TEST ** endorse chaincode deployment good test', function(t) {

chain.addPeer(new Peer('grpc://localhost:7051'));
chain.addPeer(new Peer('grpc://localhost:7056'));
///
the_user = admin;
nonce = utils.getNonce();
tx_id = chain.buildTransactionID(nonce, the_user);

// send proposal to endorser
var request = {
chaincodePath: testUtil.CHAINCODE_PATH,
chaincodeId: 'endorser_test',
chaincodeId: chaincode_id,
chaincodeVersion: chaincode_version,
txId: tx_id,
nonce: nonce
};

return chain.sendInstallProposal(request);

},
(err) => {
t.fail('Failed to enroll user \'admin\'. ' + err);
t.end();
}).then((results) => {
var proposalResponses = results[0];

var proposal = results[1];
var header = results[2];
var all_good = true;
for(var i in proposalResponses) {
let one_good = false;
if (proposalResponses && proposalResponses[0].response && proposalResponses[0].response.status === 200) {
one_good = true;
logger.info('install proposal was good');
} else {
logger.error('install proposal was bad');
}
all_good = all_good & one_good;
}
if (all_good) {
t.pass(util.format('Successfully sent install Proposal and received ProposalResponse: Status - %s', proposalResponses[0].response.status));
return Promise.resolve(all_good);
if (useSteps) {
t.end();
}
} else {
t.fail('Failed to send install Proposal or receive valid response. Response null or status is not 200. exiting...');
t.end();
}
},
(err) => {
t.fail('Failed to send install proposal due to error: ' + err.stack ? err.stack : err);
t.end();
})
.then(function(all_good) {
// send proposal to endorser
nonce = utils.getNonce();
tx_id = chain.buildTransactionID(nonce, the_user);

var request = {
chaincodePath: testUtil.CHAINCODE_PATH,
chaincodeId: chaincode_id,
chaincodeVersion: chaincode_version,
fcn: 'init',
args: ['a', '100', 'b', '200'],
chainId: 'testchainid',
txId: 'blah',
nonce: utils.getNonce()
chainId: chain_id,
txId: tx_id,
nonce: nonce
};

return chain.sendDeploymentProposal(request);
},
function(err) {
t.fail('Failed to enroll user \'admin\'. ' + err);
t.end();
}
).then(
function(data) {
})
.then(function(data) {
if (Array.isArray(data) && data.length === 3) {
let response = data[0];

Expand Down
16 changes: 11 additions & 5 deletions test/integration/orderer-chain-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('\n\n** TEST ** orderer via member missing orderer', function(t) {
}
).then(
function(status) {
console.log('Status: ' + status + ', type: (' + typeof status + ')');
t.comment('Status: ' + status + ', type: (' + typeof status + ')');
if (status === 0) {
t.fail('Successfully submitted request, which is bad because the chain is missing orderers.');
} else {
Expand All @@ -67,7 +67,7 @@ test('\n\n** TEST ** orderer via member missing orderer', function(t) {
t.end();
},
function(err) {
console.log('Error: ' + err);
t.comment('Error: ' + err);
t.pass('Successfully tested invalid submission due to missing orderers. Error code: ' + err);
t.end();
}
Expand Down Expand Up @@ -161,15 +161,20 @@ test('\n\n** TEST ** orderer via member bad orderer address', function(t) {
t.pass('Successfully enrolled user \'admin\'');

// send to orderer
return chain.sendTransaction('some data');
var request = {
proposalResponses: 'blah',
proposal: 'blah',
header: 'blah'
};
return chain.sendTransaction(request);
},
function(err) {
t.fail('Failed to enroll user \'admin\'. ' + err);
t.end();
}
).then(
function(status) {
console.log('Status: ' + status + ', type: (' + typeof status + ')');
t.comment('Status: ' + status + ', type: (' + typeof status + ')');
if (status === 0) {
t.fail('Successfully submitted request, which is bad because the chain\'s orderer address is invalid');
} else {
Expand All @@ -178,11 +183,12 @@ test('\n\n** TEST ** orderer via member bad orderer address', function(t) {
t.end();
},
function(err) {
t.pass('Failed to submit ::' + err);
t.pass('Failed to submit ::' + err.stack ? err.stack : err);
t.end();
}
).catch(function(err) {
t.pass('Failed to submit orderer request. ' + err);
t.end();
});
});

6 changes: 3 additions & 3 deletions test/unit/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,10 @@ test('\n\n ** Chain sendTransaction() tests **\n\n', function (t) {
.then(function () {
t.fail('Should not have been able to resolve the promise because of missing parameters');
}, function (err) {
if (err.message.indexOf('Missing "proposalResponse" parameter in transaction request') >= 0) {
t.pass('Successfully caught missing proposalResponse error');
if (err.message.indexOf('Missing "proposalResponses" parameter in transaction request') >= 0) {
t.pass('Successfully caught missing proposalResponses error');
} else {
t.fail('Failed to catch the missing proposalResponse error. Error: ' + err.stack ? err.stack : err);
t.fail('Failed to catch the missing proposalResponses error. Error: ' + err.stack ? err.stack : err);
}
});

Expand Down

0 comments on commit 0344555

Please sign in to comment.