From 4742546432680af246763d127a20733ccf9b8fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Lillo=20Igualada?= Date: Fri, 20 Jan 2023 17:25:54 +0100 Subject: [PATCH] Include in docs how to check events --- docs/send-transactions.md | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/send-transactions.md b/docs/send-transactions.md index e4de9504..04a843ce 100644 --- a/docs/send-transactions.md +++ b/docs/send-transactions.md @@ -119,3 +119,46 @@ const main = async () => { main() ``` +## Transaction result + +As showed before, the result of sending a transaction can be captured on a variable or constant, allowing you to access its result and any errors that may occur. This can be specially interesting for testing the behavior of any events that were emitted during the execution of the transaction. + +### Checking events + +The `events` object array can be found inside the result object, following the previous example: + +``` + const [result, error, logs] = await shallPass( + sendTransaction("log-message", [], args) + ) + console.log({result}) +``` +The console output will be: +``` + { + blockId: '', + status: 4, + statusString: 'SEALED', + statusCode: 0, + errorMessage: '', + events: [ [Object] ] + } +``` + +And if we dig a little further on the events object: +``` +console.log({result.events}) +``` +We will get the array containing the emitted events, that will look something like this: +``` + [ + { + type: 'eventType', + transactionId: 'txId', + transactionIndex: 1, + eventIndex: 0, + data: {} + } + ] +``` +Most times you will want to access the `data` object inside each emitted event to test that the info emitted matches what is expected. \ No newline at end of file