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

Commit

Permalink
Update Debug (#1130)
Browse files Browse the repository at this point in the history
kill the chaincode container if running
move instantiate and upgrade to when play is pressed
update readme

closes #1118

Signed-off-by: Caroline Fletcher <caroline.fletcher@uk.ibm.com>
  • Loading branch information
cazfletch authored and Jakeeyturner committed Jul 17, 2019
1 parent 08a193b commit 959121c
Show file tree
Hide file tree
Showing 29 changed files with 919 additions and 551 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,19 @@ To debug your smart contract follow these steps:
1. Ensure you are connected to the `local_fabric` runtime and that the `local_fabric` peer is in development mode. Development mode is indicated by an infinity symbol on a peer, under `Nodes` in the `Local Fabric Ops` panel. To toggle development mode, right-click the peer and select `Toggle Development Mode`. By toggling development mode, transactions will now have a large timeout value.
2. Open your smart contract project in your workspace.
3. Open the debug view in Visual Studio Code using the left-hand navigation bar.
4. Select the `Debug Smart Contract` configuration by using the dropdown in the upper-left and click the **play** button on the debug toolbar.
5. Select `Instantiate Smart Contract` from the blockchain icon on the debug toolbar. This action will package, install and instantiate a debug version of the selected smart contract. If there is a version of the selected smart contract already instantiated, select `Upgrade Smart Contract`.
6. Add breakpoints to the smart contract by clicking on the relevant line numbers in your smart contract files.
7. To submit or evaluate a transaction, click the blockchain icon on the debug toolbar. Alternatively, in the `Fabric Gateways` panel, you can right click on transactions to submit or evaluate them. Execution will be paused on any breakpoints you've defined.
4. Select the `Debug Smart Contract` configuration by using the dropdown in the upper-left and click the **play** button on the debug toolbar. The extension will automatically instantiate or upgrade the smart contract as appropriate. If you want to test out a function that is called on instantiate or upgrade add the following to the launch configuration, where `name` is the name of the smart contract and `version` is different to the previous version used. Alternatively if you are using JavaScript or TypeScript then you can update the `version` in the package.json file.

To make iterative changes to your smart contract while debugging, after making your changes click the **restart** button. You can also stop the debugging session, make futher changes and start debugging again, without needing to upgrade your smart contract. Please note, as this stores the smart contract in local memory, for many changes to large smart contracts, you may need to reinstantiate the smart contract. If you restart the `local_fabric` runtime after stopping a debugging session, you must select `Upgrade Smart Contract` by clicking the blockchain icon on the debug toolbar. This will install a new `vscode-debug-XXXXXXX` version of your smart contract, which then allows you to continue submitting and debugging transactions.
```
"env": {
"CORE_CHAINCODE_ID_NAME": <name>:<version>
}
```

5. Add breakpoints to the smart contract by clicking on the relevant line numbers in your smart contract files.
6. To submit or evaluate a transaction, click the blockchain icon on the debug toolbar. Alternatively, in the `Fabric Gateways` panel, you can right click on transactions to submit or evaluate them. Execution will be paused on any breakpoints you've defined.

#### Making changes to your contract while debugging
To make iterative changes to your smart contract while debugging, after making your changes click the **restart** button. You can also stop the debugging session, make further changes and start debugging again, without needing to upgrade your smart contract.

### Add a gateway for connecting to your own Hyperledger Fabric instance
To connect to our own Hyperledger Fabric instance, it must be running [Hyperledger Fabric v1.4.1](https://hyperledger-fabric.readthedocs.io/en/release-1.4/install.html) or later.
Expand Down
20 changes: 19 additions & 1 deletion client/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,25 @@
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
}, {
},
{
"name": "Debug Unit Tests (no coverage)",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch",
"env": {
"WITHOUTCOVERAGE": "true"
}
},
{
"name": "Node Integration Tests",
"type": "extensionHost",
"request": "launch",
Expand Down
17 changes: 12 additions & 5 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@ To debug your smart contract follow these steps:
1. Ensure you are connected to the `local_fabric` runtime and that the `local_fabric` peer is in development mode. Development mode is indicated by an infinity symbol on a peer, under `Nodes` in the `Local Fabric Ops` panel. To toggle development mode, right-click the peer and select `Toggle Development Mode`. By toggling development mode, transactions will now have a large timeout value.
2. Open your smart contract project in your workspace.
3. Open the debug view in Visual Studio Code using the left-hand navigation bar.
4. Select the `Debug Smart Contract` configuration by using the dropdown in the upper-left and click the **play** button on the debug toolbar.
5. Select `Instantiate Smart Contract` from the blockchain icon on the debug toolbar. This action will package, install and instantiate a debug version of the selected smart contract. If there is a version of the selected smart contract already instantiated, select `Upgrade Smart Contract`.
6. Add breakpoints to the smart contract by clicking on the relevant line numbers in your smart contract files.
7. To submit or evaluate a transaction, click the blockchain icon on the debug toolbar. Alternatively, in the `Fabric Gateways` panel, you can right click on transactions to submit or evaluate them. Execution will be paused on any breakpoints you've defined.
4. Select the `Debug Smart Contract` configuration by using the dropdown in the upper-left and click the **play** button on the debug toolbar. The extension will automatically instantiate or upgrade the smart contract as appropriate. If you want to test out a function that is called on instantiate or upgrade add the following to the launch configuration, where `name` is the name of the smart contract and `version` is different to the previous version used. Alternatively if you are using JavaScript or TypeScript then you can update the `version` in the package.json file.

To make iterative changes to your smart contract while debugging, after making your changes click the **restart** button. You can also stop the debugging session, make futher changes and start debugging again, without needing to upgrade your smart contract. Please note, as this stores the smart contract in local memory, for many changes to large smart contracts, you may need to reinstantiate the smart contract. If you restart the `local_fabric` runtime after stopping a debugging session, you must select `Upgrade Smart Contract` by clicking the blockchain icon on the debug toolbar. This will install a new `vscode-debug-XXXXXXX` version of your smart contract, which then allows you to continue submitting and debugging transactions.
```
"env": {
"CORE_CHAINCODE_ID_NAME": <name>:<version>
}
```

5. Add breakpoints to the smart contract by clicking on the relevant line numbers in your smart contract files.
6. To submit or evaluate a transaction, click the blockchain icon on the debug toolbar. Alternatively, in the `Fabric Gateways` panel, you can right click on transactions to submit or evaluate them. Execution will be paused on any breakpoints you've defined.

#### Making changes to your contract while debugging
To make iterative changes to your smart contract while debugging, after making your changes click the **restart** button. You can also stop the debugging session, make further changes and start debugging again, without needing to upgrade your smart contract.

### Add a gateway for connecting to your own Hyperledger Fabric instance
To connect to our own Hyperledger Fabric instance, it must be running [Hyperledger Fabric v1.4.1](https://hyperledger-fabric.readthedocs.io/en/release-1.4/install.html) or later.
Expand Down
4 changes: 2 additions & 2 deletions client/cucumber/helpers/smartContractHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class SmartContractHelper {
}
});

this.userInputUtilHelper.inputBoxStub.withArgs('optional: What function do you want to call?').resolves(transaction);
this.userInputUtilHelper.inputBoxStub.withArgs('optional: What function do you want to call on instantiate?').resolves(transaction);
this.userInputUtilHelper.inputBoxStub.withArgs('optional: What are the arguments to the function, (comma seperated)').resolves(args);

this.userInputUtilHelper.showYesNoQuickPick.resolves(UserInputUtil.NO);
Expand Down Expand Up @@ -228,7 +228,7 @@ export class SmartContractHelper {
data: { name: name, channel: 'mychannel', version: '0.0.1' }
});

