Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getter for contract definitions #991

Merged
merged 3 commits into from
Sep 10, 2020

Conversation

RosieMurphy0
Copy link
Contributor

Signed-off-by: RosieMurphy0 [email protected]

Adds a function that returns the array that holds the contracts for a specified channel from the config file.

Contributes to #940

*/
getContractDefinitionsForChannelName(channelPassed) {
const channelList = this.adapterConfiguration.channels;
const channelWanted = channelList.filter(channelContracts => channelContracts.channelName === channelPassed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we don't have a validator yet and not sure when a validator would be made available for now lets add some defensive checks here to make sure that there is a channelList, so you can check the example used in getChannelNamesForCreation.

* @param {string} channelPassed channel wanted
* @returns {Array} all of contract definitions for channel
*/
getContractDefinitionsForChannelName(channelPassed) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would suggest changing channelPassed to channelName for the parameter

getContractDefinitionsForChannelName(channelPassed) {
const channelList = this.adapterConfiguration.channels;
const channelWanted = channelList.filter(channelContracts => channelContracts.channelName === channelPassed);
const contractDefinitions = channelWanted[0].contracts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, if the contracts definition is not there, then we should just return an empty array. Currently if it wasn't present we would be returning null or undefined. This will need a further test to check for.


if (channelList && Array.isArray(channelList)){
const channelWanted = channelList.filter(channelContracts => channelContracts.channelName === channelName);
const contractDefinitions = channelWanted[0].contracts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should test here what is in contracts, eg

if (contractDefinitions && 
    Array.isArray(contractDefinitions) {
   return contractDefinitions;
}

Then add a test to see that you get an empty array is the contracts property hasn't been specified

Copy link
Contributor

@davidkel davidkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davidkel davidkel merged commit c4015c9 into hyperledger-caliper:master Sep 10, 2020
@RosieMurphy0 RosieMurphy0 deleted the con-defs branch October 1, 2020 12:29
danielporto pushed a commit to danielporto/caliper that referenced this pull request Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants