Search…
Testing your Smart Trigger
This feature is currently under development for our new UI!

Overview

After you finished writing custom ParsiQL code for your Smart Trigger, you might be tempt to test it before deploying. The TEST feature located in the Smart Trigger code editor can help you understand if the ParsiQL code is right and will run without error.
Note that this TEST function will not send you any notifications or data through your Delivery Channels nor it will use your plan’s actions.

Smart Trigger with Native Streams

Setting up the sample transaction

When pressed, you will be greeted with a Trigger Testing pop-up with Sample Transaction.
This Sample Transaction contains all the information of a transaction you want to test your Smart Trigger with.
Default Sample Transaction for Ethereum (left) and BSC Smart Trigger
Before pressing TEST you need to change the fields so the sample transaction would match with the conditions you wrote in your Smart Trigger code. For example, check the following BSC Smart Trigger code:
stream TestingCode
from BscBEP20Transfers
where @to == BSC.address("0x0000000000000000000000000000000123456789")
process
let txInfo = { txHash: @transaction.hash }
if @to == BSC.address("0x0000000000000000000000000000000123456789") && @value >= 8000000000000000000 && @token.symbol == "TestToken" then
let transfer_type = "deposit"
emit { @from, @to, @value, txInfo, symbol: @token.symbol, decimals: @token.decimals, transfer_type }
end
end
Based on that code, we need to make sure that the sample transaction must have following fields changed:
  • The "to" address must be "0x0000000000000000000000000000000123456789"
  • The "value" must be more than or equal to 8000000000000000000
  • The "token" "symbol" must be "TestToken"
When finished editing the fields you need, press TEST then switch to CONSOLE tab. It should automatically go to testing part of the console. If everything was correct, There you’ll see JSON string that your Smart Trigger produced, containing everything that you chose to emit.
JSON string of a correctly tested Smart Trigger

Smart Trigger with User Streams

Creating the sample transaction

The main difference between testing a Smart Trigger with User Defined Streams and Native Streams is that you need to provide your own "transaction sample".
When writing one, you need to have these fields:
  • contractEventStream
  • event(or function),
  • contract
  • transaction
  • block
  • topics
  • parsedData
  • data
  • all event/function components

contractEventStream

For demonstration, let's say I want to monitor an ETH contract event called AdminChangedand saved this user stream as TEST. So automatically our Stream is called ETH_TEST_AdminChanged_Events in code editor.
contractEventStream must have the same name as your User Defined Stream

event / function

Since we are monitoring an event called AdminChanged, we need to fill this field as AdminChanged

contract

contract must have an address of a contract that you are monitoring

transaction, block, topics, parsedData and data

These fields are just a technicality. For ease of use, you can add this block of JSON to your transaction sample:
"parsedData":"anything",
"topics":[],
"data":"0x"
"block":
{
"hash": "0x2741e5e7e71f2f4f6374ad487171c08161fc917b097cac4ec329097f605ee3ba",
"number": "9308070",
"timestamp": "1631876485",
"parentHash": "0xc80632e0e8e9e84889f3430c86d997bfcec594003ad173fdb7b7dac79f14ec65"
},
"transaction":
{
"hash": "0x8e886ef79a7e53a8422c485b5f89b1f51c060f8801b9f6fe68200feecd3c7476",
"index": "1",
"origin": "0x0e1401b7037163764b161fd989bdcf224bb5dcc4",
"blockHash": "0x2741e5e7e71f2f4f6374ad487171c08161fc917b097cac4ec329097f605ee3ba"
}

Event/Functions components

To see what components does your stream have, press < to the right of Save, Deploy and Test buttons and Stream explorer will appear.
In our example, AdminChanged event has several components: previousAdmin and newAdmin which are address'eth' type. If you need these components (i.e. you are emitting them in your code), you must add them in your transaction sample.

Sample Transaction sample

After everything, your Sample Transaction should look something like this:
{
"contractEventStream": "ETH_TEST_AdminChanged_Events",
"event": "AdminChanged",
"parsedData": "anything"
"topics":[],
"data":"0x",
"contract": "0xContractAddress",
"previousAdmin": "0xccf6c29d87eb2c0bafede74f5df35f84541f4549",
"newAdmin": "0x87b675e9219a3b870df51449268b8c8c2241bf0c",
"block":
{
"hash": "0x2741e5e7e71f2f4f6374ad487171c08161fc917b097cac4ec329097f605ee3ba",
"number": "9308070",
"timestamp": "1631876485",
"parentHash": "0xc80632e0e8e9e84889f3430c86d997bfcec594003ad173fdb7b7dac79f14ec65"
},
"transaction":
{
"hash": "0x8e886ef79a7e53a8422c485b5f89b1f51c060f8801b9f6fe68200feecd3c7476",
"index": "1",
"origin": "0x0e1401b7037163764b161fd989bdcf224bb5dcc4",
"blockHash": "0x2741e5e7e71f2f4f6374ad487171c08161fc917b097cac4ec329097f605ee3ba"
}
}
After that, go to your Smart Trigger's console and there you should see everything you emitted with your Smart Trigger :)
Last modified 8mo ago
Copy link
On this page
Overview
Smart Trigger with Native Streams
Setting up the sample transaction
Smart Trigger with User Streams
Creating the sample transaction
Sample Transaction sample