this.userInputUtilHelper.inputBoxStub.withArgs('optional: What function do you want to call?').resolves(transaction);
this.userInputUtilHelper.inputBoxStub.withArgs('optional: What function do you want to call on upgrade?').resolves(transaction);
this.userInputUtilHelper.inputBoxStub.withArgs('optional: What are the arguments to the function, (e.g. ["arg1", "arg2"])', '[]').resolves(args);

this.userInputUtilHelper.showYesNoQuickPick.resolves(UserInputUtil.NO);
Expand Down
4 changes: 2 additions & 2 deletions client/integrationTest/integrationTestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class IntegrationTestUtil {
}
});

this.inputBoxStub.withArgs('optional: What function do you want to call?').resolves(transaction);
this.inputBoxStub.withArgs('optional: What function do you want to call on instantiate?').resolves(transaction);
this.inputBoxStub.withArgs('optional: What are the arguments to the function, (e.g. ["arg1", "arg2"])', '[]').resolves(args);

this.showYesNoQuickPick.resolves(UserInputUtil.NO);
Expand Down Expand Up @@ -331,7 +331,7 @@ export class IntegrationTestUtil {
data: { name: name, channel: 'mychannel', version: '0.0.1' }
});

this.inputBoxStub.withArgs('optional: What function do you want to call?').resolves('');
this.inputBoxStub.withArgs('optional: What function do you want to call on upgrade?').resolves('');
this.inputBoxStub.withArgs('optional: What are the arguments to the function, (e.g. ["arg1", "arg2"])', '[]').resolves('');

this.showYesNoQuickPick.resolves(UserInputUtil.NO);
Expand Down

0 comments on commit 959121c

Please sign in to comment.