Skip to content
On this page

Utils

The sp.utils module contains a few helper functions. To use it, simply include it in the module list for your test scenarios, before any the other modules:

python
sp.test_scenario([sp.utils,main])

Conversion functions

utils.mutez_to_nat(x: sp.mutez) → sp.nat

Convert a sp.mutez value to a sp.nat value.

python
x = sp.mutez(3)
assert utils.mutez_to_nat(x) == sp.nat(3)

TIP

One can often avoid using utils.nat_to_mutez by storing values of type sp.mutez or by accepting sp.mutez (instead of sp.nat) values as a parameter.

utils.nat_to_mutez(x: sp.nat) → sp.mutez

Convert a sp.nat value to a sp.mutez value.

python
x = 3
assert utils.nat_to_mutez(x) == sp.mutez(3)
utils.seconds_of_timestamp(x: sp.timestamp) → sp.nat

Convert a sp.timestamp value to a sp.nat value. The returned value represents the number of seconds since the epoch.

python
x = sp.timestamp(1095379199)
assert utils.seconds_of_timestamp(x) == 1095379199