You can use the invokeScript method provided by Neo-CLI for testing.
Testing tool
A test is initiated by a POST request. This section we use a common POST tool POSTMAN to do the testing. You can write a POST tool for testing as well.
After compiling your smart contract and getting the related script hash, you can use POSTMAN to test by following these steps:
Configure the CLI address. Select POST in the list and enter the RPC interface address of Neo-CLI.
Select raw and JSON , and configure as follows:
Replace the string in params with the script hash of the smart contract to test. Click Send to start a testing. See the figure below:
Example 1 - Testing a contract without parameters
Write the following code and save the generated .avm file as d:\\1.avm .
Create an netcore project and import the Neo project.
Write the following code to obtain the smart contract script hash:
After running above code you can get the contract script: “52c56b6c766b00527ac461516c766b51527ac46203006c766b51c3616c7566”.
Use postman to test, as shown below:
"state": The value "HALT, BREAK" indicates the test is successful.
Stack is the value left on the Stack, which is the bytearray corresponding to the string "Hello, World!".
Example 2 - Testing a contract with parameters
Write the following code and save the generated .avm file as d:\\2.avm 。
Write the following code for testing:
Use PostMan to test:
Example 3 - Testing a contract deployed on the blockchain
Majority of steps are similar. Refer to the first two examples.