Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Au shah issue1826 #1958

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/blockchain-extension/cucumber/data/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,29 @@
"requiredPeerCount": 1,
"maxPeerCount": 1,
"blockToLive": 100
},
{
"name": "CollectionOne",
"policy": {
"identities": [
{
"role": {
"name": "member",
"mspId": "Org1MSP"
}
}
],
"policy": {
"1-of": [
{
"signed-by": 0
}
]
}
},
"requiredPeerCount": 1,
"maxPeerCount": 1,
"blockToLive": 0,
"memberOnlyRead": true
}
]
12 changes: 12 additions & 0 deletions packages/blockchain-extension/cucumber/features/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ Feature: Created Smart Contracts
| TypeScript | Conga | TypeScriptContract | 0.0.1 |
| Java | Conga | JavaContract | 0.0.1 |
| Go | null | GoContract | 0.0.1 |

@ansibleFabric
Scenario Outline: Create a private data smart contract
Given a private <language> smart contract for <assetType> assets with the name <name> and version <version> and mspid <mspid>
And the contract hasn't been created already
When I create the private contract
Then a new contract directory should exist
Examples:
| language | assetType | name | mspid | version |
| JavaScript | PrivateConga | PrivateJavaScriptContract | Org1MSP | 0.0.1 |
| TypeScript | PrivateConga | PrivateTypeScriptContract | Org1MSP | 0.0.1 |
| Java | PrivateConga | PrivateJavaContract | Org1MSP | 0.0.1 |
17 changes: 17 additions & 0 deletions packages/blockchain-extension/cucumber/features/install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ Feature: Install Smart Contract
| TypeScript | Conga | TypeScriptContract | [email protected] | 0.0.1 |
| Java | Conga | JavaContract | [email protected] | 0.0.1 |
| Go | null | GoContract | [email protected] | 0.0.1 |


@ansibleFabric
Scenario Outline: Install a smart contract
Given a private <language> smart contract for <assetType> assets with the name <name> and version <version> and mspid <mspid>
Given an environment 'myAnsibleFabric' exists
And the 'myAnsibleFabric' environment is connected
And the private contract has been created
And the contract has been packaged
When I install the package
Then there should be a installed smart contract tree item with a label '<installedName>' in the 'Fabric Environments' panel
And the tree item should have a tooltip equal to 'Installed on: Org1Peer1, Org1Peer2, Org2Peer1, Org2Peer2'
Examples:
| language | assetType | name | installedName | version |
| JavaScript | PrivateConga | PrivateJavaScriptContract | [email protected] | 0.0.1 |
| TypeScript | PrivateConga | PrivateTypeScriptContract | [email protected] | 0.0.1 |
| Java | PrivateConga | PrivateJavaContract | [email protected] | 0.0.1 |
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Instantiate Smart Contracts
And the contract has been packaged
And the package has been installed
When I instantiate the installed package with the transaction '' and args '', not using private data on channel 'mychannel'
Then there should be a instantiated smart contract tree item with a label '<instantiatedName>' in the 'Fabric Environments' panel
Then there should be an instantiated smart contract tree item with a label '<instantiatedName>' in the 'Fabric Environments' panel
And the tree item should have a tooltip equal to 'Instantiated on: mychannel'
Examples:
| language | assetType | name | instantiatedName | version |
Expand All @@ -18,3 +18,19 @@ Feature: Instantiate Smart Contracts
| Java | Conga | JavaContract | [email protected] | 0.0.1 |
| Go | null | GoContract | [email protected] | 0.0.1 |

@ansibleFabric
Scenario Outline: Instantiate a private smart contract
Given a private <language> smart contract for <assetType> assets with the name <name> and version <version> and mspid <mspid>
Given an environment 'myAnsibleFabric' exists
And the 'myAnsibleFabric' environment is connected
And the private contract has been created
And the contract has been packaged
And the package has been installed
When I instantiate the installed package with the transaction '' and args '', using private data on channel 'channel1'
Then there should be an instantiated smart contract tree item with a label '<instantiatedName>' in the 'Fabric Environments' panel
And the tree item should have a tooltip equal to 'Instantiated on: channel1'
Examples:
| language | assetType | name | instantiatedName | mspid | version |
| JavaScript | PrivateConga | PrivateJavaScriptContract | [email protected] | Org1MSP | 0.0.1 |
| TypeScript | PrivateConga | PrivateTypeScriptContract | [email protected] | Org1MSP | 0.0.1 |
| Java | PrivateConga | PrivateJavaContract | [email protected] | Org1MSP | 0.0.1 |
24 changes: 23 additions & 1 deletion packages/blockchain-extension/cucumber/features/submit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Submit transaction
| Go | null | GoContract | 0.0.1 |


