From 92fe6542db6a5bf4ce5eb0a64aae1d0514c7fdd4 Mon Sep 17 00:00:00 2001 From: Adam Welc Date: Wed, 11 May 2022 10:50:44 -0700 Subject: [PATCH] [Move] Fixed test function calling entry functino and updated docs (#1653) --- doc/src/build/move.md | 19 ++++++++----------- sui_programmability/tutorial/sources/M1.move | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/doc/src/build/move.md b/doc/src/build/move.md index f9fc53c4d4953..793c562deb283 100644 --- a/doc/src/build/move.md +++ b/doc/src/build/move.md @@ -37,9 +37,7 @@ In Sui, Move is used to define, create and manage programmable Sui imposes additional restrictions on the code that can be written in Move, effectively using a subset of Move (a.k.a. *Sui Move*), which makes certain parts of the original Move documentation not applicable -to smart contract development in Sui (e.g., there is no concept of a -[script](https://github.com/diem/move/blob/main/language/documentation/book/src/modules-and-scripts.md#scripts) -in Sui Move). Consequently, it's best to simply follow this tutorial +to smart contract development in Sui. Consequently, it's best to simply follow this tutorial and relevant Move documentation links provided in the tutorial. Before we look at the Move code included with Sui, let's talk briefly @@ -254,13 +252,10 @@ that it will do what it is intended to do.) In general, an entry function, must satisfy the following properties: -- be public +- have `public(script)` visibility modifier - have no return value -- have parameters ordered as follows: - - one or more Sui objects (or vectors of objects) - - one or more primitive types (or vectors of such types) - - a mutable reference to an instance of the `TxContext` struct - defined in the [TxContext module](https://github.com/MystenLabs/sui/tree/main/sui_programmability/framework/sources/TxContext.move) +- have a mutable reference to an instance of the `TxContext` struct + defined in the [TxContext module](https://github.com/MystenLabs/sui/tree/main/sui_programmability/framework/sources/TxContext.move) as the last parameter More, concretely, the `transfer` function is public, has no return value, and has three parameters: @@ -659,11 +654,13 @@ struct available for function definitions: We can now build the module extended with the new functions but still have only one test defined. Let us change that by adding another test -function: +function. Note that this function needs to have `public(script)` +visibility modifier to be able to call other functions with the same +modifier, such as our entry function `sword_create`. ``` rust #[test] - public fun test_sword_transactions() { + public(script) fun test_sword_transactions() { use Sui::TestScenario; let admin = @0xABBA; diff --git a/sui_programmability/tutorial/sources/M1.move b/sui_programmability/tutorial/sources/M1.move index 2aab9086c0e97..e118d67a1cf5a 100644 --- a/sui_programmability/tutorial/sources/M1.move +++ b/sui_programmability/tutorial/sources/M1.move @@ -87,7 +87,7 @@ module MyFirstPackage::M1 { } #[test] - public fun test_sword_transactions() { + public(script) fun test_sword_transactions() { use Sui::TestScenario; // create test addresses representing users