diff --git a/doc/move_code/objects_tutorial/sources/Ch1_2/ColorObject.move b/doc/move_code/objects_tutorial/sources/Ch1_2/ColorObject.move index 30c0764abadd1..4aa3b9538c193 100644 --- a/doc/move_code/objects_tutorial/sources/Ch1_2/ColorObject.move +++ b/doc/move_code/objects_tutorial/sources/Ch1_2/ColorObject.move @@ -65,13 +65,13 @@ module Tutorial::ColorObjectTests { let not_owner = @0x2; TestScenario::next_tx(scenario, ¬_owner); { - assert!(!TestScenario::can_remove_object(scenario), 0); + assert!(!TestScenario::can_take_object(scenario), 0); }; // Check that @owner indeed owns the just-created ColorObject. // Also checks the value fields of the object. TestScenario::next_tx(scenario, &owner); { - let object = TestScenario::remove_object(scenario); + let object = TestScenario::take_object(scenario); let (red, green, blue) = ColorObject::get_color(&object); assert!(red == 255 && green == 0 && blue == 255, 0); TestScenario::return_object(scenario, object); @@ -92,14 +92,14 @@ module Tutorial::ColorObjectTests { // Delete the ColorObject we just created. TestScenario::next_tx(scenario, &owner); { - let object = TestScenario::remove_object(scenario); + let object = TestScenario::take_object(scenario); let ctx = TestScenario::ctx(scenario); ColorObject::delete(object, ctx); }; // Verify that the object was indeed deleted. TestScenario::next_tx(scenario, &owner); { - assert!(!TestScenario::can_remove_object(scenario), 0); + assert!(!TestScenario::can_take_object(scenario), 0); } } @@ -116,19 +116,19 @@ module Tutorial::ColorObjectTests { let recipient = @0x2; TestScenario::next_tx(scenario, &owner); { - let object = TestScenario::remove_object(scenario); + let object = TestScenario::take_object(scenario); let ctx = TestScenario::ctx(scenario); ColorObject::transfer(object, recipient, ctx); }; // Check that owner no longer owns the object. TestScenario::next_tx(scenario, &owner); { - assert!(!TestScenario::can_remove_object(scenario), 0); + assert!(!TestScenario::can_take_object(scenario), 0); }; // Check that recipient now owns the object. TestScenario::next_tx(scenario, &recipient); { - assert!(TestScenario::can_remove_object(scenario), 0); + assert!(TestScenario::can_take_object(scenario), 0); }; } } \ No newline at end of file diff --git a/doc/src/build/move.md b/doc/src/build/move.md index 0dbbbc6075fb8..775c3e801142b 100644 --- a/doc/src/build/move.md +++ b/doc/src/build/move.md @@ -688,7 +688,7 @@ function: TestScenario::next_tx(scenario, &initial_owner); { // extract the sword owned by the initial owner - let sword = TestScenario::remove_object(scenario); + let sword = TestScenario::take_object(scenario); // transfer the sword to the final owner sword_transfer(sword, final_owner, TestScenario::ctx(scenario)); }; @@ -696,7 +696,7 @@ function: TestScenario::next_tx(scenario, &final_owner); { // extract the sword owned by the final owner - let sword = TestScenario::remove_object(scenario); + let sword = TestScenario::take_object(scenario); // verify that the sword has expected properties assert!(magic(&sword) == 42 && strength(&sword) == 7, 1); // return the sword to the object pool (it cannot be simply "dropped") @@ -719,7 +719,7 @@ the sword it now owns to its final owner. Please note that in *pure Move* we do not have the notion of Sui storage and, consequently, no easy way for the emulated Sui transaction to retrieve it from storage. This is where the `TestScenario` module comes to help - its -`remove_object` function makes an object of a given type (in this case +`take_object` function makes an object of a given type (in this case of type `Sword`) owned by an address executing the current transaction available for manipulation by the Move code. (For now, we assume that there is only one such object.) In this case, the object retrieved @@ -878,7 +878,7 @@ We can now create a function to test the module initialization: TestScenario::next_tx(scenario, &admin); { // extract the Forge object - let forge = TestScenario::remove_object(scenario); + let forge = TestScenario::take_object(scenario); // verify number of created swords assert!(swords_created(&forge) == 0, 1); // return the Forge object to the object pool diff --git a/doc/src/build/programming-with-objects/ch1-object-basics.md b/doc/src/build/programming-with-objects/ch1-object-basics.md index 3111cc8c46834..a77726d6fc9bf 100644 --- a/doc/src/build/programming-with-objects/ch1-object-basics.md +++ b/doc/src/build/programming-with-objects/ch1-object-basics.md @@ -113,26 +113,26 @@ let not_owner = @0x2; // Check that @not_owner does not own the just-created ColorObject. TestScenario::next_tx(scenario, ¬_owner); { - assert!(!TestScenario::can_remove_object(scenario), 0); + assert!(!TestScenario::can_take_object(scenario), 0); }; ``` `TestScenario::next_tx` switches the transaction sender to `@0x2`, which is a new address than the previous one. -`TestScenario::can_remove_object` checks whether an object with the given type actually exists in the global storage owned by the current sender of the transaction. In this code, we assert that we should not be able to remove such an object, because `@0x2` does not own any object. +`TestScenario::can_take_object` checks whether an object with the given type actually exists in the global storage owned by the current sender of the transaction. In this code, we assert that we should not be able to remove such an object, because `@0x2` does not own any object. > :bulb: The second parameter of `assert!` is the error code. In non-test code, we usually define a list of dedicated error code constants for each type of error that could happen in production. For unit tests though, it's usually unnecessary because there will be way too many assetions and the stacktrace upon error is sufficient to tell where the error happened. Hence we recommend just putting `0` there in unit tests for assertions. Finally we check that `@0x1` owns the object and the object value is consistent: ```rust TestScenario::next_tx(scenario, &owner); { - let object = TestScenario::remove_object(scenario); + let object = TestScenario::take_object(scenario); let (red, green, blue) = ColorObject::get_color(&object); assert!(red == 255 && green == 0 && blue == 255, 0); TestScenario::return_object(scenario, object); }; ``` -`TestScenario::remove_object` removes the object of given type from global storage that's owned by the current transaction sender (it also implicitly checks `can_remove_object`). If this line of code succeeds, it means that `owner` indeed owns an object of type `ColorObject`. +`TestScenario::take_object` removes the object of given type from global storage that's owned by the current transaction sender (it also implicitly checks `can_take_object`). If this line of code succeeds, it means that `owner` indeed owns an object of type `ColorObject`. We also check that the field values of the object match with what we set in creation. At the end, we must return the object back to the global storage by calling `TestScenario::return_object` so that it's back to the global storage. This also ensures that if any mutations happened to the object during the test, the global storage is aware of the changes. -You may have noticed that `remove_object` picks the object only based on the type parameter. What if there are multiple objects of the same type owned by the account? How do we retrieve each of them? In fact, if you call `remove_object` when there are more than one object of the same type in the same account, an assertion failure will be triggered. We are working on adding an API just for this. Update coming soon. +You may have noticed that `take_object` picks the object only based on the type parameter. What if there are multiple objects of the same type owned by the account? How do we retrieve each of them? In fact, if you call `take_object` when there are more than one object of the same type in the same account, an assertion failure will be triggered. We are working on adding an API just for this. Update coming soon. Again, you can find the full code [here](../../../move_code/objects_tutorial/sources/Ch1_2/ColorObject.move). diff --git a/doc/src/build/programming-with-objects/ch2-using-objects.md b/doc/src/build/programming-with-objects/ch2-using-objects.md index 60b45371b80e1..7cf00f366fe9e 100644 --- a/doc/src/build/programming-with-objects/ch2-using-objects.md +++ b/doc/src/build/programming-with-objects/ch2-using-objects.md @@ -62,14 +62,14 @@ let scenario = &mut TestScenario::begin(&owner); // Delete the ColorObject we just created. TestScenario::next_tx(scenario, &owner); { - let object = TestScenario::remove_object(scenario); + let object = TestScenario::take_object(scenario); let ctx = TestScenario::ctx(scenario); ColorObject::delete(object, ctx); }; // Verify that the object was indeed deleted. TestScenario::next_tx(scenario, &owner); { - assert!(!TestScenario::can_remove_object(scenario), 0); + assert!(!TestScenario::can_take_object(scenario), 0); } ``` The first part is the same as what we have seen in [Chapter 1](./ch1-object-basics.md#writing-unit-tests), which creates a new `ColorObject` and put it to the owner's account. The second transaction is what we are testing: retrieve the object from the storage, and then delete it. Since the object is deleted, there is no need (in fact, impossible) to return it to the storage. The last part checks that the object is indeed no longer in the global storage, and hence cannot be retrieved from there. @@ -96,7 +96,7 @@ let scenario = &mut TestScenario::begin(&owner); let recipient = @0x2; TestScenario::next_tx(scenario, &owner); { - let object = TestScenario::remove_object(scenario); + let object = TestScenario::take_object(scenario); let ctx = TestScenario::ctx(scenario); ColorObject::transfer(object, recipient, ctx); }; @@ -106,12 +106,12 @@ Note that in the second transaction, the sender of the transaction should still // Check that owner no longer owns the object. TestScenario::next_tx(scenario, &owner); { - assert!(!TestScenario::can_remove_object(scenario), 0); + assert!(!TestScenario::can_take_object(scenario), 0); }; // Check that recipient now owns the object. TestScenario::next_tx(scenario, &recipient); { - assert!(TestScenario::can_remove_object(scenario), 0); + assert!(TestScenario::can_take_object(scenario), 0); }; ``` diff --git a/sui_core/src/unit_tests/data/hero/sources/Hero.move b/sui_core/src/unit_tests/data/hero/sources/Hero.move index 08a27d2ffa577..05569ae99dd3d 100644 --- a/sui_core/src/unit_tests/data/hero/sources/Hero.move +++ b/sui_core/src/unit_tests/data/hero/sources/Hero.move @@ -313,7 +313,7 @@ module Examples::Hero { // Admin mints 500 coins and sends them to the Player so they can buy game items TestScenario::next_tx(scenario, &admin); { - let treasury_cap = TestScenario::remove_object>(scenario); + let treasury_cap = TestScenario::take_object>(scenario); let ctx = TestScenario::ctx(scenario); let coins = Coin::mint(500, &mut treasury_cap, ctx); Coin::transfer(coins, copy player); @@ -322,21 +322,21 @@ module Examples::Hero { // Player purchases a hero with the coins TestScenario::next_tx(scenario, &player); { - let coin = TestScenario::remove_object>(scenario); + let coin = TestScenario::take_object>(scenario); acquire_hero(coin, TestScenario::ctx(scenario)); }; // Admin sends a boar to the Player TestScenario::next_tx(scenario, &admin); { - let admin_cap = TestScenario::remove_object(scenario); + let admin_cap = TestScenario::take_object(scenario); send_boar(&mut admin_cap, 10, 10, player, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, admin_cap) }; // Player slays the boar! TestScenario::next_tx(scenario, &player); { - let hero = TestScenario::remove_object(scenario); - let boar = TestScenario::remove_object(scenario); + let hero = TestScenario::take_object(scenario); + let boar = TestScenario::take_object(scenario); slay(&mut hero, boar, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, hero) }; diff --git a/sui_programmability/examples/basics/sources/Lock.move b/sui_programmability/examples/basics/sources/Lock.move index a9ef6d058c17b..25a604781e418 100644 --- a/sui_programmability/examples/basics/sources/Lock.move +++ b/sui_programmability/examples/basics/sources/Lock.move @@ -127,7 +127,7 @@ module Basics::LockTest { // key to User2, so that he can have access to the stored treasure. TestScenario::next_tx(scenario, &user1); { - let key = TestScenario::remove_object>(scenario); + let key = TestScenario::take_object>(scenario); Transfer::transfer(key, user2); }; @@ -135,8 +135,8 @@ module Basics::LockTest { // User2 is impatient and he decides to take the treasure. TestScenario::next_tx(scenario, &user2); { - let lock = TestScenario::remove_object>(scenario); - let key = TestScenario::remove_object>(scenario); + let lock = TestScenario::take_object>(scenario); + let key = TestScenario::take_object>(scenario); let ctx = TestScenario::ctx(scenario); Lock::take(&mut lock, &key, ctx); diff --git a/sui_programmability/examples/defi/tests/EscrowTests.move b/sui_programmability/examples/defi/tests/EscrowTests.move index 59a6cf1dfec3c..16b84f484cf0f 100644 --- a/sui_programmability/examples/defi/tests/EscrowTests.move +++ b/sui_programmability/examples/defi/tests/EscrowTests.move @@ -47,11 +47,11 @@ module DeFi::EscrowTests { // The third party returns item A to Alice, item B to Bob TestScenario::next_tx(scenario, &THIRD_PARTY_ADDRESS); { - let item_a = TestScenario::remove_object>(scenario); + let item_a = TestScenario::take_object>(scenario); let ctx = TestScenario::ctx(scenario); Escrow::return_to_sender(item_a, ctx); - let item_b = TestScenario::remove_object>(scenario); + let item_b = TestScenario::take_object>(scenario); let ctx = TestScenario::ctx(scenario); Escrow::return_to_sender(item_b, ctx); }; @@ -82,8 +82,8 @@ module DeFi::EscrowTests { fun swap(scenario: &mut Scenario, third_party: &address) { TestScenario::next_tx(scenario, third_party); { - let item_a = TestScenario::remove_object>(scenario); - let item_b = TestScenario::remove_object>(scenario); + let item_a = TestScenario::take_object>(scenario); + let item_b = TestScenario::take_object>(scenario); let ctx = TestScenario::ctx(scenario); Escrow::swap(item_a, item_b, ctx); }; @@ -157,6 +157,6 @@ module DeFi::EscrowTests { fun owns_object(scenario: &mut Scenario, owner: &address): bool{ TestScenario::next_tx(scenario, owner); - TestScenario::can_remove_object(scenario) + TestScenario::can_take_object(scenario) } } diff --git a/sui_programmability/examples/defi/tests/FlashLenderTests.move b/sui_programmability/examples/defi/tests/FlashLenderTests.move index 5013920c139e1..6b34276eb784c 100644 --- a/sui_programmability/examples/defi/tests/FlashLenderTests.move +++ b/sui_programmability/examples/defi/tests/FlashLenderTests.move @@ -23,7 +23,7 @@ module DeFi::FlashLenderTests { // borrower requests and repays a loan of 10 coins + the fee TestScenario::next_tx(scenario, &borrower); { - let lender = TestScenario::remove_object>(scenario); + let lender = TestScenario::take_object>(scenario); let ctx = TestScenario::ctx(scenario); let (loan, receipt) = FlashLender::loan(&mut lender, 10, ctx); @@ -40,8 +40,8 @@ module DeFi::FlashLenderTests { // admin withdraws the 1 coin profit from lending TestScenario::next_tx(scenario, &admin); { - let lender = TestScenario::remove_object>(scenario); - let admin_cap = TestScenario::remove_object(scenario); + let lender = TestScenario::take_object>(scenario); + let admin_cap = TestScenario::take_object(scenario); let ctx = TestScenario::ctx(scenario); // max loan size should have increased because of the fee payment diff --git a/sui_programmability/examples/defi/tests/SharedEscrowTest.move b/sui_programmability/examples/defi/tests/SharedEscrowTest.move index 6860e9636bfea..62f1f2b4db85a 100644 --- a/sui_programmability/examples/defi/tests/SharedEscrowTest.move +++ b/sui_programmability/examples/defi/tests/SharedEscrowTest.move @@ -118,7 +118,7 @@ module DeFi::SharedEscrowTests { fun cancel(scenario: &mut Scenario, initiator: &address) { TestScenario::next_tx(scenario, initiator); { - let escrow = TestScenario::remove_object>(scenario); + let escrow = TestScenario::take_object>(scenario); let ctx = TestScenario::ctx(scenario); SharedEscrow::cancel(&mut escrow, ctx); TestScenario::return_object(scenario, escrow); @@ -128,7 +128,7 @@ module DeFi::SharedEscrowTests { fun exchange(scenario: &mut Scenario, bob: &address, item_b_verioned_id: VersionedID) { TestScenario::next_tx(scenario, bob); { - let escrow = TestScenario::remove_object>(scenario); + let escrow = TestScenario::take_object>(scenario); let item_b = ItemB { id: item_b_verioned_id }; @@ -171,6 +171,6 @@ module DeFi::SharedEscrowTests { fun owns_object(scenario: &mut Scenario, owner: &address): bool{ TestScenario::next_tx(scenario, owner); - TestScenario::can_remove_object(scenario) + TestScenario::can_take_object(scenario) } } diff --git a/sui_programmability/examples/fungible_tokens/tests/BASKETTests.move b/sui_programmability/examples/fungible_tokens/tests/BASKETTests.move index 59335be2cd23d..80d9f9ad7fe36 100644 --- a/sui_programmability/examples/fungible_tokens/tests/BASKETTests.move +++ b/sui_programmability/examples/fungible_tokens/tests/BASKETTests.move @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module FungibleTokens::BASKETTests { +module FungibleTokens::BASKETTests { use FungibleTokens::BASKET::{Self, Reserve}; use FungibleTokens::MANAGED::MANAGED; use Sui::Coin; @@ -20,7 +20,7 @@ module FungibleTokens::BASKETTests { }; TestScenario::next_tx(scenario, &user); { - let reserve = TestScenario::remove_object(scenario); + let reserve = TestScenario::take_object(scenario); let ctx = TestScenario::ctx(scenario); assert!(BASKET::total_supply(&reserve) == 0, 0); @@ -29,7 +29,7 @@ module FungibleTokens::BASKETTests { let managed = Coin::mint_for_testing(num_coins, ctx); let basket = BASKET::mint(&mut reserve, sui, managed, ctx); assert!(Coin::value(&basket) == num_coins, 1); - assert!(BASKET::total_supply(&reserve) == num_coins, 2); + assert!(BASKET::total_supply(&reserve) == num_coins, 2); let (sui, managed) = BASKET::burn(&mut reserve, basket, ctx); assert!(Coin::value(&sui) == num_coins, 3); diff --git a/sui_programmability/examples/games/hero/sources/Hero.move b/sui_programmability/examples/games/hero/sources/Hero.move index a77ee88401bd2..0a5ac83c02057 100644 --- a/sui_programmability/examples/games/hero/sources/Hero.move +++ b/sui_programmability/examples/games/hero/sources/Hero.move @@ -316,15 +316,15 @@ module HeroGame::Hero { // Admin sends a boar to the Player TestScenario::next_tx(scenario, &admin); { - let admin_cap = TestScenario::remove_object(scenario); + let admin_cap = TestScenario::take_object(scenario); send_boar(&mut admin_cap, 10, 10, player, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, admin_cap) }; // Player slays the boar! TestScenario::next_tx(scenario, &player); { - let hero = TestScenario::remove_object(scenario); - let boar = TestScenario::remove_object(scenario); + let hero = TestScenario::take_object(scenario); + let boar = TestScenario::take_object(scenario); slay(&mut hero, boar, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, hero) }; diff --git a/sui_programmability/examples/games/tests/RockPaperScissorsTests.move b/sui_programmability/examples/games/tests/RockPaperScissorsTests.move index 149de7cdf4015..8ea82bdccf911 100644 --- a/sui_programmability/examples/games/tests/RockPaperScissorsTests.move +++ b/sui_programmability/examples/games/tests/RockPaperScissorsTests.move @@ -31,8 +31,8 @@ module Games::RockPaperScissorsTests { // Now it's time for The Main Guy to accept his turn. TestScenario::next_tx(scenario, &the_main_guy); { - let game = TestScenario::remove_object(scenario); - let cap = TestScenario::remove_object(scenario); + let game = TestScenario::take_object(scenario); + let cap = TestScenario::take_object(scenario); assert!(Game::status(&game) == 0, 0); // STATUS_READY @@ -52,8 +52,8 @@ module Games::RockPaperScissorsTests { TestScenario::next_tx(scenario, &the_main_guy); { - let game = TestScenario::remove_object(scenario); - let cap = TestScenario::remove_object(scenario); + let game = TestScenario::take_object(scenario); + let cap = TestScenario::take_object(scenario); Game::add_hash(&mut game, cap, TestScenario::ctx(scenario)); assert!(Game::status(&game) == 2, 0); // STATUS_HASHES_SUBMITTED @@ -69,8 +69,8 @@ module Games::RockPaperScissorsTests { TestScenario::next_tx(scenario, &the_main_guy); { - let game = TestScenario::remove_object(scenario); - let secret = TestScenario::remove_object(scenario); + let game = TestScenario::take_object(scenario); + let secret = TestScenario::take_object(scenario); Game::match_secret(&mut game, secret, TestScenario::ctx(scenario)); assert!(Game::status(&game) == 3, 0); // STATUS_REVEALING @@ -85,8 +85,8 @@ module Games::RockPaperScissorsTests { // calls the [`select_winner`] function to release The Prize. TestScenario::next_tx(scenario, &the_main_guy); { - let game = TestScenario::remove_object(scenario); - let secret = TestScenario::remove_object(scenario); + let game = TestScenario::take_object(scenario); + let secret = TestScenario::take_object(scenario); Game::match_secret(&mut game, secret, TestScenario::ctx(scenario)); assert!(Game::status(&game) == 4, 0); // STATUS_REVEALED @@ -96,7 +96,7 @@ module Games::RockPaperScissorsTests { TestScenario::next_tx(scenario, &mr_spock); // If it works, then MrSpock is in possession of the prize; - let prize = TestScenario::remove_object(scenario); + let prize = TestScenario::take_object(scenario); // Don't forget to give it back! TestScenario::return_object(scenario, prize); } diff --git a/sui_programmability/examples/games/tests/SharedTicTacToeTests.move b/sui_programmability/examples/games/tests/SharedTicTacToeTests.move index 5c5277592930b..9ebfd30532a1b 100644 --- a/sui_programmability/examples/games/tests/SharedTicTacToeTests.move +++ b/sui_programmability/examples/games/tests/SharedTicTacToeTests.move @@ -72,11 +72,11 @@ module Games::SharedTicTacToeTests { // X has the Trophy TestScenario::next_tx(scenario, &player_x); - assert!(TestScenario::can_remove_object(scenario), 1); + assert!(TestScenario::can_take_object(scenario), 1); TestScenario::next_tx(scenario, &player_o); // O has no Trophy - assert!(!TestScenario::can_remove_object(scenario), 2); + assert!(!TestScenario::can_take_object(scenario), 2); } @@ -182,9 +182,9 @@ module Games::SharedTicTacToeTests { // No one has the trophy TestScenario::next_tx(scenario, &player_x); - assert!(!TestScenario::can_remove_object(scenario), 1); + assert!(!TestScenario::can_take_object(scenario), 1); TestScenario::next_tx(scenario, &player_o); - assert!(!TestScenario::can_remove_object(scenario), 1); + assert!(!TestScenario::can_take_object(scenario), 1); } @@ -199,7 +199,7 @@ module Games::SharedTicTacToeTests { TestScenario::next_tx(scenario, player); let status; { - let game = TestScenario::remove_object(scenario); + let game = TestScenario::take_object(scenario); SharedTicTacToe::place_mark(&mut game, row, col, TestScenario::ctx(scenario)); status = SharedTicTacToe::get_status(&game); TestScenario::return_object(scenario, game); diff --git a/sui_programmability/examples/games/tests/TicTacToeTests.move b/sui_programmability/examples/games/tests/TicTacToeTests.move index 06502bc06b954..5bdbd4857a04d 100644 --- a/sui_programmability/examples/games/tests/TicTacToeTests.move +++ b/sui_programmability/examples/games/tests/TicTacToeTests.move @@ -75,11 +75,11 @@ module Games::TicTacToeTests { // X has the trophy TestScenario::next_tx(scenario, &player_x); - assert!(TestScenario::can_remove_object(scenario), 1); + assert!(TestScenario::can_take_object(scenario), 1); TestScenario::next_tx(scenario, &player_o); // O has no Trophy - assert!(!TestScenario::can_remove_object(scenario), 1); + assert!(!TestScenario::can_take_object(scenario), 1); } @@ -186,9 +186,9 @@ module Games::TicTacToeTests { // No one has the trophy TestScenario::next_tx(scenario, &player_x); - assert!(!TestScenario::can_remove_object(scenario), 1); + assert!(!TestScenario::can_take_object(scenario), 1); TestScenario::next_tx(scenario, &player_o); - assert!(!TestScenario::can_remove_object(scenario), 1); + assert!(!TestScenario::can_take_object(scenario), 1); } fun place_mark( @@ -201,7 +201,7 @@ module Games::TicTacToeTests { // Step 1: player creates a mark and sends it to the game. TestScenario::next_tx(scenario, player); { - let cap = TestScenario::remove_object(scenario); + let cap = TestScenario::take_object(scenario); TicTacToe::send_mark_to_game(&mut cap, *admin, row, col, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, cap); }; @@ -209,8 +209,8 @@ module Games::TicTacToeTests { TestScenario::next_tx(scenario, admin); let status; { - let game = TestScenario::remove_object(scenario); - let mark = TestScenario::remove_object(scenario); + let game = TestScenario::take_object(scenario); + let mark = TestScenario::take_object(scenario); assert!(TicTacToe::mark_player(&mark) == player, 0); assert!(TicTacToe::mark_row(&mark) == row, 1); assert!(TicTacToe::mark_col(&mark) == col, 2); diff --git a/sui_programmability/examples/nfts/sources/Marketplace.move b/sui_programmability/examples/nfts/sources/Marketplace.move index 9c36d806b1591..4d2807df2c831 100644 --- a/sui_programmability/examples/nfts/sources/Marketplace.move +++ b/sui_programmability/examples/nfts/sources/Marketplace.move @@ -170,9 +170,9 @@ module NFTs::MarketplaceTests { // SELLER lists KITTY at the Marketplace for 100 SUI. fun list_kitty(scenario: &mut Scenario) { TestScenario::next_tx(scenario, &SELLER); - let mkp = TestScenario::remove_object(scenario); - let bag = TestScenario::remove_nested_object(scenario, &mkp); - let nft = TestScenario::remove_object>(scenario); + let mkp = TestScenario::take_object(scenario); + let bag = TestScenario::take_nested_object(scenario, &mkp); + let nft = TestScenario::take_object>(scenario); Marketplace::list, SUI>(&mkp, &mut bag, nft, 100, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, mkp); @@ -189,9 +189,9 @@ module NFTs::MarketplaceTests { TestScenario::next_tx(scenario, &SELLER); { - let mkp = TestScenario::remove_object(scenario); - let bag = TestScenario::remove_nested_object(scenario, &mkp); - let listing = TestScenario::remove_nested_object, SUI>>(scenario, &bag); + let mkp = TestScenario::take_object(scenario); + let bag = TestScenario::take_nested_object(scenario, &mkp); + let listing = TestScenario::take_nested_object, SUI>>(scenario, &bag); // Do the delist operation on a Marketplace. let nft = Marketplace::delist, SUI>(&mkp, &mut bag, listing, TestScenario::ctx(scenario)); @@ -217,9 +217,9 @@ module NFTs::MarketplaceTests { // BUYER attempts to delist KITTY and he has no right to do so. :( TestScenario::next_tx(scenario, &BUYER); { - let mkp = TestScenario::remove_object(scenario); - let bag = TestScenario::remove_nested_object(scenario, &mkp); - let listing = TestScenario::remove_nested_object, SUI>>(scenario, &bag); + let mkp = TestScenario::take_object(scenario); + let bag = TestScenario::take_nested_object(scenario, &mkp); + let listing = TestScenario::take_nested_object, SUI>>(scenario, &bag); // Do the delist operation on a Marketplace. let nft = Marketplace::delist, SUI>(&mkp, &mut bag, listing, TestScenario::ctx(scenario)); @@ -242,10 +242,10 @@ module NFTs::MarketplaceTests { // BUYER takes 100 SUI from his wallet and purchases KITTY. TestScenario::next_tx(scenario, &BUYER); { - let coin = TestScenario::remove_object>(scenario); - let mkp = TestScenario::remove_object(scenario); - let bag = TestScenario::remove_nested_object(scenario, &mkp); - let listing = TestScenario::remove_nested_object, SUI>>(scenario, &bag); + let coin = TestScenario::take_object>(scenario); + let mkp = TestScenario::take_object(scenario); + let bag = TestScenario::take_nested_object(scenario, &mkp); + let listing = TestScenario::take_nested_object, SUI>>(scenario, &bag); let payment = Coin::withdraw(&mut coin, 100, TestScenario::ctx(scenario)); // Do the buy call and expect successful purchase. @@ -273,10 +273,10 @@ module NFTs::MarketplaceTests { // BUYER takes 100 SUI from his wallet and purchases KITTY. TestScenario::next_tx(scenario, &BUYER); { - let coin = TestScenario::remove_object>(scenario); - let mkp = TestScenario::remove_object(scenario); - let bag = TestScenario::remove_nested_object(scenario, &mkp); - let listing = TestScenario::remove_nested_object, SUI>>(scenario, &bag); + let coin = TestScenario::take_object>(scenario); + let mkp = TestScenario::take_object(scenario); + let bag = TestScenario::take_nested_object(scenario, &mkp); + let listing = TestScenario::take_nested_object, SUI>>(scenario, &bag); // AMOUNT here is 10 while expected is 100. let payment = Coin::withdraw(&mut coin, 10, TestScenario::ctx(scenario)); diff --git a/sui_programmability/examples/nfts/tests/AuctionTests.move b/sui_programmability/examples/nfts/tests/AuctionTests.move index 1af5cb4816140..eeb40fca5bf30 100644 --- a/sui_programmability/examples/nfts/tests/AuctionTests.move +++ b/sui_programmability/examples/nfts/tests/AuctionTests.move @@ -71,7 +71,7 @@ module NFTs::AuctionTests { // a transaction by the first bidder to create and put a bid TestScenario::next_tx(scenario, &bidder1); { - let coin = TestScenario::remove_object>(scenario); + let coin = TestScenario::take_object>(scenario); Auction::bid(coin, auction_id, auctioneer, TestScenario::ctx(scenario)); }; @@ -79,9 +79,9 @@ module NFTs::AuctionTests { // a transaction by the auctioneer to update state of the auction TestScenario::next_tx(scenario, &auctioneer); { - let auction = TestScenario::remove_object>(scenario); + let auction = TestScenario::take_object>(scenario); - let bid = TestScenario::remove_object(scenario); + let bid = TestScenario::take_object(scenario); Auction::update_auction(&mut auction, bid, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, auction); @@ -91,7 +91,7 @@ module NFTs::AuctionTests { // bidder's) TestScenario::next_tx(scenario, &bidder2); { - let coin = TestScenario::remove_object>(scenario); + let coin = TestScenario::take_object>(scenario); Auction::bid(coin, auction_id, auctioneer, TestScenario::ctx(scenario)); }; @@ -99,9 +99,9 @@ module NFTs::AuctionTests { // a transaction by the auctioneer to update state of the auction TestScenario::next_tx(scenario, &auctioneer); { - let auction = TestScenario::remove_object>(scenario); + let auction = TestScenario::take_object>(scenario); - let bid = TestScenario::remove_object(scenario); + let bid = TestScenario::take_object(scenario); Auction::update_auction(&mut auction, bid, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, auction); @@ -110,7 +110,7 @@ module NFTs::AuctionTests { // a transaction by the auctioneer to end auction TestScenario::next_tx(scenario, &auctioneer); { - let auction = TestScenario::remove_object>(scenario); + let auction = TestScenario::take_object>(scenario); Auction::end_auction(auction, TestScenario::ctx(scenario)); }; @@ -119,7 +119,7 @@ module NFTs::AuctionTests { // second bidder's bid was the same as that of the first one) TestScenario::next_tx(scenario, &bidder1); { - let acquired_item = TestScenario::remove_object(scenario); + let acquired_item = TestScenario::take_object(scenario); assert!(acquired_item.value == 42, EWRONG_ITEM_VALUE); diff --git a/sui_programmability/examples/nfts/tests/DiscountCouponTests.move b/sui_programmability/examples/nfts/tests/DiscountCouponTests.move index 3f9deddd87f41..bdf0733280454 100644 --- a/sui_programmability/examples/nfts/tests/DiscountCouponTests.move +++ b/sui_programmability/examples/nfts/tests/DiscountCouponTests.move @@ -34,16 +34,16 @@ module NFTs::DiscountCouponTests { // Mint and transfer NFT + top up recipient's address. TestScenario::next_tx(scenario, &ISSUER_ADDRESS); - { - let coin = TestScenario::remove_object>(scenario); + { + let coin = TestScenario::take_object>(scenario); DiscountCoupon::mint_and_topup(coin, 10, 1648820870, USER1_ADDRESS, TestScenario::ctx(scenario)); }; TestScenario::next_tx(scenario, &USER1_ADDRESS); { - assert!(TestScenario::can_remove_object>(scenario), 0); - let nft_coupon = TestScenario::remove_object>(scenario); // if can remove, object exists - assert!(DiscountCoupon::issuer(NFT::data(&nft_coupon)) == ISSUER_ADDRESS, 0); + assert!(TestScenario::can_take_object>(scenario), 0); + let nft_coupon = TestScenario::take_object>(scenario); // if can remove, object exists + assert!(DiscountCoupon::issuer(NFT::data(&nft_coupon)) == ISSUER_ADDRESS, 0); TestScenario::return_object(scenario, nft_coupon); } } diff --git a/sui_programmability/examples/nfts/tests/SharedAuctionTests.move b/sui_programmability/examples/nfts/tests/SharedAuctionTests.move index 0512adc62ffb7..791831b0a2a53 100644 --- a/sui_programmability/examples/nfts/tests/SharedAuctionTests.move +++ b/sui_programmability/examples/nfts/tests/SharedAuctionTests.move @@ -68,8 +68,8 @@ module NFTs::SharedAuctionTests { // a transaction by the first bidder to put a bid TestScenario::next_tx(scenario, &bidder1); { - let coin = TestScenario::remove_object>(scenario); - let auction = TestScenario::remove_object>(scenario); + let coin = TestScenario::take_object>(scenario); + let auction = TestScenario::take_object>(scenario); SharedAuction::bid(coin, &mut auction, TestScenario::ctx(scenario)); @@ -81,8 +81,8 @@ module NFTs::SharedAuctionTests { // bidder's) TestScenario::next_tx(scenario, &bidder2); { - let coin = TestScenario::remove_object>(scenario); - let auction = TestScenario::remove_object>(scenario); + let coin = TestScenario::take_object>(scenario); + let auction = TestScenario::take_object>(scenario); SharedAuction::bid(coin, &mut auction, TestScenario::ctx(scenario)); @@ -93,7 +93,7 @@ module NFTs::SharedAuctionTests { // have been returned (as a result of the failed bid). TestScenario::next_tx(scenario, &bidder2); { - let coin = TestScenario::remove_object>(scenario); + let coin = TestScenario::take_object>(scenario); assert!(Coin::value(&coin) == COIN_VALUE, EWRONG_COIN_VALUE); @@ -103,7 +103,7 @@ module NFTs::SharedAuctionTests { // a transaction by the owner to end auction TestScenario::next_tx(scenario, &owner); { - let auction = TestScenario::remove_object>(scenario); + let auction = TestScenario::take_object>(scenario); // pass auction as mutable reference as its a shared // object that cannot be deleted @@ -116,7 +116,7 @@ module NFTs::SharedAuctionTests { // second bidder's bid was the same as that of the first one) TestScenario::next_tx(scenario, &bidder1); { - let acquired_item = TestScenario::remove_object(scenario); + let acquired_item = TestScenario::take_object(scenario); assert!(acquired_item.value == 42, EWRONG_ITEM_VALUE); diff --git a/sui_programmability/framework/sources/TestScenario.move b/sui_programmability/framework/sources/TestScenario.move index 3ba70b3ab8a41..327ecf397cb74 100644 --- a/sui_programmability/framework/sources/TestScenario.move +++ b/sui_programmability/framework/sources/TestScenario.move @@ -17,7 +17,7 @@ module Sui::TestScenario { /// Attempted to return an object to the inventory that was not previously removed from the /// inventory during the current transaction. Can happen if the user attempts to call /// `return_object` on a locally constructed object rather than one returned from a `TestScenario` - /// function such as `remove_object`. + /// function such as `take_object`. const ECANT_RETURN_OBJECT: u64 = 2; /// Attempted to retrieve an object of a particular type from the inventory, but it is empty. @@ -26,7 +26,7 @@ module Sui::TestScenario { const EEMPTY_INVENTORY: u64 = 3; /// Expected 1 object of this type in the tx sender's inventory, but found >1. - /// Consider using TestScenario::remove_object_by_id to select a specific object + /// Consider using TestScenario::take_object_by_id to select a specific object const EINVENTORY_AMBIGUITY: u64 = 4; /// The inventory previously contained an object of this type, but it was removed during the current @@ -41,7 +41,7 @@ module Sui::TestScenario { /// Utility for mocking a multi-transaction Sui execution in a single Move procedure. /// A `Scenario` maintains a view of the global object pool built up by the execution. - /// These objects can be accessed via functions like `remove_object`, which gives the + /// These objects can be accessed via functions like `take_object`, which gives the /// transaction sender access to (only) objects in their inventory. /// Example usage: /// ``` @@ -58,7 +58,7 @@ module Sui::TestScenario { /// TestScenario::next_tx(scenario, &addr2) /// { /// // remove the SomeObject value from addr2's inventory - /// let obj = TestScenario::remove_object(scenario); + /// let obj = TestScenario::take_object(scenario); /// // use it to test some function that needs this value /// SomeObject::some_function(obj) /// } @@ -129,8 +129,8 @@ module Sui::TestScenario { /// Aborts if there is no object of type `T` in the inventory of the tx sender /// Aborts if there is >1 object of type `T` in the inventory of the tx sender--this function /// only succeeds when the object to choose is unambiguous. In cases where there are multiple `T`'s, - /// the caller should resolve the ambiguity by using `remove_object_by_id`. - public fun remove_object(scenario: &mut Scenario): T { + /// the caller should resolve the ambiguity by using `take_object_by_id`. + public fun take_object(scenario: &mut Scenario): T { let sender = sender(scenario); remove_unique_object(scenario, sender) } @@ -139,17 +139,17 @@ module Sui::TestScenario { /// Aborts if there is no object of type `T2` owned by `parent_obj` /// Aborts if there is >1 object of type `T2` owned by `parent_obj`--this function /// only succeeds when the object to choose is unambiguous. In cases where there are are multiple `T`'s - /// owned by `parent_obj`, the caller should resolve the ambiguity using `remove_nested_object_by_id`. - public fun remove_nested_object( + /// owned by `parent_obj`, the caller should resolve the ambiguity using `take_nested_object_by_id`. + public fun take_nested_object( scenario: &mut Scenario, parent_obj: &T1 ): T2 { remove_unique_object(scenario, ID::id_address(ID::id(parent_obj))) } - /// Same as `remove_object`, but returns the object of type `T` with object ID `id`. + /// Same as `take_object`, but returns the object of type `T` with object ID `id`. /// Should only be used in cases where current tx sender has more than one object of /// type `T` in their inventory. - public fun remove_object_by_id(scenario: &mut Scenario, id: ID): T { + public fun take_object_by_id(scenario: &mut Scenario, id: ID): T { let object_opt: Option = find_object_by_id_in_inventory(scenario, &id); assert!(Option::is_some(&object_opt), EOBJECT_ID_NOT_FOUND); @@ -162,9 +162,9 @@ module Sui::TestScenario { object } - /// This function tells you whether calling `remove_object_by_id` would succeed. + /// This function tells you whether calling `take_object_by_id` would succeed. /// It provides a way to check without triggering assertions. - public fun can_remove_object_by_id(scenario: &Scenario, id: ID): bool { + public fun can_take_object_by_id(scenario: &Scenario, id: ID): bool { let object_opt: Option = find_object_by_id_in_inventory(scenario, &id); if (Option::is_none(&object_opt)) { Option::destroy_none(object_opt); @@ -177,9 +177,9 @@ module Sui::TestScenario { return !Vector::contains(&scenario.removed, &id) } - /// Same as `remove_nested_object`, but returns the child object of type `T` with object ID `id`. + /// Same as `take_nested_object`, but returns the child object of type `T` with object ID `id`. /// Should only be used in cases where the parent object has more than one child of type `T`. - public fun remove_nested_object_by_id( + public fun take_nested_object_by_id( _scenario: &mut Scenario, _parent_obj: &T1, _child_id: ID ): T2 { // TODO: implement me @@ -187,9 +187,9 @@ module Sui::TestScenario { } /// Return `t` to the global object pool maintained by `scenario`. - /// Subsequent calls to `remove_object` will succeed if the object is in the inventory of the current + /// Subsequent calls to `take_object` will succeed if the object is in the inventory of the current /// transaction sender. - /// Aborts if `t` was not previously removed from the inventory via a call to `remove_object` or similar. + /// Aborts if `t` was not previously taken from the inventory via a call to `take_object` or similar. public fun return_object(scenario: &mut Scenario, t: T) { let id = ID::id(&t); let removed = &mut scenario.removed; @@ -206,8 +206,8 @@ module Sui::TestScenario { update_object(t) } - /// Return `true` if a call to `remove_object(scenario)` will succeed - public fun can_remove_object(scenario: &Scenario): bool { + /// Return `true` if a call to `take_object(scenario)` will succeed + public fun can_take_object(scenario: &Scenario): bool { let objects: vector = get_inventory( sender(scenario), last_tx_start_index(scenario) diff --git a/sui_programmability/framework/tests/BagTests.move b/sui_programmability/framework/tests/BagTests.move index 90d514bc491e6..d0f97cc4c8741 100644 --- a/sui_programmability/framework/tests/BagTests.move +++ b/sui_programmability/framework/tests/BagTests.move @@ -33,7 +33,7 @@ module Sui::BagTests { // Add two objects of different types into the bag. TestScenario::next_tx(scenario, &sender); { - let bag = TestScenario::remove_object(scenario); + let bag = TestScenario::take_object(scenario); assert!(Bag::size(&bag) == 0, EBAG_SIZE_MISMATCH); let obj1 = Object1 { id: TxContext::new_id(TestScenario::ctx(scenario)) }; diff --git a/sui_programmability/framework/tests/CollectionTests.move b/sui_programmability/framework/tests/CollectionTests.move index 0364e7d1ddeee..2964f232b5f28 100644 --- a/sui_programmability/framework/tests/CollectionTests.move +++ b/sui_programmability/framework/tests/CollectionTests.move @@ -27,7 +27,7 @@ module Sui::CollectionTests { // Add two objects of different types into the collection. TestScenario::next_tx(scenario, &sender); { - let collection = TestScenario::remove_object>(scenario); + let collection = TestScenario::take_object>(scenario); assert!(Collection::size(&collection) == 0, 0); let obj1 = Object { id: TxContext::new_id(TestScenario::ctx(scenario)) }; @@ -61,7 +61,7 @@ module Sui::CollectionTests { // Add a new object to the Collection. TestScenario::next_tx(scenario, &sender); { - let collection = TestScenario::remove_object>(scenario); + let collection = TestScenario::take_object>(scenario); let obj = Object { id: TxContext::new_id(TestScenario::ctx(scenario)) }; Collection::add(&mut collection, obj); TestScenario::return_object(scenario, collection); @@ -70,9 +70,9 @@ module Sui::CollectionTests { // Remove the object from the collection and add it to the bag. TestScenario::next_tx(scenario, &sender); { - let collection = TestScenario::remove_object>(scenario); - let bag = TestScenario::remove_object(scenario); - let obj = TestScenario::remove_nested_object, Object>(scenario, &collection); + let collection = TestScenario::take_object>(scenario); + let bag = TestScenario::take_object(scenario); + let obj = TestScenario::take_nested_object, Object>(scenario, &collection); let id = *ID::id(&obj); let (obj, child_ref) = Collection::remove(&mut collection, obj); @@ -89,9 +89,9 @@ module Sui::CollectionTests { // Remove the object from the bag and add it back to the collection. TestScenario::next_tx(scenario, &sender); { - let collection = TestScenario::remove_object>(scenario); - let bag = TestScenario::remove_object(scenario); - let obj = TestScenario::remove_nested_object(scenario, &bag); + let collection = TestScenario::take_object>(scenario); + let bag = TestScenario::take_object(scenario); + let obj = TestScenario::take_nested_object(scenario, &bag); let id = *ID::id(&obj); let obj = Bag::remove(&mut bag, obj); diff --git a/sui_programmability/framework/tests/CrossChainAirdropTests.move b/sui_programmability/framework/tests/CrossChainAirdropTests.move index 718a07f5f1c16..6e9ec041a70bf 100644 --- a/sui_programmability/framework/tests/CrossChainAirdropTests.move +++ b/sui_programmability/framework/tests/CrossChainAirdropTests.move @@ -31,13 +31,13 @@ module Sui::CrossChainAirdropTests { // claim a token claim_token(&mut scenario, &oracle_address, SOURCE_TOKEN_ID); - + // verify that the recipient has received the nft assert!(owns_object(&mut scenario, &RECIPIENT_ADDRESS), EOBJECT_NOT_FOUND); } #[test] - #[expected_failure(abort_code = 0)] + #[expected_failure(abort_code = 0)] fun test_double_claim() { let (scenario, oracle_address) = init(); @@ -60,7 +60,7 @@ module Sui::CrossChainAirdropTests { fun claim_token(scenario: &mut Scenario, oracle_address: &address, token_id: u64) { TestScenario::next_tx(scenario, oracle_address); { - let oracle = TestScenario::remove_object(scenario); + let oracle = TestScenario::take_object(scenario); let ctx = TestScenario::ctx(scenario); CrossChainAirdrop::claim( &mut oracle, @@ -78,6 +78,6 @@ module Sui::CrossChainAirdropTests { fun owns_object(scenario: &mut Scenario, owner: &address): bool{ // Verify the token has been transfer to the recipient TestScenario::next_tx(scenario, owner); - TestScenario::can_remove_object>(scenario) + TestScenario::can_take_object>(scenario) } } diff --git a/sui_programmability/framework/tests/TestScenarioTests.move b/sui_programmability/framework/tests/TestScenarioTests.move index 85a8b906ac003..1084d918fa929 100644 --- a/sui_programmability/framework/tests/TestScenarioTests.move +++ b/sui_programmability/framework/tests/TestScenarioTests.move @@ -34,15 +34,15 @@ module Sui::TestScenarioTests { TestScenario::next_tx(&mut scenario, &sender); { let id = TestScenario::new_id(&mut scenario); - let child = TestScenario::remove_object(&mut scenario); + let child = TestScenario::take_object(&mut scenario); let wrapper = Wrapper { id, child }; Transfer::transfer(wrapper, copy sender); }; // wrapped object should no longer be removable, but wrapper should be TestScenario::next_tx(&mut scenario, &sender); { - assert!(!TestScenario::can_remove_object(&scenario), 0); - assert!(TestScenario::can_remove_object(&scenario), 1); + assert!(!TestScenario::can_take_object(&scenario), 0); + assert!(TestScenario::can_take_object(&scenario), 1); } } @@ -58,13 +58,13 @@ module Sui::TestScenarioTests { // object gets removed, then returned TestScenario::next_tx(&mut scenario, &sender); { - let object = TestScenario::remove_object(&mut scenario); + let object = TestScenario::take_object(&mut scenario); TestScenario::return_object(&mut scenario, object); }; // Object should remain accessible TestScenario::next_tx(&mut scenario, &sender); { - assert!(TestScenario::can_remove_object(&scenario), 0); + assert!(TestScenario::can_take_object(&scenario), 0); } } @@ -79,14 +79,14 @@ module Sui::TestScenarioTests { }; TestScenario::next_tx(&mut scenario, &sender); { - let obj = TestScenario::remove_object(&mut scenario); + let obj = TestScenario::take_object(&mut scenario); assert!(obj.value == 10, 0); obj.value = 100; TestScenario::return_object(&mut scenario, obj); }; TestScenario::next_tx(&mut scenario, &sender); { - let obj = TestScenario::remove_object(&mut scenario); + let obj = TestScenario::take_object(&mut scenario); assert!(obj.value == 100, 1); TestScenario::return_object(&mut scenario, obj); } @@ -101,7 +101,7 @@ module Sui::TestScenarioTests { let obj = Object { id, value: 10 }; Transfer::transfer(obj, copy sender); // an object transferred during the tx shouldn't be available in that tx - assert!(!TestScenario::can_remove_object(&scenario), 0) + assert!(!TestScenario::can_take_object(&scenario), 0) }; } @@ -117,8 +117,8 @@ module Sui::TestScenarioTests { }; TestScenario::next_tx(&mut scenario, &sender); { - let obj1 = TestScenario::remove_object(&mut scenario); - let obj2 = TestScenario::remove_object(&mut scenario); + let obj1 = TestScenario::take_object(&mut scenario); + let obj2 = TestScenario::take_object(&mut scenario); TestScenario::return_object(&mut scenario, obj1); TestScenario::return_object(&mut scenario, obj2); } @@ -141,34 +141,34 @@ module Sui::TestScenarioTests { // addr1 -> addr2 TestScenario::next_tx(&mut scenario, &addr1); { - let obj = TestScenario::remove_object(&mut scenario); + let obj = TestScenario::take_object(&mut scenario); Transfer::transfer(obj, copy addr2) }; // addr1 cannot access TestScenario::next_tx(&mut scenario, &addr1); { - assert!(!TestScenario::can_remove_object(&scenario), 0); + assert!(!TestScenario::can_take_object(&scenario), 0); }; // addr2 -> addr3 TestScenario::next_tx(&mut scenario, &addr2); { - let obj = TestScenario::remove_object(&mut scenario); + let obj = TestScenario::take_object(&mut scenario); Transfer::transfer(obj, copy addr3) }; // addr1 cannot access TestScenario::next_tx(&mut scenario, &addr1); { - assert!(!TestScenario::can_remove_object(&scenario), 0); + assert!(!TestScenario::can_take_object(&scenario), 0); }; // addr2 cannot access TestScenario::next_tx(&mut scenario, &addr2); { - assert!(!TestScenario::can_remove_object(&scenario), 0); + assert!(!TestScenario::can_take_object(&scenario), 0); }; // addr3 *can* access TestScenario::next_tx(&mut scenario, &addr3); { - assert!(TestScenario::can_remove_object(&scenario), 0); + assert!(TestScenario::can_take_object(&scenario), 0); } } @@ -185,13 +185,13 @@ module Sui::TestScenarioTests { let obj = Object { id, value: 100 }; Transfer::transfer(obj, copy tx2_sender); // sender cannot access the object - assert!(!TestScenario::can_remove_object(&scenario), 0); + assert!(!TestScenario::can_take_object(&scenario), 0); }; // check that tx2_sender can get the object, and it's the same one TestScenario::next_tx(&mut scenario, &tx2_sender); { - assert!(TestScenario::can_remove_object(&scenario), 1); - let received_obj = TestScenario::remove_object(&mut scenario); + assert!(TestScenario::can_take_object(&scenario), 1); + let received_obj = TestScenario::take_object(&mut scenario); let Object { id: received_id, value } = received_obj; assert!(ID::inner(&received_id) == &id_bytes, ID_BYTES_MISMATCH); assert!(value == 100, VALUE_MISMATCH); @@ -200,12 +200,12 @@ module Sui::TestScenarioTests { // check that the object is no longer accessible after deletion TestScenario::next_tx(&mut scenario, &tx2_sender); { - assert!(!TestScenario::can_remove_object(&scenario), 2); + assert!(!TestScenario::can_take_object(&scenario), 2); } } #[test] - fun test_remove_object_by_id() { + fun test_take_object_by_id() { let sender = @0x0; let scenario = TestScenario::begin(&sender); let versioned_id1 = TestScenario::new_id(&mut scenario); @@ -225,20 +225,20 @@ module Sui::TestScenarioTests { TestScenario::next_tx(&mut scenario, &sender); { assert!( - TestScenario::can_remove_object_by_id(&mut scenario, id1), + TestScenario::can_take_object_by_id(&mut scenario, id1), OBJECT_ID_NOT_FOUND ); assert!( - TestScenario::can_remove_object_by_id(&mut scenario, id2), + TestScenario::can_take_object_by_id(&mut scenario, id2), OBJECT_ID_NOT_FOUND ); assert!( - TestScenario::can_remove_object_by_id(&mut scenario, id3), + TestScenario::can_take_object_by_id(&mut scenario, id3), OBJECT_ID_NOT_FOUND ); - let obj1 = TestScenario::remove_object_by_id(&mut scenario, id1); - let obj3 = TestScenario::remove_object_by_id(&mut scenario, id3); - let obj2 = TestScenario::remove_object_by_id(&mut scenario, id2); + let obj1 = TestScenario::take_object_by_id(&mut scenario, id1); + let obj3 = TestScenario::take_object_by_id(&mut scenario, id3); + let obj2 = TestScenario::take_object_by_id(&mut scenario, id2); assert!(obj1.value == 10, VALUE_MISMATCH); assert!(obj2.value == 20, VALUE_MISMATCH); assert!(obj3.value == 30, VALUE_MISMATCH); @@ -259,7 +259,7 @@ module Sui::TestScenarioTests { }; TestScenario::next_tx(&mut scenario, &sender); { - let obj = TestScenario::remove_object(&mut scenario); + let obj = TestScenario::take_object(&mut scenario); // Transfer an immutable object, this won't fail right away. Transfer::transfer(obj, copy sender); }; @@ -267,7 +267,7 @@ module Sui::TestScenarioTests { { // while removing the object, test scenario will read the inventory, // and discover that we transferred an immutable object. - let obj = TestScenario::remove_object(&mut scenario); + let obj = TestScenario::take_object(&mut scenario); TestScenario::return_object(&mut scenario, obj); }; } @@ -283,7 +283,7 @@ module Sui::TestScenarioTests { }; TestScenario::next_tx(&mut scenario, &sender); { - let obj = TestScenario::remove_object(&mut scenario); + let obj = TestScenario::take_object(&mut scenario); obj.value = 200; TestScenario::return_object(&mut scenario, obj); }; diff --git a/sui_programmability/tutorial/sources/M1.move b/sui_programmability/tutorial/sources/M1.move index 9efa016f3ae6f..d4378e3688cbd 100644 --- a/sui_programmability/tutorial/sources/M1.move +++ b/sui_programmability/tutorial/sources/M1.move @@ -78,7 +78,7 @@ module MyFirstPackage::M1 { TestScenario::next_tx(scenario, &admin); { // extract the Forge object - let forge = TestScenario::remove_object(scenario); + let forge = TestScenario::take_object(scenario); // verify number of created swords assert!(swords_created(&forge) == 0, 1); // return the Forge object to the object pool @@ -103,7 +103,7 @@ module MyFirstPackage::M1 { // second transaction executed by admin to create the sword TestScenario::next_tx(scenario, &admin); { - let forge = TestScenario::remove_object(scenario); + let forge = TestScenario::take_object(scenario); // create the sword and transfer it to the initial owner sword_create(&mut forge, 42, 7, initial_owner, TestScenario::ctx(scenario)); TestScenario::return_object(scenario, forge) @@ -112,7 +112,7 @@ module MyFirstPackage::M1 { TestScenario::next_tx(scenario, &initial_owner); { // extract the sword owned by the initial owner - let sword = TestScenario::remove_object(scenario); + let sword = TestScenario::take_object(scenario); // transfer the sword to the final owner sword_transfer(sword, final_owner, TestScenario::ctx(scenario)); }; @@ -121,7 +121,7 @@ module MyFirstPackage::M1 { { // extract the sword owned by the final owner - let sword = TestScenario::remove_object(scenario); + let sword = TestScenario::take_object(scenario); // verify that the sword has expected properties assert!(magic(&sword) == 42 && strength(&sword) == 7, 1); // return the sword to the object pool (it cannot be simply "dropped")