Scenario Outline: Submit a transaction for a smart contract using generated transaction data
Scenario Outline: Submit a transaction for a smart contract using generated transaction data
Given a <language> smart contract for <assetType> assets with the name <name> and version <version>
And the Local Fabric is running
And the 'Local Fabric' environment is connected
Expand All @@ -40,6 +40,28 @@ Feature: Submit transaction
| language | assetType | name | version |
| TypeScript | Conga | TypeScriptContract | 0.0.1 |

@ansibleFabric
Scenario Outline: Submit a verify transaction for a private data smart contract
Given a private <language> smart contract for <assetType> assets with the name <name> and version <version> and mspid <mspid>
Given an environment 'myAnsibleFabric' exists
And the 'myAnsibleFabric' environment is connected
And the 'admin' identity
And I'm connected to the 'myAnsibleFabric - Org1 gateway' gateway
And the private contract has been created
And the contract has been packaged
And the package has been installed
And the contract has been instantiated with the transaction '' and args '', using private data on channel 'channel1'
When I submit the transaction 'createPrivateConga' on the channel 'mychannel' with args '["001"]' and with the transient data '{"privateValue":"125"}'
Then the logger should have been called with 'SUCCESS', 'Successfully submitted transaction' and 'No value returned from createPrivateConga'
When I submit the transaction 'verifyPrivateConga' on the channel 'mychannel' with args '["001", "{\"privateValue\":\"125\"}"]'
Then the logger should have been called with 'SUCCESS', 'Successfully submitted transaction' and 'Returned value from verifyPrivateConga: true'
Examples:
| language | assetType | name | mspid | version |
| JavaScript | PrivateConga | PrivateJavaScriptContract | Org1MSP | 0.0.1 |
| TypeScript | PrivateConga | PrivateTypeScriptContract | Org1MSP | 0.0.1 |
| Java | PrivateConga | PrivateJavaContract | Org1MSP | 0.0.1 |


