Logging, Debugging & Testing
In this reference, you will learn how to log arbitry inputs in your Substreams execution, and how to create unit tests for your modules.
Using logs in Substreams
It is possible to log arbitrary strings to the standard output of the Substreams execution. You will see these logs when running your Substreams using substreams gui
or substreams run
commands.
NOTE: When using the substreams gui
command, use the L
key to toggle logs.
To log something in Rust, use one of the following functions:
OR
OR
Unit Testing
The definition of the function is a standard Substreams module, which needs the
#[substreams::handlers::map]
macro. Because of the macro, the real signature of the function is more complex than just a couple of input parameters. Therefore, to facilitate the testing, all the logic is contained inside the_filtered_events
function.
The
_filtered_events
function, which contains the real logic, is just filtering the events (events: Events
) matching the filter provided in the query (query: String
).
The
filtered_events
test is split into three parts:Given: create the inputs of the function. In this case, we are reading a full Ethereum Block from a base-64-encoded file. Later in this doc, you will learn how to generate this file.
When: the actual execution of the function. The tests will filter all the events with
address=0x5acc84a3e955bdd76467d3348077d003f00ffb97
because we know this event is contained in the input Block.Expect: there are you assertions: the number of events returned must be greater than 0; all the events returned must have the
0x5acc84a3e955bdd76467d3348077d003f00ffb97
address.
Generating the Input of the Test
The following example uses firecore
to get the 5300300
Block of Ethereum Mainnet in base64-encoded file.
Last updated
Was this helpful?