Test Your Chaincode Using Visual Studio Code
If your chaincode is running on a network, you can test any of the generated methods. Additionally, If you chose to create the executeQuery
method during your chaincode development, you can run SQL rich queries if your chaincode is deployed to an Oracle Blockchain Platform network.
Test Your Chaincode on a Local Hyperledger Fabric Network
Once your chaincode project is running on a local network, you can test it.
Blockchain App Builder contains a built-in wizard to assist you with invoking or querying your chaincode.
- Select your chaincode project in the Chaincodes pane. In the Chaincode Details pane, select Execute. The chaincode name should already be selected. Ensure the target environment is set to Local Environment and the channel will default to the only channel available.
- In the Function field, select your method from the drop-down list. Every method available in the chaincode is listed.
- In the Function Param field, select the More Actions (…) button. This will launch a window with available properties for your selected method. Enter the properties, click Omit for any non-mandatory property you don't want submitted when you invoke your method, and click Save.
- Click Invoke.
The Output console window will show that the function has been invoked. Alternatively, in the Chaincode Actions pane, the Function Output window displays the output. Click the More Actions (…) button to see this output formatted.
If you want to save the method and parameters you just ran, you can click Save and enter a name and description for it. It will be saved in your chaincode project in the Queries
folder. To use it again, right-click it and select Open.
If you make any changes to the controller file that would alter the methods, select the Reload icon at the top of the Chaincode Execute pane. The change should now be reflected in the Function drop-down list.
Note:
If you don't want to use the wizard for testing, you can also run the Blockchain App Builder command line tools in the Visual Studio Code Terminal window. Follow the instructions provided here to test with the command line: Test Your Chaincode on a Local Hyperledger Fabric Network.Automatic Install and Instantiate After Update
Whenever you update and save your chaincode, the changes will be compiled, installed and instantiated automatically. There is no need to strip down or bring up the local network again. All projects will be automatically compiled and deployed on every change.
Testing Lifecycle Operations on a Remote Oracle Blockchain Platform Network
Once your chaincode project has successfully deployed to your remote Oracle Blockchain Platform network, you can test it as described in Test Your Chaincode on a Local Hyperledger Fabric Network.
You can use the same invoke and query commands to perform all method transactions on a remote Oracle Blockchain Platform Cloud or Enterprise Edition network; everything supported on the local network is also supported on the remote network. Simply select the Oracle Blockchain Platform instance as your target environment when executing your tests.
Execute Berkeley DB SQL Rich Queries
If you chose to create the executeQuery
method during your chaincode development, you can run SQL rich queries if your chaincode is deployed to an Oracle Blockchain Platform network.
If you have used executeQuery
in the customMethods
section of the specification file, a corresponding executeQuery
method will be created in the controller.
customMethods:
- executeQuery
- "fetchRawMaterial(supplierid: string, rawMaterialSupply: number)"
- "getRawMaterialFromSupplier(manufacturerId: string, supplierld: string, rawMaterialSupply: number)"
- "createProducts(manufacturerId: string, rawMaterialConsumed: number, productsCreated: number)"
- "sendProductsToDistribution()"
**
*
* BDB sql rich queries can be executed in OBP CS/EE.
* This method can be invoked only when connected to remote OBP CS/EE network.
*
*/
@Validator(yup.string())
public async executeQuery(query: string) {
const result = await OchainController.query(query);
return result;
}
You can invoke this method to execute Berkeley DB SQL rich queries on Oracle Blockchain Platform network, ensuring that you select the Oracle Blockchain Platform environment that you created as your target environment when running the queries.
- In the Chaincode Details pane, select Execute. The chaincode name, target environment, and channel should already be pre-filled from the deployment step.
- In the Function Name field, select
executeQuery
from the drop-down list. - In the Function Param field, select the More Actions (…) button. This will launch a window where you can enter the query string. Enter the arguments for your query, and click Save.
- Click Query.
> ochain query executeQuery "SELECT key, valueJson FROM <STATE> WHERE
json_extract(valueJson, '$.rawMaterialAvailable') = 4"
The entire SQL query is taken in the argument, so you can make changes to your query on the fly.