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

Commit

Permalink
ix spinner on channel for contracts not started
Browse files Browse the repository at this point in the history
Signed-off-by: heatherlp <heatherpollard0@gmail.com>
  • Loading branch information
heatherlp committed Jul 10, 2019
1 parent f6229ca commit a3f6aef
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 74 deletions.
10 changes: 10 additions & 0 deletions client/integrationTest/nodeTests/integrationNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { FabricWalletUtil } from '../../src/fabric/FabricWalletUtil';
import { FabricRuntimeUtil } from '../../src/fabric/FabricRuntimeUtil';
import { PeerTreeItem } from '../../src/explorer/runtimeOps/PeerTreeItem';
import { SettingConfigurations } from '../../SettingConfigurations';
import { InstantiatedUnknownTreeItem } from '../../src/explorer/model/InstantiatedUnknownTreeItem';

chai.use(sinonChai);
chai.use(chaiAsPromised);
Expand Down Expand Up @@ -255,6 +256,9 @@ describe('Integration Tests for Node Smart Contracts', () => {
channels.length.should.equal(1);
channels[0].label.should.equal('mychannel');

const instantiatedUnknownTreeItems: Array<InstantiatedUnknownTreeItem> = await myExtension.getBlockchainRuntimeExplorerProvider().getChildren(channels[0]) as Array<InstantiatedUnknownTreeItem>;
await myExtension.getBlockchainRuntimeExplorerProvider().getChildren(instantiatedUnknownTreeItems[0]);

instantiatedChaincodesItems = await myExtension.getBlockchainGatewayExplorerProvider().getChildren(channels[0]) as Array<InstantiatedContractTreeItem>;

instantiatedSmartContract = instantiatedChaincodesItems.find((_instantiatedSmartContract: BlockchainTreeItem) => {
Expand Down Expand Up @@ -422,6 +426,9 @@ describe('Integration Tests for Node Smart Contracts', () => {
channels[0].label.should.equal('mychannel');
channels[1].label.should.equal('myotherchannel');

const instantiatedUnknownTreeItems: Array<InstantiatedUnknownTreeItem> = await myExtension.getBlockchainRuntimeExplorerProvider().getChildren(channels[0]) as Array<InstantiatedUnknownTreeItem>;
await myExtension.getBlockchainRuntimeExplorerProvider().getChildren(instantiatedUnknownTreeItems[0]);

const instantiatedChaincodesItems: Array<InstantiatedContractTreeItem> = await myExtension.getBlockchainGatewayExplorerProvider().getChildren(channels[0]) as Array<InstantiatedContractTreeItem>;

const instantiatedSmartContract: InstantiatedContractTreeItem = instantiatedChaincodesItems.find((_instantiatedSmartContract: BlockchainTreeItem) => {
Expand Down Expand Up @@ -463,6 +470,9 @@ describe('Integration Tests for Node Smart Contracts', () => {
channels[0].label.should.equal('mychannel');
channels[1].label.should.equal('myotherchannel');

const instantiatedUnknownTreeItems: Array<InstantiatedUnknownTreeItem> = await myExtension.getBlockchainRuntimeExplorerProvider().getChildren(channels[0]) as Array<InstantiatedUnknownTreeItem>;
await myExtension.getBlockchainRuntimeExplorerProvider().getChildren(instantiatedUnknownTreeItems[0]);

const instantiatedChaincodesItems: Array<InstantiatedContractTreeItem> = await myExtension.getBlockchainGatewayExplorerProvider().getChildren(channels[0]) as Array<InstantiatedContractTreeItem>;

const instantiatedSmartContract: BlockchainTreeItem = instantiatedChaincodesItems.find((_instantiatedSmartContract: BlockchainTreeItem) => {
Expand Down
8 changes: 6 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
},
{
"command": "gatewaysExplorer.testSmartContractEntry",
"title": "Generate Tests for Smart Contract",
"title": "Generate Tests for Smart Contract(s)",
"category": "IBM Blockchain Platform"
},
{
Expand Down Expand Up @@ -612,7 +612,7 @@
"when": "view == gatewaysExplorer && viewItem == blockchain-gateway-dissociated-item"
},
{
"command": "gatewaysExplorer.testAllSmartContractEntry",
"command": "gatewaysExplorer.testSmartContractEntry",
"when": "view == gatewaysExplorer && viewItem == blockchain-instantiated-multi-contract-item"
},
{
Expand All @@ -623,6 +623,10 @@
"command": "gatewaysExplorer.testSmartContractEntry",
"when": "view == gatewaysExplorer && viewItem == blockchain-contract-item"
},
{
"command": "gatewaysExplorer.testSmartContractEntry",
"when": "view == gatewaysExplorer && viewItem == blockchain-instantiated-unknown-item"
},
{
"command": "gatewaysExplorer.submitTransactionEntry",
"when": "view == gatewaysExplorer && viewItem == blockchain-transaction-item"
Expand Down
6 changes: 3 additions & 3 deletions client/src/commands/testSmartContractCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { FabricConnectionManager } from '../fabric/FabricConnectionManager';
import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter';
import { Reporter } from '../util/Reporter';
import { CommandUtil } from '../util/CommandUtil';
import { InstantiatedContractTreeItem } from '../explorer/model/InstantiatedContractTreeItem';
import { InstantiatedTreeItem } from '../explorer/model/InstantiatedTreeItem';
import { FabricGatewayRegistryEntry } from '../fabric/FabricGatewayRegistryEntry';
import { MetadataUtil } from '../util/MetadataUtil';
import { LogType } from '../logging/OutputAdapter';
Expand All @@ -32,7 +32,7 @@ import { IFabricClientConnection } from '../fabric/IFabricClientConnection';
import { ContractTreeItem } from '../explorer/model/ContractTreeItem';
import { FABRIC_CLIENT_VERSION, FABRIC_NETWORK_VERSION } from '../util/ExtensionUtil';

export async function testSmartContract(allContracts: boolean, chaincode?: InstantiatedContractTreeItem | ContractTreeItem): Promise<void> {
export async function testSmartContract(allContracts: boolean, chaincode?: InstantiatedTreeItem | ContractTreeItem): Promise<void> {

let chaincodeLabel: string;
let chosenChaincode: IBlockchainQuickPickItem<{ name: string, channel: string, version: string }>;
Expand Down Expand Up @@ -82,7 +82,7 @@ export async function testSmartContract(allContracts: boolean, chaincode?: Insta
const connection: IFabricClientConnection = FabricConnectionManager.instance().getConnection();

let transactions: Map<string, any[]> = await MetadataUtil.getTransactions(connection, chaincodeName, channelName, true);
if (transactions.size === 0) {
if (!transactions || transactions.size === 0) {
outputAdapter.log(LogType.ERROR, `Populated metadata required for generating smart contract tests, see previous error`);

return;
Expand Down
65 changes: 45 additions & 20 deletions client/src/explorer/gatewayExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { InstantiatedContractTreeItem } from './model/InstantiatedContractTreeIt
import { InstantiatedTreeItem } from './runtimeOps/InstantiatedTreeItem';
import { IFabricClientConnection } from '../fabric/IFabricClientConnection';
import { InstantiatedMultiContractTreeItem } from './model/InstantiatedMultiContractTreeItem';
import { InstantiatedUnknownTreeItem } from './model/InstantiatedUnknownTreeItem';

export class BlockchainGatewayExplorerProvider implements BlockchainExplorerProvider {

Expand All @@ -52,6 +53,8 @@ export class BlockchainGatewayExplorerProvider implements BlockchainExplorerProv

private fabricGatewayRegistry: FabricGatewayRegistry = FabricGatewayRegistry.instance();

private instantiatedChaincodeTreeItems: Array<any> = [];

constructor() {
const outputAdapter: VSCodeBlockchainOutputAdapter = VSCodeBlockchainOutputAdapter.instance();

Expand Down Expand Up @@ -103,8 +106,7 @@ export class BlockchainGatewayExplorerProvider implements BlockchainExplorerProv
const channelElement: ChannelTreeItem = element as ChannelTreeItem;

if (channelElement.chaincodes.length > 0) {
const instantiatedChaincodes: Array<InstantiatedTreeItem> = await this.createInstantiatedChaincodeTree(element as ChannelTreeItem);
this.tree.push(...instantiatedChaincodes);
this.tree = await this.createInstantiatedChaincodeTree(element as ChannelTreeItem);
}
}

Expand All @@ -120,6 +122,14 @@ export class BlockchainGatewayExplorerProvider implements BlockchainExplorerProv
}
}

if (element instanceof InstantiatedUnknownTreeItem) {
// Populate the tree with correct instantiated tree items
await this.populateInstantiatedTreeItems(element);
// Calls getChildren on channelTreeItem
await this.refresh(element.channel);
return;
}

// This won't be called before connecting to a gateway
if (element instanceof InstantiatedContractTreeItem) {
this.tree = await this.createContractTree(element as InstantiatedContractTreeItem);
Expand All @@ -131,6 +141,9 @@ export class BlockchainGatewayExplorerProvider implements BlockchainExplorerProv
}

return this.tree;
} else {
// Reset the store of instantiatedChaincodeTreeItems
this.instantiatedChaincodeTreeItems = [];
}

if (FabricConnectionManager.instance().getConnection()) {
Expand Down Expand Up @@ -221,30 +234,42 @@ export class BlockchainGatewayExplorerProvider implements BlockchainExplorerProv
private async createInstantiatedChaincodeTree(channelTreeElement: ChannelTreeItem): Promise<Array<InstantiatedTreeItem>> {
const tree: Array<InstantiatedTreeItem> = [];

for (const instantiatedChaincode of channelTreeElement.chaincodes) {
const connection: IFabricClientConnection = FabricConnectionManager.instance().getConnection();
const contracts: Array<string> = await MetadataUtil.getContractNames(connection, instantiatedChaincode.name, channelTreeElement.label);
if (!contracts) {
tree.push(new InstantiatedChaincodeTreeItem(this, instantiatedChaincode.name, channelTreeElement, instantiatedChaincode.version, vscode.TreeItemCollapsibleState.None, contracts, true));
continue;
}

if (contracts.length === 0) {
const collapsedState: vscode.TreeItemCollapsibleState = vscode.TreeItemCollapsibleState.None;
tree.push(new InstantiatedContractTreeItem(this, instantiatedChaincode.name, channelTreeElement, instantiatedChaincode.version, collapsedState, contracts, true));

} else if (contracts.length === 1) {
const collapsedState: vscode.TreeItemCollapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
tree.push(new InstantiatedContractTreeItem(this, instantiatedChaincode.name, channelTreeElement, instantiatedChaincode.version, collapsedState, contracts, true));
for (const chaincode of channelTreeElement.chaincodes) {
// Is the chaincode in the this.instantiatedChaincodeTreeItems store?
const index: number = this.instantiatedChaincodeTreeItems.findIndex((treeItem: any) => {
return `${chaincode.name}@${chaincode.version}` === treeItem.label;
});
if (index !== -1) {
// Push the stored tree item to the tree
tree.push(this.instantiatedChaincodeTreeItems[index]);
} else {
const collapsedState: vscode.TreeItemCollapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
tree.push(new InstantiatedMultiContractTreeItem(this, instantiatedChaincode.name, channelTreeElement, instantiatedChaincode.version, collapsedState, contracts, true));
// Chaincode isn't stored
// Populate tree with generic instantiatedUnknownTreeItem and type them properly when vscode calls getTreeItem on each one
tree.push(new InstantiatedUnknownTreeItem(this, chaincode.name, channelTreeElement, chaincode.version, vscode.TreeItemCollapsibleState.Collapsed, undefined, true));
}
}

return tree;
}

private async populateInstantiatedTreeItems(unknownTreItem: InstantiatedUnknownTreeItem): Promise<void> {
// Determine contracts for each instantiated chaincode and properly assign element
const connection: IFabricClientConnection = FabricConnectionManager.instance().getConnection();
const contracts: Array<string> = await MetadataUtil.getContractNames(connection, unknownTreItem.name, unknownTreItem.channel.label);
let newElement: BlockchainTreeItem;
if (!contracts) {
newElement = new InstantiatedChaincodeTreeItem(this, unknownTreItem.name, unknownTreItem.channel, unknownTreItem.version, vscode.TreeItemCollapsibleState.None, contracts, true);
} else if (contracts.length === 0) {
newElement = new InstantiatedContractTreeItem(this, unknownTreItem.name, unknownTreItem.channel, unknownTreItem.version, vscode.TreeItemCollapsibleState.None, contracts, true);
} else if (contracts.length === 1) {
newElement = new InstantiatedContractTreeItem(this, unknownTreItem.name, unknownTreItem.channel, unknownTreItem.version, vscode.TreeItemCollapsibleState.Collapsed, contracts, true);
} else {
newElement = new InstantiatedMultiContractTreeItem(this, unknownTreItem.name, unknownTreItem.channel, unknownTreItem.version, vscode.TreeItemCollapsibleState.Collapsed, contracts, true);
}

// Populate and store instantiatedChaincodeTreeItems with correct tree items
this.instantiatedChaincodeTreeItems.push(newElement);
}

private async createContractTree(chainCodeElement: InstantiatedChaincodeTreeItem): Promise<Array<ContractTreeItem>> {
const tree: Array<any> = [];
for (const contract of chainCodeElement.contracts) {
Expand Down
21 changes: 21 additions & 0 deletions client/src/explorer/model/InstantiatedUnknownTreeItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

import { InstantiatedTreeItem } from './InstantiatedTreeItem';

export class InstantiatedUnknownTreeItem extends InstantiatedTreeItem {
contextValue: string = 'blockchain-instantiated-unknown-item';
}
2 changes: 1 addition & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export async function registerCommands(context: vscode.ExtensionContext): Promis
context.subscriptions.push(vscode.commands.registerCommand(ExtensionCommands.INSTANTIATE_SMART_CONTRACT, (channelTreeItem?: ChannelTreeItem, channelName?: string, peerNames?: Array<string>) => instantiateSmartContract(channelTreeItem, channelName, peerNames)));
context.subscriptions.push(vscode.commands.registerCommand(ExtensionCommands.EDIT_GATEWAY, (treeItem: GatewayTreeItem) => editGatewayCommand(treeItem)));
context.subscriptions.push(vscode.commands.registerCommand(ExtensionCommands.TEST_ALL_SMART_CONTRACT, (chaincode: InstantiatedContractTreeItem) => testSmartContract(true, chaincode)));
context.subscriptions.push(vscode.commands.registerCommand(ExtensionCommands.TEST_SMART_CONTRACT, (contract: ContractTreeItem) => testSmartContract(false, contract)));
context.subscriptions.push(vscode.commands.registerCommand(ExtensionCommands.TEST_SMART_CONTRACT, (treeItem: ContractTreeItem | InstantiatedTreeItem) => testSmartContract(false, treeItem)));
context.subscriptions.push(vscode.commands.registerCommand(ExtensionCommands.SUBMIT_TRANSACTION, (transactionTreeItem?: InstantiatedTreeItem | TransactionTreeItem, channelName?: string, smartContract?: string) => submitTransaction(false, transactionTreeItem, channelName, smartContract)));
context.subscriptions.push(vscode.commands.registerCommand(ExtensionCommands.EVALUATE_TRANSACTION, (transactionTreeItem?: InstantiatedTreeItem | TransactionTreeItem, channelName?: string, smartContract?: string) => submitTransaction(true, transactionTreeItem, channelName, smartContract)));
context.subscriptions.push(vscode.commands.registerCommand(ExtensionCommands.UPGRADE_SMART_CONTRACT, (instantiatedChainCodeTreeItem?: InstantiatedTreeItem, channelName?: string, peerNames?: Array<string>) => upgradeSmartContract(instantiatedChainCodeTreeItem, channelName, peerNames)));
Expand Down
17 changes: 14 additions & 3 deletions client/test/commands/submitTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { ExtensionCommands } from '../../ExtensionCommands';
import { VSCodeBlockchainDockerOutputAdapter } from '../../src/logging/VSCodeBlockchainDockerOutputAdapter';
import { InstantiatedContractTreeItem } from '../../src/explorer/model/InstantiatedContractTreeItem';
import { InstantiatedChaincodeTreeItem } from '../../src/explorer/model/InstantiatedChaincodeTreeItem';
import { InstantiatedUnknownTreeItem } from '../../src/explorer/model/InstantiatedUnknownTreeItem';

chai.use(sinonChai);
chai.should();
Expand Down Expand Up @@ -223,10 +224,15 @@ describe('SubmitTransactionCommand', () => {

const channelChildren: Array<BlockchainTreeItem> = await blockchainGatewayExplorerProvider.getChildren(myChannel) as Array<BlockchainTreeItem>;

const instantiatedChainCodes: Array<InstantiatedContractTreeItem> = await blockchainGatewayExplorerProvider.getChildren(channelChildren[0]) as Array<InstantiatedContractTreeItem>;
instantiatedChainCodes.length.should.equal(1);
const instantiatedUnknownChainCodes: Array<InstantiatedUnknownTreeItem> = await blockchainGatewayExplorerProvider.getChildren(channelChildren[0]) as Array<InstantiatedUnknownTreeItem>;
instantiatedUnknownChainCodes.length.should.equal(1);

await blockchainGatewayExplorerProvider.getChildren(instantiatedUnknownChainCodes[0]);

const instantiatedContractTreeItems: Array<InstantiatedContractTreeItem> = await blockchainGatewayExplorerProvider.getChildren(channelChildren[0]) as Array<InstantiatedContractTreeItem>;
instantiatedContractTreeItems.length.should.equal(1);

const transactions: Array<TransactionTreeItem> = await blockchainGatewayExplorerProvider.getChildren(instantiatedChainCodes[0]) as Array<TransactionTreeItem>;
const transactions: Array<TransactionTreeItem> = await blockchainGatewayExplorerProvider.getChildren(instantiatedContractTreeItems[0]) as Array<TransactionTreeItem>;
transactions.length.should.equal(3);

await vscode.commands.executeCommand(ExtensionCommands.SUBMIT_TRANSACTION, transactions[0]);
Expand All @@ -245,6 +251,11 @@ describe('SubmitTransactionCommand', () => {

const channelChildren: Array<BlockchainTreeItem> = await blockchainGatewayExplorerProvider.getChildren(myChannel) as Array<BlockchainTreeItem>;

const instantiatedUnknownChainCodes: Array<InstantiatedUnknownTreeItem> = await blockchainGatewayExplorerProvider.getChildren(channelChildren[0]) as Array<InstantiatedUnknownTreeItem>;
instantiatedUnknownChainCodes.length.should.equal(1);

await blockchainGatewayExplorerProvider.getChildren(instantiatedUnknownChainCodes[0]);

const instantiatedChainCodes: Array<InstantiatedChaincodeTreeItem> = await blockchainGatewayExplorerProvider.getChildren(channelChildren[0]) as Array<InstantiatedChaincodeTreeItem>;
instantiatedChainCodes.length.should.equal(1);

Expand Down
Loading

0 comments on commit a3f6aef

Please sign in to comment.