Skip to content

Commit

Permalink
[FABN-975] enable e2e tests
Browse files Browse the repository at this point in the history
- add to test list for main test
- update tests for changes made
- modify network tests to only create wallet once

Change-Id: I19224a1584c0ad4e4cccbb33e98f0f709e4d16ae
Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
nklincoln authored and harrisob committed Nov 6, 2018
1 parent 5fcf519 commit 93fe94d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 97 deletions.
2 changes: 1 addition & 1 deletion build/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ gulp.task('run-test-cucumber', shell.task(
// Main test method to run all test suites
// - lint, unit first, then FV, then scenario
gulp.task('run-test', (done) => {
const tasks = ['clean-up', 'docker-clean', 'pre-test', 'ca', 'compile', 'lint', 'run-test-mocha', 'run-tape-unit', 'docker-clean', 'run-test-cucumber', 'run-logger-unit'];
const tasks = ['clean-up', 'docker-clean', 'pre-test', 'ca', 'compile', 'lint', 'run-test-mocha', 'run-tape-unit', 'run-tape-e2e', 'docker-clean', 'run-test-cucumber', 'run-logger-unit'];
runSequence(...tasks, done);
});

Expand Down
6 changes: 0 additions & 6 deletions fabric-network/lib/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ class Gateway {
this.client = config;
}

if (this.options.discovery && this.options.discovery.enabled) {
this.client.setConfigSetting('initialize-with-discovery', true);
} else {
this.client.setConfigSetting('initialize-with-discovery', false);
}

// setup an initial identity for the Gateway
if (options.identity) {
logger.debug('%s - setting identity', method);
Expand Down
22 changes: 11 additions & 11 deletions test/integration/e2e/e2eUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,22 +268,22 @@ function instantiateChaincodeWithId(userOrg, chaincode_id, chaincode_path, versi
// the v1 chaincode has Init() method that expects a transient map
if (upgrade && badTransient) {
// first test that a bad transient map would get the chaincode to return an error
let request1 = buildChaincodeProposal(client, the_user, chaincode_id, chaincode_path, version, language, upgrade, badTransientMap);
tx_id = request1.txId;
request = buildChaincodeProposal(client, the_user, chaincode_id, chaincode_path, version, language, upgrade, badTransientMap);
tx_id = request.txId;

logger.debug(util.format(
'Upgrading chaincode "%s" at path "%s" to version "%s" by passing args "%s" to method "%s" in transaction "%s"',
request1.chaincodeId,
request1.chaincodePath,
request1.chaincodeVersion,
request1.args,
request1.fcn,
request1.txId.getTransactionID()
request.chaincodeId,
request.chaincodePath,
request.chaincodeVersion,
request.args,
request.fcn,
request.txId.getTransactionID()
));

// this is the longest response delay in the test, sometimes
// x86 CI times out. set the per-request timeout to a super-long value
return channel.sendUpgradeProposal(request1, 10 * 60 * 1000)
return channel.sendUpgradeProposal(request, 10 * 60 * 1000)
.then((results) => {
const proposalResponses = results[0];

Expand All @@ -304,11 +304,11 @@ function instantiateChaincodeWithId(userOrg, chaincode_id, chaincode_path, versi
if (success) {
// successfully tested the negative conditions caused by
// the bad transient map, now send the good transient map
request1 = buildChaincodeProposal(client, the_user, chaincode_id, chaincode_path,
request = buildChaincodeProposal(client, the_user, chaincode_id, chaincode_path,
version, language, upgrade, transientMap);
tx_id = request.txId;

return channel.sendUpgradeProposal(request1, 10 * 60 * 1000);
return channel.sendUpgradeProposal(request, 10 * 60 * 1000);
} else {
throw new Error('Failed to test for bad transient map. The chaincode should have rejected the upgrade proposal.');
}
Expand Down
62 changes: 27 additions & 35 deletions test/integration/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// in a happy-path scenario
'use strict';

const rewire = require('rewire');
const utils = require('fabric-client/lib/utils.js');
const logger = utils.getLogger('install');

Expand Down Expand Up @@ -90,53 +89,46 @@ test('\n\n** Test chaincode install using chaincodePackage[byte] **\n\n', (t) =>
chaincodeVersion: testUtil.getUniqueVersion()
};

const _getChaincodeDeploymentSpec = rewire('fabric-client/lib/Client.js').__get__('_getChaincodeDeploymentSpec');

// install from source
_getChaincodeDeploymentSpec(params, false)
.then((cdsBytes) => {
params.chaincodePackage = cdsBytes;
installChaincode(params, t)
.then((info) => {
if (info === 'success') {
t.pass(params.testDesc + ' - success');
return true;
} else {
t.fail(params.testDesc + ' - ' + info);
t.end();
}
},
(err) => {
t.fail(params.testDesc + ' - install reject: ' + err);
t.end();
}).catch((err) => {
t.fail(params.testDesc + ' - install error. ' + err.stack ? err.stack : err);
t.end();
}).then(() => {
params.channelName = params.channelName + '0';
params.testDesc = params.testDesc + '0';
installChaincode(params, t)
.then((info) => {
if (info === 'success') {
t.pass(params.testDesc + ' - success');
return true;
if (info && info instanceof Error && info.message.includes('install-package.' + params.chaincodeVersion + ' exists')) {
t.pass('passed check for exists same code again');
t.end();
} else {
t.fail(params.testDesc + ' - ' + info);
t.fail('failed check for exists same code again');
t.end();
}
},
(err) => {
t.fail(params.testDesc + ' - install reject: ' + err);
t.fail(params.testDesc + ' - install same chaincode again - reject, error');
logger.error(err.stack ? err.stack : err);
t.end();
}).catch((err) => {
t.fail(params.testDesc + ' - install error. ' + err.stack ? err.stack : err);
t.fail(params.testDesc + ' - install same chaincode again - error');
logger.error(err.stack ? err.stack : err);
t.end();
}).then(() => {
params.channelName = params.channelName + '0';
params.testDesc = params.testDesc + '0';
installChaincode(params, t)
.then((info) => {
if (info && info instanceof Error && info.message.includes('install-package.' + params.chaincodeVersion + ' exists')) {
t.pass('passed check for exists same code again');
t.end();
} else {
t.fail('failed check for exists same code again');
t.end();
}
},
(err) => {
t.fail(params.testDesc + ' - install same chaincode again - reject, error');
logger.error(err.stack ? err.stack : err);
t.end();
}).catch((err) => {
t.fail(params.testDesc + ' - install same chaincode again - error');
logger.error(err.stack ? err.stack : err);
t.end();
});
});
});
t.end();
});

function installChaincode(params, t) {
Expand Down
64 changes: 21 additions & 43 deletions test/integration/network-e2e/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ async function getFirstEventHubForOrg(gateway, orgMSP) {
return channel.getChannelEventHub(orgPeer.getName());
}

test('\n\n***** Network End-to-end flow: import identity into wallet *****\n\n', async (t) => {
await inMemoryIdentitySetup();
const exists = await inMemoryWallet.exists('[email protected]');
if (exists) {
t.pass('Successfully imported [email protected] into wallet');
} else {
t.fail('Failed to import [email protected] into wallet');
test('\n\n***** Network End-to-end flow: import identity into wallet and configure tls *****\n\n', async (t) => {
try {
await inMemoryIdentitySetup();
await tlsSetup();
const exists = await inMemoryWallet.exists('[email protected]');
if (exists) {
t.pass('Successfully imported [email protected] into wallet');
} else {
t.fail('Failed to import [email protected] into wallet');
}
} catch (err) {
t.fail('Failed to import identity into wallet and configure tls. ' + err.stack ? err.stack : err);
}
t.end();
});
Expand All @@ -77,8 +82,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
let org1EventHub;

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -133,9 +136,6 @@ test('\n\n***** Network End-to-end flow: invoke multiple transactions to move mo
let org1EventHub;

try {
await inMemoryIdentitySetup();
await tlsSetup();


const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -213,8 +213,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
let org1EventHub;

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -269,8 +267,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
const gateway = new Gateway();
let org1EventHub;
try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -327,8 +323,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
let org2EventHub;

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -392,8 +386,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
let org2EventHub;

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -457,8 +449,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
let org2EventHub;

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -527,8 +517,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
let org2EventHub;

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -595,8 +583,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
const gateway = new Gateway();

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -631,8 +617,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction with transient data
const gateway = new Gateway();

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -685,8 +669,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction with empty string re
const gateway = new Gateway();

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down Expand Up @@ -716,19 +698,17 @@ test('\n\n***** Network End-to-end flow: invoke transaction with empty string re
test('\n\n***** Network End-to-end flow: handle transaction error *****\n\n', async (t) => {
const gateway = new Gateway();

await inMemoryIdentitySetup();
await tlsSetup();
try {

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
identity: '[email protected]',
clientTlsIdentity: 'tlsId',
discovery: {
enabled: false
}
});
const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
identity: '[email protected]',
clientTlsIdentity: 'tlsId',
discovery: {
enabled: false
}
});

try {
const response = await contract.submitTransaction('throwError', 'a', 'b', '100');
t.fail('Transaction "throwError" should have thrown an error. Got response: ' + response.toString());
} catch (expectedErr) {
Expand Down Expand Up @@ -893,8 +873,6 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
const gateway = new Gateway();

try {
await inMemoryIdentitySetup();
await tlsSetup();

const contract = await createContract(t, gateway, {
wallet: inMemoryWallet,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/network-e2e/updateAnchorPeers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const channel_name = testUtil.NETWORK_END2END.channel;
const anchorPeerTXFileOrg1 = path.join(__dirname, '../../fixtures/channel/mychannel-org1anchor.tx');


test('\n\n***** End-to-end flow: setAnchorPeers *****\n\n', async (t) => {
test('\n\n***** Network End-to-end flow: setAnchorPeers *****\n\n', async (t) => {
// this will use the connection profile to set up the client
const client_org1 = await testUtil.getClientForOrg(t, 'org1');
const client_org2 = await testUtil.getClientForOrg(t, 'org2');
Expand Down

0 comments on commit 93fe94d

Please sign in to comment.