Skip to content

Test Helpers

The helpers that the tests of the library use, which it exposes as well: GenUtils, with the reconciliation of the fields that merge uses, and the comparators that sort transactions, transfers and outputs as the wallet does.

GenUtils

Bases: ABC

Collection of generic utilities.

bool_equals(val, opt_val) staticmethod

Compare a bool to an optional bool.

Parameters:

Name Type Description Default
val bool

value to compare.

required
opt_val bool | None

optional value to compare against; False if None.

required

Returns:

Type Description
bool

True if opt_val is set and equals val, False otherwise.

get_uuid() staticmethod

Return a random unique identifier.

Returns:

Type Description
str

a unique id.

reconcile_bool(val1, val2, resolve_defined=None, resolve_true=None, resolve_max=None, err_msg='') staticmethod

Reconcile two optional bools to a single value, the same logic used internally to merge model fields (e.g. MoneroTx.merge()).

  • If both are equal (including both None), returns that value.
  • If exactly one is None, returns the other, unless resolve_defined is False, in which case None is returned.
  • Otherwise, if both are set and differ: resolve_true picks whichever operand equals resolve_true; else resolve_max picks the greater (True) or lesser (False) of the two, treating True as 1 and False as 0.

Parameters:

Name Type Description Default
val1 bool | None

first value.

required
val2 bool | None

second value.

required
resolve_defined bool | None

when only one side is set and this is False, return None instead of the set side.

None
resolve_true bool | None

when both sides are set and differ, prefer whichever operand equals this value.

None
resolve_max bool | None

when both sides are set and differ (and resolve_true didn't resolve it), prefer the greater (True) or lesser (False) value.

None
err_msg str

extra context appended to the error message on conflict.

''

Returns:

Type Description
bool | None

the reconciled value.

Raises:

Type Description
RuntimeError

If none of the above resolves.

reconcile_string(val1, val2, resolve_defined=None, resolve_true=None, resolve_max=None, err_msg='') staticmethod

Reconcile two optional strings. Unlike the bool/int overloads, resolve_true/resolve_max are accepted for signature symmetry but are not used.

Parameters:

Name Type Description Default
val1 str | None

first value.

required
val2 str | None

second value.

required
resolve_defined bool | None

see reconcile_bool.

None
resolve_true bool | None

accepted but ignored.

None
resolve_max bool | None

accepted but ignored.

None
err_msg str

extra context appended to the error message on conflict.

''

Returns:

Type Description
str | None

the reconciled value.

Raises:

Type Description
RuntimeError

on different strings always regardless of resolve_true/resolve_max flags.

reconcile_string_list(v1, v2, err_msg='') staticmethod

Reconcile two string lists: equal lists are returned as-is, an empty list yields the other.

Parameters:

Name Type Description Default
v1 list[str]

first list.

required
v2 list[str]

second list.

required
err_msg str

extra context appended to the error message on conflict.

''

Returns:

Type Description
list[str]

the reconciled list.

Raises:

Type Description
RuntimeError

on two different non-empty lists.

reconcile_uint64(val1, val2, resolve_defined=None, resolve_true=None, resolve_max=None, err_msg='') staticmethod

Reconcile two optional unsigned 64-bit integers. See reconcile_bool for the resolution rules (resolve_max here picks the numeric max/min).

Parameters:

Name Type Description Default
val1 int | None

first value.

required
val2 int | None

second value.

required
resolve_defined bool | None

see reconcile_bool.

None
resolve_true bool | None

see reconcile_bool.

None
resolve_max bool | None

prefer the larger (True) or smaller (False) value.

None
err_msg str

extra context appended to the error message on conflict.

''

Returns:

Type Description
int | None

the reconciled value.

Raises:

Type Description
RuntimeError

If none of the above resolves.

wait_for(duration_ms) staticmethod

Block the calling thread for the given duration. Releases the GIL while sleeping.

Parameters:

Name Type Description Default
duration_ms int

duration to wait, in milliseconds.

required

Raises:

Type Description
TypeError

Must be a non-negative number that fits in a valid uint64_t range.

Comparators

TxHeightComparator

Compares two transactions by their height.

compare(tx1, tx2) staticmethod

Compare two transactions by height.

Unconfirmed transactions (no block) sort after confirmed ones; when both are unconfirmed or share the same height and block, their original order within the block's tx list is preserved.

Parameters:

Name Type Description Default
tx1 MoneroTx

first transaction to compare.

required
tx2 MoneroTx

second transaction to compare.

required

Returns:

Type Description
bool

True if tx1 sorts before tx2, False otherwise.

IncomingTransferComparator

Compares two incoming transfers by ascending account and subaddress indices.

compare(transfer1, transfer2) staticmethod

Compare two incoming transfers.

Compares by transaction height first (see TxHeightComparator), then by account index, then by subaddress index.

Parameters:

Name Type Description Default
transfer1 MoneroIncomingTransfer

first transfer to compare.

required
transfer2 MoneroIncomingTransfer

second transfer to compare.

required

Returns:

Type Description
bool

True if transfer1 sorts before transfer2, False otherwise.

OutputComparator

Compares two wallet outputs by ascending account, subaddress and output index.

compare(output1, output2) staticmethod

Compare two wallet outputs.

Compares by transaction height first (see TxHeightComparator), then by account index, subaddress index, output index and finally key image hex.

Parameters:

Name Type Description Default
output1 MoneroOutputWallet

first output to compare.

required
output2 MoneroOutputWallet

second output to compare.

required

Returns:

Type Description
bool

True if output1 sorts before output2, False otherwise.