assert_events

(alias) function assert_events(expected: (text, gtv)...)

Assert that the given events were emitted during the construction of the last block, in the specified order.

Events are emitted in application code using op_context.emit_event().

Example - single event:

Application code
operation main() {
op_context.emit_event("my_message_type", "my_data".to_gtv());
}
Test code
function test_main() {
main().run();

// Assertion passes
rell.test.assert_events(("my_message_type", "my_data".to_gtv()));
}

function test_main_bad_1() {
main().run();

// Assertion fails - wrong message type
rell.test.assert_events(("other_message_type", "my_data".to_gtv()));
}

function test_main_bad_2() {
main().run();

// Assertion fails - wrong message content
rell.test.assert_events(("my_message_type", "other_data".to_gtv()));
}

Example - multiple events:

Application code
operation main() {
op_context.emit_event("my_message_type", "my_data".to_gtv());
op_context.emit_event("other_message_type", "other_data".to_gtv());
}
Test code
function test_main() {
main().run();

// Assertion passes
rell.test.assert_events(
("my_message_type", "my_data".to_gtv()),
("other_message_type", "other_data".to_gtv())
);
}

function test_main_bad() {
main().run();

// Assertion fails - event order incorrect
rell.test.assert_events(
("other_message_type", "other_data".to_gtv()),
("my_message_type", "my_data".to_gtv())
);
}

To assert a subset of events, or to assert independently of event order, use rell.test.get_events() and make assertions over elements of the returned list.

Alias

Since

0.13.0

Parameters

expected

expected event sequence

See also