Skip to main content

rell.test.op

rell.test.op type represents a Rell operation within the Rell testing framework.

Example

A rell.test.op is instantiated by calling any user-defined operation. For example, when a user defines my_operation, it becomes a rell.test.op when called in a test.

main.rell
module;

operation my_operation(name) {}
test.rell
@test module;

import main.*;

function test() {
val my_op: rell.test.op = my_operation("foo");
}

Properties

val name: text

The name of the operation (read-only).

Returns:

  • The name of the operation as a text string.

val args: list<gtv>

The arguments of the operation (read-only). Returns a new mutable list on every read.

Returns:

  • A new mutable list of the operation's arguments on every read.

Functions

function tx(): rell.test.tx

Creates a transaction builder object containing this operation.

Parameters:

  • None

Returns:

  • rell.test.tx - transaction builder object containing this operation.

function sign(keypair: rell.test.keypair...) : rell.test.tx

Signs the transaction containing this operation. Equivalent to .tx().sign(...).

Parameters:

  • Accepts one or more keypairs to sign the transaction.

Returns:

  • rell.test.tx - the transaction builder object, allowing for method chaining.

function sign(privkey: rell.test.privkey...) : rell.test.tx

Signs the transaction containing this operation. Equivalent to .tx().sign(...).

Parameters:

  • Accepts one or more private keys to sign the transaction.

Returns:

  • rell.test.tx - the transaction builder object, allowing for method chaining.

function run(): void

Runs a block containing a transaction with this single operation. Equivalent to .tx().run().

Parameters:

  • None

Returns:

  • Nothing

function run_must_fail(expected: text? = null): rell.test.failure

Runs a block containing a transaction with this single operation and expects it to fail. If an expected message is passed, it will pass only if the failure message contains the expected message. Throws an exception on success, not on failure. Equivalent to .tx().run_must_fail().

Parameters:

  • expected (optional): Text containing the expected error message.

Returns:

  • A rell.test.failure object containing information about the failure, if the transaction fails as expected. Throws an exception if the transaction succeeds unexpectedly.

Example

operation will_fail_sometimes(will_fail: booelan) {
require(!will_fail, "This operation has failed");
}

function test_fails() {
will_fail_sometimes(false).run();
will_fail_sometimes(true).run_must_fail();
will_fail_sometimes(true).run_must_fail("has failed");
}