Debug & Publish
Debugging and publishing Sui contracts
Last updated
Debugging and publishing Sui contracts
Last updated
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.
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 , 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 Move code and to that code. See the for information on how to publish the package created in this tutorial.
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
type
No 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: