Post
Share your knowledge.
How to test a function with a Receiving parameter in Sui?
I'm trying to test the receive_object
function with a Receiving
parameter in Sui based on the docs at this link. Initially, I created a test using the example, but I'm struggling with how to get the sent argument to be a Receiving
type. I've also tried denoting the receiving type, but encountered errors. Could someone guide me on properly testing this function?
- Move CLI
- Move
Answers
4If you are still facing issues with denoting the Receiving
type in your tests, it might be helpful to test using the SUI CLI. With the CLI, you can easily specify type arguments using the --type-args
flag, which could simplify your testing scenario.
In some test scenarios, transferring objects directly as shared might not work as intended, especially if you get errors related to instantiation rights. Adjusting the way transactions are structured to facilitate object sharing initially, before attempting public receipt, could resolve these issues.
You may first need to structure your test in a way that transfers the object to the SharedObject
using one TransactionBlock. In a subsequent TransactionBlock, you can call the module function for accepting, i.e., the function with Receiving<T>
. This approach ensures that the object is first appropriately shared before attempting to receive it.
When transferring an object, using the public_transfer
method is correct if you intend to give full ownership to the object, even if you are not specifically transferring it to a SharedObject
. Both methods suit different use cases, so make sure you're using the one that aligns with your objective.
Do you know the answer?
Please log in and share it.
Move is an executable bytecode language used to implement custom transactions and smart contracts.