Skip to content

Commit

Permalink
stress less
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkhala committed Jan 24, 2024
1 parent 8d36062 commit 9a4bb8d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 100 deletions.
3 changes: 3 additions & 0 deletions app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const projectResolve = (...args) => path.resolve(projectRoot, ...args);

const CRYPTO_CONFIG_DIR = homeResolve(globalConfig.docker.volumes.MSPROOT);

export function orgNamesOfChannel(channelName){
return Object.keys(globalConfig.channels[channelName].organizations)
}
const preparePeer = (orgName, peerIndex, peerConfig) => {
const {port: peerPort} = peerConfig;

Expand Down
37 changes: 15 additions & 22 deletions cc/golang/contracts.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import assert from 'assert';
import * as helper from '../../app/helper.js';
import {installAll, ChaincodeDefinitionOperator} from '../../app/installHelper.js';
import {installAll} from '../../app/installHelper.js';
import FabricGateway from '../../common/nodejs/fabric-gateway/index.js';
import {consoleLogger} from '@davidkhala/logger/log4.js';
import UserBuilder from '../../common/nodejs/admin/user.js';
import {dev} from '../testutil.js';
import {dev, smartApprove, commit} from '../testutil.js';

const chaincodeID = 'contracts';
const logger = consoleLogger(`chaincode:${chaincodeID}`);
const orderers = helper.newOrderers();
const orderer = orderers[0];
const channel = 'allchannel';

const init_required = false;

describe('deploy', function () {
this.timeout(0);

Expand All @@ -31,25 +29,14 @@ describe('deploy', function () {

const orgs = ['icdd', 'astri.org'];
for (const org of orgs) {
// TODO migrate to testutil.js
const admin = helper.getOrgAdmin(org);
const peers = helper.newPeers([0, 1], org);
const operator = new ChaincodeDefinitionOperator(channel, admin, peers, init_required);
await operator.connect();
await operator.queryInstalledAndApprove(chaincodeID, orderer);
await operator.disconnect();
await smartApprove(org, chaincodeID, orderer);
}

});
it('commit', async () => {
// TODO migrate to testutil.js
const org = 'icdd';
const peers = [helper.newPeer(0, 'astri.org'), helper.newPeer(0, 'icdd')];
const admin = helper.getOrgAdmin(org);
const operator = new ChaincodeDefinitionOperator(channel, admin, peers, init_required);
await operator.connect();
await operator.queryAndCommit(chaincodeID, orderer);
await operator.disconnect();
await commit(org, chaincodeID, orderer);
});
});
describe('invoke', function () {
Expand All @@ -76,14 +63,20 @@ describe('invoke', function () {

});
it('p1e', async () => {
await assert.rejects(async () => {
await contract.evaluateTransaction('StupidContract:P1E');
});
await assert.rejects(async () => {
await contract.evaluateTransaction('StupidContract:p1E');
});


});
it('stress 10', async () => {
for (let i = 0; i < 10; i++) {
await contract.submitTransaction('ping');
}
for (let i = 0; i < 10; i++) {
await contract.submit(['ping'], undefined, undefined, true);
}
for (let i = 0; i < 10; i++) {
await contract.evaluateTransaction('ping');
}
});
});

Expand Down
75 changes: 0 additions & 75 deletions cc/golang/stress.js

This file was deleted.

18 changes: 18 additions & 0 deletions cc/testutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,21 @@ export async function dev(org, chaincodeID, init_required = false) {
logger.debug({installed, uncommitted, committed, definitions});
await operator.disconnect();
}

export async function smartApprove(org, chaincodeID, orderer, init_required = false) {
const admin = helper.getOrgAdmin(org);
const peers = helper.newPeers([0, 1], org);
const operator = new ChaincodeDefinitionOperator(channel, admin, peers, init_required);
await operator.connect();
await operator.queryInstalledAndApprove(chaincodeID, orderer);
await operator.disconnect();
}

export async function commit(org, chaincodeID, orderer, init_required = false) {
const peers = helper.orgNamesOfChannel(channel).map(orgName => helper.newPeer(0, orgName));
const admin = helper.getOrgAdmin(org);
const operator = new ChaincodeDefinitionOperator(channel, admin, peers, init_required);
await operator.connect();
await operator.queryAndCommit(chaincodeID, orderer);
await operator.disconnect();
}
3 changes: 0 additions & 3 deletions config/chaincode.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"stress": {
"path": "chaincode/golang/stress"
},
"contracts": {
"path": "chaincode/golang/contracts"
},
Expand Down

0 comments on commit 9a4bb8d

Please sign in to comment.