From 6ad523251e8bb75d485977c4f45438713434ac55 Mon Sep 17 00:00:00 2001 From: Damir Shamanaev Date: Tue, 27 Aug 2024 15:03:16 +0300 Subject: [PATCH 1/3] better links --- book/src/move-basics/option.md | 2 -- book/src/move-basics/standard-library.md | 23 +++++++++++++++++++ .../src/programmability/hot-potato-pattern.md | 13 ++++++----- book/src/programmability/sui-framework.md | 20 +++++++++------- .../samples/sources/move-basics/vector.move | 3 --- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/book/src/move-basics/option.md b/book/src/move-basics/option.md index 05bb052d..e39d1fb4 100644 --- a/book/src/move-basics/option.md +++ b/book/src/move-basics/option.md @@ -4,8 +4,6 @@ Option is a type that represents an optional value which may or may not exist. T in Move is borrowed from Rust, and it is a very useful primitive in Move. `Option` is defined in the [Standard Library](./standard-library.md), and is defined as follows: -File: move-stdlib/source/option.move - ```move // File: move-stdlib/source/option.move /// Abstraction of a value that may or may not be present. diff --git a/book/src/move-basics/standard-library.md b/book/src/move-basics/standard-library.md index da25e58a..21beb4a3 100644 --- a/book/src/move-basics/standard-library.md +++ b/book/src/move-basics/standard-library.md @@ -32,6 +32,29 @@ and which module implements it. +## Integer Modules + +The Move Standard Library provides a set of functions associated with integer types. These functions +are split into multiple modules, each associated with a specific integer type. The modules should +not be imported directly, but their functions are available on every integer value. + +> All of the modules provide the same set of functions. Namely, `max`, `diff`, +> `divide_and_round_up`, `sqrt` and `pow`. + + +
+ +| Module | Description | +| ---------------------------------------------------------------------- | ----------------------------- | +| [std::u8](https://docs.sui.io/references/framework/move-stdlib/u8) | Functions for the `u8` type | +| [std::16](https://docs.sui.io/references/framework/move-stdlib/u64) | Functions for the `u16` type | +| [std::u32](https://docs.sui.io/references/framework/move-stdlib/u64) | Functions for the `u32` type | +| [std::u64](https://docs.sui.io/references/framework/move-stdlib/u64) | Functions for the `u64` type | +| [std::u128](https://docs.sui.io/references/framework/move-stdlib/u128) | Functions for the `u128` type | +| [std::u256](https://docs.sui.io/references/framework/move-stdlib/u256) | Functions for the `u256` type | + +
+ ## Exported Addresses Standard Library exports one named address - `std = 0x1`. diff --git a/book/src/programmability/hot-potato-pattern.md b/book/src/programmability/hot-potato-pattern.md index 82022d42..95fa1852 100644 --- a/book/src/programmability/hot-potato-pattern.md +++ b/book/src/programmability/hot-potato-pattern.md @@ -105,12 +105,13 @@ will cover in the next section. The pattern is used in various forms in the Sui Framework. Here are some examples: -- `sui::borrow` - uses hot potato to ensure that the borrowed value is returned to the correct - container. -- `sui::transfer_policy` - defines a `TransferRequest` - a hot potato which can only be consumed if - all conditions are met. -- `sui::token` - in the Closed Loop Token system, an `ActionRequest` carries the information about - the performed action and collects approvals similarly to `TransferRequest`. +- [sui::borrow](https://docs.sui.io/references/framework/sui-framework/borrow) - uses hot potato to + ensure that the borrowed value is returned to the correct container. +- [sui::transfer_policy](https://docs.sui.io/references/framework/sui-framework/transfer_policy) - + defines a `TransferRequest` - a hot potato which can only be consumed if all conditions are met. +- [sui::token](https://docs.sui.io/references/framework/sui-framework/token) - in the Closed Loop + Token system, an `ActionRequest` carries the information about the performed action and collects + approvals similarly to `TransferRequest`. ## Summary diff --git a/book/src/programmability/sui-framework.md b/book/src/programmability/sui-framework.md index bba2b2d8..a07182c6 100644 --- a/book/src/programmability/sui-framework.md +++ b/book/src/programmability/sui-framework.md @@ -47,9 +47,12 @@ still part of the same framework._
-| Module | Description | Chapter | -| ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------- | -| [sui::bcs](https://docs.sui.io/references/framework/sui-framework/bcs) | Implements the BCS encoding and decoding functions | [Binary Canonical Serialization](./bcs.md) | +| Module | Description | Chapter | +| ---------------------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------ | +| [sui::bcs](https://docs.sui.io/references/framework/sui-framework/bcs) | Implements the BCS encoding and decoding functions | [Binary Canonical Serialization](./bcs.md) | +| [sui::borrow](https://docs.sui.io/references/framework/sui-framework/borrow) | Implements the borrowing mechanic for borrowing by _value_ | [Hot Potato](./hot-potato-pattern.md) | +| [sui::hex](https://docs.sui.io/references/framework/sui-framework/hex) | Implements the hex encoding and decoding functions | - | +| [sui::types](https://docs.sui.io/references/framework/sui-framework/types) | Provides a way to check if the type is a One-Time-Witness | [One Time Witness](./one-time-witness.md) | ## Exported Addresses @@ -100,11 +103,12 @@ Commerce: - sui::transfer_policy -- sui::bcs -- sui::hex -- sui::math -- sui::types -- sui::borrow +Utilities: ++ sui::bcs ++ sui::hex +- sui::math (deprecated) ++ sui::types ++ sui::borrow - sui::authenticator diff --git a/packages/samples/sources/move-basics/vector.move b/packages/samples/sources/move-basics/vector.move index 29b4e792..db09f35b 100644 --- a/packages/samples/sources/move-basics/vector.move +++ b/packages/samples/sources/move-basics/vector.move @@ -4,7 +4,6 @@ #[allow(unused_variable)] module book::vector_syntax { #[test] fun test_vector() { - // ANCHOR: literal // An empty vector of bool elements. let empty: vector = vector[]; @@ -21,7 +20,6 @@ let vv: vector> = vector[ } #[test] fun vector_methods() { - // ANCHOR: methods let mut v = vector[10u8, 20, 30]; @@ -34,7 +32,6 @@ let last_value = v.pop_back(); assert!(last_value == 40, 2); // ANCHOR_END: methods } - } From 9ecaf8f7bb33a3fc4310e831591c2ec69aa6af32 Mon Sep 17 00:00:00 2001 From: Damir Shamanaev Date: Tue, 27 Aug 2024 15:15:54 +0300 Subject: [PATCH 2/3] adds error attribute note --- book/src/move-basics/assert-and-abort.md | 13 ++++++++++++- .../sources/move-basics/assert-and-abort.move | 19 +++++++++++++++++++ .../importing-modules-members.move | 15 +++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/samples/sources/move-basics/importing-modules-members.move diff --git a/book/src/move-basics/assert-and-abort.md b/book/src/move-basics/assert-and-abort.md index 27aa0908..319dc4eb 100644 --- a/book/src/move-basics/assert-and-abort.md +++ b/book/src/move-basics/assert-and-abort.md @@ -45,7 +45,8 @@ The code above will, of course, abort with abort code `1`. The `assert!` macro is a built-in macro that can be used to assert a condition. If the condition is false, the transaction will abort with the given abort code. The `assert!` macro is a convenient way to abort a transaction if a condition is not met. The macro shortens the code otherwise written with -an `if` expression + `abort`. The `code` argument is required and has to be a `u64` value. +an `if` expression + `abort`. The `code` argument is optional, but has to be a `u64` value or an +`#[error]` (see below for more information). ```move {{#include ../../../packages/samples/sources/move-basics/assert-and-abort.move:assert}} @@ -63,6 +64,16 @@ code and make it easier to understand the abort scenarios. {{#include ../../../packages/samples/sources/move-basics/assert-and-abort.move:error_const}} ``` +## Error messages + +Move 2024 introduces a special type of error constant, marked with the `#[error]` attribute. This +attribute allows the error constant to be of type `vector` and can be used to store an error +message. + +```move +{{#include ../../../packages/samples/sources/move-basics/assert-and-abort.move:error_attribute}} +``` + ## Further reading - [Abort and Assert](/reference/abort-and-assert.html) in the Move Reference. diff --git a/packages/samples/sources/move-basics/assert-and-abort.move b/packages/samples/sources/move-basics/assert-and-abort.move index 885e51f8..528a81fb 100644 --- a/packages/samples/sources/move-basics/assert-and-abort.move +++ b/packages/samples/sources/move-basics/assert-and-abort.move @@ -50,3 +50,22 @@ public fun update_record(/* ... , */ user_has_access: bool, field_exists: bool) /* ... */ } // ANCHOR_END: error_const + +public struct User { is_authorized: bool, value: u64 } + +// ANCHOR: error_attribute +#[error] +const ENotAuthorized: vector = b"The user is not authorized to perform this action"; + +#[error] +const EValueTooLow: vector = b"The value is too low, it should be at least 10"; + +/// Performs an action on behalf of the user. +public fun update_value(user: &mut User, value: u64) { + assert!(user.is_authorized, ENotAuthorized); + assert!(value >= 10, EValueTooLow); + + user.value = value; +} +// ANCHOR_END: error_attribute +} diff --git a/packages/samples/sources/move-basics/importing-modules-members.move b/packages/samples/sources/move-basics/importing-modules-members.move new file mode 100644 index 00000000..91472676 --- /dev/null +++ b/packages/samples/sources/move-basics/importing-modules-members.move @@ -0,0 +1,15 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[allow(unused_use)] +// ANCHOR: members +module book::more_imports; + +use book::module_one::new; // imports the `new` function from the `module_one` module +use book::module_one::Character; // importing the `Character` struct from the `module_one` module + +/// Calls the `new` function from the `module_one` module. +public fun create_character(): Character { + new() +} +// ANCHOR_END: members From 84bdd4247463602f8c62ffb55232d30277adbcce Mon Sep 17 00:00:00 2001 From: Damir Shamanaev Date: Mon, 21 Oct 2024 18:27:10 +0300 Subject: [PATCH 3/3] better assert() --- .../move-basics/constants-shop-price.move | 2 +- .../sources/move-basics/control-flow.move | 22 +++++++-------- .../sources/move-basics/expression.move | 5 +--- .../samples/sources/move-basics/function.move | 6 ++-- .../samples/sources/move-basics/generics.move | 4 +-- .../move-basics/importing-module-members.move | 15 ---------- .../samples/sources/move-basics/option.move | 6 ++-- .../sources/move-basics/references.move | 4 +-- .../samples/sources/move-basics/string.move | 4 +-- .../sources/move-basics/struct-methods-2.move | 4 +-- .../sources/move-basics/struct-methods.move | 4 +-- .../samples/sources/move-basics/struct.move | 6 ++-- .../sources/move-basics/type-reflection.move | 2 +- .../samples/sources/move-basics/vector.move | 6 ++-- .../samples/sources/programmability/bcs.move | 18 ++++++------ .../programmability/collections-2.move | 6 ++-- .../programmability/collections-3.move | 2 +- .../sources/programmability/fast-path.move | 2 +- .../sources/programmability/publisher.move | 4 +-- .../sources/your-first-move/hello_world.move | 20 ++++++------- .../your-first-move/hello_world_debug.move | 28 +++++++++---------- .../your-first-move/hello_world_docs.move | 26 ++++++++--------- 22 files changed, 89 insertions(+), 107 deletions(-) delete mode 100644 packages/samples/sources/move-basics/importing-module-members.move diff --git a/packages/samples/sources/move-basics/constants-shop-price.move b/packages/samples/sources/move-basics/constants-shop-price.move index 1092bccb..165a5ff8 100644 --- a/packages/samples/sources/move-basics/constants-shop-price.move +++ b/packages/samples/sources/move-basics/constants-shop-price.move @@ -16,7 +16,7 @@ public struct Item {} /// Purchase an item from the shop. public fun purchase(coin: Coin): Item { - assert!(coin.value() == ITEM_PRICE, 0); + assert!(coin.value() == ITEM_PRICE); transfer::public_transfer(coin, SHOP_OWNER); diff --git a/packages/samples/sources/move-basics/control-flow.move b/packages/samples/sources/move-basics/control-flow.move index c34e5e33..27c71a8b 100644 --- a/packages/samples/sources/move-basics/control-flow.move +++ b/packages/samples/sources/move-basics/control-flow.move @@ -26,7 +26,7 @@ fun test_if_else() { 0 }; - assert!(y == 1, 0); + assert!(y == 1); } // ANCHOR_END: if_else // ANCHOR: while_loop @@ -50,9 +50,9 @@ fun while_loop(mut x: u8): u8 { #[test] fun test_while() { - assert!(while_loop(0) == 10, 0); // 10 times - assert!(while_loop(5) == 5, 0); // 5 times - assert!(while_loop(10) == 0, 0); // loop never executed + assert!(while_loop(0) == 10); // 10 times + assert!(while_loop(5) == 5); // 5 times + assert!(while_loop(10) == 0); // loop never executed } // ANCHOR_END: while_loop // ANCHOR: infinite_while @@ -66,7 +66,7 @@ fun test_infinite_while() { }; // This line will never be executed. - assert!(x == 5, 0); + assert!(x == 5); } // ANCHOR_END: infinite_while #[allow(dead_code)] @@ -81,7 +81,7 @@ fun test_infinite_loop() { }; // This line will never be executed. - assert!(x == 5, 0); + assert!(x == 5); } // ANCHOR_END: infinite_loop // ANCHOR: break_loop @@ -99,7 +99,7 @@ fun test_break_loop() { } }; - assert!(x == 5, 0); + assert!(x == 5); } // ANCHOR_END: break_loop // ANCHOR: continue_loop @@ -124,7 +124,7 @@ fun test_continue_loop() { } }; - assert!(x == 10, 0); // 10 + assert!(x == 10); // 10 } // ANCHOR_END: continue_loop // ANCHOR: return_statement @@ -144,8 +144,8 @@ fun is_positive(x: u8): bool { #[test] fun test_return() { - assert!(is_positive(5) == false, 0); - assert!(is_positive(0) == false, 0); - assert!(is_positive(1) == true, 0); + assert!(is_positive(5) == false); + assert!(is_positive(0) == false); + assert!(is_positive(1) == true); } // ANCHOR_END: return_statement diff --git a/packages/samples/sources/move-basics/expression.move b/packages/samples/sources/move-basics/expression.move index 2f3b7d13..c5cd9272 100644 --- a/packages/samples/sources/move-basics/expression.move +++ b/packages/samples/sources/move-basics/expression.move @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #[allow(unused_variable)] -module book::expression { +module book::expression; #[test] fun expression_examples() { @@ -81,7 +81,4 @@ while (bool_expr) { expr; }; // loop is an expression, but returns `()` as well. loop { expr; break }; // ANCHOR_END: control_flow - - -} } diff --git a/packages/samples/sources/move-basics/function.move b/packages/samples/sources/move-basics/function.move index 3f8b96d7..e93aaaf1 100644 --- a/packages/samples/sources/move-basics/function.move +++ b/packages/samples/sources/move-basics/function.move @@ -15,7 +15,7 @@ public fun add(a: u64, b: u64): u64 { #[test] fun test_add() { let sum = add(1, 2); - assert!(sum == 3, 0); + assert!(sum == 3); } // ANCHOR_END: math @@ -36,8 +36,8 @@ fun get_name_and_age(): (vector, u8) { // Tuple must be destructured to access its elements. // Name and age are declared as immutable variables. let (name, age) = get_name_and_age(); -assert!(name == b"John", 0); -assert!(age == 25, 0); +assert!(name == b"John"); +assert!(age == 25); // ANCHOR_END: tuple_return_imm // ANCHOR: tuple_return_mut diff --git a/packages/samples/sources/move-basics/generics.move b/packages/samples/sources/move-basics/generics.move index 869e7196..7ef6bfaf 100644 --- a/packages/samples/sources/move-basics/generics.move +++ b/packages/samples/sources/move-basics/generics.move @@ -74,8 +74,8 @@ fun test_swap_type_params() { let Pair { first: pf1, second: ps1 } = pair1; // first1: u8, second1: bool let Pair { first: pf2, second: ps2 } = pair2; // first2: bool, second2: u8 - assert!(pf1 == ps2, 0x0); // 10 == 10 - assert!(ps1 == pf2, 0x0); // true == true + assert!(pf1 == ps2); // 10 == 10 + assert!(ps1 == pf2); // true == true } // ANCHOR_END: test_pair_swap diff --git a/packages/samples/sources/move-basics/importing-module-members.move b/packages/samples/sources/move-basics/importing-module-members.move deleted file mode 100644 index 91472676..00000000 --- a/packages/samples/sources/move-basics/importing-module-members.move +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[allow(unused_use)] -// ANCHOR: members -module book::more_imports; - -use book::module_one::new; // imports the `new` function from the `module_one` module -use book::module_one::Character; // importing the `Character` struct from the `module_one` module - -/// Calls the `new` function from the `module_one` module. -public fun create_character(): Character { - new() -} -// ANCHOR_END: members diff --git a/packages/samples/sources/move-basics/option.move b/packages/samples/sources/move-basics/option.move index 593d4b71..5fd24139 100644 --- a/packages/samples/sources/move-basics/option.move +++ b/packages/samples/sources/move-basics/option.move @@ -31,15 +31,15 @@ public fun register( let mut opt = option::some(b"Alice"); // `option.is_some()` returns true if option contains a value. -assert!(opt.is_some(), 1); +assert!(opt.is_some()); // internal value can be `borrow`ed and `borrow_mut`ed. -assert!(opt.borrow() == &b"Alice", 0); +assert!(opt.borrow() == &b"Alice"); // `option.extract` takes the value out of the option, leaving the option empty. let inner = opt.extract(); // `option.is_none()` returns true if option is None. -assert!(opt.is_none(), 2); +assert!(opt.is_none()); // ANCHOR_END: usage } diff --git a/packages/samples/sources/move-basics/references.move b/packages/samples/sources/move-basics/references.move index 1326899c..f2b5e032 100644 --- a/packages/samples/sources/move-basics/references.move +++ b/packages/samples/sources/move-basics/references.move @@ -51,7 +51,7 @@ fun test_card() { enter_metro(&mut card); - assert!(is_valid(&card), 0); // read the card! + assert!(is_valid(&card)); // read the card! enter_metro(&mut card); // modify the card but don't move it enter_metro(&mut card); // modify the card but don't move it @@ -67,7 +67,7 @@ fun test_card_2024() { let mut card = purchase(); card.enter_metro(); // modify the card but don't move it - assert!(card.is_valid(), 0); // read the card! + assert!(card.is_valid()); // read the card! card.enter_metro(); // modify the card but don't move it card.enter_metro(); // modify the card but don't move it diff --git a/packages/samples/sources/move-basics/string.move b/packages/samples/sources/move-basics/string.move index 8cc50137..f1747c78 100644 --- a/packages/samples/sources/move-basics/string.move +++ b/packages/samples/sources/move-basics/string.move @@ -59,11 +59,11 @@ let hello = b"Hello".to_string(); // this is a valid UTF-8 string let hello = b"Hello".try_to_string(); -assert!(hello.is_some(), 0); // abort if the value is not valid UTF-8 +assert!(hello.is_some()); // abort if the value is not valid UTF-8 // this is not a valid UTF-8 string let invalid = b"\xFF".try_to_string(); -assert!(invalid.is_none(), 0); // abort if the value is valid UTF-8 +assert!(invalid.is_none()); // abort if the value is valid UTF-8 // ANCHOR_END: safe_utf8 } diff --git a/packages/samples/sources/move-basics/struct-methods-2.move b/packages/samples/sources/move-basics/struct-methods-2.move index a7923eef..4e80f6ec 100644 --- a/packages/samples/sources/move-basics/struct-methods-2.move +++ b/packages/samples/sources/move-basics/struct-methods-2.move @@ -36,9 +36,9 @@ public fun villain_health(villain: &Villain): u8 { villain.health } // Test the methods of the `Hero` and `Villain` structs. fun test_associated_methods() { let hero = new_hero(); - assert!(hero.health() == 100, 1); + assert!(hero.health() == 100); let villain = new_villain(); - assert!(villain.health() == 100, 3); + assert!(villain.health() == 100); } // ANCHOR_END: hero_and_villain diff --git a/packages/samples/sources/move-basics/struct-methods.move b/packages/samples/sources/move-basics/struct-methods.move index 3d8df5a8..a7164ec0 100644 --- a/packages/samples/sources/move-basics/struct-methods.move +++ b/packages/samples/sources/move-basics/struct-methods.move @@ -31,7 +31,7 @@ fun test_methods() { let mut hero = new(); hero.heal_spell(); - assert!(hero.health() == 110, 1); - assert!(hero.mana() == 90, 2); + assert!(hero.health() == 110); + assert!(hero.mana() == 90); } // ANCHOR_END: hero diff --git a/packages/samples/sources/move-basics/struct.move b/packages/samples/sources/move-basics/struct.move index 7e91e038..91e2e1f6 100644 --- a/packages/samples/sources/move-basics/struct.move +++ b/packages/samples/sources/move-basics/struct.move @@ -41,13 +41,13 @@ let mut artist = Artist { let artist_name = artist.name; // Access a field of the `Artist` struct. -assert!(artist.name == string::utf8(b"The Beatles"), 0); +assert!(artist.name == b"The Beatles".to_string()); // Mutate the `name` field of the `Artist` struct. -artist.name = string::utf8(b"Led Zeppelin"); +artist.name = b"Led Zeppelin".to_string(); // Check that the `name` field has been mutated. -assert!(artist.name == string::utf8(b"Led Zeppelin"), 1); +assert!(artist.name == b"Led Zeppelin".to_string()); // ANCHOR_END: access // ANCHOR: unpack diff --git a/packages/samples/sources/move-basics/type-reflection.move b/packages/samples/sources/move-basics/type-reflection.move index 3670db49..5acfd692 100644 --- a/packages/samples/sources/move-basics/type-reflection.move +++ b/packages/samples/sources/move-basics/type-reflection.move @@ -32,6 +32,6 @@ fun test_type_reflection() { let (type_name, module_name, _address_str) = do_i_know_you(); // - assert!(module_name == b"type_reflection".to_ascii_string(), 1); + assert!(module_name == b"type_reflection".to_ascii_string()); } // ANCHOR_END: main diff --git a/packages/samples/sources/move-basics/vector.move b/packages/samples/sources/move-basics/vector.move index db09f35b..4fba05be 100644 --- a/packages/samples/sources/move-basics/vector.move +++ b/packages/samples/sources/move-basics/vector.move @@ -23,13 +23,13 @@ let vv: vector> = vector[ // ANCHOR: methods let mut v = vector[10u8, 20, 30]; -assert!(v.length() == 3, 0); -assert!(!v.is_empty(), 1); +assert!(v.length() == 3); +assert!(!v.is_empty()); v.push_back(40); let last_value = v.pop_back(); -assert!(last_value == 40, 2); +assert!(last_value == 40); // ANCHOR_END: methods } } diff --git a/packages/samples/sources/programmability/bcs.move b/packages/samples/sources/programmability/bcs.move index 81565d85..17fd7dbd 100644 --- a/packages/samples/sources/programmability/bcs.move +++ b/packages/samples/sources/programmability/bcs.move @@ -47,7 +47,7 @@ custom_bytes.append(bcs::to_bytes(&b"hello, world!".to_string())); custom_bytes.append(bcs::to_bytes(&true)); // struct is just a sequence of fields, so the bytes should be the same! -assert!(&struct_bytes == &custom_bytes, 0); +assert!(&struct_bytes == &custom_bytes); // ANCHOR_END: encode_struct } @@ -61,12 +61,12 @@ let mut bcs = bcs::new(x"010000000000000000"); // Same bytes can be read differently, for example: Option let value: Option = bcs.peel_option_u64(); -assert!(value.is_some(), 0); -assert!(value.borrow() == &0, 1); +assert!(value.is_some()); +assert!(value.borrow() == &0); let remainder = bcs.into_remainder_bytes(); -assert!(remainder.length() == 0, 2); +assert!(remainder.length() == 0); // ANCHOR_END: decode // ANCHOR: chain_decode @@ -94,25 +94,25 @@ while (len > 0) { len = len - 1; }; -assert!(vec.length() == 1, 0); +assert!(vec.length() == 1); // ANCHOR_END: decode_vector // ANCHOR: decode_option let mut bcs = bcs::new(x"00"); let is_some = bcs.peel_bool(); -assert!(is_some == false, 0); +assert!(is_some == false); let mut bcs = bcs::new(x"0101"); let is_some = bcs.peel_bool(); let value = bcs.peel_u8(); -assert!(is_some == true, 1); -assert!(value == 1, 2); +assert!(is_some == true); +assert!(value == 1); // ANCHOR_END: decode_option // ANCHOR: decode_struct -// some bytes... +// some bytes... let mut bcs = bcs::new(x"0101010F0000000000F00000000000"); let (age, is_active, name) = ( diff --git a/packages/samples/sources/programmability/collections-2.move b/packages/samples/sources/programmability/collections-2.move index 9c5c28a6..d06ce27b 100644 --- a/packages/samples/sources/programmability/collections-2.move +++ b/packages/samples/sources/programmability/collections-2.move @@ -20,9 +20,9 @@ fun vec_set_playground() { set.insert(2); // add an item to the set set.insert(3); - assert!(set.contains(&1), 0); // check if an item is in the set - assert!(set.size() == 3, 1); // get the number of items in the set - assert!(!set.is_empty(), 2); // check if the set is empty + assert!(set.contains(&1)); // check if an item is in the set + assert!(set.size() == 3); // get the number of items in the set + assert!(!set.is_empty()); // check if the set is empty set.remove(&2); // remove an item from the set } diff --git a/packages/samples/sources/programmability/collections-3.move b/packages/samples/sources/programmability/collections-3.move index 05664e99..35e7066b 100644 --- a/packages/samples/sources/programmability/collections-3.move +++ b/packages/samples/sources/programmability/collections-3.move @@ -21,7 +21,7 @@ fun vec_map_playground() { map.insert(2, b"two".to_string()); // add a key-value pair to the map map.insert(3, b"three".to_string()); - assert!(map.contains(&2), 0); // check if a key is in the map + assert!(map.contains(&2)); // check if a key is in the map map.remove(&2); // remove a key-value pair from the map } diff --git a/packages/samples/sources/programmability/fast-path.move b/packages/samples/sources/programmability/fast-path.move index 78b302cf..6afa71ca 100644 --- a/packages/samples/sources/programmability/fast-path.move +++ b/packages/samples/sources/programmability/fast-path.move @@ -36,7 +36,7 @@ module book::coffee_machine { /// Put the cup back. This is a fast path operation. public fun put_back(cup: Cup) { let Cup { id, has_coffee: _ } = cup; - object::delete(id); + id.delete(); } } // ANCHOR_END: main diff --git a/packages/samples/sources/programmability/publisher.move b/packages/samples/sources/programmability/publisher.move index 20c1a4f3..1af4382a 100644 --- a/packages/samples/sources/programmability/publisher.move +++ b/packages/samples/sources/programmability/publisher.move @@ -36,11 +36,11 @@ let publisher = package::test_claim(USE_PUBLISHER {}, ctx); // ANCHOR: use_publisher // Checks if the type is from the same module, hence the `Publisher` has the // authority over it. -assert!(publisher.from_module(), 0); +assert!(publisher.from_module()); // Checks if the type is from the same package, hence the `Publisher` has the // authority over it. -assert!(publisher.from_package(), 0); +assert!(publisher.from_package()); // ANCHOR_END: use_publisher sui::test_utils::destroy(publisher); } diff --git a/packages/samples/sources/your-first-move/hello_world.move b/packages/samples/sources/your-first-move/hello_world.move index f852b18c..0f3ae515 100644 --- a/packages/samples/sources/your-first-move/hello_world.move +++ b/packages/samples/sources/your-first-move/hello_world.move @@ -1,16 +1,16 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module book::hello_world { - use std::string::String; +module book::hello_world; - public fun hello_world(): String { - b"Hello, World!".to_string() - } +use std::string::String; - #[test] - fun test_is_hello_world() { - let expected = b"Hello, World!".to_string(); - assert!(hello_world() == expected, 0) - } +public fun hello_world(): String { + b"Hello, World!".to_string() +} + +#[test] +fun test_is_hello_world() { + let expected = b"Hello, World!".to_string(); + assert!(hello_world() == expected) } diff --git a/packages/samples/sources/your-first-move/hello_world_debug.move b/packages/samples/sources/your-first-move/hello_world_debug.move index 00b85898..99de59e9 100644 --- a/packages/samples/sources/your-first-move/hello_world_debug.move +++ b/packages/samples/sources/your-first-move/hello_world_debug.move @@ -1,21 +1,21 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module book::hello_world_debug { - use std::string::String; - use std::debug; +module book::hello_world_debug; - public fun hello_world(): String { - let result = b"Hello, World!".to_string(); - debug::print(&result); - result - } +use std::string::String; +use std::debug; - #[test] - fun test_is_hello_world() { - let expected = b"Hello, World!".to_string(); - let actual = hello_world(); +public fun hello_world(): String { + let result = b"Hello, World!".to_string(); + debug::print(&result); + result +} + +#[test] +fun test_is_hello_world() { + let expected = b"Hello, World!".to_string(); + let actual = hello_world(); - assert!(actual == expected, 0) - } + assert!(actual == expected) } diff --git a/packages/samples/sources/your-first-move/hello_world_docs.move b/packages/samples/sources/your-first-move/hello_world_docs.move index d100e7ec..3ad5add2 100644 --- a/packages/samples/sources/your-first-move/hello_world_docs.move +++ b/packages/samples/sources/your-first-move/hello_world_docs.move @@ -2,20 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 /// This module contains a function that returns a string "Hello, World!". -module book::hello_world_docs { - use std::string::String; +module book::hello_world_docs; - /// As the name says: returns a string "Hello, World!". - public fun hello_world(): String { - b"Hello, World!".to_string() - } +use std::string::String; - #[test] - /// This is a test for the `hello_world` function. - fun test_is_hello_world() { - let expected = b"Hello, World!".to_string(); - let actual = hello_world(); +/// As the name says: returns a string "Hello, World!". +public fun hello_world(): String { + b"Hello, World!".to_string() +} + +#[test] +/// This is a test for the `hello_world` function. +fun test_is_hello_world() { + let expected = b"Hello, World!".to_string(); + let actual = hello_world(); - assert!(actual == expected, 0) - } + assert!(actual == expected) }