@otherFabric
Scenario Outline: Submit a transaction for a smart contract (other fabric)
Given an environment 'myFabric' exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ export class GatewayHelper {
if (!transientData) {
transientData = '';
}
this.userInputUtilHelper.inputBoxStub.withArgs('optional: What is the transient data for the transaction, e.g. {"key": "value"}', '{}').resolves(transientData);

const transientDataWithoutQuotes: string = transientData.slice(1, -1);

this.userInputUtilHelper.inputBoxStub.withArgs('optional: What is the transient data for the transaction, e.g. {"key": "value"}', '{}').resolves(transientDataWithoutQuotes);

this.userInputUtilHelper.showQuickPickStub.withArgs('Select a peer-targeting policy for this transaction', [UserInputUtil.DEFAULT, UserInputUtil.CUSTOM]).resolves(UserInputUtil.DEFAULT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class SmartContractHelper {
this.userInputUtilHelper = userInputUtilHelper;
}

public async createSmartContract(language: string, assetType: string, contractName: string): Promise<string> {
public async createSmartContract(language: string, assetType: string, contractName: string, mspid?: string): Promise<string> {

let type: LanguageType;
if (language === 'Go') {
Expand All @@ -60,9 +60,16 @@ export class SmartContractHelper {
throw new Error(`You must update this test to support the ${language} language`);
}

this.userInputUtilHelper.showLanguagesQuickPickStub.resolves({ label: language, type });
if (contractName.includes('Private')) {
this.userInputUtilHelper.showQuickPickItemStub.resolves({label: UserInputUtil.GENERATE_PD_CONTRACT, description: UserInputUtil.GENERATE_PD_CONTRACT_DESCRIPTION, data: 'private'});
this.userInputUtilHelper.inputBoxStub.withArgs('Name the type of asset managed by this smart contract', 'MyPrivateAsset').resolves(assetType);
this.userInputUtilHelper.inputBoxStub.withArgs('Please provide an mspID for the private data collection', 'Org1MSP').resolves(mspid);
} else {
this.userInputUtilHelper.showQuickPickItemStub.resolves({label: UserInputUtil.GENERATE_DEFAULT_CONTRACT, description: UserInputUtil.GENERATE_DEFAULT_CONTRACT_DESCRIPTION, data: 'default'});
this.userInputUtilHelper.inputBoxStub.withArgs('Name the type of asset managed by this smart contract', 'MyAsset').resolves(assetType);
}

this.userInputUtilHelper.inputBoxStub.withArgs('Name the type of asset managed by this smart contract', 'MyAsset').resolves(assetType);
this.userInputUtilHelper.showLanguagesQuickPickStub.resolves({ label: language, type });

this.userInputUtilHelper.showFolderOptionsStub.withArgs('Choose how to open your new project').resolves(UserInputUtil.ADD_TO_WORKSPACE);

Expand Down Expand Up @@ -206,7 +213,8 @@ export class SmartContractHelper {
this.userInputUtilHelper.showYesNoQuickPick.resolves(UserInputUtil.NO);
if (privateData) {
this.userInputUtilHelper.showYesNoQuickPick.resolves(UserInputUtil.YES);
const collectionPath: string = path.join(__dirname, '../../integrationTest/data/collection.json');
this.userInputUtilHelper.getWorkspaceFoldersStub.callThrough();
const collectionPath: string = path.join(__dirname, '../../../cucumber/data/collection.json');
this.userInputUtilHelper.browseStub.resolves(collectionPath);
}

Expand Down Expand Up @@ -258,7 +266,7 @@ export class SmartContractHelper {
this.userInputUtilHelper.showYesNoQuickPick.resolves(UserInputUtil.NO);
if (privateData) {
this.userInputUtilHelper.showYesNoQuickPick.resolves(UserInputUtil.YES);
const collectionPath: string = path.join(__dirname, '../../integrationTest/data/collection.json');
const collectionPath: string = path.join(__dirname, '../../../cucumber/data/collection.json');
this.userInputUtilHelper.browseStub.resolves(collectionPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,41 @@ module.exports = function(): any {
* Given
*/

this.Given('a {string} smart contract for {string} assets with the name {string} and version {string}', this.timeout, async (language: string, assetType: string, name: string, version: string) => {
this.Given(/^a (private )?(.+) smart contract for (.+) assets with the name (.+) and version (.\S+)( and mspid)? ?(.+)?$/, this.timeout, async (privateOrNot: string, language: string, assetType: string, name: string, version: string, _ignore: string, mspid: string) => {
this.contractLanguage = language;
if (assetType === 'null') {
assetType = null;
}

if (privateOrNot === 'private ') {
this.mspid = mspid;
} else {
this.mspid = null;
}

this.contractAssetType = assetType;
this.namespace = `${this.contractAssetType}Contract`;
this.contractName = name;
this.contractVersion = version;
});

this.Given("the contract hasn't been created already", this.timeout, async () => {
this.Given(/the contract hasn't been created already/, this.timeout, async () => {
const contractDirectory: string = this.smartContractHelper.getContractDirectory(this.contractName, this.contractLanguage);
const exists: boolean = await fs.pathExists(contractDirectory);
if (exists) {
await fs.remove(contractDirectory);
}
});

this.Given('the contract has been created', this.timeout, async () => {
this.Given(/the( private)? contract has been created/, this.timeout, async (_privateOrNot: string) => {
const contractDirectory: string = this.smartContractHelper.getContractDirectory(this.contractName, this.contractLanguage);
const exists: boolean = await fs.pathExists(contractDirectory);
if (!exists) {
this.contractDirectory = await this.smartContractHelper.createSmartContract(this.contractLanguage, this.contractAssetType, this.contractName);
if (_privateOrNot === ' private') {
this.contractDirectory = await this.smartContractHelper.createSmartContract(this.contractLanguage, this.contractAssetType, this.contractName, this.mspid);
} else {
this.contractDirectory = await this.smartContractHelper.createSmartContract(this.contractLanguage, this.contractAssetType, this.contractName);
}
} else {
this.contractDirectory = contractDirectory;
}
Expand All @@ -76,8 +87,12 @@ module.exports = function(): any {
* When
*/

this.When('I create the contract', this.timeout, async () => {
this.contractDirectory = await this.smartContractHelper.createSmartContract(this.contractLanguage, this.contractAssetType, this.contractName);
this.When(/I create the( private)? contract/, this.timeout, async (_privateOrNot: string) => {
if (_privateOrNot === ' private') {
this.contractDirectory = await this.smartContractHelper.createSmartContract(this.contractLanguage, this.contractAssetType, this.contractName, this.mspid);
} else {
this.contractDirectory = await this.smartContractHelper.createSmartContract(this.contractLanguage, this.contractAssetType, this.contractName);
}
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export class UserInputUtil {
static readonly CANCEL_NO_CERT_CHAIN: string = 'Cancel';
static readonly CANCEL_NO_CERT_CHAIN_DESCRIPTION: string = '(CA certificate chain must be added to Operative System trusted root certificates)';
static readonly CONNECT_NO_CA_CERT_CHAIN: string = 'Proceed without certificate verification';
static readonly GENERATE_DEFAULT_CONTRACT: string = 'Default Contract';
static readonly GENERATE_DEFAULT_CONTRACT_DESCRIPTION: string = 'CRUD operations to a ledger shared by all network members';
static readonly GENERATE_PD_CONTRACT: string = 'Private Data Contract';
static readonly GENERATE_PD_CONTRACT_DESCRIPTION: string = 'CRUD and verify operations to a collection, private to a single network member';

public static async showQuickPick(prompt: string, items: string[], canPickMany: boolean = false): Promise<string | string[]> {
const quickPickOptions: vscode.QuickPickOptions = {
Expand Down
Loading