Debug & Publish
Debugging and publishing Sui contracts
Debug
There is no debugger for Move currently. To aid with debugging, you can use the std::debug
module to print out arbitrary values.
Alternatively, any call to abort
or assertion failure also prints the stacktrace at the point of failure.
You must remove all calls to functions in the debug
module from no-test code before you can publish the new module (test code is marked with the #[test]
annota
Publish
For functions in a Sui Move package to actually be callable from Sui (rather than an emulated Sui execution scenario), you have to publish the package to the Sui distributed ledger, where it is represented as an immutable Sui object.
At this point, however, the sui move
command does not support package publishing. In fact, it is not clear if it even makes sense to accommodate package publishing, which happens once per package creation, in the context of a unit testing framework. Instead, you can use the Sui CLI client to publish Move code and to call that code. See the Sui CLI client documentation for information on how to publish the package created in this tutorial.
Module Initialisers
Each module in a package can include a special initializer function that runs at publication time. The goal of an initializer function is to pre-initialize module-specific data (to create singleton objects). The initializer function must have the following properties for it to execute at publication:
Function name must be
init
A single parameter of
&mut TxContext
typeNo return values
Private visibility
While the sui move
command does not support publishing explicitly, you can still test module initializers using the testing framework by dedicating the first transaction to executing the initializer function.
Continuing the fantasy game example, the init
function should create a Forge
object.
The tests so far call the init
function, but the initializer function itself isn't tested to ensure it properly creates a Forge
object. To test this functionality, modify the sword_create
function to take the forge as a parameter and to update the number of created swords at the end of the function:
Create a function to test the module initialization:
Last updated