From ca37ecc050f3b47d01ad36a550d91b17da524705 Mon Sep 17 00:00:00 2001 From: Damir S Date: Wed, 15 Jun 2022 19:41:01 +0300 Subject: [PATCH] [chore, move] Lowercase all the modules and addresses (#2558) --- Cargo.lock | 8 +- crates/generate-json-rpc-spec/src/main.rs | 2 +- .../tests/call/simple.exp | 2 +- .../tests/call/simple.move | 12 +- .../children/child_of_shared_object.move | 36 +- .../tests/entry_points/no_txn_context.move | 10 +- .../tests/entry_points/wrong_visibility.move | 2 +- .../tests/publish/init.exp | 2 +- .../tests/publish/init.move | 10 +- .../tests/publish/init_param.exp | 2 +- .../tests/publish/init_param.move | 10 +- .../tests/publish/init_public.move | 10 +- .../tests/publish/init_ret.move | 10 +- .../tests/sui/coin_transfer.exp | 10 +- .../tests/sui/coin_transfer.move | 4 +- .../tests/sui/freeze.move | 8 +- .../sui/move_call_incorrect_function.exp | 4 +- .../sui/move_call_incorrect_function.move | 4 +- .../tests/sui/object_basics.exp | 6 +- .../tests/sui/object_basics.move | 10 +- .../tests/sui/unwrap.exp | 4 +- .../tests/sui/unwrap.move | 6 +- crates/sui-adapter/src/adapter.rs | 2 +- crates/sui-cluster-test/src/main.rs | 2 +- .../sui-core/src/authority/authority_store.rs | 2 +- .../unit_tests/authority_aggregator_tests.rs | 10 +- .../src/unit_tests/authority_tests.rs | 16 +- .../src/unit_tests/batch_transaction_tests.rs | 6 +- .../src/unit_tests/consensus_tests.rs | 2 +- .../src/unit_tests/data/hero/Move.toml | 2 +- .../hero/sources/{Hero.move => hero.move} | 110 +++--- .../{TrustedCoin.move => trusted_coin.move} | 18 +- .../unit_tests/data/object_owner/Move.toml | 4 +- .../{ObjectOwner.move => object_owner.move} | 44 +-- .../unit_tests/data/object_wrapping/Move.toml | 4 +- ...jectWrapping.move => object_wrapping.move} | 28 +- crates/sui-core/src/unit_tests/gas_tests.rs | 2 +- .../src/unit_tests/gateway_state_tests.rs | 6 +- .../src/unit_tests/move_integration_tests.rs | 38 +- crates/sui-framework/Move.toml | 2 +- crates/sui-framework/README.md | 2 +- .../sources/{Bag.move => bag.move} | 24 +- .../sources/{Balance.move => balance.move} | 44 +-- .../sources/{Coin.move => coin.move} | 58 +-- .../{Collection.move => collection.move} | 28 +- .../{DevNetNFT.move => devnet_nft.move} | 82 ++-- ...pochTimeLock.move => epoch_time_lock.move} | 8 +- ...C721Metadata.move => erc721_metadata.move} | 14 +- .../sources/{Event.move => event.move} | 2 +- .../delegation.move} | 50 +-- .../epoch_reward_record.move} | 18 +- .../Genesis.move => governance/genesis.move} | 22 +- .../sui_system.move} | 112 +++--- .../validator.move} | 44 +-- .../validator_set.move} | 60 +-- .../sources/{ID.move => id.move} | 12 +- .../{LockedCoin.move => locked_coin.move} | 36 +- .../sources/{Math.move => math.move} | 28 +- .../{ObjectBasics.move => object_basics.move} | 28 +- .../sources/{SUI.move => sui.move} | 16 +- .../{TestScenario.move => test_scenario.move} | 46 +-- .../sources/{Transfer.move => transfer.move} | 28 +- .../{TxContext.move => tx_context.move} | 10 +- .../sources/{Url.move => url.move} | 2 +- .../sources/{UTF8.move => utf8.move} | 2 +- crates/sui-framework/src/natives/event.rs | 2 +- crates/sui-framework/src/natives/mod.rs | 34 +- .../src/natives/test_scenario.rs | 2 +- crates/sui-framework/tests/BagTests.move | 86 ---- .../sui-framework/tests/CoinBalanceTests.move | 90 ----- .../sui-framework/tests/CollectionTests.move | 140 ------- crates/sui-framework/tests/IDTests.move | 25 -- .../tests/TestScenarioTests.move | 372 ------------------ .../sui-framework/tests/TxContextTests.move | 24 -- .../tests/ValidatorSetTests.move | 96 ----- .../sui-framework/tests/ValidatorTests.move | 82 ---- crates/sui-framework/tests/bag_tests.move | 86 ++++ .../tests/coin_balance_tests.move | 90 +++++ .../sui-framework/tests/collection_tests.move | 140 +++++++ crates/sui-framework/tests/id_tests.move | 25 ++ .../tests/{MathTests.move => math_tests.move} | 28 +- .../tests/test_scenario_tests.move | 372 ++++++++++++++++++ .../sui-framework/tests/tx_context_tests.move | 24 ++ .../tests/{UrlTests.move => url_tests.move} | 24 +- .../tests/validator_set_tests.move | 96 +++++ .../sui-framework/tests/validator_tests.move | 82 ++++ crates/sui-json-rpc-api/src/rpc_types.rs | 14 +- .../src/unit_tests/gateway_types_tests.rs | 6 +- crates/sui-json/src/tests.rs | 6 +- crates/sui-open-rpc/samples/objects.json | 10 +- .../sui-open-rpc/samples/owned_objects.json | 298 ++++++++------ crates/sui-open-rpc/samples/transactions.json | 24 +- .../src/test_adapter.rs | 4 +- crates/sui-types/src/balance.rs | 6 +- crates/sui-types/src/base_types.rs | 4 +- crates/sui-types/src/coin.rs | 8 +- crates/sui-types/src/gas_coin.rs | 6 +- crates/sui-types/src/id.rs | 16 +- crates/sui-types/src/sui_system_state.rs | 10 +- .../generic_and_generic_object_params.exp | 3 +- .../generic_and_generic_object_params.mvir | 4 +- .../generic_param_after_primitive.exp | 3 +- .../generic_param_after_primitive.mvir | 4 +- .../generic_with_key_invalid.mvir | 8 +- .../entry_points/generic_with_key_valid.mvir | 4 +- .../tests/entry_points/id.exp | 3 +- .../tests/entry_points/id.mvir | 4 +- .../nested_generic_vector_param.mvir | 4 +- .../nested_key_generic_vector_param.mvir | 4 +- .../tests/entry_points/non_key_struct.mvir | 4 +- .../entry_points/non_key_struct_generic.exp | 4 +- .../entry_points/non_key_struct_generic.mvir | 8 +- .../non_key_struct_generic_valid.exp | 3 +- .../non_key_struct_generic_valid.mvir | 4 +- .../entry_points/non_key_struct_vector.mvir | 4 +- .../tests/entry_points/option.mvir | 4 +- .../entry_points/optional_txn_context.exp | 3 +- .../entry_points/optional_txn_context.mvir | 4 +- .../tests/entry_points/return_values.mvir | 16 +- .../single_generic_vector_param.mvir | 4 +- .../tests/entry_points/single_type_param.mvir | 4 +- .../single_type_param_generic_object.exp | 3 +- .../single_type_param_generic_object.mvir | 4 +- .../entry_points/single_type_param_key.mvir | 4 +- .../tests/global_storage_access/all.exp | 2 +- .../global_storage_access/borrow_global.exp | 4 +- .../borrow_global_mut.exp | 4 +- .../tests/global_storage_access/exists.exp | 4 +- .../tests/global_storage_access/move_from.exp | 4 +- .../tests/global_storage_access/move_to.exp | 4 +- ...mut_borrow_generic_key_struct_id_field.exp | 2 +- .../mut_borrow_key_struct_id_field.exp | 2 +- .../mut_borrow_key_struct_non_id_field.exp | 3 +- .../mut_borrow_non_key_struct_id_field.exp | 3 +- .../id_leak/direct_leak_through_call.exp | 2 +- .../id_leak/indirect_leak_through_call.exp | 2 +- .../tests/id_leak/through_direct_return.exp | 2 +- .../tests/id_leak/through_indirect_return.exp | 2 +- .../tests/id_leak/through_reference.exp | 2 +- .../tests/id_leak/through_vector.exp | 2 +- .../tests/init/cannot_call_init.mvir | 6 +- .../tests/init/must_have_txn_context.exp | 4 +- .../tests/init/must_have_txn_context.mvir | 6 +- .../tests/init/not_generic.mvir | 4 +- .../tests/init/not_private.mvir | 12 +- .../tests/init/not_txn_context.exp | 8 +- .../tests/init/not_txn_context.mvir | 12 +- .../tests/init/return_values.mvir | 4 +- .../key_struct_first_field_not_id.exp | 2 +- ...ruct_id_field_incorrect_struct_address.exp | 2 +- ..._struct_id_field_incorrect_struct_name.exp | 2 +- .../key_struct_id_field_incorrect_type.exp | 2 +- .../key_struct_id_field_valid.exp | 3 +- .../key_struct_second_field_id.exp | 2 +- .../struct_with_key/key_struct_with_drop.exp | 2 +- .../sui-verifier/src/entry_points_verifier.rs | 2 +- crates/sui-verifier/src/id_leak_verifier.rs | 8 +- crates/sui-verifier/src/private_transfer.rs | 8 +- .../src/struct_with_key_verifier.rs | 4 +- .../tests/common/module_builder.rs | 4 +- .../sui/src/benchmark/transaction_creator.rs | 2 +- crates/sui/src/unit_tests/cli_tests.rs | 12 +- .../data/custom_genesis_package_1/Move.toml | 2 +- ...leObjects.move => combinable_objects.move} | 30 +- ...plate.move => custom_object_template.move} | 18 +- .../{TicTacToe.move => tic_tac_toe.move} | 48 +-- .../{TrustedCoin.move => trusted_coin.move} | 18 +- .../custom_genesis_package_2/sources/M1.move | 10 +- .../data/dummy_modules_publish/Move.toml | 2 +- .../{TrustedCoin.move => trusted_coin.move} | 18 +- crates/sui/src/unit_tests/rpc_server_tests.rs | 2 +- crates/sui/src/wallet_commands.rs | 4 +- crates/sui/tests/checkpoints_tests.rs | 4 +- crates/sui/tests/shared_objects_tests.rs | 28 +- crates/test-utils/src/messages.rs | 2 +- doc/src/build/json-rpc.md | 4 +- doc/src/build/move.md | 122 +++--- .../ch1-object-basics.md | 54 +-- .../ch2-using-objects.md | 86 ++-- .../ch3-immutable-objects.md | 42 +- .../ch4-object-wrapping.md | 52 +-- .../ch5-child-objects.md | 64 +-- doc/src/build/transactions.md | 6 +- doc/src/build/wallet.md | 34 +- doc/src/contribute/observability.md | 2 +- doc/src/explore/devnet.md | 4 +- doc/src/explore/prototypes.md | 14 +- .../client/src/utils/static/mock_data.json | 32 +- explorer/client/src/utils/stringUtils.ts | 2 +- .../src/airdrop/airdropService.ts | 2 +- .../src/sdk/gateway-generated-schema.ts | 4 +- sdk/typescript/README.md | 6 +- sdk/typescript/src/types/framework.ts | 4 +- sdk/typescript/src/types/objects.ts | 2 +- sui_programmability/examples/basics/Move.toml | 2 +- .../examples/basics/sources/Counter.move | 114 ------ .../examples/basics/sources/Sandwich.move | 178 --------- .../examples/basics/sources/counter.move | 114 ++++++ .../basics/sources/{Lock.move => lock.move} | 70 ++-- .../sources/{Object.move => object.move} | 18 +- .../examples/basics/sources/sandwich.move | 178 +++++++++ sui_programmability/examples/defi/Move.toml | 2 +- .../defi/sources/{Escrow.move => escrow.move} | 30 +- .../{FlashLender.move => flash_lender.move} | 46 +-- .../{SharedEscrow.move => shared_escrow.move} | 26 +- .../examples/defi/tests/FlashLenderTests.move | 61 --- .../{EscrowTests.move => escrow_tests.move} | 62 +-- .../defi/tests/flash_lender_tests.move | 61 +++ ...scrowTest.move => shared_escrow_test.move} | 72 ++-- .../examples/fungible_tokens/Move.toml | 2 +- .../sources/{BASKET.move => basket.move} | 50 +-- .../sources/{MANAGED.move => managed.move} | 18 +- .../fungible_tokens/tests/BASKETTests.move | 45 --- .../fungible_tokens/tests/basket_tests.move | 45 +++ sui_programmability/examples/games/Move.toml | 2 +- .../games/sources/{Hero.move => hero.move} | 122 +++--- ...Scissors.move => rock_paper_scissors.move} | 42 +- .../sources/{SeaHero.move => sea_hero.move} | 38 +- ...eaHeroHelper.move => sea_hero_helper.move} | 36 +- ...TicTacToe.move => shared_tic_tac_toe.move} | 26 +- .../{TicTacToe.move => tic_tac_toe.move} | 48 +-- ...ts.move => rock_paper_scissors_tests.move} | 64 +-- ...sts.move => shared_tic_tac_toe_tests.move} | 42 +- ...acToeTests.move => tic_tac_toe_tests.move} | 57 ++- .../examples/move_tutorial/Move.toml | 2 +- .../sources/{M1.move => m1.move} | 72 ++-- sui_programmability/examples/nfts/Move.toml | 2 +- sui_programmability/examples/nfts/README.md | 2 +- .../examples/nfts/sources/Marketplace.move | 300 -------------- .../sources/{Auction.move => auction.move} | 36 +- .../{AuctionLib.move => auction_lib.move} | 44 +-- .../nfts/sources/{Chat.move => chat.move} | 18 +- ...nAirdrop.move => cross_chain_airdrop.move} | 24 +- ...scountCoupon.move => discount_coupon.move} | 26 +- .../sources/{Geniteam.move => geniteam.move} | 50 +-- .../examples/nfts/sources/marketplace.move | 300 ++++++++++++++ .../nfts/sources/{Num.move => num.move} | 16 +- ...SharedAuction.move => shared_auction.move} | 26 +- .../examples/nfts/tests/ChatTests.move | 34 -- .../nfts/tests/DiscountCouponTests.move | 49 --- .../nfts/tests/SharedAuctionTests.move | 129 ------ .../{AuctionTests.move => auction_tests.move} | 80 ++-- .../examples/nfts/tests/chat_tests.move | 34 ++ ...ts.move => cross_chain_airdrop_tests.move} | 28 +- .../nfts/tests/discount_coupon_tests.move | 49 +++ .../nfts/tests/shared_auction_tests.move | 129 ++++++ .../examples/objects_tutorial/Move.toml | 3 +- .../objects_tutorial/sources/ColorObject.move | 220 ----------- .../sources/color_object.move | 220 +++++++++++ ...SimpleWarrior.move => simple_warrior.move} | 24 +- .../{TrustedSwap.move => trusted_swap.move} | 44 +-- .../examples/regulated_coin/Move.toml | 7 +- ...RegulatedCoin.move => regulated_coin.move} | 266 ++++++------- .../ui/app/redux/slices/sui-objects/Coin.ts | 6 +- .../ui/app/redux/slices/sui-objects/NFT.ts | 2 +- 255 files changed, 4255 insertions(+), 4227 deletions(-) rename crates/sui-core/src/unit_tests/data/hero/sources/{Hero.move => hero.move} (78%) rename crates/sui-core/src/unit_tests/data/hero/sources/{TrustedCoin.move => trusted_coin.move} (66%) rename crates/sui-core/src/unit_tests/data/object_owner/sources/{ObjectOwner.move => object_owner.move} (68%) rename crates/sui-core/src/unit_tests/data/object_wrapping/sources/{ObjectWrapping.move => object_wrapping.move} (70%) rename crates/sui-framework/sources/{Bag.move => bag.move} (89%) rename crates/sui-framework/sources/{Balance.move => balance.move} (73%) rename crates/sui-framework/sources/{Coin.move => coin.move} (82%) rename crates/sui-framework/sources/{Collection.move => collection.move} (89%) rename crates/sui-framework/sources/{DevNetNFT.move => devnet_nft.move} (51%) rename crates/sui-framework/sources/{EpochTimeLock.move => epoch_time_lock.move} (80%) rename crates/sui-framework/sources/{ERC721Metadata.move => erc721_metadata.move} (86%) rename crates/sui-framework/sources/{Event.move => event.move} (94%) rename crates/sui-framework/sources/{Governance/Delegation.move => governance/delegation.move} (82%) rename crates/sui-framework/sources/{Governance/EpochRewardRecord.move => governance/epoch_reward_record.move} (85%) rename crates/sui-framework/sources/{Governance/Genesis.move => governance/genesis.move} (84%) rename crates/sui-framework/sources/{Governance/SuiSystem.move => governance/sui_system.move} (72%) rename crates/sui-framework/sources/{Governance/Validator.move => governance/validator.move} (89%) rename crates/sui-framework/sources/{Governance/ValidatorSet.move => governance/validator_set.move} (91%) rename crates/sui-framework/sources/{ID.move => id.move} (97%) rename crates/sui-framework/sources/{LockedCoin.move => locked_coin.move} (69%) rename crates/sui-framework/sources/{Math.move => math.move} (82%) rename crates/sui-framework/sources/{ObjectBasics.move => object_basics.move} (67%) rename crates/sui-framework/sources/{SUI.move => sui.move} (61%) rename crates/sui-framework/sources/{TestScenario.move => test_scenario.move} (93%) rename crates/sui-framework/sources/{Transfer.move => transfer.move} (91%) rename crates/sui-framework/sources/{TxContext.move => tx_context.move} (95%) rename crates/sui-framework/sources/{Url.move => url.move} (99%) rename crates/sui-framework/sources/{UTF8.move => utf8.move} (98%) delete mode 100644 crates/sui-framework/tests/BagTests.move delete mode 100644 crates/sui-framework/tests/CoinBalanceTests.move delete mode 100644 crates/sui-framework/tests/CollectionTests.move delete mode 100644 crates/sui-framework/tests/IDTests.move delete mode 100644 crates/sui-framework/tests/TestScenarioTests.move delete mode 100644 crates/sui-framework/tests/TxContextTests.move delete mode 100644 crates/sui-framework/tests/ValidatorSetTests.move delete mode 100644 crates/sui-framework/tests/ValidatorTests.move create mode 100644 crates/sui-framework/tests/bag_tests.move create mode 100644 crates/sui-framework/tests/coin_balance_tests.move create mode 100644 crates/sui-framework/tests/collection_tests.move create mode 100644 crates/sui-framework/tests/id_tests.move rename crates/sui-framework/tests/{MathTests.move => math_tests.move} (61%) create mode 100644 crates/sui-framework/tests/test_scenario_tests.move create mode 100644 crates/sui-framework/tests/tx_context_tests.move rename crates/sui-framework/tests/{UrlTests.move => url_tests.move} (62%) create mode 100644 crates/sui-framework/tests/validator_set_tests.move create mode 100644 crates/sui-framework/tests/validator_tests.move rename crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/{CombinableObjects.move => combinable_objects.move} (64%) rename crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/{CustomObjectTemplate.move => custom_object_template.move} (91%) rename crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/{TicTacToe.move => tic_tac_toe.move} (88%) rename crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/{TrustedCoin.move => trusted_coin.move} (66%) rename crates/sui/src/unit_tests/data/dummy_modules_publish/sources/{TrustedCoin.move => trusted_coin.move} (66%) delete mode 100644 sui_programmability/examples/basics/sources/Counter.move delete mode 100644 sui_programmability/examples/basics/sources/Sandwich.move create mode 100644 sui_programmability/examples/basics/sources/counter.move rename sui_programmability/examples/basics/sources/{Lock.move => lock.move} (64%) rename sui_programmability/examples/basics/sources/{Object.move => object.move} (91%) create mode 100644 sui_programmability/examples/basics/sources/sandwich.move rename sui_programmability/examples/defi/sources/{Escrow.move => escrow.move} (83%) rename sui_programmability/examples/defi/sources/{FlashLender.move => flash_lender.move} (83%) rename sui_programmability/examples/defi/sources/{SharedEscrow.move => shared_escrow.move} (78%) delete mode 100644 sui_programmability/examples/defi/tests/FlashLenderTests.move rename sui_programmability/examples/defi/tests/{EscrowTests.move => escrow_tests.move} (68%) create mode 100644 sui_programmability/examples/defi/tests/flash_lender_tests.move rename sui_programmability/examples/defi/tests/{SharedEscrowTest.move => shared_escrow_test.move} (69%) rename sui_programmability/examples/fungible_tokens/sources/{BASKET.move => basket.move} (66%) rename sui_programmability/examples/fungible_tokens/sources/{MANAGED.move => managed.move} (76%) delete mode 100644 sui_programmability/examples/fungible_tokens/tests/BASKETTests.move create mode 100644 sui_programmability/examples/fungible_tokens/tests/basket_tests.move rename sui_programmability/examples/games/sources/{Hero.move => hero.move} (78%) rename sui_programmability/examples/games/sources/{RockPaperScissors.move => rock_paper_scissors.move} (90%) rename sui_programmability/examples/games/sources/{SeaHero.move => sea_hero.move} (81%) rename sui_programmability/examples/games/sources/{SeaHeroHelper.move => sea_hero_helper.move} (77%) rename sui_programmability/examples/games/sources/{SharedTicTacToe.move => shared_tic_tac_toe.move} (90%) rename sui_programmability/examples/games/sources/{TicTacToe.move => tic_tac_toe.move} (89%) rename sui_programmability/examples/games/tests/{RockPaperScissorsTests.move => rock_paper_scissors_tests.move} (53%) rename sui_programmability/examples/games/tests/{SharedTicTacToeTests.move => shared_tic_tac_toe_tests.move} (75%) rename sui_programmability/examples/games/tests/{TicTacToeTests.move => tic_tac_toe_tests.move} (71%) rename sui_programmability/examples/move_tutorial/sources/{M1.move => m1.move} (66%) delete mode 100644 sui_programmability/examples/nfts/sources/Marketplace.move rename sui_programmability/examples/nfts/sources/{Auction.move => auction.move} (82%) rename sui_programmability/examples/nfts/sources/{AuctionLib.move => auction_lib.move} (86%) rename sui_programmability/examples/nfts/sources/{Chat.move => chat.move} (86%) rename sui_programmability/examples/nfts/sources/{CrossChainAirdrop.move => cross_chain_airdrop.move} (90%) rename sui_programmability/examples/nfts/sources/{DiscountCoupon.move => discount_coupon.move} (77%) rename sui_programmability/examples/nfts/sources/{Geniteam.move => geniteam.move} (89%) create mode 100644 sui_programmability/examples/nfts/sources/marketplace.move rename sui_programmability/examples/nfts/sources/{Num.move => num.move} (85%) rename sui_programmability/examples/nfts/sources/{SharedAuction.move => shared_auction.move} (80%) delete mode 100644 sui_programmability/examples/nfts/tests/ChatTests.move delete mode 100644 sui_programmability/examples/nfts/tests/DiscountCouponTests.move delete mode 100644 sui_programmability/examples/nfts/tests/SharedAuctionTests.move rename sui_programmability/examples/nfts/tests/{AuctionTests.move => auction_tests.move} (50%) create mode 100644 sui_programmability/examples/nfts/tests/chat_tests.move rename sui_programmability/examples/nfts/tests/{CrossChainAirdropTests.move => cross_chain_airdrop_tests.move} (71%) create mode 100644 sui_programmability/examples/nfts/tests/discount_coupon_tests.move create mode 100644 sui_programmability/examples/nfts/tests/shared_auction_tests.move delete mode 100644 sui_programmability/examples/objects_tutorial/sources/ColorObject.move create mode 100644 sui_programmability/examples/objects_tutorial/sources/color_object.move rename sui_programmability/examples/objects_tutorial/sources/{SimpleWarrior.move => simple_warrior.move} (71%) rename sui_programmability/examples/objects_tutorial/sources/{TrustedSwap.move => trusted_swap.move} (68%) rename sui_programmability/examples/regulated_coin/sources/{RegulatedCoin.move => regulated_coin.move} (63%) diff --git a/Cargo.lock b/Cargo.lock index c484114af0fc6..f465e69b0c05d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1925,9 +1925,9 @@ dependencies = [ [[package]] name = "flume" -version = "0.10.12" +version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843c03199d0c0ca54bc1ea90ac0d507274c28abcc4f691ae8b4eaa375087c76a" +checksum = "1ceeb589a3157cac0ab8cc585feb749bd2cea5cb55a6ee802ad72d9fd38303da" dependencies = [ "futures-core", "futures-sink", @@ -6990,9 +6990,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.19.2" +version = "1.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439" +checksum = "95eec79ea28c00a365f539f1961e9278fbcaf81c0ff6aaf0e93c181352446948" dependencies = [ "bytes", "libc", diff --git a/crates/generate-json-rpc-spec/src/main.rs b/crates/generate-json-rpc-spec/src/main.rs index 77462af4eb59e..724ec62b3ab68 100644 --- a/crates/generate-json-rpc-spec/src/main.rs +++ b/crates/generate-json-rpc-spec/src/main.rs @@ -359,7 +359,7 @@ async fn get_nft_response( let result = WalletCommands::Call { package: ObjectID::from(SUI_FRAMEWORK_ADDRESS), - module: "DevNetNFT".to_string(), + module: "devnet_nft".to_string(), function: "mint".to_string(), type_args: vec![], args, diff --git a/crates/sui-adapter-transactional-tests/tests/call/simple.exp b/crates/sui-adapter-transactional-tests/tests/call/simple.exp index 358f207092bbc..4ecefc84db43d 100644 --- a/crates/sui-adapter-transactional-tests/tests/call/simple.exp +++ b/crates/sui-adapter-transactional-tests/tests/call/simple.exp @@ -10,4 +10,4 @@ written: object(104) task 3 'view-object'. lines 32-32: Owner: Account Address ( A ) -Contents: Test::M1::Object {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(105)}}, version: 1u64}, value: 0u64} +Contents: Test::M1::Object {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(105)}}, version: 1u64}, value: 0u64} diff --git a/crates/sui-adapter-transactional-tests/tests/call/simple.move b/crates/sui-adapter-transactional-tests/tests/call/simple.move index d94cf2e5421d6..3f9268d4be4ba 100644 --- a/crates/sui-adapter-transactional-tests/tests/call/simple.move +++ b/crates/sui-adapter-transactional-tests/tests/call/simple.move @@ -5,10 +5,10 @@ //# publish module Test::M1 { - use Sui::ID::VersionedID; - use Sui::TxContext::{Self, TxContext}; - use Sui::Transfer; - use Sui::Coin::Coin; + use sui::id::VersionedID; + use sui::tx_context::{Self, TxContext}; + use sui::transfer; + use sui::coin::Coin; struct Object has key, store { id: VersionedID, @@ -20,8 +20,8 @@ module Test::M1 { } public entry fun create(value: u64, recipient: address, ctx: &mut TxContext) { - Transfer::transfer( - Object { id: TxContext::new_id(ctx), value }, + transfer::transfer( + Object { id: tx_context::new_id(ctx), value }, recipient ) } diff --git a/crates/sui-adapter-transactional-tests/tests/children/child_of_shared_object.move b/crates/sui-adapter-transactional-tests/tests/children/child_of_shared_object.move index 12a4bb8004a3c..0fdfb669597e0 100644 --- a/crates/sui-adapter-transactional-tests/tests/children/child_of_shared_object.move +++ b/crates/sui-adapter-transactional-tests/tests/children/child_of_shared_object.move @@ -6,26 +6,26 @@ //# publish module T3::O3 { - use Sui::ID::VersionedID; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::id::VersionedID; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; struct O3 has key, store { id: VersionedID, } public entry fun create(ctx: &mut TxContext) { - let o = O3 { id: TxContext::new_id(ctx) }; - Transfer::transfer(o, TxContext::sender(ctx)) + let o = O3 { id: tx_context::new_id(ctx) }; + transfer::transfer(o, tx_context::sender(ctx)) } } //# publish module T2::O2 { - use Sui::ID::VersionedID; - use Sui::Transfer::{Self, ChildRef}; - use Sui::TxContext::{Self, TxContext}; + use sui::id::VersionedID; + use sui::transfer::{Self, ChildRef}; + use sui::tx_context::{Self, TxContext}; use T3::O3::O3; struct O2 has key, store { @@ -34,18 +34,18 @@ module T2::O2 { } public entry fun create_shared(child: O3, ctx: &mut TxContext) { - Transfer::share_object(new(child, ctx)) + transfer::share_object(new(child, ctx)) } public entry fun create_owned(child: O3, ctx: &mut TxContext) { - Transfer::transfer(new(child, ctx), TxContext::sender(ctx)) + transfer::transfer(new(child, ctx), tx_context::sender(ctx)) } public entry fun use_o2_o3(_o2: &mut O2, _o3: &mut O3) {} fun new(child: O3, ctx: &mut TxContext): O2 { - let id = TxContext::new_id(ctx); - let (id, child) = Transfer::transfer_to_object_id(child, id); + let id = tx_context::new_id(ctx); + let (id, child) = transfer::transfer_to_object_id(child, id); O2 { id, child } } } @@ -54,9 +54,9 @@ module T2::O2 { //# publish module T1::O1 { - use Sui::ID::VersionedID; - use Sui::Transfer::{Self, ChildRef}; - use Sui::TxContext::{Self, TxContext}; + use sui::id::VersionedID; + use sui::transfer::{Self, ChildRef}; + use sui::tx_context::{Self, TxContext}; use T2::O2::O2; use T3::O3::O3; @@ -66,15 +66,15 @@ module T1::O1 { } public entry fun create_shared(child: O2, ctx: &mut TxContext) { - Transfer::share_object(new(child, ctx)) + transfer::share_object(new(child, ctx)) } // This function will be invalid if _o2 is a shared object and owns _o3. public entry fun use_o2_o3(_o2: &mut O2, _o3: &mut O3) {} fun new(child: O2, ctx: &mut TxContext): O1 { - let id = TxContext::new_id(ctx); - let (id, child) = Transfer::transfer_to_object_id(child, id); + let id = tx_context::new_id(ctx); + let (id, child) = transfer::transfer_to_object_id(child, id); O1 { id, child } } } diff --git a/crates/sui-adapter-transactional-tests/tests/entry_points/no_txn_context.move b/crates/sui-adapter-transactional-tests/tests/entry_points/no_txn_context.move index 6a1c2d4c63c0f..285b7952aabfa 100644 --- a/crates/sui-adapter-transactional-tests/tests/entry_points/no_txn_context.move +++ b/crates/sui-adapter-transactional-tests/tests/entry_points/no_txn_context.move @@ -5,16 +5,16 @@ //# publish module Test::M { - use Sui::TxContext::{Self, TxContext}; + use sui::tx_context::{Self, TxContext}; struct Obj has key { - id: Sui::ID::VersionedID, + id: sui::id::VersionedID, value: u64 } public entry fun mint(ctx: &mut TxContext) { - Sui::Transfer::transfer( - Obj { id: TxContext::new_id(ctx), value: 0 }, - TxContext::sender(ctx), + sui::transfer::transfer( + Obj { id: tx_context::new_id(ctx), value: 0 }, + tx_context::sender(ctx), ) } diff --git a/crates/sui-adapter-transactional-tests/tests/entry_points/wrong_visibility.move b/crates/sui-adapter-transactional-tests/tests/entry_points/wrong_visibility.move index fc3c326a31339..86f934046d0d1 100644 --- a/crates/sui-adapter-transactional-tests/tests/entry_points/wrong_visibility.move +++ b/crates/sui-adapter-transactional-tests/tests/entry_points/wrong_visibility.move @@ -7,7 +7,7 @@ //# publish module Test::M { - use Sui::TxContext::TxContext; + use sui::tx_context::TxContext; public fun t1(_: &mut TxContext) { abort 0 diff --git a/crates/sui-adapter-transactional-tests/tests/publish/init.exp b/crates/sui-adapter-transactional-tests/tests/publish/init.exp index 7ba02aa01e0f6..2a21a87891826 100644 --- a/crates/sui-adapter-transactional-tests/tests/publish/init.exp +++ b/crates/sui-adapter-transactional-tests/tests/publish/init.exp @@ -6,7 +6,7 @@ written: object(102) task 2 'view-object'. lines 25-25: Owner: Account Address ( _ ) -Contents: Test::M1::Object {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(104)}}, version: 1u64}, value: 42u64} +Contents: Test::M1::Object {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(104)}}, version: 1u64}, value: 42u64} task 3 'view-object'. lines 27-27: 103::M1 diff --git a/crates/sui-adapter-transactional-tests/tests/publish/init.move b/crates/sui-adapter-transactional-tests/tests/publish/init.move index 665aaa3bc55a8..57053224145ba 100644 --- a/crates/sui-adapter-transactional-tests/tests/publish/init.move +++ b/crates/sui-adapter-transactional-tests/tests/publish/init.move @@ -5,9 +5,9 @@ //# publish module Test::M1 { - use Sui::ID::VersionedID; - use Sui::TxContext::{Self, TxContext}; - use Sui::Transfer; + use sui::id::VersionedID; + use sui::tx_context::{Self, TxContext}; + use sui::transfer; struct Object has key, store { id: VersionedID, @@ -17,8 +17,8 @@ module Test::M1 { // initializer that should be executed upon publishing this module fun init(ctx: &mut TxContext) { let value = 42; - let singleton = Object { id: TxContext::new_id(ctx), value }; - Transfer::transfer(singleton, TxContext::sender(ctx)) + let singleton = Object { id: tx_context::new_id(ctx), value }; + transfer::transfer(singleton, tx_context::sender(ctx)) } } diff --git a/crates/sui-adapter-transactional-tests/tests/publish/init_param.exp b/crates/sui-adapter-transactional-tests/tests/publish/init_param.exp index 79052711daeda..6e4873dfe9a9d 100644 --- a/crates/sui-adapter-transactional-tests/tests/publish/init_param.exp +++ b/crates/sui-adapter-transactional-tests/tests/publish/init_param.exp @@ -1,4 +1,4 @@ processed 2 tasks task 1 'publish'. lines 5-24: -Error: Failed to verify the Move module, reason: "Expected exactly one parameter for _::M1::init of type &mut Sui::TxContext::TxContext". +Error: Failed to verify the Move module, reason: "Expected exactly one parameter for _::M1::init of type &mut sui::tx_context::TxContext". diff --git a/crates/sui-adapter-transactional-tests/tests/publish/init_param.move b/crates/sui-adapter-transactional-tests/tests/publish/init_param.move index a4f1d64df1e87..2e8e7755cd331 100644 --- a/crates/sui-adapter-transactional-tests/tests/publish/init_param.move +++ b/crates/sui-adapter-transactional-tests/tests/publish/init_param.move @@ -7,9 +7,9 @@ // initializer not valid due extra non-ctx param module Test::M1 { - use Sui::ID::VersionedID; - use Sui::TxContext::{Self, TxContext}; - use Sui::Transfer; + use sui::id::VersionedID; + use sui::tx_context::{Self, TxContext}; + use sui::transfer; struct Object has key, store { id: VersionedID, @@ -18,7 +18,7 @@ module Test::M1 { // value param invalid fun init(ctx: &mut TxContext, value: u64) { - let singleton = Object { id: TxContext::new_id(ctx), value }; - Transfer::transfer(singleton, TxContext::sender(ctx)) + let singleton = Object { id: tx_context::new_id(ctx), value }; + transfer::transfer(singleton, tx_context::sender(ctx)) } } diff --git a/crates/sui-adapter-transactional-tests/tests/publish/init_public.move b/crates/sui-adapter-transactional-tests/tests/publish/init_public.move index 2b0a5f44fd393..3ac707396e470 100644 --- a/crates/sui-adapter-transactional-tests/tests/publish/init_public.move +++ b/crates/sui-adapter-transactional-tests/tests/publish/init_public.move @@ -7,9 +7,9 @@ // initializer not valid due to public visibility module Test::M1 { - use Sui::ID::VersionedID; - use Sui::TxContext::{Self, TxContext}; - use Sui::Transfer; + use sui::id::VersionedID; + use sui::tx_context::{Self, TxContext}; + use sui::transfer; struct Object has key, store { id: VersionedID, @@ -19,7 +19,7 @@ module Test::M1 { // public initializer - should not be executed public fun init(ctx: &mut TxContext) { let value = 42; - let singleton = Object { id: TxContext::new_id(ctx), value }; - Transfer::transfer(singleton, TxContext::sender(ctx)) + let singleton = Object { id: tx_context::new_id(ctx), value }; + transfer::transfer(singleton, tx_context::sender(ctx)) } } diff --git a/crates/sui-adapter-transactional-tests/tests/publish/init_ret.move b/crates/sui-adapter-transactional-tests/tests/publish/init_ret.move index eab7ad5d84787..c5310059174dd 100644 --- a/crates/sui-adapter-transactional-tests/tests/publish/init_ret.move +++ b/crates/sui-adapter-transactional-tests/tests/publish/init_ret.move @@ -7,9 +7,9 @@ // initializer not valid due to return value module Test::M1 { - use Sui::ID::VersionedID; - use Sui::TxContext::{Self, TxContext}; - use Sui::Transfer; + use sui::id::VersionedID; + use sui::tx_context::{Self, TxContext}; + use sui::transfer; struct Object has key, store { id: VersionedID, @@ -19,8 +19,8 @@ module Test::M1 { // initializer that should be executed upon publishing this module fun init(ctx: &mut TxContext): u64 { let value = 42; - let singleton = Object { id: TxContext::new_id(ctx), value }; - Transfer::transfer(singleton, TxContext::sender(ctx)); + let singleton = Object { id: tx_context::new_id(ctx), value }; + transfer::transfer(singleton, tx_context::sender(ctx)); value } } diff --git a/crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.exp b/crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.exp index 04d026cc33842..144d88fd1f16e 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.exp +++ b/crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.exp @@ -5,7 +5,7 @@ A: object(100), B: object(101), C: object(102) task 1 'view-object'. lines 8-8: Owner: Account Address ( A ) -Contents: Sui::Coin::Coin {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(100)}}, version: 0u64}, balance: Sui::Balance::Balance {value: 100000u64}} +Contents: sui::coin::Coin {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(100)}}, version: 0u64}, balance: sui::balance::Balance {value: 100000u64}} task 2 'run'. lines 10-10: created: object(106) @@ -13,19 +13,19 @@ written: object(100), object(105) task 3 'view-object'. lines 12-12: Owner: Account Address ( A ) -Contents: Sui::Coin::Coin {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(100)}}, version: 1u64}, balance: Sui::Balance::Balance {value: 99990u64}} +Contents: sui::coin::Coin {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(100)}}, version: 1u64}, balance: sui::balance::Balance {value: 99990u64}} task 4 'view-object'. lines 14-14: Owner: Account Address ( B ) -Contents: Sui::Coin::Coin {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(106)}}, version: 1u64}, balance: Sui::Balance::Balance {value: 10u64}} +Contents: sui::coin::Coin {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(106)}}, version: 1u64}, balance: sui::balance::Balance {value: 10u64}} task 5 'run'. lines 16-16: written: object(100), object(107) task 6 'view-object'. lines 18-18: Owner: Account Address ( C ) -Contents: Sui::Coin::Coin {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(100)}}, version: 2u64}, balance: Sui::Balance::Balance {value: 99990u64}} +Contents: sui::coin::Coin {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(100)}}, version: 2u64}, balance: sui::balance::Balance {value: 99990u64}} task 7 'view-object'. lines 20-20: Owner: Account Address ( B ) -Contents: Sui::Coin::Coin {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(107)}}, version: 1u64}, balance: Sui::Balance::Balance {value: 99600u64}} +Contents: sui::coin::Coin {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 1u64}, balance: sui::balance::Balance {value: 99593u64}} diff --git a/crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.move b/crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.move index 175acd4dabb5a..07346aac40a8e 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.move +++ b/crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.move @@ -7,13 +7,13 @@ //# view-object 100 -//# run Sui::Coin::split_and_transfer --type-args Sui::SUI::SUI --args object(100) 10 @B --sender A +//# run sui::coin::split_and_transfer --type-args sui::sui::SUI --args object(100) 10 @B --sender A //# view-object 100 //# view-object 106 -//# run Sui::Coin::transfer --type-args Sui::SUI::SUI --args object(100) @C --sender B +//# run sui::coin::transfer --type-args sui::sui::SUI --args object(100) @C --sender B //# view-object 100 diff --git a/crates/sui-adapter-transactional-tests/tests/sui/freeze.move b/crates/sui-adapter-transactional-tests/tests/sui/freeze.move index 8083506ba99ae..106b0c5543c4b 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/freeze.move +++ b/crates/sui-adapter-transactional-tests/tests/sui/freeze.move @@ -5,10 +5,10 @@ //# init --accounts A -//# run Sui::ObjectBasics::create --args 10 @A +//# run sui::object_basics::create --args 10 @A -//# run Sui::ObjectBasics::freeze_object --args object(104) +//# run sui::object_basics::freeze_object --args object(104) -//# run Sui::ObjectBasics::transfer --args object(104) @A +//# run sui::object_basics::transfer --args object(104) @A -//# run Sui::ObjectBasics::set_value --args object(104) 1 +//# run sui::object_basics::set_value --args object(104) 1 diff --git a/crates/sui-adapter-transactional-tests/tests/sui/move_call_incorrect_function.exp b/crates/sui-adapter-transactional-tests/tests/sui/move_call_incorrect_function.exp index fad4ae3e621c1..3534ce7d0eec3 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/move_call_incorrect_function.exp +++ b/crates/sui-adapter-transactional-tests/tests/sui/move_call_incorrect_function.exp @@ -1,7 +1,7 @@ processed 2 tasks task 0 'run'. lines 7-9: -Error: Failed to verify the Move module, reason: "VMError with status LINKER_ERROR at location UNDEFINED and message Cannot find ModuleId { address: _, name: Identifier(\"ObjectBasics\") } in data cache". +Error: Failed to verify the Move module, reason: "VMError with status LINKER_ERROR at location UNDEFINED and message Cannot find ModuleId { address: _, name: Identifier(\"object_basics\") } in data cache". task 1 'run'. lines 10-10: -Error: Function resolution failure: "Could not resolve function 'foo' in module Sui::ObjectBasics". +Error: Function resolution failure: "Could not resolve function 'foo' in module sui::object_basics". diff --git a/crates/sui-adapter-transactional-tests/tests/sui/move_call_incorrect_function.move b/crates/sui-adapter-transactional-tests/tests/sui/move_call_incorrect_function.move index c7f38dc55ec5f..cef5db9ea3959 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/move_call_incorrect_function.move +++ b/crates/sui-adapter-transactional-tests/tests/sui/move_call_incorrect_function.move @@ -4,7 +4,7 @@ // These functions do not exist // Instead of calling on the Sui package, we are calling a non-existant package -//# run 0x242::ObjectBasics::create +//# run 0x242::object_basics::create // Calling a non-existant function. -//# run Sui::ObjectBasics::foo +//# run sui::object_basics::foo diff --git a/crates/sui-adapter-transactional-tests/tests/sui/object_basics.exp b/crates/sui-adapter-transactional-tests/tests/sui/object_basics.exp index 14a9d5fe143f6..369c6072f67dd 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/object_basics.exp +++ b/crates/sui-adapter-transactional-tests/tests/sui/object_basics.exp @@ -9,21 +9,21 @@ written: object(104) task 2 'view-object'. lines 10-10: Owner: Account Address ( A ) -Contents: Sui::ObjectBasics::Object {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(105)}}, version: 1u64}, value: 10u64} +Contents: sui::object_basics::Object {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(105)}}, version: 1u64}, value: 10u64} task 3 'run'. lines 12-12: written: object(105), object(106) task 4 'view-object'. lines 14-14: Owner: Account Address ( B ) -Contents: Sui::ObjectBasics::Object {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(105)}}, version: 2u64}, value: 10u64} +Contents: sui::object_basics::Object {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(105)}}, version: 2u64}, value: 10u64} task 5 'run'. lines 16-16: created: object(108) written: object(107) task 6 'run'. lines 18-18: -events: MoveEvent(MoveObject { type_: StructTag { address: Sui, module: Identifier("ObjectBasics"), name: Identifier("NewValueEvent"), type_params: [] }, contents: [20, 0, 0, 0, 0, 0, 0, 0] }) +events: MoveEvent(MoveObject { type_: StructTag { address: sui, module: Identifier("object_basics"), name: Identifier("NewValueEvent"), type_params: [] }, contents: [20, 0, 0, 0, 0, 0, 0, 0] }) written: object(105), object(108), object(109) task 7 'run'. lines 20-20: diff --git a/crates/sui-adapter-transactional-tests/tests/sui/object_basics.move b/crates/sui-adapter-transactional-tests/tests/sui/object_basics.move index 25d6e1848dbcb..8e4366ef6342d 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/object_basics.move +++ b/crates/sui-adapter-transactional-tests/tests/sui/object_basics.move @@ -5,16 +5,16 @@ //# init --accounts A B -//# run Sui::ObjectBasics::create --sender A --args 10 @A +//# run sui::object_basics::create --sender A --args 10 @A //# view-object 105 -//# run Sui::ObjectBasics::transfer --sender A --args object(105) @B +//# run sui::object_basics::transfer --sender A --args object(105) @B //# view-object 105 -//# run Sui::ObjectBasics::create --sender B --args 20 @B +//# run sui::object_basics::create --sender B --args 20 @B -//# run Sui::ObjectBasics::update --sender B --args object(105) object(108) --view-events +//# run sui::object_basics::update --sender B --args object(105) object(108) --view-events -//# run Sui::ObjectBasics::delete --sender B --args object(105) +//# run sui::object_basics::delete --sender B --args object(105) diff --git a/crates/sui-adapter-transactional-tests/tests/sui/unwrap.exp b/crates/sui-adapter-transactional-tests/tests/sui/unwrap.exp index 5bc5b79ad60cb..cf4afeeba1e49 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/unwrap.exp +++ b/crates/sui-adapter-transactional-tests/tests/sui/unwrap.exp @@ -9,7 +9,7 @@ written: object(103) task 2 'view-object'. lines 11-11: Owner: Account Address ( A ) -Contents: Sui::ObjectBasics::Object {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(104)}}, version: 1u64}, value: 10u64} +Contents: sui::object_basics::Object {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(104)}}, version: 1u64}, value: 10u64} task 3 'run'. lines 13-13: created: object(106) @@ -22,4 +22,4 @@ deleted: object(106) task 5 'view-object'. lines 17-17: Owner: Account Address ( A ) -Contents: Sui::ObjectBasics::Object {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(104)}}, version: 3u64}, value: 10u64} +Contents: sui::object_basics::Object {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(104)}}, version: 3u64}, value: 10u64} diff --git a/crates/sui-adapter-transactional-tests/tests/sui/unwrap.move b/crates/sui-adapter-transactional-tests/tests/sui/unwrap.move index f884473dec944..ed845dd19b2e1 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/unwrap.move +++ b/crates/sui-adapter-transactional-tests/tests/sui/unwrap.move @@ -6,12 +6,12 @@ //# init --accounts A -//# run Sui::ObjectBasics::create --args 10 @A +//# run sui::object_basics::create --args 10 @A //# view-object 104 -//# run Sui::ObjectBasics::wrap --args object(104) --sender A +//# run sui::object_basics::wrap --args object(104) --sender A -//# run Sui::ObjectBasics::unwrap --args object(106) --sender A +//# run sui::object_basics::unwrap --args object(106) --sender A //# view-object 104 diff --git a/crates/sui-adapter/src/adapter.rs b/crates/sui-adapter/src/adapter.rs index 9894a18690ebd..39d9750d2841d 100644 --- a/crates/sui-adapter/src/adapter.rs +++ b/crates/sui-adapter/src/adapter.rs @@ -476,7 +476,7 @@ fn process_successful_execution< // If an object is owned by another object, we are not allowed to directly delete the child // object because this could lead to a dangling reference of the ownership. Such // dangling reference can never be dropped. To delete this object, one must either first transfer - // the child object to an account address, or call through Transfer::delete_child_object(), + // the child object to an account address, or call through transfer::delete_child_object(), // which would consume both the child object and the ChildRef ownership reference, // and emit the DeleteChildObject event. These child objects can be safely deleted. return Err(SuiError::DeleteObjectOwnedObject); diff --git a/crates/sui-cluster-test/src/main.rs b/crates/sui-cluster-test/src/main.rs index d18255ac24b1e..c06cb44d8f574 100644 --- a/crates/sui-cluster-test/src/main.rs +++ b/crates/sui-cluster-test/src/main.rs @@ -259,7 +259,7 @@ impl ClusterTest { } let (_, effects) = call_move( ObjectID::from(SUI_FRAMEWORK_ADDRESS), - "DevNetNFT", + "devnet_nft", "mint", vec![], Some(gas_obj_id), diff --git a/crates/sui-core/src/authority/authority_store.rs b/crates/sui-core/src/authority/authority_store.rs index 642008c44c57a..c968fe5105bfa 100644 --- a/crates/sui-core/src/authority/authority_store.rs +++ b/crates/sui-core/src/authority/authority_store.rs @@ -1266,7 +1266,7 @@ pub async fn generate_genesis_system_object< adapter::execute( move_vm, &mut temporary_store, - ModuleId::new(SUI_FRAMEWORK_ADDRESS, ident_str!("Genesis").to_owned()), + ModuleId::new(SUI_FRAMEWORK_ADDRESS, ident_str!("genesis").to_owned()), &ident_str!("create").to_owned(), vec![], vec![ diff --git a/crates/sui-core/src/unit_tests/authority_aggregator_tests.rs b/crates/sui-core/src/unit_tests/authority_aggregator_tests.rs index 2c9a29fb6b2c7..dc29738523717 100644 --- a/crates/sui-core/src/unit_tests/authority_aggregator_tests.rs +++ b/crates/sui-core/src/unit_tests/authority_aggregator_tests.rs @@ -132,7 +132,7 @@ fn transfer_object_move_transaction( TransactionData::new_move_call( src, framework_obj_ref, - ident_str!("ObjectBasics").to_owned(), + ident_str!("object_basics").to_owned(), ident_str!("transfer").to_owned(), Vec::new(), gas_object_ref, @@ -151,7 +151,7 @@ pub fn crate_object_move_transaction( framework_obj_ref: ObjectRef, gas_object_ref: ObjectRef, ) -> Transaction { - // When creating an ObjectBasics object, we provide the value (u64) and address which will own the object + // When creating an object_basics object, we provide the value (u64) and address which will own the object let arguments = vec![ CallArg::Pure(value.to_le_bytes().to_vec()), CallArg::Pure(bcs::to_bytes(&AccountAddress::from(dest)).unwrap()), @@ -161,7 +161,7 @@ pub fn crate_object_move_transaction( TransactionData::new_move_call( src, framework_obj_ref, - ident_str!("ObjectBasics").to_owned(), + ident_str!("object_basics").to_owned(), ident_str!("create").to_owned(), Vec::new(), gas_object_ref, @@ -183,7 +183,7 @@ pub fn delete_object_move_transaction( TransactionData::new_move_call( src, framework_obj_ref, - ident_str!("ObjectBasics").to_owned(), + ident_str!("object_basics").to_owned(), ident_str!("delete").to_owned(), Vec::new(), gas_object_ref, @@ -211,7 +211,7 @@ pub fn set_object_move_transaction( TransactionData::new_move_call( src, framework_obj_ref, - ident_str!("ObjectBasics").to_owned(), + ident_str!("object_basics").to_owned(), ident_str!("set_value").to_owned(), Vec::new(), gas_object_ref, diff --git a/crates/sui-core/src/unit_tests/authority_tests.rs b/crates/sui-core/src/unit_tests/authority_tests.rs index f977d3706d680..5a9ceed23a51f 100644 --- a/crates/sui-core/src/unit_tests/authority_tests.rs +++ b/crates/sui-core/src/unit_tests/authority_tests.rs @@ -207,7 +207,7 @@ async fn test_handle_shared_object_with_max_sequence_number() { let authority = init_state_with_objects(vec![gas_object, shared_object]).await; // Make a sample transaction. - let module = "ObjectBasics"; + let module = "object_basics"; let function = "create"; let package_object_ref = authority.get_framework_object_ref().await.unwrap(); @@ -1038,7 +1038,7 @@ async fn test_move_call_mutable_object_not_mutated() { &gas_object_id, &sender, &sender_key, - "ObjectBasics", + "object_basics", "update", vec![], vec![ @@ -1096,7 +1096,7 @@ async fn test_move_call_delete() { &gas_object_id, &sender, &sender_key, - "ObjectBasics", + "object_basics", "update", vec![], vec![ @@ -1116,7 +1116,7 @@ async fn test_move_call_delete() { &gas_object_id, &sender, &sender_key, - "ObjectBasics", + "object_basics", "delete", vec![], vec![TestCallArg::Object(new_object_id1)], @@ -1148,7 +1148,7 @@ async fn test_get_latest_parent_entry() { &gas_object_id, &sender, &sender_key, - "ObjectBasics", + "object_basics", "update", vec![], vec![ @@ -1174,7 +1174,7 @@ async fn test_get_latest_parent_entry() { &gas_object_id, &sender, &sender_key, - "ObjectBasics", + "object_basics", "delete", vec![], vec![TestCallArg::Object(new_object_id1)], @@ -1696,7 +1696,7 @@ pub async fn create_move_object( gas_object_id, sender, sender_key, - "ObjectBasics", + "object_basics", "create", vec![], vec![TestCallArg::U64(16), TestCallArg::Address(*sender)], @@ -1726,7 +1726,7 @@ async fn shared_object() { let authority = init_state_with_objects(vec![gas_object, shared_object]).await; // Make a sample transaction. - let module = "ObjectBasics"; + let module = "object_basics"; let function = "create"; let package_object_ref = authority.get_framework_object_ref().await.unwrap(); diff --git a/crates/sui-core/src/unit_tests/batch_transaction_tests.rs b/crates/sui-core/src/unit_tests/batch_transaction_tests.rs index 315fc0dc0a41d..bef31b30d3a42 100644 --- a/crates/sui-core/src/unit_tests/batch_transaction_tests.rs +++ b/crates/sui-core/src/unit_tests/batch_transaction_tests.rs @@ -39,7 +39,7 @@ async fn test_batch_transaction_ok() -> anyhow::Result<()> { for _ in 0..N { transactions.push(SingleTransactionKind::Call(MoveCall { package: package_object_ref, - module: ident_str!("ObjectBasics").to_owned(), + module: ident_str!("object_basics").to_owned(), function: ident_str!("create").to_owned(), type_arguments: vec![], arguments: vec![ @@ -106,7 +106,7 @@ async fn test_batch_transaction_last_one_fail() -> anyhow::Result<()> { let package_object_ref = authority_state.get_framework_object_ref().await?; transactions.push(SingleTransactionKind::Call(MoveCall { package: package_object_ref, - module: ident_str!("ObjectBasics").to_owned(), + module: ident_str!("object_basics").to_owned(), function: ident_str!("create").to_owned(), type_arguments: vec![], arguments: vec![], @@ -186,7 +186,7 @@ async fn test_batch_insufficient_gas_balance() -> anyhow::Result<()> { for _ in 0..N { transactions.push(SingleTransactionKind::Call(MoveCall { package: package_object_ref, - module: ident_str!("ObjectBasics").to_owned(), + module: ident_str!("object_basics").to_owned(), function: ident_str!("create").to_owned(), type_arguments: vec![], arguments: vec![ diff --git a/crates/sui-core/src/unit_tests/consensus_tests.rs b/crates/sui-core/src/unit_tests/consensus_tests.rs index 8eec9e0c41b5a..b1cf23432d6c4 100644 --- a/crates/sui-core/src/unit_tests/consensus_tests.rs +++ b/crates/sui-core/src/unit_tests/consensus_tests.rs @@ -47,7 +47,7 @@ pub async fn test_certificates(authority: &AuthorityState) -> Vec, ctx: &mut TxContext ): Sword { - let value = Coin::value(&payment); + let value = coin::value(&payment); // ensure the user pays enough for the sword assert!(value >= MIN_SWORD_COST, EINSUFFICIENT_FUNDS); // pay the admin for this sword - Transfer::transfer(payment, admin()); + transfer::transfer(payment, admin()); // magic of the sword is proportional to the amount you paid, up to // a max. one can only imbue a sword with so much magic let magic = (value - MIN_SWORD_COST) / MIN_SWORD_COST; Sword { - id: TxContext::new_id(ctx), - magic: Math::min(magic, MAX_MAGIC), + id: tx_context::new_id(ctx), + magic: math::min(magic, MAX_MAGIC), strength: 1 } } @@ -225,14 +225,14 @@ module Examples::Hero { public entry fun acquire_hero(payment: Coin, ctx: &mut TxContext) { let sword = create_sword(payment, ctx); let hero = create_hero(sword, ctx); - Transfer::transfer(hero, TxContext::sender(ctx)) + transfer::transfer(hero, tx_context::sender(ctx)) } /// Anyone can create a hero if they have a sword. All heroes start with the /// same attributes. public fun create_hero(sword: Sword, ctx: &mut TxContext): Hero { Hero { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), hp: 100, experience: 0, sword: option::some(sword), @@ -248,8 +248,8 @@ module Examples::Hero { ) { admin.potions_created = admin.potions_created + 1; // send potion to the designated player - Transfer::transfer( - Potion { id: TxContext::new_id(ctx), potency }, + transfer::transfer( + Potion { id: tx_context::new_id(ctx), potency }, player ) } @@ -264,8 +264,8 @@ module Examples::Hero { ) { admin.boars_created = admin.boars_created + 1; // send boars to the designated player - Transfer::transfer( - Boar { id: TxContext::new_id(ctx), hp, strength }, + transfer::transfer( + Boar { id: tx_context::new_id(ctx), hp, strength }, player ) } @@ -282,63 +282,63 @@ module Examples::Hero { #[test_only] public fun delete_hero_for_testing(hero: Hero) { let Hero { id, hp: _, experience: _, sword } = hero; - ID::delete(id); + id::delete(id); let sword = option::destroy_some(sword); let Sword { id, magic: _, strength: _ } = sword; - ID::delete(id) + id::delete(id) } #[test_only] public fun delete_game_admin_for_testing(admin: GameAdmin) { let GameAdmin { id, boars_created: _, potions_created: _ } = admin; - ID::delete(id); + id::delete(id); } #[test] public fun slay_boar_test() { - use Examples::TrustedCoin::{Self, EXAMPLE}; - use Sui::Coin::{Self, TreasuryCap}; - use Sui::TestScenario; + use examples::trusted_coin::{Self, EXAMPLE}; + use sui::coin::{Self, TreasuryCap}; + use sui::test_scenario; let admin = ADMIN; let player = @0x0; - let scenario = &mut TestScenario::begin(&admin); + let scenario = &mut test_scenario::begin(&admin); // Run the module initializers { - let ctx = TestScenario::ctx(scenario); - TrustedCoin::test_init(ctx); + let ctx = test_scenario::ctx(scenario); + trusted_coin::test_init(ctx); init(ctx); }; // Admin mints 500 coins and sends them to the Player so they can buy game items - TestScenario::next_tx(scenario, &admin); + test_scenario::next_tx(scenario, &admin); { - let treasury_cap = TestScenario::take_owned>(scenario); - let ctx = TestScenario::ctx(scenario); - let coins = Coin::mint(500, &mut treasury_cap, ctx); - Coin::transfer(coins, copy player); - TestScenario::return_owned(scenario, treasury_cap); + let treasury_cap = test_scenario::take_owned>(scenario); + let ctx = test_scenario::ctx(scenario); + let coins = coin::mint(500, &mut treasury_cap, ctx); + coin::transfer(coins, copy player); + test_scenario::return_owned(scenario, treasury_cap); }; // Player purchases a hero with the coins - TestScenario::next_tx(scenario, &player); + test_scenario::next_tx(scenario, &player); { - let coin = TestScenario::take_owned>(scenario); - acquire_hero(coin, TestScenario::ctx(scenario)); + let coin = test_scenario::take_owned>(scenario); + acquire_hero(coin, test_scenario::ctx(scenario)); }; // Admin sends a boar to the Player - TestScenario::next_tx(scenario, &admin); + test_scenario::next_tx(scenario, &admin); { - let admin_cap = TestScenario::take_owned(scenario); - send_boar(&mut admin_cap, 10, 10, player, TestScenario::ctx(scenario)); - TestScenario::return_owned(scenario, admin_cap) + let admin_cap = test_scenario::take_owned(scenario); + send_boar(&mut admin_cap, 10, 10, player, test_scenario::ctx(scenario)); + test_scenario::return_owned(scenario, admin_cap) }; // Player slays the boar! - TestScenario::next_tx(scenario, &player); + test_scenario::next_tx(scenario, &player); { - let hero = TestScenario::take_owned(scenario); - let boar = TestScenario::take_owned(scenario); - slay(&mut hero, boar, TestScenario::ctx(scenario)); - TestScenario::return_owned(scenario, hero) + let hero = test_scenario::take_owned(scenario); + let boar = test_scenario::take_owned(scenario); + slay(&mut hero, boar, test_scenario::ctx(scenario)); + test_scenario::return_owned(scenario, hero) }; } } diff --git a/crates/sui-core/src/unit_tests/data/hero/sources/TrustedCoin.move b/crates/sui-core/src/unit_tests/data/hero/sources/trusted_coin.move similarity index 66% rename from crates/sui-core/src/unit_tests/data/hero/sources/TrustedCoin.move rename to crates/sui-core/src/unit_tests/data/hero/sources/trusted_coin.move index 2a7b896558bb4..363e2d6001a25 100644 --- a/crates/sui-core/src/unit_tests/data/hero/sources/TrustedCoin.move +++ b/crates/sui-core/src/unit_tests/data/hero/sources/trusted_coin.move @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 /// Example coin with a trusted owner responsible for minting/burning (e.g., a stablecoin) -module Examples::TrustedCoin { - use Sui::Coin::{Self, TreasuryCap}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module examples::trusted_coin { + use sui::coin::{Self, TreasuryCap}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Name of the coin struct EXAMPLE has drop {} @@ -16,17 +16,17 @@ module Examples::TrustedCoin { fun init(ctx: &mut TxContext) { // Get a treasury cap for the coin and give it to the transaction // sender - let treasury_cap = Coin::create_currency(EXAMPLE{}, ctx); - Transfer::transfer(treasury_cap, TxContext::sender(ctx)) + let treasury_cap = coin::create_currency(EXAMPLE{}, ctx); + transfer::transfer(treasury_cap, tx_context::sender(ctx)) } public entry fun mint(treasury_cap: &mut TreasuryCap, amount: u64, ctx: &mut TxContext) { - let coin = Coin::mint(amount, treasury_cap, ctx); - Coin::transfer(coin, TxContext::sender(ctx)); + let coin = coin::mint(amount, treasury_cap, ctx); + coin::transfer(coin, tx_context::sender(ctx)); } public entry fun transfer(treasury_cap: TreasuryCap, recipient: address) { - Coin::transfer_cap(treasury_cap, recipient); + coin::transfer_cap(treasury_cap, recipient); } #[test_only] diff --git a/crates/sui-core/src/unit_tests/data/object_owner/Move.toml b/crates/sui-core/src/unit_tests/data/object_owner/Move.toml index 1db107aeb3ca8..5d3f0eecb6e0d 100644 --- a/crates/sui-core/src/unit_tests/data/object_owner/Move.toml +++ b/crates/sui-core/src/unit_tests/data/object_owner/Move.toml @@ -1,9 +1,9 @@ [package] -name = "ObjectOwner" +name = "object_owner" version = "0.0.1" [dependencies] Sui = { local = "../../../../../sui-framework" } [addresses] -ObjectOwner = "0x0" +object_owner = "0x0" diff --git a/crates/sui-core/src/unit_tests/data/object_owner/sources/ObjectOwner.move b/crates/sui-core/src/unit_tests/data/object_owner/sources/object_owner.move similarity index 68% rename from crates/sui-core/src/unit_tests/data/object_owner/sources/ObjectOwner.move rename to crates/sui-core/src/unit_tests/data/object_owner/sources/object_owner.move index cf3145e41b20f..011f0099728e3 100644 --- a/crates/sui-core/src/unit_tests/data/object_owner/sources/ObjectOwner.move +++ b/crates/sui-core/src/unit_tests/data/object_owner/sources/object_owner.move @@ -1,11 +1,11 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module ObjectOwner::ObjectOwner { +module object_owner::object_owner { use std::option::{Self, Option}; - use Sui::ID::{Self, VersionedID}; - use Sui::Transfer::{Self, ChildRef}; - use Sui::TxContext::{Self, TxContext}; + use sui::id::{Self, VersionedID}; + use sui::transfer::{Self, ChildRef}; + use sui::tx_context::{Self, TxContext}; struct Parent has key { id: VersionedID, @@ -22,33 +22,33 @@ module ObjectOwner::ObjectOwner { } public entry fun create_child(ctx: &mut TxContext) { - Transfer::transfer( - Child { id: TxContext::new_id(ctx) }, - TxContext::sender(ctx), + transfer::transfer( + Child { id: tx_context::new_id(ctx) }, + tx_context::sender(ctx), ); } public entry fun create_parent(ctx: &mut TxContext) { let parent = Parent { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), child: option::none(), }; - Transfer::transfer(parent, TxContext::sender(ctx)); + transfer::transfer(parent, tx_context::sender(ctx)); } public entry fun create_parent_and_child(ctx: &mut TxContext) { - let parent_id = TxContext::new_id(ctx); - let child = Child { id: TxContext::new_id(ctx) }; - let (parent_id, child_ref) = Transfer::transfer_to_object_id(child, parent_id); + let parent_id = tx_context::new_id(ctx); + let child = Child { id: tx_context::new_id(ctx) }; + let (parent_id, child_ref) = transfer::transfer_to_object_id(child, parent_id); let parent = Parent { id: parent_id, child: option::some(child_ref), }; - Transfer::transfer(parent, TxContext::sender(ctx)); + transfer::transfer(parent, tx_context::sender(ctx)); } public entry fun add_child(parent: &mut Parent, child: Child) { - let child_ref = Transfer::transfer_to_object(child, parent); + let child_ref = transfer::transfer_to_object(child, parent); option::fill(&mut parent.child, child_ref); } @@ -61,38 +61,38 @@ module ObjectOwner::ObjectOwner { public entry fun transfer_child(parent: &mut Parent, child: Child, new_parent: &mut Parent) { let child_ref = option::extract(&mut parent.child); - let new_child_ref = Transfer::transfer_child_to_object(child, child_ref, new_parent); + let new_child_ref = transfer::transfer_child_to_object(child, child_ref, new_parent); option::fill(&mut new_parent.child, new_child_ref); } public entry fun remove_child(parent: &mut Parent, child: Child, ctx: &mut TxContext) { let child_ref = option::extract(&mut parent.child); - Transfer::transfer_child_to_address(child, child_ref, TxContext::sender(ctx)); + transfer::transfer_child_to_address(child, child_ref, tx_context::sender(ctx)); } // Call to delete_child can fail if it's still owned by a parent. public entry fun delete_child(child: Child, _parent: &mut Parent) { let Child { id } = child; - ID::delete(id); + id::delete(id); } public entry fun delete_parent_and_child(parent: Parent, child: Child) { let Parent { id: parent_id, child: child_ref_opt } = parent; let child_ref = option::extract(&mut child_ref_opt); option::destroy_none(child_ref_opt); - ID::delete(parent_id); + id::delete(parent_id); let Child { id: child_id } = child; - Transfer::delete_child_object(child_id, child_ref); + transfer::delete_child_object(child_id, child_ref); } public entry fun create_another_parent(child: Child, ctx: &mut TxContext) { - let id = TxContext::new_id(ctx); - let (id, child_ref) = Transfer::transfer_to_object_id(child, id); + let id = tx_context::new_id(ctx); + let (id, child_ref) = transfer::transfer_to_object_id(child, id); let parent = AnotherParent { id, child: child_ref, }; - Transfer::transfer(parent, TxContext::sender(ctx)); + transfer::transfer(parent, tx_context::sender(ctx)); } } diff --git a/crates/sui-core/src/unit_tests/data/object_wrapping/Move.toml b/crates/sui-core/src/unit_tests/data/object_wrapping/Move.toml index 0c90ab448cf86..7c2bcde9d0dea 100644 --- a/crates/sui-core/src/unit_tests/data/object_wrapping/Move.toml +++ b/crates/sui-core/src/unit_tests/data/object_wrapping/Move.toml @@ -1,9 +1,9 @@ [package] -name = "ObjectWrapping" +name = "object_wrapping" version = "0.0.1" [dependencies] Sui = { local = "../../../../../sui-framework" } [addresses] -ObjectWrapping = "0x0" +object_wrapping = "0x0" diff --git a/crates/sui-core/src/unit_tests/data/object_wrapping/sources/ObjectWrapping.move b/crates/sui-core/src/unit_tests/data/object_wrapping/sources/object_wrapping.move similarity index 70% rename from crates/sui-core/src/unit_tests/data/object_wrapping/sources/ObjectWrapping.move rename to crates/sui-core/src/unit_tests/data/object_wrapping/sources/object_wrapping.move index 8e5b91d72c7bf..c00ee978a8b09 100644 --- a/crates/sui-core/src/unit_tests/data/object_wrapping/sources/ObjectWrapping.move +++ b/crates/sui-core/src/unit_tests/data/object_wrapping/sources/object_wrapping.move @@ -1,11 +1,11 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module ObjectWrapping::ObjectWrapping { +module object_wrapping::object_wrapping { use std::option::{Self, Option}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; - use Sui::ID::{Self, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + use sui::id::{Self, VersionedID}; struct Child has key, store { id: VersionedID, @@ -17,21 +17,21 @@ module ObjectWrapping::ObjectWrapping { } public entry fun create_child(ctx: &mut TxContext) { - Transfer::transfer( + transfer::transfer( Child { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), }, - TxContext::sender(ctx), + tx_context::sender(ctx), ) } public entry fun create_parent(child: Child, ctx: &mut TxContext) { - Transfer::transfer( + transfer::transfer( Parent { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), child: option::some(child), }, - TxContext::sender(ctx), + tx_context::sender(ctx), ) } @@ -41,19 +41,19 @@ module ObjectWrapping::ObjectWrapping { public entry fun extract_child(parent: &mut Parent, ctx: &mut TxContext) { let child = option::extract(&mut parent.child); - Transfer::transfer( + transfer::transfer( child, - TxContext::sender(ctx), + tx_context::sender(ctx), ) } public entry fun delete_parent(parent: Parent) { let Parent { id: parent_id, child: child_opt } = parent; - ID::delete(parent_id); + id::delete(parent_id); if (option::is_some(&child_opt)) { let child = option::extract(&mut child_opt); let Child { id: child_id } = child; - ID::delete(child_id); + id::delete(child_id); }; option::destroy_none(child_opt) } diff --git a/crates/sui-core/src/unit_tests/gas_tests.rs b/crates/sui-core/src/unit_tests/gas_tests.rs index 42222a4946274..256ce5dd7d966 100644 --- a/crates/sui-core/src/unit_tests/gas_tests.rs +++ b/crates/sui-core/src/unit_tests/gas_tests.rs @@ -355,7 +355,7 @@ async fn test_move_call_gas() -> SuiResult { let package_object_ref = authority_state.get_framework_object_ref().await?; let gas_object = authority_state.get_object(&gas_object_id).await?.unwrap(); - let module = ident_str!("ObjectBasics").to_owned(); + let module = ident_str!("object_basics").to_owned(); let function = ident_str!("create").to_owned(); let args = vec![ CallArg::Pure(16u64.to_le_bytes().to_vec()), diff --git a/crates/sui-core/src/unit_tests/gateway_state_tests.rs b/crates/sui-core/src/unit_tests/gateway_state_tests.rs index 5581309f56d51..fe21c85b463d8 100644 --- a/crates/sui-core/src/unit_tests/gateway_state_tests.rs +++ b/crates/sui-core/src/unit_tests/gateway_state_tests.rs @@ -556,7 +556,7 @@ async fn test_get_owner_object() { .move_call( addr1, package, - "ObjectOwner".to_string(), + "object_owner".to_string(), "create_parent".to_string(), vec![], vec![], @@ -577,7 +577,7 @@ async fn test_get_owner_object() { .move_call( addr1, package, - "ObjectOwner".to_string(), + "object_owner".to_string(), "create_child".to_string(), vec![], vec![], @@ -600,7 +600,7 @@ async fn test_get_owner_object() { .move_call( addr1, package, - "ObjectOwner".to_string(), + "object_owner".to_string(), "add_child".to_string(), vec![], vec![ diff --git a/crates/sui-core/src/unit_tests/move_integration_tests.rs b/crates/sui-core/src/unit_tests/move_integration_tests.rs index a9430cc9040a1..3c6b246352ebd 100644 --- a/crates/sui-core/src/unit_tests/move_integration_tests.rs +++ b/crates/sui-core/src/unit_tests/move_integration_tests.rs @@ -38,7 +38,7 @@ async fn test_object_wrapping_unwrapping() { &sender, &sender_key, &package, - "ObjectWrapping", + "object_wrapping", "create_child", vec![], vec![], @@ -60,7 +60,7 @@ async fn test_object_wrapping_unwrapping() { &sender, &sender_key, &package, - "ObjectWrapping", + "object_wrapping", "create_parent", vec![], vec![TestCallArg::Object(child_object_ref.0)], @@ -102,7 +102,7 @@ async fn test_object_wrapping_unwrapping() { &sender, &sender_key, &package, - "ObjectWrapping", + "object_wrapping", "extract_child", vec![], vec![TestCallArg::Object(parent_object_ref.0)], @@ -136,7 +136,7 @@ async fn test_object_wrapping_unwrapping() { &sender, &sender_key, &package, - "ObjectWrapping", + "object_wrapping", "set_child", vec![], vec![ @@ -171,7 +171,7 @@ async fn test_object_wrapping_unwrapping() { &sender, &sender_key, &package, - "ObjectWrapping", + "object_wrapping", "delete_parent", vec![], vec![TestCallArg::Object(parent_object_ref.0)], @@ -218,7 +218,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "create_parent", vec![], vec![], @@ -238,7 +238,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "create_child", vec![], vec![], @@ -257,7 +257,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "mutate_child", vec![], vec![TestCallArg::Object(child.0)], @@ -273,7 +273,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "add_child", vec![], vec![TestCallArg::Object(parent.0), TestCallArg::Object(child.0)], @@ -296,7 +296,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "mutate_child", vec![], vec![TestCallArg::Object(child.0)], @@ -311,7 +311,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "mutate_child_with_parent", vec![], vec![TestCallArg::Object(child.0), TestCallArg::Object(parent.0)], @@ -327,7 +327,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "create_parent", vec![], vec![], @@ -346,7 +346,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "transfer_child", vec![], vec![ @@ -391,7 +391,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "delete_child", vec![], vec![ @@ -413,7 +413,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "remove_child", vec![], vec![ @@ -437,7 +437,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "delete_child", vec![], vec![ @@ -454,14 +454,14 @@ async fn test_object_owning_another_object() { assert_eq!(event1.object_id(), Some(child.0)); // Create a parent and a child together. This tests the - // Transfer::transfer_to_object_id() API. + // transfer::transfer_to_object_id() API. let effects = call_move( &authority, &gas, &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "create_parent_and_child", vec![], vec![], @@ -486,7 +486,7 @@ async fn test_object_owning_another_object() { &sender, &sender_key, &package, - "ObjectOwner", + "object_owner", "delete_parent_and_child", vec![], vec![TestCallArg::Object(parent.0), TestCallArg::Object(child.0)], diff --git a/crates/sui-framework/Move.toml b/crates/sui-framework/Move.toml index 6b700ca9e5918..7047ffa7216c4 100644 --- a/crates/sui-framework/Move.toml +++ b/crates/sui-framework/Move.toml @@ -9,4 +9,4 @@ MoveStdlib = { local = "deps/move-stdlib" } #MoveStdlib = { git = "https://github.com/diem/diem.git", subdir="language/move-stdlib", rev = "346301f33b3489bb4e486ae6c0aa5e030223b492" } [addresses] -Sui = "0x2" +sui = "0x2" diff --git a/crates/sui-framework/README.md b/crates/sui-framework/README.md index 878c0ea273abe..545e30957cc32 100644 --- a/crates/sui-framework/README.md +++ b/crates/sui-framework/README.md @@ -1,6 +1,6 @@ # Sui Programmability with Move -This is a proof-of-concept Move standard library for Sui (`sources/`), along with several examples of programs that Sui users might want to write (`examples`). `CustomObjectTemplate.move` is a good starting point for understanding the proposed model. +This is a proof-of-concept Move standard library for Sui (`sources/`), along with several examples of programs that Sui users might want to write (`examples`). `custom_object_template.move` is a good starting point for understanding the proposed model. ### Setup diff --git a/crates/sui-framework/sources/Bag.move b/crates/sui-framework/sources/bag.move similarity index 89% rename from crates/sui-framework/sources/Bag.move rename to crates/sui-framework/sources/bag.move index aab46ba70f29a..31d7d44bcc28d 100644 --- a/crates/sui-framework/sources/Bag.move +++ b/crates/sui-framework/sources/bag.move @@ -9,13 +9,13 @@ /// could mutate the objects in the Bag. /// Bag is different from the Collection type in that Collection /// only supports owning objects of the same type. -module Sui::Bag { +module sui::bag { use std::errors; use std::option::{Self, Option}; use std::vector::Self; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer::{Self, ChildRef}; - use Sui::TxContext::{Self, TxContext}; + use sui::id::{Self, ID, VersionedID}; + use sui::transfer::{Self, ChildRef}; + use sui::tx_context::{Self, TxContext}; // Error codes /// When removing an object from the collection, EObjectNotFound @@ -54,7 +54,7 @@ module Sui::Bag { errors::limit_exceeded(EInvalidMaxCapacity) ); Bag { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), objects: vector::empty(), max_capacity, } @@ -62,7 +62,7 @@ module Sui::Bag { /// Create a new Bag and transfer it to the signer. public entry fun create(ctx: &mut TxContext) { - Transfer::transfer(new(ctx), TxContext::sender(ctx)) + transfer::transfer(new(ctx), tx_context::sender(ctx)) } /// Returns the size of the Bag. @@ -79,12 +79,12 @@ module Sui::Bag { size(c) + 1 <= c.max_capacity, errors::limit_exceeded(EMaxCapacityExceeded) ); - let id = ID::id(&object); + let id = id::id(&object); if (contains(c, id)) { abort EObjectDoubleAdd }; vector::push_back(&mut c.objects, *id); - Transfer::transfer_to_object_unsafe(object, old_child_ref, c); + transfer::transfer_to_object_unsafe(object, old_child_ref, c); } /// Add a new object to the Bag. @@ -109,7 +109,7 @@ module Sui::Bag { /// Remove and return the object from the Bag. /// Abort if the object is not found. public fun remove(c: &mut Bag, object: T): T { - let idx = find(c, ID::id(&object)); + let idx = find(c, id::id(&object)); if (option::is_none(&idx)) { abort EObjectNotFound }; @@ -120,19 +120,19 @@ module Sui::Bag { /// Remove the object from the Bag, and then transfer it to the signer. public entry fun remove_and_take(c: &mut Bag, object: T, ctx: &mut TxContext) { let object = remove(c, object); - Transfer::transfer(object, TxContext::sender(ctx)); + transfer::transfer(object, tx_context::sender(ctx)); } /// Transfer the entire Bag to `recipient`. public entry fun transfer(c: Bag, recipient: address) { - Transfer::transfer(c, recipient) + transfer::transfer(c, recipient) } public fun transfer_to_object_id( obj: Bag, owner_id: VersionedID, ): (VersionedID, ChildRef) { - Transfer::transfer_to_object_id(obj, owner_id) + transfer::transfer_to_object_id(obj, owner_id) } /// Look for the object identified by `id_bytes` in the Bag. diff --git a/crates/sui-framework/sources/Balance.move b/crates/sui-framework/sources/balance.move similarity index 73% rename from crates/sui-framework/sources/Balance.move rename to crates/sui-framework/sources/balance.move index ca880d968a876..1d4d5c4c18500 100644 --- a/crates/sui-framework/sources/Balance.move +++ b/crates/sui-framework/sources/balance.move @@ -5,9 +5,9 @@ /// Allows separation of the transferable `Coin` type and the storable /// `Balance` eliminating the need to create new IDs for each application /// that needs to hold coins. -module Sui::Balance { - friend Sui::Coin; - friend Sui::SuiSystem; +module sui::balance { + friend sui::coin; + friend sui::sui_system; /// For when trying to destroy a non-zero balance. const ENonZero: u64 = 0; @@ -51,13 +51,13 @@ module Sui::Balance { let Balance { value: _ } = balance; } - /// Can only be called by Sui::Coin. + /// Can only be called by sui::coin. /// Create a `Balance` with a predefined value; required for minting new `Coin`s. public(friend) fun create_with_value(value: u64): Balance { Balance { value } } - /// Can only be called by Sui::Coin. + /// Can only be called by sui::coin. /// Destroy a `Balance` returning its value. Required for burning `Coin`s public(friend) fun destroy(self: Balance): u64 { let Balance { value } = self; @@ -78,31 +78,31 @@ module Sui::Balance { } #[test_only] -module Sui::BalanceTests { - use Sui::Balance; - use Sui::SUI::SUI; +module sui::balance_tests { + use sui::balance; + use sui::sui::SUI; #[test] fun test_balance() { - let balance = Balance::zero(); - let another = Balance::create_for_testing(1000); + let balance = balance::zero(); + let another = balance::create_for_testing(1000); - Balance::join(&mut balance, another); + balance::join(&mut balance, another); - assert!(Balance::value(&balance) == 1000, 0); + assert!(balance::value(&balance) == 1000, 0); - let balance1 = Balance::split(&mut balance, 333); - let balance2 = Balance::split(&mut balance, 333); - let balance3 = Balance::split(&mut balance, 334); + let balance1 = balance::split(&mut balance, 333); + let balance2 = balance::split(&mut balance, 333); + let balance3 = balance::split(&mut balance, 334); - Balance::destroy_zero(balance); + balance::destroy_zero(balance); - assert!(Balance::value(&balance1) == 333, 1); - assert!(Balance::value(&balance2) == 333, 2); - assert!(Balance::value(&balance3) == 334, 3); + assert!(balance::value(&balance1) == 333, 1); + assert!(balance::value(&balance2) == 333, 2); + assert!(balance::value(&balance3) == 334, 3); - Balance::destroy_for_testing(balance1); - Balance::destroy_for_testing(balance2); - Balance::destroy_for_testing(balance3); + balance::destroy_for_testing(balance1); + balance::destroy_for_testing(balance2); + balance::destroy_for_testing(balance3); } } diff --git a/crates/sui-framework/sources/Coin.move b/crates/sui-framework/sources/coin.move similarity index 82% rename from crates/sui-framework/sources/Coin.move rename to crates/sui-framework/sources/coin.move index 9bd3ccdfe6cb5..8fe5167a85441 100644 --- a/crates/sui-framework/sources/Coin.move +++ b/crates/sui-framework/sources/coin.move @@ -1,11 +1,11 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::Coin { - use Sui::Balance::{Self, Balance}; - use Sui::ID::{Self, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module sui::coin { + use sui::balance::{Self, Balance}; + use sui::id::{Self, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; use std::vector; /// A coin of type `T` worth `value`. Transferable and storable @@ -35,13 +35,13 @@ module Sui::Coin { /// Wrap a balance into a Coin to make it transferable. public fun from_balance(balance: Balance, ctx: &mut TxContext): Coin { - Coin { id: TxContext::new_id(ctx), balance } + Coin { id: tx_context::new_id(ctx), balance } } /// Destruct a Coin wrapper and keep the balance. public fun into_balance(coin: Coin): Balance { let Coin { id, balance } = coin; - ID::delete(id); + id::delete(id); balance } @@ -52,34 +52,34 @@ module Sui::Coin { balance: &mut Balance, value: u64, ctx: &mut TxContext, ): Coin { Coin { - id: TxContext::new_id(ctx), - balance: Balance::split(balance, value) + id: tx_context::new_id(ctx), + balance: balance::split(balance, value) } } /// Deposit a `Coin` to the `Balance` public fun deposit(balance: &mut Balance, coin: Coin) { - Balance::join(balance, into_balance(coin)); + balance::join(balance, into_balance(coin)); } // === Functionality for Coin holders === /// Send `c` to `recipient` public entry fun transfer(c: Coin, recipient: address) { - Transfer::transfer(c, recipient) + transfer::transfer(c, recipient) } /// Transfer `c` to the sender of the current transaction public fun keep(c: Coin, ctx: &TxContext) { - transfer(c, TxContext::sender(ctx)) + transfer(c, tx_context::sender(ctx)) } /// Consume the coin `c` and add its value to `self`. /// Aborts if `c.value + self.value > U64_MAX` public entry fun join(self: &mut Coin, c: Coin) { let Coin { id, balance } = c; - ID::delete(id); - Balance::join(&mut self.balance, balance); + id::delete(id); + balance::join(&mut self.balance, balance); } /// Join everything in `coins` with `self` @@ -97,14 +97,14 @@ module Sui::Coin { /// Public getter for the coin's value public fun value(self: &Coin): u64 { - Balance::value(&self.balance) + balance::value(&self.balance) } /// Destroy a coin with value zero public fun destroy_zero(c: Coin) { let Coin { id, balance } = c; - ID::delete(id); - Balance::destroy_zero(balance); + id::delete(id); + balance::destroy_zero(balance); } // === Registering new coin types and managing the coin supply === @@ -112,7 +112,7 @@ module Sui::Coin { /// Make any Coin with a zero value. Useful for placeholding /// bids/payments or preemptively making empty balances. public fun zero(ctx: &mut TxContext): Coin { - Coin { id: TxContext::new_id(ctx), balance: Balance::zero() } + Coin { id: tx_context::new_id(ctx), balance: balance::zero() } } /// Create a new currency type `T` as and return the `TreasuryCap` @@ -125,7 +125,7 @@ module Sui::Coin { _witness: T, ctx: &mut TxContext ): TreasuryCap { - TreasuryCap { id: TxContext::new_id(ctx), total_supply: 0 } + TreasuryCap { id: tx_context::new_id(ctx), total_supply: 0 } } /// Create a coin worth `value`. and increase the total supply @@ -134,7 +134,7 @@ module Sui::Coin { value: u64, cap: &mut TreasuryCap, ctx: &mut TxContext, ): Coin { Coin { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), balance: mint_balance(value, cap) } } @@ -146,15 +146,15 @@ module Sui::Coin { value: u64, cap: &mut TreasuryCap ): Balance { cap.total_supply = cap.total_supply + value; - Balance::create_with_value(value) + balance::create_with_value(value) } /// Destroy the coin `c` and decrease the total supply in `cap` /// accordingly. public fun burn(c: Coin, cap: &mut TreasuryCap) { let Coin { id, balance } = c; - let value = Balance::destroy(balance); - ID::delete(id); + let value = balance::destroy(balance); + id::delete(id); cap.total_supply = cap.total_supply - value } @@ -165,7 +165,7 @@ module Sui::Coin { /// Give away the treasury cap to `recipient` public fun transfer_cap(c: TreasuryCap, recipient: address) { - Transfer::transfer(c, recipient) + transfer::transfer(c, recipient) } // === Entrypoints === @@ -173,14 +173,14 @@ module Sui::Coin { /// Send `amount` units of `c` to `recipient /// Aborts with `EVALUE` if `amount` is greater than or equal to `amount` public entry fun split_and_transfer(c: &mut Coin, amount: u64, recipient: address, ctx: &mut TxContext) { - Transfer::transfer(withdraw(&mut c.balance, amount, ctx), recipient) + transfer::transfer(withdraw(&mut c.balance, amount, ctx), recipient) } /// Split coin `self` to two coins, one with balance `split_amount`, /// and the remaining balance is left is `self`. public entry fun split(self: &mut Coin, split_amount: u64, ctx: &mut TxContext) { let new_coin = withdraw(&mut self.balance, split_amount, ctx); - Transfer::transfer(new_coin, TxContext::sender(ctx)); + transfer::transfer(new_coin, tx_context::sender(ctx)); } /// Split coin `self` into multiple coins, each with balance specified @@ -199,14 +199,14 @@ module Sui::Coin { #[test_only] /// Mint coins of any type for (obviously!) testing purposes only public fun mint_for_testing(value: u64, ctx: &mut TxContext): Coin { - Coin { id: TxContext::new_id(ctx), balance: Balance::create_with_value(value) } + Coin { id: tx_context::new_id(ctx), balance: balance::create_with_value(value) } } #[test_only] /// Destroy a `Coin` with any value in it for testing purposes. public fun destroy_for_testing(self: Coin): u64 { let Coin { id, balance } = self; - ID::delete(id); - Balance::destroy_for_testing(balance) + id::delete(id); + balance::destroy_for_testing(balance) } } diff --git a/crates/sui-framework/sources/Collection.move b/crates/sui-framework/sources/collection.move similarity index 89% rename from crates/sui-framework/sources/Collection.move rename to crates/sui-framework/sources/collection.move index d95f028a28656..48878bb4e7b19 100644 --- a/crates/sui-framework/sources/Collection.move +++ b/crates/sui-framework/sources/collection.move @@ -11,13 +11,13 @@ /// Collection allows us to own a list of same-typed objects, but still able to /// access and operate on each individual object. /// In contrast to `Bag`, `Collection` requires all objects have the same type. -module Sui::Collection { +module sui::collection { use std::errors; use std::option::{Self, Option}; use std::vector::Self; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer::{Self, ChildRef}; - use Sui::TxContext::{Self, TxContext}; + use sui::id::{Self, ID, VersionedID}; + use sui::transfer::{Self, ChildRef}; + use sui::tx_context::{Self, TxContext}; // Error codes /// When removing an object from the collection, EObjectNotFound @@ -62,7 +62,7 @@ module Sui::Collection { errors::limit_exceeded(EInvalidMaxCapacity) ); Collection { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), objects: vector::empty(), max_capacity, } @@ -70,7 +70,7 @@ module Sui::Collection { /// Create a new Collection and transfer it to the signer. public entry fun create(ctx: &mut TxContext) { - Transfer::transfer(new(ctx), TxContext::sender(ctx)) + transfer::transfer(new(ctx), tx_context::sender(ctx)) } /// Returns the size of the collection. @@ -91,13 +91,13 @@ module Sui::Collection { size(c) + 1 <= c.max_capacity, errors::limit_exceeded(EMaxCapacityExceeded) ); - let id = ID::id(&object); + let id = id::id(&object); assert!(!contains(c, id), EObjectDoubleAdd); let child_ref = if (option::is_none(&old_child_ref)) { - Transfer::transfer_to_object(object, c) + transfer::transfer_to_object(object, c) } else { let old_child_ref = option::extract(&mut old_child_ref); - Transfer::transfer_child_to_object(object, old_child_ref, c) + transfer::transfer_child_to_object(object, old_child_ref, c) }; vector::push_back(&mut c.objects, child_ref); option::destroy_none(old_child_ref); @@ -129,7 +129,7 @@ module Sui::Collection { /// Remove and return the object from the collection. /// Abort if the object is not found. public fun remove(c: &mut Collection, object: T): (T, ChildRef) { - let idx = find(c, ID::id(&object)); + let idx = find(c, id::id(&object)); assert!(option::is_some(&idx), EObjectNotFound); let child_ref = vector::remove(&mut c.objects, *option::borrow(&idx)); (object, child_ref) @@ -142,19 +142,19 @@ module Sui::Collection { ctx: &mut TxContext, ) { let (object, child_ref) = remove(c, object); - Transfer::transfer_child_to_address(object, child_ref, TxContext::sender(ctx)); + transfer::transfer_child_to_address(object, child_ref, tx_context::sender(ctx)); } /// Transfer the entire collection to `recipient`. public entry fun transfer(c: Collection, recipient: address) { - Transfer::transfer(c, recipient) + transfer::transfer(c, recipient) } public fun transfer_to_object_id( obj: Collection, owner_id: VersionedID, ): (VersionedID, ChildRef>) { - Transfer::transfer_to_object_id(obj, owner_id) + transfer::transfer_to_object_id(obj, owner_id) } /// Look for the object identified by `id_bytes` in the collection. @@ -164,7 +164,7 @@ module Sui::Collection { let len = size(c); while (i < len) { let child_ref = vector::borrow(&c.objects, i); - if (Transfer::is_child_unsafe(child_ref, id)) { + if (transfer::is_child_unsafe(child_ref, id)) { return option::some(i) }; i = i + 1; diff --git a/crates/sui-framework/sources/DevNetNFT.move b/crates/sui-framework/sources/devnet_nft.move similarity index 51% rename from crates/sui-framework/sources/DevNetNFT.move rename to crates/sui-framework/sources/devnet_nft.move index 282e61af8bf52..881633814df27 100644 --- a/crates/sui-framework/sources/DevNetNFT.move +++ b/crates/sui-framework/sources/devnet_nft.move @@ -5,21 +5,21 @@ /// on Sui. The user should be able to use the wallet command line tool /// (https://docs.sui.io/build/wallet) to mint an NFT. For example, /// `wallet example-nft --name --description --url ` -module Sui::DevNetNFT { - use Sui::Url::{Self, Url}; - use Sui::UTF8; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Event; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module sui::devnet_nft { + use sui::url::{Self, Url}; + use sui::utf8; + use sui::id::{Self, ID, VersionedID}; + use sui::event; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// An example NFT that can be minted by anybody struct DevNetNFT has key, store { id: VersionedID, /// Name for the token - name: UTF8::String, + name: utf8::String, /// Description of the token - description: UTF8::String, + description: utf8::String, /// URL for the token url: Url, // TODO: allow custom attributes @@ -31,10 +31,10 @@ module Sui::DevNetNFT { // The creator of the NFT creator: address, // The name of the NFT - name: UTF8::String, + name: utf8::String, } - /// Create a new DevNetNFT + /// Create a new devnet_nft public entry fun mint( name: vector, description: vector, @@ -42,25 +42,25 @@ module Sui::DevNetNFT { ctx: &mut TxContext ) { let nft = DevNetNFT { - id: TxContext::new_id(ctx), - name: UTF8::string_unsafe(name), - description: UTF8::string_unsafe(description), - url: Url::new_unsafe_from_bytes(url) + id: tx_context::new_id(ctx), + name: utf8::string_unsafe(name), + description: utf8::string_unsafe(description), + url: url::new_unsafe_from_bytes(url) }; - let sender = TxContext::sender(ctx); - Event::emit(MintNFTEvent { - object_id: *ID::inner(&nft.id), + let sender = tx_context::sender(ctx); + event::emit(MintNFTEvent { + object_id: *id::inner(&nft.id), creator: sender, name: nft.name, }); - Transfer::transfer(nft, sender); + transfer::transfer(nft, sender); } /// Transfer `nft` to `recipient` public entry fun transfer( nft: DevNetNFT, recipient: address, _: &mut TxContext ) { - Transfer::transfer(nft, recipient) + transfer::transfer(nft, recipient) } /// Update the `description` of `nft` to `new_description` @@ -69,22 +69,22 @@ module Sui::DevNetNFT { new_description: vector, _: &mut TxContext ) { - nft.description = UTF8::string_unsafe(new_description) + nft.description = utf8::string_unsafe(new_description) } /// Permanently delete `nft` public entry fun burn(nft: DevNetNFT, _: &mut TxContext) { let DevNetNFT { id, name: _, description: _, url: _ } = nft; - ID::delete(id) + id::delete(id) } /// Get the NFT's `name` - public fun name(nft: &DevNetNFT): &UTF8::String { + public fun name(nft: &DevNetNFT): &utf8::String { &nft.name } /// Get the NFT's `description` - public fun description(nft: &DevNetNFT): &UTF8::String { + public fun description(nft: &DevNetNFT): &utf8::String { &nft.description } @@ -95,39 +95,39 @@ module Sui::DevNetNFT { } #[test_only] -module Sui::DevNetNFTTests { - use Sui::DevNetNFT::{Self, DevNetNFT}; - use Sui::TestScenario; - use Sui::UTF8; +module sui::devnet_nftTests { + use sui::devnet_nft::{Self, DevNetNFT}; + use sui::test_scenario; + use sui::utf8; #[test] fun mint_transfer_update() { let addr1 = @0xA; let addr2 = @0xB; // create the NFT - let scenario = TestScenario::begin(&addr1); + let scenario = test_scenario::begin(&addr1); { - DevNetNFT::mint(b"test", b"a test", b"https://www.sui.io", TestScenario::ctx(&mut scenario)) + devnet_nft::mint(b"test", b"a test", b"https://www.sui.io", test_scenario::ctx(&mut scenario)) }; // send it from A to B - TestScenario::next_tx(&mut scenario, &addr1); + test_scenario::next_tx(&mut scenario, &addr1); { - let nft = TestScenario::take_owned(&mut scenario); - DevNetNFT::transfer(nft, addr2, TestScenario::ctx(&mut scenario)); + let nft = test_scenario::take_owned(&mut scenario); + devnet_nft::transfer(nft, addr2, test_scenario::ctx(&mut scenario)); }; // update its description - TestScenario::next_tx(&mut scenario, &addr2); + test_scenario::next_tx(&mut scenario, &addr2); { - let nft = TestScenario::take_owned(&mut scenario); - DevNetNFT::update_description(&mut nft, b"a new description", TestScenario::ctx(&mut scenario)) ; - assert!(*UTF8::bytes(DevNetNFT::description(&nft)) == b"a new description", 0); - TestScenario::return_owned(&mut scenario, nft); + let nft = test_scenario::take_owned(&mut scenario); + devnet_nft::update_description(&mut nft, b"a new description", test_scenario::ctx(&mut scenario)) ; + assert!(*utf8::bytes(devnet_nft::description(&nft)) == b"a new description", 0); + test_scenario::return_owned(&mut scenario, nft); }; // burn it - TestScenario::next_tx(&mut scenario, &addr2); + test_scenario::next_tx(&mut scenario, &addr2); { - let nft = TestScenario::take_owned(&mut scenario); - DevNetNFT::burn(nft, TestScenario::ctx(&mut scenario)) + let nft = test_scenario::take_owned(&mut scenario); + devnet_nft::burn(nft, test_scenario::ctx(&mut scenario)) } } } diff --git a/crates/sui-framework/sources/EpochTimeLock.move b/crates/sui-framework/sources/epoch_time_lock.move similarity index 80% rename from crates/sui-framework/sources/EpochTimeLock.move rename to crates/sui-framework/sources/epoch_time_lock.move index f5b1bf7abef7e..9a4146a48db8f 100644 --- a/crates/sui-framework/sources/EpochTimeLock.move +++ b/crates/sui-framework/sources/epoch_time_lock.move @@ -1,8 +1,8 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::EpochTimeLock { - use Sui::TxContext::{Self, TxContext}; +module sui::epoch_time_lock { + use sui::tx_context::{Self, TxContext}; /// The epoch passed into the creation of a lock has already passed. const EEPOCH_ALREADY_PASSED: u64 = 0; @@ -17,13 +17,13 @@ module Sui::EpochTimeLock { /// Create a new epoch time lock with `epoch`. Aborts if the current epoch is less than the input epoch. public fun new(epoch: u64, ctx: &mut TxContext) : EpochTimeLock { - assert!(TxContext::epoch(ctx) < epoch, EEPOCH_ALREADY_PASSED); + assert!(tx_context::epoch(ctx) < epoch, EEPOCH_ALREADY_PASSED); EpochTimeLock { epoch } } /// Destroys an epoch time lock. Aborts if the current epoch is less than the locked epoch. public fun destroy(lock: EpochTimeLock, ctx: &mut TxContext) { let EpochTimeLock { epoch } = lock; - assert!(TxContext::epoch(ctx) >= epoch, EEPOCH_STILL_LOCKED); + assert!(tx_context::epoch(ctx) >= epoch, EEPOCH_STILL_LOCKED); } } diff --git a/crates/sui-framework/sources/ERC721Metadata.move b/crates/sui-framework/sources/erc721_metadata.move similarity index 86% rename from crates/sui-framework/sources/ERC721Metadata.move rename to crates/sui-framework/sources/erc721_metadata.move index 918efc19b9da5..6545889381a47 100644 --- a/crates/sui-framework/sources/ERC721Metadata.move +++ b/crates/sui-framework/sources/erc721_metadata.move @@ -1,10 +1,10 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::ERC721Metadata { +module sui::erc721_metadata { use std::ascii; - use Sui::Url::{Self, Url}; - use Sui::UTF8; + use sui::url::{Self, Url}; + use sui::utf8; // TODO: add symbol()? /// A wrapper type for the ERC721 metadata standard https://eips.ethereum.org/EIPS/eip-721 @@ -14,7 +14,7 @@ module Sui::ERC721Metadata { /// A descriptive name for a collection of NFTs in this contract. /// This corresponds to the `name()` method in the /// ERC721Metadata interface in EIP-721. - name: UTF8::String, + name: utf8::String, /// A distinct Uniform Resource Identifier (URI) for a given asset. /// This corresponds to the `tokenURI()` method in the ERC721Metadata /// interface in EIP-721. @@ -35,8 +35,8 @@ module Sui::ERC721Metadata { let uri_str = ascii::string(token_uri); ERC721Metadata { token_id, - name: UTF8::string_unsafe(name), - token_uri: Url::new_unsafe(uri_str), + name: utf8::string_unsafe(name), + token_uri: url::new_unsafe(uri_str), } } @@ -52,7 +52,7 @@ module Sui::ERC721Metadata { &self.token_uri } - public fun name(self: &ERC721Metadata): &UTF8::String { + public fun name(self: &ERC721Metadata): &utf8::String { &self.name } } diff --git a/crates/sui-framework/sources/Event.move b/crates/sui-framework/sources/event.move similarity index 94% rename from crates/sui-framework/sources/Event.move rename to crates/sui-framework/sources/event.move index 983cd12d2cd7a..0eaab32b4c7e5 100644 --- a/crates/sui-framework/sources/Event.move +++ b/crates/sui-framework/sources/event.move @@ -1,7 +1,7 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::Event { +module sui::event { /// Add `t` to the event log of this transaction // TODO(https://github.com/MystenLabs/sui/issues/19): diff --git a/crates/sui-framework/sources/Governance/Delegation.move b/crates/sui-framework/sources/governance/delegation.move similarity index 82% rename from crates/sui-framework/sources/Governance/Delegation.move rename to crates/sui-framework/sources/governance/delegation.move index 59c3440ee04f7..9beaeb07578e9 100644 --- a/crates/sui-framework/sources/Governance/Delegation.move +++ b/crates/sui-framework/sources/governance/delegation.move @@ -1,18 +1,18 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::Delegation { +module sui::delegation { use std::option::{Self, Option}; - use Sui::Balance::Balance; - use Sui::Coin::{Self, Coin}; - use Sui::ID::{Self, VersionedID}; - use Sui::LockedCoin::{Self, LockedCoin}; - use Sui::SUI::SUI; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; - use Sui::EpochTimeLock::EpochTimeLock; + use sui::balance::Balance; + use sui::coin::{Self, Coin}; + use sui::id::{Self, VersionedID}; + use sui::locked_coin::{Self, LockedCoin}; + use sui::sui::SUI; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + use sui::epoch_time_lock::EpochTimeLock; - friend Sui::SuiSystem; + friend sui::sui_system; /// A custodial delegation object. When the delegation is active, the delegation /// object holds the delegated stake coin. It also contains the delegation @@ -52,17 +52,17 @@ module Sui::Delegation { stake: Coin, ctx: &mut TxContext, ) { - let delegate_amount = Coin::value(&stake); + let delegate_amount = coin::value(&stake); let delegation = Delegation { - id: TxContext::new_id(ctx), - active_delegation: option::some(Coin::into_balance(stake)), + id: tx_context::new_id(ctx), + active_delegation: option::some(coin::into_balance(stake)), ending_epoch: option::none(), delegate_amount, next_reward_unclaimed_epoch: starting_epoch, coin_locked_until_epoch: option::none(), validator_address, }; - Transfer::transfer(delegation, TxContext::sender(ctx)) + transfer::transfer(delegation, tx_context::sender(ctx)) } public(friend) fun create_from_locked_coin( @@ -71,10 +71,10 @@ module Sui::Delegation { stake: LockedCoin, ctx: &mut TxContext, ) { - let delegate_amount = LockedCoin::value(&stake); - let (balance, epoch_lock) = LockedCoin::into_balance(stake); + let delegate_amount = locked_coin::value(&stake); + let (balance, epoch_lock) = locked_coin::into_balance(stake); let delegation = Delegation { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), active_delegation: option::some(balance), ending_epoch: option::none(), delegate_amount, @@ -82,7 +82,7 @@ module Sui::Delegation { coin_locked_until_epoch: option::some(epoch_lock), validator_address, }; - Transfer::transfer(delegation, TxContext::sender(ctx)) + transfer::transfer(delegation, tx_context::sender(ctx)) } /// Deactivate the delegation. Send back the stake and set the ending epoch. @@ -95,13 +95,13 @@ module Sui::Delegation { assert!(ending_epoch >= self.next_reward_unclaimed_epoch, 0); let stake = option::extract(&mut self.active_delegation); - let sender = TxContext::sender(ctx); + let sender = tx_context::sender(ctx); if (option::is_none(&self.coin_locked_until_epoch)) { - Transfer::transfer(Coin::from_balance(stake, ctx), sender); + transfer::transfer(coin::from_balance(stake, ctx), sender); } else { let locked_until_epoch = option::extract(&mut self.coin_locked_until_epoch); - LockedCoin::new_from_balance(stake, locked_until_epoch, sender, ctx); + locked_coin::new_from_balance(stake, locked_until_epoch, sender, ctx); }; self.ending_epoch = option::some(ending_epoch); @@ -113,8 +113,8 @@ module Sui::Delegation { reward: Balance, ctx: &mut TxContext, ) { - let sender = TxContext::sender(ctx); - Coin::transfer(Coin::from_balance(reward, ctx), sender); + let sender = tx_context::sender(ctx); + coin::transfer(coin::from_balance(reward, ctx), sender); self.next_reward_unclaimed_epoch = self.next_reward_unclaimed_epoch + 1; } @@ -133,7 +133,7 @@ module Sui::Delegation { coin_locked_until_epoch, validator_address: _, } = self; - ID::delete(id); + id::delete(id); option::destroy_none(active_delegation); option::destroy_none(coin_locked_until_epoch); let ending_epoch = *option::borrow(&ending_epoch); @@ -141,7 +141,7 @@ module Sui::Delegation { } public entry fun transfer(self: Delegation, recipient: address) { - Transfer::transfer(self, recipient) + transfer::transfer(self, recipient) } /// Checks whether the delegation object is eligible to claim the reward diff --git a/crates/sui-framework/sources/Governance/EpochRewardRecord.move b/crates/sui-framework/sources/governance/epoch_reward_record.move similarity index 85% rename from crates/sui-framework/sources/Governance/EpochRewardRecord.move rename to crates/sui-framework/sources/governance/epoch_reward_record.move index 8cb7d927c515f..a36a07ff4436a 100644 --- a/crates/sui-framework/sources/Governance/EpochRewardRecord.move +++ b/crates/sui-framework/sources/governance/epoch_reward_record.move @@ -1,13 +1,13 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::EpochRewardRecord { - use Sui::ID::VersionedID; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module sui::epoch_reward_record { + use sui::id::VersionedID; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; - friend Sui::SuiSystem; - friend Sui::ValidatorSet; + friend sui::sui_system; + friend sui::validator_set; /// EpochRewardRecord is an immutable record created per epoch per active validator. /// Sufficient information is saved in the record so that delegators can claim @@ -32,8 +32,8 @@ module Sui::EpochRewardRecord { validator: address, ctx: &mut TxContext, ) { - Transfer::share_object(EpochRewardRecord { - id: TxContext::new_id(ctx), + transfer::share_object(EpochRewardRecord { + id: tx_context::new_id(ctx), epoch, computation_charge, total_stake, @@ -56,6 +56,4 @@ module Sui::EpochRewardRecord { public fun validator(self: &EpochRewardRecord): address { self.validator } - - } diff --git a/crates/sui-framework/sources/Governance/Genesis.move b/crates/sui-framework/sources/governance/genesis.move similarity index 84% rename from crates/sui-framework/sources/Governance/Genesis.move rename to crates/sui-framework/sources/governance/genesis.move index 92182e601909d..115df95f8cb06 100644 --- a/crates/sui-framework/sources/Governance/Genesis.move +++ b/crates/sui-framework/sources/governance/genesis.move @@ -1,14 +1,14 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::Genesis { +module sui::genesis { use std::vector; - use Sui::Coin; - use Sui::SUI; - use Sui::SuiSystem; - use Sui::TxContext::TxContext; - use Sui::Validator; + use sui::coin; + use sui::sui; + use sui::sui_system; + use sui::tx_context::TxContext; + use sui::validator; /// The initial amount of SUI locked in the storage fund. /// 10^14, an arbitrary number. @@ -31,8 +31,8 @@ module Sui::Genesis { validator_stakes: vector, ctx: &mut TxContext, ) { - let treasury_cap = SUI::new(ctx); - let storage_fund = Coin::mint_balance(INIT_STORAGE_FUND, &mut treasury_cap); + let treasury_cap = sui::new(ctx); + let storage_fund = coin::mint_balance(INIT_STORAGE_FUND, &mut treasury_cap); let validators = vector::empty(); let count = vector::length(&validator_pubkeys); assert!( @@ -49,16 +49,16 @@ module Sui::Genesis { let name = *vector::borrow(&validator_names, i); let net_address = *vector::borrow(&validator_net_addresses, i); let stake = *vector::borrow(&validator_stakes, i); - vector::push_back(&mut validators, Validator::new( + vector::push_back(&mut validators, validator::new( sui_address, pubkey, name, net_address, - Coin::mint_balance(stake, &mut treasury_cap), + coin::mint_balance(stake, &mut treasury_cap), )); i = i + 1; }; - SuiSystem::create( + sui_system::create( validators, treasury_cap, storage_fund, diff --git a/crates/sui-framework/sources/Governance/SuiSystem.move b/crates/sui-framework/sources/governance/sui_system.move similarity index 72% rename from crates/sui-framework/sources/Governance/SuiSystem.move rename to crates/sui-framework/sources/governance/sui_system.move index d2a1dac06c427..239b02c9bd0dc 100644 --- a/crates/sui-framework/sources/Governance/SuiSystem.move +++ b/crates/sui-framework/sources/governance/sui_system.move @@ -1,20 +1,20 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::SuiSystem { - use Sui::Balance::{Self, Balance}; - use Sui::Coin::{Self, Coin, TreasuryCap}; - use Sui::Delegation::{Self, Delegation}; - use Sui::EpochRewardRecord::{Self, EpochRewardRecord}; - use Sui::ID::{Self, VersionedID}; - use Sui::LockedCoin::{Self, LockedCoin}; - use Sui::SUI::SUI; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; - use Sui::Validator::{Self, Validator}; - use Sui::ValidatorSet::{Self, ValidatorSet}; +module sui::sui_system { + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin, TreasuryCap}; + use sui::delegation::{Self, Delegation}; + use sui::epoch_reward_record::{Self, EpochRewardRecord}; + use sui::id::{Self, VersionedID}; + use sui::locked_coin::{Self, LockedCoin}; + use sui::sui::SUI; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + use sui::validator::{Self, Validator}; + use sui::validator_set::{Self, ValidatorSet}; - friend Sui::Genesis; + friend sui::genesis; /// A list of system config parameters. // TDOO: We will likely add more, a few potential ones: @@ -61,18 +61,18 @@ module Sui::SuiSystem { ) { let state = SuiSystemState { // Use a hardcoded ID. - id: ID::get_sui_system_state_object_id(), + id: id::get_sui_system_state_object_id(), epoch: 0, - validators: ValidatorSet::new(validators), + validators: validator_set::new(validators), treasury_cap, storage_fund, parameters: SystemParameters { min_validator_stake, max_validator_candidate_count, }, - delegation_reward: Balance::zero(), + delegation_reward: balance::zero(), }; - Transfer::share_object(state); + transfer::share_object(state); } // ==== entry functions ==== @@ -91,23 +91,23 @@ module Sui::SuiSystem { ctx: &mut TxContext, ) { assert!( - ValidatorSet::total_validator_candidate_count(&self.validators) < self.parameters.max_validator_candidate_count, + validator_set::total_validator_candidate_count(&self.validators) < self.parameters.max_validator_candidate_count, 0 ); - let stake_amount = Coin::value(&stake); + let stake_amount = coin::value(&stake); assert!( stake_amount >= self.parameters.min_validator_stake, 0 ); - let validator = Validator::new( - TxContext::sender(ctx), + let validator = validator::new( + tx_context::sender(ctx), pubkey_bytes, name, net_address, - Coin::into_balance(stake) + coin::into_balance(stake) ); - ValidatorSet::request_add_validator(&mut self.validators, validator); + validator_set::request_add_validator(&mut self.validators, validator); } /// A validator can call this function to request a removal in the next epoch. @@ -119,7 +119,7 @@ module Sui::SuiSystem { self: &mut SuiSystemState, ctx: &mut TxContext, ) { - ValidatorSet::request_remove_validator( + validator_set::request_remove_validator( &mut self.validators, ctx, ) @@ -131,9 +131,9 @@ module Sui::SuiSystem { new_stake: Coin, ctx: &mut TxContext, ) { - ValidatorSet::request_add_stake( + validator_set::request_add_stake( &mut self.validators, - Coin::into_balance(new_stake), + coin::into_balance(new_stake), ctx, ) } @@ -148,7 +148,7 @@ module Sui::SuiSystem { withdraw_amount: u64, ctx: &mut TxContext, ) { - ValidatorSet::request_withdraw_stake( + validator_set::request_withdraw_stake( &mut self.validators, withdraw_amount, self.parameters.min_validator_stake, @@ -162,12 +162,12 @@ module Sui::SuiSystem { validator_address: address, ctx: &mut TxContext, ) { - let amount = Coin::value(&delegate_stake); - ValidatorSet::request_add_delegation(&mut self.validators, validator_address, amount); + let amount = coin::value(&delegate_stake); + validator_set::request_add_delegation(&mut self.validators, validator_address, amount); // Delegation starts from the next epoch. let starting_epoch = self.epoch + 1; - Delegation::create(starting_epoch, validator_address, delegate_stake, ctx); + delegation::create(starting_epoch, validator_address, delegate_stake, ctx); } public entry fun request_add_delegation_with_locked_coin( @@ -176,12 +176,12 @@ module Sui::SuiSystem { validator_address: address, ctx: &mut TxContext, ) { - let amount = LockedCoin::value(&delegate_stake); - ValidatorSet::request_add_delegation(&mut self.validators, validator_address, amount); + let amount = locked_coin::value(&delegate_stake); + validator_set::request_add_delegation(&mut self.validators, validator_address, amount); // Delegation starts from the next epoch. let starting_epoch = self.epoch + 1; - Delegation::create_from_locked_coin(starting_epoch, validator_address, delegate_stake, ctx); + delegation::create_from_locked_coin(starting_epoch, validator_address, delegate_stake, ctx); } public entry fun request_remove_delegation( @@ -189,12 +189,12 @@ module Sui::SuiSystem { delegation: &mut Delegation, ctx: &mut TxContext, ) { - ValidatorSet::request_remove_delegation( + validator_set::request_remove_delegation( &mut self.validators, - Delegation::validator(delegation), - Delegation::delegate_amount(delegation), + delegation::validator(delegation), + delegation::delegate_amount(delegation), ); - Delegation::undelegate(delegation, self.epoch, ctx) + delegation::undelegate(delegation, self.epoch, ctx) } // TODO: Once we support passing vector of object references as arguments, @@ -206,15 +206,15 @@ module Sui::SuiSystem { epoch_reward_record: &mut EpochRewardRecord, ctx: &mut TxContext, ) { - let epoch = EpochRewardRecord::epoch(epoch_reward_record); - let validator = EpochRewardRecord::validator(epoch_reward_record); - assert!(Delegation::can_claim_reward(delegation, epoch, validator), 0); - let reward_amount = EpochRewardRecord::claim_reward( + let epoch = epoch_reward_record::epoch(epoch_reward_record); + let validator = epoch_reward_record::validator(epoch_reward_record); + assert!(delegation::can_claim_reward(delegation, epoch, validator), 0); + let reward_amount = epoch_reward_record::claim_reward( epoch_reward_record, - Delegation::delegate_amount(delegation), + delegation::delegate_amount(delegation), ); - let reward = Balance::split(&mut self.delegation_reward, reward_amount); - Delegation::claim_reward(delegation, reward, ctx); + let reward = balance::split(&mut self.delegation_reward, reward_amount); + delegation::claim_reward(delegation, reward, ctx); } /// This function should be called at the end of an epoch, and advances the system to the next epoch. @@ -231,22 +231,22 @@ module Sui::SuiSystem { ctx: &mut TxContext, ) { // Validator will make a special system call with sender set as 0x0. - assert!(TxContext::sender(ctx) == @0x0, 0); + assert!(tx_context::sender(ctx) == @0x0, 0); - let storage_reward = Balance::create_with_value(storage_charge); - let computation_reward = Balance::create_with_value(computation_charge); + let storage_reward = balance::create_with_value(storage_charge); + let computation_reward = balance::create_with_value(computation_charge); - let delegation_stake = ValidatorSet::delegation_stake(&self.validators); - let validator_stake = ValidatorSet::validator_stake(&self.validators); - let storage_fund = Balance::value(&self.storage_fund); + let delegation_stake = validator_set::delegation_stake(&self.validators); + let validator_stake = validator_set::validator_stake(&self.validators); + let storage_fund = balance::value(&self.storage_fund); let total_stake = delegation_stake + validator_stake + storage_fund; let delegator_reward_amount = delegation_stake * computation_charge / total_stake; - let delegator_reward = Balance::split(&mut computation_reward, delegator_reward_amount); - Balance::join(&mut self.storage_fund, storage_reward); - Balance::join(&mut self.delegation_reward, delegator_reward); + let delegator_reward = balance::split(&mut computation_reward, delegator_reward_amount); + balance::join(&mut self.storage_fund, storage_reward); + balance::join(&mut self.delegation_reward, delegator_reward); - ValidatorSet::create_epoch_records( + validator_set::create_epoch_records( &self.validators, self.epoch, computation_charge, @@ -257,14 +257,14 @@ module Sui::SuiSystem { self.epoch = self.epoch + 1; // Sanity check to make sure we are advancing to the right epoch. assert!(new_epoch == self.epoch, 0); - ValidatorSet::advance_epoch( + validator_set::advance_epoch( &mut self.validators, &mut computation_reward, ctx, ); // Because of precision issues with integer divisions, we expect that there will be some // remaining balance in `computation_reward`. All of these go to the storage fund. - Balance::join(&mut self.storage_fund, computation_reward) + balance::join(&mut self.storage_fund, computation_reward) } /// Return the current epoch number. Useful for applications that need a coarse-grained concept of time, diff --git a/crates/sui-framework/sources/Governance/Validator.move b/crates/sui-framework/sources/governance/validator.move similarity index 89% rename from crates/sui-framework/sources/Governance/Validator.move rename to crates/sui-framework/sources/governance/validator.move index e29916d1698ff..2e3f754fbb5c2 100644 --- a/crates/sui-framework/sources/Governance/Validator.move +++ b/crates/sui-framework/sources/governance/validator.move @@ -1,25 +1,25 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::Validator { +module sui::validator { use std::ascii; use std::option::{Self, Option}; use std::vector; - use Sui::Balance::{Self, Balance}; - use Sui::Coin; - use Sui::SUI::SUI; - use Sui::Transfer; - use Sui::TxContext::TxContext; + use sui::balance::{Self, Balance}; + use sui::coin; + use sui::sui::SUI; + use sui::transfer; + use sui::tx_context::TxContext; - friend Sui::Genesis; - friend Sui::SuiSystem; - friend Sui::ValidatorSet; + friend sui::genesis; + friend sui::sui_system; + friend sui::validator_set; #[test_only] - friend Sui::ValidatorTests; + friend sui::validator_tests; #[test_only] - friend Sui::ValidatorSetTests; + friend sui::validator_set_tests; struct ValidatorMetadata has store, drop, copy { /// The Sui Address of the validator. This is the sender that created the Validator object, @@ -83,7 +83,7 @@ module Sui::Validator { pubkey_bytes, name, net_address, - next_epoch_stake: Balance::value(&stake), + next_epoch_stake: balance::value(&stake), }, stake, delegation: 0, @@ -115,10 +115,10 @@ module Sui::Validator { if (option::is_some(&pending_stake)) { // pending_stake can be non-empty as it can contain the gas reward from the last epoch. let pending_stake_balance = option::extract(&mut pending_stake); - Balance::join(&mut stake, pending_stake_balance); + balance::join(&mut stake, pending_stake_balance); }; option::destroy_none(pending_stake); - Transfer::transfer(Coin::from_balance(stake, ctx), metadata.sui_address); + transfer::transfer(coin::from_balance(stake, ctx), metadata.sui_address); } /// Add stake to an active validator. The new stake is added to the pending_stake field, @@ -127,10 +127,10 @@ module Sui::Validator { self: &mut Validator, new_stake: Balance, ) { - let new_stake_value = Balance::value(&new_stake); + let new_stake_value = balance::value(&new_stake); let pending_stake = if (option::is_some(&self.pending_stake)) { let pending_stake = option::extract(&mut self.pending_stake); - Balance::join(&mut pending_stake, new_stake); + balance::join(&mut pending_stake, new_stake); pending_stake } else { new_stake @@ -157,14 +157,14 @@ module Sui::Validator { public(friend) fun adjust_stake(self: &mut Validator, ctx: &mut TxContext) { if (option::is_some(&self.pending_stake)) { let pending_stake = option::extract(&mut self.pending_stake); - Balance::join(&mut self.stake, pending_stake); + balance::join(&mut self.stake, pending_stake); }; if (self.pending_withdraw > 0) { - let coin = Coin::withdraw(&mut self.stake, self.pending_withdraw, ctx); - Coin::transfer(coin, self.metadata.sui_address); + let coin = coin::withdraw(&mut self.stake, self.pending_withdraw, ctx); + coin::transfer(coin, self.metadata.sui_address); self.pending_withdraw = 0; }; - assert!(Balance::value(&self.stake) == self.metadata.next_epoch_stake, 0); + assert!(balance::value(&self.stake) == self.metadata.next_epoch_stake, 0); self.delegation = self.delegation + self.pending_delegation - self.pending_delegation_withdraw; self.pending_delegation = 0; @@ -195,7 +195,7 @@ module Sui::Validator { } public fun stake_amount(self: &Validator): u64 { - Balance::value(&self.stake) + balance::value(&self.stake) } public fun delegate_amount(self: &Validator): u64 { @@ -208,7 +208,7 @@ module Sui::Validator { public fun pending_stake_amount(self: &Validator): u64 { if (option::is_some(&self.pending_stake)) { - Balance::value(option::borrow(&self.pending_stake)) + balance::value(option::borrow(&self.pending_stake)) } else { 0 } diff --git a/crates/sui-framework/sources/Governance/ValidatorSet.move b/crates/sui-framework/sources/governance/validator_set.move similarity index 91% rename from crates/sui-framework/sources/Governance/ValidatorSet.move rename to crates/sui-framework/sources/governance/validator_set.move index fc4d2ad6ead95..2020a31d3a25e 100644 --- a/crates/sui-framework/sources/Governance/ValidatorSet.move +++ b/crates/sui-framework/sources/governance/validator_set.move @@ -1,20 +1,20 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::ValidatorSet { +module sui::validator_set { use std::option::{Self, Option}; use std::vector; - use Sui::Balance::{Self, Balance}; - use Sui::EpochRewardRecord; - use Sui::SUI::SUI; - use Sui::TxContext::{Self, TxContext}; - use Sui::Validator::{Self, Validator, ValidatorMetadata}; + use sui::balance::{Self, Balance}; + use sui::epoch_reward_record; + use sui::sui::SUI; + use sui::tx_context::{Self, TxContext}; + use sui::validator::{Self, Validator, ValidatorMetadata}; - friend Sui::SuiSystem; + friend sui::sui_system; #[test_only] - friend Sui::ValidatorSetTests; + friend sui::validator_set_tests; struct ValidatorSet has store { /// Total amount of stake from all active validators (not including delegation), @@ -86,7 +86,7 @@ module Sui::ValidatorSet { self: &mut ValidatorSet, ctx: &TxContext, ) { - let validator_address = TxContext::sender(ctx); + let validator_address = tx_context::sender(ctx); let validator_index_opt = find_validator(&self.active_validators, validator_address); assert!(option::is_some(&validator_index_opt), 0); let validator_index = option::extract(&mut validator_index_opt); @@ -106,9 +106,9 @@ module Sui::ValidatorSet { new_stake: Balance, ctx: &TxContext, ) { - let validator_address = TxContext::sender(ctx); + let validator_address = tx_context::sender(ctx); let validator = get_validator_mut(&mut self.active_validators, validator_address); - Validator::request_add_stake(validator, new_stake); + validator::request_add_stake(validator, new_stake); } /// Called by `SuiSystem`, to withdraw stake from a validator. @@ -120,9 +120,9 @@ module Sui::ValidatorSet { min_validator_stake: u64, ctx: &TxContext, ) { - let validator_address = TxContext::sender(ctx); + let validator_address = tx_context::sender(ctx); let validator = get_validator_mut(&mut self.active_validators, validator_address); - Validator::request_withdraw_stake(validator, withdraw_amount, min_validator_stake); + validator::request_withdraw_stake(validator, withdraw_amount, min_validator_stake); } public(friend) fun is_active_validator( @@ -138,7 +138,7 @@ module Sui::ValidatorSet { delegate_amount: u64, ) { let validator = get_validator_mut(&mut self.active_validators, validator_address); - Validator::request_add_delegation(validator, delegate_amount); + validator::request_add_delegation(validator, delegate_amount); } public(friend) fun request_remove_delegation( @@ -152,7 +152,7 @@ module Sui::ValidatorSet { if (option::is_some(&validator_index_opt)) { let validator_index = option::extract(&mut validator_index_opt); let validator = vector::borrow_mut(&mut self.active_validators, validator_index); - Validator::request_remove_delegation(validator, delegate_amount); + validator::request_remove_delegation(validator, delegate_amount); } } @@ -167,12 +167,12 @@ module Sui::ValidatorSet { let i = 0; while (i < length) { let v = vector::borrow(&self.active_validators, i); - EpochRewardRecord::create( + epoch_reward_record::create( epoch, computation_charge, total_stake, - Validator::delegator_count(v), - Validator::sui_address(v), + validator::delegator_count(v), + validator::sui_address(v), ctx, ); i = i + 1; @@ -195,7 +195,7 @@ module Sui::ValidatorSet { let rewards = compute_reward_distribution( &self.active_validators, self.validator_stake, - Balance::value(computation_reward), + balance::value(computation_reward), ); // `adjust_stake` must be called before `distribute_reward`, because reward distribution goes to @@ -231,7 +231,7 @@ module Sui::ValidatorSet { let i = 0; while (i < len) { let v = vector::borrow(validators, i); - if (Validator::is_duplicate(v, new_validator)) { + if (validator::is_duplicate(v, new_validator)) { return true }; i = i + 1; @@ -247,7 +247,7 @@ module Sui::ValidatorSet { let i = 0; while (i < length) { let v = vector::borrow(validators, i); - if (Validator::sui_address(v) == validator_address) { + if (validator::sui_address(v) == validator_address) { return option::some(i) }; i = i + 1; @@ -274,7 +274,7 @@ module Sui::ValidatorSet { while (!vector::is_empty(withdraw_list)) { let index = vector::pop_back(withdraw_list); let validator = vector::remove(validators, index); - Validator::destroy(validator, ctx); + validator::destroy(validator, ctx); } } @@ -315,8 +315,8 @@ module Sui::ValidatorSet { let i = 0; while (i < length) { let v = vector::borrow(validators, i); - validator_state = validator_state + Validator::stake_amount(v); - delegate_stake = delegate_stake + Validator::delegate_amount(v); + validator_state = validator_state + validator::stake_amount(v); + delegate_stake = delegate_stake + validator::delegate_amount(v); i = i + 1; }; let total_stake = validator_state + delegate_stake; @@ -338,7 +338,7 @@ module Sui::ValidatorSet { let i = 0; while (i < length) { let validator = vector::borrow_mut(validators, i); - Validator::adjust_stake(validator, ctx); + validator::adjust_stake(validator, ctx); i = i + 1; } } @@ -360,7 +360,7 @@ module Sui::ValidatorSet { // Integer divisions will truncate the results. Because of this, we expect that at the end // there will be some reward remaining in `total_reward`. // Use u128 to avoid multiplication overflow. - let stake_amount: u128 = (Validator::stake_amount(validator) as u128); + let stake_amount: u128 = (validator::stake_amount(validator) as u128); let reward_amount = stake_amount * (total_reward as u128) / (total_stake as u128); vector::push_back(&mut results, (reward_amount as u64)); i = i + 1; @@ -375,9 +375,9 @@ module Sui::ValidatorSet { while (i < length) { let validator = vector::borrow_mut(validators, i); let reward_amount = *vector::borrow(rewards, i); - let reward = Balance::split(reward, reward_amount); + let reward = balance::split(reward, reward_amount); // Because reward goes to pending stake, it's the same as calling `request_add_stake`. - Validator::request_add_stake(validator, reward); + validator::request_add_stake(validator, reward); i = i + 1; } } @@ -398,7 +398,7 @@ module Sui::ValidatorSet { continue }; }; - let metadata = Validator::metadata( + let metadata = validator::metadata( vector::borrow(&self.active_validators, active_count - 1), ); vector::push_back(&mut result, *metadata); @@ -423,7 +423,7 @@ module Sui::ValidatorSet { } = self; while (!vector::is_empty(&active_validators)) { let v = vector::pop_back(&mut active_validators); - Validator::destroy(v, ctx); + validator::destroy(v, ctx); }; vector::destroy_empty(active_validators); vector::destroy_empty(pending_validators); diff --git a/crates/sui-framework/sources/ID.move b/crates/sui-framework/sources/id.move similarity index 97% rename from crates/sui-framework/sources/ID.move rename to crates/sui-framework/sources/id.move index 01b8545d63234..8d4ee991032c9 100644 --- a/crates/sui-framework/sources/ID.move +++ b/crates/sui-framework/sources/id.move @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 /// Sui object identifiers -module Sui::ID { +module sui::id { use std::bcs; use std::vector; - friend Sui::SuiSystem; - friend Sui::Transfer; - friend Sui::TxContext; + friend sui::sui_system; + friend sui::transfer; + friend sui::tx_context; #[test_only] - friend Sui::TestScenario; + friend sui::test_scenario; /// Version of an object ID created by the current transaction. const INITIAL_VERSION: u64 = 0; @@ -48,7 +48,7 @@ module Sui::ID { /// A globally unique ID paired with a version. Similar to `UniqueID`, /// this is a privileged type that can only be derived from a `TxContext` /// VersionedID doesn't have the `drop` ability, so deleting a `VersionedID` - /// requires a call to `ID::delete` + /// requires a call to `id::delete` struct VersionedID has store { id: UniqueID, /// Version number for the object. The version number is incremented each diff --git a/crates/sui-framework/sources/LockedCoin.move b/crates/sui-framework/sources/locked_coin.move similarity index 69% rename from crates/sui-framework/sources/LockedCoin.move rename to crates/sui-framework/sources/locked_coin.move index b5d69193d21db..0cafc39d83e16 100644 --- a/crates/sui-framework/sources/LockedCoin.move +++ b/crates/sui-framework/sources/locked_coin.move @@ -1,15 +1,15 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::LockedCoin { - use Sui::Balance::{Self, Balance}; - use Sui::Coin::{Self, Coin}; - use Sui::ID::{Self, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; - use Sui::EpochTimeLock::{Self, EpochTimeLock}; +module sui::locked_coin { + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin}; + use sui::id::{Self, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + use sui::epoch_time_lock::{Self, EpochTimeLock}; - friend Sui::Delegation; + friend sui::delegation; /// A coin of type `T` locked until `locked_until_epoch`. struct LockedCoin has key, store { @@ -21,23 +21,23 @@ module Sui::LockedCoin { /// Create a LockedCoin from `balance` and transfer it to `owner`. public fun new_from_balance(balance: Balance, locked_until_epoch: EpochTimeLock, owner: address, ctx: &mut TxContext) { let locked_coin = LockedCoin { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), balance, locked_until_epoch }; - Transfer::transfer(locked_coin, owner); + transfer::transfer(locked_coin, owner); } /// Destruct a LockedCoin wrapper and keep the balance. public(friend) fun into_balance(coin: LockedCoin): (Balance, EpochTimeLock) { let LockedCoin { id, locked_until_epoch, balance } = coin; - ID::delete(id); + id::delete(id); (balance, locked_until_epoch) } /// Public getter for the locked coin's value public fun value(self: &LockedCoin): u64 { - Balance::value(&self.balance) + balance::value(&self.balance) } /// Lock a coin up until `locked_until_epoch`. The input Coin is deleted and a LockedCoin @@ -46,8 +46,8 @@ module Sui::LockedCoin { public entry fun lock_coin( coin: Coin, recipient: address, locked_until_epoch: u64, ctx: &mut TxContext ) { - let balance = Coin::into_balance(coin); - new_from_balance(balance, EpochTimeLock::new(locked_until_epoch, ctx), recipient, ctx); + let balance = coin::into_balance(coin); + new_from_balance(balance, epoch_time_lock::new(locked_until_epoch, ctx), recipient, ctx); } /// Unlock a locked coin. The function aborts if the current epoch is less than the `locked_until_epoch` @@ -55,9 +55,9 @@ module Sui::LockedCoin { /// to the sender. public entry fun unlock_coin(locked_coin: LockedCoin, ctx: &mut TxContext) { let LockedCoin { id, balance, locked_until_epoch } = locked_coin; - ID::delete(id); - EpochTimeLock::destroy(locked_until_epoch, ctx); - let coin = Coin::from_balance(balance, ctx); - Transfer::transfer(coin, TxContext::sender(ctx)); + id::delete(id); + epoch_time_lock::destroy(locked_until_epoch, ctx); + let coin = coin::from_balance(balance, ctx); + transfer::transfer(coin, tx_context::sender(ctx)); } } diff --git a/crates/sui-framework/sources/Math.move b/crates/sui-framework/sources/math.move similarity index 82% rename from crates/sui-framework/sources/Math.move rename to crates/sui-framework/sources/math.move index db9148e3aa379..3f209943b8e67 100644 --- a/crates/sui-framework/sources/Math.move +++ b/crates/sui-framework/sources/math.move @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 /// Basic math for nicer programmability -module Sui::Math { +module sui::math { /// Return the larger of `x` and `y` public fun max(x: u64, y: u64): u64 { @@ -24,28 +24,28 @@ module Sui::Math { /// Get a nearest lower integer Square Root for `x`. Given that this /// function can only operate with integers, it is impossible - /// to get perfect (or precise) integer square root for some numbers. + /// to get perfect (or precise) integer square root for some numbers. /// - /// Example: + /// Example: /// ``` - /// Math::sqrt(9) => 3 - /// Math::sqrt(8) => 2 // the nearest lower square root is 4; + /// math::sqrt(9) => 3 + /// math::sqrt(8) => 2 // the nearest lower square root is 4; /// ``` /// - /// In integer math, one of the possible ways to get results with more - /// precision is to use higher values or temporarily multiply the - /// value by some bigger number. Ideally if this is a square of 10 or 100. - /// + /// In integer math, one of the possible ways to get results with more + /// precision is to use higher values or temporarily multiply the + /// value by some bigger number. Ideally if this is a square of 10 or 100. + /// /// Example: /// ``` - /// Math::sqrt(8) => 2; - /// Math::sqrt(8 * 10000) => 282; + /// math::sqrt(8) => 2; + /// math::sqrt(8 * 10000) => 282; /// // now we can use this value as if it was 2.82; /// // but to get the actual result, this value needs /// // to be divided by 100 (because sqrt(10000)). - /// /// - /// Math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + /// + /// math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) /// ``` public fun sqrt(x: u64): u64 { let bit = 1u128 << 64; @@ -61,7 +61,7 @@ module Sui::Math { }; bit = bit >> 2; }; - + (res as u64) } } diff --git a/crates/sui-framework/sources/ObjectBasics.move b/crates/sui-framework/sources/object_basics.move similarity index 67% rename from crates/sui-framework/sources/ObjectBasics.move rename to crates/sui-framework/sources/object_basics.move index 739655a699709..b66c6b846215d 100644 --- a/crates/sui-framework/sources/ObjectBasics.move +++ b/crates/sui-framework/sources/object_basics.move @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 /// Test CTURD object basics (create, transfer, update, read, delete) -module Sui::ObjectBasics { - use Sui::Event; - use Sui::ID::{Self, VersionedID}; - use Sui::TxContext::{Self, TxContext}; - use Sui::Transfer; +module sui::object_basics { + use sui::event; + use sui::id::{Self, VersionedID}; + use sui::tx_context::{Self, TxContext}; + use sui::transfer; struct Object has key, store { id: VersionedID, @@ -23,18 +23,18 @@ module Sui::ObjectBasics { } public entry fun create(value: u64, recipient: address, ctx: &mut TxContext) { - Transfer::transfer( - Object { id: TxContext::new_id(ctx), value }, + transfer::transfer( + Object { id: tx_context::new_id(ctx), value }, recipient ) } public entry fun transfer(o: Object, recipient: address) { - Transfer::transfer(o, recipient) + transfer::transfer(o, recipient) } public entry fun freeze_object(o: Object) { - Transfer::freeze_object(o) + transfer::freeze_object(o) } public entry fun set_value(o: &mut Object, value: u64) { @@ -45,21 +45,21 @@ module Sui::ObjectBasics { public entry fun update(o1: &mut Object, o2: &Object) { o1.value = o2.value; // emit an event so the world can see the new value - Event::emit(NewValueEvent { new_value: o2.value }) + event::emit(NewValueEvent { new_value: o2.value }) } public entry fun delete(o: Object) { let Object { id, value: _ } = o; - ID::delete(id); + id::delete(id); } public entry fun wrap(o: Object, ctx: &mut TxContext) { - Transfer::transfer(Wrapper { id: TxContext::new_id(ctx), o }, TxContext::sender(ctx)) + transfer::transfer(Wrapper { id: tx_context::new_id(ctx), o }, tx_context::sender(ctx)) } public entry fun unwrap(w: Wrapper, ctx: &mut TxContext) { let Wrapper { id, o } = w; - ID::delete(id); - Transfer::transfer(o, TxContext::sender(ctx)) + id::delete(id); + transfer::transfer(o, tx_context::sender(ctx)) } } diff --git a/crates/sui-framework/sources/SUI.move b/crates/sui-framework/sources/sui.move similarity index 61% rename from crates/sui-framework/sources/SUI.move rename to crates/sui-framework/sources/sui.move index 4be4e490ad3a5..ca5820096fa46 100644 --- a/crates/sui-framework/sources/SUI.move +++ b/crates/sui-framework/sources/sui.move @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 /// Coin is the token used to pay for gas in Sui -module Sui::SUI { - use Sui::Coin; - use Sui::Coin::TreasuryCap; - use Sui::TxContext::TxContext; +module sui::sui { + use sui::coin; + use sui::coin::TreasuryCap; + use sui::tx_context::TxContext; - friend Sui::Genesis; + friend sui::genesis; /// Name of the coin struct SUI has drop {} @@ -15,12 +15,12 @@ module Sui::SUI { /// Register the token to acquire its `TreasuryCap`. /// This should be called only once during genesis creation. public(friend) fun new(ctx: &mut TxContext): TreasuryCap { - Coin::create_currency(SUI{}, ctx) + coin::create_currency(SUI{}, ctx) } /// Transfer to a recipient - public entry fun transfer(c: Coin::Coin, recipient: address) { - Coin::transfer(c, recipient) + public entry fun transfer(c: coin::Coin, recipient: address) { + coin::transfer(c, recipient) } } diff --git a/crates/sui-framework/sources/TestScenario.move b/crates/sui-framework/sources/test_scenario.move similarity index 93% rename from crates/sui-framework/sources/TestScenario.move rename to crates/sui-framework/sources/test_scenario.move index 0eb028af1579f..ebe51e06fb2d0 100644 --- a/crates/sui-framework/sources/TestScenario.move +++ b/crates/sui-framework/sources/test_scenario.move @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module Sui::TestScenario { - use Sui::ID::{Self, ID, VersionedID}; - use Sui::TxContext::{Self, TxContext}; +module sui::test_scenario { + use sui::id::{Self, ID, VersionedID}; + use sui::tx_context::{Self, TxContext}; use std::option::{Self, Option}; use std::vector; @@ -13,7 +13,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_owned` on a locally constructed object rather than one returned from a `TestScenario` + /// `return_owned` on a locally constructed object rather than one returned from a `test_scenario` /// function such as `take_owned`. const ECantReturnObject: u64 = 2; @@ -23,7 +23,7 @@ module Sui::TestScenario { const EEmptyInventory: u64 = 3; /// Expected 1 object of this type in the tx sender's inventory, but found >1. - /// Consider using TestScenario::take_owned_by_id to select a specific object + /// Consider using test_scenario::take_owned_by_id to select a specific object const EInventoryAmbiguity: u64 = 4; /// The inventory previously contained an object of this type, but it was removed during the current @@ -42,17 +42,17 @@ module Sui::TestScenario { /// let addr1: address = 0; /// let addr2: address = 1; /// // begin a test scenario in a context where addr1 is the sender - /// let scenario = &mut TestScenario::begin(&addr1); + /// let scenario = &mut test_scenario::begin(&addr1); /// // addr1 sends an object to addr2 /// { /// let some_object: SomeObject = ... // construct an object - /// Transfer::transfer(some_object, copy addr2) + /// transfer::transfer(some_object, copy addr2) /// }; /// // end the first transaction and begin a new one where addr2 is the sender - /// TestScenario::next_tx(scenario, &addr2) + /// test_scenario::next_tx(scenario, &addr2) /// { /// // remove the SomeObject value from addr2's inventory - /// let obj = TestScenario::take_owned(scenario); + /// let obj = test_scenario::take_owned(scenario); /// // use it to test some function that needs this value /// SomeObject::some_function(obj) /// } @@ -68,12 +68,12 @@ module Sui::TestScenario { event_start_indexes: vector, } - /// A wrapper for TestScenario to return an immutable object from the inventory + /// A wrapper for test_scenario to return an immutable object from the inventory struct ImmutableWrapper { object: T, } - /// A wrapper for TestScenario to return a shared object from the inventory + /// A wrapper for test_scenario to return a shared object from the inventory struct SharedWrapper { object: T, } @@ -81,7 +81,7 @@ module Sui::TestScenario { /// Begin a new multi-transaction test scenario in a context where `sender` is the tx sender public fun begin(sender: &address): Scenario { Scenario { - ctx: TxContext::new_from_hint(*sender, 0, 0, 0), + ctx: tx_context::new_from_hint(*sender, 0, 0, 0), removed: vector::empty(), event_start_indexes: vector[0], } @@ -110,13 +110,13 @@ module Sui::TestScenario { // create a seed for new transaction digest to ensure that this tx has a different // digest (and consequently, different object ID's) than the previous tx let new_tx_digest_seed = (vector::length(&scenario.event_start_indexes) as u8); - let epoch = TxContext::epoch(&scenario.ctx); - scenario.ctx = TxContext::new_from_hint(*sender, new_tx_digest_seed, epoch, 0); + let epoch = tx_context::epoch(&scenario.ctx); + scenario.ctx = tx_context::new_from_hint(*sender, new_tx_digest_seed, epoch, 0); } /// Advance the scenario to a new epoch. public fun next_epoch(scenario: &mut Scenario) { - TxContext::increment_epoch_number(&mut scenario.ctx); + tx_context::increment_epoch_number(&mut scenario.ctx); } /// Remove the object of type `T` from the inventory of the current tx sender in `scenario`. @@ -186,7 +186,7 @@ module Sui::TestScenario { let signer_address = sender(scenario); let objects = get_object_owned_inventory( signer_address, - ID::id_address(ID::id(parent_obj)), + id::id_address(id::id(parent_obj)), last_tx_start_index(scenario), ); remove_unique_object_from_inventory(scenario, objects) @@ -240,7 +240,7 @@ module Sui::TestScenario { let signer_address = sender(scenario); let objects = get_object_owned_inventory( signer_address, - ID::id_address(ID::id(parent_obj)), + id::id_address(id::id(parent_obj)), last_tx_start_index(scenario), ); let child_object_opt = find_object_by_id_in_inventory(objects, &child_id); @@ -259,7 +259,7 @@ module Sui::TestScenario { /// transaction sender. /// Aborts if `t` was not previously taken from the inventory via a call to `take_owned` or similar. public fun return_owned(scenario: &mut Scenario, t: T) { - let id = ID::id(&t); + let id = id::id(&t); let removed = &mut scenario.removed; // TODO: add Vector::remove_element to Std that does this 3-liner let (is_mem, idx) = vector::index_of(removed, id); @@ -296,7 +296,7 @@ module Sui::TestScenario { // yet been removed from the inventory. let res = vector::length(&objects) == 1; if (res) { - let id = ID::id(vector::borrow(&objects, 0)); + let id = id::id(vector::borrow(&objects, 0)); res = !vector::contains(&scenario.removed, id); }; drop_object_for_testing(objects); @@ -310,12 +310,12 @@ module Sui::TestScenario { /// Generate a fresh ID for the current tx associated with this `scenario` public fun new_id(scenario: &mut Scenario): VersionedID { - TxContext::new_id(&mut scenario.ctx) + tx_context::new_id(&mut scenario.ctx) } /// Return the sender of the current tx in this `scenario` public fun sender(scenario: &Scenario): address { - TxContext::sender(&scenario.ctx) + tx_context::sender(&scenario.ctx) } /// Return the number of concluded transactions in this scenario. @@ -345,7 +345,7 @@ module Sui::TestScenario { if (objects_len == 1) { // found a unique object. ensure that it hasn't already been removed, then return it let t = vector::pop_back(&mut inventory); - let id = ID::id(&t); + let id = id::id(&t); vector::destroy_empty(inventory); assert!(!vector::contains(&scenario.removed, id), EAlreadyRemovedObject); @@ -362,7 +362,7 @@ module Sui::TestScenario { let object_opt = option::none(); while (!vector::is_empty(&inventory)) { let element = vector::pop_back(&mut inventory); - if (ID::id(&element) == id) { + if (id::id(&element) == id) { // Within the same test scenario, there is no way to // create two objects with the same ID. So this should // be unique. diff --git a/crates/sui-framework/sources/Transfer.move b/crates/sui-framework/sources/transfer.move similarity index 91% rename from crates/sui-framework/sources/Transfer.move rename to crates/sui-framework/sources/transfer.move index dfe4132733251..6d478efa9a998 100644 --- a/crates/sui-framework/sources/Transfer.move +++ b/crates/sui-framework/sources/transfer.move @@ -1,14 +1,14 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::Transfer { +module sui::transfer { use std::option::{Self, Option}; - use Sui::ID::{Self, ID, VersionedID}; + use sui::id::{Self, ID, VersionedID}; // To allow access to transfer_to_object_unsafe. - friend Sui::Bag; + friend sui::bag; // To allow access to is_child_unsafe. - friend Sui::Collection; + friend sui::collection; // When transferring a child object, this error is thrown if the child object // doesn't match the ChildRef that represents the ownership. @@ -29,7 +29,7 @@ module Sui::Transfer { /// Check whether the `child` object is actually the child object /// owned by the parent through the given `child_ref`. public fun is_child(child_ref: &ChildRef, child: &T): bool { - &child_ref.child_id == ID::id(child) + &child_ref.child_id == id::id(child) } /// Check whether the `child_ref`'s child_id is `id`. @@ -63,8 +63,8 @@ module Sui::Transfer { /// Transfer ownership of `obj` to another object `owner`. /// Returns a non-droppable struct ChildRef that represents the ownership. public fun transfer_to_object(obj: T, owner: &mut R): ChildRef { - let obj_id = *ID::id(&obj); - let owner_id = ID::id_address(ID::id(owner)); + let obj_id = *id::id(&obj); + let owner_id = id::id_address(id::id(owner)); transfer_internal(obj, owner_id, true); ChildRef { child_id: obj_id } } @@ -78,9 +78,9 @@ module Sui::Transfer { /// The `owner_id` will be returned (so that it can be used to continue creating the parent object), /// along returned is the ChildRef as a reference to the ownership. public fun transfer_to_object_id(obj: T, owner_id: VersionedID): (VersionedID, ChildRef) { - let obj_id = *ID::id(&obj); - let inner_owner_id = *ID::inner(&owner_id); - transfer_internal(obj, ID::id_address(&inner_owner_id), true); + let obj_id = *id::id(&obj); + let inner_owner_id = *id::inner(&owner_id); + transfer_internal(obj, id::id_address(&inner_owner_id), true); let child_ref = ChildRef { child_id: obj_id }; (owner_id, child_ref) } @@ -108,7 +108,7 @@ module Sui::Transfer { /// consume a ChildRef. It will return a ChildRef that represents the new ownership. public fun transfer_child_to_object(child: T, child_ref: ChildRef, owner: &mut R): ChildRef { let ChildRef { child_id } = child_ref; - assert!(&child_id == ID::id(&child), EChildIDMismatch); + assert!(&child_id == id::id(&child), EChildIDMismatch); transfer_to_object(child, owner) } @@ -117,7 +117,7 @@ module Sui::Transfer { /// owned by an object. public fun transfer_child_to_address(child: T, child_ref: ChildRef, recipient: address) { let ChildRef { child_id } = child_ref; - assert!(&child_id == ID::id(&child), EChildIDMismatch); + assert!(&child_id == id::id(&child), EChildIDMismatch); transfer(child, recipient) } @@ -127,8 +127,8 @@ module Sui::Transfer { /// has been unpacked, so it is now safe to delete `child_ref`. public fun delete_child_object(child_id: VersionedID, child_ref: ChildRef) { let ChildRef { child_id: child_ref_id } = child_ref; - assert!(&child_ref_id == ID::inner(&child_id), EChildIDMismatch); - delete_child_object_internal(ID::id_address(&child_ref_id), child_id) + assert!(&child_ref_id == id::inner(&child_id), EChildIDMismatch); + delete_child_object_internal(id::id_address(&child_ref_id), child_id) } /// Freeze `obj`. After freezing `obj` becomes immutable and can no diff --git a/crates/sui-framework/sources/TxContext.move b/crates/sui-framework/sources/tx_context.move similarity index 95% rename from crates/sui-framework/sources/TxContext.move rename to crates/sui-framework/sources/tx_context.move index bccde5526e28d..c7b7c0a420229 100644 --- a/crates/sui-framework/sources/TxContext.move +++ b/crates/sui-framework/sources/tx_context.move @@ -1,16 +1,16 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::TxContext { +module sui::tx_context { use std::signer; - use Sui::ID::{Self, VersionedID}; + use sui::id::{Self, VersionedID}; #[test_only] use std::errors; #[test_only] use std::vector; #[test_only] - use Sui::ID::ID; + use sui::id::ID; /// Number of bytes in an tx hash (which will be the transaction digest) const TX_HASH_LENGTH: u64 = 32; @@ -55,7 +55,7 @@ module Sui::TxContext { /// Generate a new, globally unique object ID with version 0 public fun new_id(ctx: &mut TxContext): VersionedID { let ids_created = ctx.ids_created; - let id = ID::new_versioned_id(derive_id(*&ctx.tx_hash, ids_created)); + let id = id::new_versioned_id(derive_id(*&ctx.tx_hash, ids_created)); ctx.ids_created = ids_created + 1; id } @@ -117,7 +117,7 @@ module Sui::TxContext { public fun last_created_object_id(self: &TxContext): ID { let ids_created = self.ids_created; assert!(ids_created > 0, ENoIDsCreated); - ID::new(derive_id(*&self.tx_hash, ids_created - 1)) + id::new(derive_id(*&self.tx_hash, ids_created - 1)) } #[test_only] diff --git a/crates/sui-framework/sources/Url.move b/crates/sui-framework/sources/url.move similarity index 99% rename from crates/sui-framework/sources/Url.move rename to crates/sui-framework/sources/url.move index 5b02a3979787b..1693247bb9511 100644 --- a/crates/sui-framework/sources/Url.move +++ b/crates/sui-framework/sources/url.move @@ -5,7 +5,7 @@ /// Url: Sui type which wraps a URL /// UrlCommitment: Sui type which wraps a Url but also includes an immutable commitment /// to the hash of the resource at the given URL -module Sui::Url { +module sui::url { use std::ascii::{Self, String}; use std::vector; diff --git a/crates/sui-framework/sources/UTF8.move b/crates/sui-framework/sources/utf8.move similarity index 98% rename from crates/sui-framework/sources/UTF8.move rename to crates/sui-framework/sources/utf8.move index 7d2df313aad0e..a0ebe692a966d 100644 --- a/crates/sui-framework/sources/UTF8.move +++ b/crates/sui-framework/sources/utf8.move @@ -1,7 +1,7 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Sui::UTF8 { +module sui::utf8 { use std::ascii; use std::option::Option; diff --git a/crates/sui-framework/src/natives/event.rs b/crates/sui-framework/src/natives/event.rs index bf41def9cdeb6..70cbc7bddafdf 100644 --- a/crates/sui-framework/src/natives/event.rs +++ b/crates/sui-framework/src/natives/event.rs @@ -14,7 +14,7 @@ use move_vm_types::{ use smallvec::smallvec; use std::collections::VecDeque; -/// Implementation of Move native function `Event::emit(event: T)` +/// Implementation of Move native function `event::emit(event: T)` /// Adds an event to the transaction's event log pub fn emit( context: &mut NativeContext, diff --git a/crates/sui-framework/src/natives/mod.rs b/crates/sui-framework/src/natives/mod.rs index c1883d9deec2b..3ab6ac6a3fb7b 100644 --- a/crates/sui-framework/src/natives/mod.rs +++ b/crates/sui-framework/src/natives/mod.rs @@ -17,52 +17,52 @@ pub fn all_natives( sui_framework_addr: AccountAddress, ) -> NativeFunctionTable { const SUI_NATIVES: &[(&str, &str, NativeFunction)] = &[ - ("Event", "emit", event::emit), - ("ID", "bytes_to_address", id::bytes_to_address), - ("ID", "delete_id", id::delete_id), - ("ID", "get_versioned_id", id::get_versioned_id), + ("event", "emit", event::emit), + ("id", "bytes_to_address", id::bytes_to_address), + ("id", "delete_id", id::delete_id), + ("id", "get_versioned_id", id::get_versioned_id), ( - "TestScenario", + "test_scenario", "drop_object_for_testing", test_scenario::drop_object_for_testing, ), ( - "TestScenario", + "test_scenario", "emit_wrapped_object_events", test_scenario::emit_wrapped_object_events, ), ( - "TestScenario", + "test_scenario", "get_account_owned_inventory", test_scenario::get_account_owned_inventory, ), ( - "TestScenario", + "test_scenario", "get_object_owned_inventory", test_scenario::get_object_owned_inventory, ), ( - "TestScenario", + "test_scenario", "get_unowned_inventory", test_scenario::get_unowned_inventory, ), - ("TestScenario", "num_events", test_scenario::num_events), + ("test_scenario", "num_events", test_scenario::num_events), ( - "TestScenario", + "test_scenario", "update_object", test_scenario::update_object, ), ( - "Transfer", + "transfer", "delete_child_object_internal", transfer::delete_child_object_internal, ), - ("Transfer", "transfer_internal", transfer::transfer_internal), - ("Transfer", "freeze_object", transfer::freeze_object), - ("Transfer", "share_object", transfer::share_object), - ("TxContext", "derive_id", tx_context::derive_id), + ("transfer", "transfer_internal", transfer::transfer_internal), + ("transfer", "freeze_object", transfer::freeze_object), + ("transfer", "share_object", transfer::share_object), + ("tx_context", "derive_id", tx_context::derive_id), ( - "TxContext", + "tx_context", "new_signer_from_address", tx_context::new_signer_from_address, ), diff --git a/crates/sui-framework/src/natives/test_scenario.rs b/crates/sui-framework/src/natives/test_scenario.rs index d5339abdd9641..74091b67d3422 100644 --- a/crates/sui-framework/src/natives/test_scenario.rs +++ b/crates/sui-framework/src/natives/test_scenario.rs @@ -100,7 +100,7 @@ fn get_global_inventory(events: &[Event]) -> Result { }; if *event_type_byte == WRAPPED_OBJECT_EVENT { - // special, TestScenario-only event for object wrapping. treat the same as DeleteObjectID for inventory purposes--a wrapped object is not available for use + // special, test_scenario-only event for object wrapping. treat the same as DeleteObjectID for inventory purposes--a wrapped object is not available for use assert!(inventory.remove(&obj_id).is_some()); continue; } diff --git a/crates/sui-framework/tests/BagTests.move b/crates/sui-framework/tests/BagTests.move deleted file mode 100644 index 4cad147b27c48..0000000000000 --- a/crates/sui-framework/tests/BagTests.move +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module Sui::BagTests { - use Sui::Bag::{Self, Bag}; - use Sui::ID::{Self, VersionedID}; - use Sui::TestScenario; - use Sui::TxContext; - - const EBAG_SIZE_MISMATCH: u64 = 0; - const EOBJECT_NOT_FOUND: u64 = 1; - - struct Object1 has key, store { - id: VersionedID, - } - - struct Object2 has key, store { - id: VersionedID, - } - - #[test] - fun test_bag() { - let sender = @0x0; - let scenario = &mut TestScenario::begin(&sender); - - // Create a new Bag and transfer it to the sender. - TestScenario::next_tx(scenario, &sender); - { - Bag::create(TestScenario::ctx(scenario)); - }; - - // Add two objects of different types into the bag. - TestScenario::next_tx(scenario, &sender); - { - let bag = TestScenario::take_owned(scenario); - assert!(Bag::size(&bag) == 0, EBAG_SIZE_MISMATCH); - - let obj1 = Object1 { id: TxContext::new_id(TestScenario::ctx(scenario)) }; - let id1 = *ID::id(&obj1); - let obj2 = Object2 { id: TxContext::new_id(TestScenario::ctx(scenario)) }; - let id2 = *ID::id(&obj2); - - Bag::add(&mut bag, obj1); - Bag::add(&mut bag, obj2); - assert!(Bag::size(&bag) == 2, EBAG_SIZE_MISMATCH); - - assert!(Bag::contains(&bag, &id1), EOBJECT_NOT_FOUND); - assert!(Bag::contains(&bag, &id2), EOBJECT_NOT_FOUND); - - TestScenario::return_owned(scenario, bag); - }; - // TODO: Test object removal once we can retrieve object owned objects from TestScenario. - } - - #[test] - #[expected_failure(abort_code = 520)] - fun test_init_with_invalid_max_capacity() { - let ctx = TxContext::dummy(); - // Sui::Bag::DEFAULT_MAX_CAPACITY is not readable outside the module - let max_capacity = 65536; - let bag = Bag::new_with_max_capacity(&mut ctx, max_capacity + 1); - Bag::transfer(bag, TxContext::sender(&ctx)); - } - - #[test] - #[expected_failure(abort_code = 520)] - fun test_init_with_zero() { - let ctx = TxContext::dummy(); - let bag = Bag::new_with_max_capacity(&mut ctx, 0); - Bag::transfer(bag, TxContext::sender(&ctx)); - } - - #[test] - #[expected_failure(abort_code = 776)] - fun test_exceed_max_capacity() { - let ctx = TxContext::dummy(); - let bag = Bag::new_with_max_capacity(&mut ctx, 1); - - let obj1 = Object1 { id: TxContext::new_id(&mut ctx) }; - Bag::add(&mut bag, obj1); - let obj2 = Object2 { id: TxContext::new_id(&mut ctx) }; - Bag::add(&mut bag, obj2); - Bag::transfer(bag, TxContext::sender(&ctx)); - } -} diff --git a/crates/sui-framework/tests/CoinBalanceTests.move b/crates/sui-framework/tests/CoinBalanceTests.move deleted file mode 100644 index 6130a4171a8ae..0000000000000 --- a/crates/sui-framework/tests/CoinBalanceTests.move +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module Sui::TestCoin { - use Sui::TestScenario::{Self, ctx}; - use Sui::Coin; - use Sui::Balance; - use Sui::SUI::SUI; - use Sui::LockedCoin::LockedCoin; - use Sui::TxContext; - use Sui::LockedCoin; - use Sui::Coin::Coin; - - #[test] - fun type_morphing() { - let test = &mut TestScenario::begin(&@0x1); - - let balance = Balance::zero(); - let coin = Coin::from_balance(balance, ctx(test)); - let balance = Coin::into_balance(coin); - - Balance::destroy_zero(balance); - - let coin = Coin::mint_for_testing(100, ctx(test)); - let balance_mut = Coin::balance_mut(&mut coin); - let sub_balance = Balance::split(balance_mut, 50); - - assert!(Balance::value(&sub_balance) == 50, 0); - assert!(Coin::value(&coin) == 50, 0); - - let balance = Coin::into_balance(coin); - Balance::join(&mut balance, sub_balance); - - assert!(Balance::value(&balance) == 100, 0); - - let coin = Coin::from_balance(balance, ctx(test)); - Coin::keep(coin, ctx(test)); - } - - const TEST_SENDER_ADDR: address = @0xA11CE; - const TEST_RECIPIENT_ADDR: address = @0xB0B; - - #[test] - public entry fun test_locked_coin_valid() { - let scenario = &mut TestScenario::begin(&TEST_SENDER_ADDR); - let ctx = TestScenario::ctx(scenario); - let coin = Coin::mint_for_testing(42, ctx); - - TestScenario::next_tx(scenario, &TEST_SENDER_ADDR); - // Lock up the coin until epoch 2. - LockedCoin::lock_coin(coin, TEST_RECIPIENT_ADDR, 2, TestScenario::ctx(scenario)); - - // Advance the epoch by 2. - TestScenario::next_epoch(scenario); - TestScenario::next_epoch(scenario); - assert!(TxContext::epoch(TestScenario::ctx(scenario)) == 2, 1); - - TestScenario::next_tx(scenario, &TEST_RECIPIENT_ADDR); - let locked_coin = TestScenario::take_owned>(scenario); - // The unlock should go through since epoch requirement is met. - LockedCoin::unlock_coin(locked_coin, TestScenario::ctx(scenario)); - - TestScenario::next_tx(scenario, &TEST_RECIPIENT_ADDR); - let unlocked_coin = TestScenario::take_owned>(scenario); - assert!(Coin::value(&unlocked_coin) == 42, 2); - Coin::destroy_for_testing(unlocked_coin); - } - - #[test] - #[expected_failure(abort_code = 1)] - public entry fun test_locked_coin_invalid() { - let scenario = &mut TestScenario::begin(&TEST_SENDER_ADDR); - let ctx = TestScenario::ctx(scenario); - let coin = Coin::mint_for_testing(42, ctx); - - TestScenario::next_tx(scenario, &TEST_SENDER_ADDR); - // Lock up the coin until epoch 2. - LockedCoin::lock_coin(coin, TEST_RECIPIENT_ADDR, 2, TestScenario::ctx(scenario)); - - // Advance the epoch by 1. - TestScenario::next_epoch(scenario); - assert!(TxContext::epoch(TestScenario::ctx(scenario)) == 1, 1); - - TestScenario::next_tx(scenario, &TEST_RECIPIENT_ADDR); - let locked_coin = TestScenario::take_owned>(scenario); - // The unlock should fail. - LockedCoin::unlock_coin(locked_coin, TestScenario::ctx(scenario)); - } -} diff --git a/crates/sui-framework/tests/CollectionTests.move b/crates/sui-framework/tests/CollectionTests.move deleted file mode 100644 index 63379f3f9fc78..0000000000000 --- a/crates/sui-framework/tests/CollectionTests.move +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module Sui::CollectionTests { - use Sui::Bag::{Self, Bag}; - use Sui::Collection::{Self, Collection}; - use Sui::ID::{Self, VersionedID}; - use Sui::TestScenario; - use Sui::TxContext; - - struct Object has key, store { - id: VersionedID, - } - - #[test] - fun test_collection() { - let sender = @0x0; - let scenario = &mut TestScenario::begin(&sender); - - // Create a new Collection and transfer it to the sender. - TestScenario::next_tx(scenario, &sender); - { - Collection::create(TestScenario::ctx(scenario)); - }; - - // Add two objects of different types into the collection. - TestScenario::next_tx(scenario, &sender); - { - let collection = TestScenario::take_owned>(scenario); - assert!(Collection::size(&collection) == 0, 0); - - let obj1 = Object { id: TxContext::new_id(TestScenario::ctx(scenario)) }; - let id1 = *ID::id(&obj1); - let obj2 = Object { id: TxContext::new_id(TestScenario::ctx(scenario)) }; - let id2 = *ID::id(&obj2); - - Collection::add(&mut collection, obj1); - Collection::add(&mut collection, obj2); - assert!(Collection::size(&collection) == 2, 0); - - assert!(Collection::contains(&collection, &id1), 0); - assert!(Collection::contains(&collection, &id2), 0); - - TestScenario::return_owned(scenario, collection); - }; - } - - #[test] - fun test_collection_bag_interaction() { - let sender = @0x0; - let scenario = &mut TestScenario::begin(&sender); - - // Create a new Collection and a new Bag and transfer them to the sender. - TestScenario::next_tx(scenario, &sender); - { - Collection::create(TestScenario::ctx(scenario)); - Bag::create(TestScenario::ctx(scenario)); - }; - - // Add a new object to the Collection. - TestScenario::next_tx(scenario, &sender); - { - let collection = TestScenario::take_owned>(scenario); - let obj = Object { id: TxContext::new_id(TestScenario::ctx(scenario)) }; - Collection::add(&mut collection, obj); - TestScenario::return_owned(scenario, collection); - }; - - // Remove the object from the collection and add it to the bag. - TestScenario::next_tx(scenario, &sender); - { - let collection = TestScenario::take_owned>(scenario); - let bag = TestScenario::take_owned(scenario); - let obj = TestScenario::take_child_object, Object>(scenario, &collection); - let id = *ID::id(&obj); - - let (obj, child_ref) = Collection::remove(&mut collection, obj); - Bag::add_child_object(&mut bag, obj, child_ref); - - assert!(Collection::size(&collection) == 0, 0); - assert!(Bag::size(&bag) == 1, 0); - assert!(Bag::contains(&bag, &id), 0); - - TestScenario::return_owned(scenario, collection); - TestScenario::return_owned(scenario, bag); - }; - - // Remove the object from the bag and add it back to the collection. - TestScenario::next_tx(scenario, &sender); - { - let collection = TestScenario::take_owned>(scenario); - let bag = TestScenario::take_owned(scenario); - let obj = TestScenario::take_child_object(scenario, &bag); - let id = *ID::id(&obj); - - let obj = Bag::remove(&mut bag, obj); - Collection::add(&mut collection, obj); - - assert!(Collection::size(&collection) == 1, 0); - assert!(Bag::size(&bag) == 0, 0); - assert!(Collection::contains(&collection, &id), 0); - - TestScenario::return_owned(scenario, collection); - TestScenario::return_owned(scenario, bag); - }; - - } - - #[test] - #[expected_failure(abort_code = 520)] - fun test_init_with_invalid_max_capacity() { - let ctx = TxContext::dummy(); - // Sui::Collection::DEFAULT_MAX_CAPACITY is not readable outside the module - let max_capacity = 65536; - let collection = Collection::new_with_max_capacity(&mut ctx, max_capacity + 1); - Collection::transfer(collection, TxContext::sender(&ctx)); - } - - #[test] - #[expected_failure(abort_code = 520)] - fun test_init_with_zero() { - let ctx = TxContext::dummy(); - let collection = Collection::new_with_max_capacity(&mut ctx, 0); - Collection::transfer(collection, TxContext::sender(&ctx)); - } - - #[test] - #[expected_failure(abort_code = 776)] - fun test_exceed_max_capacity() { - let ctx = TxContext::dummy(); - let collection = Collection::new_with_max_capacity(&mut ctx, 1); - - let obj1 = Object { id: TxContext::new_id(&mut ctx) }; - Collection::add(&mut collection, obj1); - let obj2 = Object { id: TxContext::new_id(&mut ctx) }; - Collection::add(&mut collection, obj2); - Collection::transfer(collection, TxContext::sender(&ctx)); - } -} diff --git a/crates/sui-framework/tests/IDTests.move b/crates/sui-framework/tests/IDTests.move deleted file mode 100644 index f3aa0c7b44b42..0000000000000 --- a/crates/sui-framework/tests/IDTests.move +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module Sui::IDTests { - use Sui::ID; - use Sui::TxContext; - - const ID_BYTES_MISMATCH: u64 = 0; - - struct Object has key { - id: ID::VersionedID, - } - - #[test] - fun test_get_id() { - let ctx = TxContext::dummy(); - let versioned_id = TxContext::new_id(&mut ctx); - let obj_id = *ID::inner(&versioned_id); - let obj = Object { id: versioned_id }; - assert!(*ID::id(&obj) == obj_id, ID_BYTES_MISMATCH); - let Object { id } = obj; - ID::delete(id); - } -} diff --git a/crates/sui-framework/tests/TestScenarioTests.move b/crates/sui-framework/tests/TestScenarioTests.move deleted file mode 100644 index 1f516e6a151a2..0000000000000 --- a/crates/sui-framework/tests/TestScenarioTests.move +++ /dev/null @@ -1,372 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module Sui::TestScenarioTests { - use Sui::ID; - use Sui::TestScenario::{Self, Scenario}; - use Sui::Transfer::{Self, ChildRef}; - use Sui::TxContext; - - const ID_BYTES_MISMATCH: u64 = 0; - const VALUE_MISMATCH: u64 = 1; - const OBJECT_ID_NOT_FOUND: u64 = 2; - - struct Object has key, store { - id: ID::VersionedID, - value: u64, - } - - struct Wrapper has key { - id: ID::VersionedID, - child: Object, - } - - struct Parent has key { - id: ID::VersionedID, - child: ChildRef, - } - - struct MultiChildParent has key { - id: ID::VersionedID, - child1: ChildRef, - child2: ChildRef, - } - - #[test] - fun test_wrap_unwrap() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - { - let id = TestScenario::new_id(&mut scenario); - let obj = Object { id, value: 10 }; - Transfer::transfer(obj, copy sender); - }; - // now, object gets wrapped - TestScenario::next_tx(&mut scenario, &sender); - { - let id = TestScenario::new_id(&mut scenario); - let child = TestScenario::take_owned(&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_take_owned(&scenario), 0); - assert!(TestScenario::can_take_owned(&scenario), 1); - } - } - - #[test] - fun test_remove_then_return() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - { - let id = TestScenario::new_id(&mut scenario); - let obj = Object { id, value: 10 }; - Transfer::transfer(obj, copy sender); - }; - // object gets removed, then returned - TestScenario::next_tx(&mut scenario, &sender); - { - let object = TestScenario::take_owned(&mut scenario); - TestScenario::return_owned(&mut scenario, object); - }; - // Object should remain accessible - TestScenario::next_tx(&mut scenario, &sender); - { - assert!(TestScenario::can_take_owned(&scenario), 0); - } - } - - #[test] - fun test_return_and_update() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - { - let id = TestScenario::new_id(&mut scenario); - let obj = Object { id, value: 10 }; - Transfer::transfer(obj, copy sender); - }; - TestScenario::next_tx(&mut scenario, &sender); - { - let obj = TestScenario::take_owned(&mut scenario); - assert!(obj.value == 10, 0); - obj.value = 100; - TestScenario::return_owned(&mut scenario, obj); - }; - TestScenario::next_tx(&mut scenario, &sender); - { - let obj = TestScenario::take_owned(&mut scenario); - assert!(obj.value == 100, 1); - TestScenario::return_owned(&mut scenario, obj); - } - } - - #[test] - fun test_remove_during_tx() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - { - let id = TestScenario::new_id(&mut scenario); - 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_take_owned(&scenario), 0) - }; - } - - #[test] - #[expected_failure(abort_code = 5 /* EALREADY_REMOVED_OBJECT */)] - fun test_double_remove() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - { - let id = TestScenario::new_id(&mut scenario); - let obj = Object { id, value: 10 }; - Transfer::transfer(obj, copy sender); - }; - TestScenario::next_tx(&mut scenario, &sender); - { - let obj1 = TestScenario::take_owned(&mut scenario); - let obj2 = TestScenario::take_owned(&mut scenario); - TestScenario::return_owned(&mut scenario, obj1); - TestScenario::return_owned(&mut scenario, obj2); - } - } - - #[test] - fun test_three_owners() { - // make sure an object that goes from addr1 -> addr2 -> addr3 can only be accessed by - // the appropriate owner at each stage - let addr1 = @0x0; - let addr2 = @0x1; - let addr3 = @0x2; - let scenario = TestScenario::begin(&addr1); - { - let id = TestScenario::new_id(&mut scenario); - let obj = Object { id, value: 10 }; - // self-transfer - Transfer::transfer(obj, copy addr1); - }; - // addr1 -> addr2 - TestScenario::next_tx(&mut scenario, &addr1); - { - let obj = TestScenario::take_owned(&mut scenario); - Transfer::transfer(obj, copy addr2) - }; - // addr1 cannot access - TestScenario::next_tx(&mut scenario, &addr1); - { - assert!(!TestScenario::can_take_owned(&scenario), 0); - }; - // addr2 -> addr3 - TestScenario::next_tx(&mut scenario, &addr2); - { - let obj = TestScenario::take_owned(&mut scenario); - Transfer::transfer(obj, copy addr3) - }; - // addr1 cannot access - TestScenario::next_tx(&mut scenario, &addr1); - { - assert!(!TestScenario::can_take_owned(&scenario), 0); - }; - // addr2 cannot access - TestScenario::next_tx(&mut scenario, &addr2); - { - assert!(!TestScenario::can_take_owned(&scenario), 0); - }; - // addr3 *can* access - TestScenario::next_tx(&mut scenario, &addr3); - { - assert!(TestScenario::can_take_owned(&scenario), 0); - } - } - - #[test] - fun test_transfer_then_delete() { - let tx1_sender = @0x0; - let tx2_sender = @0x1; - let scenario = TestScenario::begin(&tx1_sender); - // send an object to tx2_sender - let id_bytes; - { - let id = TestScenario::new_id(&mut scenario); - id_bytes = *ID::inner(&id); - let obj = Object { id, value: 100 }; - Transfer::transfer(obj, copy tx2_sender); - // sender cannot access the object - assert!(!TestScenario::can_take_owned(&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_take_owned(&scenario), 1); - let received_obj = TestScenario::take_owned(&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); - ID::delete(received_id); - }; - // check that the object is no longer accessible after deletion - TestScenario::next_tx(&mut scenario, &tx2_sender); - { - assert!(!TestScenario::can_take_owned(&scenario), 2); - } - } - - #[test] - fun test_take_owned_by_id() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - let versioned_id1 = TestScenario::new_id(&mut scenario); - let versioned_id2 = TestScenario::new_id(&mut scenario); - let versioned_id3 = TestScenario::new_id(&mut scenario); - let id1 = *ID::inner(&versioned_id1); - let id2 = *ID::inner(&versioned_id2); - let id3 = *ID::inner(&versioned_id3); - { - let obj1 = Object { id: versioned_id1, value: 10 }; - let obj2 = Object { id: versioned_id2, value: 20 }; - let obj3 = Object { id: versioned_id3, value: 30 }; - Transfer::transfer(obj1, copy sender); - Transfer::transfer(obj2, copy sender); - Transfer::transfer(obj3, copy sender); - }; - TestScenario::next_tx(&mut scenario, &sender); - { - assert!( - TestScenario::can_take_owned_by_id(&mut scenario, id1), - OBJECT_ID_NOT_FOUND - ); - assert!( - TestScenario::can_take_owned_by_id(&mut scenario, id2), - OBJECT_ID_NOT_FOUND - ); - assert!( - TestScenario::can_take_owned_by_id(&mut scenario, id3), - OBJECT_ID_NOT_FOUND - ); - let obj1 = TestScenario::take_owned_by_id(&mut scenario, id1); - let obj3 = TestScenario::take_owned_by_id(&mut scenario, id3); - let obj2 = TestScenario::take_owned_by_id(&mut scenario, id2); - assert!(obj1.value == 10, VALUE_MISMATCH); - assert!(obj2.value == 20, VALUE_MISMATCH); - assert!(obj3.value == 30, VALUE_MISMATCH); - TestScenario::return_owned(&mut scenario, obj1); - TestScenario::return_owned(&mut scenario, obj2); - TestScenario::return_owned(&mut scenario, obj3); - }; - } - - #[test] - fun test_get_last_created_object_id() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - { - let versioned_id = TestScenario::new_id(&mut scenario); - let id = *ID::inner(&versioned_id); - let obj = Object { id: versioned_id, value: 10 }; - Transfer::transfer(obj, copy sender); - let ctx = TestScenario::ctx(&mut scenario); - assert!(id == TxContext::last_created_object_id(ctx), 0); - }; - } - - #[test] - fun test_take_child_object() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - create_parent_and_object(&mut scenario); - - TestScenario::next_tx(&mut scenario, &sender); - { - // sender cannot take object directly. - assert!(!TestScenario::can_take_owned(&scenario), 0); - // sender can take parent, however. - assert!(TestScenario::can_take_owned(&scenario), 0); - - let parent = TestScenario::take_owned(&mut scenario); - // Make sure we can take the child object with the parent object. - let child = TestScenario::take_child_object(&mut scenario, &parent); - TestScenario::return_owned(&mut scenario, parent); - TestScenario::return_owned(&mut scenario, child); - }; - } - - #[expected_failure(abort_code = 3 /* EMPTY_INVENTORY */)] - #[test] - fun test_take_child_object_incorrect_signer() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - create_parent_and_object(&mut scenario); - - TestScenario::next_tx(&mut scenario, &sender); - let parent = TestScenario::take_owned(&mut scenario); - - let another = @0x1; - TestScenario::next_tx(&mut scenario, &another); - // This should fail even though we have parent object here. - // Because the signer doesn't match. - let child = TestScenario::take_child_object(&mut scenario, &parent); - TestScenario::return_owned(&mut scenario, child); - - TestScenario::return_owned(&mut scenario, parent); - } - - #[test] - fun test_take_child_object_by_id() { - let sender = @0x0; - let scenario = TestScenario::begin(&sender); - // Create two children and a parent object. - let child1 = Object { - id: TestScenario::new_id(&mut scenario), - value: 10, - }; - let child1_id = *ID::id(&child1); - let child2 = Object { - id: TestScenario::new_id(&mut scenario), - value: 20, - }; - let child2_id = *ID::id(&child2); - let parent_id = TestScenario::new_id(&mut scenario); - let (parent_id, child1_ref) = Transfer::transfer_to_object_id(child1, parent_id); - let (parent_id, child2_ref) = Transfer::transfer_to_object_id(child2, parent_id); - - let parent = MultiChildParent { - id: parent_id, - child1: child1_ref, - child2: child2_ref, - }; - Transfer::transfer(parent, sender); - - TestScenario::next_tx(&mut scenario, &sender); - { - let parent = TestScenario::take_owned(&mut scenario); - let child1 = TestScenario::take_child_object_by_id(&mut scenario, &parent, child1_id); - let child2 = TestScenario::take_child_object_by_id(&mut scenario, &parent, child2_id); - assert!(child1.value == 10, 0); - assert!(child2.value == 20, 0); - TestScenario::return_owned(&mut scenario, parent); - TestScenario::return_owned(&mut scenario, child1); - TestScenario::return_owned(&mut scenario, child2); - }; - } - - /// Create object and parent. object is a child of parent. - /// parent is owned by sender of `scenario`. - fun create_parent_and_object(scenario: &mut Scenario) { - let parent_id = TestScenario::new_id(scenario); - let object = Object { - id: TestScenario::new_id(scenario), - value: 10, - }; - let (parent_id, child) = Transfer::transfer_to_object_id(object, parent_id); - let parent = Parent { - id: parent_id, - child, - }; - Transfer::transfer(parent, TestScenario::sender(scenario)); - } -} diff --git a/crates/sui-framework/tests/TxContextTests.move b/crates/sui-framework/tests/TxContextTests.move deleted file mode 100644 index 4b7eff4719762..0000000000000 --- a/crates/sui-framework/tests/TxContextTests.move +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module Sui::TxContextTests { - use Sui::ID; - use Sui::TxContext; - - #[test] - fun test_id_generation() { - let ctx = TxContext::dummy(); - assert!(TxContext::get_ids_created(&ctx) == 0, 0); - - let id1 = TxContext::new_id(&mut ctx); - let id2 = TxContext::new_id(&mut ctx); - - // new_id should always produce fresh ID's - assert!(&id1 != &id2, 1); - assert!(TxContext::get_ids_created(&ctx) == 2, 2); - ID::delete(id1); - ID::delete(id2); - } - -} diff --git a/crates/sui-framework/tests/ValidatorSetTests.move b/crates/sui-framework/tests/ValidatorSetTests.move deleted file mode 100644 index 563fafd0db91a..0000000000000 --- a/crates/sui-framework/tests/ValidatorSetTests.move +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module Sui::ValidatorSetTests { - use Sui::Balance; - use Sui::Coin; - use Sui::SUI::SUI; - use Sui::TxContext::{Self, TxContext}; - use Sui::Validator::{Self, Validator}; - use Sui::ValidatorSet; - - #[test] - fun test_validator_set_flow() { - // Create 4 validators, with stake 100, 200, 300, 400. - let (ctx1, validator1) = create_validator(@0x1, 1); - let (_ctx2, validator2) = create_validator(@0x2, 2); - let (_ctx3, validator3) = create_validator(@0x3, 3); - let (_ctx4, validator4) = create_validator(@0x4, 4); - - // Create a validator set with only the first validator in it. - let validator_set = ValidatorSet::new(vector[validator1]); - assert!(ValidatorSet::total_validator_candidate_count(&validator_set) == 1, 0); - assert!(ValidatorSet::validator_stake(&validator_set) == 100, 0); - - // Add the other 3 validators one by one. - ValidatorSet::request_add_validator( - &mut validator_set, - validator2, - ); - // Adding validator during the epoch should not affect stake and quorum threshold. - assert!(ValidatorSet::total_validator_candidate_count(&validator_set) == 2, 0); - assert!(ValidatorSet::validator_stake(&validator_set) == 100, 0); - - ValidatorSet::request_add_validator( - &mut validator_set, - validator3, - ); - ValidatorSet::request_add_stake( - &mut validator_set, - Coin::into_balance(Coin::mint_for_testing(500, &mut ctx1)), - &ctx1, - ); - // Adding stake to existing active validator during the epoch - // should not change total stake. - assert!(ValidatorSet::validator_stake(&validator_set) == 100, 0); - - ValidatorSet::request_withdraw_stake( - &mut validator_set, - 500, - 100 /* min_validator_stake */, - &ctx1, - ); - assert!(ValidatorSet::validator_stake(&validator_set) == 100, 0); - - ValidatorSet::request_add_validator( - &mut validator_set, - validator4, - ); - - let reward = Balance::zero(); - ValidatorSet::advance_epoch(&mut validator_set, &mut reward, &mut ctx1); - // The total stake and quorum should reflect 4 validators. - assert!(ValidatorSet::total_validator_candidate_count(&validator_set) == 4, 0); - assert!(ValidatorSet::validator_stake(&validator_set) == 1000, 0); - - ValidatorSet::request_remove_validator( - &mut validator_set, - &ctx1, - ); - // Total validator candidate count changes, but total stake remains during epoch. - assert!(ValidatorSet::total_validator_candidate_count(&validator_set) == 3, 0); - assert!(ValidatorSet::validator_stake(&validator_set) == 1000, 0); - ValidatorSet::advance_epoch(&mut validator_set, &mut reward, &mut ctx1); - // Validator1 is gone. - assert!(ValidatorSet::validator_stake(&validator_set) == 900, 0); - - ValidatorSet::destroy_for_testing(validator_set, &mut ctx1); - Balance::destroy_zero(reward); - } - - fun create_validator(addr: address, hint: u8): (TxContext, Validator) { - let stake_value = (hint as u64) * 100; - let ctx = TxContext::new_from_hint(addr, hint, 0, 0); - let init_stake = Coin::mint_for_testing(stake_value, &mut ctx); - let init_stake = Coin::into_balance(init_stake); - let validator = Validator::new( - addr, - vector[hint], - vector[hint], - vector[hint], - init_stake, - ); - (ctx, validator) - } -} diff --git a/crates/sui-framework/tests/ValidatorTests.move b/crates/sui-framework/tests/ValidatorTests.move deleted file mode 100644 index 407ea6afbc095..0000000000000 --- a/crates/sui-framework/tests/ValidatorTests.move +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module Sui::ValidatorTests { - use Sui::Coin::{Self, Coin}; - use Sui::SUI::SUI; - use Sui::TestScenario; - use Sui::Validator; - - #[test] - fun test_validator_owner_flow() { - let sender = @0x1; - let scenario = &mut TestScenario::begin(&sender); - { - let ctx = TestScenario::ctx(scenario); - - let init_stake = Coin::into_balance(Coin::mint_for_testing(10, ctx)); - let validator = Validator::new( - sender, - x"FF", - b"Validator1", - x"FFFF", - init_stake, - ); - assert!(Validator::stake_amount(&validator) == 10, 0); - assert!(Validator::sui_address(&validator) == sender, 0); - - Validator::destroy(validator, ctx); - }; - - // Check that after destroy, the original stake still exists. - TestScenario::next_tx(scenario, &sender); - { - let stake_coin = TestScenario::take_owned>(scenario); - assert!(Coin::value(&stake_coin) == 10, 0); - TestScenario::return_owned(scenario, stake_coin); - }; - } - - #[test] - fun test_pending_validator_flow() { - let sender = @0x1; - let scenario = &mut TestScenario::begin(&sender); - let ctx = TestScenario::ctx(scenario); - let init_stake = Coin::into_balance(Coin::mint_for_testing(10, ctx)); - let validator = Validator::new( - sender, - x"FF", - b"Validator1", - x"FFFF", - init_stake, - ); - - let new_stake = Coin::into_balance(Coin::mint_for_testing(30, ctx)); - Validator::request_add_stake(&mut validator, new_stake); - - assert!(Validator::stake_amount(&validator) == 10, 0); - assert!(Validator::pending_stake_amount(&validator) == 30, 0); - - Validator::request_withdraw_stake(&mut validator, 5, 35); - assert!(Validator::stake_amount(&validator) == 10, 0); - assert!(Validator::pending_stake_amount(&validator) == 30, 0); - assert!(Validator::pending_withdraw(&validator) == 5, 0); - - // Calling `adjust_stake` will withdraw the coin and transfer to sender. - Validator::adjust_stake(&mut validator, ctx); - - assert!(Validator::stake_amount(&validator) == 35, 0); - assert!(Validator::pending_stake_amount(&validator) == 0, 0); - assert!(Validator::pending_withdraw(&validator) == 0, 0); - - TestScenario::next_tx(scenario, &sender); - { - let withdraw = TestScenario::take_owned>(scenario); - assert!(Coin::value(&withdraw) == 5, 0); - TestScenario::return_owned(scenario, withdraw); - }; - - Validator::destroy(validator, TestScenario::ctx(scenario)); - } -} diff --git a/crates/sui-framework/tests/bag_tests.move b/crates/sui-framework/tests/bag_tests.move new file mode 100644 index 0000000000000..ddcbb9caea4c2 --- /dev/null +++ b/crates/sui-framework/tests/bag_tests.move @@ -0,0 +1,86 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module sui::bag_tests { + use sui::bag::{Self, Bag}; + use sui::id::{Self, VersionedID}; + use sui::test_scenario; + use sui::tx_context; + + const EBAG_SIZE_MISMATCH: u64 = 0; + const EOBJECT_NOT_FOUND: u64 = 1; + + struct Object1 has key, store { + id: VersionedID, + } + + struct Object2 has key, store { + id: VersionedID, + } + + #[test] + fun test_bag() { + let sender = @0x0; + let scenario = &mut test_scenario::begin(&sender); + + // Create a new Bag and transfer it to the sender. + test_scenario::next_tx(scenario, &sender); + { + bag::create(test_scenario::ctx(scenario)); + }; + + // Add two objects of different types into the bag. + test_scenario::next_tx(scenario, &sender); + { + let bag = test_scenario::take_owned(scenario); + assert!(bag::size(&bag) == 0, EBAG_SIZE_MISMATCH); + + let obj1 = Object1 { id: tx_context::new_id(test_scenario::ctx(scenario)) }; + let id1 = *id::id(&obj1); + let obj2 = Object2 { id: tx_context::new_id(test_scenario::ctx(scenario)) }; + let id2 = *id::id(&obj2); + + bag::add(&mut bag, obj1); + bag::add(&mut bag, obj2); + assert!(bag::size(&bag) == 2, EBAG_SIZE_MISMATCH); + + assert!(bag::contains(&bag, &id1), EOBJECT_NOT_FOUND); + assert!(bag::contains(&bag, &id2), EOBJECT_NOT_FOUND); + + test_scenario::return_owned(scenario, bag); + }; + // TODO: Test object removal once we can retrieve object owned objects from test_scenario. + } + + #[test] + #[expected_failure(abort_code = 520)] + fun test_init_with_invalid_max_capacity() { + let ctx = tx_context::dummy(); + // Sui::bag::DEFAULT_MAX_CAPACITY is not readable outside the module + let max_capacity = 65536; + let bag = bag::new_with_max_capacity(&mut ctx, max_capacity + 1); + bag::transfer(bag, tx_context::sender(&ctx)); + } + + #[test] + #[expected_failure(abort_code = 520)] + fun test_init_with_zero() { + let ctx = tx_context::dummy(); + let bag = bag::new_with_max_capacity(&mut ctx, 0); + bag::transfer(bag, tx_context::sender(&ctx)); + } + + #[test] + #[expected_failure(abort_code = 776)] + fun test_exceed_max_capacity() { + let ctx = tx_context::dummy(); + let bag = bag::new_with_max_capacity(&mut ctx, 1); + + let obj1 = Object1 { id: tx_context::new_id(&mut ctx) }; + bag::add(&mut bag, obj1); + let obj2 = Object2 { id: tx_context::new_id(&mut ctx) }; + bag::add(&mut bag, obj2); + bag::transfer(bag, tx_context::sender(&ctx)); + } +} diff --git a/crates/sui-framework/tests/coin_balance_tests.move b/crates/sui-framework/tests/coin_balance_tests.move new file mode 100644 index 0000000000000..f2aca29b1a17e --- /dev/null +++ b/crates/sui-framework/tests/coin_balance_tests.move @@ -0,0 +1,90 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module sui::test_coin { + use sui::test_scenario::{Self, ctx}; + use sui::coin; + use sui::balance; + use sui::sui::SUI; + use sui::locked_coin::LockedCoin; + use sui::tx_context; + use sui::locked_coin; + use sui::coin::Coin; + + #[test] + fun type_morphing() { + let test = &mut test_scenario::begin(&@0x1); + + let balance = balance::zero(); + let coin = coin::from_balance(balance, ctx(test)); + let balance = coin::into_balance(coin); + + balance::destroy_zero(balance); + + let coin = coin::mint_for_testing(100, ctx(test)); + let balance_mut = coin::balance_mut(&mut coin); + let sub_balance = balance::split(balance_mut, 50); + + assert!(balance::value(&sub_balance) == 50, 0); + assert!(coin::value(&coin) == 50, 0); + + let balance = coin::into_balance(coin); + balance::join(&mut balance, sub_balance); + + assert!(balance::value(&balance) == 100, 0); + + let coin = coin::from_balance(balance, ctx(test)); + coin::keep(coin, ctx(test)); + } + + const TEST_SENDER_ADDR: address = @0xA11CE; + const TEST_RECIPIENT_ADDR: address = @0xB0B; + + #[test] + public entry fun test_locked_coin_valid() { + let scenario = &mut test_scenario::begin(&TEST_SENDER_ADDR); + let ctx = test_scenario::ctx(scenario); + let coin = coin::mint_for_testing(42, ctx); + + test_scenario::next_tx(scenario, &TEST_SENDER_ADDR); + // Lock up the coin until epoch 2. + locked_coin::lock_coin(coin, TEST_RECIPIENT_ADDR, 2, test_scenario::ctx(scenario)); + + // Advance the epoch by 2. + test_scenario::next_epoch(scenario); + test_scenario::next_epoch(scenario); + assert!(tx_context::epoch(test_scenario::ctx(scenario)) == 2, 1); + + test_scenario::next_tx(scenario, &TEST_RECIPIENT_ADDR); + let locked_coin = test_scenario::take_owned>(scenario); + // The unlock should go through since epoch requirement is met. + locked_coin::unlock_coin(locked_coin, test_scenario::ctx(scenario)); + + test_scenario::next_tx(scenario, &TEST_RECIPIENT_ADDR); + let unlocked_coin = test_scenario::take_owned>(scenario); + assert!(coin::value(&unlocked_coin) == 42, 2); + coin::destroy_for_testing(unlocked_coin); + } + + #[test] + #[expected_failure(abort_code = 1)] + public entry fun test_locked_coin_invalid() { + let scenario = &mut test_scenario::begin(&TEST_SENDER_ADDR); + let ctx = test_scenario::ctx(scenario); + let coin = coin::mint_for_testing(42, ctx); + + test_scenario::next_tx(scenario, &TEST_SENDER_ADDR); + // Lock up the coin until epoch 2. + locked_coin::lock_coin(coin, TEST_RECIPIENT_ADDR, 2, test_scenario::ctx(scenario)); + + // Advance the epoch by 1. + test_scenario::next_epoch(scenario); + assert!(tx_context::epoch(test_scenario::ctx(scenario)) == 1, 1); + + test_scenario::next_tx(scenario, &TEST_RECIPIENT_ADDR); + let locked_coin = test_scenario::take_owned>(scenario); + // The unlock should fail. + locked_coin::unlock_coin(locked_coin, test_scenario::ctx(scenario)); + } +} diff --git a/crates/sui-framework/tests/collection_tests.move b/crates/sui-framework/tests/collection_tests.move new file mode 100644 index 0000000000000..e87502fdbc395 --- /dev/null +++ b/crates/sui-framework/tests/collection_tests.move @@ -0,0 +1,140 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module sui::collection_tests { + use sui::bag::{Self, Bag}; + use sui::collection::{Self, Collection}; + use sui::id::{Self, VersionedID}; + use sui::test_scenario; + use sui::tx_context; + + struct Object has key, store { + id: VersionedID, + } + + #[test] + fun test_collection() { + let sender = @0x0; + let scenario = &mut test_scenario::begin(&sender); + + // Create a new Collection and transfer it to the sender. + test_scenario::next_tx(scenario, &sender); + { + collection::create(test_scenario::ctx(scenario)); + }; + + // Add two objects of different types into the collection. + test_scenario::next_tx(scenario, &sender); + { + let collection = test_scenario::take_owned>(scenario); + assert!(collection::size(&collection) == 0, 0); + + let obj1 = Object { id: tx_context::new_id(test_scenario::ctx(scenario)) }; + let id1 = *id::id(&obj1); + let obj2 = Object { id: tx_context::new_id(test_scenario::ctx(scenario)) }; + let id2 = *id::id(&obj2); + + collection::add(&mut collection, obj1); + collection::add(&mut collection, obj2); + assert!(collection::size(&collection) == 2, 0); + + assert!(collection::contains(&collection, &id1), 0); + assert!(collection::contains(&collection, &id2), 0); + + test_scenario::return_owned(scenario, collection); + }; + } + + #[test] + fun test_collection_bag_interaction() { + let sender = @0x0; + let scenario = &mut test_scenario::begin(&sender); + + // Create a new Collection and a new Bag and transfer them to the sender. + test_scenario::next_tx(scenario, &sender); + { + collection::create(test_scenario::ctx(scenario)); + bag::create(test_scenario::ctx(scenario)); + }; + + // Add a new object to the Collection. + test_scenario::next_tx(scenario, &sender); + { + let collection = test_scenario::take_owned>(scenario); + let obj = Object { id: tx_context::new_id(test_scenario::ctx(scenario)) }; + collection::add(&mut collection, obj); + test_scenario::return_owned(scenario, collection); + }; + + // Remove the object from the collection and add it to the bag. + test_scenario::next_tx(scenario, &sender); + { + let collection = test_scenario::take_owned>(scenario); + let bag = test_scenario::take_owned(scenario); + let obj = test_scenario::take_child_object, Object>(scenario, &collection); + let id = *id::id(&obj); + + let (obj, child_ref) = collection::remove(&mut collection, obj); + bag::add_child_object(&mut bag, obj, child_ref); + + assert!(collection::size(&collection) == 0, 0); + assert!(bag::size(&bag) == 1, 0); + assert!(bag::contains(&bag, &id), 0); + + test_scenario::return_owned(scenario, collection); + test_scenario::return_owned(scenario, bag); + }; + + // Remove the object from the bag and add it back to the collection. + test_scenario::next_tx(scenario, &sender); + { + let collection = test_scenario::take_owned>(scenario); + let bag = test_scenario::take_owned(scenario); + let obj = test_scenario::take_child_object(scenario, &bag); + let id = *id::id(&obj); + + let obj = bag::remove(&mut bag, obj); + collection::add(&mut collection, obj); + + assert!(collection::size(&collection) == 1, 0); + assert!(bag::size(&bag) == 0, 0); + assert!(collection::contains(&collection, &id), 0); + + test_scenario::return_owned(scenario, collection); + test_scenario::return_owned(scenario, bag); + }; + + } + + #[test] + #[expected_failure(abort_code = 520)] + fun test_init_with_invalid_max_capacity() { + let ctx = tx_context::dummy(); + // Sui::collection::DEFAULT_MAX_CAPACITY is not readable outside the module + let max_capacity = 65536; + let collection = collection::new_with_max_capacity(&mut ctx, max_capacity + 1); + collection::transfer(collection, tx_context::sender(&ctx)); + } + + #[test] + #[expected_failure(abort_code = 520)] + fun test_init_with_zero() { + let ctx = tx_context::dummy(); + let collection = collection::new_with_max_capacity(&mut ctx, 0); + collection::transfer(collection, tx_context::sender(&ctx)); + } + + #[test] + #[expected_failure(abort_code = 776)] + fun test_exceed_max_capacity() { + let ctx = tx_context::dummy(); + let collection = collection::new_with_max_capacity(&mut ctx, 1); + + let obj1 = Object { id: tx_context::new_id(&mut ctx) }; + collection::add(&mut collection, obj1); + let obj2 = Object { id: tx_context::new_id(&mut ctx) }; + collection::add(&mut collection, obj2); + collection::transfer(collection, tx_context::sender(&ctx)); + } +} diff --git a/crates/sui-framework/tests/id_tests.move b/crates/sui-framework/tests/id_tests.move new file mode 100644 index 0000000000000..48a26dcc4dcc9 --- /dev/null +++ b/crates/sui-framework/tests/id_tests.move @@ -0,0 +1,25 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module sui::id_tests { + use sui::id; + use sui::tx_context; + + const ID_BYTES_MISMATCH: u64 = 0; + + struct Object has key { + id: id::VersionedID, + } + + #[test] + fun test_get_id() { + let ctx = tx_context::dummy(); + let versioned_id = tx_context::new_id(&mut ctx); + let obj_id = *id::inner(&versioned_id); + let obj = Object { id: versioned_id }; + assert!(*id::id(&obj) == obj_id, ID_BYTES_MISMATCH); + let Object { id } = obj; + id::delete(id); + } +} diff --git a/crates/sui-framework/tests/MathTests.move b/crates/sui-framework/tests/math_tests.move similarity index 61% rename from crates/sui-framework/tests/MathTests.move rename to crates/sui-framework/tests/math_tests.move index e9d3e7f1411a0..8b0834c5d8ff3 100644 --- a/crates/sui-framework/tests/MathTests.move +++ b/crates/sui-framework/tests/math_tests.move @@ -2,44 +2,44 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module Sui::MathTests { - use Sui::Math; +module sui::math_tests { + use sui::math; #[test] fun test_max() { - assert!(Math::max(10, 100) == 100, 1); - assert!(Math::max(100, 10) == 100, 2); - assert!(Math::max(0, 0) == 0, 3); + assert!(math::max(10, 100) == 100, 1); + assert!(math::max(100, 10) == 100, 2); + assert!(math::max(0, 0) == 0, 3); } #[test] fun test_min() { - assert!(Math::min(10, 100) == 10, 1); - assert!(Math::min(100, 10) == 10, 2); - assert!(Math::min(0, 0) == 0, 3); + assert!(math::min(10, 100) == 10, 1); + assert!(math::min(100, 10) == 10, 2); + assert!(math::min(0, 0) == 0, 3); } #[test] fun test_perfect_sqrt() { let i = 0; while (i < 1000) { - assert!(Math::sqrt(i * i) == i, 1); + assert!(math::sqrt(i * i) == i, 1); i = i + 1; } } #[test] // This function tests whether the (square root)^2 equals the - // initial value OR whether it is equal to the nearest lower + // initial value OR whether it is equal to the nearest lower // number that does. fun test_imperfect_sqrt() { let i = 1; let prev = 1; while (i <= 1000) { - let root = Math::sqrt(i); - + let root = math::sqrt(i); + assert!(i == root * root || root == prev, 0); - + prev = root; i = i + 1; } @@ -48,6 +48,6 @@ module Sui::MathTests { #[test] fun test_sqrt_big_numbers() { let u64_max = 18446744073709551615; - assert!(4294967295 == Math::sqrt(u64_max), 0) + assert!(4294967295 == math::sqrt(u64_max), 0) } } diff --git a/crates/sui-framework/tests/test_scenario_tests.move b/crates/sui-framework/tests/test_scenario_tests.move new file mode 100644 index 0000000000000..8ae268a850f10 --- /dev/null +++ b/crates/sui-framework/tests/test_scenario_tests.move @@ -0,0 +1,372 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module sui::test_scenarioTests { + use sui::id; + use sui::test_scenario::{Self, Scenario}; + use sui::transfer::{Self, ChildRef}; + use sui::tx_context; + + const ID_BYTES_MISMATCH: u64 = 0; + const VALUE_MISMATCH: u64 = 1; + const OBJECT_ID_NOT_FOUND: u64 = 2; + + struct Object has key, store { + id: id::VersionedID, + value: u64, + } + + struct Wrapper has key { + id: id::VersionedID, + child: Object, + } + + struct Parent has key { + id: id::VersionedID, + child: ChildRef, + } + + struct MultiChildParent has key { + id: id::VersionedID, + child1: ChildRef, + child2: ChildRef, + } + + #[test] + fun test_wrap_unwrap() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + { + let id = test_scenario::new_id(&mut scenario); + let obj = Object { id, value: 10 }; + transfer::transfer(obj, copy sender); + }; + // now, object gets wrapped + test_scenario::next_tx(&mut scenario, &sender); + { + let id = test_scenario::new_id(&mut scenario); + let child = test_scenario::take_owned(&mut scenario); + let wrapper = Wrapper { id, child }; + transfer::transfer(wrapper, copy sender); + }; + // wrapped object should no longer be removable, but wrapper should be + test_scenario::next_tx(&mut scenario, &sender); + { + assert!(!test_scenario::can_take_owned(&scenario), 0); + assert!(test_scenario::can_take_owned(&scenario), 1); + } + } + + #[test] + fun test_remove_then_return() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + { + let id = test_scenario::new_id(&mut scenario); + let obj = Object { id, value: 10 }; + transfer::transfer(obj, copy sender); + }; + // object gets removed, then returned + test_scenario::next_tx(&mut scenario, &sender); + { + let object = test_scenario::take_owned(&mut scenario); + test_scenario::return_owned(&mut scenario, object); + }; + // Object should remain accessible + test_scenario::next_tx(&mut scenario, &sender); + { + assert!(test_scenario::can_take_owned(&scenario), 0); + } + } + + #[test] + fun test_return_and_update() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + { + let id = test_scenario::new_id(&mut scenario); + let obj = Object { id, value: 10 }; + transfer::transfer(obj, copy sender); + }; + test_scenario::next_tx(&mut scenario, &sender); + { + let obj = test_scenario::take_owned(&mut scenario); + assert!(obj.value == 10, 0); + obj.value = 100; + test_scenario::return_owned(&mut scenario, obj); + }; + test_scenario::next_tx(&mut scenario, &sender); + { + let obj = test_scenario::take_owned(&mut scenario); + assert!(obj.value == 100, 1); + test_scenario::return_owned(&mut scenario, obj); + } + } + + #[test] + fun test_remove_during_tx() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + { + let id = test_scenario::new_id(&mut scenario); + 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!(!test_scenario::can_take_owned(&scenario), 0) + }; + } + + #[test] + #[expected_failure(abort_code = 5 /* EALREADY_REMOVED_OBJECT */)] + fun test_double_remove() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + { + let id = test_scenario::new_id(&mut scenario); + let obj = Object { id, value: 10 }; + transfer::transfer(obj, copy sender); + }; + test_scenario::next_tx(&mut scenario, &sender); + { + let obj1 = test_scenario::take_owned(&mut scenario); + let obj2 = test_scenario::take_owned(&mut scenario); + test_scenario::return_owned(&mut scenario, obj1); + test_scenario::return_owned(&mut scenario, obj2); + } + } + + #[test] + fun test_three_owners() { + // make sure an object that goes from addr1 -> addr2 -> addr3 can only be accessed by + // the appropriate owner at each stage + let addr1 = @0x0; + let addr2 = @0x1; + let addr3 = @0x2; + let scenario = test_scenario::begin(&addr1); + { + let id = test_scenario::new_id(&mut scenario); + let obj = Object { id, value: 10 }; + // self-transfer + transfer::transfer(obj, copy addr1); + }; + // addr1 -> addr2 + test_scenario::next_tx(&mut scenario, &addr1); + { + let obj = test_scenario::take_owned(&mut scenario); + transfer::transfer(obj, copy addr2) + }; + // addr1 cannot access + test_scenario::next_tx(&mut scenario, &addr1); + { + assert!(!test_scenario::can_take_owned(&scenario), 0); + }; + // addr2 -> addr3 + test_scenario::next_tx(&mut scenario, &addr2); + { + let obj = test_scenario::take_owned(&mut scenario); + transfer::transfer(obj, copy addr3) + }; + // addr1 cannot access + test_scenario::next_tx(&mut scenario, &addr1); + { + assert!(!test_scenario::can_take_owned(&scenario), 0); + }; + // addr2 cannot access + test_scenario::next_tx(&mut scenario, &addr2); + { + assert!(!test_scenario::can_take_owned(&scenario), 0); + }; + // addr3 *can* access + test_scenario::next_tx(&mut scenario, &addr3); + { + assert!(test_scenario::can_take_owned(&scenario), 0); + } + } + + #[test] + fun test_transfer_then_delete() { + let tx1_sender = @0x0; + let tx2_sender = @0x1; + let scenario = test_scenario::begin(&tx1_sender); + // send an object to tx2_sender + let id_bytes; + { + let id = test_scenario::new_id(&mut scenario); + id_bytes = *id::inner(&id); + let obj = Object { id, value: 100 }; + transfer::transfer(obj, copy tx2_sender); + // sender cannot access the object + assert!(!test_scenario::can_take_owned(&scenario), 0); + }; + // check that tx2_sender can get the object, and it's the same one + test_scenario::next_tx(&mut scenario, &tx2_sender); + { + assert!(test_scenario::can_take_owned(&scenario), 1); + let received_obj = test_scenario::take_owned(&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); + id::delete(received_id); + }; + // check that the object is no longer accessible after deletion + test_scenario::next_tx(&mut scenario, &tx2_sender); + { + assert!(!test_scenario::can_take_owned(&scenario), 2); + } + } + + #[test] + fun test_take_owned_by_id() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + let versioned_id1 = test_scenario::new_id(&mut scenario); + let versioned_id2 = test_scenario::new_id(&mut scenario); + let versioned_id3 = test_scenario::new_id(&mut scenario); + let id1 = *id::inner(&versioned_id1); + let id2 = *id::inner(&versioned_id2); + let id3 = *id::inner(&versioned_id3); + { + let obj1 = Object { id: versioned_id1, value: 10 }; + let obj2 = Object { id: versioned_id2, value: 20 }; + let obj3 = Object { id: versioned_id3, value: 30 }; + transfer::transfer(obj1, copy sender); + transfer::transfer(obj2, copy sender); + transfer::transfer(obj3, copy sender); + }; + test_scenario::next_tx(&mut scenario, &sender); + { + assert!( + test_scenario::can_take_owned_by_id(&mut scenario, id1), + OBJECT_ID_NOT_FOUND + ); + assert!( + test_scenario::can_take_owned_by_id(&mut scenario, id2), + OBJECT_ID_NOT_FOUND + ); + assert!( + test_scenario::can_take_owned_by_id(&mut scenario, id3), + OBJECT_ID_NOT_FOUND + ); + let obj1 = test_scenario::take_owned_by_id(&mut scenario, id1); + let obj3 = test_scenario::take_owned_by_id(&mut scenario, id3); + let obj2 = test_scenario::take_owned_by_id(&mut scenario, id2); + assert!(obj1.value == 10, VALUE_MISMATCH); + assert!(obj2.value == 20, VALUE_MISMATCH); + assert!(obj3.value == 30, VALUE_MISMATCH); + test_scenario::return_owned(&mut scenario, obj1); + test_scenario::return_owned(&mut scenario, obj2); + test_scenario::return_owned(&mut scenario, obj3); + }; + } + + #[test] + fun test_get_last_created_object_id() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + { + let versioned_id = test_scenario::new_id(&mut scenario); + let id = *id::inner(&versioned_id); + let obj = Object { id: versioned_id, value: 10 }; + transfer::transfer(obj, copy sender); + let ctx = test_scenario::ctx(&mut scenario); + assert!(id == tx_context::last_created_object_id(ctx), 0); + }; + } + + #[test] + fun test_take_child_object() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + create_parent_and_object(&mut scenario); + + test_scenario::next_tx(&mut scenario, &sender); + { + // sender cannot take object directly. + assert!(!test_scenario::can_take_owned(&scenario), 0); + // sender can take parent, however. + assert!(test_scenario::can_take_owned(&scenario), 0); + + let parent = test_scenario::take_owned(&mut scenario); + // Make sure we can take the child object with the parent object. + let child = test_scenario::take_child_object(&mut scenario, &parent); + test_scenario::return_owned(&mut scenario, parent); + test_scenario::return_owned(&mut scenario, child); + }; + } + + #[expected_failure(abort_code = 3 /* EMPTY_INVENTORY */)] + #[test] + fun test_take_child_object_incorrect_signer() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + create_parent_and_object(&mut scenario); + + test_scenario::next_tx(&mut scenario, &sender); + let parent = test_scenario::take_owned(&mut scenario); + + let another = @0x1; + test_scenario::next_tx(&mut scenario, &another); + // This should fail even though we have parent object here. + // Because the signer doesn't match. + let child = test_scenario::take_child_object(&mut scenario, &parent); + test_scenario::return_owned(&mut scenario, child); + + test_scenario::return_owned(&mut scenario, parent); + } + + #[test] + fun test_take_child_object_by_id() { + let sender = @0x0; + let scenario = test_scenario::begin(&sender); + // Create two children and a parent object. + let child1 = Object { + id: test_scenario::new_id(&mut scenario), + value: 10, + }; + let child1_id = *id::id(&child1); + let child2 = Object { + id: test_scenario::new_id(&mut scenario), + value: 20, + }; + let child2_id = *id::id(&child2); + let parent_id = test_scenario::new_id(&mut scenario); + let (parent_id, child1_ref) = transfer::transfer_to_object_id(child1, parent_id); + let (parent_id, child2_ref) = transfer::transfer_to_object_id(child2, parent_id); + + let parent = MultiChildParent { + id: parent_id, + child1: child1_ref, + child2: child2_ref, + }; + transfer::transfer(parent, sender); + + test_scenario::next_tx(&mut scenario, &sender); + { + let parent = test_scenario::take_owned(&mut scenario); + let child1 = test_scenario::take_child_object_by_id(&mut scenario, &parent, child1_id); + let child2 = test_scenario::take_child_object_by_id(&mut scenario, &parent, child2_id); + assert!(child1.value == 10, 0); + assert!(child2.value == 20, 0); + test_scenario::return_owned(&mut scenario, parent); + test_scenario::return_owned(&mut scenario, child1); + test_scenario::return_owned(&mut scenario, child2); + }; + } + + /// Create object and parent. object is a child of parent. + /// parent is owned by sender of `scenario`. + fun create_parent_and_object(scenario: &mut Scenario) { + let parent_id = test_scenario::new_id(scenario); + let object = Object { + id: test_scenario::new_id(scenario), + value: 10, + }; + let (parent_id, child) = transfer::transfer_to_object_id(object, parent_id); + let parent = Parent { + id: parent_id, + child, + }; + transfer::transfer(parent, test_scenario::sender(scenario)); + } +} diff --git a/crates/sui-framework/tests/tx_context_tests.move b/crates/sui-framework/tests/tx_context_tests.move new file mode 100644 index 0000000000000..51a4e0caa30d6 --- /dev/null +++ b/crates/sui-framework/tests/tx_context_tests.move @@ -0,0 +1,24 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module sui::tx_context_tests { + use sui::id; + use sui::tx_context; + + #[test] + fun test_id_generation() { + let ctx = tx_context::dummy(); + assert!(tx_context::get_ids_created(&ctx) == 0, 0); + + let id1 = tx_context::new_id(&mut ctx); + let id2 = tx_context::new_id(&mut ctx); + + // new_id should always produce fresh ID's + assert!(&id1 != &id2, 1); + assert!(tx_context::get_ids_created(&ctx) == 2, 2); + id::delete(id1); + id::delete(id2); + } + +} diff --git a/crates/sui-framework/tests/UrlTests.move b/crates/sui-framework/tests/url_tests.move similarity index 62% rename from crates/sui-framework/tests/UrlTests.move rename to crates/sui-framework/tests/url_tests.move index 2a00831935cb2..e01c98d0692bd 100644 --- a/crates/sui-framework/tests/UrlTests.move +++ b/crates/sui-framework/tests/url_tests.move @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module Sui::UrlTests { - use Sui::Url; +module sui::url_tests { + use sui::url; use std::ascii::Self; const EHASH_LENGTH_MISMATCH: u64 = 0; @@ -14,8 +14,8 @@ module Sui::UrlTests { // url strings are not currently validated let url_str = ascii::string(x"414243454647"); - let url = Url::new_unsafe(url_str); - assert!(Url::inner_url(&url) == url_str, URL_STRING_MISMATCH); + let url = url::new_unsafe(url_str); + assert!(url::inner_url(&url) == url_str, URL_STRING_MISMATCH); } #[test] @@ -26,8 +26,8 @@ module Sui::UrlTests { // length too short let hash = x"badf012345"; - let url = Url::new_unsafe(url_str); - let _ = Url::new_unsafe_url_commitment(url, hash); + let url = url::new_unsafe(url_str); + let _ = url::new_unsafe_url_commitment(url, hash); } #[test] @@ -37,15 +37,15 @@ module Sui::UrlTests { // 32 bytes let hash = x"1234567890123456789012345678901234567890abcdefabcdefabcdefabcdef"; - let url = Url::new_unsafe(url_str); - let url_commit = Url::new_unsafe_url_commitment(url, hash); + let url = url::new_unsafe(url_str); + let url_commit = url::new_unsafe_url_commitment(url, hash); - assert!(Url::url_commitment_resource_hash(&url_commit) == hash, EHASH_LENGTH_MISMATCH); - assert!(Url::url_commitment_inner_url(&url_commit) == url_str, URL_STRING_MISMATCH); + assert!(url::url_commitment_resource_hash(&url_commit) == hash, EHASH_LENGTH_MISMATCH); + assert!(url::url_commitment_inner_url(&url_commit) == url_str, URL_STRING_MISMATCH); let url_str = ascii::string(x"37414243454647"); - Url::url_commitment_update(&mut url_commit, url_str); - assert!(Url::url_commitment_inner_url(&url_commit) == url_str, URL_STRING_MISMATCH); + url::url_commitment_update(&mut url_commit, url_str); + assert!(url::url_commitment_inner_url(&url_commit) == url_str, URL_STRING_MISMATCH); } } diff --git a/crates/sui-framework/tests/validator_set_tests.move b/crates/sui-framework/tests/validator_set_tests.move new file mode 100644 index 0000000000000..ca3810ceb7c39 --- /dev/null +++ b/crates/sui-framework/tests/validator_set_tests.move @@ -0,0 +1,96 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module sui::validator_set_tests { + use sui::balance; + use sui::coin; + use sui::sui::SUI; + use sui::tx_context::{Self, TxContext}; + use sui::validator::{Self, Validator}; + use sui::validator_set; + + #[test] + fun test_validator_set_flow() { + // Create 4 validators, with stake 100, 200, 300, 400. + let (ctx1, validator1) = create_validator(@0x1, 1); + let (_ctx2, validator2) = create_validator(@0x2, 2); + let (_ctx3, validator3) = create_validator(@0x3, 3); + let (_ctx4, validator4) = create_validator(@0x4, 4); + + // Create a validator set with only the first validator in it. + let validator_set = validator_set::new(vector[validator1]); + assert!(validator_set::total_validator_candidate_count(&validator_set) == 1, 0); + assert!(validator_set::validator_stake(&validator_set) == 100, 0); + + // Add the other 3 validators one by one. + validator_set::request_add_validator( + &mut validator_set, + validator2, + ); + // Adding validator during the epoch should not affect stake and quorum threshold. + assert!(validator_set::total_validator_candidate_count(&validator_set) == 2, 0); + assert!(validator_set::validator_stake(&validator_set) == 100, 0); + + validator_set::request_add_validator( + &mut validator_set, + validator3, + ); + validator_set::request_add_stake( + &mut validator_set, + coin::into_balance(coin::mint_for_testing(500, &mut ctx1)), + &ctx1, + ); + // Adding stake to existing active validator during the epoch + // should not change total stake. + assert!(validator_set::validator_stake(&validator_set) == 100, 0); + + validator_set::request_withdraw_stake( + &mut validator_set, + 500, + 100 /* min_validator_stake */, + &ctx1, + ); + assert!(validator_set::validator_stake(&validator_set) == 100, 0); + + validator_set::request_add_validator( + &mut validator_set, + validator4, + ); + + let reward = balance::zero(); + validator_set::advance_epoch(&mut validator_set, &mut reward, &mut ctx1); + // The total stake and quorum should reflect 4 validators. + assert!(validator_set::total_validator_candidate_count(&validator_set) == 4, 0); + assert!(validator_set::validator_stake(&validator_set) == 1000, 0); + + validator_set::request_remove_validator( + &mut validator_set, + &ctx1, + ); + // Total validator candidate count changes, but total stake remains during epoch. + assert!(validator_set::total_validator_candidate_count(&validator_set) == 3, 0); + assert!(validator_set::validator_stake(&validator_set) == 1000, 0); + validator_set::advance_epoch(&mut validator_set, &mut reward, &mut ctx1); + // Validator1 is gone. + assert!(validator_set::validator_stake(&validator_set) == 900, 0); + + validator_set::destroy_for_testing(validator_set, &mut ctx1); + balance::destroy_zero(reward); + } + + fun create_validator(addr: address, hint: u8): (TxContext, Validator) { + let stake_value = (hint as u64) * 100; + let ctx = tx_context::new_from_hint(addr, hint, 0, 0); + let init_stake = coin::mint_for_testing(stake_value, &mut ctx); + let init_stake = coin::into_balance(init_stake); + let validator = validator::new( + addr, + vector[hint], + vector[hint], + vector[hint], + init_stake, + ); + (ctx, validator) + } +} diff --git a/crates/sui-framework/tests/validator_tests.move b/crates/sui-framework/tests/validator_tests.move new file mode 100644 index 0000000000000..c53a9a1856d14 --- /dev/null +++ b/crates/sui-framework/tests/validator_tests.move @@ -0,0 +1,82 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module sui::validator_tests { + use sui::coin::{Self, Coin}; + use sui::sui::SUI; + use sui::test_scenario; + use sui::validator; + + #[test] + fun test_validator_owner_flow() { + let sender = @0x1; + let scenario = &mut test_scenario::begin(&sender); + { + let ctx = test_scenario::ctx(scenario); + + let init_stake = coin::into_balance(coin::mint_for_testing(10, ctx)); + let validator = validator::new( + sender, + x"FF", + b"Validator1", + x"FFFF", + init_stake, + ); + assert!(validator::stake_amount(&validator) == 10, 0); + assert!(validator::sui_address(&validator) == sender, 0); + + validator::destroy(validator, ctx); + }; + + // Check that after destroy, the original stake still exists. + test_scenario::next_tx(scenario, &sender); + { + let stake_coin = test_scenario::take_owned>(scenario); + assert!(coin::value(&stake_coin) == 10, 0); + test_scenario::return_owned(scenario, stake_coin); + }; + } + + #[test] + fun test_pending_validator_flow() { + let sender = @0x1; + let scenario = &mut test_scenario::begin(&sender); + let ctx = test_scenario::ctx(scenario); + let init_stake = coin::into_balance(coin::mint_for_testing(10, ctx)); + let validator = validator::new( + sender, + x"FF", + b"Validator1", + x"FFFF", + init_stake, + ); + + let new_stake = coin::into_balance(coin::mint_for_testing(30, ctx)); + validator::request_add_stake(&mut validator, new_stake); + + assert!(validator::stake_amount(&validator) == 10, 0); + assert!(validator::pending_stake_amount(&validator) == 30, 0); + + validator::request_withdraw_stake(&mut validator, 5, 35); + assert!(validator::stake_amount(&validator) == 10, 0); + assert!(validator::pending_stake_amount(&validator) == 30, 0); + assert!(validator::pending_withdraw(&validator) == 5, 0); + + // Calling `adjust_stake` will withdraw the coin and transfer to sender. + validator::adjust_stake(&mut validator, ctx); + + assert!(validator::stake_amount(&validator) == 35, 0); + assert!(validator::pending_stake_amount(&validator) == 0, 0); + assert!(validator::pending_withdraw(&validator) == 0, 0); + + test_scenario::next_tx(scenario, &sender); + { + let withdraw = test_scenario::take_owned>(scenario); + assert!(coin::value(&withdraw) == 5, 0); + test_scenario::return_owned(scenario, withdraw); + }; + + validator::destroy(validator, test_scenario::ctx(scenario)); + } +} diff --git a/crates/sui-json-rpc-api/src/rpc_types.rs b/crates/sui-json-rpc-api/src/rpc_types.rs index 9db5d36f9d1a8..d46ccf1a3e357 100644 --- a/crates/sui-json-rpc-api/src/rpc_types.rs +++ b/crates/sui-json-rpc-api/src/rpc_types.rs @@ -693,7 +693,7 @@ fn try_convert_type(type_: &StructTag, fields: &[(Identifier, MoveValue)]) -> Op .map(|(id, value)| (id.to_string(), value.clone().into())) .collect::>(); match struct_name.as_str() { - "0x2::UTF8::String" | "0x1::ascii::String" => { + "0x2::utf8::String" | "0x1::ascii::String" => { if let SuiMoveValue::Bytearray(bytes) = fields["bytes"].clone() { if let Ok(bytes) = bytes.to_vec() { if let Ok(s) = String::from_utf8(bytes) { @@ -702,18 +702,18 @@ fn try_convert_type(type_: &StructTag, fields: &[(Identifier, MoveValue)]) -> Op } } } - "0x2::Url::Url" => return Some(fields["url"].clone()), - "0x2::ID::ID" => { + "0x2::url::Url" => return Some(fields["url"].clone()), + "0x2::id::ID" => { if let SuiMoveValue::Address(id) = fields["bytes"] { return Some(SuiMoveValue::Address(id)); } } - "0x2::ID::UniqueID" => { + "0x2::id::UniqueID" => { if let SuiMoveValue::Address(id) = fields["id"].clone() { return Some(SuiMoveValue::Address(id)); } } - "0x2::ID::VersionedID" => { + "0x2::id::VersionedID" => { if let SuiMoveValue::Address(address) = fields["id"].clone() { if let SuiMoveValue::Number(version) = fields["version"].clone() { return Some(SuiMoveValue::VersionedID { @@ -723,12 +723,12 @@ fn try_convert_type(type_: &StructTag, fields: &[(Identifier, MoveValue)]) -> Op } } } - "0x2::Balance::Balance" => { + "0x2::balance::Balance" => { if let SuiMoveValue::Number(value) = fields["value"].clone() { return Some(SuiMoveValue::Number(value)); } } - "0x1::Option::Option" => { + "0x1::option::Option" => { if let SuiMoveValue::Vector(values) = fields["vec"].clone() { return Some(SuiMoveValue::Option(Box::new(values.first().cloned()))); } diff --git a/crates/sui-json-rpc-api/src/unit_tests/gateway_types_tests.rs b/crates/sui-json-rpc-api/src/unit_tests/gateway_types_tests.rs index 147789781aca4..d1bb67e26174a 100644 --- a/crates/sui-json-rpc-api/src/unit_tests/gateway_types_tests.rs +++ b/crates/sui-json-rpc-api/src/unit_tests/gateway_types_tests.rs @@ -57,8 +57,8 @@ fn test_move_value_to_string() { let move_value = MoveValue::Struct(MoveStruct::WithTypes { type_: StructTag { address: SUI_FRAMEWORK_ADDRESS, + module: ident_str!("utf8").to_owned(), name: ident_str!("String").to_owned(), - module: ident_str!("UTF8").to_owned(), type_params: vec![], }, fields: vec![(ident_str!("bytes").to_owned(), MoveValue::Vector(values))], @@ -81,8 +81,8 @@ fn test_move_value_to_url() { let string_move_value = MoveValue::Struct(MoveStruct::WithTypes { type_: StructTag { address: SUI_FRAMEWORK_ADDRESS, + module: ident_str!("utf8").to_owned(), name: ident_str!("String").to_owned(), - module: ident_str!("UTF8").to_owned(), type_params: vec![], }, fields: vec![(ident_str!("bytes").to_owned(), MoveValue::Vector(values))], @@ -91,8 +91,8 @@ fn test_move_value_to_url() { let url_move_value = MoveValue::Struct(MoveStruct::WithTypes { type_: StructTag { address: SUI_FRAMEWORK_ADDRESS, + module: ident_str!("url").to_owned(), name: ident_str!("Url").to_owned(), - module: ident_str!("Url").to_owned(), type_params: vec![], }, fields: vec![(ident_str!("url").to_owned(), string_move_value)], diff --git a/crates/sui-json/src/tests.rs b/crates/sui-json/src/tests.rs index e1fdc8a5815b7..137bde1f1b210 100644 --- a/crates/sui-json/src/tests.rs +++ b/crates/sui-json/src/tests.rs @@ -295,7 +295,7 @@ fn test_basic_args_linter_top_level() { let example_package = Object::new_package(compiled_modules, TransactionDigest::genesis()); let example_package = example_package.data.try_as_package().unwrap(); - let module = Identifier::new("Geniteam").unwrap(); + let module = Identifier::new("geniteam").unwrap(); let function = Identifier::new("create_monster").unwrap(); /* @@ -404,7 +404,7 @@ fn test_basic_args_linter_top_level() { .try_as_package() .unwrap(); - let module = Identifier::new("ObjectBasics").unwrap(); + let module = Identifier::new("object_basics").unwrap(); let function = Identifier::new("create").unwrap(); /* @@ -440,7 +440,7 @@ fn test_basic_args_linter_top_level() { // Test with object args - let module = Identifier::new("ObjectBasics").unwrap(); + let module = Identifier::new("object_basics").unwrap(); let function = Identifier::new("transfer").unwrap(); /* diff --git a/crates/sui-open-rpc/samples/objects.json b/crates/sui-open-rpc/samples/objects.json index d70a9a7d83596..12b8b951df455 100644 --- a/crates/sui-open-rpc/samples/objects.json +++ b/crates/sui-open-rpc/samples/objects.json @@ -4,7 +4,7 @@ "details": { "data": { "dataType": "moveObject", - "type": "0x2::DevNetNFT::DevNetNFT", + "type": "0x2::devnet_nft::devnet_nft", "fields": { "description": "An NFT created by the wallet Command Line Tool", "id": { @@ -37,7 +37,7 @@ "details": { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 100000, "id": { @@ -82,7 +82,7 @@ "details": { "data": { "dataType": "moveObject", - "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::Hero::Hero", + "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::hero::Hero", "fields": { "experience": 0, "game_id": "0x8c0fd2c50a977dde203b6c966814f4d8941b47b7", @@ -92,11 +92,11 @@ "version": 1 }, "sword": { - "type": "0x1::option::Option<0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::Hero::Sword>", + "type": "0x1::option::Option<0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::hero::Sword>", "fields": { "vec": [ { - "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::Hero::Sword", + "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::hero::Sword", "fields": { "game_id": "0x8c0fd2c50a977dde203b6c966814f4d8941b47b7", "id": { diff --git a/crates/sui-open-rpc/samples/owned_objects.json b/crates/sui-open-rpc/samples/owned_objects.json index 5c4d018bb03f0..b5fa9140cb309 100644 --- a/crates/sui-open-rpc/samples/owned_objects.json +++ b/crates/sui-open-rpc/samples/owned_objects.json @@ -4,7 +4,7 @@ "objectId": "0x0833b8050695a7c5f8f982edb027c7b4a9784144", "version": 1, "digest": "/seGVnecNFUeI2ECAUf6oqb46r2uBNz/g+/Y23Fnhrk=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -14,7 +14,7 @@ "objectId": "0x09b7e66811356a95c1c11f659ac2e706d57d48a3", "version": 1, "digest": "EuZXXws+M+y1L/BdbUHiGgGtt4sQud0A5bYjbynLFV0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -24,7 +24,7 @@ "objectId": "0x0bb7abe79e65f28206759931b2cc00e0bab373f4", "version": 7, "digest": "Eyo4CLf/fH8EoGDazdaDbCXHFgVe/fckt9GJcP0pOjk=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -34,7 +34,7 @@ "objectId": "0x15a8506c8549848bad388e0597b0c147860e23db", "version": 3, "digest": "ooX070rATxGaOVSdFedfkQWoVGKjjcbrnGyCZq2XFAA=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -44,7 +44,7 @@ "objectId": "0x194691babfb1e7dbfe51c7f17dad24171e5d6898", "version": 0, "digest": "MQbwPbpR7YzZ/7gGZjOif9FsXkNExRZ5pP0Mmmrd3D4=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -54,7 +54,7 @@ "objectId": "0x1e481b2466d8fcd4a783559d792d685016c801a7", "version": 0, "digest": "dHVNzJ3SfNqjda3B7skq94MWAe3TbsguAh4cebzu4HQ=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -64,7 +64,7 @@ "objectId": "0x25a72b378e32cc672fe00fda4b8a80bb87392c7b", "version": 0, "digest": "h3RPgGe67dv1iILEvtCWeEOJ89iJRcasHzn59iJF6o0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -74,7 +74,7 @@ "objectId": "0x2ac3bc5478aea9ed3641b28d5568c03f39388e08", "version": 1, "digest": "VN3UdGWJI6QD5uZHxGK36sceNtJsayT4yS/Fqj8rBjk=", - "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::Hero::Hero", + "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::hero::Hero", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -84,7 +84,7 @@ "objectId": "0x40b391ee39f0b039e610c48f20607292c3fda257", "version": 0, "digest": "AD9RrY/7VmctiyuDv1Plm3eXGdk8kSZREl3rjf7Wx0A=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -94,7 +94,7 @@ "objectId": "0x42c70d8990458b92479c5221becbb5f9ebfaea18", "version": 1, "digest": "KTND2UTTFkWvRG4YWY9KksFov0unu2UxnIa0Ydt9SA0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -104,7 +104,7 @@ "objectId": "0x4340022dedcedb87be8309d243f22b1adb44916a", "version": 0, "digest": "9De7lVAARoTPiQYIVwCFdx5QWELARyxHq0Emh4UIM18=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -114,7 +114,7 @@ "objectId": "0x4439a2733ed1955d5aae1fec2110c8f7250bc228", "version": 0, "digest": "BxAdomdmB9Cb3ZZcQQzIRWAu+5wkyhRuyYdz9t5msnw=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -134,7 +134,7 @@ "objectId": "0x5276e0fc2d0408c219ecf49117359252ceb83428", "version": 0, "digest": "dx0u8/IUDR7qu91JoN5yxo3tk7NvsePa/pBMCAuJyQQ=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -144,7 +144,7 @@ "objectId": "0x56a68b0185d0a7b99617c69c68223b8cd3c3f385", "version": 1, "digest": "cKnHAqoVg+EluPmIA830wAlw4KNa5ji5hO4RYh4Vt9A=", - "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::Hero::GameAdmin", + "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::hero::GameAdmin", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -154,7 +154,7 @@ "objectId": "0x578c7569e2e5ab5eeae959e2b92912a5fb049ecf", "version": 0, "digest": "ubGRtO0Sm/td2xzeDuR4u1cWhx2YZC6VHW/pnbP0VaM=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -164,7 +164,7 @@ "objectId": "0x6652c6d2b7d1ef2adc89f59472005df2b77ba37e", "version": 0, "digest": "AYYjnZ4zH8spWAMnYypJkPS0BeXHIR78nUXi3QnkuC4=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -174,7 +174,7 @@ "objectId": "0x6d78662e453ec42fd136afc9ef0f4b2dacb6738c", "version": 0, "digest": "TT3gHmj4QB8LuFMc+Q3tdFSAW8iRFup9hliROpmgzC4=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -184,7 +184,7 @@ "objectId": "0x6df180c5838511ccbe1cb68e7a58e6f67f0f3548", "version": 1, "digest": "NCG+2E/zdVm4JMEmusIX83YhonBTOr2eyFFbWZZmBOg=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -194,7 +194,7 @@ "objectId": "0x7a108ed34027f62b51918362fbc821a36365cb1e", "version": 0, "digest": "aQqu+yNpJVcCGIv8+i4YlU0ywinipiTC/vhGeo8WpA0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -204,7 +204,7 @@ "objectId": "0x835efba9445ecc8f1e796413412efac1abc094de", "version": 0, "digest": "Q22hFjdaB4zCwm43J2f9+O39U9+a6/X6WZb5/S0+Vk0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -214,7 +214,7 @@ "objectId": "0x90c34d9e0a1a4ffed59588428350ca083a04ef58", "version": 0, "digest": "uq7DE++0QAG2+bKzTGn7bXUnwhJ2SE9K8mgFJDp1Q84=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -223,8 +223,13 @@ { "objectId": "0x95ab7c13f9219202a19787a8e5d40d8c38a7b0ad", "version": 0, +<<<<<<< HEAD + "digest": "7M72ZITIQdqdVAYiE6qOkX9rjC7WSl7ZGzuBCrSPb3U=", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +======= "digest": "ltOFRKirE6orIPs4y6l0RTu9WgeZTIDP9o8UgcS9G50=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +>>>>>>> main "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -233,8 +238,13 @@ { "objectId": "0x95c52ae8c2fa58469271b72d9699dc09155433eb", "version": 0, +<<<<<<< HEAD + "digest": "SFZV5pYMkgjXQffCKu21Nq9OhLcuiGR/0vZv6DexgG0=", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +======= "digest": "qZ88Euv5JikEsJimbmGEc0dLUQm442OxurnpYKTeXvI=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +>>>>>>> main "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -243,8 +253,13 @@ { "objectId": "0x981e3133b06cf19eb0aff388cc462d0f16bb8adc", "version": 0, +<<<<<<< HEAD + "digest": "S8mVAw2WHY1AP623m2Ryyu0Xpk9+k9qquxrKJhng1F4=", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +======= "digest": "q1yO3J/yq3G5EdrZOHCyPHn4M6Wm7zueP7GJQBVR4gg=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +>>>>>>> main "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -254,7 +269,7 @@ "objectId": "0x9b4c6bef0f011b7560b56eb71411ebc3050646db", "version": 0, "digest": "f97XbnmYBqZZK+w/Mlnygbl60++Kd6KUF2fp6tDsBkc=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -264,7 +279,7 @@ "objectId": "0xa032c9982b65acfa9f1a4d028e89c011fc195429", "version": 0, "digest": "QUobrATHrXHBePJE+FgBqgnTNwlLupX5uZygE2sqgVE=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -274,7 +289,7 @@ "objectId": "0xa1541766854bfa27eb2314daaf3f990293720a24", "version": 0, "digest": "NKO497dW5ZwAUalQW7BiI9URDLgB+IlRQI5oRcm24bg=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -284,7 +299,7 @@ "objectId": "0xabe967abdc144418ca2227f57338da1b317b8dca", "version": 0, "digest": "ZQhMvJnpBbYEFhm9RpnHzzdrJ2Fmt6cOCiN1gOck0LE=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -294,7 +309,7 @@ "objectId": "0xb983bdc1b20992d1f26818937103463980fab900", "version": 0, "digest": "OtoU9763TEoDQHFdpzybhWqu9twJ4blxEkk+PJ8c1n8=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -304,7 +319,7 @@ "objectId": "0xbe81468535c6e20f91e86511583114b3c552f005", "version": 0, "digest": "s/tIOuEAcWDQawVoNNl5WN95TeefzKx+mysPSZlNmEc=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -313,8 +328,23 @@ { "objectId": "0xc2fe61d367a9fd89d4ff78a53577cf8dcb44eec3", "version": 1, +<<<<<<< HEAD + "digest": "fhttcnj+FYjDchLgNzcZzb2dT6O10rjQjSZxCtYww0w=", + "type": "0x237966f94764a944512afde1acbad0511f5e4fa4::hero::GameAdmin", + "owner": { + "AddressOwner": "0x51372a6dcf5799e4c39f7cd6bc68e27bdc92728c" + }, + "previousTransaction": "LjFPo9XEryFjeWsC225LgxoisRpcwWeCNuGEPH/6F9Q=" + }, + { + "objectId": "0xc6970cd384a867d2085f14489ced1741b9034820", + "version": 0, + "digest": "Gb5h+Nmk4vMbS1M/niFiiRn5eZoMmxlUFoX9/JXA/gw=", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +======= "digest": "FZALvDlOYAuumIT6H7guyXL7lfA8yH70uUZVKCVDcPM=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +>>>>>>> main "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -324,7 +354,7 @@ "objectId": "0xc4fc0711edee273a9255754b698870cb1237a734", "version": 0, "digest": "mfYfJCxH6cVyf5lnWOJHnFiKTX8XkQ+b10dj3FRKAGw=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -333,8 +363,13 @@ { "objectId": "0xccd79c8b17cf7530aa8a31869bccbd98bff2e151", "version": 0, +<<<<<<< HEAD + "digest": "kKO40w6ha7ZHIX7+IopfMPCcKolEvSPVxl2kujptugg=", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +======= "digest": "4SyB7yYSkV/96SrGKTPFo6EHgXH6vYbA0LhsDp2/Wjk=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +>>>>>>> main "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -343,8 +378,13 @@ { "objectId": "0xcf7dec93e8f1e166d934d30e685bc87041ebabcb", "version": 0, +<<<<<<< HEAD + "digest": "2WXUR4FWJZj/paGvUI89NoopoHj7aoOPdKAukmmbiC0=", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +======= "digest": "clJ2nI7B4KrVZ4l1eAQe6rYBEZz0PkOzbWKDpMUQvtM=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", +>>>>>>> main "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -354,7 +394,7 @@ "objectId": "0xd2f9bfbb50336fe3078c275d10410d82ffd0de6e", "version": 0, "digest": "KqZauNozmFyS8/1U6gk+cCYqsg+Hbj/nlaZlsaQbL3k=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -364,7 +404,7 @@ "objectId": "0xdb32ba84935eca5222e0e81da4d2533a15d4aba4", "version": 0, "digest": "nG7a8eqkJjxjP8kQONiw0rvG3tURdj7gmpE/F0tvQSI=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -374,7 +414,7 @@ "objectId": "0xe23d2851a6deb1f7888e8269cb78e4918bd43924", "version": 0, "digest": "p1vAQLkYuGsYBu7bxsPA8SqWg2nLaImOczvFbUAhluE=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -384,7 +424,7 @@ "objectId": "0xe33ff25bdffba609a83a5327ee565af645eb019d", "version": 1, "digest": "/CXzljbZPnlaZVRO39h89t7gBsOT9/k/zmgbIFpgZG0=", - "type": "0x2::DevNetNFT::DevNetNFT", + "type": "0x2::devnet_nft::DevNetNFT", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -394,7 +434,7 @@ "objectId": "0xf73af09866934d69c73ab1c8d60692915766f8ae", "version": 1, "digest": "csTH85poW96NFZSlPt24V+Wv4VnUj1llLFoCT4lglq4=", - "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::SeaHero::SeaHeroAdmin", + "type": "0x92f1de78e9bbdfb7992ecc4c241a9b69a07aa33d::sea_hero::SeaHeroAdmin", "owner": { "AddressOwner": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122" }, @@ -406,7 +446,7 @@ "objectId": "0x05fc9d2da170c6ba1e74d40b3ae8ec277f66c95e", "version": 0, "digest": "vIG/ZwoV/wSOQeHLSc/1jvsIoaXvhpZVUvfE9CCTd1U=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -416,7 +456,7 @@ "objectId": "0x0a04032994420f2983f9319a98a9ee9772d1b9bd", "version": 0, "digest": "W7KZy9fRZbba9rdVm5k7UCQTEv/IT1KL/iFR0ojJFHs=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -426,7 +466,7 @@ "objectId": "0x0bb5a7af8c7d26e576ce4ad9f79679629d5f366c", "version": 0, "digest": "/rbWU4+Jfu+UqhirBk2RiK/6sQV5YBi1hSGqh+Ta+2Y=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -436,7 +476,7 @@ "objectId": "0x10eb39f450987eccd817d7aeb16bd742fd8bab33", "version": 0, "digest": "ZsGGnmGyvctN8hagjoPdgD/DxyOHFOa16rJFE2wccgg=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -446,7 +486,7 @@ "objectId": "0x1410452c4bab5b7660f740374b82535126e4960e", "version": 0, "digest": "M6BzHyy+nUcDV90ody00gV9F/3IzBOPk8eUZc0CGm08=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -456,7 +496,7 @@ "objectId": "0x14734dd43d566824d5f6c1681f937a38e6175c31", "version": 0, "digest": "4/Qasl9QEbd9BFjyy4sPHhxgzkQFOuGK2o+6upbg4os=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -466,7 +506,7 @@ "objectId": "0x155119615dd055660421530803c63975a1e76bd6", "version": 0, "digest": "OKhF79lyE7gA41pKFIqgGx38F2jXsJ/jJ0Ozvtsiirc=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -476,7 +516,7 @@ "objectId": "0x1d9a59f327accd213df89264893b0ce09ae8b785", "version": 0, "digest": "4Q0ULheVx9EU23pTpmaTp9o7auxv3Yw+hc84nE8sDgA=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -486,7 +526,7 @@ "objectId": "0x263a492a85d94fefded3bc6b7983210d37df0f1d", "version": 0, "digest": "fFWfCTgzncZsxrudidhnTwuEWbvpYYb4t02oeQn3HvA=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -496,7 +536,7 @@ "objectId": "0x2acbdf3faf5d887685d5e4e616ac28bc28e21250", "version": 0, "digest": "7nViCSnCM3PK7YJf377c+GLbNNiEHQ9dgXqhOIl5Ats=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -506,7 +546,7 @@ "objectId": "0x47e7f10ebe3a5200bfe906b45666acd4d7b12df6", "version": 0, "digest": "WAEU8vUn6bTyQV8KHsljMLyzqigq0R4XTCZI5eli+7c=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -516,7 +556,7 @@ "objectId": "0x54613e094b819f63dbaf1bbb6a4a34cdbbdcad30", "version": 0, "digest": "Wf8je9qYw0ihx2XU6+JEobOpvCgrFBtv1n6Nan66V58=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -526,7 +566,7 @@ "objectId": "0x569be3c5a85cf32ed11c21738efcdc1e915b4279", "version": 0, "digest": "7nugHF+e0okF9ckNYYAbGMWHq0UM5QLToPl+jDi0dFA=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -536,7 +576,7 @@ "objectId": "0x5d4e7e7ca845eb84e50e65b8f0e83c3a56ac8da6", "version": 0, "digest": "KwuHkpqgJ9+c75+ibC6zA7Ei8r5v6eLschJDYP5B3uA=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -546,7 +586,7 @@ "objectId": "0x610f8cf4ed012490e2dfedbb80da1ae4ba519761", "version": 0, "digest": "KBOcF4pCFxvZQR6W2YX5PfjiXZ+CPZNo64vBIsmVFdY=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -556,7 +596,7 @@ "objectId": "0x64cdbe9c38dd274f151b08970ac632fe5598ef63", "version": 0, "digest": "vrMvo/czzOPcqz/vcb0FKcR9YAe9DRL7EgiyR3f7vvg=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -566,7 +606,7 @@ "objectId": "0x6f55fea4af29aa3c2be4ae5812f48acca3d4d859", "version": 0, "digest": "TKACsxLT5/+YK0CZOcdblWl071ZCBAAmfAsFSXzXaSw=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -576,7 +616,7 @@ "objectId": "0x734b58e38e880192cbd4dbc11dae77a551216d09", "version": 0, "digest": "TZQJzyvmgkGUAoslDsQpbU7IU0+rQYs1D0ixYKjJG6A=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -586,7 +626,7 @@ "objectId": "0x7505ce9a7c84a5cb08fc21bfd5e0b6e0d0caf84e", "version": 0, "digest": "f2/DuGIvBOLI2drkwhoQmh/YZAkGleXd0rr4UvBxJWg=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -596,7 +636,7 @@ "objectId": "0x7de0d6fe053eff37533979e7bd8dd2a60eca88b1", "version": 0, "digest": "yVi7Dk2qFNH4TnaylcjYyOnLKIFjHdsyS42D0FmmXPU=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -606,7 +646,7 @@ "objectId": "0x82e3f435b89fe18d97ea2709ca37f8b90c1d02a1", "version": 0, "digest": "1U/pj9PEsuUr/2jgKg0QQKvD8Ycwx9UY5eO4FPEGeH4=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -616,7 +656,7 @@ "objectId": "0x861435a9991441db71ca42273d63625316fbfc9f", "version": 0, "digest": "IkcQhFRYUhV2NapqslgnKk83tFDZdrDHwMaQ7SN2i+0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -626,7 +666,7 @@ "objectId": "0x9618c322d97b4f5ea6fb92a2286edc48ef1e43b1", "version": 0, "digest": "Wx2MliAsE1dJVoK2L1AhaZofg3jMen7Fqc1xM0AsN4g=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -636,7 +676,7 @@ "objectId": "0x99a57490377c3839bf82a5d28c7f3be51211e46d", "version": 0, "digest": "KIj63MK5QJgkcEgHAfBZQ8eOpvYkZQCXati60zc/CP0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -646,7 +686,7 @@ "objectId": "0xa4bc2644817f6ed53301f4d74fe21092eae8b141", "version": 0, "digest": "LWVIJAStOQdtW0zU0r85UOrHFrdUrh2WE1SKJENnQkc=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -656,7 +696,7 @@ "objectId": "0xa5e57e593a570799782b93932f783ee2e56b7499", "version": 0, "digest": "HIcHPqktnO+jA7Nvl4noPwe6fRfJCgnUsLxEHC862oQ=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -666,7 +706,7 @@ "objectId": "0xb0f5eda0c14fa1e278f57091034f9a2a0c801b28", "version": 0, "digest": "gWyyYAuY+3pualUYEc1DC08c16BhRqaC4I068UhfUdI=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -676,7 +716,7 @@ "objectId": "0xb47af42d7e36fecda98f9438e043d604c4260cb4", "version": 0, "digest": "19abB1TiUiEIeaOF8PCzF8hoXJEGrAWqzavGI5Zi83I=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -686,7 +726,7 @@ "objectId": "0xb7ee33d0e00102ee127a95b926003b2e8c2d2ac8", "version": 0, "digest": "ya2BW6rlHiz5dd9lXzpVrgU9vZdqjrbZdBCRdQz7l5g=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -696,7 +736,7 @@ "objectId": "0xf8aa24d3b21b76ba799f853df52946d8475cc501", "version": 0, "digest": "QEHpn5BD184oI0N8NwpwGzy6ewQXfxg9+qj2YMok88M=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0x471289fb50813d41e5e36c7c237ab88df2c6ee4e" }, @@ -708,7 +748,7 @@ "objectId": "0x05fdd762b1765120c19e3f0f69b2cc64c614d559", "version": 0, "digest": "rEfbmhZVss2S3gEoxzwW085Ot6dKWeQtBMCu3+ZS6Og=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -718,7 +758,7 @@ "objectId": "0x12d1528691cd154d8a22de843f22c243ff0a7a79", "version": 0, "digest": "1E+1SBC6wFe2Sws+Q0A8sY/WwEIT+Wx/AZyH1TN4zzc=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -728,7 +768,7 @@ "objectId": "0x1469e6327df93b1616e9a70bddf79d7aea47d79d", "version": 0, "digest": "TTpFNUG4F2iowU4xkN2ocCQuX7P9IKU38P+zZGguI+Y=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -738,7 +778,7 @@ "objectId": "0x1f729f924b892964ece6e28c7d29e5c6ac5f043a", "version": 0, "digest": "eCJe2LXzgTG1IXCgkLjCybCRhVBRButCoWTtRr4z7aY=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -748,7 +788,7 @@ "objectId": "0x3c6a680f5f4cf3140609d9f1566092479c31b0d9", "version": 0, "digest": "eCebgQvMRyeYSNNOLohiy05kq39K/UTJ64luFPV7zYs=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -758,7 +798,7 @@ "objectId": "0x46730f9ff247c33b985352c18c1ff1f038d473a0", "version": 0, "digest": "nGuoLGr4RrDLQ1kdvwJgkdShlatfxgcBk1kHRuX/N+s=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -768,7 +808,7 @@ "objectId": "0x486ef898d580004dfa8de28db7cbfd64c4d53456", "version": 0, "digest": "QL5Oz7ZCyC2erX7HBc3EcahMOb0nhv1egldaij9tv4E=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -778,7 +818,7 @@ "objectId": "0x59c09cb6156a3206ce97fd713efae1e7ce285ce6", "version": 0, "digest": "PIUSTWGfp2EQ89bVu65CxWZ2RPwS5g5XKpk4cauwL/c=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -788,7 +828,7 @@ "objectId": "0x5fd753049758bbe02528fc058503529b81e8522b", "version": 0, "digest": "1UQgfqrg4qfgiF7nY3gdjs1CiyrX8r4Ess//0QiAZv4=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -798,7 +838,7 @@ "objectId": "0x656d86ddd11cc8c149b2397e114af751b7e88843", "version": 0, "digest": "pY70FwcK9N++yyBqYtajzlZ2Mi/NtNFZEDsEbe6UU1M=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -808,7 +848,7 @@ "objectId": "0x70b2ed9165380d19445fa4ef074e5429393d2360", "version": 0, "digest": "/2mjDlQLfjvsXJtSbDDdNMDCyNoBMi16jzrUVuFVd2U=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -818,7 +858,7 @@ "objectId": "0x79f76b8b60fdb142f33b1bc8baa94209b9bffc05", "version": 0, "digest": "t5EDBuZmlrHSYnyozqNDsXHZMBGrOiAKy/74F/EcQxk=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -828,7 +868,7 @@ "objectId": "0x953f43170e3f6cf531c914623f9cc7938a60e886", "version": 0, "digest": "ZfJCtmf8bcHr4idwR1rI8+ozkItgYOO6os5t0MVl32o=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -838,7 +878,7 @@ "objectId": "0x9bf4414b349a37d007f77c47da7fbc7f002ce722", "version": 0, "digest": "pByAHtg6ICQGTP80QXsaro2rJI8IWSL+M6sKqUEiarQ=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -848,7 +888,7 @@ "objectId": "0xa03214c4b8deba5bddc801c5750f14b1afefcbb3", "version": 0, "digest": "yDcbRS5WEGbAZ0Kk06s+hsK/jVoIHpYboSQAx09rFks=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -858,7 +898,7 @@ "objectId": "0xa1f33d0c36c25fb00cd7c32823388b5aefbf7acf", "version": 0, "digest": "Xsj3xQviDufjitC9V+Hcdj6XtwY30V+BeFAVujOGQwo=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -868,7 +908,7 @@ "objectId": "0xa5df7ccfb982fae43c1511a8b7e37d5a79e595e8", "version": 0, "digest": "hDHTxNTZhYE9sDgyrAaN/0gZgGUZCCH9Ux8DfEUmTyo=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -878,7 +918,7 @@ "objectId": "0xa7a6847c1e10af2031fe6374c22672d1e06b15ca", "version": 0, "digest": "hUY6b+JEU9im7TFdNpCU/aQuOotd8azAQDoo/iX3SJE=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -888,7 +928,7 @@ "objectId": "0xb0ad7c1ac5ef4506f3742ca66613a586ba59d101", "version": 0, "digest": "tCYbLdcfmDPmhoqYqanD/xSl5qcHlj9dZYBc1ly/dP8=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -898,7 +938,7 @@ "objectId": "0xb9bb828e8e8348400c5ee8e18a291dd92aeaae13", "version": 0, "digest": "9tcb6OHZ1QaPModlQPhOof8gWRdUV6wJTqwEd8Aa55I=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -908,7 +948,7 @@ "objectId": "0xbcf88219ae5e3dc8083d84a9a0dc754de67b06cc", "version": 0, "digest": "6KWBXREeezCTwMBYvdu3yjvXqUhuhFVymAELJDUszR0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -918,7 +958,7 @@ "objectId": "0xbe418c03dd74fe7d425116fda2c09e0ac00aebb7", "version": 0, "digest": "RUz4h5XXnMM5Ea/Ijb5dxxbrefiT2h8l7yBJSW1ZVJk=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -928,7 +968,7 @@ "objectId": "0xd006df2a3a27ab0e4b4a49473275d13380712509", "version": 0, "digest": "LVV3zBku3qfvQy7gHt3kpNDQS38cilNypoHbzxOJd7c=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -938,7 +978,7 @@ "objectId": "0xd096a44f3174603bc1a58a87b0257d3734e729d5", "version": 0, "digest": "P2EQ46u2WJd4fZbzn7g/HTSoBClDZ4Hz7rPjVyffvrE=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -948,7 +988,7 @@ "objectId": "0xd0e40ca323258a391c8d2584393d71473000b062", "version": 0, "digest": "FtkHAcGXk8O8pAMWCNoVraH/GDVBK3Vlpr9tNcUX4kM=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -958,7 +998,7 @@ "objectId": "0xd27fb69df5d0064731b928b456e4f6ae0ed7042f", "version": 0, "digest": "5v04Y67AmcDdPByJf2a2IZTBJC98V8pajHBS2K+pXak=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -968,7 +1008,7 @@ "objectId": "0xe102bd246aa56e469f98689bb3cb64ceab6e85cb", "version": 0, "digest": "cbP8dLnd5FsVJg6b/FWjj3/14P75CcEXFvivTSRiElE=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -978,7 +1018,7 @@ "objectId": "0xe5565456f47bf291833eea8a7b1cb65d97cf5f5f", "version": 0, "digest": "StYmm+zWjelVxAOqkDcoQ9inUJYMiApVSGHWxO0GW88=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -988,7 +1028,7 @@ "objectId": "0xeb0df1266e7771c99eef1315ce205a893ff35a8a", "version": 0, "digest": "dXb3PXBEPqRbRJEQjV09epOGqGpDn05vydEIMHuOu+Q=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -998,7 +1038,7 @@ "objectId": "0xef8483af1eae5a8b9b5c128d20e2fce757ec0837", "version": 0, "digest": "AE2DFRqAofqNndMsTHsEkfRASox4y3qAaFQiPEX4kCY=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xab3c524078957eb666ab374b6f6cec17910abf78" }, @@ -1010,7 +1050,7 @@ "objectId": "0x0eb6c98099a0e4ba1326ebe3d7b6bf1d99496025", "version": 0, "digest": "02gaJnoZLJI/Kv4jSvQqzo3Vpbftjn/IHk5o7DabtTQ=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1020,7 +1060,7 @@ "objectId": "0x0f5cc220b07015380144f56a5f90aa6a3c714c82", "version": 0, "digest": "wdVz6NkmmhbmKnJ3Ig265i9+JQYwdZw6L++mXD6SwWM=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1030,7 +1070,7 @@ "objectId": "0x10f7c420fa2eef2dabedf2200321b76155a94a8c", "version": 0, "digest": "icWh6meMZ35qJnComm+2a0i0B26ewAnW9oaVloyVfFE=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1040,7 +1080,7 @@ "objectId": "0x177ff5cb7162fcb5d3c8567909032e08e36934a8", "version": 0, "digest": "hkwvym+/qs519d0vTXf49azp0nr+kbojw9iKHPLNvgQ=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1050,7 +1090,7 @@ "objectId": "0x1a052bc3cb6bd58b363b0ac544b8cd345aa24e6c", "version": 0, "digest": "4wN6EgHTZVWXHubjLy5DBYhYc89S+7sgVFxTIuIAhOw=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1060,7 +1100,7 @@ "objectId": "0x3868648b0073d70f1b0a0c0845345efe41c10093", "version": 0, "digest": "7Us0h0h0AiaANbxIMV0tGEcXNxhr8cA7SxrkC7ycO8s=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1070,7 +1110,7 @@ "objectId": "0x3cdff70daf71be23abdea24bc1f4ed55bcfd020a", "version": 0, "digest": "aq2gYYI+T9VH5PsGyC87tItOdnMCv+XkTkoYqGucmyM=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1080,7 +1120,7 @@ "objectId": "0x3e5e3da7f3fbe0cafaa20dead1091b558687396e", "version": 0, "digest": "lEuJodVcWuFduGFTLsHnaED5SFqChCFJu4Jgz3u/b9Q=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1090,7 +1130,7 @@ "objectId": "0x459efdfe31cccee66b6fe14c05686924bf0f87ee", "version": 0, "digest": "Tx1ekG5tWQNJNmcMfFi9wHAt2XgIT6vqCAs93XHcrNY=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1100,7 +1140,7 @@ "objectId": "0x460604c55edb09025e9c3ddf0f4aca283286161f", "version": 0, "digest": "NNfjoZrqH1YeZWf98cc4fJcAlirUWJN1ZFpeBBHk32A=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1110,7 +1150,7 @@ "objectId": "0x4a6ac16b35e8fd78ec1107090a0f2f0db8e7e05b", "version": 0, "digest": "1/cMPx/OwI83SNYSEYfaH+rZFndmVHQNaMFhF4D6YZI=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1120,7 +1160,7 @@ "objectId": "0x567f18c020135437dcd956bdb69bc93dd03b998c", "version": 0, "digest": "jVhc7n3XQCP8SvSiOiBKR9bI1amqi7aKZdt7+SiXF7s=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1130,7 +1170,7 @@ "objectId": "0x647121e47732e11d487db64ed7a351ee57c15436", "version": 0, "digest": "PTyTZMJkon7we8NAxVVWG/Md/wZn1ro9xpb8Co6rKME=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1140,7 +1180,7 @@ "objectId": "0x6c405dcc8b75dc639325e1d20e457e28abbd8817", "version": 0, "digest": "OJpHowvJKI/l04uPyhPLixMZB/KB5mdplPDiRDB5GUs=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1150,7 +1190,7 @@ "objectId": "0x705448f70e8183399a3cdf7046e2cb6b5e33102f", "version": 0, "digest": "XC346u760bywbEq4vver2xq0fBC2j0r0dUYg2nLJ6YA=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1160,7 +1200,7 @@ "objectId": "0x7a16586ca3aae19c147f2248f03ac3b3e904da15", "version": 0, "digest": "a3XJJLy43izlDVl3XZdfYW8SwO4pqOc4H89ln0PfK2g=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1170,7 +1210,7 @@ "objectId": "0x7b1687406ee5db299082b2dff8436bfcaf621183", "version": 0, "digest": "RPEBLp3Fe/JUeRI0hvgzD5CZ515gZ77K+5OBbsjYn+U=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1180,7 +1220,7 @@ "objectId": "0x82e6f4ede7d188398b8fbf79a64ec561d79cdae0", "version": 0, "digest": "YccFAyOwQh04Wp6EWsXX9fDn+zo8tFcJalHvXW9YpHU=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1190,7 +1230,7 @@ "objectId": "0x8a06a2091e4cc75bbf4308b59ef07652562edecb", "version": 0, "digest": "e0qwto0M7VfLYvTiYt4C8U2VkPp7uH1NIZ/6hFHlcnw=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1200,7 +1240,7 @@ "objectId": "0x9445352c804fe7ef8d5a6edc2f7a8252c17938a7", "version": 0, "digest": "KruixbxndWtflRnmV3jXOFuf6SAPfWp+v7lQPwC7GFk=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1210,7 +1250,7 @@ "objectId": "0x983efa825cfe3670eb7fb2ccf6bf6f9b1efc7b84", "version": 0, "digest": "SLODbffQx6VrDYHruYzplsRFlwz1/vqk/jBw0PMOWe0=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1220,7 +1260,7 @@ "objectId": "0x99b391d835a93adfda5327ffad76a25ea3702920", "version": 0, "digest": "8Bt0jQB4OLddMYnehKrP/+0cqWjR2oasnbYSwRY7Pnw=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1230,7 +1270,7 @@ "objectId": "0x9c82a1320722d1fb1fff65bf984edfa0280a04a7", "version": 0, "digest": "g/qSxWV32gt041moTTQRng6EKnu1VZMWxFN2Qds/aoA=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1240,7 +1280,7 @@ "objectId": "0xaebee2d9610b5a5902ab0dbedaa1f205ab0991f4", "version": 0, "digest": "7UetTteWwT+G8o9XDyJXeqfe/Fjs1hOVEgzIlFcrQJ4=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1250,7 +1290,7 @@ "objectId": "0xc752a96533c360270f0dd53eab64ff23d6b609c0", "version": 0, "digest": "mCU0Z6G6/K6Wwv/6ZqoO9j+aHvuJB2uuT5lFUu2iHTM=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1260,7 +1300,7 @@ "objectId": "0xc991961e647f79c21e084e45e8a6d903cdb6bbb3", "version": 0, "digest": "xm4Rwo3Z2amrk3i4BXnERINSjzfkxOcIDc0FXsb8f/s=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1270,7 +1310,7 @@ "objectId": "0xe0e02fd03727137718a505a25351c2777c822cf8", "version": 0, "digest": "fyUNLCRT+4lIPqkXAH4A6dmw5G0zbD8VY4UlMVeXqFo=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1280,7 +1320,7 @@ "objectId": "0xe354e5c2fb73d427c321b51bbda1851fceed5e9a", "version": 0, "digest": "c7IwuL3LIB3SLr3Kzm5+HjR0Nvzkeo4A26mBVdBnnx8=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1290,7 +1330,7 @@ "objectId": "0xecee480ad45dd1cf035e64ee11f87107c920cfaa", "version": 0, "digest": "sKDSl9RCAWQLiQNfVcIa/ScROOXydCISMwAn1KzGAOA=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, @@ -1300,7 +1340,7 @@ "objectId": "0xed160eda8f07840b124b030e8a8b259480847cea", "version": 0, "digest": "vIo9Ub1/Tf0bBaP/ezEZNhXEVf22PilZEc2UqLkVlHE=", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "owner": { "AddressOwner": "0xb50d1074b335ee268344b1b54096e5692a68c20f" }, diff --git a/crates/sui-open-rpc/samples/transactions.json b/crates/sui-open-rpc/samples/transactions.json index 1d01909c54977..4e30fadc73519 100644 --- a/crates/sui-open-rpc/samples/transactions.json +++ b/crates/sui-open-rpc/samples/transactions.json @@ -12,7 +12,7 @@ "version": 1, "digest": "aWgI94W3rJkcG74fwSfZmmd+XKuueGL9ulSCeVW0kD0=" }, - "module": "DevNetNFT", + "module": "devnet_nft", "function": "mint", "arguments": [ "Example NFT", @@ -96,7 +96,7 @@ "events": [ { "moveEvent": { - "type": "0x2::DevNetNFT::MintNFTEvent", + "type": "0x2::devnet_nft::MintNFTEvent", "fields": { "creator": "0x08177f0d3cb878f43ed6f6d1990629b0ce3d3122", "name": "Example NFT", @@ -229,10 +229,10 @@ "version": 1, "digest": "aWgI94W3rJkcG74fwSfZmmd+XKuueGL9ulSCeVW0kD0=" }, - "module": "Coin", + "module": "coin", "function": "split_vec", "typeArguments": [ - "0x2::SUI::SUI" + "0x2::sui::SUI" ], "arguments": [ "0xbb7abe79e65f28206759931b2cc00e0bab373f4", @@ -277,7 +277,7 @@ "updatedCoin": { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 95582, "id": { @@ -301,7 +301,7 @@ { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 20, "id": { @@ -324,7 +324,7 @@ { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 20, "id": { @@ -347,7 +347,7 @@ { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 20, "id": { @@ -370,7 +370,7 @@ { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 20, "id": { @@ -393,7 +393,7 @@ { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 20, "id": { @@ -417,7 +417,7 @@ "updatedGas": { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 98935, "id": { @@ -513,7 +513,7 @@ "updatedGas": { "data": { "dataType": "moveObject", - "type": "0x2::Coin::Coin<0x2::SUI::SUI>", + "type": "0x2::coin::Coin<0x2::sui::SUI>", "fields": { "balance": 98686, "id": { diff --git a/crates/sui-transactional-test-runner/src/test_adapter.rs b/crates/sui-transactional-test-runner/src/test_adapter.rs index 4d5272824ed83..817be118e7fb2 100644 --- a/crates/sui-transactional-test-runner/src/test_adapter.rs +++ b/crates/sui-transactional-test-runner/src/test_adapter.rs @@ -137,7 +137,7 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter<'a> { (n.clone(), addr) })); for (name, addr) in additional_mapping { - if named_address_mapping.contains_key(&name) || name == "Sui" { + if named_address_mapping.contains_key(&name) || name == "sui" { panic!("Invalid init. The named address '{}' is reserved", name) } named_address_mapping.insert(name, addr); @@ -688,7 +688,7 @@ static NAMED_ADDRESSES: Lazy> = Lazy::new(|| assert!(map.get("std").unwrap().into_inner() == MOVE_STDLIB_ADDRESS); // TODO fix Sui framework constants map.insert( - "Sui".to_string(), + "sui".to_string(), NumericalAddress::new( SUI_FRAMEWORK_ADDRESS.into_bytes(), move_compiler::shared::NumberFormat::Hex, diff --git a/crates/sui-types/src/balance.rs b/crates/sui-types/src/balance.rs index a80c0780e4b54..48c49630073b5 100644 --- a/crates/sui-types/src/balance.rs +++ b/crates/sui-types/src/balance.rs @@ -10,8 +10,8 @@ use move_core_types::value::{MoveFieldLayout, MoveStructLayout, MoveTypeLayout}; use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; -pub const BALANCE_MODULE_NAME: &IdentStr = ident_str!("Balance"); -pub const BALANCE_STRUCT_NAME: &IdentStr = BALANCE_MODULE_NAME; +pub const BALANCE_MODULE_NAME: &IdentStr = ident_str!("balance"); +pub const BALANCE_STRUCT_NAME: &IdentStr = ident_str!("Balance"); #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, Eq, PartialEq)] pub struct Balance { @@ -26,8 +26,8 @@ impl Balance { pub fn type_(type_param: StructTag) -> StructTag { StructTag { address: SUI_FRAMEWORK_ADDRESS, - name: BALANCE_STRUCT_NAME.to_owned(), module: BALANCE_MODULE_NAME.to_owned(), + name: BALANCE_STRUCT_NAME.to_owned(), type_params: vec![TypeTag::Struct(type_param)], } } diff --git a/crates/sui-types/src/base_types.rs b/crates/sui-types/src/base_types.rs index 481f9d86ec2e0..73aa95a447e58 100644 --- a/crates/sui-types/src/base_types.rs +++ b/crates/sui-types/src/base_types.rs @@ -295,8 +295,8 @@ impl IntoPoint for ExecutionDigests { pub const STD_OPTION_MODULE_NAME: &IdentStr = ident_str!("option"); pub const STD_OPTION_STRUCT_NAME: &IdentStr = ident_str!("Option"); -pub const TX_CONTEXT_MODULE_NAME: &IdentStr = ident_str!("TxContext"); -pub const TX_CONTEXT_STRUCT_NAME: &IdentStr = TX_CONTEXT_MODULE_NAME; +pub const TX_CONTEXT_MODULE_NAME: &IdentStr = ident_str!("tx_context"); +pub const TX_CONTEXT_STRUCT_NAME: &IdentStr = ident_str!("TxContext"); #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub struct TxContext { diff --git a/crates/sui-types/src/coin.rs b/crates/sui-types/src/coin.rs index a771c34b3342c..3f03e239ab417 100644 --- a/crates/sui-types/src/coin.rs +++ b/crates/sui-types/src/coin.rs @@ -17,12 +17,12 @@ use crate::{ }; use schemars::JsonSchema; -pub const COIN_MODULE_NAME: &IdentStr = ident_str!("Coin"); -pub const COIN_STRUCT_NAME: &IdentStr = COIN_MODULE_NAME; +pub const COIN_MODULE_NAME: &IdentStr = ident_str!("coin"); +pub const COIN_STRUCT_NAME: &IdentStr = ident_str!("Coin"); pub const COIN_JOIN_FUNC_NAME: &IdentStr = ident_str!("join"); pub const COIN_SPLIT_VEC_FUNC_NAME: &IdentStr = ident_str!("split_vec"); -// Rust version of the Move Sui::Coin::Coin type +// Rust version of the Move sui::coin::Coin type #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, Eq, PartialEq)] pub struct Coin { pub id: VersionedID, @@ -79,7 +79,7 @@ impl Coin { } } -// Rust version of the Move Sui::Coin::TreasuryCap type +// Rust version of the Move sui::coin::TreasuryCap type #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] pub struct TreasuryCap { pub id: VersionedID, diff --git a/crates/sui-types/src/gas_coin.rs b/crates/sui-types/src/gas_coin.rs index 1b53b333edbd9..a91b7c9c6f66b 100644 --- a/crates/sui-types/src/gas_coin.rs +++ b/crates/sui-types/src/gas_coin.rs @@ -20,8 +20,8 @@ use crate::{ SUI_FRAMEWORK_ADDRESS, }; -pub const GAS_MODULE_NAME: &IdentStr = ident_str!("SUI"); -pub const GAS_STRUCT_NAME: &IdentStr = GAS_MODULE_NAME; +pub const GAS_MODULE_NAME: &IdentStr = ident_str!("sui"); +pub const GAS_STRUCT_NAME: &IdentStr = ident_str!("SUI"); pub struct GAS {} impl GAS { @@ -39,7 +39,7 @@ impl GAS { } } -/// Rust version of the Move Sui::Coin::Coin type +/// Rust version of the Move sui::coin::Coin type #[derive(Debug, Serialize, Deserialize)] pub struct GasCoin(pub Coin); diff --git a/crates/sui-types/src/id.rs b/crates/sui-types/src/id.rs index b4dc188b3cc00..66e81ca0ceeda 100644 --- a/crates/sui-types/src/id.rs +++ b/crates/sui-types/src/id.rs @@ -14,26 +14,26 @@ use move_core_types::{ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -pub const ID_MODULE_NAME: &IdentStr = ident_str!("ID"); +pub const ID_MODULE_NAME: &IdentStr = ident_str!("id"); pub const VERSIONED_ID_STRUCT_NAME: &IdentStr = ident_str!("VersionedID"); pub const UNIQUE_ID_STRUCT_NAME: &IdentStr = ident_str!("UniqueID"); -pub const ID_STRUCT_NAME: &IdentStr = ID_MODULE_NAME; +pub const ID_STRUCT_NAME: &IdentStr = ident_str!("ID"); -/// Rust version of the Move Sui::ID::VersionedID type +/// Rust version of the Move sui::id::VersionedID type #[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, Eq, PartialEq)] pub struct VersionedID { pub id: UniqueID, pub version: u64, } -/// Rust version of the Move Sui::ID::UniqueID type +/// Rust version of the Move sui::id::UniqueID type #[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, Eq, PartialEq)] #[serde(transparent)] pub struct UniqueID { pub id: ID, } -/// Rust version of the Move Sui::ID::ID type +/// Rust version of the Move sui::id::ID type #[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, Eq, PartialEq)] #[serde(transparent)] pub struct ID { @@ -53,8 +53,8 @@ impl VersionedID { pub fn type_() -> StructTag { StructTag { address: SUI_FRAMEWORK_ADDRESS, - name: VERSIONED_ID_STRUCT_NAME.to_owned(), module: ID_MODULE_NAME.to_owned(), + name: VERSIONED_ID_STRUCT_NAME.to_owned(), type_params: Vec::new(), } } @@ -89,8 +89,8 @@ impl UniqueID { pub fn type_() -> StructTag { StructTag { address: SUI_FRAMEWORK_ADDRESS, - name: UNIQUE_ID_STRUCT_NAME.to_owned(), module: ID_MODULE_NAME.to_owned(), + name: UNIQUE_ID_STRUCT_NAME.to_owned(), type_params: Vec::new(), } } @@ -110,8 +110,8 @@ impl ID { pub fn type_() -> StructTag { StructTag { address: SUI_FRAMEWORK_ADDRESS, - name: ID_STRUCT_NAME.to_owned(), module: ID_MODULE_NAME.to_owned(), + name: ID_STRUCT_NAME.to_owned(), type_params: Vec::new(), } } diff --git a/crates/sui-types/src/sui_system_state.rs b/crates/sui-types/src/sui_system_state.rs index 38c6dddf62a75..108416bc38c7e 100644 --- a/crates/sui-types/src/sui_system_state.rs +++ b/crates/sui-types/src/sui_system_state.rs @@ -9,10 +9,10 @@ use serde::{Deserialize, Serialize}; use crate::{balance::Balance, coin::TreasuryCap, id::VersionedID, SUI_FRAMEWORK_ADDRESS}; const SUI_SYSTEM_STATE_STRUCT_NAME: &IdentStr = ident_str!("SuiSystemState"); -pub const SUI_SYSTEM_MODULE_NAME: &IdentStr = ident_str!("SuiSystem"); +pub const SUI_SYSTEM_MODULE_NAME: &IdentStr = ident_str!("sui_system"); pub const ADVANCE_EPOCH_FUNCTION_NAME: &IdentStr = ident_str!("advance_epoch"); -/// Rust version of the Move Sui::SuiSystem::SystemParameters type +/// Rust version of the Move sui::sui_system::SystemParameters type #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] pub struct SystemParameters { pub min_validator_stake: u64, @@ -35,7 +35,7 @@ pub struct ValidatorMetadata { pub next_epoch_stake: u64, } -/// Rust version of the Move Sui::Validator::Validator type +/// Rust version of the Move sui::validator::Validator type #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] pub struct Validator { pub metadata: ValidatorMetadata, @@ -50,7 +50,7 @@ pub struct Validator { pub pending_delegator_withdraw_count: u64, } -/// Rust version of the Move Sui::ValidatorSet::ValidatorSet type +/// Rust version of the Move sui::validator_set::ValidatorSet type #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] pub struct ValidatorSet { pub validator_stake: u64, @@ -62,7 +62,7 @@ pub struct ValidatorSet { pub next_epoch_validators: Vec, } -/// Rust version of the Move Sui::SuiSystem::SuiSystemState type +/// Rust version of the Move sui::sui_system::SuiSystemState type #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] pub struct SuiSystemState { pub id: VersionedID, diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_and_generic_object_params.exp b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_and_generic_object_params.exp index a9d54aa84f3ee..9f33cc21b36c1 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_and_generic_object_params.exp +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_and_generic_object_params.exp @@ -1,5 +1,4 @@ processed 1 task task 0 'publish'. lines 4-16: -created: object(103) -written: object(102) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_and_generic_object_params.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_and_generic_object_params.mvir index 3180c3b7b2339..662b7df8c5a9b 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_and_generic_object_params.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_and_generic_object_params.mvir @@ -4,11 +4,11 @@ //# publish module 0x0.M { import 0x2.ID; - import 0x2.TxContext; + import 0x2.tx_context; struct Obj has key { id: ID.VersionedID, } - public entry foo(l0: T0, l1: Self.Obj, c: &mut TxContext.TxContext) { + public entry foo(l0: T0, l1: Self.Obj, c: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_param_after_primitive.exp b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_param_after_primitive.exp index a9d54aa84f3ee..9f33cc21b36c1 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_param_after_primitive.exp +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_param_after_primitive.exp @@ -1,5 +1,4 @@ processed 1 task task 0 'publish'. lines 4-16: -created: object(103) -written: object(102) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_param_after_primitive.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_param_after_primitive.mvir index 1627873f21b90..c7ef7e3562fa5 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_param_after_primitive.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_param_after_primitive.mvir @@ -4,11 +4,11 @@ //# publish module 0x0.M { import 0x2.ID; - import 0x2.TxContext; + import 0x2.tx_context; struct Obj has key { id: ID.VersionedID, } - public entry foo(l0: Self.Obj, l1: u64, l2: T, ctx: &mut TxContext.TxContext) { + public entry foo(l0: Self.Obj, l1: u64, l2: T, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_with_key_invalid.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_with_key_invalid.mvir index c2ba8ffdb4575..9591dbdfacfcd 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_with_key_invalid.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_with_key_invalid.mvir @@ -5,10 +5,10 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x1.option; - public entry no(l0: option.Option, ctx: &mut TxContext.TxContext) { + public entry no(l0: option.Option, ctx: &mut tx_context.TxContext) { label l0: abort 0; } @@ -17,10 +17,10 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x1.option; - public entry no(l0: vector>, ctx: &mut TxContext.TxContext) { + public entry no(l0: vector>, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_with_key_valid.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_with_key_valid.mvir index 783fdb31d5cb7..75b01f0326002 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/generic_with_key_valid.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/generic_with_key_valid.mvir @@ -5,10 +5,10 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x1.option; - public entry yes(l0: T, l1: &T, l2: &mut T, ctx: &mut TxContext.TxContext) { + public entry yes(l0: T, l1: &T, l2: &mut T, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/id.exp b/crates/sui-verifier-transactional-tests/tests/entry_points/id.exp index aef711dcb0cff..f5b7b0c84acf0 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/id.exp +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/id.exp @@ -1,5 +1,4 @@ processed 1 task task 0 'publish'. lines 6-21: -created: object(103) -written: object(102) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/id.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/id.mvir index 1f55639b64633..a7e224bee5628 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/id.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/id.mvir @@ -5,14 +5,14 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x2.ID; public entry yes( l0: ID.ID, l1: vector, l2: vector>, - ctx: &mut TxContext.TxContext, + ctx: &mut tx_context.TxContext, ) { label l0: abort 0; diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/nested_generic_vector_param.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/nested_generic_vector_param.mvir index 265e7ca4882bc..aa11e545a01e2 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/nested_generic_vector_param.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/nested_generic_vector_param.mvir @@ -3,9 +3,9 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; - public entry foo(l: vector>, ctx: &mut TxContext.TxContext) { + public entry foo(l: vector>, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/nested_key_generic_vector_param.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/nested_key_generic_vector_param.mvir index 55b43e3003f0b..11074571f7a83 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/nested_key_generic_vector_param.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/nested_key_generic_vector_param.mvir @@ -3,9 +3,9 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; - public entry foo(l: vector>, ctx: &mut TxContext.TxContext) { + public entry foo(l: vector>, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct.mvir index b0332e88fc88a..b005f3df5d821 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct.mvir @@ -5,11 +5,11 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; struct S has copy, drop, store { value: u64 } - public entry no(s: Self.S, ctx: &mut TxContext.TxContext) { + public entry no(s: Self.S, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic.exp b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic.exp index 64ca919cb7bb9..1b7a7a4016966 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic.exp +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic.exp @@ -1,7 +1,7 @@ processed 2 tasks task 0 'publish'. lines 6-21: -Error: Failed to verify the Move module, reason: "Invalid entry point parameter type. Expected primitive or object type. Got: _::M::Obj<_::M::NoStore>". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID task 1 'publish'. lines 23-35: -Error: Failed to verify the Move module, reason: "Invalid entry point parameter type. Expected primitive or object type. Got: _::M::Obj". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic.mvir index c34cca4aba1df..a0be4278fd3a7 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic.mvir @@ -5,13 +5,13 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x2.ID; struct Obj has key { id: ID.VersionedID } struct NoStore has copy, drop { value: u64 } - public entry no(s: Self.Obj, ctx: &mut TxContext.TxContext) { + public entry no(s: Self.Obj, ctx: &mut tx_context.TxContext) { label l0: abort 0; } @@ -22,12 +22,12 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x2.ID; struct Obj has key { id: ID.VersionedID } - public entry no(s: Self.Obj, ctx: &mut TxContext.TxContext) { + public entry no(s: Self.Obj, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic_valid.exp b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic_valid.exp index d7ee4600d039b..a372cd36c56fa 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic_valid.exp +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic_valid.exp @@ -1,5 +1,4 @@ processed 1 task task 0 'publish'. lines 6-18: -created: object(103) -written: object(102) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic_valid.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic_valid.mvir index dab38c2df70f6..495a5e96aec63 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic_valid.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_generic_valid.mvir @@ -5,12 +5,12 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x2.ID; struct Obj has key { id: ID.VersionedID } - public entry no(s: Self.Obj, ctx: &mut TxContext.TxContext) { + public entry no(s: Self.Obj, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_vector.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_vector.mvir index adb7509491000..0c12eb207262f 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_vector.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/non_key_struct_vector.mvir @@ -5,11 +5,11 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; struct S has copy, drop, store { value: u64 } - public entry no(s: vector, ctx: &mut TxContext.TxContext) { + public entry no(s: vector, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/option.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/option.mvir index 470f19d76e9fd..04a23b9b0a9ed 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/option.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/option.mvir @@ -5,7 +5,7 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x1.option; public entry yes( @@ -14,7 +14,7 @@ module 0x0.M { l2: option.Option>, l3: vector>, l4: option.Option>, - ctx: &mut TxContext.TxContext + ctx: &mut tx_context.TxContext ) { label l0: abort 0; diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/optional_txn_context.exp b/crates/sui-verifier-transactional-tests/tests/entry_points/optional_txn_context.exp index 00d935de5785b..4911380b2c46b 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/optional_txn_context.exp +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/optional_txn_context.exp @@ -5,5 +5,4 @@ created: object(103) written: object(102) task 1 'publish'. lines 14-23: -created: object(105) -written: object(104) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/optional_txn_context.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/optional_txn_context.mvir index deab025bf8342..47433a2a879aa 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/optional_txn_context.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/optional_txn_context.mvir @@ -3,7 +3,7 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; public entry t() { label l0: abort 0; @@ -13,7 +13,7 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; import 0x2.ID; struct Obj has key { id: ID.VersionedID } public entry t(flag: bool, arg: &mut Self.Obj) { diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/return_values.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/return_values.mvir index 812545e378986..d6d57cca6face 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/return_values.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/return_values.mvir @@ -3,8 +3,8 @@ //# publish module 0x0.M { - import 0x2.TxContext; - public entry foo(ctx: &mut TxContext.TxContext): u64 { + import 0x2.tx_context; + public entry foo(ctx: &mut tx_context.TxContext): u64 { label l0: abort 0; } @@ -12,8 +12,8 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; - public entry foo(ctx: &mut TxContext.TxContext): u64 * u8 { + import 0x2.tx_context; + public entry foo(ctx: &mut tx_context.TxContext): u64 * u8 { label l0: abort 0; } @@ -21,8 +21,8 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; - public entry foo(ctx: &mut TxContext.TxContext): vector { + import 0x2.tx_context; + public entry foo(ctx: &mut tx_context.TxContext): vector { label l0: abort 0; } @@ -31,8 +31,8 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; - public entry foo(ctx: &mut TxContext.TxContext): &u8 { + import 0x2.tx_context; + public entry foo(ctx: &mut tx_context.TxContext): &u8 { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/single_generic_vector_param.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/single_generic_vector_param.mvir index fab0e129a968c..db192fef6c845 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/single_generic_vector_param.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/single_generic_vector_param.mvir @@ -3,9 +3,9 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; - public entry foo(l: vector, ctx: &mut TxContext.TxContext) { + public entry foo(l: vector, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param.mvir index 83a7464afb6f6..01777af1f64e5 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param.mvir @@ -3,9 +3,9 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; - public entry foo(l: T, ctx: &mut TxContext.TxContext) { + public entry foo(l: T, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_generic_object.exp b/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_generic_object.exp index a9d54aa84f3ee..9f33cc21b36c1 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_generic_object.exp +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_generic_object.exp @@ -1,5 +1,4 @@ processed 1 task task 0 'publish'. lines 4-16: -created: object(103) -written: object(102) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_generic_object.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_generic_object.mvir index 5d828993621a4..2057aebe001c1 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_generic_object.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_generic_object.mvir @@ -4,11 +4,11 @@ //# publish module 0x0.M { import 0x2.ID; - import 0x2.TxContext; + import 0x2.tx_context; struct Obj has key { id: ID.VersionedID, } - public entry foo(l: Self.Obj, ctx: &mut TxContext.TxContext) { + public entry foo(l: Self.Obj, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_key.mvir b/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_key.mvir index de03efe0472b4..ee4c3bd24aa80 100644 --- a/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_key.mvir +++ b/crates/sui-verifier-transactional-tests/tests/entry_points/single_type_param_key.mvir @@ -3,9 +3,9 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; - public entry foo(l: T, ctx: &mut TxContext.TxContext) { + public entry foo(l: T, ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/global_storage_access/all.exp b/crates/sui-verifier-transactional-tests/tests/global_storage_access/all.exp index e49b97f73d18b..c93831c1d991c 100644 --- a/crates/sui-verifier-transactional-tests/tests/global_storage_access/all.exp +++ b/crates/sui-verifier-transactional-tests/tests/global_storage_access/all.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-31: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [Exists(StructDefinitionIndex(0)), ExistsGeneric(StructDefInstantiationIndex(0)), ImmBorrowGlobal(StructDefinitionIndex(0)), ImmBorrowGlobalGeneric(StructDefInstantiationIndex(0)), MutBorrowGlobal(StructDefinitionIndex(0)), MutBorrowGlobalGeneric(StructDefInstantiationIndex(0)), MoveFrom(StructDefinitionIndex(0)), MoveFromGeneric(StructDefInstantiationIndex(0)), MoveTo(StructDefinitionIndex(0)), MoveToGeneric(StructDefInstantiationIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/global_storage_access/borrow_global.exp b/crates/sui-verifier-transactional-tests/tests/global_storage_access/borrow_global.exp index 9baec3624e86e..de2e5637e2810 100644 --- a/crates/sui-verifier-transactional-tests/tests/global_storage_access/borrow_global.exp +++ b/crates/sui-verifier-transactional-tests/tests/global_storage_access/borrow_global.exp @@ -1,7 +1,7 @@ processed 2 tasks task 0 'publish'. lines 4-15: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [ImmBorrowGlobal(StructDefinitionIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID task 1 'publish'. lines 17-27: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [ImmBorrowGlobalGeneric(StructDefInstantiationIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/global_storage_access/borrow_global_mut.exp b/crates/sui-verifier-transactional-tests/tests/global_storage_access/borrow_global_mut.exp index feb588adb3919..de2e5637e2810 100644 --- a/crates/sui-verifier-transactional-tests/tests/global_storage_access/borrow_global_mut.exp +++ b/crates/sui-verifier-transactional-tests/tests/global_storage_access/borrow_global_mut.exp @@ -1,7 +1,7 @@ processed 2 tasks task 0 'publish'. lines 4-15: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [MutBorrowGlobal(StructDefinitionIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID task 1 'publish'. lines 17-27: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [MutBorrowGlobalGeneric(StructDefInstantiationIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/global_storage_access/exists.exp b/crates/sui-verifier-transactional-tests/tests/global_storage_access/exists.exp index 4e834f61f1924..b50c4be516e8d 100644 --- a/crates/sui-verifier-transactional-tests/tests/global_storage_access/exists.exp +++ b/crates/sui-verifier-transactional-tests/tests/global_storage_access/exists.exp @@ -1,7 +1,7 @@ processed 2 tasks task 0 'publish'. lines 4-14: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [Exists(StructDefinitionIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID task 1 'publish'. lines 16-25: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [ExistsGeneric(StructDefInstantiationIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/global_storage_access/move_from.exp b/crates/sui-verifier-transactional-tests/tests/global_storage_access/move_from.exp index 79afc552c2586..ae0232b83640e 100644 --- a/crates/sui-verifier-transactional-tests/tests/global_storage_access/move_from.exp +++ b/crates/sui-verifier-transactional-tests/tests/global_storage_access/move_from.exp @@ -1,7 +1,7 @@ processed 2 tasks task 0 'publish'. lines 4-20: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [MoveFrom(StructDefinitionIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID task 1 'publish'. lines 22-38: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [MoveFromGeneric(StructDefInstantiationIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/global_storage_access/move_to.exp b/crates/sui-verifier-transactional-tests/tests/global_storage_access/move_to.exp index 6e03cc51f32dc..de2e5637e2810 100644 --- a/crates/sui-verifier-transactional-tests/tests/global_storage_access/move_to.exp +++ b/crates/sui-verifier-transactional-tests/tests/global_storage_access/move_to.exp @@ -1,7 +1,7 @@ processed 2 tasks task 0 'publish'. lines 4-15: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [MoveTo(StructDefinitionIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID task 1 'publish'. lines 17-27: -Error: Failed to verify the Move module, reason: "Access to Move global storage is not allowed. Found in function no: [MoveToGeneric(StructDefInstantiationIndex(0))]". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_generic_key_struct_id_field.exp b/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_generic_key_struct_id_field.exp index b598befabd2a4..b4a4540418967 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_generic_key_struct_id_field.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_generic_key_struct_id_field.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-18: -Error: Failed to verify the Move module, reason: "In function foo: ID field of struct Foo cannot be mut borrowed because ID is immutable.". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_key_struct_id_field.exp b/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_key_struct_id_field.exp index b598befabd2a4..b4a4540418967 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_key_struct_id_field.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_key_struct_id_field.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-18: -Error: Failed to verify the Move module, reason: "In function foo: ID field of struct Foo cannot be mut borrowed because ID is immutable.". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_key_struct_non_id_field.exp b/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_key_struct_non_id_field.exp index 21090bca772c8..4984e293cafcb 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_key_struct_non_id_field.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_key_struct_non_id_field.exp @@ -1,5 +1,4 @@ processed 1 task task 0 'publish'. lines 4-19: -created: object(103) -written: object(102) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_non_key_struct_id_field.exp b/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_non_key_struct_id_field.exp index da8e7bece8e72..b4a4540418967 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_non_key_struct_id_field.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_immutable/mut_borrow_non_key_struct_id_field.exp @@ -1,5 +1,4 @@ processed 1 task task 0 'publish'. lines 4-18: -created: object(103) -written: object(102) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_leak/direct_leak_through_call.exp b/crates/sui-verifier-transactional-tests/tests/id_leak/direct_leak_through_call.exp index e3a089eb95925..5ff684dbd6a9c 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_leak/direct_leak_through_call.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_leak/direct_leak_through_call.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-25: -Error: Failed to verify the Move module, reason: "ID leak detected in function foo: ID leaked through function call.". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_leak/indirect_leak_through_call.exp b/crates/sui-verifier-transactional-tests/tests/id_leak/indirect_leak_through_call.exp index e3a089eb95925..5ff684dbd6a9c 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_leak/indirect_leak_through_call.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_leak/indirect_leak_through_call.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-25: -Error: Failed to verify the Move module, reason: "ID leak detected in function foo: ID leaked through function call.". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_leak/through_direct_return.exp b/crates/sui-verifier-transactional-tests/tests/id_leak/through_direct_return.exp index 75cef76189499..4984e293cafcb 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_leak/through_direct_return.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_leak/through_direct_return.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-19: -Error: Failed to verify the Move module, reason: "ID leak detected in function foo: ID leaked through function return.". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_leak/through_indirect_return.exp b/crates/sui-verifier-transactional-tests/tests/id_leak/through_indirect_return.exp index 75cef76189499..4984e293cafcb 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_leak/through_indirect_return.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_leak/through_indirect_return.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-19: -Error: Failed to verify the Move module, reason: "ID leak detected in function foo: ID leaked through function return.". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_leak/through_reference.exp b/crates/sui-verifier-transactional-tests/tests/id_leak/through_reference.exp index dd958c3275c62..b2b8df8cb2971 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_leak/through_reference.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_leak/through_reference.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-20: -Error: Failed to publish the Move module(s), reason: "VMError with status WRITEREF_WITHOUT_DROP_ABILITY at location Module ModuleId { address: _, name: Identifier(\"M\") } at index 0 for function definition at code offset 5 in function definition 0". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/id_leak/through_vector.exp b/crates/sui-verifier-transactional-tests/tests/id_leak/through_vector.exp index 23c7c42090cb6..b2b8df8cb2971 100644 --- a/crates/sui-verifier-transactional-tests/tests/id_leak/through_vector.exp +++ b/crates/sui-verifier-transactional-tests/tests/id_leak/through_vector.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-20: -Error: Failed to verify the Move module, reason: "ID leak detected in function foo: ID is leaked into a vector". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/init/cannot_call_init.mvir b/crates/sui-verifier-transactional-tests/tests/init/cannot_call_init.mvir index 77ccfeec77a4c..d9da3fdd96596 100644 --- a/crates/sui-verifier-transactional-tests/tests/init/cannot_call_init.mvir +++ b/crates/sui-verifier-transactional-tests/tests/init/cannot_call_init.mvir @@ -3,13 +3,13 @@ //# publish module 0x0.M { - import 0x2.TxContext; - init(ctx: &mut TxContext.TxContext) { + import 0x2.tx_context; + init(ctx: &mut tx_context.TxContext) { label l0: abort 0; } - public entry init_again(ctx: &mut TxContext.TxContext) { + public entry init_again(ctx: &mut tx_context.TxContext) { label l0: Self.init(move(ctx)); return; diff --git a/crates/sui-verifier-transactional-tests/tests/init/must_have_txn_context.exp b/crates/sui-verifier-transactional-tests/tests/init/must_have_txn_context.exp index af7706ea81939..bc171b75d1dcb 100644 --- a/crates/sui-verifier-transactional-tests/tests/init/must_have_txn_context.exp +++ b/crates/sui-verifier-transactional-tests/tests/init/must_have_txn_context.exp @@ -1,7 +1,7 @@ processed 2 tasks task 0 'publish'. lines 4-11: -Error: Failed to verify the Move module, reason: "Expected exactly one parameter for _::M::init of type &mut Sui::TxContext::TxContext". +Error: Failed to verify the Move module, reason: "Expected exactly one parameter for _::M::init of type &mut sui::tx_context::TxContext". task 1 'publish'. lines 14-21: -Error: Failed to verify the Move module, reason: "Expected exactly one parameter for _::M::init of type &mut Sui::TxContext::TxContext". +Error: Failed to verify the Move module, reason: "Expected exactly one parameter for _::M::init of type &mut sui::tx_context::TxContext". diff --git a/crates/sui-verifier-transactional-tests/tests/init/must_have_txn_context.mvir b/crates/sui-verifier-transactional-tests/tests/init/must_have_txn_context.mvir index c8b34146b6a68..f4a06d35a9798 100644 --- a/crates/sui-verifier-transactional-tests/tests/init/must_have_txn_context.mvir +++ b/crates/sui-verifier-transactional-tests/tests/init/must_have_txn_context.mvir @@ -3,7 +3,7 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; init() { label l0: abort 0; @@ -13,8 +13,8 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; - init(ctx: &mut TxContext.TxContext, ctx2: &mut TxContext.TxContext) { + import 0x2.tx_context; + init(ctx: &mut tx_context.TxContext, ctx2: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/init/not_generic.mvir b/crates/sui-verifier-transactional-tests/tests/init/not_generic.mvir index e3de0beaf5e96..e7fbd91f8c823 100644 --- a/crates/sui-verifier-transactional-tests/tests/init/not_generic.mvir +++ b/crates/sui-verifier-transactional-tests/tests/init/not_generic.mvir @@ -3,8 +3,8 @@ //# publish module 0x0.M { - import 0x2.TxContext; - init(ctx: &mut TxContext.TxContext) { + import 0x2.tx_context; + init(ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/init/not_private.mvir b/crates/sui-verifier-transactional-tests/tests/init/not_private.mvir index 060ac125f4db1..f437a4ab1c225 100644 --- a/crates/sui-verifier-transactional-tests/tests/init/not_private.mvir +++ b/crates/sui-verifier-transactional-tests/tests/init/not_private.mvir @@ -3,8 +3,8 @@ //# publish module 0x0.M { - import 0x2.TxContext; - public init(ctx: &mut TxContext.TxContext) { + import 0x2.tx_context; + public init(ctx: &mut tx_context.TxContext) { label l0: abort 0; } @@ -12,8 +12,8 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; - public entry init(ctx: &mut TxContext.TxContext) { + import 0x2.tx_context; + public entry init(ctx: &mut tx_context.TxContext) { label l0: abort 0; } @@ -21,8 +21,8 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; - public(friend) init(ctx: &mut TxContext.TxContext) { + import 0x2.tx_context; + public(friend) init(ctx: &mut tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/init/not_txn_context.exp b/crates/sui-verifier-transactional-tests/tests/init/not_txn_context.exp index f7d82cb031608..fce1fb3f7f864 100644 --- a/crates/sui-verifier-transactional-tests/tests/init/not_txn_context.exp +++ b/crates/sui-verifier-transactional-tests/tests/init/not_txn_context.exp @@ -1,13 +1,13 @@ processed 4 tasks task 0 'publish'. lines 4-11: -Error: Failed to verify the Move module, reason: "Expected parameter for _::M::init to be &mut mut Sui::TxContext::TxContext, but found u64". +Error: Failed to verify the Move module, reason: "Expected parameter for _::M::init to be &mut sui::tx_context::TxContext, but found u64". task 1 'publish'. lines 13-20: -Error: Failed to verify the Move module, reason: "Expected parameter for _::TxContext::init to be &mut mut Sui::TxContext::TxContext, but found _::TxContext::TxContext". +Error: Failed to verify the Move module, reason: "Expected parameter for _::tx_context::init to be &mut sui::tx_context::TxContext, but found _::tx_context::TxContext". task 2 'publish'. lines 22-29: -Error: Failed to verify the Move module, reason: "Expected parameter for _::M::init to be &mut mut Sui::TxContext::TxContext, but found &Sui::TxContext::TxContext". +Error: Failed to verify the Move module, reason: "Expected parameter for _::M::init to be &mut sui::tx_context::TxContext, but found &sui::tx_context::TxContext". task 3 'publish'. lines 32-39: -Error: Failed to verify the Move module, reason: "Expected parameter for _::M::init to be &mut mut Sui::TxContext::TxContext, but found Sui::TxContext::TxContext". +Error: Failed to verify the Move module, reason: "Expected parameter for _::M::init to be &mut sui::tx_context::TxContext, but found sui::tx_context::TxContext". diff --git a/crates/sui-verifier-transactional-tests/tests/init/not_txn_context.mvir b/crates/sui-verifier-transactional-tests/tests/init/not_txn_context.mvir index 80321a66a1193..4f5b6b2494041 100644 --- a/crates/sui-verifier-transactional-tests/tests/init/not_txn_context.mvir +++ b/crates/sui-verifier-transactional-tests/tests/init/not_txn_context.mvir @@ -3,7 +3,7 @@ //# publish module 0x0.M { - import 0x2.TxContext; + import 0x2.tx_context; init(ctx: u64) { label l0: abort 0; @@ -11,7 +11,7 @@ module 0x0.M { } //# publish -module 0x0.TxContext { +module 0x0.tx_context { struct TxContext { value: u64 } init(ctx: Self.TxContext) { label l0: @@ -21,8 +21,8 @@ module 0x0.TxContext { //# publish module 0x0.M { - import 0x2.TxContext; - init(ctx: &TxContext.TxContext) { + import 0x2.tx_context; + init(ctx: &tx_context.TxContext) { label l0: abort 0; } @@ -31,8 +31,8 @@ module 0x0.M { //# publish module 0x0.M { - import 0x2.TxContext; - init(ctx: TxContext.TxContext) { + import 0x2.tx_context; + init(ctx: tx_context.TxContext) { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/init/return_values.mvir b/crates/sui-verifier-transactional-tests/tests/init/return_values.mvir index 56db67df28372..cde2019a3e1b7 100644 --- a/crates/sui-verifier-transactional-tests/tests/init/return_values.mvir +++ b/crates/sui-verifier-transactional-tests/tests/init/return_values.mvir @@ -3,8 +3,8 @@ //# publish module 0x0.M { - import 0x2.TxContext; - init(ctx: &mut TxContext.TxContext): u64 { + import 0x2.tx_context; + init(ctx: &mut tx_context.TxContext): u64 { label l0: abort 0; } diff --git a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_first_field_not_id.exp b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_first_field_not_id.exp index 160f38f5952bb..57847a5f44d31 100644 --- a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_first_field_not_id.exp +++ b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_first_field_not_id.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-10: -Error: Failed to verify the Move module, reason: "First field of struct S must be 'id', flag found". +Error: Failed to publish the Move module(s), reason: "VMError with status LINKER_ERROR at location UNDEFINED and message Cannot find ModuleId { address: sui, name: Identifier(\"ID\") } in data cache". diff --git a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_struct_address.exp b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_struct_address.exp index b96e8025d7ef1..598e84180d7c2 100644 --- a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_struct_address.exp +++ b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_struct_address.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-11: -Error: Failed to verify the Move module, reason: "First field of struct S must be of type Sui::ID::VersionedID, _::ID::VersionedID type found". +Error: Failed to publish the Move module(s), reason: "VMError with status LINKER_ERROR at location UNDEFINED and message Cannot find ModuleId { address: sui, name: Identifier(\"ID\") } in data cache". diff --git a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_struct_name.exp b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_struct_name.exp index 1aa4003d88016..4df09270cf7e2 100644 --- a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_struct_name.exp +++ b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_struct_name.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-10: -Error: Failed to verify the Move module, reason: "First field of struct S must be of type Sui::ID::VersionedID, Sui::ID::ID type found". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_type.exp b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_type.exp index e3a2c34d05923..57847a5f44d31 100644 --- a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_type.exp +++ b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_incorrect_type.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-10: -Error: Failed to verify the Move module, reason: "First field of struct S must be of ID type, Bool type found". +Error: Failed to publish the Move module(s), reason: "VMError with status LINKER_ERROR at location UNDEFINED and message Cannot find ModuleId { address: sui, name: Identifier(\"ID\") } in data cache". diff --git a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_valid.exp b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_valid.exp index 939fe39acec26..4df09270cf7e2 100644 --- a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_valid.exp +++ b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_id_field_valid.exp @@ -1,5 +1,4 @@ processed 1 task task 0 'publish'. lines 4-10: -created: object(103) -written: object(102) +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_second_field_id.exp b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_second_field_id.exp index a2eda753e36f6..267d6ebf632a3 100644 --- a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_second_field_id.exp +++ b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_second_field_id.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-11: -Error: Failed to verify the Move module, reason: "First field of struct S must be 'id', flag found". +Error: Dependency not provided for 0000000000000000000000000000000000000002.ID diff --git a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_with_drop.exp b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_with_drop.exp index 3a5134d72708b..57847a5f44d31 100644 --- a/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_with_drop.exp +++ b/crates/sui-verifier-transactional-tests/tests/struct_with_key/key_struct_with_drop.exp @@ -1,4 +1,4 @@ processed 1 task task 0 'publish'. lines 4-10: -Error: Failed to verify the Move module, reason: "Struct S cannot have both key and drop abilities". +Error: Failed to publish the Move module(s), reason: "VMError with status LINKER_ERROR at location UNDEFINED and message Cannot find ModuleId { address: sui, name: Identifier(\"ID\") } in data cache". diff --git a/crates/sui-verifier/src/entry_points_verifier.rs b/crates/sui-verifier/src/entry_points_verifier.rs index 833a068a62e6c..917f12176309a 100644 --- a/crates/sui-verifier/src/entry_points_verifier.rs +++ b/crates/sui-verifier/src/entry_points_verifier.rs @@ -141,7 +141,7 @@ fn verify_init_function(module: &CompiledModule, fdef: &FunctionDefinition) -> R Ok(()) } else { Err(format!( - "Expected parameter for {}::{} to be &mut mut {}::{}::{}, but found {}", + "Expected parameter for {}::{} to be &mut {}::{}::{}, but found {}", module.self_id(), INIT_FN_NAME, SUI_FRAMEWORK_ADDRESS, diff --git a/crates/sui-verifier/src/id_leak_verifier.rs b/crates/sui-verifier/src/id_leak_verifier.rs index 2492708ce833d..f2d170d9d83a1 100644 --- a/crates/sui-verifier/src/id_leak_verifier.rs +++ b/crates/sui-verifier/src/id_leak_verifier.rs @@ -174,15 +174,15 @@ fn is_call_safe_to_leak(verifier: &IDLeakAnalysis, function_handle: &FunctionHan return false; } - // Sui::ID::delete - (verifier.binary_view.identifier_at(m.name).as_str() == "ID" + // sui::id::delete + (verifier.binary_view.identifier_at(m.name).as_str() == "id" && verifier .binary_view .identifier_at(function_handle.name) .as_str() == "delete") || - // Sui::Transfer::delete_child_object - (verifier.binary_view.identifier_at(m.name).as_str() == "Transfer" + // sui::transfer::delete_child_object + (verifier.binary_view.identifier_at(m.name).as_str() == "transfer" && verifier .binary_view .identifier_at(function_handle.name) diff --git a/crates/sui-verifier/src/private_transfer.rs b/crates/sui-verifier/src/private_transfer.rs index b50be214f7a8b..635de7cf73dde 100644 --- a/crates/sui-verifier/src/private_transfer.rs +++ b/crates/sui-verifier/src/private_transfer.rs @@ -16,14 +16,14 @@ use sui_types::{ use crate::format_signature_token; -/// All transfer functions (the functions in `Sui::Transfer`) are "private" in that they are +/// All transfer functions (the functions in `sui::transfer`) are "private" in that they are /// restricted to the module. -/// For example, with `Transfer::transfer(...)`, either: +/// For example, with `transfer::transfer(...)`, either: /// - `T` must be a type declared in the current module or /// - `T` must have `store` pub fn verify_module(module: &CompiledModule) -> SuiResult { let view = &BinaryIndexedView::Module(module); - // do not need to check the Sui::Transfer module itself + // do not need to check the sui::transfer module itself if is_transfer_module(view, module.self_handle()) { return Ok(()); } @@ -115,7 +115,7 @@ fn verify_function(view: &BinaryIndexedView, fdef: &FunctionDefinition) -> Resul }; if !has_store && !is_defined_in_current_module { return Err(format!( - "Invalid call to '{}::Transfer::{}'. \ + "Invalid call to '{}::transfer::{}'. \ Invalid transfer of object of type '{}'. \ The transferred object's type must be defined in the current module, \ or must have the 'store' type ability", diff --git a/crates/sui-verifier/src/struct_with_key_verifier.rs b/crates/sui-verifier/src/struct_with_key_verifier.rs index b55c3b7e70251..6e2c043405d7f 100644 --- a/crates/sui-verifier/src/struct_with_key_verifier.rs +++ b/crates/sui-verifier/src/struct_with_key_verifier.rs @@ -72,9 +72,9 @@ fn verify_key_structs(module: &CompiledModule) -> SuiResult { fp_ensure!( id_type_struct_name == "VersionedID" && id_type_module_address == &SUI_FRAMEWORK_ADDRESS - && id_type_module_name == "ID", + && id_type_module_name == "id", verification_failure(format!( - "First field of struct {} must be of type {}::ID::VersionedID, {}::{}::{} type found", + "First field of struct {} must be of type {}::id::VersionedID, {}::{}::{} type found", name, SUI_FRAMEWORK_ADDRESS, id_type_module_address, diff --git a/crates/sui-verifier/tests/common/module_builder.rs b/crates/sui-verifier/tests/common/module_builder.rs index 776581236f794..fc7e9c755721c 100644 --- a/crates/sui-verifier/tests/common/module_builder.rs +++ b/crates/sui-verifier/tests/common/module_builder.rs @@ -55,10 +55,10 @@ impl ModuleBuilder { } } - /// Creates the "ID" module in framework address, along with the "VersionedID" struct. + /// Creates the "id" module in framework address, along with the "VersionedID" struct. /// Both the module and the ID struct information are returned. pub fn default() -> (Self, StructInfo) { - let mut module = Self::new(SUI_FRAMEWORK_ADDRESS, "ID"); + let mut module = Self::new(SUI_FRAMEWORK_ADDRESS, "id"); let id = module.add_struct( module.get_self_index(), "VersionedID", diff --git a/crates/sui/src/benchmark/transaction_creator.rs b/crates/sui/src/benchmark/transaction_creator.rs index f3552513e12c7..f1a2833d18e39 100644 --- a/crates/sui/src/benchmark/transaction_creator.rs +++ b/crates/sui/src/benchmark/transaction_creator.rs @@ -32,7 +32,7 @@ fn make_transfer_transaction( SingleTransactionKind::Call(MoveCall { package: framework_obj_ref, - module: ident_str!("SUI").to_owned(), + module: ident_str!("sui").to_owned(), function: ident_str!("transfer").to_owned(), type_arguments: Vec::new(), arguments: vec![ diff --git a/crates/sui/src/unit_tests/cli_tests.rs b/crates/sui/src/unit_tests/cli_tests.rs index 124b13d2d38e4..35045ba6d8616 100644 --- a/crates/sui/src/unit_tests/cli_tests.rs +++ b/crates/sui/src/unit_tests/cli_tests.rs @@ -173,7 +173,7 @@ async fn test_create_example_nft_command() -> Result<(), anyhow::Error> { match result { WalletCommandResult::CreateExampleNFT(GetObjectDataResponse::Exists(obj)) => { assert_eq!(obj.owner, address); - assert_eq!(obj.data.type_().unwrap(), "0x2::DevNetNFT::DevNetNFT"); + assert_eq!(obj.data.type_().unwrap(), "0x2::devnet_nft::DevNetNFT"); Ok(obj) } _ => Err(anyhow!( @@ -432,7 +432,7 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { // Test case with no gas specified let resp = WalletCommands::Call { package: ObjectID::from_hex_literal("0x2").unwrap(), - module: "ObjectBasics".to_string(), + module: "object_basics".to_string(), function: "create".to_string(), type_args: vec![], args, @@ -472,7 +472,7 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { let resp = WalletCommands::Call { package: ObjectID::from_hex_literal("0x2").unwrap(), - module: "ObjectBasics".to_string(), + module: "object_basics".to_string(), function: "create".to_string(), type_args: vec![], args: args.to_vec(), @@ -500,7 +500,7 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { let resp = WalletCommands::Call { package: ObjectID::from_hex_literal("0x2").unwrap(), - module: "ObjectBasics".to_string(), + module: "object_basics".to_string(), function: "transfer".to_string(), type_args: vec![], args: args.to_vec(), @@ -513,7 +513,7 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { assert!(resp.is_err()); let err_string = format!("{} ", resp.err().unwrap()); - assert!(err_string.contains("Expected argument of type 0x2::ObjectBasics::Object, but found type 0x2::Coin::Coin<0x2::SUI::SUI>")); + assert!(err_string.contains("Expected argument of type 0x2::object_basics::Object, but found type 0x2::coin::Coin<0x2::sui::SUI>")); // Try a proper transfer let obj_str = format!("0x{:02x}", created_obj); @@ -527,7 +527,7 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { WalletCommands::Call { package: ObjectID::from_hex_literal("0x2").unwrap(), - module: "ObjectBasics".to_string(), + module: "object_basics".to_string(), function: "transfer".to_string(), type_args: vec![], args: args.to_vec(), diff --git a/crates/sui/src/unit_tests/data/custom_genesis_package_1/Move.toml b/crates/sui/src/unit_tests/data/custom_genesis_package_1/Move.toml index 255a7d2f9774c..e6b34720bf6d4 100644 --- a/crates/sui/src/unit_tests/data/custom_genesis_package_1/Move.toml +++ b/crates/sui/src/unit_tests/data/custom_genesis_package_1/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { local = "../../../../../sui-framework" } [addresses] -Examples = "0x0" +examples = "0x0" diff --git a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/CombinableObjects.move b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/combinable_objects.move similarity index 64% rename from crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/CombinableObjects.move rename to crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/combinable_objects.move index 8c0b1d651c41e..be134e7e5a5d0 100644 --- a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/CombinableObjects.move +++ b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/combinable_objects.move @@ -3,12 +3,12 @@ /// Example of objects that can be combined to create /// new objects -module Examples::CombinableObjects { - use Examples::TrustedCoin::EXAMPLE; - use Sui::Coin::{Self, Coin}; - use Sui::ID::{Self, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module examples::combinable_objects { + use examples::trusted_coin::EXAMPLE; + use sui::coin::{Self, Coin}; + use sui::id::{Self, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; struct Ham has key { id: VersionedID @@ -34,16 +34,16 @@ module Examples::CombinableObjects { /// Exchange `c` for some ham public fun buy_ham(c: Coin, ctx: &mut TxContext): Ham { - assert!(Coin::value(&c) == HAM_PRICE, EINSUFFICIENT_FUNDS); - Transfer::transfer(c, admin()); - Ham { id: TxContext::new_id(ctx) } + assert!(coin::value(&c) == HAM_PRICE, EINSUFFICIENT_FUNDS); + transfer::transfer(c, admin()); + Ham { id: tx_context::new_id(ctx) } } /// Exchange `c` for some bread public fun buy_bread(c: Coin, ctx: &mut TxContext): Bread { - assert!(Coin::value(&c) == BREAD_PRICE, EINSUFFICIENT_FUNDS); - Transfer::transfer(c, admin()); - Bread { id: TxContext::new_id(ctx) } + assert!(coin::value(&c) == BREAD_PRICE, EINSUFFICIENT_FUNDS); + transfer::transfer(c, admin()); + Bread { id: tx_context::new_id(ctx) } } /// Combine the `ham` and `bread` into a delicious sandwich @@ -52,9 +52,9 @@ module Examples::CombinableObjects { ): Sandwich { let Ham { id: ham_id } = ham; let Bread { id: bread_id } = bread; - ID::delete(ham_id); - ID::delete(bread_id); - Sandwich { id: TxContext::new_id(ctx) } + id::delete(ham_id); + id::delete(bread_id); + Sandwich { id: tx_context::new_id(ctx) } } fun admin(): address { diff --git a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/CustomObjectTemplate.move b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/custom_object_template.move similarity index 91% rename from crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/CustomObjectTemplate.move rename to crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/custom_object_template.move index 37fd1dd34984b..1a2285a6a479f 100644 --- a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/CustomObjectTemplate.move +++ b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/custom_object_template.move @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 /// An example of a custom object with comments explaining the relevant bits -module Examples::CustomObjectTemplate { - use Sui::ID::VersionedID; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module examples::custom_object_template { + use sui::id::VersionedID; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// A custom sui object. Every object must have the `key` attribute /// (indicating that it is allowed to be a key in the sui global object @@ -48,7 +48,7 @@ module Examples::CustomObjectTemplate { /// be transferred by the module that declares it. public fun transfer(o: Object, recipient: address) { assert!(some_conditional_logic(), 0); - Transfer::transfer(o, recipient) + transfer::transfer(o, recipient) } /// Simple getter @@ -61,10 +61,10 @@ module Examples::CustomObjectTemplate { /// from this module to read/write it, package it into another object, ...) public fun create(tx: &mut TxContext): Object { Object { - id: TxContext::new_id(tx), + id: tx_context::new_id(tx), custom_field: 0, child_obj: ChildObject { a_field: false }, - nested_obj: AnotherObject { id: TxContext::new_id(tx) } + nested_obj: AnotherObject { id: tx_context::new_id(tx) } } } @@ -99,8 +99,8 @@ module Examples::CustomObjectTemplate { write_field(to_write, v + int_input); transfer(to_consume, recipient); // demonstrate creating a new object for the sender - let sender = TxContext::sender(ctx); - Transfer::transfer(create(ctx), sender) + let sender = tx_context::sender(ctx); + transfer::transfer(create(ctx), sender) } fun some_conditional_logic(): bool { diff --git a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TicTacToe.move b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/tic_tac_toe.move similarity index 88% rename from crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TicTacToe.move rename to crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/tic_tac_toe.move index d91509bf9030b..434f90d85a073 100644 --- a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TicTacToe.move +++ b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/tic_tac_toe.move @@ -1,14 +1,14 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Examples::TicTacToe { +module examples::tic_tac_toe { use std::option::{Self, Option}; use std::vector; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Event; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::id::{Self, ID, VersionedID}; + use sui::event; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; // Game status const IN_PROGRESS: u8 = 0; @@ -62,8 +62,8 @@ module Examples::TicTacToe { public entry fun create_game(x_address: address, o_address: address, ctx: &mut TxContext) { // TODO: Validate sender address, only GameAdmin can create games. - let id = TxContext::new_id(ctx); - let game_id = *ID::inner(&id); + let id = tx_context::new_id(ctx); + let game_id = *id::inner(&id); let gameboard = vector[ vector[option::none(), option::none(), option::none()], vector[option::none(), option::none(), option::none()], @@ -77,19 +77,19 @@ module Examples::TicTacToe { x_address: x_address, o_address: o_address, }; - Transfer::transfer(game, TxContext::sender(ctx)); + transfer::transfer(game, tx_context::sender(ctx)); let cap = MarkMintCap { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), game_id: copy game_id, remaining_supply: 5, }; - Transfer::transfer(cap, x_address); + transfer::transfer(cap, x_address); let cap = MarkMintCap { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), game_id, remaining_supply: 5, }; - Transfer::transfer(cap, o_address); + transfer::transfer(cap, o_address); } /// Generate a new mark intended for location (row, col). @@ -101,11 +101,11 @@ module Examples::TicTacToe { let mark = mint_mark(cap, row, col, ctx); // Once an event is emitted, it should be observed by a game server. // The game server will then call `place_mark` to place this mark. - Event::emit(MarkSentEvent { + event::emit(MarkSentEvent { game_id: *&cap.game_id, - mark_id: *ID::inner(&mark.id), + mark_id: *id::inner(&mark.id), }); - Transfer::transfer(mark, game_address); + transfer::transfer(mark, game_address); } public entry fun place_mark(game: &mut TicTacToe, mark: Mark, ctx: &mut TxContext) { @@ -129,11 +129,11 @@ module Examples::TicTacToe { if (game.game_status != IN_PROGRESS) { // Notify the server that the game ended so that it can delete the game. - Event::emit(GameEndEvent { game_id: *ID::inner(&game.id) }); + event::emit(GameEndEvent { game_id: *id::inner(&game.id) }); if (game.game_status == X_WIN) { - Transfer::transfer( Trophy { id: TxContext::new_id(ctx) }, *&game.x_address); + transfer::transfer( Trophy { id: tx_context::new_id(ctx) }, *&game.x_address); } else if (game.game_status == O_WIN) { - Transfer::transfer( Trophy { id: TxContext::new_id(ctx) }, *&game.o_address); + transfer::transfer( Trophy { id: tx_context::new_id(ctx) }, *&game.o_address); } } } @@ -153,17 +153,17 @@ module Examples::TicTacToe { vector::destroy_empty(row); }; vector::destroy_empty(gameboard); - ID::delete(id); + id::delete(id); } public entry fun delete_trophy(trophy: Trophy) { let Trophy { id } = trophy; - ID::delete(id); + id::delete(id); } public entry fun delete_cap(cap: MarkMintCap) { let MarkMintCap { id, game_id: _, remaining_supply: _ } = cap; - ID::delete(id); + id::delete(id); } public fun get_status(game: &TicTacToe): u8 { @@ -176,8 +176,8 @@ module Examples::TicTacToe { }; cap.remaining_supply = cap.remaining_supply - 1; Mark { - id: TxContext::new_id(ctx), - player: TxContext::sender(ctx), + id: tx_context::new_id(ctx), + player: tx_context::sender(ctx), row, col, } @@ -252,7 +252,7 @@ module Examples::TicTacToe { fun delete_mark(mark: Mark) { let Mark { id, player: _, row: _, col: _ } = mark; - ID::delete(id); + id::delete(id); } public fun mark_player(mark: &Mark): &address { diff --git a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TrustedCoin.move b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/trusted_coin.move similarity index 66% rename from crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TrustedCoin.move rename to crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/trusted_coin.move index 2a7b896558bb4..363e2d6001a25 100644 --- a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TrustedCoin.move +++ b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/trusted_coin.move @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 /// Example coin with a trusted owner responsible for minting/burning (e.g., a stablecoin) -module Examples::TrustedCoin { - use Sui::Coin::{Self, TreasuryCap}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module examples::trusted_coin { + use sui::coin::{Self, TreasuryCap}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Name of the coin struct EXAMPLE has drop {} @@ -16,17 +16,17 @@ module Examples::TrustedCoin { fun init(ctx: &mut TxContext) { // Get a treasury cap for the coin and give it to the transaction // sender - let treasury_cap = Coin::create_currency(EXAMPLE{}, ctx); - Transfer::transfer(treasury_cap, TxContext::sender(ctx)) + let treasury_cap = coin::create_currency(EXAMPLE{}, ctx); + transfer::transfer(treasury_cap, tx_context::sender(ctx)) } public entry fun mint(treasury_cap: &mut TreasuryCap, amount: u64, ctx: &mut TxContext) { - let coin = Coin::mint(amount, treasury_cap, ctx); - Coin::transfer(coin, TxContext::sender(ctx)); + let coin = coin::mint(amount, treasury_cap, ctx); + coin::transfer(coin, tx_context::sender(ctx)); } public entry fun transfer(treasury_cap: TreasuryCap, recipient: address) { - Coin::transfer_cap(treasury_cap, recipient); + coin::transfer_cap(treasury_cap, recipient); } #[test_only] diff --git a/crates/sui/src/unit_tests/data/custom_genesis_package_2/sources/M1.move b/crates/sui/src/unit_tests/data/custom_genesis_package_2/sources/M1.move index 60ca3d1bfbf41..e482d2a4aba08 100644 --- a/crates/sui/src/unit_tests/data/custom_genesis_package_2/sources/M1.move +++ b/crates/sui/src/unit_tests/data/custom_genesis_package_2/sources/M1.move @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 module Test::M1 { - use Sui::ID::VersionedID; - use Sui::TxContext::{Self, TxContext}; - use Sui::Transfer; + use sui::id::VersionedID; + use sui::tx_context::{Self, TxContext}; + use sui::transfer; struct Object has key, store { id: VersionedID, @@ -13,7 +13,7 @@ module Test::M1 { // initializer that should be executed upon publishing this module fun init(ctx: &mut TxContext) { - let singleton = Object { id: TxContext::new_id(ctx), value: 12 }; - Transfer::transfer(singleton, TxContext::sender(ctx)) + let singleton = Object { id: tx_context::new_id(ctx), value: 12 }; + transfer::transfer(singleton, tx_context::sender(ctx)) } } diff --git a/crates/sui/src/unit_tests/data/dummy_modules_publish/Move.toml b/crates/sui/src/unit_tests/data/dummy_modules_publish/Move.toml index 255a7d2f9774c..e6b34720bf6d4 100644 --- a/crates/sui/src/unit_tests/data/dummy_modules_publish/Move.toml +++ b/crates/sui/src/unit_tests/data/dummy_modules_publish/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { local = "../../../../../sui-framework" } [addresses] -Examples = "0x0" +examples = "0x0" diff --git a/crates/sui/src/unit_tests/data/dummy_modules_publish/sources/TrustedCoin.move b/crates/sui/src/unit_tests/data/dummy_modules_publish/sources/trusted_coin.move similarity index 66% rename from crates/sui/src/unit_tests/data/dummy_modules_publish/sources/TrustedCoin.move rename to crates/sui/src/unit_tests/data/dummy_modules_publish/sources/trusted_coin.move index 2a7b896558bb4..363e2d6001a25 100644 --- a/crates/sui/src/unit_tests/data/dummy_modules_publish/sources/TrustedCoin.move +++ b/crates/sui/src/unit_tests/data/dummy_modules_publish/sources/trusted_coin.move @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 /// Example coin with a trusted owner responsible for minting/burning (e.g., a stablecoin) -module Examples::TrustedCoin { - use Sui::Coin::{Self, TreasuryCap}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module examples::trusted_coin { + use sui::coin::{Self, TreasuryCap}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Name of the coin struct EXAMPLE has drop {} @@ -16,17 +16,17 @@ module Examples::TrustedCoin { fun init(ctx: &mut TxContext) { // Get a treasury cap for the coin and give it to the transaction // sender - let treasury_cap = Coin::create_currency(EXAMPLE{}, ctx); - Transfer::transfer(treasury_cap, TxContext::sender(ctx)) + let treasury_cap = coin::create_currency(EXAMPLE{}, ctx); + transfer::transfer(treasury_cap, tx_context::sender(ctx)) } public entry fun mint(treasury_cap: &mut TreasuryCap, amount: u64, ctx: &mut TxContext) { - let coin = Coin::mint(amount, treasury_cap, ctx); - Coin::transfer(coin, TxContext::sender(ctx)); + let coin = coin::mint(amount, treasury_cap, ctx); + coin::transfer(coin, tx_context::sender(ctx)); } public entry fun transfer(treasury_cap: TreasuryCap, recipient: address) { - Coin::transfer_cap(treasury_cap, recipient); + coin::transfer_cap(treasury_cap, recipient); } #[test_only] diff --git a/crates/sui/src/unit_tests/rpc_server_tests.rs b/crates/sui/src/unit_tests/rpc_server_tests.rs index 514258c6e4367..3b20f564d680f 100644 --- a/crates/sui/src/unit_tests/rpc_server_tests.rs +++ b/crates/sui/src/unit_tests/rpc_server_tests.rs @@ -116,7 +116,7 @@ async fn test_move_call() -> Result<(), anyhow::Error> { let gas = objects.first().unwrap(); let package_id = ObjectID::new(SUI_FRAMEWORK_ADDRESS.into_bytes()); - let module = "ObjectBasics".to_string(); + let module = "object_basics".to_string(); let function = "create".to_string(); let json_args = vec![ diff --git a/crates/sui/src/wallet_commands.rs b/crates/sui/src/wallet_commands.rs index 607e02b967558..17ce0af4a6d6e 100644 --- a/crates/sui/src/wallet_commands.rs +++ b/crates/sui/src/wallet_commands.rs @@ -502,7 +502,7 @@ impl WalletCommands { } let (_, effects) = call_move( ObjectID::from(SUI_FRAMEWORK_ADDRESS), - "DevNetNFT", + "devnet_nft", "mint", vec![], gas, @@ -664,7 +664,7 @@ impl Display for WalletCommandResult { for oref in object_refs { let owner_type = match oref.owner { Owner::AddressOwner(_) => "AddressOwner", - Owner::ObjectOwner(_) => "ObjectOwner", + Owner::ObjectOwner(_) => "object_owner", Owner::Shared => "Shared", Owner::Immutable => "Immutable", }; diff --git a/crates/sui/tests/checkpoints_tests.rs b/crates/sui/tests/checkpoints_tests.rs index d217b890ac317..ff2ce6be4015e 100644 --- a/crates/sui/tests/checkpoints_tests.rs +++ b/crates/sui/tests/checkpoints_tests.rs @@ -247,7 +247,7 @@ async fn checkpoint_with_shared_objects() { tokio::task::yield_now().await; let create_counter_transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "create", package_ref, /* arguments */ Vec::default(), @@ -266,7 +266,7 @@ async fn checkpoint_with_shared_objects() { tokio::task::yield_now().await; let increment_counter_transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "increment", package_ref, vec![CallArg::SharedObject(counter_id)], diff --git a/crates/sui/tests/shared_objects_tests.rs b/crates/sui/tests/shared_objects_tests.rs index 06ed21410ac90..d30aa18937dac 100644 --- a/crates/sui/tests/shared_objects_tests.rs +++ b/crates/sui/tests/shared_objects_tests.rs @@ -81,7 +81,7 @@ async fn call_shared_object_contract() { tokio::task::yield_now().await; let transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "create", package_ref, /* arguments */ Vec::default(), @@ -94,7 +94,7 @@ async fn call_shared_object_contract() { tokio::task::yield_now().await; let transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "assert_value", package_ref, vec![ @@ -111,7 +111,7 @@ async fn call_shared_object_contract() { tokio::task::yield_now().await; let transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "increment", package_ref, vec![CallArg::SharedObject(counter_id)], @@ -125,7 +125,7 @@ async fn call_shared_object_contract() { tokio::task::yield_now().await; let transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "assert_value", package_ref, vec![ @@ -159,7 +159,7 @@ async fn shared_object_flood() { tokio::task::yield_now().await; let transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "create", package_ref, /* arguments */ Vec::default(), @@ -172,7 +172,7 @@ async fn shared_object_flood() { tokio::task::yield_now().await; let transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "assert_value", package_ref, vec![ @@ -189,7 +189,7 @@ async fn shared_object_flood() { tokio::task::yield_now().await; let transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "increment", package_ref, vec![CallArg::SharedObject(counter_id)], @@ -203,7 +203,7 @@ async fn shared_object_flood() { tokio::task::yield_now().await; let transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "assert_value", package_ref, vec![ @@ -235,7 +235,7 @@ async fn shared_object_sync() { tokio::task::yield_now().await; let create_counter_transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "create", package_ref, /* arguments */ Vec::default(), @@ -274,7 +274,7 @@ async fn shared_object_sync() { tokio::task::yield_now().await; let increment_counter_transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "increment", package_ref, vec![CallArg::SharedObject(counter_id)], @@ -336,7 +336,7 @@ async fn replay_shared_object_transaction() { tokio::task::yield_now().await; let create_counter_transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "create", package_ref, /* arguments */ Vec::default(), @@ -377,7 +377,7 @@ async fn shared_object_on_gateway() { tokio::task::yield_now().await; let create_counter_transaction = move_transaction( gas_objects.pop().unwrap(), - "Counter", + "counter", "create", package_ref, /* arguments */ Vec::default(), @@ -405,7 +405,7 @@ async fn shared_object_on_gateway() { let g = gateway.clone(); let increment_counter_transaction = move_transaction( gas_object, - "Counter", + "counter", "increment", package_ref, /* arguments */ vec![CallArg::SharedObject(shared_object_id)], @@ -426,7 +426,7 @@ async fn shared_object_on_gateway() { let assert_value_transaction = move_transaction( last_gas_object, - "Counter", + "counter", "assert_value", package_ref, vec![ diff --git a/crates/test-utils/src/messages.rs b/crates/test-utils/src/messages.rs index e40cdf6185fbc..f8550fe0fdeb1 100644 --- a/crates/test-utils/src/messages.rs +++ b/crates/test-utils/src/messages.rs @@ -86,7 +86,7 @@ pub fn test_shared_object_transactions() -> Vec { let mut transactions = Vec::new(); let shared_object_id = test_shared_object().id(); for gas_object in test_gas_objects() { - let module = "ObjectBasics"; + let module = "object_basics"; let function = "create"; let genesis_package_objects = genesis::clone_genesis_packages(); let package_object_ref = get_genesis_package_by_module(&genesis_package_objects, module); diff --git a/doc/src/build/json-rpc.md b/doc/src/build/json-rpc.md index de1d75f0903f1..1832e833d283b 100644 --- a/doc/src/build/json-rpc.md +++ b/doc/src/build/json-rpc.md @@ -202,9 +202,9 @@ curl --location --request POST $SUI_RPC_HOST \ "params": [ "{{owner_address}}", "0x2", - "Coin", + "coin", "transfer", - ["0x2::SUI::SUI"], + ["0x2::sui::sui"], ["{{coin_object_id}}", "{{recipient_address}}"], "{{gas_object_id}}", 2000 diff --git a/doc/src/build/move.md b/doc/src/build/move.md index 7066a39669a6a..5b660aad35085 100644 --- a/doc/src/build/move.md +++ b/doc/src/build/move.md @@ -92,7 +92,7 @@ file. Let's see how module definition appears in the `Coin` module file: ```rust -module Sui::Coin { +module sui::coin { ... } ``` @@ -124,7 +124,7 @@ file: ``` [addresses] -Sui = "0x2" +sui = "0x2" ``` ### Move structs @@ -241,7 +241,7 @@ simplest entry functions is defined in the to implement gas object transfer: ```rust -public entry fun transfer(c: Coin::Coin, recipient: address, _ctx: &mut TxContext) { +public entry fun transfer(c: coin::Coin, recipient: address, _ctx: &mut TxContext) { ... } ``` @@ -343,7 +343,7 @@ definitions in the `M1.move` file: ``` rust module MyFirstPackage::M1 { - use Sui::ID::VersionedID; + use sui::id::VersionedID; struct Sword has key, store { id: VersionedID, @@ -455,14 +455,14 @@ file: ``` rust #[test] public fun test_sword_create() { - use Sui::TxContext; + use sui::tx_context; // create a dummy TxContext for testing - let ctx = TxContext::dummy(); + let ctx = tx_context::dummy(); // create a sword let sword = Sword { - id: TxContext::new_id(&mut ctx), + id: tx_context::new_id(&mut ctx), magic: 42, strength: 7, }; @@ -477,7 +477,7 @@ create a dummy instance of the `TxContext` struct needed to create a unique identifier of our sword object, then create the sword itself, and finally call its accessor functions to verify that they return correct values. Note the dummy context is passed to the -`TxContext::new_id` function as a mutable reference argument (`&mut`), +`tx_context::new_id` function as a mutable reference argument (`&mut`), and the sword itself is passed to its accessor functions as a read-only reference argument. @@ -500,7 +500,7 @@ error[E06001]: unused value without 'drop' 27 │ let sword = Sword { │ ----- The local variable 'sword' still contains a value. The value does not have the 'drop' ability and must be consumed before the function returns │ ╭─────────────────────' -28 │ │ id: TxContext::new_id(&mut ctx), +28 │ │ id: tx_context::new_id(&mut ctx), 29 │ │ magic: 42, 30 │ │ strength: 7, 31 │ │ }; @@ -536,7 +536,7 @@ the beginning of our testing function to import the [Transfer module](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/Transfer.move): ``` rust - use Sui::Transfer; + use sui::transfer; ``` @@ -547,7 +547,7 @@ the end of our test function: ``` rust // create a dummy address and transfer the sword let dummy_address = @0xCAFE; - Transfer::transfer(sword, dummy_address); + transfer::transfer(sword, dummy_address); ``` We can now run the test command again and see that indeed a single @@ -580,7 +580,7 @@ $ sui-move test -h The testing example we have seen so far is largely *pure Move* and has little to do with Sui beyond using some Sui packages, such as -`Sui::TxContext` and `Sui::Transfer`. While this style of testing is +`sui::tx_context` and `sui::transfer`. While this style of testing is already very useful for developers writing Move code for Sui, they may also want to test additional Sui-specific features. In particular, a Move call in Sui is encapsulated in a Sui @@ -590,15 +590,15 @@ transactions within a single test (e.g. one transaction creating an object and the other one transferring it). Sui-specific testing is supported via the -[TestScenario module](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/TestScenario.move) +[test_scenario module](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/test_scenario.move) that provides Sui-related testing functionality otherwise unavailable in *pure Move* and its [testing framework](https://github.com/move-language/move/blob/main/language/documentation/book/src/unit-testing.md). -The main concept in the `TestScenario` is a scenario that emulates a +The main concept in the `test_scenario` is a scenario that emulates a series of Sui transactions, each executed by a (potentially) different user. At a high level, a developer writing a test starts the first -transaction using the `TestScenario::begin` function that takes an +transaction using the `test_scenario::begin` function that takes an address of the user executing this transaction as the first and only argument and returns an instance of the `Scenario` struct representing a scenario. @@ -607,34 +607,34 @@ An instance of the `Scenario` struct contains a per-address object pool emulating Sui's object storage, with helper functions provided to manipulate objects in the pool. Once the first transaction is finished, subsequent transactions can be started using -the `TestScenario::next_tx` function that takes an instance of the +the `test_scenario::next_tx` function that takes an instance of the `Scenario` struct representing the current scenario and an address of a (new) user as arguments. Let us extend our running example with a multi-transaction test that -uses the `TestScenario` to test sword creation and transfer from the +uses the `test_scenario` to test sword creation and transfer from the point of view of a Sui developer. First, let us create [entry functions](#entry-functions) callable from Sui that implement sword creation and transfer and put them into the `M1.move` file: ``` rust public entry fun sword_create(magic: u64, strength: u64, recipient: address, ctx: &mut TxContext) { - use Sui::Transfer; - use Sui::TxContext; + use sui::transfer; + use sui::tx_context; // create a sword let sword = Sword { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), magic: magic, strength: strength, }; // transfer the sword - Transfer::transfer(sword, recipient); + transfer::transfer(sword, recipient); } public entry fun sword_transfer(sword: Sword, recipient: address, _ctx: &mut TxContext) { - use Sui::Transfer; + use sui::transfer; // transfer the sword - Transfer::transfer(sword, recipient); + transfer::transfer(sword, recipient); } ``` @@ -649,7 +649,7 @@ existing module-wide `ID` module import) to make the `TxContext` struct available for function definitions: ``` rust - use Sui::TxContext::TxContext; + use sui::tx_context::TxContext; ``` We can now build the module extended with the new functions but still @@ -659,35 +659,35 @@ function. ``` rust #[test] fun test_sword_transactions() { - use Sui::TestScenario; + use sui::test_scenario; let admin = @0xABBA; let initial_owner = @0xCAFE; let final_owner = @0xFACE; // first transaction executed by admin - let scenario = &mut TestScenario::begin(&admin); + let scenario = &mut test_scenario::begin(&admin); { // create the sword and transfer it to the initial owner - sword_create(42, 7, initial_owner, TestScenario::ctx(scenario)); + sword_create(42, 7, initial_owner, test_scenario::ctx(scenario)); }; // second transaction executed by the initial sword owner - TestScenario::next_tx(scenario, &initial_owner); + test_scenario::next_tx(scenario, &initial_owner); { // extract the sword owned by the initial owner - let sword = TestScenario::take_owned(scenario); + let sword = test_scenario::take_owned(scenario); // transfer the sword to the final owner - sword_transfer(sword, final_owner, TestScenario::ctx(scenario)); + sword_transfer(sword, final_owner, test_scenario::ctx(scenario)); }; // third transaction executed by the final sword owner - TestScenario::next_tx(scenario, &final_owner); + test_scenario::next_tx(scenario, &final_owner); { // extract the sword owned by the final owner - let sword = TestScenario::take_owned(scenario); + let sword = test_scenario::take_owned(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") - TestScenario::return_owned(scenario, sword) + test_scenario::return_owned(scenario, sword) } } ``` @@ -701,11 +701,11 @@ address that creates a sword and transfers its ownership to the initial owner. The second transaction is executed by the initial owner (passed as an -argument to the `TestScenario::next_tx` function) who then transfers +argument to the `test_scenario::next_tx` function) who then transfers 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 +storage. This is where the `test_scenario` module comes to help - its `take_owned` 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 @@ -722,10 +722,10 @@ disappear. In the *pure Move* testing function, we handled this problem by transferring the sword object to the fake address. But the -`TestScenario` package gives us a more elegant solution, which is +`test_scenario` package gives us a more elegant solution, which is closer to what happens when Move code is actually executed in the context of Sui - we can simply return the sword to the object pool -using the `TestScenario::return_owned` function. +using the `test_scenario::return_owned` function. We can now run the test command again and see that we now have two successful tests for our module: @@ -822,15 +822,15 @@ And module initializer is the perfect place to do it: ``` rust // module initializer to be executed when this module is published fun init(ctx: &mut TxContext) { - use Sui::Transfer; - use Sui::TxContext; + use sui::transfer; + use sui::tx_context; let admin = Forge { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), swords_created: 0, }; // transfer the forge object to the module/package publisher // (presumably the game admin) - Transfer::transfer(admin, TxContext::sender(ctx)); + transfer::transfer(admin, tx_context::sender(ctx)); } ``` @@ -850,26 +850,26 @@ We can now create a function to test the module initialization: ``` rust #[test] public fun test_module_init() { - use Sui::TestScenario; + use sui::test_scenario; // create test address representing game admin let admin = @0xABBA; // first transaction to emulate module initialization - let scenario = &mut TestScenario::begin(&admin); + let scenario = &mut test_scenario::begin(&admin); { - init(TestScenario::ctx(scenario)); + init(test_scenario::ctx(scenario)); }; // second transaction to check if the forge has been created // and has initial value of zero swords created - TestScenario::next_tx(scenario, &admin); + test_scenario::next_tx(scenario, &admin); { // extract the Forge object - let forge = TestScenario::take_owned(scenario); + let forge = test_scenario::take_owned(scenario); // verify number of created swords assert!(swords_created(&forge) == 0, 1); // return the Forge object to the object pool - TestScenario::return_owned(scenario, forge) + test_scenario::return_owned(scenario, forge) } } @@ -903,9 +903,9 @@ The [`Transfer`](https://github.com/MystenLabs/sui/blob/main/crates/sui-framewor The most common case is to transfer an object to an account address. For example, when a new object is created, it is typically transferred to an account address so that the address owns the object. To transfer an object `obj` to an account address `recipient`: ``` -use Sui::Transfer; +use sui::transfer; -Transfer::transfer(obj, recipient); +transfer::transfer(obj, recipient); ``` This call will fully consume the object, making it no longer accessible in the current transaction. Once an account address owns an object, for any future use (either read or write) of this object, the signer of the transaction must be the owner of the object. @@ -921,28 +921,28 @@ public entry fun entry_function(a: &A, b: &B, c: &mut C, ctx: &mut TxContext); A common pattern of object owning another object is to have a field in the parent object to track the ID of the child object. It is important to ensure that we keep such a field's value consistent with the actual ownership relationship. For example, we do not end up in a situation where the parent's child field contains an ID pointing to object A, while in fact the parent owns object B. To ensure the consistency, we defined a custom type called `ChildRef` to represent object ownership. Whenever an object is transferred to another object, a `ChildRef` instance is created to uniquely identify the ownership. The library implementation ensures that the `ChildRef` goes side-by-side with the child object so that we never lose track or mix up objects. To transfer an object `obj` (whose owner is an account address) to another object `owner`: ``` -Transfer::transfer_to_object(obj, &mut owner); +transfer::transfer_to_object(obj, &mut owner); ``` This function returns a `ChildRef` instance that cannot be dropped arbitrarily. It can be stored in the parent as a field. Sometimes we need to set the child field of a parent while constructing it. In this case, we don't yet have a parent object to transfer into. In this case, we can call the `transfer_to_object_id` API. Example: ``` -let parent_id = TxContext::new_id(ctx); -let child = Child { id: TxContext::new_id(ctx) }; -let (parent_id, child_ref) = Transfer::transfer_to_object_id(child, parent_id); +let parent_id = tx_context::new_id(ctx); +let child = Child { id: tx_context::new_id(ctx) }; +let (parent_id, child_ref) = transfer::transfer_to_object_id(child, parent_id); let parent = Parent { id: parent_id, child: child_ref, }; -Transfer::transfer(parent, TxContext::sender(ctx)); +transfer::transfer(parent, tx_context::sender(ctx)); ``` To transfer an object `child` from one parent object to a new parent object `new_parent`, we can use the following API: ``` -Transfer::transfer_child_to_object(child, child_ref, &mut new_parent); +transfer::transfer_child_to_object(child, child_ref, &mut new_parent); ``` Note that in this call, we must also have the `child_ref` to prove the original ownership. The call will return a new instance of `ChildRef` that the new parent can maintain. To transfer an object `child` from an object to an account address `recipient`, we can use the following API: ``` -Transfer::transfer_child_to_address(child, child_ref, recipient); +transfer::transfer_child_to_address(child, child_ref, recipient); ``` This call also requires to have the `child_ref` as proof of original ownership. After this transfer, the object will be owned by `recipient`. @@ -953,7 +953,7 @@ More examples of how objects can be transferred and owned can be found in #### Freeze an object To make an object `obj` shared and immutable, one can call: ``` -Transfer::freeze_object(obj); +transfer::freeze_object(obj); ``` After this call, `obj` becomes immutable which means it can never be mutated or deleted. This process is also irreversible: once an object is frozen, it will stay frozen forever. An immutable object can be used as reference by anyone in their Move call. @@ -962,7 +962,7 @@ This feature is still in development. It only works in Move for demo purpose, an To make an object `obj` shared and mutable, one can call: ``` -Transfer::share_object(obj); +transfer::share_object(obj); ``` After this call, `obj` stays mutable, but becomes shared by everyone, i.e. anyone can send a transaction to mutate this object. However, such an object cannot be deleted, transferred or embedded in another object as a field. @@ -973,15 +973,15 @@ Shared mutable object can be powerful in that it will make programming a lot sim To create a new ID for a new object: ``` -use Sui::TxContext; +use sui::tx_context; // assmue `ctx` has type `&mut TxContext`. -let id = TxContext::new_id(ctx); +let id = tx_context::new_id(ctx); ``` To obtain the current transaction sender's account address: ``` -TxContext::sender(ctx) +tx_context::sender(ctx) ``` ## Next steps 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 c7e2d8dddde72..85dea65e68175 100644 --- a/doc/src/build/programming-with-objects/ch1-object-basics.md +++ b/doc/src/build/programming-with-objects/ch1-object-basics.md @@ -14,7 +14,7 @@ struct Color { The above `struct` defines a data structure that can represent RGB color. `struct`s like this can be used to organize data with complicated semantics. However, instances of `struct`s like `Color` are not Sui objects yet. To define a struct that represents a Sui object type, we must add a `key` capability to the definition, and the first field of the struct must be the `id` of the object with type `VersionedID` from the [ID library](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/ID.move): ```rust -use Sui::ID::VersionedID; +use sui::id::VersionedID; struct ColorObject has key { id: VersionedID, @@ -29,16 +29,16 @@ Now `ColorObject` represents a Sui object type and can be used to create Sui obj > :bulb: The `VersionedID` type is internal to Sui, and you most likely won't need to deal with it directly. For curious readers, it contains the unique `ID` of the object and the version of the object. Each time a mutable object is used in a transaction, its version will increase by 1. ### Create Sui object -Now that we have learned how to define a Sui object type, how do we create/instantiate a Sui object? In order to create a new Sui object from its type, we must assign an initial value to each of the fields, including `id`. The only way to create a new unique `VersionedID` for a Sui object is to call `TxContext::new_id`. The `new_id` function takes the current transaction context as an argument to generate unique IDs. The transaction context is of type `&mut TxContext` and should be passed down from an [entry function](../move.md#entry-functions) (a function that can be called directly from a transaction). Let's look at how we may define a constructor for `ColorObject`: +Now that we have learned how to define a Sui object type, how do we create/instantiate a Sui object? In order to create a new Sui object from its type, we must assign an initial value to each of the fields, including `id`. The only way to create a new unique `VersionedID` for a Sui object is to call `tx_context::new_id`. The `new_id` function takes the current transaction context as an argument to generate unique IDs. The transaction context is of type `&mut TxContext` and should be passed down from an [entry function](../move.md#entry-functions) (a function that can be called directly from a transaction). Let's look at how we may define a constructor for `ColorObject`: ```rust -/// TxContext::Self represents the TxContext module, which allows us call +/// tx_context::Self represents the TxContext module, which allows us call /// functions in the module, such as the `new_id` function. -/// TxContext::TxContext represents the TxContext struct in TxContext module. -use Sui::TxContext::{Self, TxContext}; +/// tx_context::TxContext represents the TxContext struct in TxContext module. +use sui::tx_context::{Self, TxContext}; fun new(red: u8, green: u8, blue: u8, ctx: &mut TxContext): ColorObject { ColorObject { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), red, green, blue, @@ -59,16 +59,16 @@ This places `obj` in global storage along with metadata that records `recipient` > :bulb: In core Move, we would call `move_to(a: address, t: T)` to add the entry `(a, T) -> t` to the global storage. But because (as explained above) the schema of Sui Move's global storage is different, we use the `Transfer` APIs instead of `move_to` or the other [global storage operators](https://github.com/move-language/move/blob/main/language/documentation/book/src/global-storage-operators.md) in core Move. These operators cannot be used in Sui Move. A common use of this API is to transfer the object to the sender/signer of the current transaction (e.g., mint an NFT owned by you). The only way to obtain the sender of the current transaction is to rely on the transaction context passed in from an entry function. The last argument to an entry function must be the current transaction context, defined as `ctx: &mut TxContext`. -To obtain the current signer's address, one can call `TxContext::sender(ctx)`. +To obtain the current signer's address, one can call `tx_context::sender(ctx)`. Below is the code that creates a new `ColorObject` and makes it owned by the sender of the transaction: ```rust -use Sui::Transfer; +use sui::transfer; // This is an entry function that can be called directly by a Transaction. public entry fun create(red: u8, green: u8, blue: u8, ctx: &mut TxContext) { let color_object = new(red, green, blue, ctx); - Transfer::transfer(color_object, TxContext::sender(ctx)) + transfer::transfer(color_object, tx_context::sender(ctx)) } ``` > :bulb: Naming convention: Constructors are typically named **`new`**, which returns an instance of the struct type. The **`create`** function is typically defined as an entry function that constructs the struct and transfers it to the desired owner (most commonly the sender). @@ -90,22 +90,22 @@ sui-move build ### Writing unit tests After defining the `create` function, we want to test this function in Move using unit tests, without having to go all the way through sending Sui transactions. Since [Sui manages global storage separately outside of Move](../../learn/sui-move-diffs.md#object-centric-global-storage), there is no direct way to retrieve objects from global storage within Move. This poses a question: after calling the `create` function, how do we check that the object is properly transferred? -To assist easy testing in Move, we provide a comprehensive testing framework in the [TestScenario](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/TestScenario.move) module that allows us to interact with objects put into the global storage. This allows us to test the behavior of any function directly in Move unit tests. A lot of this is also covered in our [Move testing doc](../move.md#sui-specific-testing). +To assist easy testing in Move, we provide a comprehensive testing framework in the [test_scenario](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/test_scenario.move) module that allows us to interact with objects put into the global storage. This allows us to test the behavior of any function directly in Move unit tests. A lot of this is also covered in our [Move testing doc](../move.md#sui-specific-testing). -The idea of `TestScenario` is to emulate a series of Sui transactions, each sent from a particular address. A developer writing a test starts the first transaction using the `TestScenario::begin` function that takes the address of the user sending this transaction as an argument and returns an instance of the `Scenario` struct representing a test scenario. +The idea of `test_scenario` is to emulate a series of Sui transactions, each sent from a particular address. A developer writing a test starts the first transaction using the `test_scenario::begin` function that takes the address of the user sending this transaction as an argument and returns an instance of the `Scenario` struct representing a test scenario. -An instance of the `Scenario` struct contains a per-address object pool emulating Sui's object storage, with helper functions provided to manipulate objects in the pool. Once the first transaction is finished, subsequent transactions can be started using the `TestScenario::next_tx` function that takes an instance of the `Scenario` struct representing the current scenario and an address of a (new) user as arguments. +An instance of the `Scenario` struct contains a per-address object pool emulating Sui's object storage, with helper functions provided to manipulate objects in the pool. Once the first transaction is finished, subsequent transactions can be started using the `test_scenario::next_tx` function that takes an instance of the `Scenario` struct representing the current scenario and an address of a (new) user as arguments. -Now let's try to write a test for the `create` function. Tests that need to use `TestScenario` must be in a separate module, either under a `tests` directory, or in the same file but in a module annotated with `#[test_only]`. This is because `TestScenario` itself is a test-only module, and can be used only by test-only modules. +Now let's try to write a test for the `create` function. Tests that need to use `test_scenario` must be in a separate module, either under a `tests` directory, or in the same file but in a module annotated with `#[test_only]`. This is because `test_scenario` itself is a test-only module, and can be used only by test-only modules. First of all, we begin the test with a hardcoded test address, which will also give us a transaction context as if we are sending a transaction from this address. We then call the `create` function, which should create a `ColorObject` and transfer it to the test address: ```rust let owner = @0x1; // Create a ColorObject and transfer it to @owner. -let scenario = &mut TestScenario::begin(&owner); +let scenario = &mut test_scenario::begin(&owner); { - let ctx = TestScenario::ctx(scenario); - ColorObject::create(255, 0, 255, ctx); + let ctx = test_scenario::ctx(scenario); + color_object::create(255, 0, 255, ctx); }; ``` >:books: Note there is a "`;`" after "`}`". This is required except for the last statement in the function. Refer to the [Move book](https://move-book.com/syntax-basics/expression-and-scope.html) for a detailed explanation. @@ -114,29 +114,29 @@ Now account `@0x1` should own the object. Let's first make sure it's not owned b ```rust let not_owner = @0x2; // Check that @not_owner does not own the just-created ColorObject. -TestScenario::next_tx(scenario, ¬_owner); +test_scenario::next_tx(scenario, ¬_owner); { - assert!(!TestScenario::can_take_owned(scenario), 0); + assert!(!test_scenario::can_take_owned(scenario), 0); }; ``` -`TestScenario::next_tx` switches the transaction sender to `@0x2`, which is a new address than the previous one. -`TestScenario::can_take_owned` 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. +`test_scenario::next_tx` switches the transaction sender to `@0x2`, which is a new address than the previous one. +`test_scenario::can_take_owned` 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); +test_scenario::next_tx(scenario, &owner); { - let object = TestScenario::take_owned(scenario); - let (red, green, blue) = ColorObject::get_color(&object); + let object = test_scenario::take_owned(scenario); + let (red, green, blue) = color_object::get_color(&object); assert!(red == 255 && green == 0 && blue == 255, 0); - TestScenario::return_owned(scenario, object); + test_scenario::return_owned(scenario, object); }; ``` -`TestScenario::take_owned` removes the object of given type from global storage that's owned by the current transaction sender (it also implicitly checks `can_take_owned`). 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_owned` 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. +`test_scenario::take_owned` removes the object of given type from global storage that's owned by the current transaction sender (it also implicitly checks `can_take_owned`). 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 `test_scenario::return_owned` 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. Again, you can find the full code in [ColorObject.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/objects_tutorial/sources/ColorObject.move). @@ -191,7 +191,7 @@ Owner: AddressOwner(k#5db53ebb05fd3ea5f1d163d9d487ee8cd7b591ee) Version: 1 ID: 0x5eb2c3e55693282faa7f5b07ce1c4803e6fdc1bb Readonly: false -Type: 0x57258f32746fd1443f2a077c0c6ec03282087c19::ColorObject +Type: 0x57258f32746fd1443f2a077c0c6ec03282087c19::color_object::ColorObject ``` As we can see, it's owned by the current default wallet address that we saw earlier. And the type of this object is `ColorObject`! 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 ef2f97fb5cfc2..969212d08a506 100644 --- a/doc/src/build/programming-with-objects/ch2-using-objects.md +++ b/doc/src/build/programming-with-objects/ch2-using-objects.md @@ -34,44 +34,44 @@ In the above function signature, `from_object` can be a read-only reference beca > :bulb: Although `from_object` is a read-only reference in this transaction, it is still a mutable object in Sui storage--another transaction could be sent to mutate the object at the same time! To prevent this, Sui must lock any mutable object used as a transaction input, even when it's passed as a read-only reference. In addition, only an object's owner can send a transaction that locks the object. Let's write a unit test to see how we could interact with multiple objects of the same type in tests. -In the previous chapter, we introduced the `take_owned` API, which takes an object of type `T` from the global storage created by previous transactions. However, what if there are multiple objects of the same type? `take_owned` will no longer be able to tell which one to return. To solve this problem, we need to use two new APIs. The first is `TxContext::last_created_object_id(ctx)`, which returns the ID of the most recent created object. The second is `TestScenario::take_owned_by_id`, which returns an object of type `T` with a specific object ID. +In the previous chapter, we introduced the `take_owned` API, which takes an object of type `T` from the global storage created by previous transactions. However, what if there are multiple objects of the same type? `take_owned` will no longer be able to tell which one to return. To solve this problem, we need to use two new APIs. The first is `tx_context::last_created_object_id(ctx)`, which returns the ID of the most recent created object. The second is `test_scenario::take_owned_by_id`, which returns an object of type `T` with a specific object ID. Now let's take a look at the test (`test_copy_into`): ```rust let owner = @0x1; -let scenario = &mut TestScenario::begin(&owner); +let scenario = &mut test_scenario::begin(&owner); // Create two ColorObjects owned by `owner`, and obtain their IDs. let (id1, id2) = { - let ctx = TestScenario::ctx(scenario); - ColorObject::create(255, 255, 255, ctx); - let id1 = TxContext::last_created_object_id(ctx); - ColorObject::create(0, 0, 0, ctx); - let id2 = TxContext::last_created_object_id(ctx); + let ctx = test_scenario::ctx(scenario); + color_object::create(255, 255, 255, ctx); + let id1 = tx_context::last_created_object_id(ctx); + color_object::create(0, 0, 0, ctx); + let id2 = tx_context::last_created_object_id(ctx); (id1, id2) }; ``` -The above code created two objects. Note that right after each call, we make a call to `TxContext::last_created_object_id` to get the ID of the object just created. At the end we have `id1` and `id2` capturing the IDs of the two objects. Next we retrieve both of them and test the `copy_into` method: +The above code created two objects. Note that right after each call, we make a call to `tx_context::last_created_object_id` to get the ID of the object just created. At the end we have `id1` and `id2` capturing the IDs of the two objects. Next we retrieve both of them and test the `copy_into` method: ```rust -TestScenario::next_tx(scenario, &owner); +test_scenario::next_tx(scenario, &owner); { - let obj1 = TestScenario::take_owned_by_id(scenario, id1); - let obj2 = TestScenario::take_owned_by_id(scenario, id2); - let (red, green, blue) = ColorObject::get_color(&obj1); + let obj1 = test_scenario::take_owned_by_id(scenario, id1); + let obj2 = test_scenario::take_owned_by_id(scenario, id2); + let (red, green, blue) = color_object::get_color(&obj1); assert!(red == 255 && green == 255 && blue == 255, 0); - let ctx = TestScenario::ctx(scenario); - ColorObject::copy_into(&obj2, &mut obj1); - TestScenario::return_owned(scenario, obj1); - TestScenario::return_owned(scenario, obj2); + let ctx = test_scenario::ctx(scenario); + color_object::copy_into(&obj2, &mut obj1); + test_scenario::return_owned(scenario, obj1); + test_scenario::return_owned(scenario, obj2); }; ``` We used `take_owned_by_id` to take both objects using different IDs. We then used `copy_into` to update `obj1`'s value using `obj2`'s. We can verify that the mutation works: ```rust -TestScenario::next_tx(scenario, &owner); +test_scenario::next_tx(scenario, &owner); { - let obj1 = TestScenario::take_owned_by_id(scenario, id1); - let (red, green, blue) = ColorObject::get_color(&obj1); + let obj1 = test_scenario::take_owned_by_id(scenario, id1); + let (red, green, blue) = color_object::get_color(&obj1); assert!(red == 0 && green == 0 && blue == 0, 0); - TestScenario::return_owned(scenario, obj1); + test_scenario::return_owned(scenario, obj1); } ``` @@ -93,30 +93,30 @@ Let's define a function in the `ColorObject` module that allows us to delete the ```rust public entry fun delete(object: ColorObject) { let ColorObject { id, red: _, green: _, blue: _ } = object; - ID::delete(id); + id::delete(id); } ``` -As we can see, the object is unpacked, generating individual fields. The u8 values are primitive types and can all be dropped. However the `id` cannot be dropped and must be explicitly deleted through the `ID::delete` API. At the end of this call, the object will no longer be stored on-chain. +As we can see, the object is unpacked, generating individual fields. The u8 values are primitive types and can all be dropped. However the `id` cannot be dropped and must be explicitly deleted through the `id::delete` API. At the end of this call, the object will no longer be stored on-chain. We can add a unit test for it, as well: ```rust let owner = @0x1; // Create a ColorObject and transfer it to @owner. -let scenario = &mut TestScenario::begin(&owner); +let scenario = &mut test_scenario::begin(&owner); { - let ctx = TestScenario::ctx(scenario); - ColorObject::create(255, 0, 255, ctx); + let ctx = test_scenario::ctx(scenario); + color_object::create(255, 0, 255, ctx); }; // Delete the ColorObject we just created. -TestScenario::next_tx(scenario, &owner); +test_scenario::next_tx(scenario, &owner); { - let object = TestScenario::take_owned(scenario); - ColorObject::delete(object); + let object = test_scenario::take_owned(scenario); + color_object::delete(object); }; // Verify that the object was indeed deleted. -TestScenario::next_tx(scenario, &owner); +test_scenario::next_tx(scenario, &owner); { - assert!(!TestScenario::can_take_owned(scenario), 0); + assert!(!test_scenario::can_take_owned(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 puts it in 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, it is impossible) to return it to the storage. The last part of the test checks that the object is indeed no longer in the global storage and hence cannot be retrieved from there. @@ -125,40 +125,40 @@ The first part is the same as what we have seen in [Chapter 1](./ch1-object-basi The owner of the object may want to transfer it to another account. To support this, the `ColorObject` module will need to define a `transfer` API: ```rust public entry fun transfer(object: ColorObject, recipient: address) { - Transfer::transfer(object, recipient) + transfer::transfer(object, recipient) } ``` ->:bulb: One cannot call `Transfer::transfer` directly as it is not an `entry` function. +>:bulb: One cannot call `transfer::transfer` directly as it is not an `entry` function. Let's add a test for transferring too. First of all, we create an object in `owner`'s account and then transfer it to a different account `recipient`: ```rust let owner = @0x1; // Create a ColorObject and transfer it to @owner. -let scenario = &mut TestScenario::begin(&owner); +let scenario = &mut test_scenario::begin(&owner); { - let ctx = TestScenario::ctx(scenario); - ColorObject::create(255, 0, 255, ctx); + let ctx = test_scenario::ctx(scenario); + color_object::create(255, 0, 255, ctx); }; // Transfer the object to recipient. let recipient = @0x2; -TestScenario::next_tx(scenario, &owner); +test_scenario::next_tx(scenario, &owner); { - let object = TestScenario::take_owned(scenario); - let ctx = TestScenario::ctx(scenario); - ColorObject::transfer(object, recipient, ctx); + let object = test_scenario::take_owned(scenario); + let ctx = test_scenario::ctx(scenario); + color_object::transfer(object, recipient, ctx); }; ``` Note that in the second transaction, the sender of the transaction should still be `owner`, because only the `owner` can transfer the object that it owns. After the tranfser, we can verify that `owner` no longer owns the object, while `recipient` now owns it: ```rust // Check that owner no longer owns the object. -TestScenario::next_tx(scenario, &owner); +test_scenario::next_tx(scenario, &owner); { - assert!(!TestScenario::can_take_owned(scenario), 0); + assert!(!test_scenario::can_take_owned(scenario), 0); }; // Check that recipient now owns the object. -TestScenario::next_tx(scenario, &recipient); +test_scenario::next_tx(scenario, &recipient); { - assert!(TestScenario::can_take_owned(scenario), 0); + assert!(test_scenario::can_take_owned(scenario), 0); }; ``` diff --git a/doc/src/build/programming-with-objects/ch3-immutable-objects.md b/doc/src/build/programming-with-objects/ch3-immutable-objects.md index 2058779fcd87e..b3f206ef4ae38 100644 --- a/doc/src/build/programming-with-objects/ch3-immutable-objects.md +++ b/doc/src/build/programming-with-objects/ch3-immutable-objects.md @@ -17,17 +17,17 @@ After this call, the specified object will become permanently immutable. This is Let's add an entry function to the [ColorObject](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/objects_tutorial/sources/ColorObject.move) module to turn an existing (owned) `ColorObject` into an immutable object: ```rust public entry fun freeze_object(object: ColorObject) { - Transfer::freeze_object(object) + transfer::freeze_object(object) } ``` In the above function, one must already own a `ColorObject` to be able to pass it in. At the end of this call, this object is *frozen* and can never be mutated. It is also no longer owned by anyone. -> :bulb: Note the `Transfer::freeze_object` API requires passing the object by value. Had we allowed passing the object by a mutable reference, we would then still be able to mutate the object after the `freeze_object` call; this contradicts the fact that it should have become immutable. +> :bulb: Note the `transfer::freeze_object` API requires passing the object by value. Had we allowed passing the object by a mutable reference, we would then still be able to mutate the object after the `freeze_object` call; this contradicts the fact that it should have become immutable. Alternatively, you can also provide an API that creates an immutable object at birth: ```rust public entry fun create_immutable(red: u8, green: u8, blue: u8, ctx: &mut TxContext) { let color_object = new(red, green, blue, ctx); - Transfer::freeze_object(color_object) + transfer::freeze_object(color_object) } ``` In this function, a fresh new `ColorObject` is created and immediately turned into an immutable object before being owned by anyone. @@ -48,22 +48,22 @@ Since immutable objects can never be mutated, there will never be a data race ev ### Test immutable object Let's take a look at how we interact with immutable objects in unit tests. -Previously, we used the `TestScenario::take_owned` API to take an object from the global storage that's owned by the sender of the transaction in a unit test. And `take_owned` returns an object by value, which allows you to mutate, delete or transfer it. +Previously, we used the `test_scenario::take_owned` API to take an object from the global storage that's owned by the sender of the transaction in a unit test. And `take_owned` returns an object by value, which allows you to mutate, delete or transfer it. -To take an immutable object, we will need to use a new API: `TestScenario::take_immutable`. This is required because immutable objects can be accessed only through read-only references. To ensure this, instead of returning the object directly, `take_immutable` returns a wrapper, which we will need to make another call to get a read-only reference: `TestScenario::borrow`. +To take an immutable object, we will need to use a new API: `test_scenario::take_immutable`. This is required because immutable objects can be accessed only through read-only references. To ensure this, instead of returning the object directly, `take_immutable` returns a wrapper, which we will need to make another call to get a read-only reference: `test_scenario::borrow`. Let's see it work in action (`ColorObjectTests::test_immutable`): ```rust let sender1 = @0x1; -let scenario = &mut TestScenario::begin(&sender1); +let scenario = &mut test_scenario::begin(&sender1); { - let ctx = TestScenario::ctx(scenario); - ColorObject::create_immutable(255, 0, 255, ctx); + let ctx = test_scenario::ctx(scenario); + color_object::create_immutable(255, 0, 255, ctx); }; -TestScenario::next_tx(scenario, &sender1); +test_scenario::next_tx(scenario, &sender1); { // take_owned does not work for immutable objects. - assert!(!TestScenario::can_take_owned(scenario), 0); + assert!(!test_scenario::can_take_owned(scenario), 0); }; ``` In this test, we submit a transaction as `sender1`, which would create an immutable object. @@ -71,13 +71,13 @@ As we can see above, `can_take_owned` will no longer return `true`, ```rust // Any sender can work. let sender2 = @0x2; -TestScenario::next_tx(scenario, &sender2); +test_scenario::next_tx(scenario, &sender2); { - let object_wrapper = TestScenario::take_immutable(scenario); - let object = TestScenario::borrow(&object_wrapper); - let (red, green, blue) = ColorObject::get_color(object); + let object_wrapper = test_scenario::take_immutable(scenario); + let object = test_scenario::borrow(&object_wrapper); + let (red, green, blue) = color_object::get_color(object); assert!(red == 255 && green == 0 && blue == 255, 0); - TestScenario::return_immutable(scenario, object_wrapper); + test_scenario::return_immutable(scenario, object_wrapper); }; ``` To show that this object is indeed not owned by anyone, we start the next transaction with `sender2`. As explained earlier, we used `take_immutable` and subsequently `borrow` to obtain a read-only reference to the object. It succeeded! This means that any sender will be able to take an immutable object. In the end, to return the object, we also need to call a new API: `return_immutable`. @@ -94,9 +94,9 @@ public entry fun update( } ``` To summarize, we introduced three new API functions to interact with immutable objects in unit tests: -- `TestScenario::take_immutable` to take an immutable object wrapper from global storage. -- `TestScenario::borrow` to obtain a read-only reference from the wrapper above. -- `TestScenario::return_mmutable` to return the wrapper back to the global storage. +- `test_scenario::take_immutable` to take an immutable object wrapper from global storage. +- `test_scenario::borrow` to obtain a read-only reference from the wrapper above. +- `test_scenario::return_mmutable` to return the wrapper back to the global storage. ### On-chain interactions @@ -114,7 +114,7 @@ Set the package object ID to the `$PACKAGE` environment variable as we did in pr Then create a new `ColorObject`: ``` -$ wallet call --gas-budget 1000 --package $PACKAGE --module "ColorObject" --function "create" --args 0 255 0 +$ wallet call --gas-budget 1000 --package $PACKAGE --module "color_object" --function "create" --args 0 255 0 ``` Set the newly created object ID to `$OBJECT`. If we look at the list of objects in the current active account address's wallet: ``` @@ -122,7 +122,7 @@ $ wallet objects --address=$ADDR ``` There should be one more, with ID `$OBJECT`. Let's turn it into an immutable object: ``` -$ wallet call --gas-budget 1000 --package $PACKAGE --module "ColorObject" --function "freeze_object" --args \"0x$OBJECT\" +$ wallet call --gas-budget 1000 --package $PACKAGE --module "color_object" --function "freeze_object" --args \"0x$OBJECT\" ``` Now let's look at the list of objects we own again: ``` @@ -136,6 +136,6 @@ Owner: Immutable ``` If we try to mutate it: ``` -$ wallet call --gas-budget 1000 --package $PACKAGE --module "ColorObject" --function "update" --args \"0x$OBJECT\" 0 0 0 +$ wallet call --gas-budget 1000 --package $PACKAGE --module "color_object" --function "update" --args \"0x$OBJECT\" 0 0 0 ``` It will complain that an immutable object cannot be passed to a mutable argument. diff --git a/doc/src/build/programming-with-objects/ch4-object-wrapping.md b/doc/src/build/programming-with-objects/ch4-object-wrapping.md index e71816543a2db..09859ced4c73e 100644 --- a/doc/src/build/programming-with-objects/ch4-object-wrapping.md +++ b/doc/src/build/programming-with-objects/ch4-object-wrapping.md @@ -51,17 +51,17 @@ In a real application, we probably would make sure that there is a limited suppl ```rust public entry fun create_object(scarcity: u8, style: u8, ctx: &mut TxContext) { let object = Object { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), scarcity, style, }; - Transfer::transfer(object, TxContext::sender(ctx)) + transfer::transfer(object, tx_context::sender(ctx)) } ``` Anyone can call `create_object` to create a new object with specified `scarcity` and `style`. The created object will be sent to the signer of the transaction. We will likely also want to be able to transfer the object to others: ```rust public entry fun transfer_object(object: Object, ctx: &mut TxContext) { - Transfer::transfer(object, TxContext::sender(ctx)) + transfer::transfer(object, tx_context::sender(ctx)) } ``` @@ -83,14 +83,14 @@ struct ObjectWrapper has key { `ObjectWrapper` defines a Sui object type, wraps the object that we want to swap as `to_swap`, and tracks the original owner of the object in `original_owner`. To make this more interesting and realistic, we can also expect that we may need to pay the third party some fee for this swap. Below we define an interface to request a swap by someone who owns an `Object`: ```rust public entry fun request_swap(object: Object, fee: Coin, service_address: address, ctx: &mut TxContext) { - assert!(Coin::value(&fee) >= MIN_FEE, 0); + assert!(coin::value(&fee) >= MIN_FEE, 0); let wrapper = ObjectWrapper { - id: TxContext::new_id(ctx), - original_owner: TxContext::sender(ctx), + id: tx_context::new_id(ctx), + original_owner: tx_context::sender(ctx), to_swap: object, - fee: Coin::into_balance(fee), + fee: coin::into_balance(fee), }; - Transfer::transfer(wrapper, service_address); + transfer::transfer(wrapper, service_address); } ``` In the above entry function, to request swapping an `object`, one must pass the object by value so that it's fully consumed and wrapped into `ObjectWrapper`. A fee (in the type of `Coin`) is also provided. The function also checks that the fee is sufficient. Note that we turn `Coin` into `Balance` when putting it into the `wrapper` object. This is because `Coin` is a Sui object type and used only to pass around as Sui objects (e.g. as entry function arguments or objects sent to addresses). For coin balances that need to be embedded in another Sui object struct, we use `Balance` instead because it's not a Sui object type and hence is much cheaper to use. @@ -126,27 +126,27 @@ let ObjectWrapper { ``` We now have all the things we need for the actual swap: ```rust -Transfer::transfer(object1, original_owner2); -Transfer::transfer(object2, original_owner1); +transfer::transfer(object1, original_owner2); +transfer::transfer(object2, original_owner1); ``` The above code does the swap: it sends `object1` to the original owner of `object2`, and sends `object1` to the original owner of `object2`. The service provider is also happy to take the fee: ```rust -let service_address = TxContext::sender(ctx); +let service_address = tx_context::sender(ctx); Balance::join(&mut fee1, fee2); -Transfer::transfer(Coin::from_balance(fee1, ctx), service_address); +transfer::transfer(coin::from_balance(fee1, ctx), service_address); ``` `fee2` is merged into `fee1`, turned into a `Coin` and sent to the `service_address`. Finally, we signal Sui that we have deleted both wrapper objects: ```rust -ID::delete(id1); -ID::delete(id2); +id::delete(id1); +id::delete(id2); ``` At the end of this call, the two objects have been swapped (sent to the opposite owner) and the service provider takes the service fee. Since the contract defined only one way to deal with `ObjectWrapper` - `execute_swap` - there is no other way the service operator can interact with `ObjectWrapper` despite its ownership. -The full source code can be found in [TrustedSwap.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/objects_tutorial/sources/TrustedSwap.move). +The full source code can be found in [trusted_swap.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/objects_tutorial/sources/trusted_swap.move). -A more complex example of using direct wrapping can be found in [Escrow.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/defi/sources/Escrow.move). +A more complex example of using direct wrapping can be found in [escrow.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/defi/sources/escrow.move). ### Wrapping through `Option` When Sui object type `Bar` is directly wrapped into `Foo`, there is not much flexiblity: a `Foo` object must have a `Bar` object in it, and in order to take out the `Bar` object one must destroy the `Foo` object. However, there are cases where we want more flexibility: the wrapping type may or may not always have the wrapped object in it, and the wrapped object may be replaced with a different object at some point. @@ -175,30 +175,30 @@ When we are creating a new warrior, we can set the `sword` and `shield` to `none ```rust public entry fun create_warrior(ctx: &mut TxContext) { let warrior = SimpleWarrior { - id: TxContext::new_id(ctx), - sword: Option::none(), - shield: Option::none(), + id: tx_context::new_id(ctx), + sword: option::none(), + shield: option::none(), }; - Transfer::transfer(warrior, TxContext::sender(ctx)) + transfer::transfer(warrior, tx_context::sender(ctx)) } ``` With this, we can then define functions to equip new swords or new shields: ```rust public entry fun equip_sword(warrior: &mut SimpleWarrior, sword: Sword, ctx: &mut TxContext) { - if (Option::is_some(&warrior.sword)) { - let old_sword = Option::extract(&mut warrior.sword); - Transfer::transfer(old_sword, TxContext::sender(ctx)); + if (option::is_some(&warrior.sword)) { + let old_sword = option::extract(&mut warrior.sword); + transfer::transfer(old_sword, tx_context::sender(ctx)); }; - Option::fill(&mut warrior.sword, sword); + option::fill(&mut warrior.sword, sword); } ``` In the above function, we are passing a `warrior` as mutable reference of `SimpleWarrior`, and a `sword` passed by value because we need to wrap it into the `warrior`. It is important to note that because `Sword` is a Sui object type without `drop` ability, if the warrior already has a sword equipped, that sword cannot just be dropped. If we make a call to `Option::fill` without first checking and taking out the existing sword, a runtime error may occur. Hence in `equip_sword`, we first check if there is already a sword equipped, and if so, we take it out and send it back to the sender. This matches what you would expect when you equip a new sword--you get the old sword back, if there is one. -Full code can be found in [SimpleWarrior.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/objects_tutorial/sources/SimpleWarrior.move). +Full code can be found in [simple_warrior.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/objects_tutorial/sources/simple_warrior.move). -You can also find a more complex example in [Hero.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/games/sources/Hero.move). +You can also find a more complex example in [hero.move](https://github.com/MystenLabs/sui/blob/main/sui_programmability/examples/games/sources/hero.move). ### Wrapping through `vector` The concept of wrapping objects in a vector field of another Sui object is very similar to wrapping through `Option`: an object may contain 0, 1 or many of the wrapped objects of the same type. diff --git a/doc/src/build/programming-with-objects/ch5-child-objects.md b/doc/src/build/programming-with-objects/ch5-child-objects.md index b2e3216d7c42f..153686f7d16c7 100644 --- a/doc/src/build/programming-with-objects/ch5-child-objects.md +++ b/doc/src/build/programming-with-objects/ch5-child-objects.md @@ -14,7 +14,7 @@ Fortunately, Sui provides another way to represent object relationships: *an obj There are two ways of creating child objects which we describe in the following sections. #### transfer_to_object -Assume we own two objects in our account address. To make one object own the other object, we can use the following API in the [`Transfer`](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/Transfer.move) library: +Assume we own two objects in our account address. To make one object own the other object, we can use the following API in the [`transfer`](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/transfer.move) library: ```rust public fun transfer_to_object( obj: T, @@ -27,7 +27,7 @@ The function returns a special struct `ChildRef` where `T` matches the type o This is very important because later on if we attempt to delete the parent object, the existence of the child references forces us to take care of them. Otherwise, we may end up in a situation where we deleted the parent object, but there are still some child objects; and these child objects will be locked forever, as we will explain in latter sections. In the last section, we will also see how this reference is used to move around child objects and to prevent making mistakes. -Let's look at some code. The full source code can be found in [ObjectOwner.move](https://github.com/MystenLabs/sui/blob/main/crates/sui-core/src/unit_tests/data/object_owner/sources/ObjectOwner.move). +Let's look at some code. The full source code can be found in [object_owner.move](https://github.com/MystenLabs/sui/blob/main/crates/sui-core/src/unit_tests/data/object_owner/sources/object_owner.move). First we define two object types for the parent and the child: ```rust @@ -44,9 +44,9 @@ struct Child has key { First we define an API to create an object of `Child` type: ```rust public entry fun create_child(ctx: &mut TxContext) { - Transfer::transfer( - Child { id: TxContext::new_id(ctx) }, - TxContext::sender(ctx), + transfer::transfer( + Child { id: tx_context::new_id(ctx) }, + tx_context::sender(ctx), ); } ``` @@ -55,18 +55,18 @@ Similarly, we can define an API to create an object of `Parent` type: ```rust public entry fun create_parent(ctx: &mut TxContext) { let parent = Parent { - id: TxContext::new_id(ctx), - child: Option::none(), + id: tx_context::new_id(ctx), + child: option::none(), }; - Transfer::transfer(parent, TxContext::sender(ctx)); + transfer::transfer(parent, tx_context::sender(ctx)); } ``` Since the `child` field is `Option` type, we can start with `Option::none()`. Now we can define an API that makes an object of `Child` a child of an object of `Parent`: ```rust public entry fun add_child(parent: &mut Parent, child: Child) { - let child_ref = Transfer::transfer_to_object(child, parent); - Option::fill(&mut parent.child, child_ref); + let child_ref = transfer::transfer_to_object(child, parent); + option::fill(&mut parent.child, child_ref); } ``` This function takes `child` by value, calls `transfer_to_object` to transfer the `child` object to the `parent`, and returns a `child_ref`. @@ -84,7 +84,7 @@ public fun transfer_to_object_id( owner_id: VersionedID, ): (VersionedID, ChildRef); ``` -To use this API, we don't need to create a parent object yet; we need only the object ID of the parent object, which can be created in advance through `TxContext::new_id(ctx)`. The function returns a tuple: it will return the `owner_id` that was passed in, along with the `ChildRef` representing a reference to the child object `obj`. It may seem strange that we require passing in `owner_id` by value only to return it. This is to ensure that the caller of the function does indeed own a `VersionedID` that hasn't been used in any object yet. Without this, it can be easy to make mistakes. +To use this API, we don't need to create a parent object yet; we need only the object ID of the parent object, which can be created in advance through `tx_context::new_id(ctx)`. The function returns a tuple: it will return the `owner_id` that was passed in, along with the `ChildRef` representing a reference to the child object `obj`. It may seem strange that we require passing in `owner_id` by value only to return it. This is to ensure that the caller of the function does indeed own a `VersionedID` that hasn't been used in any object yet. Without this, it can be easy to make mistakes. Let's see how this is used in action. First we define another object type that has a non-optional child field: ```rust struct AnotherParent has key { @@ -95,13 +95,13 @@ struct AnotherParent has key { And let's see how we define the API to create `AnotherParent` instance: ```rust public entry fun create_another_parent(child: Child, ctx: &mut TxContext) { - let id = TxContext::new_id(ctx); - let (id, child_ref) = Transfer::transfer_to_object_id(child, id); + let id = tx_context::new_id(ctx); + let (id, child_ref) = transfer::transfer_to_object_id(child, id); let parent = AnotherParent { id, child: child_ref, }; - Transfer::transfer(parent, TxContext::sender(ctx)); + transfer::transfer(parent, tx_context::sender(ctx)); } ``` In the above function, we need to first create the ID of the new parent object. With the ID, we can then transfer the child object to it by calling `transfer_to_object_id`, thereby obtaining a reference `child_ref`. With both `id` and `child_ref`, we can create an object of `AnotherParent`, which we would eventually transfer to the sender's account. @@ -128,7 +128,7 @@ The newly published package object ID: 0x3cfcee192b2fbafbce74a211e40eaf9e4cb746b Then we create a child object: ``` $ export PKG=0x3cfcee192b2fbafbce74a211e40eaf9e4cb746b9 -$ wallet call --package $PKG --module ObjectOwner --function create_child --gas-budget 1000 +$ wallet call --package $PKG --module object_owner --function create_child --gas-budget 1000 ``` ``` ----- Transaction Effects ---- @@ -138,7 +138,7 @@ Created Objects: At this point we only created the child object, but it's still owned by an account address. We can verify that we should be able to call `mutate_child` function by only passing in the child object: ``` $ export CHILD=0xb41d157fdeda968c5b5f0d8b87b6ebb84d7d1941 -$ wallet call --package $PKG --module ObjectOwner --function mutate_child --args $CHILD --gas-budget 1000 +$ wallet call --package $PKG --module object_owner --function mutate_child --args $CHILD --gas-budget 1000 ``` ``` ----- Transaction Effects ---- @@ -150,7 +150,7 @@ Indeed the transasaction succeeded. Now let's create the `Parent` object as well: ``` -$ wallet call --package $PKG --module ObjectOwner --function create_parent --gas-budget 1000 +$ wallet call --package $PKG --module object_owner --function create_parent --gas-budget 1000 ``` ``` ----- Transaction Effects ---- @@ -160,7 +160,7 @@ Created Objects: Now we can make the parent object own the child object: ``` $ export PARENT=0x2f893c18241cfbcd390875f6e1566f4db949392e -$ wallet call --package $PKG --module ObjectOwner --function add_child --args $PARENT $CHILD --gas-budget 1000 +$ wallet call --package $PKG --module object_owner --function add_child --args $PARENT $CHILD --gas-budget 1000 ``` ``` ----- Transaction Effects ---- @@ -171,7 +171,7 @@ As we can see, the owner of the child object has been changed to the parent obje Now if we try to call `mutate_child` again, we will see an error: ``` -$ wallet call --package $PKG --module ObjectOwner --function mutate_child --args $CHILD --gas-budget 1000 +$ wallet call --package $PKG --module object_owner --function mutate_child --args $CHILD --gas-budget 1000 ``` ``` Object 0xb41d157fdeda968c5b5f0d8b87b6ebb84d7d1941 is owned by object 0x2f893c18241cfbcd390875f6e1566f4db949392e, which is not in the input @@ -179,7 +179,7 @@ Object 0xb41d157fdeda968c5b5f0d8b87b6ebb84d7d1941 is owned by object 0x2f893c182 To be able to mutate the child object, we must also pass the parent object as argument. Hence we need to call the `mutate_child_with_parent` function: ``` -$ wallet call --package $PKG --module ObjectOwner --function mutate_child_with_parent --args $CHILD $PARENT --gas-budget 1000 +$ wallet call --package $PKG --module object_owner --function mutate_child_with_parent --args $CHILD $PARENT --gas-budget 1000 ``` It will finish successfully. @@ -207,8 +207,8 @@ There are two important things worth mentioning: To demonstrate how to use this API, let's implement a function that removes a child object from a parent object and transfer it back to the account owner: ```rust public entry fun remove_child(parent: &mut Parent, child: Child, ctx: &mut TxContext) { - let child_ref = Option::extract(&mut parent.child); - Transfer::transfer_child_to_address(child, child_ref, TxContext::sender(ctx)); + let child_ref = option::extract(&mut parent.child); + transfer::transfer_child_to_address(child, child_ref, tx_context::sender(ctx)); } ``` In the above function, the reference to the child is extracted from the `parent` object, which is then passed together with the `child` object to the `transfer_child_to_address`, with recipient as the sender of the transaction. It is important to note that this function must also take the `child` object as an argument. Move is not able to obtain the child object only from the reference. An object must always be explicitly provided in the transaction to make the transfer work. As we explained earlier, the fact that `transfer_child_to_address` requires the child reference as an argument guarantees that the `parent` object no longer holds a reference to the child object. @@ -230,9 +230,9 @@ Comparing to the previous API, there are two primary differences: To see how to use this API, let's define a function that could transfer a child object to a new parent: ```rust public entry fun transfer_child(parent: &mut Parent, child: Child, new_parent: &mut Parent) { - let child_ref = Option::extract(&mut parent.child); - let new_child_ref = Transfer::transfer_child_to_object(child, child_ref, new_parent); - Option::fill(&mut new_parent.child, new_child_ref); + let child_ref = option::extract(&mut parent.child); + let new_child_ref = transfer::transfer_child_to_object(child, child_ref, new_parent); + option::fill(&mut new_parent.child, new_child_ref); } ``` Similar to `remove_child`, the `child` object must be passed explicitly by-value in the arguments. First of all we extract the existing child reference, and pass it to `transfer_child_to_object` along with `child`, and a mutable reference to `new_parent`. This call will return a new child reference. We then fill the `new_parent`'s `child` field with this new reference. Since `ChildRef` type is not droppable, `Option::fill` will fail if `new_parent.child` already contains an existing `ChildRef`. This ensures that we never accidentally drop a `ChildRef` without properly transferring the child. @@ -248,7 +248,7 @@ What happens if we try to delete a child directly using what we learned in the f ```rust public entry fun delete_child(child: Child, _parent: &mut Parent) { let Child { id } = child; - ID::delete(id); + id::delete(id); } ``` If you follow the wallet interaction above and then try to call the `delete_child` function here on a child object, you will see the following runtime error: @@ -268,18 +268,18 @@ public fun delete_child_object( ); ``` The function takes both the ID of the child object and the child reference as arguments. As explained in chapter 1, to delete an object we must first unpack the object, and upon doing so a non-droppable `id` will need to be deleted explicitly. -Instead of calling `ID::delete` on the `id`, for child object, here we require calling `Transfer::delete_child_object` with the `id` and the child reference. +Instead of calling `id::delete` on the `id`, for child object, here we require calling `transfer::delete_child_object` with the `id` and the child reference. To demonstrate how to use this API, we define a function that can delete a parent object and a child object altogether: ```rust public entry fun delete_parent_and_child(parent: Parent, child: Child) { let Parent { id: parent_id, child: child_ref_opt } = parent; - let child_ref = Option::extract(&mut child_ref_opt); - Option::destroy_none(child_ref_opt); - ID::delete(parent_id); + let child_ref = option::extract(&mut child_ref_opt); + option::destroy_none(child_ref_opt); + id::delete(parent_id); let Child { id: child_id } = child; - Transfer::delete_child_object(child_id, child_ref); + transfer::delete_child_object(child_id, child_ref); } ``` In the above example, after we unpacked the `parent` object we are able to extract the `child_ref`. We then also unpack the `child` object to obtain the `child_id`. -Notice that when deleting the `parent` object, we called `ID::delete`, while when deleting the `child` object, we called `delete_child_object`. +Notice that when deleting the `parent` object, we called `id::delete`, while when deleting the `child` object, we called `delete_child_object`. diff --git a/doc/src/build/transactions.md b/doc/src/build/transactions.md index 628b78affd8fe..25e96767db0f8 100644 --- a/doc/src/build/transactions.md +++ b/doc/src/build/transactions.md @@ -8,7 +8,7 @@ All updates to the Sui ledger happen via a transaction. This section describes t All Sui transactions have the following common metadata: * Sender address: The address of the user sending this transaction. -* Gas Input: An object reference pointing to the object that will be used to pay for this transaction's execution and storage. This object must be owned by the user and must be of type `Sui::Coin::Coin` (i.e., the Sui native currency). +* Gas Input: An object reference pointing to the object that will be used to pay for this transaction's execution and storage. This object must be owned by the user and must be of type `sui::coin::Coin` (i.e., the Sui native currency). * Gas Price: An unsigned integer specifying the number of native tokens per gas unit this transaction will pay. The gas price must always be nonzero. * Maximum Gas Budget: The maximum number of gas units that can be expended by executing this transaction. If this budget is exceeded, transaction execution will abort and have no effects other than debiting the gas input. The gas input object must have a value higher than the gas price multiplied by the max gas, and this product is the maximum amount that the gas input object will be debited for the transaction. * Epoch: The Sui epoch this transaction is intended for. @@ -42,7 +42,7 @@ Native transactions are optimized versions of common Sui operations. Each native This transaction type transfers coins from the sender to the specified recipients. In addition to the common metadata above, a transfer transaction includes the following fields: -* Input: An object reference pointing to a mutable object owned by the sender. The object must be of type `Sui::Coin::Coin` with arbitrary `T`--that is, any fungible token. The gas input object from above cannot also appear as an object input. +* Input: An object reference pointing to a mutable object owned by the sender. The object must be of type `sui::coin::Coin` with arbitrary `T`--that is, any fungible token. The gas input object from above cannot also appear as an object input. * Recipients: The addresses that will receive payments from this transfer. This list must be non-empty. * Amounts: A list of unsigned integers encoding the amount that each recipient will receive. This list must be the same length as the recipients list. Each amount will be debited from the input object, wrapped in a freshly created coin object, and sent to the corresponding recipient address. The value of the input object must be greater than or equal to the sum of the amounts. @@ -50,7 +50,7 @@ In addition to the common metadata above, a transfer transaction includes the fo This transaction type combines several coin objects into one. It includes the following field: -Inputs: A list of unique object references pointing to mutable objects owned by the sender. The objects must all have the same type: `Sui::Coin::Coin` with arbitrary `T`--that is, any fungible token. The list must contain at least two objects. All objects except the first one will be destroyed, and the new value of the first object will be its old value plus the sum of the value of all destroyed objects. The gas input object from above cannot also appear as an object input. +Inputs: A list of unique object references pointing to mutable objects owned by the sender. The objects must all have the same type: `sui::coin::Coin` with arbitrary `T`--that is, any fungible token. The list must contain at least two objects. All objects except the first one will be destroyed, and the new value of the first object will be its old value plus the sum of the value of all destroyed objects. The gas input object from above cannot also appear as an object input. ## Further reading diff --git a/doc/src/build/wallet.md b/doc/src/build/wallet.md index efb9131428f7b..5f2a51d86ca3f 100644 --- a/doc/src/build/wallet.md +++ b/doc/src/build/wallet.md @@ -515,7 +515,7 @@ This should give you output similar to the following: ID: 0x124bbde643189b573c98d05c092f4927225421d7 Version: 1 Owner: Account Address ( 0x62cd5bc220b28a34265bcb24995fb45a51d39832 ) -Type: 0x2::Coin::Coin<0x2::SUI::SUI> +Type: 0x2::coin::Coin<0x2::sui::SUI> ``` The result shows some basic information about the object, the owner, @@ -535,7 +535,7 @@ Here is example `json` output: "fields": { "value": 99126 }, - "type": "0x2::Balance::Balance<0x2::SUI::SUI>" + "type": "0x2::balance::Balance<0x2::sui::SUI>" }, "id": { "fields": { @@ -545,17 +545,17 @@ Here is example `json` output: "fields": { "bytes": "124bbde643189b573c98d05c092f4927225421d7" }, - "type": "0x2::ID::ID" + "type": "0x2::id::ID" } }, - "type": "0x2::ID::UniqueID" + "type": "0x2::id::UniqueID" }, "version": 1 }, - "type": "0x2::ID::VersionedID" + "type": "0x2::id::VersionedID" } }, - "type": "0x2::Coin::Coin<0x2::SUI::SUI>" + "type": "0x2::coin::Coin<0x2::sui::SUI>" }, "owner": { "AddressOwner": "0x62cd5bc220b28a34265bcb24995fb45a51d39832" @@ -643,7 +643,7 @@ $ wallet objects --address 0xc72cf3adcc4d11c03079cef2c8992aea5268677a ## Creating example NFTs -You may create an [NFT-like object](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/DevNetNFT.move#L16) on Sui using the following command: +You may create an [NFT-like object](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/devnet_nft.move#L16) on Sui using the following command: ```shell $ wallet create-example-nft @@ -658,10 +658,10 @@ Owner: AddressOwner(k#66af3898e7558b79e115ab61184a958497d1905a) Version: 1 ID: 0x70874f1abd0a9a0126726a626ff48374f7b2d9c6 Readonly: false -Type: 0x2::DevNetNFT::DevNetNFT +Type: 0x2::devnet_nft::DevNetNFT ``` -The command will invoke the `mint` function in the `DevNetNFT` module, which mints a Sui object with three attributes: name, description, and image URL with [default values](https://github.com/MystenLabs/sui/blob/27dff728a4c9cb65cd5d92a574105df20cb51887/sui/src/wallet_commands.rs#L39) and transfers the object to your address. You can also provide custom values using the following instructions: +The command will invoke the `mint` function in the `devnet_nft` module, which mints a Sui object with three attributes: name, description, and image URL with [default values](https://github.com/MystenLabs/sui/blob/27dff728a4c9cb65cd5d92a574105df20cb51887/sui/src/wallet_commands.rs#L39) and transfers the object to your address. You can also provide custom values using the following instructions: `create-example-nft` command usage: @@ -749,7 +749,7 @@ Module : Coin Function : join Object Arguments : [(0x149a3493c97fafc696526052fe08e77043d4be0b, SequenceNumber(0), o#2d50f098c913e1863ece507dcdcd5a291252f6c1df89ec8f16c62b542ac723b5), (1B19F74AD77A95D7562432F6991AC9EC1EA2C57C, SequenceNumber(0), o#d390dc554759f892a714b2659046f3f47830cd789b3ec1df9d40bd876c3e1352)] Pure Arguments : [] -Type Arguments : [Struct(StructTag { address: 0000000000000000000000000000000000000002, module: Identifier("SUI"), name: Identifier("SUI"), type_params: [] })] +Type Arguments : [Struct(StructTag { address: 0000000000000000000000000000000000000002, module: Identifier("sui"), name: Identifier("SUI"), type_params: [] })] ----- Merge Coin Results ---- Updated Coin : Coin { id: 0x149a3493c97fafc696526052fe08e77043d4be0b, value: 200000 } @@ -818,7 +818,7 @@ Module : Coin Function : split_vec Object Arguments : [(0x13347bd461e8a2b9ee5de7f6131063a3050a45c4, SequenceNumber(0), o#4ca351cbf507cac8162cb8278a38c1c9cdf4c6d2be05f2bee405da02ce8a4aa1)] Pure Arguments : [[3, 232, 3, 0, 0, 0, 0, 0, 0, 136, 19, 0, 0, 0, 0, 0, 0, 184, 11, 0, 0, 0, 0, 0, 0]] -Type Arguments : [Struct(StructTag { address: 0000000000000000000000000000000000000002, module: Identifier("SUI"), name: Identifier("SUI"), type_params: [] })] +Type Arguments : [Struct(StructTag { address: 0000000000000000000000000000000000000002, module: Identifier("sui"), name: Identifier("SUI"), type_params: [] })] ----- Split Coin Results ---- Updated Coin : Coin { id: 0x13347bd461e8a2b9ee5de7f6131063a3050a45c4, value: 91000 } @@ -852,8 +852,8 @@ for the first look at Move source code and a description of the following function we will be calling in this tutorial: ```rust -public entry fun transfer(c: Coin::Coin, recipient: address) { - Coin::transfer(c, Address::new(recipient)) +public entry fun transfer(c: coin::Coin, recipient: address) { + coin::transfer(c, Address::new(recipient)) } ``` @@ -884,10 +884,10 @@ but for the sake of this exercise, let's choose the last one on the list. We will perform the transfer by calling the `transfer` function from -the SUI module using the following Sui Wallet command: +the sui module using the following Sui Wallet command: ```shell -$ wallet call --function transfer --module SUI --package 0x2 --args 0x5044DC15D3C71D500116EB026E8B70D0A180F3AC 0xF456EBEF195E4A231488DF56B762AC90695BE2DD --gas-budget 1000 +$ wallet call --function transfer --module sui --package 0x2 --args 0x5044DC15D3C71D500116EB026E8B70D0A180F3AC 0xF456EBEF195E4A231488DF56B762AC90695BE2DD --gas-budget 1000 ``` This is a pretty complicated command so let's explain all of its @@ -926,7 +926,7 @@ Signed Authorities : [k#21d89c3a12409b7aeadf36a9753417ead5fa9ea607ccb666e83b739b Transaction Kind : Call Gas Budget : 1000 Package ID : 0x2 -Module : SUI +Module : sui Function : transfer Object Arguments : [(0x5044dc15d3c71d500116eb026e8b70d0a180f3ac, SequenceNumber(0), o#748fabf1f7f92c8d00b54f5b431fd4e28d9dfd642cc0bc5c48b16dc0efdc58c1)] Pure Arguments : [[244, 86, 235, 239, 25, 94, 74, 35, 20, 136, 223, 86, 183, 98, 172, 144, 105, 91, 226, 221]] @@ -972,7 +972,7 @@ Owner: AddressOwner(k#f456ebef195e4a231488df56b762ac90695be2dd) Version: 1 ID: 0x5044dc15d3c71d500116eb026e8b70d0a180f3ac Readonly: false -Type: 0x2::Coin::Coin<0x2::SUI::SUI> +Type: 0x2::coin::Coin<0x2::sui::SUI> ``` ## Publish packages diff --git a/doc/src/contribute/observability.md b/doc/src/contribute/observability.md index 2804681842a5e..5bdab7be44401 100644 --- a/doc/src/contribute/observability.md +++ b/doc/src/contribute/observability.md @@ -45,7 +45,7 @@ and tracing a transaction across the gateway (`authority_aggregator`) as well as ``` 7ab7774d1f7bd40848}: sui_core::authority_aggregator: Broadcasting transaction request to authorities quorum_threshold=3 validity_threshold=2 timeout_after_quorum=60s -2022-03-05T01:35:03.383791Z TRACE test_move_call_args_linter_command:process_tx{tx_digest=t#7e5f08ab09ec80e3372c101c5858c96965a25326c21af27ab7774d1f7bd40848}: sui_core::authority_aggregator: Transaction data: TransactionData { kind: Call(MoveCall { package: (0000000000000000000000000000000000000002, SequenceNumber(1), o#3104eb8786a94f58d88564c38e22f13d79e3868c5cf81c9c9228fe91465eccad), module: Identifier("ObjectBasics"), function: Identifier("transfer"), type_arguments: [], object_arguments: [(DA40C299F382CBC3C1EBEEA97351F5F185BAD359, SequenceNumber(1), o#d299113b3b52fd1b9dc01e3ba9cf70345faed592af04a56e287057f166ed2783)], shared_object_arguments: [], pure_arguments: [[145, 123, 205, 38, 175, 158, 193, 63, 122, 56, 238, 127, 139, 117, 186, 164, 89, 46, 222, 252]], gas_budget: 1000 }), sender: k#37ebb9c16574a57bcc7b52a6312a35991748be55, gas_payment: (3EE0283D2D12D5C49D0E4E2F509D07227A64ADF2, SequenceNumber(1), o#3ad1a71ee65e8e6675e6a0fb1e893e48c1820b274d3055d75f4abb850c9663e5) } +2022-03-05T01:35:03.383791Z TRACE test_move_call_args_linter_command:process_tx{tx_digest=t#7e5f08ab09ec80e3372c101c5858c96965a25326c21af27ab7774d1f7bd40848}: sui_core::authority_aggregator: Transaction data: TransactionData { kind: Call(MoveCall { package: (0000000000000000000000000000000000000002, SequenceNumber(1), o#3104eb8786a94f58d88564c38e22f13d79e3868c5cf81c9c9228fe91465eccad), module: Identifier("object_basics"), function: Identifier("transfer"), type_arguments: [], object_arguments: [(DA40C299F382CBC3C1EBEEA97351F5F185BAD359, SequenceNumber(1), o#d299113b3b52fd1b9dc01e3ba9cf70345faed592af04a56e287057f166ed2783)], shared_object_arguments: [], pure_arguments: [[145, 123, 205, 38, 175, 158, 193, 63, 122, 56, 238, 127, 139, 117, 186, 164, 89, 46, 222, 252]], gas_budget: 1000 }), sender: k#37ebb9c16574a57bcc7b52a6312a35991748be55, gas_payment: (3EE0283D2D12D5C49D0E4E2F509D07227A64ADF2, SequenceNumber(1), o#3ad1a71ee65e8e6675e6a0fb1e893e48c1820b274d3055d75f4abb850c9663e5) } 2022-03-05T01:35:03.385294Z DEBUG test_move_call_args_linter_command:process_tx{tx_digest=t#7e5f08ab09ec80e3372c101c5858c96965a25326c21af27ab7774d1f7bd40848}: sui_core::authority: Checked locks and found mutable objects num_mutable_objects=2 2022-03-05T01:35:03.386500Z DEBUG test_move_call_args_linter_command:process_tx{tx_digest=t#7e5f08ab09ec80e3372c101c5858c96965a25326c21af27ab7774d1f7bd40848}: sui_core::authority: Checked locks and found mutable objects num_mutable_objects=2 2022-03-05T01:35:03.387681Z DEBUG test_move_call_args_linter_command:process_tx{tx_digest=t#7e5f08ab09ec80e3372c101c5858c96965a25326c21af27ab7774d1f7bd40848}: sui_core::authority_aggregator: Received signatures response from authorities for transaction req broadcast num_errors=0 good_stake=3 bad_stake=0 num_signatures=3 has_certificate=true diff --git a/doc/src/explore/devnet.md b/doc/src/explore/devnet.md index 3e4035f1ad5c1..30dbc4e8b74cc 100644 --- a/doc/src/explore/devnet.md +++ b/doc/src/explore/devnet.md @@ -72,7 +72,7 @@ Successfully created an ExampleNFT: ID: ED883F6812AF447B9B0CE220DA5EA9E0F58012FE Version: 1 Owner: Account Address ( 9E9A9D406961E478AA80F4A6B2B167673F3DF8BA ) -Type: 0x2::DevNetNFT::DevNetNFT +Type: 0x2::devnet_nft::DevNetNFT ``` The above command created an object with ID `ED883F6812AF447B9B0CE220DA5EA9E0F58012FE`. Note you may use `wallet` to [view objects owned by the account](https://docs.sui.io/build/wallet#view-objects-owned-by-the-account). @@ -96,7 +96,7 @@ Successfully created an ExampleNFT: ID: EC97467A40A1305FFDEF7019C3045FBC7AA31E29 Version: 1 Owner: Account Address ( 9E9A9D406961E478AA80F4A6B2B167673F3DF8BA ) -Type: 0x2::DevNetNFT::DevNetNFT +Type: 0x2::devnet_nft::DevNetNFT ``` That you can similarly view at: diff --git a/doc/src/explore/prototypes.md b/doc/src/explore/prototypes.md index 6bcdbba173856..b3be009d29d0f 100644 --- a/doc/src/explore/prototypes.md +++ b/doc/src/explore/prototypes.md @@ -25,7 +25,7 @@ With Sui, we believe game developers should not be limited by the platform perfo Created by game development studio GenITeam, these prototypes use both the Unity SDK and Sui [APIs](https://playground.open-rpc.org/?uiSchema%5BappBar%5D%5Bui:splitView%5D=false&schemaUrl=https://raw.githubusercontent.com/MystenLabs/sui/main/sui/open_rpc/spec/openrpc.json&uiSchema%5BappBar%5D%5Bui:input%5D=false). -GenITeam’s developers who worked on this collaboration are neither smart contract nor Move developers. Based on their input, we created a data model and shared simple APIs. With these APIs, Geniteam was able to mint fully on-chain NFTs that are mutable, own other on-chain assets, and freely transfer to other applications. +GenITeam’s developers who worked on this collaboration are neither smart contract nor Move developers. Based on their input, we created a data model and shared simple APIs. With these APIs, geniteam was able to mint fully on-chain NFTs that are mutable, own other on-chain assets, and freely transfer to other applications. This proof of concept build is meant to demonstrate the capabilities for game developers unlocked through Sui. We look forward to seeing what the creative minds in the gaming community come up with as we unveil additional capabilities in the upcoming months. With each bug fixed we learned insights on what game developers look for in a SDK. Sui is committed to building SDKs that are accessible for all levels of developers with varying degrees of smart contracts expertise. @@ -40,7 +40,7 @@ POST `/call` with body: { "sender": "{{owner}}", "packageObjectId": "0x2", - "module": "Geniteam", + "module": "geniteam", "function": "create_monster", "args": [ "0x{{player_id}}", @@ -65,7 +65,7 @@ POST `/call` with body: { "sender": "{{owner}}", "packageObjectId": "0x2", - "module": "Geniteam", + "module": "geniteam", "function": "update_monster_stats", "args": [ "0x{{player_id}}", @@ -113,7 +113,7 @@ GET /object_info?objectId={{monster_id}} // Create a Monster and add it to the Farm's collection of Monsters public entry fun create_monster(_player: &mut Player, farm: &mut Farm, - pet_monsters_c: &mut Collection::Collection, + pet_monsters_c: &mut collection::Collection, monster_name: vector, monster_img_index: u64, breed: u8, @@ -136,7 +136,7 @@ GET /object_info?objectId={{monster_id}} // Add it to the collection - Collection::add(pet_monsters_c, monster); + collection::add(pet_monsters_c, monster); } // Creates a basic Monster object @@ -150,7 +150,7 @@ GET /object_info?objectId={{monster_id}} ): Monster { Monster { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), monster_name: ASCII::string(monster_name), monster_img_index, breed, @@ -174,7 +174,7 @@ GET /object_info?objectId={{monster_id}} public entry fun update_monster_stats( _player: &mut Player, _farm: &mut Farm, - _pet_monsters: &mut Collection::Collection, + _pet_monsters: &mut collection::Collection, self: &mut Monster, monster_level: u64, hunger_level: u64, diff --git a/explorer/client/src/utils/static/mock_data.json b/explorer/client/src/utils/static/mock_data.json index 12451d5dbe8b6..56cbf013aab2d 100644 --- a/explorer/client/src/utils/static/mock_data.json +++ b/explorer/client/src/utils/static/mock_data.json @@ -422,7 +422,7 @@ "owner": "SingleOwner(k#player2)", "version": "87", "readonly": "true", - "objType": "0x2::Coin::Coin<0x2::USD::USD>", + "objType": "0x2::coin::Coin<0x2::USD::USD>", "data": { "tx_digest": "Da4vHc9IwbvOYblE8LnrVsqXwryt2Kmms+xnJ7Zx5E4=", "contents": { @@ -437,7 +437,7 @@ "owner": "SingleOwner(k#player2)", "version": "87", "readonly": "true", - "objType": "0x2::Coin::Coin<0x2::USD::USD>", + "objType": "0x2::coin::Coin<0x2::USD::USD>", "data": { "contents": { "id": {}, @@ -451,7 +451,7 @@ "owner": "SingleOwner(k#player2)", "version": "87", "readonly": "true", - "objType": "0x2::Coin::Coin<0x2::SUI::SUI>", + "objType": "0x2::coin::Coin<0x2::sui::SUI>", "data": { "contents": { "id": {}, @@ -465,7 +465,7 @@ "owner": "SingleOwner(k#player2)", "version": "87", "readonly": "true", - "objType": "0x2::Coin::Coin<0x2::SUI::SUI>", + "objType": "0x2::coin::Coin<0x2::sui::SUI>", "data": { "contents": { "id": {}, @@ -649,18 +649,18 @@ "fields": { "bytes": "37196de8502e6d80e6a31fba1a5d6986cc018805" }, - "type": "0x2::ID::ID" + "type": "0x2::id::ID" } }, - "type": "0x2::ID::UniqueID" + "type": "0x2::id::UniqueID" }, "version": 0 }, - "type": "0x2::ID::VersionedID" + "type": "0x2::id::VersionedID" }, "value": 100000 }, - "type": "0x2::Coin::Coin<0x2::SUI::SUI>" + "type": "0x2::coin::Coin<0x2::sui::SUI>" }, "owner": { "AddressOwner": "3997c1099d2961e09c2a302d8e3644d6ce1237ce" @@ -675,7 +675,7 @@ "category": "object", "version": "5", "readonly": "false", - "objType": "0x2::Geniteam::Monster", + "objType": "0x2::geniteam::Monster", "name": "Brown Dog", "data": { "contents": { @@ -698,7 +698,7 @@ "category": "object", "version": "6", "readonly": "false", - "objType": "0x2::Geniteam::Monster", + "objType": "0x2::geniteam::Monster", "name": "Brown Water Dog", "data": { "contents": { @@ -729,7 +729,7 @@ "category": "object", "version": "1", "readonly": "true", - "objType": "0x2::Geniteam::MonsterCosmetic", + "objType": "0x2::geniteam::MonsterCosmetic", "name": "Water Rune", "data": { "contents": { @@ -745,7 +745,7 @@ "category": "object", "version": "4", "readonly": "false", - "objType": "0x2::Geniteam::Monster", + "objType": "0x2::geniteam::Monster", "name": "White Cat", "data": { "contents": { @@ -768,7 +768,7 @@ "category": "object", "version": "5", "readonly": "false", - "objType": "0x2::Geniteam::Monster", + "objType": "0x2::geniteam::Monster", "name": "White Cat with Glasses", "data": { "contents": { @@ -798,7 +798,7 @@ "category": "object", "version": "1", "readonly": "true", - "objType": "0x2::Geniteam::MonsterCosmetic", + "objType": "0x2::geniteam::MonsterCosmetic", "name": "Glasses", "data": { "contents": { @@ -814,7 +814,7 @@ "category": "object", "version": "7", "readonly": "false", - "objType": "0x2::Geniteam::Monster", + "objType": "0x2::geniteam::Monster", "name": "White Fire Cat", "data": { "contents": { @@ -845,7 +845,7 @@ "category": "object", "version": "1", "readonly": "true", - "objType": "0x2::Geniteam::MonsterCosmetic", + "objType": "0x2::geniteam::MonsterCosmetic", "name": "Fire Rune", "data": { "contents": { diff --git a/explorer/client/src/utils/stringUtils.ts b/explorer/client/src/utils/stringUtils.ts index 99ee995a903d0..41dc94b87cf07 100644 --- a/explorer/client/src/utils/stringUtils.ts +++ b/explorer/client/src/utils/stringUtils.ts @@ -20,7 +20,7 @@ export const trimStdLibPrefix = (str: string): string => str.replace(/^0x2::/, ''); export const handleCoinType = (str: string): string => - str === '0x2::Coin::Coin<0x2::SUI::SUI>' + str === '0x2::coin::Coin<0x2::sui::SUI>' ? 'SUI' : str.match(/^([a-zA-Z0-9:]*)<([a-zA-Z0-9:]*)>$/)?.[2] || str; diff --git a/nft_mirror/oracle_server/src/airdrop/airdropService.ts b/nft_mirror/oracle_server/src/airdrop/airdropService.ts index e4a98d8bf8986..feadccbf30e91 100644 --- a/nft_mirror/oracle_server/src/airdrop/airdropService.ts +++ b/nft_mirror/oracle_server/src/airdrop/airdropService.ts @@ -228,7 +228,7 @@ export class AirdropService { ): Promise<[string, string]> { const objects = await connection.bulkFetchObjects(oracleAddress); const gasCoin = objects.filter( - (o) => o.objType === '0x2::Coin::Coin<0x2::GAS::GAS>' + (o) => o.objType === '0x2::coin::Coin<0x2::GAS::GAS>' )[0].id; const oracle_object_identifier = this.getPackageAndModule().join('::') + diff --git a/nft_mirror/oracle_server/src/sdk/gateway-generated-schema.ts b/nft_mirror/oracle_server/src/sdk/gateway-generated-schema.ts index 28d8df778ea0b..a82e15137b478 100644 --- a/nft_mirror/oracle_server/src/sdk/gateway-generated-schema.ts +++ b/nft_mirror/oracle_server/src/sdk/gateway-generated-schema.ts @@ -24,7 +24,7 @@ export interface paths { * { * "sender": "b378b8d26c4daa95c5f6a2e2295e6e5f34371c1659e95f572788ffa55c265363", * "package_object_id": "0x2", - * "module": "ObjectBasics", + * "module": "object_basics", * "function": "create", * "args": [ * 200, @@ -237,7 +237,7 @@ export interface operations { * { * "sender": "b378b8d26c4daa95c5f6a2e2295e6e5f34371c1659e95f572788ffa55c265363", * "package_object_id": "0x2", - * "module": "ObjectBasics", + * "module": "object_basics", * "function": "create", * "args": [ * 200, diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md index 741348d117454..3b344a9c84d3a 100644 --- a/sdk/typescript/README.md +++ b/sdk/typescript/README.md @@ -70,7 +70,7 @@ const txn = await provider.getTransaction( For any operations that involves signing or submitting transactions, you should use the `Signer` API. For example: -To transfer a `0x2::Coin::Coin`: +To transfer a `0x2::coin::Coin`: ```typescript import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js'; @@ -88,7 +88,7 @@ const transferTxn = await signer.transferCoin({ console.log('transferTxn', transferTxn); ``` -To split a `0x2::Coin::Coin` into multiple coins +To split a `0x2::coin::Coin` into multiple coins ```typescript import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js'; @@ -139,7 +139,7 @@ const signer = new RawSigner( ); const moveCallTxn = await signer.executeMoveCall({ packageObjectId: '0x2', - module: 'DevNetNFT', + module: 'devnet_nft', function: 'mint', typeArguments: [], arguments: [ diff --git a/sdk/typescript/src/types/framework.ts b/sdk/typescript/src/types/framework.ts index 2088bc56c94c9..727826ad0f008 100644 --- a/sdk/typescript/src/types/framework.ts +++ b/sdk/typescript/src/types/framework.ts @@ -8,12 +8,12 @@ import { getMoveObjectType } from './objects'; import BN from 'bn.js'; /** - * Utility class for 0x2::Coin + * Utility class for 0x2::coin * as defined in https://github.com/MystenLabs/sui/blob/ca9046fd8b1a9e8634a4b74b0e7dabdc7ea54475/sui_programmability/framework/sources/Coin.move#L4 */ export class Coin { static isCoin(data: GetObjectDataResponse): boolean { - return getMoveObjectType(data)?.startsWith('0x2::Coin::Coin') ?? false; + return getMoveObjectType(data)?.startsWith('0x2::coin::Coin') ?? false; } static getBalance(data: GetObjectDataResponse): BN | undefined { diff --git a/sdk/typescript/src/types/objects.ts b/sdk/typescript/src/types/objects.ts index fe418f7b3ea1d..b392e20354e02 100644 --- a/sdk/typescript/src/types/objects.ts +++ b/sdk/typescript/src/types/objects.ts @@ -29,7 +29,7 @@ export type SuiData = { dataType: ObjectType } & ( ); export type SuiMoveObject = { - /** Move type (e.g., "0x2::Coin::Coin<0x2::SUI::SUI>") */ + /** Move type (e.g., "0x2::coin::Coin<0x2::sui::SUI>") */ type: string; /** Fields and values stored inside the Move object */ fields: ObjectContentFields; diff --git a/sui_programmability/examples/basics/Move.toml b/sui_programmability/examples/basics/Move.toml index a8edf3d83f791..ea0e40d734277 100644 --- a/sui_programmability/examples/basics/Move.toml +++ b/sui_programmability/examples/basics/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { local = "../../../crates/sui-framework" } [addresses] -Basics = "0x0" +basics = "0x0" diff --git a/sui_programmability/examples/basics/sources/Counter.move b/sui_programmability/examples/basics/sources/Counter.move deleted file mode 100644 index dc4c98962214c..0000000000000 --- a/sui_programmability/examples/basics/sources/Counter.move +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -/// This example demonstrates a basic use of a shared object. -/// Rules: -/// - anyone can create and share a counter -/// - everyone can increment a counter by 1 -/// - the owner of the counter can reset it to any value -module Basics::Counter { - use Sui::Transfer; - use Sui::ID::VersionedID; - use Sui::TxContext::{Self, TxContext}; - - /// A shared counter. - struct Counter has key { - id: VersionedID, - owner: address, - value: u64 - } - - public fun owner(counter: &Counter): address { - counter.owner - } - - public fun value(counter: &Counter): u64 { - counter.value - } - - /// Create and share a Counter object. - public entry fun create(ctx: &mut TxContext) { - Transfer::share_object(Counter { - id: TxContext::new_id(ctx), - owner: TxContext::sender(ctx), - value: 0 - }) - } - - /// Increment a counter by 1. - public entry fun increment(counter: &mut Counter) { - counter.value = counter.value + 1; - } - - /// Set value (only runnable by the Counter owner) - public entry fun set_value(counter: &mut Counter, value: u64, ctx: &mut TxContext) { - assert!(counter.owner == TxContext::sender(ctx), 0); - counter.value = value; - } - - /// Assert a value for the counter. - public entry fun assert_value(counter: &Counter, value: u64) { - assert!(counter.value == value, 0) - } -} - -#[test_only] -module Basics::CounterTest { - use Sui::TestScenario; - use Basics::Counter; - - #[test] - fun test_counter() { - let owner = @0xC0FFEE; - let user1 = @0xA1; - - let scenario = &mut TestScenario::begin(&user1); - - TestScenario::next_tx(scenario, &owner); - { - Counter::create(TestScenario::ctx(scenario)); - }; - - TestScenario::next_tx(scenario, &user1); - { - let counter_wrapper = TestScenario::take_shared(scenario); - let counter = TestScenario::borrow_mut(&mut counter_wrapper); - - assert!(Counter::owner(counter) == owner, 0); - assert!(Counter::value(counter) == 0, 1); - - Counter::increment(counter); - Counter::increment(counter); - Counter::increment(counter); - TestScenario::return_shared(scenario, counter_wrapper); - }; - - TestScenario::next_tx(scenario, &owner); - { - let counter_wrapper = TestScenario::take_shared(scenario); - let counter = TestScenario::borrow_mut(&mut counter_wrapper); - - assert!(Counter::owner(counter) == owner, 0); - assert!(Counter::value(counter) == 3, 1); - - Counter::set_value(counter, 100, TestScenario::ctx(scenario)); - - TestScenario::return_shared(scenario, counter_wrapper); - }; - - TestScenario::next_tx(scenario, &user1); - { - let counter_wrapper = TestScenario::take_shared(scenario); - let counter = TestScenario::borrow_mut(&mut counter_wrapper); - - assert!(Counter::owner(counter) == owner, 0); - assert!(Counter::value(counter) == 100, 1); - - Counter::increment(counter); - - assert!(Counter::value(counter) == 101, 2); - - TestScenario::return_shared(scenario, counter_wrapper); - }; - } -} diff --git a/sui_programmability/examples/basics/sources/Sandwich.move b/sui_programmability/examples/basics/sources/Sandwich.move deleted file mode 100644 index 33c02f1b8075a..0000000000000 --- a/sui_programmability/examples/basics/sources/Sandwich.move +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -/// Example of objects that can be combined to create -/// new objects -module Basics::Sandwich { - use Sui::Balance::{Self, Balance}; - use Sui::Coin::{Self, Coin}; - use Sui::ID::{Self, VersionedID}; - use Sui::SUI::SUI; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; - - struct Ham has key { - id: VersionedID - } - - struct Bread has key { - id: VersionedID - } - - struct Sandwich has key { - id: VersionedID, - } - - // This Capability allows the owner to withdraw profits - struct GroceryOwnerCapability has key { - id: VersionedID - } - - // Grocery is created on module init - struct Grocery has key { - id: VersionedID, - profits: Balance - } - - /// Price for ham - const HAM_PRICE: u64 = 10; - /// Price for bread - const BREAD_PRICE: u64 = 2; - - /// Not enough funds to pay for the good in question - const EInsufficientFunds: u64 = 0; - /// Nothing to withdraw - const ENoProfits: u64 = 1; - - /// On module init, create a grocery - fun init(ctx: &mut TxContext) { - Transfer::share_object(Grocery { - id: TxContext::new_id(ctx), - profits: Balance::zero() - }); - - Transfer::transfer(GroceryOwnerCapability { - id: TxContext::new_id(ctx) - }, TxContext::sender(ctx)); - } - - /// Exchange `c` for some ham - public entry fun buy_ham( - grocery: &mut Grocery, - c: Coin, - ctx: &mut TxContext - ) { - let b = Coin::into_balance(c); - assert!(Balance::value(&b) == HAM_PRICE, EInsufficientFunds); - Balance::join(&mut grocery.profits, b); - Transfer::transfer(Ham { id: TxContext::new_id(ctx) }, TxContext::sender(ctx)) - } - - /// Exchange `c` for some bread - public entry fun buy_bread( - grocery: &mut Grocery, - c: Coin, - ctx: &mut TxContext - ) { - let b = Coin::into_balance(c); - assert!(Balance::value(&b) == BREAD_PRICE, EInsufficientFunds); - Balance::join(&mut grocery.profits, b); - Transfer::transfer(Bread { id: TxContext::new_id(ctx) }, TxContext::sender(ctx)) - } - - /// Combine the `ham` and `bread` into a delicious sandwich - public entry fun make_sandwich( - ham: Ham, bread: Bread, ctx: &mut TxContext - ) { - let Ham { id: ham_id } = ham; - let Bread { id: bread_id } = bread; - ID::delete(ham_id); - ID::delete(bread_id); - Transfer::transfer(Sandwich { id: TxContext::new_id(ctx) }, TxContext::sender(ctx)) - } - - /// See the profits of a grocery - public fun profits(grocery: &Grocery): u64 { - Balance::value(&grocery.profits) - } - - /// Owner of the grocery can collect profits by passing his capability - public entry fun collect_profits(_cap: &GroceryOwnerCapability, grocery: &mut Grocery, ctx: &mut TxContext) { - let amount = Balance::value(&grocery.profits); - - assert!(amount > 0, ENoProfits); - - // Take a transferable `Coin` from a `Balance` - let coin = Coin::withdraw(&mut grocery.profits, amount, ctx); - - Transfer::transfer(coin, TxContext::sender(ctx)); - } - - #[test_only] - public fun init_for_testing(ctx: &mut TxContext) { - init(ctx); - } -} - -#[test_only] -module Basics::TestSandwich { - use Basics::Sandwich::{Self, Grocery, GroceryOwnerCapability, Bread, Ham}; - use Sui::TestScenario; - use Sui::Coin::{Self}; - use Sui::SUI::SUI; - - #[test] - fun test_make_sandwich() { - let owner = @0x1; - let the_guy = @0x2; - - let scenario = &mut TestScenario::begin(&owner); - TestScenario::next_tx(scenario, &owner); - { - Sandwich::init_for_testing(TestScenario::ctx(scenario)); - }; - - TestScenario::next_tx(scenario, &the_guy); - { - let grocery_wrapper = TestScenario::take_shared(scenario); - let grocery = TestScenario::borrow_mut(&mut grocery_wrapper); - let ctx = TestScenario::ctx(scenario); - - Sandwich::buy_ham( - grocery, - Coin::mint_for_testing(10, ctx), - ctx - ); - - Sandwich::buy_bread( - grocery, - Coin::mint_for_testing(2, ctx), - ctx - ); - - TestScenario::return_shared(scenario, grocery_wrapper); - }; - - TestScenario::next_tx(scenario, &the_guy); - { - let ham = TestScenario::take_owned(scenario); - let bread = TestScenario::take_owned(scenario); - - Sandwich::make_sandwich(ham, bread, TestScenario::ctx(scenario)); - }; - - TestScenario::next_tx(scenario, &owner); - { - let grocery_wrapper = TestScenario::take_shared(scenario); - let grocery = TestScenario::borrow_mut(&mut grocery_wrapper); - let capability = TestScenario::take_owned(scenario); - - assert!(Sandwich::profits(grocery) == 12, 0); - Sandwich::collect_profits(&capability, grocery, TestScenario::ctx(scenario)); - assert!(Sandwich::profits(grocery) == 0, 0); - - TestScenario::return_owned(scenario, capability); - TestScenario::return_shared(scenario, grocery_wrapper); - }; - } -} diff --git a/sui_programmability/examples/basics/sources/counter.move b/sui_programmability/examples/basics/sources/counter.move new file mode 100644 index 0000000000000..ad3610fa6d3b3 --- /dev/null +++ b/sui_programmability/examples/basics/sources/counter.move @@ -0,0 +1,114 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +/// This example demonstrates a basic use of a shared object. +/// Rules: +/// - anyone can create and share a counter +/// - everyone can increment a counter by 1 +/// - the owner of the counter can reset it to any value +module basics::counter { + use sui::transfer; + use sui::id::VersionedID; + use sui::tx_context::{Self, TxContext}; + + /// A shared counter. + struct Counter has key { + id: VersionedID, + owner: address, + value: u64 + } + + public fun owner(counter: &Counter): address { + counter.owner + } + + public fun value(counter: &Counter): u64 { + counter.value + } + + /// Create and share a Counter object. + public entry fun create(ctx: &mut TxContext) { + transfer::share_object(Counter { + id: tx_context::new_id(ctx), + owner: tx_context::sender(ctx), + value: 0 + }) + } + + /// Increment a counter by 1. + public entry fun increment(counter: &mut Counter) { + counter.value = counter.value + 1; + } + + /// Set value (only runnable by the Counter owner) + public entry fun set_value(counter: &mut Counter, value: u64, ctx: &mut TxContext) { + assert!(counter.owner == tx_context::sender(ctx), 0); + counter.value = value; + } + + /// Assert a value for the counter. + public entry fun assert_value(counter: &Counter, value: u64) { + assert!(counter.value == value, 0) + } +} + +#[test_only] +module basics::counter_test { + use sui::test_scenario; + use basics::counter; + + #[test] + fun test_counter() { + let owner = @0xC0FFEE; + let user1 = @0xA1; + + let scenario = &mut test_scenario::begin(&user1); + + test_scenario::next_tx(scenario, &owner); + { + counter::create(test_scenario::ctx(scenario)); + }; + + test_scenario::next_tx(scenario, &user1); + { + let counter_wrapper = test_scenario::take_shared(scenario); + let counter = test_scenario::borrow_mut(&mut counter_wrapper); + + assert!(counter::owner(counter) == owner, 0); + assert!(counter::value(counter) == 0, 1); + + counter::increment(counter); + counter::increment(counter); + counter::increment(counter); + test_scenario::return_shared(scenario, counter_wrapper); + }; + + test_scenario::next_tx(scenario, &owner); + { + let counter_wrapper = test_scenario::take_shared(scenario); + let counter = test_scenario::borrow_mut(&mut counter_wrapper); + + assert!(counter::owner(counter) == owner, 0); + assert!(counter::value(counter) == 3, 1); + + counter::set_value(counter, 100, test_scenario::ctx(scenario)); + + test_scenario::return_shared(scenario, counter_wrapper); + }; + + test_scenario::next_tx(scenario, &user1); + { + let counter_wrapper = test_scenario::take_shared(scenario); + let counter = test_scenario::borrow_mut(&mut counter_wrapper); + + assert!(counter::owner(counter) == owner, 0); + assert!(counter::value(counter) == 100, 1); + + counter::increment(counter); + + assert!(counter::value(counter) == 101, 2); + + test_scenario::return_shared(scenario, counter_wrapper); + }; + } +} diff --git a/sui_programmability/examples/basics/sources/Lock.move b/sui_programmability/examples/basics/sources/lock.move similarity index 64% rename from sui_programmability/examples/basics/sources/Lock.move rename to sui_programmability/examples/basics/sources/lock.move index cf790ec5164f5..0cee98ddfd85b 100644 --- a/sui_programmability/examples/basics/sources/Lock.move +++ b/sui_programmability/examples/basics/sources/lock.move @@ -6,10 +6,10 @@ /// This module allows any content to be locked inside a 'virtual chest' and later /// be accessed by putting a 'key' into the 'lock'. Lock is shared and is visible /// and discoverable by the key owner. -module Basics::Lock { - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module basics::lock { + use sui::id::{Self, ID, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; use std::option::{Self, Option}; /// Lock is empty, nothing to take. @@ -42,18 +42,18 @@ module Basics::Lock { /// Lock some content inside a shared object. A Key is created and is /// sent to the transaction sender. public entry fun create(obj: T, ctx: &mut TxContext) { - let id = TxContext::new_id(ctx); - let for = *ID::inner(&id); + let id = tx_context::new_id(ctx); + let for = *id::inner(&id); - Transfer::share_object(Lock { + transfer::share_object(Lock { id, locked: option::some(obj), }); - Transfer::transfer(Key { + transfer::transfer(Key { for, - id: TxContext::new_id(ctx) - }, TxContext::sender(ctx)); + id: tx_context::new_id(ctx) + }, tx_context::sender(ctx)); } /// Lock something inside a shared object using a Key. Aborts if @@ -64,7 +64,7 @@ module Basics::Lock { key: &Key, ) { assert!(option::is_none(&lock.locked), ELockIsFull); - assert!(&key.for == ID::id(lock), EKeyMismatch); + assert!(&key.for == id::id(lock), EKeyMismatch); option::fill(&mut lock.locked, obj); } @@ -78,7 +78,7 @@ module Basics::Lock { key: &Key, ): T { assert!(option::is_some(&lock.locked), ELockIsEmpty); - assert!(&key.for == ID::id(lock), EKeyMismatch); + assert!(&key.for == id::id(lock), EKeyMismatch); option::extract(&mut lock.locked) } @@ -89,17 +89,17 @@ module Basics::Lock { key: &Key, ctx: &mut TxContext, ) { - Transfer::transfer(unlock(lock, key), TxContext::sender(ctx)) + transfer::transfer(unlock(lock, key), tx_context::sender(ctx)) } } #[test_only] -module Basics::LockTest { - use Sui::ID::VersionedID; - use Sui::TestScenario; - use Sui::TxContext; - use Sui::Transfer; - use Basics::Lock::{Self, Lock, Key}; +module basics::lockTest { + use sui::id::VersionedID; + use sui::test_scenario; + use sui::tx_context; + use sui::transfer; + use basics::lock::{Self, Lock, Key}; /// Custom structure which we will store inside a Lock. struct Treasure has store, key { @@ -111,38 +111,38 @@ module Basics::LockTest { let user1 = @0x1; let user2 = @0x2; - let scenario = &mut TestScenario::begin(&user1); + let scenario = &mut test_scenario::begin(&user1); // User1 creates a lock and places his treasure inside. - TestScenario::next_tx(scenario, &user1); + test_scenario::next_tx(scenario, &user1); { - let ctx = TestScenario::ctx(scenario); - let id = TxContext::new_id(ctx); + let ctx = test_scenario::ctx(scenario); + let id = tx_context::new_id(ctx); - Lock::create(Treasure { id }, ctx); + lock::create(Treasure { id }, ctx); }; // Now User1 owns a key from the lock. He decides to send this // key to User2, so that he can have access to the stored treasure. - TestScenario::next_tx(scenario, &user1); + test_scenario::next_tx(scenario, &user1); { - let key = TestScenario::take_owned>(scenario); + let key = test_scenario::take_owned>(scenario); - Transfer::transfer(key, user2); + transfer::transfer(key, user2); }; // User2 is impatient and he decides to take the treasure. - TestScenario::next_tx(scenario, &user2); + test_scenario::next_tx(scenario, &user2); { - let lock_wrapper = TestScenario::take_shared>(scenario); - let lock = TestScenario::borrow_mut(&mut lock_wrapper); - let key = TestScenario::take_owned>(scenario); - let ctx = TestScenario::ctx(scenario); + let lock_wrapper = test_scenario::take_shared>(scenario); + let lock = test_scenario::borrow_mut(&mut lock_wrapper); + let key = test_scenario::take_owned>(scenario); + let ctx = test_scenario::ctx(scenario); - Lock::take(lock, &key, ctx); + lock::take(lock, &key, ctx); - TestScenario::return_shared(scenario, lock_wrapper); - TestScenario::return_owned(scenario, key); + test_scenario::return_shared(scenario, lock_wrapper); + test_scenario::return_owned(scenario, key); }; } } diff --git a/sui_programmability/examples/basics/sources/Object.move b/sui_programmability/examples/basics/sources/object.move similarity index 91% rename from sui_programmability/examples/basics/sources/Object.move rename to sui_programmability/examples/basics/sources/object.move index 68a26f744a0e7..d50a92a0c7d12 100644 --- a/sui_programmability/examples/basics/sources/Object.move +++ b/sui_programmability/examples/basics/sources/object.move @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 /// An example of a custom object with comments explaining the relevant bits -module Basics::Object { - use Sui::ID::VersionedID; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module basics::object { + use sui::id::VersionedID; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// A custom sui object. Every object must have the `key` attribute /// (indicating that it is allowed to be a key in the sui global object @@ -48,7 +48,7 @@ module Basics::Object { /// be transferred by the module that declares it. public fun transfer(o: Object, recipient: address) { assert!(some_conditional_logic(), 0); - Transfer::transfer(o, recipient) + transfer::transfer(o, recipient) } /// Simple getter @@ -61,10 +61,10 @@ module Basics::Object { /// from this module to read/write it, package it into another object, ...) public fun create(tx: &mut TxContext): Object { Object { - id: TxContext::new_id(tx), + id: tx_context::new_id(tx), custom_field: 0, child_obj: ChildObject { a_field: false }, - nested_obj: AnotherObject { id: TxContext::new_id(tx) } + nested_obj: AnotherObject { id: tx_context::new_id(tx) } } } @@ -99,8 +99,8 @@ module Basics::Object { write_field(to_write, v + int_input); transfer(to_consume, recipient); // demonstrate creating a new object for the sender - let sender = TxContext::sender(ctx); - Transfer::transfer(create(ctx), sender) + let sender = tx_context::sender(ctx); + transfer::transfer(create(ctx), sender) } fun some_conditional_logic(): bool { diff --git a/sui_programmability/examples/basics/sources/sandwich.move b/sui_programmability/examples/basics/sources/sandwich.move new file mode 100644 index 0000000000000..2e5fcf82f67b5 --- /dev/null +++ b/sui_programmability/examples/basics/sources/sandwich.move @@ -0,0 +1,178 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +/// Example of objects that can be combined to create +/// new objects +module basics::sandwich { + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin}; + use sui::id::{Self, VersionedID}; + use sui::sui::SUI; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + + struct Ham has key { + id: VersionedID + } + + struct Bread has key { + id: VersionedID + } + + struct Sandwich has key { + id: VersionedID, + } + + // This Capability allows the owner to withdraw profits + struct GroceryOwnerCapability has key { + id: VersionedID + } + + // Grocery is created on module init + struct Grocery has key { + id: VersionedID, + profits: Balance + } + + /// Price for ham + const HAM_PRICE: u64 = 10; + /// Price for bread + const BREAD_PRICE: u64 = 2; + + /// Not enough funds to pay for the good in question + const EInsufficientFunds: u64 = 0; + /// Nothing to withdraw + const ENoProfits: u64 = 1; + + /// On module init, create a grocery + fun init(ctx: &mut TxContext) { + transfer::share_object(Grocery { + id: tx_context::new_id(ctx), + profits: balance::zero() + }); + + transfer::transfer(GroceryOwnerCapability { + id: tx_context::new_id(ctx) + }, tx_context::sender(ctx)); + } + + /// Exchange `c` for some ham + public entry fun buy_ham( + grocery: &mut Grocery, + c: Coin, + ctx: &mut TxContext + ) { + let b = coin::into_balance(c); + assert!(balance::value(&b) == HAM_PRICE, EInsufficientFunds); + balance::join(&mut grocery.profits, b); + transfer::transfer(Ham { id: tx_context::new_id(ctx) }, tx_context::sender(ctx)) + } + + /// Exchange `c` for some bread + public entry fun buy_bread( + grocery: &mut Grocery, + c: Coin, + ctx: &mut TxContext + ) { + let b = coin::into_balance(c); + assert!(balance::value(&b) == BREAD_PRICE, EInsufficientFunds); + balance::join(&mut grocery.profits, b); + transfer::transfer(Bread { id: tx_context::new_id(ctx) }, tx_context::sender(ctx)) + } + + /// Combine the `ham` and `bread` into a delicious sandwich + public entry fun make_sandwich( + ham: Ham, bread: Bread, ctx: &mut TxContext + ) { + let Ham { id: ham_id } = ham; + let Bread { id: bread_id } = bread; + id::delete(ham_id); + id::delete(bread_id); + transfer::transfer(Sandwich { id: tx_context::new_id(ctx) }, tx_context::sender(ctx)) + } + + /// See the profits of a grocery + public fun profits(grocery: &Grocery): u64 { + balance::value(&grocery.profits) + } + + /// Owner of the grocery can collect profits by passing his capability + public entry fun collect_profits(_cap: &GroceryOwnerCapability, grocery: &mut Grocery, ctx: &mut TxContext) { + let amount = balance::value(&grocery.profits); + + assert!(amount > 0, ENoProfits); + + // Take a transferable `Coin` from a `Balance` + let coin = coin::withdraw(&mut grocery.profits, amount, ctx); + + transfer::transfer(coin, tx_context::sender(ctx)); + } + + #[test_only] + public fun init_for_testing(ctx: &mut TxContext) { + init(ctx); + } +} + +#[test_only] +module basics::test_sandwich { + use basics::sandwich::{Self, Grocery, GroceryOwnerCapability, Bread, Ham}; + use sui::test_scenario; + use sui::coin::{Self}; + use sui::sui::SUI; + + #[test] + fun test_make_sandwich() { + let owner = @0x1; + let the_guy = @0x2; + + let scenario = &mut test_scenario::begin(&owner); + test_scenario::next_tx(scenario, &owner); + { + sandwich::init_for_testing(test_scenario::ctx(scenario)); + }; + + test_scenario::next_tx(scenario, &the_guy); + { + let grocery_wrapper = test_scenario::take_shared(scenario); + let grocery = test_scenario::borrow_mut(&mut grocery_wrapper); + let ctx = test_scenario::ctx(scenario); + + sandwich::buy_ham( + grocery, + coin::mint_for_testing(10, ctx), + ctx + ); + + sandwich::buy_bread( + grocery, + coin::mint_for_testing(2, ctx), + ctx + ); + + test_scenario::return_shared(scenario, grocery_wrapper); + }; + + test_scenario::next_tx(scenario, &the_guy); + { + let ham = test_scenario::take_owned(scenario); + let bread = test_scenario::take_owned(scenario); + + sandwich::make_sandwich(ham, bread, test_scenario::ctx(scenario)); + }; + + test_scenario::next_tx(scenario, &owner); + { + let grocery_wrapper = test_scenario::take_shared(scenario); + let grocery = test_scenario::borrow_mut(&mut grocery_wrapper); + let capability = test_scenario::take_owned(scenario); + + assert!(sandwich::profits(grocery) == 12, 0); + sandwich::collect_profits(&capability, grocery, test_scenario::ctx(scenario)); + assert!(sandwich::profits(grocery) == 0, 0); + + test_scenario::return_owned(scenario, capability); + test_scenario::return_shared(scenario, grocery_wrapper); + }; + } +} diff --git a/sui_programmability/examples/defi/Move.toml b/sui_programmability/examples/defi/Move.toml index 2077759bb9758..0078d0e6bb688 100644 --- a/sui_programmability/examples/defi/Move.toml +++ b/sui_programmability/examples/defi/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { local = "../../../crates/sui-framework" } [addresses] -DeFi = "0x0" +defi = "0x0" diff --git a/sui_programmability/examples/defi/sources/Escrow.move b/sui_programmability/examples/defi/sources/escrow.move similarity index 83% rename from sui_programmability/examples/defi/sources/Escrow.move rename to sui_programmability/examples/defi/sources/escrow.move index 8f2680f5ff035..7d61661249a2d 100644 --- a/sui_programmability/examples/defi/sources/Escrow.move +++ b/sui_programmability/examples/defi/sources/escrow.move @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 /// An escrow for atomic swap of objects that trusts a third party for liveness, but not safety. -module DeFi::Escrow { - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module defi::escrow { + use sui::id::{Self, ID, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// An object held in escrow struct EscrowedObj has key, store { @@ -39,10 +39,10 @@ module DeFi::Escrow { escrowed: T, ctx: &mut TxContext ) { - let sender = TxContext::sender(ctx); - let id = TxContext::new_id(ctx); + let sender = tx_context::sender(ctx); + let id = tx_context::new_id(ctx); // escrow the object with the trusted third party - Transfer::transfer( + transfer::transfer( EscrowedObj { id, sender, recipient, exchange_for, escrowed }, @@ -69,17 +69,17 @@ module DeFi::Escrow { exchange_for: exchange_for2, escrowed: escrowed2, } = obj2; - ID::delete(id1); - ID::delete(id2); + id::delete(id1); + id::delete(id2); // check sender/recipient compatibility assert!(&sender1 == &recipient2, EMismatchedSenderRecipient); assert!(&sender2 == &recipient1, EMismatchedSenderRecipient); // check object ID compatibility - assert!(ID::id(&escrowed1) == &exchange_for2, EMismatchedExchangeObject); - assert!(ID::id(&escrowed2) == &exchange_for1, EMismatchedExchangeObject); + assert!(id::id(&escrowed1) == &exchange_for2, EMismatchedExchangeObject); + assert!(id::id(&escrowed2) == &exchange_for1, EMismatchedExchangeObject); // everything matches. do the swap! - Transfer::transfer(escrowed1, sender2); - Transfer::transfer(escrowed2, sender1) + transfer::transfer(escrowed1, sender2); + transfer::transfer(escrowed2, sender1) } /// Trusted third party can always return an escrowed object to its original owner @@ -89,7 +89,7 @@ module DeFi::Escrow { let EscrowedObj { id, sender, recipient: _, exchange_for: _, escrowed } = obj; - ID::delete(id); - Transfer::transfer(escrowed, sender) + id::delete(id); + transfer::transfer(escrowed, sender) } } diff --git a/sui_programmability/examples/defi/sources/FlashLender.move b/sui_programmability/examples/defi/sources/flash_lender.move similarity index 83% rename from sui_programmability/examples/defi/sources/FlashLender.move rename to sui_programmability/examples/defi/sources/flash_lender.move index 3185af7342652..60e0b0930239f 100644 --- a/sui_programmability/examples/defi/sources/FlashLender.move +++ b/sui_programmability/examples/defi/sources/flash_lender.move @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 /// A flash loan that works for any Coin type -module DeFi::FlashLender { - use Sui::Balance::{Self, Balance}; - use Sui::Coin::{Self, Coin}; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module defi::flash_lender { + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin}; + use sui::id::{Self, ID, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// A shared object offering flash loans to any buyer willing to pay `fee`. struct FlashLender has key { @@ -68,20 +68,20 @@ module DeFi::FlashLender { /// Any borrower will need to repay the borrowed amount and `fee` by the end of the /// current transaction. public fun new(to_lend: Balance, fee: u64, ctx: &mut TxContext): AdminCap { - let id = TxContext::new_id(ctx); - let flash_lender_id = *ID::inner(&id); + let id = tx_context::new_id(ctx); + let flash_lender_id = *id::inner(&id); let flash_lender = FlashLender { id, to_lend, fee }; // make the `FlashLender` a shared object so anyone can request loans - Transfer::share_object(flash_lender); + transfer::share_object(flash_lender); // give the creator admin permissions - AdminCap { id: TxContext::new_id(ctx), flash_lender_id } + AdminCap { id: tx_context::new_id(ctx), flash_lender_id } } /// Same as `new`, but transfer `WithdrawCap` to the transaction sender public entry fun create(to_lend: Coin, fee: u64, ctx: &mut TxContext) { - let balance = Coin::into_balance(to_lend); + let balance = coin::into_balance(to_lend); let withdraw_cap = new(balance, fee, ctx); - Transfer::transfer(withdraw_cap, TxContext::sender(ctx)) + transfer::transfer(withdraw_cap, tx_context::sender(ctx)) } // === Core functionality: requesting a loan and repaying it === @@ -93,10 +93,10 @@ module DeFi::FlashLender { self: &mut FlashLender, amount: u64, ctx: &mut TxContext ): (Coin, Receipt) { let to_lend = &mut self.to_lend; - assert!(Balance::value(to_lend) >= amount, ELoanTooLarge); - let loan = Coin::withdraw(to_lend, amount, ctx); + assert!(balance::value(to_lend) >= amount, ELoanTooLarge); + let loan = coin::withdraw(to_lend, amount, ctx); let repay_amount = amount + self.fee; - let receipt = Receipt { flash_lender_id: *ID::id(self), repay_amount }; + let receipt = Receipt { flash_lender_id: *id::id(self), repay_amount }; (loan, receipt) } @@ -105,10 +105,10 @@ module DeFi::FlashLender { /// that issued the original loan. public fun repay(self: &mut FlashLender, payment: Coin, receipt: Receipt) { let Receipt { flash_lender_id, repay_amount } = receipt; - assert!(ID::id(self) == &flash_lender_id, ERepayToWrongLender); - assert!(Coin::value(&payment) == repay_amount, EInvalidRepaymentAmount); + assert!(id::id(self) == &flash_lender_id, ERepayToWrongLender); + assert!(coin::value(&payment) == repay_amount, EInvalidRepaymentAmount); - Coin::deposit(&mut self.to_lend, payment) + coin::deposit(&mut self.to_lend, payment) } // === Admin-only functionality === @@ -124,8 +124,8 @@ module DeFi::FlashLender { check_admin(self, admin_cap); let to_lend = &mut self.to_lend; - assert!(Balance::value(to_lend) >= amount, EWithdrawTooLarge); - Coin::withdraw(to_lend, amount, ctx) + assert!(balance::value(to_lend) >= amount, EWithdrawTooLarge); + coin::withdraw(to_lend, amount, ctx) } /// Allow admin to add more funds to `self` @@ -134,7 +134,7 @@ module DeFi::FlashLender { ) { // only the holder of the `AdminCap` for `self` can deposit funds check_admin(self, admin_cap); - Coin::deposit(&mut self.to_lend, coin); + coin::deposit(&mut self.to_lend, coin); } /// Allow admin to update the fee for `self` @@ -148,7 +148,7 @@ module DeFi::FlashLender { } fun check_admin(self: &FlashLender, admin_cap: &AdminCap) { - assert!(ID::id(self) == &admin_cap.flash_lender_id, EAdminOnly); + assert!(id::id(self) == &admin_cap.flash_lender_id, EAdminOnly); } // === Reads === @@ -160,7 +160,7 @@ module DeFi::FlashLender { /// Return the maximum amount available for borrowing public fun max_loan(self: &FlashLender): u64 { - Balance::value(&self.to_lend) + balance::value(&self.to_lend) } /// Return the amount that the holder of `self` must repay diff --git a/sui_programmability/examples/defi/sources/SharedEscrow.move b/sui_programmability/examples/defi/sources/shared_escrow.move similarity index 78% rename from sui_programmability/examples/defi/sources/SharedEscrow.move rename to sui_programmability/examples/defi/sources/shared_escrow.move index ba72440323e4d..d41201547fde5 100644 --- a/sui_programmability/examples/defi/sources/SharedEscrow.move +++ b/sui_programmability/examples/defi/sources/shared_escrow.move @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 /// An escrow for atomic swap of objects without a trusted third party -module DeFi::SharedEscrow { +module defi::shared_escrow { use std::option::{Self, Option}; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::id::{Self, ID, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// An object held in escrow struct EscrowedObj has key, store { @@ -39,10 +39,10 @@ module DeFi::SharedEscrow { escrowed_item: T, ctx: &mut TxContext ) { - let creator = TxContext::sender(ctx); - let id = TxContext::new_id(ctx); + let creator = tx_context::sender(ctx); + let id = tx_context::new_id(ctx); let escrowed = option::some(escrowed_item); - Transfer::share_object( + transfer::share_object( EscrowedObj { id, creator, recipient, exchange_for, escrowed } @@ -57,11 +57,11 @@ module DeFi::SharedEscrow { ) { assert!(option::is_some(&escrow.escrowed), EAlreadyExchangedOrCancelled); let escrowed_item = option::extract(&mut escrow.escrowed); - assert!(&TxContext::sender(ctx) == &escrow.recipient, EWrongRecipient); - assert!(ID::id(&obj) == &escrow.exchange_for, EWrongExchangeObject); + assert!(&tx_context::sender(ctx) == &escrow.recipient, EWrongRecipient); + assert!(id::id(&obj) == &escrow.exchange_for, EWrongExchangeObject); // everything matches. do the swap! - Transfer::transfer(escrowed_item, TxContext::sender(ctx)); - Transfer::transfer(obj, escrow.creator); + transfer::transfer(escrowed_item, tx_context::sender(ctx)); + transfer::transfer(obj, escrow.creator); } /// The `creator` can cancel the escrow and get back the escrowed item @@ -69,8 +69,8 @@ module DeFi::SharedEscrow { escrow: &mut EscrowedObj, ctx: &mut TxContext ) { - assert!(&TxContext::sender(ctx) == &escrow.creator, EWrongOwner); + assert!(&tx_context::sender(ctx) == &escrow.creator, EWrongOwner); assert!(option::is_some(&escrow.escrowed), EAlreadyExchangedOrCancelled); - Transfer::transfer(option::extract(&mut escrow.escrowed), escrow.creator); + transfer::transfer(option::extract(&mut escrow.escrowed), escrow.creator); } } diff --git a/sui_programmability/examples/defi/tests/FlashLenderTests.move b/sui_programmability/examples/defi/tests/FlashLenderTests.move deleted file mode 100644 index 7d6a0a4d5e0e4..0000000000000 --- a/sui_programmability/examples/defi/tests/FlashLenderTests.move +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module DeFi::FlashLenderTests { - use DeFi::FlashLender::{Self, AdminCap, FlashLender}; - use Sui::Coin; - use Sui::SUI::SUI; - use Sui::TestScenario; - - #[test] - fun flash_loan_example() { - let admin = @0x1; - let borrower = @0x2; - - // admin creates a flash lender with 100 coins and a fee of 1 coin - let scenario = &mut TestScenario::begin(&admin); - { - let ctx = TestScenario::ctx(scenario); - let coin = Coin::mint_for_testing(100, ctx); - FlashLender::create(coin, 1, ctx); - }; - // borrower requests and repays a loan of 10 coins + the fee - TestScenario::next_tx(scenario, &borrower); - { - let lender_wrapper = TestScenario::take_shared>(scenario); - let lender = TestScenario::borrow_mut(&mut lender_wrapper); - let ctx = TestScenario::ctx(scenario); - - let (loan, receipt) = FlashLender::loan(lender, 10, ctx); - // in practice, borrower does something (e.g., arbitrage) to make a profit from the loan. - // simulate this by min ting the borrower 5 coins. - let profit = Coin::mint_for_testing(5, ctx); - Coin::join(&mut profit, loan); - let to_keep = Coin::withdraw(Coin::balance_mut(&mut profit), 4, ctx); - Coin::keep(to_keep, ctx); - FlashLender::repay(lender, profit, receipt); - - TestScenario::return_shared(scenario, lender_wrapper); - }; - // admin withdraws the 1 coin profit from lending - TestScenario::next_tx(scenario, &admin); - { - let lender_wrapper = TestScenario::take_shared>(scenario); - let lender = TestScenario::borrow_mut(&mut lender_wrapper); - let admin_cap = TestScenario::take_owned(scenario); - let ctx = TestScenario::ctx(scenario); - - // max loan size should have increased because of the fee payment - assert!(FlashLender::max_loan(lender) == 101, 0); - // withdraw 1 coin from the pool available for lending - let coin = FlashLender::withdraw(lender, &admin_cap, 1, ctx); - // max loan size should decrease accordingly - assert!(FlashLender::max_loan(lender) == 100, 0); - Coin::keep(coin, ctx); - - TestScenario::return_shared(scenario, lender_wrapper); - TestScenario::return_owned(scenario, admin_cap); - } - } -} diff --git a/sui_programmability/examples/defi/tests/EscrowTests.move b/sui_programmability/examples/defi/tests/escrow_tests.move similarity index 68% rename from sui_programmability/examples/defi/tests/EscrowTests.move rename to sui_programmability/examples/defi/tests/escrow_tests.move index 759d74f0721c0..935d161111a35 100644 --- a/sui_programmability/examples/defi/tests/EscrowTests.move +++ b/sui_programmability/examples/defi/tests/escrow_tests.move @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module DeFi::EscrowTests { - use Sui::ID::{Self, VersionedID}; - use Sui::TestScenario::{Self, Scenario}; - use Sui::TxContext::{Self}; +module defi::escrow_tests { + use sui::id::{Self, VersionedID}; + use sui::test_scenario::{Self, Scenario}; + use sui::tx_context::{Self}; - use DeFi::Escrow::{Self, EscrowedObj}; + use defi::escrow::{Self, EscrowedObj}; const ALICE_ADDRESS: address = @0xACE; const BOB_ADDRESS: address = @0xACEB; @@ -45,13 +45,13 @@ module DeFi::EscrowTests { let scenario = &mut send_to_escrow(ALICE_ADDRESS, BOB_ADDRESS); // The third party returns item A to Alice, item B to Bob - TestScenario::next_tx(scenario, &THIRD_PARTY_ADDRESS); + test_scenario::next_tx(scenario, &THIRD_PARTY_ADDRESS); { - let item_a = TestScenario::take_owned>(scenario); - Escrow::return_to_sender(item_a); + let item_a = test_scenario::take_owned>(scenario); + escrow::return_to_sender(item_a); - let item_b = TestScenario::take_owned>(scenario); - Escrow::return_to_sender(item_b); + let item_b = test_scenario::take_owned>(scenario); + escrow::return_to_sender(item_b); }; // Alice now owns item A, and Bob now owns item B @@ -78,11 +78,11 @@ module DeFi::EscrowTests { } fun swap(scenario: &mut Scenario, third_party: &address) { - TestScenario::next_tx(scenario, third_party); + test_scenario::next_tx(scenario, third_party); { - let item_a = TestScenario::take_owned>(scenario); - let item_b = TestScenario::take_owned>(scenario); - Escrow::swap(item_a, item_b); + let item_a = test_scenario::take_owned>(scenario); + let item_b = test_scenario::take_owned>(scenario); + escrow::swap(item_a, item_b); }; } @@ -99,25 +99,25 @@ module DeFi::EscrowTests { override_exchange_for: bool, override_recipient: bool, ): Scenario { - let new_scenario = TestScenario::begin(&alice); + let new_scenario = test_scenario::begin(&alice); let scenario = &mut new_scenario; - let ctx = TestScenario::ctx(scenario); - let item_a_versioned_id = TxContext::new_id(ctx); + let ctx = test_scenario::ctx(scenario); + let item_a_versioned_id = tx_context::new_id(ctx); - TestScenario::next_tx(scenario, &bob); - let ctx = TestScenario::ctx(scenario); - let item_b_versioned_id = TxContext::new_id(ctx); + test_scenario::next_tx(scenario, &bob); + let ctx = test_scenario::ctx(scenario); + let item_b_versioned_id = tx_context::new_id(ctx); - let item_a_id = *ID::inner(&item_a_versioned_id); - let item_b_id = *ID::inner(&item_b_versioned_id); + let item_a_id = *id::inner(&item_a_versioned_id); + let item_b_id = *id::inner(&item_b_versioned_id); if (override_exchange_for) { - item_b_id = ID::new(RANDOM_ADDRESS); + item_b_id = id::new(RANDOM_ADDRESS); }; // Alice sends item A to the third party - TestScenario::next_tx(scenario, &alice); + test_scenario::next_tx(scenario, &alice); { - let ctx = TestScenario::ctx(scenario); + let ctx = test_scenario::ctx(scenario); let escrowed = ItemA { id: item_a_versioned_id }; @@ -125,7 +125,7 @@ module DeFi::EscrowTests { if (override_recipient) { recipient = RANDOM_ADDRESS; }; - Escrow::create( + escrow::create( recipient, THIRD_PARTY_ADDRESS, item_b_id, @@ -135,13 +135,13 @@ module DeFi::EscrowTests { }; // Bob sends item B to the third party - TestScenario::next_tx(scenario, &BOB_ADDRESS); + test_scenario::next_tx(scenario, &BOB_ADDRESS); { - let ctx = TestScenario::ctx(scenario); + let ctx = test_scenario::ctx(scenario); let escrowed = ItemB { id: item_b_versioned_id }; - Escrow::create( + escrow::create( alice, THIRD_PARTY_ADDRESS, item_a_id, @@ -153,7 +153,7 @@ module DeFi::EscrowTests { } fun owns_object(scenario: &mut Scenario, owner: &address): bool{ - TestScenario::next_tx(scenario, owner); - TestScenario::can_take_owned(scenario) + test_scenario::next_tx(scenario, owner); + test_scenario::can_take_owned(scenario) } } diff --git a/sui_programmability/examples/defi/tests/flash_lender_tests.move b/sui_programmability/examples/defi/tests/flash_lender_tests.move new file mode 100644 index 0000000000000..b779adb046cc3 --- /dev/null +++ b/sui_programmability/examples/defi/tests/flash_lender_tests.move @@ -0,0 +1,61 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module defi::flash_lender_tests { + use defi::flash_lender::{Self, AdminCap, FlashLender}; + use sui::coin; + use sui::sui::SUI; + use sui::test_scenario; + + #[test] + fun flash_loan_example() { + let admin = @0x1; + let borrower = @0x2; + + // admin creates a flash lender with 100 coins and a fee of 1 coin + let scenario = &mut test_scenario::begin(&admin); + { + let ctx = test_scenario::ctx(scenario); + let coin = coin::mint_for_testing(100, ctx); + flash_lender::create(coin, 1, ctx); + }; + // borrower requests and repays a loan of 10 coins + the fee + test_scenario::next_tx(scenario, &borrower); + { + let lender_wrapper = test_scenario::take_shared>(scenario); + let lender = test_scenario::borrow_mut(&mut lender_wrapper); + let ctx = test_scenario::ctx(scenario); + + let (loan, receipt) = flash_lender::loan(lender, 10, ctx); + // in practice, borrower does something (e.g., arbitrage) to make a profit from the loan. + // simulate this by min ting the borrower 5 coins. + let profit = coin::mint_for_testing(5, ctx); + coin::join(&mut profit, loan); + let to_keep = coin::withdraw(coin::balance_mut(&mut profit), 4, ctx); + coin::keep(to_keep, ctx); + flash_lender::repay(lender, profit, receipt); + + test_scenario::return_shared(scenario, lender_wrapper); + }; + // admin withdraws the 1 coin profit from lending + test_scenario::next_tx(scenario, &admin); + { + let lender_wrapper = test_scenario::take_shared>(scenario); + let lender = test_scenario::borrow_mut(&mut lender_wrapper); + let admin_cap = test_scenario::take_owned(scenario); + let ctx = test_scenario::ctx(scenario); + + // max loan size should have increased because of the fee payment + assert!(flash_lender::max_loan(lender) == 101, 0); + // withdraw 1 coin from the pool available for lending + let coin = flash_lender::withdraw(lender, &admin_cap, 1, ctx); + // max loan size should decrease accordingly + assert!(flash_lender::max_loan(lender) == 100, 0); + coin::keep(coin, ctx); + + test_scenario::return_shared(scenario, lender_wrapper); + test_scenario::return_owned(scenario, admin_cap); + } + } +} diff --git a/sui_programmability/examples/defi/tests/SharedEscrowTest.move b/sui_programmability/examples/defi/tests/shared_escrow_test.move similarity index 69% rename from sui_programmability/examples/defi/tests/SharedEscrowTest.move rename to sui_programmability/examples/defi/tests/shared_escrow_test.move index a75893a8a5bc9..81b32b34d219a 100644 --- a/sui_programmability/examples/defi/tests/SharedEscrowTest.move +++ b/sui_programmability/examples/defi/tests/shared_escrow_test.move @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module DeFi::SharedEscrowTests { - use Sui::ID::{Self, VersionedID}; - use Sui::TestScenario::{Self, Scenario}; - use Sui::TxContext::{Self}; +module defi::shared_escrow_tests { + use sui::id::{Self, VersionedID}; + use sui::test_scenario::{Self, Scenario}; + use sui::tx_context::{Self}; - use DeFi::SharedEscrow::{Self, EscrowedObj}; + use defi::shared_escrow::{Self, EscrowedObj}; const ALICE_ADDRESS: address = @0xACE; const BOB_ADDRESS: address = @0xACEB; @@ -45,7 +45,7 @@ module DeFi::SharedEscrowTests { fun test_cancel() { // Alice creates the escrow let (scenario, id) = create_escrow(ALICE_ADDRESS, BOB_ADDRESS); - ID::delete(id); + id::delete(id); let scenario = &mut scenario; // Alice does not own item A assert!(!owns_object(scenario, &ALICE_ADDRESS), EReturnTransferFailed); @@ -62,7 +62,7 @@ module DeFi::SharedEscrowTests { fun test_cancel_with_wrong_owner() { // Alice creates the escrow let (scenario, id) = create_escrow(ALICE_ADDRESS, BOB_ADDRESS); - ID::delete(id); + id::delete(id); let scenario = &mut scenario; // Bob tries to cancel the escrow that Alice owns and expects failure @@ -74,13 +74,13 @@ module DeFi::SharedEscrowTests { fun test_swap_wrong_objects() { // Alice creates the escrow in exchange for item b let (scenario, item_b_versioned_id) = create_escrow(ALICE_ADDRESS, BOB_ADDRESS); - ID::delete(item_b_versioned_id); + id::delete(item_b_versioned_id); let scenario = &mut scenario; // Bob tries to exchange item C for the escrowed item A and expects failure - TestScenario::next_tx(scenario, &BOB_ADDRESS); - let ctx = TestScenario::ctx(scenario); - let item_c_versioned_id = TxContext::new_id(ctx); + test_scenario::next_tx(scenario, &BOB_ADDRESS); + let ctx = test_scenario::ctx(scenario); + let item_c_versioned_id = tx_context::new_id(ctx); exchange(scenario, &BOB_ADDRESS, item_c_versioned_id); } @@ -100,7 +100,7 @@ module DeFi::SharedEscrowTests { fun test_cancel_twice() { // Alice creates the escrow let (scenario, id) = create_escrow(ALICE_ADDRESS, BOB_ADDRESS); - ID::delete(id); + id::delete(id); let scenario = &mut scenario; // Alice does not own item A assert!(!owns_object(scenario, &ALICE_ADDRESS), EReturnTransferFailed); @@ -116,27 +116,27 @@ module DeFi::SharedEscrowTests { } fun cancel(scenario: &mut Scenario, initiator: &address) { - TestScenario::next_tx(scenario, initiator); + test_scenario::next_tx(scenario, initiator); { - let escrow_wrapper = TestScenario::take_shared>(scenario); - let escrow = TestScenario::borrow_mut(&mut escrow_wrapper); - let ctx = TestScenario::ctx(scenario); - SharedEscrow::cancel(escrow, ctx); - TestScenario::return_shared(scenario, escrow_wrapper); + let escrow_wrapper = test_scenario::take_shared>(scenario); + let escrow = test_scenario::borrow_mut(&mut escrow_wrapper); + let ctx = test_scenario::ctx(scenario); + shared_escrow::cancel(escrow, ctx); + test_scenario::return_shared(scenario, escrow_wrapper); }; } fun exchange(scenario: &mut Scenario, bob: &address, item_b_verioned_id: VersionedID) { - TestScenario::next_tx(scenario, bob); + test_scenario::next_tx(scenario, bob); { - let escrow_wrapper = TestScenario::take_shared>(scenario); - let escrow = TestScenario::borrow_mut(&mut escrow_wrapper); + let escrow_wrapper = test_scenario::take_shared>(scenario); + let escrow = test_scenario::borrow_mut(&mut escrow_wrapper); let item_b = ItemB { id: item_b_verioned_id }; - let ctx = TestScenario::ctx(scenario); - SharedEscrow::exchange(item_b, escrow, ctx); - TestScenario::return_shared(scenario, escrow_wrapper); + let ctx = test_scenario::ctx(scenario); + shared_escrow::exchange(item_b, escrow, ctx); + test_scenario::return_shared(scenario, escrow_wrapper); }; } @@ -144,24 +144,24 @@ module DeFi::SharedEscrowTests { alice: address, bob: address, ): (Scenario, VersionedID) { - let new_scenario = TestScenario::begin(&alice); + let new_scenario = test_scenario::begin(&alice); let scenario = &mut new_scenario; - let ctx = TestScenario::ctx(scenario); - let item_a_versioned_id = TxContext::new_id(ctx); + let ctx = test_scenario::ctx(scenario); + let item_a_versioned_id = tx_context::new_id(ctx); - TestScenario::next_tx(scenario, &bob); - let ctx = TestScenario::ctx(scenario); - let item_b_versioned_id = TxContext::new_id(ctx); - let item_b_id = *ID::inner(&item_b_versioned_id); + test_scenario::next_tx(scenario, &bob); + let ctx = test_scenario::ctx(scenario); + let item_b_versioned_id = tx_context::new_id(ctx); + let item_b_id = *id::inner(&item_b_versioned_id); // Alice creates the escrow - TestScenario::next_tx(scenario, &alice); + test_scenario::next_tx(scenario, &alice); { - let ctx = TestScenario::ctx(scenario); + let ctx = test_scenario::ctx(scenario); let escrowed = ItemA { id: item_a_versioned_id }; - SharedEscrow::create( + shared_escrow::create( bob, item_b_id, escrowed, @@ -172,7 +172,7 @@ module DeFi::SharedEscrowTests { } fun owns_object(scenario: &mut Scenario, owner: &address): bool{ - TestScenario::next_tx(scenario, owner); - TestScenario::can_take_owned(scenario) + test_scenario::next_tx(scenario, owner); + test_scenario::can_take_owned(scenario) } } diff --git a/sui_programmability/examples/fungible_tokens/Move.toml b/sui_programmability/examples/fungible_tokens/Move.toml index 8361976dbf784..eb44c97010842 100644 --- a/sui_programmability/examples/fungible_tokens/Move.toml +++ b/sui_programmability/examples/fungible_tokens/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { local = "../../../crates/sui-framework" } [addresses] -FungibleTokens = "0x0" +fungible_tokens = "0x0" diff --git a/sui_programmability/examples/fungible_tokens/sources/BASKET.move b/sui_programmability/examples/fungible_tokens/sources/basket.move similarity index 66% rename from sui_programmability/examples/fungible_tokens/sources/BASKET.move rename to sui_programmability/examples/fungible_tokens/sources/basket.move index ced3b3ab4c309..973e7246f37a2 100644 --- a/sui_programmability/examples/fungible_tokens/sources/BASKET.move +++ b/sui_programmability/examples/fungible_tokens/sources/basket.move @@ -6,14 +6,14 @@ /// but this approach would work for a basket with arbitrary assets/ratios. /// E.g., [SDR](https://www.imf.org/en/About/Factsheets/Sheets/2016/08/01/14/51/Special-Drawing-Right-SDR) /// could be implemented this way. -module FungibleTokens::BASKET { - use FungibleTokens::MANAGED::MANAGED; - use Sui::Coin::{Self, Coin, TreasuryCap}; - use Sui::Balance::{Self, Balance}; - use Sui::ID::VersionedID; - use Sui::SUI::SUI; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module fungible_tokens::basket { + use fungible_tokens::managed::MANAGED; + use sui::coin::{Self, Coin, TreasuryCap}; + use sui::balance::{Self, Balance}; + use sui::id::VersionedID; + use sui::sui::SUI; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Name of the coin. By convention, this type has the same name as its parent module /// and has no fields. The full type of the coin defined by this module will be `COIN`. @@ -35,12 +35,12 @@ module FungibleTokens::BASKET { fun init(ctx: &mut TxContext) { // Get a treasury cap for the coin put it in the reserve - let treasury_cap = Coin::create_currency(BASKET{}, ctx); - Transfer::share_object(Reserve { - id: TxContext::new_id(ctx), + let treasury_cap = coin::create_currency(BASKET{}, ctx); + transfer::share_object(Reserve { + id: tx_context::new_id(ctx), treasury_cap, - sui: Balance::zero(), - managed: Balance::zero(), + sui: balance::zero(), + managed: balance::zero(), }) } @@ -50,22 +50,22 @@ module FungibleTokens::BASKET { public fun mint( reserve: &mut Reserve, sui: Coin, managed: Coin, ctx: &mut TxContext ): Coin { - let num_sui = Coin::value(&sui); - assert!(num_sui == Coin::value(&managed), EBadDepositRatio); + let num_sui = coin::value(&sui); + assert!(num_sui == coin::value(&managed), EBadDepositRatio); - Coin::deposit(&mut reserve.sui, sui); - Coin::deposit(&mut reserve.managed, managed); - Coin::mint(num_sui, &mut reserve.treasury_cap, ctx) + coin::deposit(&mut reserve.sui, sui); + coin::deposit(&mut reserve.managed, managed); + coin::mint(num_sui, &mut reserve.treasury_cap, ctx) } /// Burn BASKET coins and return the underlying reserve assets public fun burn( reserve: &mut Reserve, basket: Coin, ctx: &mut TxContext ): (Coin, Coin) { - let num_basket = Coin::value(&basket); - Coin::burn(basket, &mut reserve.treasury_cap); - let sui = Coin::withdraw(&mut reserve.sui, num_basket, ctx); - let managed = Coin::withdraw(&mut reserve.managed, num_basket, ctx); + let num_basket = coin::value(&basket); + coin::burn(basket, &mut reserve.treasury_cap); + let sui = coin::withdraw(&mut reserve.sui, num_basket, ctx); + let managed = coin::withdraw(&mut reserve.managed, num_basket, ctx); (sui, managed) } @@ -73,17 +73,17 @@ module FungibleTokens::BASKET { /// Return the number of `MANAGED` coins in circulation public fun total_supply(reserve: &Reserve): u64 { - Coin::total_supply(&reserve.treasury_cap) + coin::total_supply(&reserve.treasury_cap) } /// Return the number of SUI in the reserve public fun sui_supply(reserve: &Reserve): u64 { - Balance::value(&reserve.sui) + balance::value(&reserve.sui) } /// Return the number of MANAGED in the reserve public fun managed_supply(reserve: &Reserve): u64 { - Balance::value(&reserve.managed) + balance::value(&reserve.managed) } #[test_only] diff --git a/sui_programmability/examples/fungible_tokens/sources/MANAGED.move b/sui_programmability/examples/fungible_tokens/sources/managed.move similarity index 76% rename from sui_programmability/examples/fungible_tokens/sources/MANAGED.move rename to sui_programmability/examples/fungible_tokens/sources/managed.move index bdd395d49f212..82b685dc1de12 100644 --- a/sui_programmability/examples/fungible_tokens/sources/MANAGED.move +++ b/sui_programmability/examples/fungible_tokens/sources/managed.move @@ -4,10 +4,10 @@ /// Example coin with a trusted manager responsible for minting/burning (e.g., a stablecoin) /// By convention, modules defining custom coin types use upper case names, in contrast to /// ordinary modules, which use camel case. -module FungibleTokens::MANAGED { - use Sui::Coin::{Self, Coin, TreasuryCap}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module fungible_tokens::managed { + use sui::coin::{Self, Coin, TreasuryCap}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Name of the coin. By convention, this type has the same name as its parent module /// and has no fields. The full type of the coin defined by this module will be `COIN`. @@ -18,23 +18,23 @@ module FungibleTokens::MANAGED { /// registered once. fun init(ctx: &mut TxContext) { // Get a treasury cap for the coin and give it to the transaction sender - let treasury_cap = Coin::create_currency(MANAGED{}, ctx); - Transfer::transfer(treasury_cap, TxContext::sender(ctx)) + let treasury_cap = coin::create_currency(MANAGED{}, ctx); + transfer::transfer(treasury_cap, tx_context::sender(ctx)) } /// Manager can mint new coins public fun mint(treasury_cap: &mut TreasuryCap, amount: u64, ctx: &mut TxContext): Coin { - Coin::mint(amount, treasury_cap, ctx) + coin::mint(amount, treasury_cap, ctx) } /// Manager can burn coins public entry fun burn(treasury_cap: &mut TreasuryCap, coin: Coin) { - Coin::burn(coin, treasury_cap) + coin::burn(coin, treasury_cap) } /// Manager can transfer the treasury capability to a new manager public entry fun transfer_cap(treasury_cap: TreasuryCap, recipient: address) { - Coin::transfer_cap(treasury_cap, recipient); + coin::transfer_cap(treasury_cap, recipient); } #[test_only] diff --git a/sui_programmability/examples/fungible_tokens/tests/BASKETTests.move b/sui_programmability/examples/fungible_tokens/tests/BASKETTests.move deleted file mode 100644 index 1eece1290f6bd..0000000000000 --- a/sui_programmability/examples/fungible_tokens/tests/BASKETTests.move +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module FungibleTokens::BASKETTests { - use FungibleTokens::BASKET::{Self, Reserve}; - use FungibleTokens::MANAGED::MANAGED; - use Sui::Coin; - use Sui::SUI::SUI; - use Sui::TestScenario; - - #[test] - public fun test_mint_burn() { - let user = @0xA; - - let scenario = &mut TestScenario::begin(&user); - { - let ctx = TestScenario::ctx(scenario); - BASKET::init_for_testing(ctx); - }; - TestScenario::next_tx(scenario, &user); - { - let reserve_wrapper = TestScenario::take_shared(scenario); - let reserve = TestScenario::borrow_mut(&mut reserve_wrapper); - let ctx = TestScenario::ctx(scenario); - assert!(BASKET::total_supply(reserve) == 0, 0); - - let num_coins = 10; - let sui = Coin::mint_for_testing(num_coins, ctx); - let managed = Coin::mint_for_testing(num_coins, ctx); - let basket = BASKET::mint(reserve, sui, managed, ctx); - assert!(Coin::value(&basket) == num_coins, 1); - assert!(BASKET::total_supply(reserve) == num_coins, 2); - - let (sui, managed) = BASKET::burn(reserve, basket, ctx); - assert!(Coin::value(&sui) == num_coins, 3); - assert!(Coin::value(&managed) == num_coins, 4); - - Coin::keep(sui, ctx); - Coin::keep(managed, ctx); - TestScenario::return_shared(scenario, reserve_wrapper); - } - } - -} diff --git a/sui_programmability/examples/fungible_tokens/tests/basket_tests.move b/sui_programmability/examples/fungible_tokens/tests/basket_tests.move new file mode 100644 index 0000000000000..1d12d9052a0f9 --- /dev/null +++ b/sui_programmability/examples/fungible_tokens/tests/basket_tests.move @@ -0,0 +1,45 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module fungible_tokens::basket_tests { + use fungible_tokens::basket::{Self, Reserve}; + use fungible_tokens::managed::MANAGED; + use sui::coin; + use sui::sui::SUI; + use sui::test_scenario; + + #[test] + public fun test_mint_burn() { + let user = @0xA; + + let scenario = &mut test_scenario::begin(&user); + { + let ctx = test_scenario::ctx(scenario); + basket::init_for_testing(ctx); + }; + test_scenario::next_tx(scenario, &user); + { + let reserve_wrapper = test_scenario::take_shared(scenario); + let reserve = test_scenario::borrow_mut(&mut reserve_wrapper); + let ctx = test_scenario::ctx(scenario); + assert!(basket::total_supply(reserve) == 0, 0); + + let num_coins = 10; + let sui = coin::mint_for_testing(num_coins, ctx); + let managed = coin::mint_for_testing(num_coins, ctx); + let basket = basket::mint(reserve, sui, managed, ctx); + assert!(coin::value(&basket) == num_coins, 1); + assert!(basket::total_supply(reserve) == num_coins, 2); + + let (sui, managed) = basket::burn(reserve, basket, ctx); + assert!(coin::value(&sui) == num_coins, 3); + assert!(coin::value(&managed) == num_coins, 4); + + coin::keep(sui, ctx); + coin::keep(managed, ctx); + test_scenario::return_shared(scenario, reserve_wrapper); + } + } + +} diff --git a/sui_programmability/examples/games/Move.toml b/sui_programmability/examples/games/Move.toml index 077789659d356..2abfdf9c96be1 100644 --- a/sui_programmability/examples/games/Move.toml +++ b/sui_programmability/examples/games/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { local = "../../../crates/sui-framework" } [addresses] -Games = "0x0" +games = "0x0" diff --git a/sui_programmability/examples/games/sources/Hero.move b/sui_programmability/examples/games/sources/hero.move similarity index 78% rename from sui_programmability/examples/games/sources/Hero.move rename to sui_programmability/examples/games/sources/hero.move index b8b3558f40f51..7683f85a3195b 100644 --- a/sui_programmability/examples/games/sources/Hero.move +++ b/sui_programmability/examples/games/sources/hero.move @@ -3,14 +3,14 @@ /// Example of a game character with basic attributes, inventory, and /// associated logic. -module Games::Hero { - use Sui::Coin::{Self, Coin}; - use Sui::Event; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Math; - use Sui::SUI::SUI; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module games::hero { + use sui::coin::{Self, Coin}; + use sui::event; + use sui::id::{Self, ID, VersionedID}; + use sui::math; + use sui::sui::SUI; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; use std::option::{Self, Option}; /// Our hero! @@ -126,19 +126,19 @@ module Games::Hero { /// Create a new game. Separated to bypass public entry vs init requirements. fun create(ctx: &mut TxContext) { - let sender = TxContext::sender(ctx); - let id = TxContext::new_id(ctx); - let game_id = *ID::inner(&id); + let sender = tx_context::sender(ctx); + let id = tx_context::new_id(ctx); + let game_id = *id::inner(&id); - Transfer::freeze_object(GameInfo { + transfer::freeze_object(GameInfo { id, admin: sender, }); - Transfer::transfer( + transfer::transfer( GameAdmin { game_id, - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), boars_created: 0, potions_created: 0, }, @@ -178,13 +178,13 @@ module Games::Hero { level_up_sword(option::borrow_mut(&mut hero.sword), 1) }; // let the world know about the hero's triumph by emitting an event! - Event::emit(BoarSlainEvent { - slayer_address: TxContext::sender(ctx), - hero: *ID::inner(&hero.id), - boar: *ID::inner(&boar_id), + event::emit(BoarSlainEvent { + slayer_address: tx_context::sender(ctx), + hero: *id::inner(&hero.id), + boar: *id::inner(&boar_id), game_id: id(game) }); - ID::delete(boar_id); + id::delete(boar_id); } /// Strength of the hero when attacking @@ -219,10 +219,10 @@ module Games::Hero { public fun heal(hero: &mut Hero, potion: Potion) { assert!(hero.game_id == potion.game_id, 403); let Potion { id, potency, game_id: _ } = potion; - ID::delete(id); + id::delete(id); let new_hp = hero.hp + potency; // cap hero's HP at MAX_HP to avoid int overflows - hero.hp = Math::min(new_hp, MAX_HP) + hero.hp = math::min(new_hp, MAX_HP) } /// Add `new_sword` to the hero's inventory and return the old sword @@ -248,18 +248,18 @@ module Games::Hero { payment: Coin, ctx: &mut TxContext ): Sword { - let value = Coin::value(&payment); + let value = coin::value(&payment); // ensure the user pays enough for the sword assert!(value >= MIN_SWORD_COST, EINSUFFICIENT_FUNDS); // pay the admin for this sword - Transfer::transfer(payment, game.admin); + transfer::transfer(payment, game.admin); // magic of the sword is proportional to the amount you paid, up to // a max. one can only imbue a sword with so much magic let magic = (value - MIN_SWORD_COST) / MIN_SWORD_COST; Sword { - id: TxContext::new_id(ctx), - magic: Math::min(magic, MAX_MAGIC), + id: tx_context::new_id(ctx), + magic: math::min(magic, MAX_MAGIC), strength: 1, game_id: id(game) } @@ -270,7 +270,7 @@ module Games::Hero { ) { let sword = create_sword(game, payment, ctx); let hero = create_hero(game, sword, ctx); - Transfer::transfer(hero, TxContext::sender(ctx)) + transfer::transfer(hero, tx_context::sender(ctx)) } /// Anyone can create a hero if they have a sword. All heroes start with the @@ -280,7 +280,7 @@ module Games::Hero { ): Hero { check_id(game, sword.game_id); Hero { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), hp: 100, experience: 0, sword: option::some(sword), @@ -299,8 +299,8 @@ module Games::Hero { check_id(game, admin.game_id); admin.potions_created = admin.potions_created + 1; // send potion to the designated player - Transfer::transfer( - Potion { id: TxContext::new_id(ctx), potency, game_id: id(game) }, + transfer::transfer( + Potion { id: tx_context::new_id(ctx), potency, game_id: id(game) }, player ) } @@ -317,8 +317,8 @@ module Games::Hero { check_id(game, admin.game_id); admin.boars_created = admin.boars_created + 1; // send boars to the designated player - Transfer::transfer( - Boar { id: TxContext::new_id(ctx), hp, strength, game_id: id(game) }, + transfer::transfer( + Boar { id: tx_context::new_id(ctx), hp, strength, game_id: id(game) }, player ) } @@ -330,7 +330,7 @@ module Games::Hero { } public fun id(game_info: &GameInfo): ID { - *ID::inner(&game_info.id) + *id::inner(&game_info.id) } // --- Testing functions --- @@ -341,61 +341,61 @@ module Games::Hero { #[test_only] public fun delete_hero_for_testing(hero: Hero) { let Hero { id, hp: _, experience: _, sword, game_id: _ } = hero; - ID::delete(id); + id::delete(id); let sword = option::destroy_some(sword); let Sword { id, magic: _, strength: _, game_id: _ } = sword; - ID::delete(id) + id::delete(id) } #[test_only] public fun delete_game_admin_for_testing(admin: GameAdmin) { let GameAdmin { id, boars_created: _, potions_created: _, game_id: _ } = admin; - ID::delete(id); + id::delete(id); } #[test] fun slay_boar_test() { - use Sui::Coin; - use Sui::TestScenario; + use sui::coin; + use sui::test_scenario; let admin = @0xAD014; let player = @0x0; - let scenario = &mut TestScenario::begin(&admin); + let scenario = &mut test_scenario::begin(&admin); // Run the module initializers - TestScenario::next_tx(scenario, &admin); + test_scenario::next_tx(scenario, &admin); { - init(TestScenario::ctx(scenario)); + init(test_scenario::ctx(scenario)); }; // Player purchases a hero with the coins - TestScenario::next_tx(scenario, &player); + test_scenario::next_tx(scenario, &player); { - let game = TestScenario::take_immutable(scenario); - let game_ref = TestScenario::borrow(&game); - let coin = Coin::mint_for_testing(500, TestScenario::ctx(scenario)); - acquire_hero(game_ref, coin, TestScenario::ctx(scenario)); - TestScenario::return_immutable(scenario, game); + let game = test_scenario::take_immutable(scenario); + let game_ref = test_scenario::borrow(&game); + let coin = coin::mint_for_testing(500, test_scenario::ctx(scenario)); + acquire_hero(game_ref, coin, test_scenario::ctx(scenario)); + test_scenario::return_immutable(scenario, game); }; // Admin sends a boar to the Player - TestScenario::next_tx(scenario, &admin); + test_scenario::next_tx(scenario, &admin); { - let game = TestScenario::take_immutable(scenario); - let game_ref = TestScenario::borrow(&game); - let admin_cap = TestScenario::take_owned(scenario); - send_boar(game_ref, &mut admin_cap, 10, 10, player, TestScenario::ctx(scenario)); - TestScenario::return_owned(scenario, admin_cap); - TestScenario::return_immutable(scenario, game); + let game = test_scenario::take_immutable(scenario); + let game_ref = test_scenario::borrow(&game); + let admin_cap = test_scenario::take_owned(scenario); + send_boar(game_ref, &mut admin_cap, 10, 10, player, test_scenario::ctx(scenario)); + test_scenario::return_owned(scenario, admin_cap); + test_scenario::return_immutable(scenario, game); }; // Player slays the boar! - TestScenario::next_tx(scenario, &player); + test_scenario::next_tx(scenario, &player); { - let game = TestScenario::take_immutable(scenario); - let game_ref = TestScenario::borrow(&game); - let hero = TestScenario::take_owned(scenario); - let boar = TestScenario::take_owned(scenario); - slay(game_ref, &mut hero, boar, TestScenario::ctx(scenario)); - TestScenario::return_owned(scenario, hero); - TestScenario::return_immutable(scenario, game); + let game = test_scenario::take_immutable(scenario); + let game_ref = test_scenario::borrow(&game); + let hero = test_scenario::take_owned(scenario); + let boar = test_scenario::take_owned(scenario); + slay(game_ref, &mut hero, boar, test_scenario::ctx(scenario)); + test_scenario::return_owned(scenario, hero); + test_scenario::return_immutable(scenario, game); }; } } diff --git a/sui_programmability/examples/games/sources/RockPaperScissors.move b/sui_programmability/examples/games/sources/rock_paper_scissors.move similarity index 90% rename from sui_programmability/examples/games/sources/RockPaperScissors.move rename to sui_programmability/examples/games/sources/rock_paper_scissors.move index cbb00d4cb91f0..da3fddf152e45 100644 --- a/sui_programmability/examples/games/sources/RockPaperScissors.move +++ b/sui_programmability/examples/games/sources/rock_paper_scissors.move @@ -25,10 +25,10 @@ // - If player never revealed the secret // - If game owner never took or revealed the results (incentives?) -module Games::RockPaperScissors { - use Sui::ID::{Self, VersionedID}; - use Sui::TxContext::{Self, TxContext}; - use Sui::Transfer::{Self}; +module games::rock_paper_scissors { + use sui::id::{Self, VersionedID}; + use sui::tx_context::{Self, TxContext}; + use sui::transfer::{Self}; use std::vector; use std::hash; @@ -58,7 +58,7 @@ module Games::RockPaperScissors { id: VersionedID } - /// The main resource of the RockPaperScissors module. Contains all the + /// The main resource of the rock_paper_scissors module. Contains all the /// information about the game state submitted by both players. By default /// contains empty values and fills as the game progresses. /// Being destroyed in the end, once [`select_winner`] is called and the game @@ -118,16 +118,16 @@ module Games::RockPaperScissors { /// /// todo: extend with generics + T as prize public entry fun new_game(player_one: address, player_two: address, ctx: &mut TxContext) { - Transfer::transfer(Game { - id: TxContext::new_id(ctx), - prize: ThePrize { id: TxContext::new_id(ctx) }, + transfer::transfer(Game { + id: tx_context::new_id(ctx), + prize: ThePrize { id: tx_context::new_id(ctx) }, player_one, player_two, hash_one: vector[], hash_two: vector[], gesture_one: NONE, gesture_two: NONE, - }, TxContext::sender(ctx)); + }, tx_context::sender(ctx)); } /// Transfer [`PlayerTurn`] to the game owner. Nobody at this point knows what move @@ -135,10 +135,10 @@ module Games::RockPaperScissors { /// /// Currently there's no check on whether the game exists. public entry fun player_turn(at: address, hash: vector, ctx: &mut TxContext) { - Transfer::transfer(PlayerTurn { + transfer::transfer(PlayerTurn { hash, - id: TxContext::new_id(ctx), - player: TxContext::sender(ctx), + id: tx_context::new_id(ctx), + player: tx_context::sender(ctx), }, at); } @@ -159,16 +159,16 @@ module Games::RockPaperScissors { abort 0 // unreachable!() }; - ID::delete(id); + id::delete(id); } /// Submit a [`Secret`] to the game owner who then matches the hash and saves the /// gesture in the [`Game`] object. public entry fun reveal(at: address, salt: vector, ctx: &mut TxContext) { - Transfer::transfer(Secret { - id: TxContext::new_id(ctx), + transfer::transfer(Secret { + id: tx_context::new_id(ctx), salt, - player: TxContext::sender(ctx), + player: tx_context::sender(ctx), }, at); } @@ -186,7 +186,7 @@ module Games::RockPaperScissors { game.gesture_two = find_gesture(salt, &game.hash_two); }; - ID::delete(id); + id::delete(id); } /// The final accord to the game logic. After both secrets have been revealed, @@ -208,16 +208,16 @@ module Games::RockPaperScissors { let p1_wins = play(gesture_one, gesture_two); let p2_wins = play(gesture_two, gesture_one); - ID::delete(id); + id::delete(id); // If one of the players wins, he takes the prize. // If there's a tie, the game owner gets the prize. if (p1_wins) { - Transfer::transfer(prize, player_one) + transfer::transfer(prize, player_one) } else if (p2_wins) { - Transfer::transfer(prize, player_two) + transfer::transfer(prize, player_two) } else { - Transfer::transfer(prize, TxContext::sender(ctx)) + transfer::transfer(prize, tx_context::sender(ctx)) }; } diff --git a/sui_programmability/examples/games/sources/SeaHero.move b/sui_programmability/examples/games/sources/sea_hero.move similarity index 81% rename from sui_programmability/examples/games/sources/SeaHero.move rename to sui_programmability/examples/games/sources/sea_hero.move index a609683e9fab1..6ece44211fc6d 100644 --- a/sui_programmability/examples/games/sources/SeaHero.move +++ b/sui_programmability/examples/games/sources/sea_hero.move @@ -8,14 +8,14 @@ /// earns RUM tokens for hero's owner. /// Note that this mod does not require special permissions from `Hero` module; /// anyone is free to create a mod like this. -module Games::SeaHero { - use Games::Hero::{Self, Hero}; +module games::sea_hero { + use games::hero::{Self, Hero}; - use Sui::Balance::{Self, Balance}; - use Sui::ID::{Self, VersionedID}; - use Sui::Coin::{Self, TreasuryCap}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::balance::{Self, Balance}; + use sui::id::{Self, VersionedID}; + use sui::coin::{Self, TreasuryCap}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Admin capability granting permission to mint RUM tokens and /// create monsters @@ -58,15 +58,15 @@ module Games::SeaHero { /// Get a treasury cap for the coin and give it to the admin // TODO: this leverages Move module initializers fun init(ctx: &mut TxContext) { - Transfer::transfer( + transfer::transfer( SeaHeroAdmin { - id: TxContext::new_id(ctx), - treasury_cap: Coin::create_currency(RUM{}, ctx), + id: tx_context::new_id(ctx), + treasury_cap: coin::create_currency(RUM{}, ctx), monsters_created: 0, token_supply_max: 1000000, monster_max: 10, }, - TxContext::sender(ctx) + tx_context::sender(ctx) ) } @@ -77,11 +77,11 @@ module Games::SeaHero { /// Aborts if the hero is not strong enough to slay the monster public fun slay(hero: &Hero, monster: SeaMonster): Balance { let SeaMonster { id, reward } = monster; - ID::delete(id); + id::delete(id); // Hero needs strength greater than the reward value to defeat the // monster assert!( - Hero::hero_strength(hero) >= Balance::value(&reward), + hero::hero_strength(hero) >= balance::value(&reward), EHERO_NOT_STRONG_ENOUGH ); @@ -98,7 +98,7 @@ module Games::SeaHero { recipient: address, ctx: &mut TxContext ) { - let current_coin_supply = Coin::total_supply(&admin.treasury_cap); + let current_coin_supply = coin::total_supply(&admin.treasury_cap); let token_supply_max = admin.token_supply_max; // TODO: create error codes // ensure token supply cap is respected @@ -108,22 +108,22 @@ module Games::SeaHero { assert!(admin.monster_max - 1 >= admin.monsters_created, 2); let monster = SeaMonster { - id: TxContext::new_id(ctx), - reward: Coin::mint_balance(reward_amount, &mut admin.treasury_cap) + id: tx_context::new_id(ctx), + reward: coin::mint_balance(reward_amount, &mut admin.treasury_cap) }; admin.monsters_created = admin.monsters_created + 1; - Transfer::transfer(monster, recipient); + transfer::transfer(monster, recipient); } /// Send `monster` to `recipient` public fun transfer_monster( monster: SeaMonster, recipient: address ) { - Transfer::transfer(monster, recipient) + transfer::transfer(monster, recipient) } /// Reward a hero will reap from slaying this monster public fun monster_reward(monster: &SeaMonster): u64 { - Balance::value(&monster.reward) + balance::value(&monster.reward) } } diff --git a/sui_programmability/examples/games/sources/SeaHeroHelper.move b/sui_programmability/examples/games/sources/sea_hero_helper.move similarity index 77% rename from sui_programmability/examples/games/sources/SeaHeroHelper.move rename to sui_programmability/examples/games/sources/sea_hero_helper.move index 64dabc7311ddb..3076ea4b001be 100644 --- a/sui_programmability/examples/games/sources/SeaHeroHelper.move +++ b/sui_programmability/examples/games/sources/sea_hero_helper.move @@ -7,13 +7,13 @@ /// the monster for them in exchange for some of the reward. /// Anyone can create a mod like this--the permission of the `SeaHero` game /// is not required. -module Games::SeaHeroHelper { - use Games::SeaHero::{Self, SeaMonster, RUM}; - use Games::Hero::Hero; - use Sui::Coin::{Self, Coin}; - use Sui::ID::{Self, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module games::sea_hero_helper { + use games::sea_hero::{Self, SeaMonster, RUM}; + use games::hero::Hero; + use sui::coin::{Self, Coin}; + use sui::id::{Self, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Created by `monster_owner`, a player with a monster that's too strong /// for them to slay + transferred to a player who can slay the monster. @@ -45,14 +45,14 @@ module Games::SeaHeroHelper { // make sure the advertised reward is not too large + that the owner // gets a nonzero reward assert!( - SeaHero::monster_reward(&monster) > helper_reward, + sea_hero::monster_reward(&monster) > helper_reward, EINVALID_HELPER_REWARD ); - Transfer::transfer( + transfer::transfer( HelpMeSlayThisMonster { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), monster, - monster_owner: TxContext::sender(ctx), + monster_owner: tx_context::sender(ctx), helper_reward }, helper @@ -70,10 +70,10 @@ module Games::SeaHeroHelper { monster_owner, helper_reward } = wrapper; - ID::delete(id); - let owner_reward = SeaHero::slay(hero, monster); - let helper_reward = Coin::withdraw(&mut owner_reward, helper_reward, ctx); - Transfer::transfer(Coin::from_balance(owner_reward, ctx), monster_owner); + id::delete(id); + let owner_reward = sea_hero::slay(hero, monster); + let helper_reward = coin::withdraw(&mut owner_reward, helper_reward, ctx); + transfer::transfer(coin::from_balance(owner_reward, ctx), monster_owner); helper_reward } @@ -86,13 +86,13 @@ module Games::SeaHeroHelper { monster_owner, helper_reward: _ } = wrapper; - ID::delete(id); - SeaHero::transfer_monster(monster, monster_owner) + id::delete(id); + sea_hero::transfer_monster(monster, monster_owner) } /// Return the number of coins that `wrapper.owner` will earn if the /// the helper slays the monster in `wrapper. public fun owner_reward(wrapper: &HelpMeSlayThisMonster): u64 { - SeaHero::monster_reward(&wrapper.monster) - wrapper.helper_reward + sea_hero::monster_reward(&wrapper.monster) - wrapper.helper_reward } } diff --git a/sui_programmability/examples/games/sources/SharedTicTacToe.move b/sui_programmability/examples/games/sources/shared_tic_tac_toe.move similarity index 90% rename from sui_programmability/examples/games/sources/SharedTicTacToe.move rename to sui_programmability/examples/games/sources/shared_tic_tac_toe.move index 1e6289f330e12..57fbb48912703 100644 --- a/sui_programmability/examples/games/sources/SharedTicTacToe.move +++ b/sui_programmability/examples/games/sources/shared_tic_tac_toe.move @@ -14,13 +14,13 @@ // to take turns to place the marker, there won't be a significant overhead in practice. // As we can see, by using shared object, the implementation is much // simpler than the other implementation. -module Games::SharedTicTacToe { +module games::shared_tic_tac_toe { use std::vector; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Event; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::id::{Self, ID, VersionedID}; + use sui::event; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; // Game status const IN_PROGRESS: u8 = 0; @@ -65,7 +65,7 @@ module Games::SharedTicTacToe { public entry fun create_game(x_address: address, o_address: address, ctx: &mut TxContext) { // TODO: Validate sender address, only GameAdmin can create games. - let id = TxContext::new_id(ctx); + let id = tx_context::new_id(ctx); let gameboard = vector[ vector[MARK_EMPTY, MARK_EMPTY, MARK_EMPTY], vector[MARK_EMPTY, MARK_EMPTY, MARK_EMPTY], @@ -80,14 +80,14 @@ module Games::SharedTicTacToe { o_address: o_address, }; // Make the game a shared object so that both players can mutate it. - Transfer::share_object(game); + transfer::share_object(game); } public entry fun place_mark(game: &mut TicTacToe, row: u8, col: u8, ctx: &mut TxContext) { assert!(row < 3 && col < 3, EInvalidLocation); assert!(game.game_status == IN_PROGRESS, EGameEnded); let addr = get_cur_turn_address(game); - assert!(addr == TxContext::sender(ctx), EInvalidTurn); + assert!(addr == tx_context::sender(ctx), EInvalidTurn); let cell = vector::borrow_mut(vector::borrow_mut(&mut game.gameboard, (row as u64)), (col as u64)); assert!(*cell == MARK_EMPTY, ECellOccupied); @@ -98,23 +98,23 @@ module Games::SharedTicTacToe { if (game.game_status != IN_PROGRESS) { // Notify the server that the game ended so that it can delete the game. - Event::emit(GameEndEvent { game_id: *ID::inner(&game.id) }); + event::emit(GameEndEvent { game_id: *id::inner(&game.id) }); if (game.game_status == X_WIN) { - Transfer::transfer( Trophy { id: TxContext::new_id(ctx) }, *&game.x_address); + transfer::transfer( Trophy { id: tx_context::new_id(ctx) }, *&game.x_address); } else if (game.game_status == O_WIN) { - Transfer::transfer( Trophy { id: TxContext::new_id(ctx) }, *&game.o_address); + transfer::transfer( Trophy { id: tx_context::new_id(ctx) }, *&game.o_address); } } } public entry fun delete_game(game: TicTacToe) { let TicTacToe { id, gameboard: _, cur_turn: _, game_status: _, x_address: _, o_address: _ } = game; - ID::delete(id); + id::delete(id); } public entry fun delete_trophy(trophy: Trophy) { let Trophy { id } = trophy; - ID::delete(id); + id::delete(id); } public fun get_status(game: &TicTacToe): u8 { diff --git a/sui_programmability/examples/games/sources/TicTacToe.move b/sui_programmability/examples/games/sources/tic_tac_toe.move similarity index 89% rename from sui_programmability/examples/games/sources/TicTacToe.move rename to sui_programmability/examples/games/sources/tic_tac_toe.move index fb721c22b1c2f..8751ef35c9e63 100644 --- a/sui_programmability/examples/games/sources/TicTacToe.move +++ b/sui_programmability/examples/games/sources/tic_tac_toe.move @@ -17,14 +17,14 @@ // TicTacToeV2 shows a simpler way to implement this using shared objects, // providing different trade-offs: using shared object is more expensive, // however it eliminates the need of a centralized service. -module Games::TicTacToe { +module games::tic_tac_toe { use std::option::{Self, Option}; use std::vector; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Event; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::id::{Self, ID, VersionedID}; + use sui::event; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; // Game status const IN_PROGRESS: u8 = 0; @@ -79,8 +79,8 @@ module Games::TicTacToe { public entry fun create_game(x_address: address, o_address: address, ctx: &mut TxContext) { // TODO: Validate sender address, only GameAdmin can create games. - let id = TxContext::new_id(ctx); - let game_id = *ID::inner(&id); + let id = tx_context::new_id(ctx); + let game_id = *id::inner(&id); let gameboard = vector[ vector[option::none(), option::none(), option::none()], vector[option::none(), option::none(), option::none()], @@ -94,19 +94,19 @@ module Games::TicTacToe { x_address: x_address, o_address: o_address, }; - Transfer::transfer(game, TxContext::sender(ctx)); + transfer::transfer(game, tx_context::sender(ctx)); let cap = MarkMintCap { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), game_id, remaining_supply: 5, }; - Transfer::transfer(cap, x_address); + transfer::transfer(cap, x_address); let cap = MarkMintCap { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), game_id, remaining_supply: 5, }; - Transfer::transfer(cap, o_address); + transfer::transfer(cap, o_address); } /// Generate a new mark intended for location (row, col). @@ -124,11 +124,11 @@ module Games::TicTacToe { let mark = mint_mark(cap, row, col, ctx); // Once an event is emitted, it should be observed by a game server. // The game server will then call `place_mark` to place this mark. - Event::emit(MarkSentEvent { + event::emit(MarkSentEvent { game_id: *&cap.game_id, - mark_id: *ID::inner(&mark.id), + mark_id: *id::inner(&mark.id), }); - Transfer::transfer(mark, game_address); + transfer::transfer(mark, game_address); } public entry fun place_mark(game: &mut TicTacToe, mark: Mark, ctx: &mut TxContext) { @@ -152,11 +152,11 @@ module Games::TicTacToe { if (game.game_status != IN_PROGRESS) { // Notify the server that the game ended so that it can delete the game. - Event::emit(GameEndEvent { game_id: *ID::inner(&game.id) }); + event::emit(GameEndEvent { game_id: *id::inner(&game.id) }); if (game.game_status == X_WIN) { - Transfer::transfer( Trophy { id: TxContext::new_id(ctx) }, *&game.x_address); + transfer::transfer( Trophy { id: tx_context::new_id(ctx) }, *&game.x_address); } else if (game.game_status == O_WIN) { - Transfer::transfer( Trophy { id: TxContext::new_id(ctx) }, *&game.o_address); + transfer::transfer( Trophy { id: tx_context::new_id(ctx) }, *&game.o_address); } } } @@ -176,17 +176,17 @@ module Games::TicTacToe { vector::destroy_empty(row); }; vector::destroy_empty(gameboard); - ID::delete(id); + id::delete(id); } public entry fun delete_trophy(trophy: Trophy) { let Trophy { id } = trophy; - ID::delete(id); + id::delete(id); } public entry fun delete_cap(cap: MarkMintCap) { let MarkMintCap { id, game_id: _, remaining_supply: _ } = cap; - ID::delete(id); + id::delete(id); } public fun get_status(game: &TicTacToe): u8 { @@ -199,8 +199,8 @@ module Games::TicTacToe { }; cap.remaining_supply = cap.remaining_supply - 1; Mark { - id: TxContext::new_id(ctx), - player: TxContext::sender(ctx), + id: tx_context::new_id(ctx), + player: tx_context::sender(ctx), row, col, } @@ -275,7 +275,7 @@ module Games::TicTacToe { fun delete_mark(mark: Mark) { let Mark { id, player: _, row: _, col: _ } = mark; - ID::delete(id); + id::delete(id); } public fun mark_player(mark: &Mark): &address { diff --git a/sui_programmability/examples/games/tests/RockPaperScissorsTests.move b/sui_programmability/examples/games/tests/rock_paper_scissors_tests.move similarity index 53% rename from sui_programmability/examples/games/tests/RockPaperScissorsTests.move rename to sui_programmability/examples/games/tests/rock_paper_scissors_tests.move index d2294f209d753..e358f73b85422 100644 --- a/sui_programmability/examples/games/tests/RockPaperScissorsTests.move +++ b/sui_programmability/examples/games/tests/rock_paper_scissors_tests.move @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module Games::RockPaperScissorsTests { - use Games::RockPaperScissors::{Self as Game, Game, PlayerTurn, Secret, ThePrize}; - use Sui::TestScenario::{Self}; +module games::rock_paper_scissors_tests { + use games::rock_paper_scissors::{Self as Game, Game, PlayerTurn, Secret, ThePrize}; + use sui::test_scenario::{Self}; use std::vector; use std::hash; @@ -15,24 +15,24 @@ module Games::RockPaperScissorsTests { let mr_lizard = @0xA55555; let mr_spock = @0x590C; - let scenario = &mut TestScenario::begin(&the_main_guy); + let scenario = &mut test_scenario::begin(&the_main_guy); // Let the game begin! - Game::new_game(mr_spock, mr_lizard, TestScenario::ctx(scenario)); + Game::new_game(mr_spock, mr_lizard, test_scenario::ctx(scenario)); // Mr Spock makes his move. He does it secretly and hashes the gesture with a salt // so that only he knows what it is. - TestScenario::next_tx(scenario, &mr_spock); + test_scenario::next_tx(scenario, &mr_spock); { let hash = hash(Game::rock(), b"my_phaser_never_failed_me!"); - Game::player_turn(the_main_guy, hash, TestScenario::ctx(scenario)); + Game::player_turn(the_main_guy, hash, test_scenario::ctx(scenario)); }; // Now it's time for The Main Guy to accept his turn. - TestScenario::next_tx(scenario, &the_main_guy); + test_scenario::next_tx(scenario, &the_main_guy); { - let game = TestScenario::take_owned(scenario); - let cap = TestScenario::take_owned(scenario); + let game = test_scenario::take_owned(scenario); + let cap = test_scenario::take_owned(scenario); assert!(Game::status(&game) == 0, 0); // STATUS_READY @@ -40,65 +40,65 @@ module Games::RockPaperScissorsTests { assert!(Game::status(&game) == 1, 0); // STATUS_HASH_SUBMISSION - TestScenario::return_owned(scenario, game); + test_scenario::return_owned(scenario, game); }; // Same for Mr Lizard. He uses his secret phrase to encode his turn. - TestScenario::next_tx(scenario, &mr_lizard); + test_scenario::next_tx(scenario, &mr_lizard); { let hash = hash(Game::scissors(), b"sssssss_you_are_dead!"); - Game::player_turn(the_main_guy, hash, TestScenario::ctx(scenario)); + Game::player_turn(the_main_guy, hash, test_scenario::ctx(scenario)); }; - TestScenario::next_tx(scenario, &the_main_guy); + test_scenario::next_tx(scenario, &the_main_guy); { - let game = TestScenario::take_owned(scenario); - let cap = TestScenario::take_owned(scenario); + let game = test_scenario::take_owned(scenario); + let cap = test_scenario::take_owned(scenario); Game::add_hash(&mut game, cap); assert!(Game::status(&game) == 2, 0); // STATUS_HASHES_SUBMITTED - TestScenario::return_owned(scenario, game); + test_scenario::return_owned(scenario, game); }; // Now that both sides made their moves, it's time for Mr Spock and Mr Lizard to // reveal their secrets. The Main Guy will then be able to determine the winner. Who's // gonna win The Prize? We'll see in a bit! - TestScenario::next_tx(scenario, &mr_spock); - Game::reveal(the_main_guy, b"my_phaser_never_failed_me!", TestScenario::ctx(scenario)); + test_scenario::next_tx(scenario, &mr_spock); + Game::reveal(the_main_guy, b"my_phaser_never_failed_me!", test_scenario::ctx(scenario)); - TestScenario::next_tx(scenario, &the_main_guy); + test_scenario::next_tx(scenario, &the_main_guy); { - let game = TestScenario::take_owned(scenario); - let secret = TestScenario::take_owned(scenario); + let game = test_scenario::take_owned(scenario); + let secret = test_scenario::take_owned(scenario); Game::match_secret(&mut game, secret); assert!(Game::status(&game) == 3, 0); // STATUS_REVEALING - TestScenario::return_owned(scenario, game); + test_scenario::return_owned(scenario, game); }; - TestScenario::next_tx(scenario, &mr_lizard); - Game::reveal(the_main_guy, b"sssssss_you_are_dead!", TestScenario::ctx(scenario)); + test_scenario::next_tx(scenario, &mr_lizard); + Game::reveal(the_main_guy, b"sssssss_you_are_dead!", test_scenario::ctx(scenario)); // The final step. The Main Guy matches and reveals the secret of the Mr Lizard and // calls the [`select_winner`] function to release The Prize. - TestScenario::next_tx(scenario, &the_main_guy); + test_scenario::next_tx(scenario, &the_main_guy); { - let game = TestScenario::take_owned(scenario); - let secret = TestScenario::take_owned(scenario); + let game = test_scenario::take_owned(scenario); + let secret = test_scenario::take_owned(scenario); Game::match_secret(&mut game, secret); assert!(Game::status(&game) == 4, 0); // STATUS_REVEALED - Game::select_winner(game, TestScenario::ctx(scenario)); + Game::select_winner(game, test_scenario::ctx(scenario)); }; - TestScenario::next_tx(scenario, &mr_spock); + test_scenario::next_tx(scenario, &mr_spock); // If it works, then MrSpock is in possession of the prize; - let prize = TestScenario::take_owned(scenario); + let prize = test_scenario::take_owned(scenario); // Don't forget to give it back! - TestScenario::return_owned(scenario, prize); + test_scenario::return_owned(scenario, prize); } // Copy of the hashing function from the main module. diff --git a/sui_programmability/examples/games/tests/SharedTicTacToeTests.move b/sui_programmability/examples/games/tests/shared_tic_tac_toe_tests.move similarity index 75% rename from sui_programmability/examples/games/tests/SharedTicTacToeTests.move rename to sui_programmability/examples/games/tests/shared_tic_tac_toe_tests.move index 5f717c2f0a3ca..24d05e5d302cc 100644 --- a/sui_programmability/examples/games/tests/SharedTicTacToeTests.move +++ b/sui_programmability/examples/games/tests/shared_tic_tac_toe_tests.move @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module Games::SharedTicTacToeTests { - use Sui::TestScenario::{Self, Scenario}; - use Games::SharedTicTacToe::{Self, TicTacToe, Trophy}; +module games::shared_tic_tac_toe_tests { + use sui::test_scenario::{Self, Scenario}; + use games::shared_tic_tac_toe::{Self, TicTacToe, Trophy}; const SEND_MARK_FAILED: u64 = 0; const UNEXPECTED_WINNER: u64 = 1; @@ -19,8 +19,8 @@ module Games::SharedTicTacToeTests { let player_o = @0x1; // Anyone can create a game, because the game object will be eventually shared. - let scenario = &mut TestScenario::begin(&player_x); - SharedTicTacToe::create_game(copy player_x, copy player_o, TestScenario::ctx(scenario)); + let scenario = &mut test_scenario::begin(&player_x); + shared_tic_tac_toe::create_game(copy player_x, copy player_o, test_scenario::ctx(scenario)); // Player1 places an X in (1, 1). place_mark(1, 1, &player_x, scenario); /* @@ -71,12 +71,12 @@ module Games::SharedTicTacToeTests { assert!(status == X_WIN, 2); // X has the Trophy - TestScenario::next_tx(scenario, &player_x); - assert!(TestScenario::can_take_owned(scenario), 1); + test_scenario::next_tx(scenario, &player_x); + assert!(test_scenario::can_take_owned(scenario), 1); - TestScenario::next_tx(scenario, &player_o); + test_scenario::next_tx(scenario, &player_o); // O has no Trophy - assert!(!TestScenario::can_take_owned(scenario), 2); + assert!(!test_scenario::can_take_owned(scenario), 2); } @@ -86,8 +86,8 @@ module Games::SharedTicTacToeTests { let player_o = @0x1; // Anyone can create a game, because the game object will be eventually shared. - let scenario = &mut TestScenario::begin(&player_x); - SharedTicTacToe::create_game(copy player_x, copy player_o, TestScenario::ctx(scenario)); + let scenario = &mut test_scenario::begin(&player_x); + shared_tic_tac_toe::create_game(copy player_x, copy player_o, test_scenario::ctx(scenario)); // Player1 places an X in (0, 1). let status = place_mark(0, 1, &player_x, scenario); assert!(status == IN_PROGRESS, 1); @@ -181,10 +181,10 @@ module Games::SharedTicTacToeTests { assert!(status == DRAW, 2); // No one has the trophy - TestScenario::next_tx(scenario, &player_x); - assert!(!TestScenario::can_take_owned(scenario), 1); - TestScenario::next_tx(scenario, &player_o); - assert!(!TestScenario::can_take_owned(scenario), 1); + test_scenario::next_tx(scenario, &player_x); + assert!(!test_scenario::can_take_owned(scenario), 1); + test_scenario::next_tx(scenario, &player_o); + assert!(!test_scenario::can_take_owned(scenario), 1); } @@ -196,14 +196,14 @@ module Games::SharedTicTacToeTests { ): u8 { // The gameboard is now a shared object. // Any player can place a mark on it directly. - TestScenario::next_tx(scenario, player); + test_scenario::next_tx(scenario, player); let status; { - let game_wrapper = TestScenario::take_shared(scenario); - let game = TestScenario::borrow_mut(&mut game_wrapper); - SharedTicTacToe::place_mark(game, row, col, TestScenario::ctx(scenario)); - status = SharedTicTacToe::get_status(game); - TestScenario::return_shared(scenario, game_wrapper); + let game_wrapper = test_scenario::take_shared(scenario); + let game = test_scenario::borrow_mut(&mut game_wrapper); + shared_tic_tac_toe::place_mark(game, row, col, test_scenario::ctx(scenario)); + status = shared_tic_tac_toe::get_status(game); + test_scenario::return_shared(scenario, game_wrapper); }; status } diff --git a/sui_programmability/examples/games/tests/TicTacToeTests.move b/sui_programmability/examples/games/tests/tic_tac_toe_tests.move similarity index 71% rename from sui_programmability/examples/games/tests/TicTacToeTests.move rename to sui_programmability/examples/games/tests/tic_tac_toe_tests.move index ad6e6eea24f1b..eb4f233bc845d 100644 --- a/sui_programmability/examples/games/tests/TicTacToeTests.move +++ b/sui_programmability/examples/games/tests/tic_tac_toe_tests.move @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module Games::TicTacToeTests { - use Sui::TestScenario::{Self, Scenario}; - use Games::TicTacToe::{Self, Mark, MarkMintCap, TicTacToe, Trophy}; +module games::tic_tac_toe_tests { + use sui::test_scenario::{Self, Scenario}; + use games::tic_tac_toe::{Self, Mark, MarkMintCap, TicTacToe, Trophy}; const SEND_MARK_FAILED: u64 = 0; const UNEXPECTED_WINNER: u64 = 1; @@ -13,16 +13,15 @@ module Games::TicTacToeTests { const X_WIN: u8 = 1; const DRAW: u8 = 3; - #[test] fun play_tictactoe() { let admin = @0x0; let player_x = @0x1; let player_o = @0x2; - let scenario = &mut TestScenario::begin(&admin); + let scenario = &mut test_scenario::begin(&admin); // Admin creates a game - TicTacToe::create_game(copy player_x, copy player_o, TestScenario::ctx(scenario)); + tic_tac_toe::create_game(copy player_x, copy player_o, test_scenario::ctx(scenario)); // Player1 places an X in (1, 1). place_mark(1, 1, &admin, &player_x, scenario); /* @@ -74,12 +73,12 @@ module Games::TicTacToeTests { assert!(status == X_WIN, 2); // X has the trophy - TestScenario::next_tx(scenario, &player_x); - assert!(TestScenario::can_take_owned(scenario), 1); + test_scenario::next_tx(scenario, &player_x); + assert!(test_scenario::can_take_owned(scenario), 1); - TestScenario::next_tx(scenario, &player_o); + test_scenario::next_tx(scenario, &player_o); // O has no Trophy - assert!(!TestScenario::can_take_owned(scenario), 1); + assert!(!test_scenario::can_take_owned(scenario), 1); } @@ -89,9 +88,9 @@ module Games::TicTacToeTests { let player_x = @0x1; let player_o = @0x2; - let scenario = &mut TestScenario::begin(&admin); + let scenario = &mut test_scenario::begin(&admin); - TicTacToe::create_game(copy player_x, copy player_o, TestScenario::ctx(scenario)); + tic_tac_toe::create_game(copy player_x, copy player_o, test_scenario::ctx(scenario)); // Player1 places an X in (0, 1). let status = place_mark(0, 1, &admin, &player_x, scenario); assert!(status == IN_PROGRESS, 1); @@ -185,10 +184,10 @@ module Games::TicTacToeTests { assert!(status == DRAW, 2); // No one has the trophy - TestScenario::next_tx(scenario, &player_x); - assert!(!TestScenario::can_take_owned(scenario), 1); - TestScenario::next_tx(scenario, &player_o); - assert!(!TestScenario::can_take_owned(scenario), 1); + test_scenario::next_tx(scenario, &player_x); + assert!(!test_scenario::can_take_owned(scenario), 1); + test_scenario::next_tx(scenario, &player_o); + assert!(!test_scenario::can_take_owned(scenario), 1); } fun place_mark( @@ -199,24 +198,24 @@ module Games::TicTacToeTests { scenario: &mut Scenario, ): u8 { // Step 1: player creates a mark and sends it to the game. - TestScenario::next_tx(scenario, player); + test_scenario::next_tx(scenario, player); { - let cap = TestScenario::take_owned(scenario); - TicTacToe::send_mark_to_game(&mut cap, *admin, row, col, TestScenario::ctx(scenario)); - TestScenario::return_owned(scenario, cap); + let cap = test_scenario::take_owned(scenario); + tic_tac_toe::send_mark_to_game(&mut cap, *admin, row, col, test_scenario::ctx(scenario)); + test_scenario::return_owned(scenario, cap); }; // Step 2: Admin places the received mark on the game board. - TestScenario::next_tx(scenario, admin); + test_scenario::next_tx(scenario, admin); let status; { - let game = TestScenario::take_owned(scenario); - let mark = TestScenario::take_owned(scenario); - assert!(TicTacToe::mark_player(&mark) == player, 0); - assert!(TicTacToe::mark_row(&mark) == row, 1); - assert!(TicTacToe::mark_col(&mark) == col, 2); - TicTacToe::place_mark(&mut game, mark, TestScenario::ctx(scenario)); - status = TicTacToe::get_status(&game); - TestScenario::return_owned(scenario, game); + let game = test_scenario::take_owned(scenario); + let mark = test_scenario::take_owned(scenario); + assert!(tic_tac_toe::mark_player(&mark) == player, 0); + assert!(tic_tac_toe::mark_row(&mark) == row, 1); + assert!(tic_tac_toe::mark_col(&mark) == col, 2); + tic_tac_toe::place_mark(&mut game, mark, test_scenario::ctx(scenario)); + status = tic_tac_toe::get_status(&game); + test_scenario::return_owned(scenario, game); }; // return the game status status diff --git a/sui_programmability/examples/move_tutorial/Move.toml b/sui_programmability/examples/move_tutorial/Move.toml index 7cb00ec2a8361..26321d44d3e48 100644 --- a/sui_programmability/examples/move_tutorial/Move.toml +++ b/sui_programmability/examples/move_tutorial/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { local = "../../../crates/sui-framework" } [addresses] -MyFirstPackage = "0x0" +my_first_package = "0x0" diff --git a/sui_programmability/examples/move_tutorial/sources/M1.move b/sui_programmability/examples/move_tutorial/sources/m1.move similarity index 66% rename from sui_programmability/examples/move_tutorial/sources/M1.move rename to sui_programmability/examples/move_tutorial/sources/m1.move index 1feb8b2c2de6b..847a73c02782e 100644 --- a/sui_programmability/examples/move_tutorial/sources/M1.move +++ b/sui_programmability/examples/move_tutorial/sources/m1.move @@ -1,9 +1,9 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module MyFirstPackage::M1 { - use Sui::ID::VersionedID; - use Sui::TxContext::TxContext; +module my_first_package::m1 { + use sui::id::VersionedID; + use sui::tx_context::TxContext; struct Sword has key, store { id: VersionedID, @@ -18,15 +18,15 @@ module MyFirstPackage::M1 { // module initializer to be executed when this module is published fun init(ctx: &mut TxContext) { - use Sui::Transfer; - use Sui::TxContext; + use sui::transfer; + use sui::tx_context; let admin = Forge { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), swords_created: 0, }; // transfer the forge object to the module/package publisher // (presumably the game admin) - Transfer::transfer(admin, TxContext::sender(ctx)); + transfer::transfer(admin, tx_context::sender(ctx)); } public fun swords_created(self: &Forge): u64 { @@ -42,53 +42,53 @@ module MyFirstPackage::M1 { } public entry fun sword_create(forge: &mut Forge, magic: u64, strength: u64, recipient: address, ctx: &mut TxContext) { - use Sui::Transfer; - use Sui::TxContext; + use sui::transfer; + use sui::tx_context; // create a sword let sword = Sword { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), magic: magic, strength: strength, }; // transfer the sword - Transfer::transfer(sword, recipient); + transfer::transfer(sword, recipient); forge.swords_created = forge.swords_created + 1; } public entry fun sword_transfer(sword: Sword, recipient: address) { - use Sui::Transfer; + use sui::transfer; // transfer the sword - Transfer::transfer(sword, recipient); + transfer::transfer(sword, recipient); } #[test] public fun test_module_init() { - use Sui::TestScenario; + use sui::test_scenario; // create test address representing game admin let admin = @0xBABE; // first transaction to emulate module initialization - let scenario = &mut TestScenario::begin(&admin); + let scenario = &mut test_scenario::begin(&admin); { - init(TestScenario::ctx(scenario)); + init(test_scenario::ctx(scenario)); }; // second transaction to check if the forge has been created // and has initial value of zero swords created - TestScenario::next_tx(scenario, &admin); + test_scenario::next_tx(scenario, &admin); { // extract the Forge object - let forge = TestScenario::take_owned(scenario); + let forge = test_scenario::take_owned(scenario); // verify number of created swords assert!(swords_created(&forge) == 0, 1); // return the Forge object to the object pool - TestScenario::return_owned(scenario, forge) + test_scenario::return_owned(scenario, forge) } } #[test] fun test_sword_transactions() { - use Sui::TestScenario; + use sui::test_scenario; // create test addresses representing users let admin = @0xBABE; @@ -96,51 +96,51 @@ module MyFirstPackage::M1 { let final_owner = @0xFACE; // first transaction to emulate module initialization - let scenario = &mut TestScenario::begin(&admin); + let scenario = &mut test_scenario::begin(&admin); { - init(TestScenario::ctx(scenario)); + init(test_scenario::ctx(scenario)); }; // second transaction executed by admin to create the sword - TestScenario::next_tx(scenario, &admin); + test_scenario::next_tx(scenario, &admin); { - let forge = TestScenario::take_owned(scenario); + let forge = test_scenario::take_owned(scenario); // create the sword and transfer it to the initial owner - sword_create(&mut forge, 42, 7, initial_owner, TestScenario::ctx(scenario)); - TestScenario::return_owned(scenario, forge) + sword_create(&mut forge, 42, 7, initial_owner, test_scenario::ctx(scenario)); + test_scenario::return_owned(scenario, forge) }; // third transaction executed by the initial sword owner - TestScenario::next_tx(scenario, &initial_owner); + test_scenario::next_tx(scenario, &initial_owner); { // extract the sword owned by the initial owner - let sword = TestScenario::take_owned(scenario); + let sword = test_scenario::take_owned(scenario); // transfer the sword to the final owner sword_transfer(sword, final_owner); }; // fourth transaction executed by the final sword owner - TestScenario::next_tx(scenario, &final_owner); + test_scenario::next_tx(scenario, &final_owner); { // extract the sword owned by the final owner - let sword = TestScenario::take_owned(scenario); + let sword = test_scenario::take_owned(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") - TestScenario::return_owned(scenario, sword) + test_scenario::return_owned(scenario, sword) } } #[test] public fun test_sword_create() { - use Sui::Transfer; - use Sui::TxContext; + use sui::transfer; + use sui::tx_context; // create a dummy TxContext for testing - let ctx = TxContext::dummy(); + let ctx = tx_context::dummy(); // create a sword let sword = Sword { - id: TxContext::new_id(&mut ctx), + id: tx_context::new_id(&mut ctx), magic: 42, strength: 7, }; @@ -150,7 +150,7 @@ module MyFirstPackage::M1 { // create a dummy address and transfer the sword let dummy_address = @0xCAFE; - Transfer::transfer(sword, dummy_address); + transfer::transfer(sword, dummy_address); } } diff --git a/sui_programmability/examples/nfts/Move.toml b/sui_programmability/examples/nfts/Move.toml index d467526b14781..8708c44e0c88f 100644 --- a/sui_programmability/examples/nfts/Move.toml +++ b/sui_programmability/examples/nfts/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { local = "../../../crates/sui-framework" } [addresses] -NFTs = "0x0" +nfts = "0x0" diff --git a/sui_programmability/examples/nfts/README.md b/sui_programmability/examples/nfts/README.md index 3ddbce342db88..649b5d932b980 100644 --- a/sui_programmability/examples/nfts/README.md +++ b/sui_programmability/examples/nfts/README.md @@ -2,7 +2,7 @@ * Num: Issuing the first ten natural numbers as collectible NFT's. * Marketplace: An opensea-like marketplace built with shared objects. -* Geniteam: NFTs representing collectible monsters and cosmetics used in a farming game. +* geniteam: NFTs representing collectible monsters and cosmetics used in a farming game. * Auction: example implementation of an [English auction](https://en.wikipedia.org/wiki/English_auction) using single-owner objects only. * SharedAuction: example implementation of an [English auction](https://en.wikipedia.org/wiki/English_auction) using shared objects. * ImageNFT: an NFT wrapping a URL pointing to an image stored off-chain (coming soon). diff --git a/sui_programmability/examples/nfts/sources/Marketplace.move b/sui_programmability/examples/nfts/sources/Marketplace.move deleted file mode 100644 index aebc7bb6aa5c9..0000000000000 --- a/sui_programmability/examples/nfts/sources/Marketplace.move +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -module NFTs::Marketplace { - use Sui::Bag::{Self, Bag}; - use Sui::TxContext::{Self, TxContext}; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer::{Self, ChildRef}; - use Sui::Coin::{Self, Coin}; - - // For when amount paid does not match the expected. - const EAmountIncorrect: u64 = 0; - - // For when someone tries to delist without ownership. - const ENotOwner: u64 = 1; - - struct Marketplace has key { - id: VersionedID, - objects: ChildRef, - } - - /// A single listing which contains the listed item and its price in [`Coin`]. - struct Listing has key, store { - id: VersionedID, - item: T, - ask: u64, // Coin - owner: address, - } - - /// Create a new shared Marketplace. - public entry fun create(ctx: &mut TxContext) { - let id = TxContext::new_id(ctx); - let objects = Bag::new(ctx); - let (id, objects) = Bag::transfer_to_object_id(objects, id); - let market_place = Marketplace { - id, - objects, - }; - Transfer::share_object(market_place); - } - - /// List an item at the Marketplace. - public entry fun list( - _marketplace: &Marketplace, - objects: &mut Bag, - item: T, - ask: u64, - ctx: &mut TxContext - ) { - let listing = Listing { - item, - ask, - id: TxContext::new_id(ctx), - owner: TxContext::sender(ctx), - }; - Bag::add(objects, listing) - } - - /// Remove listing and get an item back. Only owner can do that. - public fun delist( - _marketplace: &Marketplace, - objects: &mut Bag, - listing: Listing, - ctx: &mut TxContext - ): T { - let listing = Bag::remove(objects, listing); - let Listing { id, item, ask: _, owner } = listing; - - assert!(TxContext::sender(ctx) == owner, ENotOwner); - - ID::delete(id); - item - } - - /// Call [`delist`] and transfer item to the sender. - public entry fun delist_and_take( - _marketplace: &Marketplace, - objects: &mut Bag, - listing: Listing, - ctx: &mut TxContext - ) { - Bag::remove_and_take(objects, listing, ctx) - } - - /// Purchase an item using a known Listing. Payment is done in Coin. - /// Amount paid must match the requested amount. If conditions are met, - /// owner of the item gets the payment and buyer receives their item. - public fun buy( - objects: &mut Bag, - listing: Listing, - paid: Coin, - ): T { - let listing = Bag::remove(objects, listing); - let Listing { id, item, ask, owner } = listing; - - assert!(ask == Coin::value(&paid), EAmountIncorrect); - - Transfer::transfer(paid, owner); - ID::delete(id); - item - } - - /// Call [`buy`] and transfer item to the sender. - public entry fun buy_and_take( - _marketplace: &Marketplace, - listing: Listing, - objects: &mut Bag, - paid: Coin, - ctx: &mut TxContext - ) { - Transfer::transfer(buy(objects, listing, paid), TxContext::sender(ctx)) - } - - /// Check whether an object was listed on a Marketplace. - public fun contains(objects: &Bag, id: &ID): bool { - Bag::contains(objects, id) - } - - /// Returns the size of the Marketplace. - public fun size(objects: &Bag): u64 { - Bag::size(objects) - } -} - -#[test_only] -module NFTs::MarketplaceTests { - use Sui::ID::{Self, VersionedID}; - use Sui::Bag::Bag; - use Sui::Transfer; - use Sui::Coin::{Self, Coin}; - use Sui::SUI::SUI; - use Sui::TxContext; - use Sui::TestScenario::{Self, Scenario}; - use NFTs::Marketplace::{Self, Marketplace, Listing}; - - // Simple Kitty-NFT data structure. - struct Kitty has key, store { - id: VersionedID, - kitty_id: u8 - } - - const ADMIN: address = @0xA55; - const SELLER: address = @0x00A; - const BUYER: address = @0x00B; - - /// Create a shared [`Marketplace`]. - fun create_marketplace(scenario: &mut Scenario) { - TestScenario::next_tx(scenario, &ADMIN); - Marketplace::create(TestScenario::ctx(scenario)); - } - - /// Mint SUI and send it to BUYER. - fun mint_some_coin(scenario: &mut Scenario) { - TestScenario::next_tx(scenario, &ADMIN); - let coin = Coin::mint_for_testing(1000, TestScenario::ctx(scenario)); - Transfer::transfer(coin, BUYER); - } - - /// Mint Kitty NFT and send it to SELLER. - fun mint_kitty(scenario: &mut Scenario) { - TestScenario::next_tx(scenario, &ADMIN); - let nft = Kitty { id: TxContext::new_id(TestScenario::ctx(scenario)), kitty_id: 1 }; - Transfer::transfer(nft, SELLER); - } - - // SELLER lists Kitty at the Marketplace for 100 SUI. - fun list_kitty(scenario: &mut Scenario) { - TestScenario::next_tx(scenario, &SELLER); - let mkp_wrapper = TestScenario::take_shared(scenario); - let mkp = TestScenario::borrow_mut(&mut mkp_wrapper); - let bag = TestScenario::take_child_object(scenario, mkp); - let nft = TestScenario::take_owned(scenario); - - Marketplace::list(mkp, &mut bag, nft, 100, TestScenario::ctx(scenario)); - TestScenario::return_shared(scenario, mkp_wrapper); - TestScenario::return_owned(scenario, bag); - } - - #[test] - fun list_and_delist() { - let scenario = &mut TestScenario::begin(&ADMIN); - - create_marketplace(scenario); - mint_kitty(scenario); - list_kitty(scenario); - - TestScenario::next_tx(scenario, &SELLER); - { - let mkp_wrapper = TestScenario::take_shared(scenario); - let mkp = TestScenario::borrow_mut(&mut mkp_wrapper); - let bag = TestScenario::take_child_object(scenario, mkp); - let listing = TestScenario::take_child_object>(scenario, &bag); - - // Do the delist operation on a Marketplace. - let nft = Marketplace::delist(mkp, &mut bag, listing, TestScenario::ctx(scenario)); - let kitty_id = burn_kitty(nft); - - assert!(kitty_id == 1, 0); - - TestScenario::return_shared(scenario, mkp_wrapper); - TestScenario::return_owned(scenario, bag); - }; - } - - #[test] - #[expected_failure(abort_code = 1)] - fun fail_to_delist() { - let scenario = &mut TestScenario::begin(&ADMIN); - - create_marketplace(scenario); - mint_some_coin(scenario); - mint_kitty(scenario); - list_kitty(scenario); - - // BUYER attempts to delist Kitty and he has no right to do so. :( - TestScenario::next_tx(scenario, &BUYER); - { - let mkp_wrapper = TestScenario::take_shared(scenario); - let mkp = TestScenario::borrow_mut(&mut mkp_wrapper); - let bag = TestScenario::take_child_object(scenario, mkp); - let listing = TestScenario::take_child_object>(scenario, &bag); - - // Do the delist operation on a Marketplace. - let nft = Marketplace::delist(mkp, &mut bag, listing, TestScenario::ctx(scenario)); - let _ = burn_kitty(nft); - - TestScenario::return_shared(scenario, mkp_wrapper); - TestScenario::return_owned(scenario, bag); - }; - } - - #[test] - fun buy_kitty() { - let scenario = &mut TestScenario::begin(&ADMIN); - - create_marketplace(scenario); - mint_some_coin(scenario); - mint_kitty(scenario); - list_kitty(scenario); - - // BUYER takes 100 SUI from his wallet and purchases Kitty. - TestScenario::next_tx(scenario, &BUYER); - { - let coin = TestScenario::take_owned>(scenario); - let mkp_wrapper = TestScenario::take_shared(scenario); - let mkp = TestScenario::borrow_mut(&mut mkp_wrapper); - let bag = TestScenario::take_child_object(scenario, mkp); - let listing = TestScenario::take_child_object>(scenario, &bag); - let payment = Coin::withdraw(Coin::balance_mut(&mut coin), 100, TestScenario::ctx(scenario)); - - // Do the buy call and expect successful purchase. - let nft = Marketplace::buy(&mut bag, listing, payment); - let kitty_id = burn_kitty(nft); - - assert!(kitty_id == 1, 0); - - TestScenario::return_shared(scenario, mkp_wrapper); - TestScenario::return_owned(scenario, bag); - TestScenario::return_owned(scenario, coin); - }; - } - - #[test] - #[expected_failure(abort_code = 0)] - fun fail_to_buy() { - let scenario = &mut TestScenario::begin(&ADMIN); - - create_marketplace(scenario); - mint_some_coin(scenario); - mint_kitty(scenario); - list_kitty(scenario); - - // BUYER takes 100 SUI from his wallet and purchases Kitty. - TestScenario::next_tx(scenario, &BUYER); - { - let coin = TestScenario::take_owned>(scenario); - let mkp_wrapper = TestScenario::take_shared(scenario); - let mkp = TestScenario::borrow_mut(&mut mkp_wrapper); - let bag = TestScenario::take_child_object(scenario, mkp); - let listing = TestScenario::take_child_object>(scenario, &bag); - - // AMOUNT here is 10 while expected is 100. - let payment = Coin::withdraw(Coin::balance_mut(&mut coin), 10, TestScenario::ctx(scenario)); - - // Attempt to buy and expect failure purchase. - let nft = Marketplace::buy(&mut bag, listing, payment); - let _ = burn_kitty(nft); - - TestScenario::return_shared(scenario, mkp_wrapper); - TestScenario::return_owned(scenario, bag); - TestScenario::return_owned(scenario, coin); - }; - } - - fun burn_kitty(kitty: Kitty): u8 { - let Kitty{ id, kitty_id } = kitty; - ID::delete(id); - kitty_id - } -} diff --git a/sui_programmability/examples/nfts/sources/Auction.move b/sui_programmability/examples/nfts/sources/auction.move similarity index 82% rename from sui_programmability/examples/nfts/sources/Auction.move rename to sui_programmability/examples/nfts/sources/auction.move index 1577d51d8fc7e..f5b487de12233 100644 --- a/sui_programmability/examples/nfts/sources/Auction.move +++ b/sui_programmability/examples/nfts/sources/auction.move @@ -32,15 +32,15 @@ /// - otherwise the funds accumulated in the auction go to the /// original owner and the item goes to the bidder that won the /// auction -module NFTs::Auction { - use Sui::Coin::{Self, Coin}; - use Sui::Balance::Balance; - use Sui::SUI::SUI; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self,TxContext}; +module nfts::auction { + use sui::coin::{Self, Coin}; + use sui::balance::Balance; + use sui::sui::SUI; + use sui::id::{Self, ID, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self,TxContext}; - use NFTs::AuctionLib::{Self, Auction}; + use nfts::auction_lib::{Self, Auction}; // Error codes. @@ -68,8 +68,8 @@ module NFTs::Auction { public fun create_auction( to_sell: T, id: VersionedID, auctioneer: address, ctx: &mut TxContext ) { - let auction = AuctionLib::create_auction(id, to_sell, ctx); - AuctionLib::transfer(auction, auctioneer); + let auction = auction_lib::create_auction(id, to_sell, ctx); + auction_lib::transfer(auction, auctioneer); } /// Creates a bid a and send it to the auctioneer along with the @@ -78,13 +78,13 @@ module NFTs::Auction { coin: Coin, auction_id: ID, auctioneer: address, ctx: &mut TxContext ) { let bid = Bid { - id: TxContext::new_id(ctx), - bidder: TxContext::sender(ctx), + id: tx_context::new_id(ctx), + bidder: tx_context::sender(ctx), auction_id, - bid: Coin::into_balance(coin), + bid: coin::into_balance(coin), }; - Transfer::transfer(bid, auctioneer); + transfer::transfer(bid, auctioneer); } /// Updates the auction based on the information in the bid @@ -94,10 +94,10 @@ module NFTs::Auction { auction: &mut Auction, bid: Bid, ctx: &mut TxContext ) { let Bid { id, bidder, auction_id, bid: balance } = bid; - assert!(AuctionLib::auction_id(auction) == &auction_id, EWrongAuction); - AuctionLib::update_auction(auction, bidder, balance, ctx); + assert!(auction_lib::auction_id(auction) == &auction_id, EWrongAuction); + auction_lib::update_auction(auction, bidder, balance, ctx); - ID::delete(id); + id::delete(id); } /// Ends the auction - transfers item to the currently highest @@ -106,6 +106,6 @@ module NFTs::Auction { public entry fun end_auction( auction: Auction, ctx: &mut TxContext ) { - AuctionLib::end_and_destroy_auction(auction, ctx); + auction_lib::end_and_destroy_auction(auction, ctx); } } diff --git a/sui_programmability/examples/nfts/sources/AuctionLib.move b/sui_programmability/examples/nfts/sources/auction_lib.move similarity index 86% rename from sui_programmability/examples/nfts/sources/AuctionLib.move rename to sui_programmability/examples/nfts/sources/auction_lib.move index b1545102e4bcb..4fcbdf45f271f 100644 --- a/sui_programmability/examples/nfts/sources/AuctionLib.move +++ b/sui_programmability/examples/nfts/sources/auction_lib.move @@ -5,18 +5,18 @@ /// English auction (https://en.wikipedia.org/wiki/English_auction), /// one using single-owner objects only and the other using shared /// objects. -module NFTs::AuctionLib { +module nfts::auction_lib { use std::option::{Self, Option}; - use Sui::Coin; - use Sui::Balance::{Self, Balance}; - use Sui::SUI::SUI; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self,TxContext}; + use sui::coin; + use sui::balance::{Self, Balance}; + use sui::sui::SUI; + use sui::id::{Self, ID, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self,TxContext}; - friend NFTs::Auction; - friend NFTs::SharedAuction; + friend nfts::auction; + friend nfts::shared_auction; /// Stores information about an auction bid. struct BidData has store { @@ -41,7 +41,7 @@ module NFTs::AuctionLib { } public(friend) fun auction_id(auction: &Auction): &ID { - ID::inner(&auction.id) + id::inner(&auction.id) } public(friend) fun auction_owner(auction: &Auction): address { @@ -59,7 +59,7 @@ module NFTs::AuctionLib { Auction { id, to_sell: option::some(to_sell), - owner: TxContext::sender(ctx), + owner: tx_context::sender(ctx), bid_data: option::none(), } } @@ -82,7 +82,7 @@ module NFTs::AuctionLib { option::fill(&mut auction.bid_data, bid_data); } else { let prev_bid_data = option::borrow(&auction.bid_data); - if (Balance::value(&funds) > Balance::value(&prev_bid_data.funds)) { + if (balance::value(&funds) > balance::value(&prev_bid_data.funds)) { // a bid higher than currently highest bid received let new_bid_data = BidData { funds, @@ -122,10 +122,10 @@ module NFTs::AuctionLib { } = option::extract(bid_data); send_balance(funds, owner, ctx); - Transfer::transfer(item, highest_bidder); + transfer::transfer(item, highest_bidder); } else { // no bids placed - send the item back to the original owner - Transfer::transfer(item, owner); + transfer::transfer(item, owner); }; } @@ -137,7 +137,7 @@ module NFTs::AuctionLib { auction: Auction, ctx: &mut TxContext ) { let Auction { id, to_sell, owner, bid_data } = auction; - ID::delete(id); + id::delete(id); end_auction(&mut to_sell, owner, &mut bid_data, ctx); @@ -156,23 +156,23 @@ module NFTs::AuctionLib { /// Helper for the most common operation - wrapping a balance and sending it fun send_balance(balance: Balance, to: address, ctx: &mut TxContext) { - Transfer::transfer(Coin::from_balance(balance, ctx), to) + transfer::transfer(coin::from_balance(balance, ctx), to) } - /// exposes Transfer::transfer + /// exposes transfer::transfer public fun transfer(obj: Auction, recipient: address) { - Transfer::transfer(obj, recipient) + transfer::transfer(obj, recipient) } - /// exposes Transfer::transfer_to_object_id + /// exposes transfer::transfer_to_object_id public fun transfer_to_object_id( obj: Auction, owner_id: VersionedID, - ): (VersionedID, Transfer::ChildRef>) { - Transfer::transfer_to_object_id(obj, owner_id) + ): (VersionedID, transfer::ChildRef>) { + transfer::transfer_to_object_id(obj, owner_id) } public fun share_object(obj: Auction) { - Transfer::share_object(obj) + transfer::share_object(obj) } } diff --git a/sui_programmability/examples/nfts/sources/Chat.move b/sui_programmability/examples/nfts/sources/chat.move similarity index 86% rename from sui_programmability/examples/nfts/sources/Chat.move rename to sui_programmability/examples/nfts/sources/chat.move index c65986df3a623..9a3f1a925d5e9 100644 --- a/sui_programmability/examples/nfts/sources/Chat.move +++ b/sui_programmability/examples/nfts/sources/chat.move @@ -1,12 +1,12 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module NFTs::Chat { +module nfts::chat { use std::ascii::{Self, String}; use std::option::{Self, Option, some}; - use Sui::ID::{Self, ID, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::id::{Self, ID, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; use std::vector::length; /// Max text length. @@ -44,13 +44,13 @@ module NFTs::Chat { ) { assert!(length(&text) <= MAX_TEXT_LENGTH, ETextOverflow); let chat = Chat { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), app_id, text: ascii::string(text), ref_id, metadata, }; - Transfer::transfer(chat, TxContext::sender(ctx)); + transfer::transfer(chat, tx_context::sender(ctx)); } /// Mint (post) a Chat object without referencing another object. @@ -60,7 +60,7 @@ module NFTs::Chat { metadata: vector, ctx: &mut TxContext, ) { - post_internal(ID::new(app_identifier), text, option::none(), metadata, ctx); + post_internal(id::new(app_identifier), text, option::none(), metadata, ctx); } /// Mint (post) a Chat object and reference another object (i.e., to simulate retweet, reply, like, attach). @@ -73,12 +73,12 @@ module NFTs::Chat { metadata: vector, ctx: &mut TxContext, ) { - post_internal(ID::new(app_identifier), text, some(ID::new(ref_identifier)), metadata, ctx); + post_internal(id::new(app_identifier), text, some(id::new(ref_identifier)), metadata, ctx); } /// Burn a Chat object. public entry fun burn(chat: Chat) { let Chat { id, app_id: _, text: _, ref_id: _, metadata: _ } = chat; - ID::delete(id); + id::delete(id); } } diff --git a/sui_programmability/examples/nfts/sources/CrossChainAirdrop.move b/sui_programmability/examples/nfts/sources/cross_chain_airdrop.move similarity index 90% rename from sui_programmability/examples/nfts/sources/CrossChainAirdrop.move rename to sui_programmability/examples/nfts/sources/cross_chain_airdrop.move index 03b2863a84428..227950fd66388 100644 --- a/sui_programmability/examples/nfts/sources/CrossChainAirdrop.move +++ b/sui_programmability/examples/nfts/sources/cross_chain_airdrop.move @@ -5,12 +5,12 @@ /// only be one copy for each unique pair of contract_address and token_id. We only /// support a single chain(Ethereum) right now, but this can be extended to other /// chains by adding a chain_id field. -module NFTs::CrossChainAirdrop { +module nfts::cross_chain_airdrop { use std::vector; - use Sui::ERC721Metadata::{Self, ERC721Metadata, TokenID}; - use Sui::ID::{VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::erc721_metadata::{Self, ERC721Metadata, TokenID}; + use sui::id::{VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// The oracle manages one `PerContractAirdropInfo` for each Ethereum contract struct CrossChainAirdropOracle has key { @@ -55,12 +55,12 @@ module NFTs::CrossChainAirdrop { /// TODO: To make this usable, the oracle should be sent to a /// hardcoded address that the contract creator has private key. fun init(ctx: &mut TxContext) { - Transfer::transfer( + transfer::transfer( CrossChainAirdropOracle { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), managed_contracts: vector::empty(), }, - TxContext::sender(ctx) + tx_context::sender(ctx) ) } @@ -75,16 +75,16 @@ module NFTs::CrossChainAirdrop { ctx: &mut TxContext, ) { let contract = get_or_create_contract(oracle, &source_contract_address); - let token_id = ERC721Metadata::new_token_id(source_token_id); + let token_id = erc721_metadata::new_token_id(source_token_id); // NOTE: this is where the globally uniqueness check happens assert!(!is_token_claimed(contract, &token_id), ETokenIDClaimed); let nft = ERC721 { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), source_contract_address: SourceContractAddress { address: source_contract_address }, - metadata: ERC721Metadata::new(token_id, name, token_uri), + metadata: erc721_metadata::new(token_id, name, token_uri), }; vector::push_back(&mut contract.claimed_source_token_ids, token_id); - Transfer::transfer(nft, recipient) + transfer::transfer(nft, recipient) } fun get_or_create_contract(oracle: &mut CrossChainAirdropOracle, source_contract_address: &vector): &mut PerContractAirdropInfo { diff --git a/sui_programmability/examples/nfts/sources/DiscountCoupon.move b/sui_programmability/examples/nfts/sources/discount_coupon.move similarity index 77% rename from sui_programmability/examples/nfts/sources/DiscountCoupon.move rename to sui_programmability/examples/nfts/sources/discount_coupon.move index 36b55d3e21385..cc26a471cb1a2 100644 --- a/sui_programmability/examples/nfts/sources/DiscountCoupon.move +++ b/sui_programmability/examples/nfts/sources/discount_coupon.move @@ -1,12 +1,12 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module NFTs::DiscountCoupon { - use Sui::Coin; - use Sui::ID::{Self, VersionedID}; - use Sui::SUI::{Self, SUI}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module nfts::discount_coupon { + use sui::coin; + use sui::id::{Self, VersionedID}; + use sui::sui::{Self, SUI}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Sending to wrong recipient. const EWrongRecipient: u64 = 0; @@ -32,7 +32,7 @@ module NFTs::DiscountCoupon { /// Mint then transfer a new `DiscountCoupon` NFT, and top up recipient with some SUI. public entry fun mint_and_topup( - coin: Coin::Coin, + coin: coin::Coin, discount: u8, expiration: u64, recipient: address, @@ -40,19 +40,19 @@ module NFTs::DiscountCoupon { ) { assert!(discount > 0 && discount <= 100, EOutOfRangeDiscount); let coupon = DiscountCoupon { - id: TxContext::new_id(ctx), - issuer: TxContext::sender(ctx), + id: tx_context::new_id(ctx), + issuer: tx_context::sender(ctx), discount, expiration, }; - Transfer::transfer(coupon, recipient); - SUI::transfer(coin, recipient); + transfer::transfer(coupon, recipient); + sui::transfer(coin, recipient); } /// Burn DiscountCoupon. public entry fun burn(nft: DiscountCoupon) { let DiscountCoupon { id, issuer: _, discount: _, expiration: _ } = nft; - ID::delete(id); + id::delete(id); } /// Transfer DiscountCoupon to issuer only. @@ -60,6 +60,6 @@ module NFTs::DiscountCoupon { // If we stick with issuer-as-receiver only, then `recipient` input won't be required). public entry fun transfer(coupon: DiscountCoupon, recipient: address) { assert!(&coupon.issuer == &recipient, EWrongRecipient); - Transfer::transfer(coupon, recipient); + transfer::transfer(coupon, recipient); } } diff --git a/sui_programmability/examples/nfts/sources/Geniteam.move b/sui_programmability/examples/nfts/sources/geniteam.move similarity index 89% rename from sui_programmability/examples/nfts/sources/Geniteam.move rename to sui_programmability/examples/nfts/sources/geniteam.move index c1f12ed714669..d548b7b489173 100644 --- a/sui_programmability/examples/nfts/sources/Geniteam.move +++ b/sui_programmability/examples/nfts/sources/geniteam.move @@ -1,13 +1,13 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module NFTs::Geniteam { - use Sui::Bag::{Self, Bag}; - use Sui::Collection::{Self, Collection}; - use Sui::ID::VersionedID; - use Sui::TxContext::{Self, TxContext}; +module nfts::geniteam { + use sui::bag::{Self, Bag}; + use sui::collection::{Self, Collection}; + use sui::id::VersionedID; + use sui::tx_context::{Self, TxContext}; use std::option::{Self, Option}; - use Sui::Transfer::{Self, ChildRef}; + use sui::transfer::{Self, ChildRef}; use std::ascii::{Self, String}; use std::vector; @@ -99,7 +99,7 @@ module NFTs::Geniteam { ) { // Create player simply and transfer to caller let player = new_player(player_name, ctx); - Transfer::transfer(player, TxContext::sender(ctx)) + transfer::transfer(player, tx_context::sender(ctx)) } /// Create a Farm and add it to the Player @@ -113,7 +113,7 @@ module NFTs::Geniteam { let farm = new_farm(farm_name, farm_img_index, total_monster_slots, ctx); // Transfer ownership of farm to player - let child_ref = Transfer::transfer_to_object(farm, player); + let child_ref = transfer::transfer_to_object(farm, player); // Store the farm option::fill(&mut player.owned_farm, child_ref) @@ -144,13 +144,13 @@ module NFTs::Geniteam { // Check if this is the right collection assert!( - Transfer::is_child(&farm.pet_monsters, pet_monsters), + transfer::is_child(&farm.pet_monsters, pet_monsters), EMonsterCollectionNotOwnedByFarm, ); // TODO: Decouple adding monster to farm from creating a monster. // Add it to the collection - Collection::add(pet_monsters, monster); + collection::add(pet_monsters, monster); } /// Create Farm cosmetic owned by player and add to its inventory @@ -160,19 +160,19 @@ module NFTs::Geniteam { ) { // Check if this is the right collection assert!( - Transfer::is_child(&player.inventory, inventory), + transfer::is_child(&player.inventory, inventory), EInventoryNotOwnedByPlayer, ); // Create the farm cosmetic object let farm_cosmetic = FarmCosmetic { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), cosmetic_type, display: ascii::string(display) }; // Add it to the player's inventory - Bag::add(inventory, farm_cosmetic); + bag::add(inventory, farm_cosmetic); } /// Create Monster cosmetic owned by player and add to its inventory @@ -182,19 +182,19 @@ module NFTs::Geniteam { ) { // Check if this is the right collection assert!( - Transfer::is_child(&player.inventory, inventory), + transfer::is_child(&player.inventory, inventory), EInventoryNotOwnedByPlayer, ); // Create the farm cosmetic object let monster_cosmetic = MonsterCosmetic { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), cosmetic_type, display: ascii::string(display) }; // Add it to the player's inventory - Bag::add(inventory, monster_cosmetic); + bag::add(inventory, monster_cosmetic); } /// Update the attributes of a player @@ -252,7 +252,7 @@ module NFTs::Geniteam { assert!(cosmetic_slot_id <= 1 , EInvalidCosmeticsSlot); // Transfer ownership of cosmetic to this farm - let child_ref = Transfer::transfer_to_object(farm_cosmetic, farm); + let child_ref = transfer::transfer_to_object(farm_cosmetic, farm); // Assign by slot if (cosmetic_slot_id == 0) { @@ -274,7 +274,7 @@ module NFTs::Geniteam { assert!(cosmetic_slot_id <= 1 , EInvalidCosmeticsSlot); // Transfer ownership of cosmetic to this monster - let child_ref = Transfer::transfer_to_object(monster_cosmetic, monster); + let child_ref = transfer::transfer_to_object(monster_cosmetic, monster); // Assign by slot if (cosmetic_slot_id == 0) { @@ -293,13 +293,13 @@ module NFTs::Geniteam { player_name: vector, ctx: &mut TxContext ): Player { // Create a new id for player. - let id = TxContext::new_id(ctx); + let id = tx_context::new_id(ctx); // Create inventory collection. - let inventory = Bag::new(ctx); + let inventory = bag::new(ctx); // Transfer ownership of inventory to player. - let (id, child_ref) = Bag::transfer_to_object_id(inventory, id); + let (id, child_ref) = bag::transfer_to_object_id(inventory, id); let player = Player { id, @@ -321,13 +321,13 @@ module NFTs::Geniteam { ctx: &mut TxContext ): Farm { // Create a new id for farm. - let id = TxContext::new_id(ctx); + let id = tx_context::new_id(ctx); // Create pet monsters collection. - let pet_monsters = Collection::new(ctx); + let pet_monsters = collection::new(ctx); // Transfer ownership of pet monsters to farm. - let (id, child_ref) = Collection::transfer_to_object_id(pet_monsters, id); + let (id, child_ref) = collection::transfer_to_object_id(pet_monsters, id); let farm = Farm { @@ -358,7 +358,7 @@ module NFTs::Geniteam { ): Monster { Monster { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), monster_name: ascii::string(monster_name), monster_img_index, breed, diff --git a/sui_programmability/examples/nfts/sources/marketplace.move b/sui_programmability/examples/nfts/sources/marketplace.move new file mode 100644 index 0000000000000..e9366de33b912 --- /dev/null +++ b/sui_programmability/examples/nfts/sources/marketplace.move @@ -0,0 +1,300 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +module nfts::marketplace { + use sui::bag::{Self, Bag}; + use sui::tx_context::{Self, TxContext}; + use sui::id::{Self, ID, VersionedID}; + use sui::transfer::{Self, ChildRef}; + use sui::coin::{Self, Coin}; + + // For when amount paid does not match the expected. + const EAmountIncorrect: u64 = 0; + + // For when someone tries to delist without ownership. + const ENotOwner: u64 = 1; + + struct Marketplace has key { + id: VersionedID, + objects: ChildRef, + } + + /// A single listing which contains the listed item and its price in [`Coin`]. + struct Listing has key, store { + id: VersionedID, + item: T, + ask: u64, // Coin + owner: address, + } + + /// Create a new shared Marketplace. + public entry fun create(ctx: &mut TxContext) { + let id = tx_context::new_id(ctx); + let objects = bag::new(ctx); + let (id, objects) = bag::transfer_to_object_id(objects, id); + let market_place = Marketplace { + id, + objects, + }; + transfer::share_object(market_place); + } + + /// List an item at the Marketplace. + public entry fun list( + _marketplace: &Marketplace, + objects: &mut Bag, + item: T, + ask: u64, + ctx: &mut TxContext + ) { + let listing = Listing { + item, + ask, + id: tx_context::new_id(ctx), + owner: tx_context::sender(ctx), + }; + bag::add(objects, listing) + } + + /// Remove listing and get an item back. Only owner can do that. + public fun delist( + _marketplace: &Marketplace, + objects: &mut Bag, + listing: Listing, + ctx: &mut TxContext + ): T { + let listing = bag::remove(objects, listing); + let Listing { id, item, ask: _, owner } = listing; + + assert!(tx_context::sender(ctx) == owner, ENotOwner); + + id::delete(id); + item + } + + /// Call [`delist`] and transfer item to the sender. + public entry fun delist_and_take( + _marketplace: &Marketplace, + objects: &mut Bag, + listing: Listing, + ctx: &mut TxContext + ) { + bag::remove_and_take(objects, listing, ctx) + } + + /// Purchase an item using a known Listing. Payment is done in Coin. + /// Amount paid must match the requested amount. If conditions are met, + /// owner of the item gets the payment and buyer receives their item. + public fun buy( + objects: &mut Bag, + listing: Listing, + paid: Coin, + ): T { + let listing = bag::remove(objects, listing); + let Listing { id, item, ask, owner } = listing; + + assert!(ask == coin::value(&paid), EAmountIncorrect); + + transfer::transfer(paid, owner); + id::delete(id); + item + } + + /// Call [`buy`] and transfer item to the sender. + public entry fun buy_and_take( + _marketplace: &Marketplace, + listing: Listing, + objects: &mut Bag, + paid: Coin, + ctx: &mut TxContext + ) { + transfer::transfer(buy(objects, listing, paid), tx_context::sender(ctx)) + } + + /// Check whether an object was listed on a Marketplace. + public fun contains(objects: &Bag, id: &ID): bool { + bag::contains(objects, id) + } + + /// Returns the size of the Marketplace. + public fun size(objects: &Bag): u64 { + bag::size(objects) + } +} + +#[test_only] +module nfts::marketplaceTests { + use sui::id::{Self, VersionedID}; + use sui::bag::Bag; + use sui::transfer; + use sui::coin::{Self, Coin}; + use sui::sui::SUI; + use sui::tx_context; + use sui::test_scenario::{Self, Scenario}; + use nfts::marketplace::{Self, Marketplace, Listing}; + + // Simple Kitty-NFT data structure. + struct Kitty has key, store { + id: VersionedID, + kitty_id: u8 + } + + const ADMIN: address = @0xA55; + const SELLER: address = @0x00A; + const BUYER: address = @0x00B; + + /// Create a shared [`Marketplace`]. + fun create_marketplace(scenario: &mut Scenario) { + test_scenario::next_tx(scenario, &ADMIN); + marketplace::create(test_scenario::ctx(scenario)); + } + + /// Mint SUI and send it to BUYER. + fun mint_some_coin(scenario: &mut Scenario) { + test_scenario::next_tx(scenario, &ADMIN); + let coin = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); + transfer::transfer(coin, BUYER); + } + + /// Mint Kitty NFT and send it to SELLER. + fun mint_kitty(scenario: &mut Scenario) { + test_scenario::next_tx(scenario, &ADMIN); + let nft = Kitty { id: tx_context::new_id(test_scenario::ctx(scenario)), kitty_id: 1 }; + transfer::transfer(nft, SELLER); + } + + // SELLER lists Kitty at the Marketplace for 100 SUI. + fun list_kitty(scenario: &mut Scenario) { + test_scenario::next_tx(scenario, &SELLER); + let mkp_wrapper = test_scenario::take_shared(scenario); + let mkp = test_scenario::borrow_mut(&mut mkp_wrapper); + let bag = test_scenario::take_child_object(scenario, mkp); + let nft = test_scenario::take_owned(scenario); + + marketplace::list(mkp, &mut bag, nft, 100, test_scenario::ctx(scenario)); + test_scenario::return_shared(scenario, mkp_wrapper); + test_scenario::return_owned(scenario, bag); + } + + #[test] + fun list_and_delist() { + let scenario = &mut test_scenario::begin(&ADMIN); + + create_marketplace(scenario); + mint_kitty(scenario); + list_kitty(scenario); + + test_scenario::next_tx(scenario, &SELLER); + { + let mkp_wrapper = test_scenario::take_shared(scenario); + let mkp = test_scenario::borrow_mut(&mut mkp_wrapper); + let bag = test_scenario::take_child_object(scenario, mkp); + let listing = test_scenario::take_child_object>(scenario, &bag); + + // Do the delist operation on a Marketplace. + let nft = marketplace::delist(mkp, &mut bag, listing, test_scenario::ctx(scenario)); + let kitty_id = burn_kitty(nft); + + assert!(kitty_id == 1, 0); + + test_scenario::return_shared(scenario, mkp_wrapper); + test_scenario::return_owned(scenario, bag); + }; + } + + #[test] + #[expected_failure(abort_code = 1)] + fun fail_to_delist() { + let scenario = &mut test_scenario::begin(&ADMIN); + + create_marketplace(scenario); + mint_some_coin(scenario); + mint_kitty(scenario); + list_kitty(scenario); + + // BUYER attempts to delist Kitty and he has no right to do so. :( + test_scenario::next_tx(scenario, &BUYER); + { + let mkp_wrapper = test_scenario::take_shared(scenario); + let mkp = test_scenario::borrow_mut(&mut mkp_wrapper); + let bag = test_scenario::take_child_object(scenario, mkp); + let listing = test_scenario::take_child_object>(scenario, &bag); + + // Do the delist operation on a Marketplace. + let nft = marketplace::delist(mkp, &mut bag, listing, test_scenario::ctx(scenario)); + let _ = burn_kitty(nft); + + test_scenario::return_shared(scenario, mkp_wrapper); + test_scenario::return_owned(scenario, bag); + }; + } + + #[test] + fun buy_kitty() { + let scenario = &mut test_scenario::begin(&ADMIN); + + create_marketplace(scenario); + mint_some_coin(scenario); + mint_kitty(scenario); + list_kitty(scenario); + + // BUYER takes 100 SUI from his wallet and purchases Kitty. + test_scenario::next_tx(scenario, &BUYER); + { + let coin = test_scenario::take_owned>(scenario); + let mkp_wrapper = test_scenario::take_shared(scenario); + let mkp = test_scenario::borrow_mut(&mut mkp_wrapper); + let bag = test_scenario::take_child_object(scenario, mkp); + let listing = test_scenario::take_child_object>(scenario, &bag); + let payment = coin::withdraw(coin::balance_mut(&mut coin), 100, test_scenario::ctx(scenario)); + + // Do the buy call and expect successful purchase. + let nft = marketplace::buy(&mut bag, listing, payment); + let kitty_id = burn_kitty(nft); + + assert!(kitty_id == 1, 0); + + test_scenario::return_shared(scenario, mkp_wrapper); + test_scenario::return_owned(scenario, bag); + test_scenario::return_owned(scenario, coin); + }; + } + + #[test] + #[expected_failure(abort_code = 0)] + fun fail_to_buy() { + let scenario = &mut test_scenario::begin(&ADMIN); + + create_marketplace(scenario); + mint_some_coin(scenario); + mint_kitty(scenario); + list_kitty(scenario); + + // BUYER takes 100 SUI from his wallet and purchases Kitty. + test_scenario::next_tx(scenario, &BUYER); + { + let coin = test_scenario::take_owned>(scenario); + let mkp_wrapper = test_scenario::take_shared(scenario); + let mkp = test_scenario::borrow_mut(&mut mkp_wrapper); + let bag = test_scenario::take_child_object(scenario, mkp); + let listing = test_scenario::take_child_object>(scenario, &bag); + + // AMOUNT here is 10 while expected is 100. + let payment = coin::withdraw(coin::balance_mut(&mut coin), 10, test_scenario::ctx(scenario)); + + // Attempt to buy and expect failure purchase. + let nft = marketplace::buy(&mut bag, listing, payment); + let _ = burn_kitty(nft); + + test_scenario::return_shared(scenario, mkp_wrapper); + test_scenario::return_owned(scenario, bag); + test_scenario::return_owned(scenario, coin); + }; + } + + fun burn_kitty(kitty: Kitty): u8 { + let Kitty{ id, kitty_id } = kitty; + id::delete(id); + kitty_id + } +} diff --git a/sui_programmability/examples/nfts/sources/Num.move b/sui_programmability/examples/nfts/sources/num.move similarity index 85% rename from sui_programmability/examples/nfts/sources/Num.move rename to sui_programmability/examples/nfts/sources/num.move index 3800d6d4f1dde..212664686907b 100644 --- a/sui_programmability/examples/nfts/sources/Num.move +++ b/sui_programmability/examples/nfts/sources/num.move @@ -1,10 +1,10 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module NFTs::Num { - use Sui::ID::{Self, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module nfts::num { + use sui::id::{Self, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; /// Very silly NFT: a natural number! struct Num has key, store { @@ -31,11 +31,11 @@ module NFTs::Num { /// Create a unique issuer cap and give it to the transaction sender fun init(ctx: &mut TxContext) { let issuer_cap = NumIssuerCap { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), supply: 0, issued_counter: 0, }; - Transfer::transfer(issuer_cap, TxContext::sender(ctx)) + transfer::transfer(issuer_cap, tx_context::sender(ctx)) } /// Create a new `Num` NFT. Aborts if `MAX_SUPPLY` NFT's have already been issued @@ -44,7 +44,7 @@ module NFTs::Num { cap.issued_counter = n + 1; cap.supply = cap.supply + 1; assert!(n <= MAX_SUPPLY, ETooManyNums); - Num { id: TxContext::new_id(ctx), n } + Num { id: tx_context::new_id(ctx), n } } /// Burn `nft`. This reduces the supply. @@ -55,6 +55,6 @@ module NFTs::Num { public fun burn(cap: &mut NumIssuerCap, nft: Num) { let Num { id, n: _ } = nft; cap.supply = cap.supply - 1; - ID::delete(id); + id::delete(id); } } diff --git a/sui_programmability/examples/nfts/sources/SharedAuction.move b/sui_programmability/examples/nfts/sources/shared_auction.move similarity index 80% rename from sui_programmability/examples/nfts/sources/SharedAuction.move rename to sui_programmability/examples/nfts/sources/shared_auction.move index 6f3603b1aa53e..8a63a1476c359 100644 --- a/sui_programmability/examples/nfts/sources/SharedAuction.move +++ b/sui_programmability/examples/nfts/sources/shared_auction.move @@ -25,12 +25,12 @@ /// - otherwise the funds accumulated in the auction go to the owner /// and the item goes to the bidder that won the auction -module NFTs::SharedAuction { - use Sui::Coin::{Self, Coin}; - use Sui::SUI::SUI; - use Sui::TxContext::{Self,TxContext}; +module nfts::shared_auction { + use sui::coin::{Self, Coin}; + use sui::sui::SUI; + use sui::tx_context::{Self,TxContext}; - use NFTs::AuctionLib::{Self, Auction}; + use nfts::auction_lib::{Self, Auction}; // Error codes. @@ -42,8 +42,8 @@ module NFTs::SharedAuction { /// Creates an auction. This is executed by the owner of the asset /// to be auctioned. public entry fun create_auction(to_sell: T, ctx: &mut TxContext) { - let auction = AuctionLib::create_auction(TxContext::new_id(ctx), to_sell, ctx); - AuctionLib::share_object(auction); + let auction = auction_lib::create_auction(tx_context::new_id(ctx), to_sell, ctx); + auction_lib::share_object(auction); } /// Sends a bid to the auction. The result is either successful @@ -53,10 +53,10 @@ module NFTs::SharedAuction { public entry fun bid( coin: Coin, auction: &mut Auction, ctx: &mut TxContext ) { - AuctionLib::update_auction( + auction_lib::update_auction( auction, - TxContext::sender(ctx), - Coin::into_balance(coin), + tx_context::sender(ctx), + coin::into_balance(coin), ctx ); } @@ -68,9 +68,9 @@ module NFTs::SharedAuction { public entry fun end_auction( auction: &mut Auction, ctx: &mut TxContext ) { - let owner = AuctionLib::auction_owner(auction); - assert!(TxContext::sender(ctx) == owner, EWrongOwner); - AuctionLib::end_shared_auction(auction, ctx); + let owner = auction_lib::auction_owner(auction); + assert!(tx_context::sender(ctx) == owner, EWrongOwner); + auction_lib::end_shared_auction(auction, ctx); } } diff --git a/sui_programmability/examples/nfts/tests/ChatTests.move b/sui_programmability/examples/nfts/tests/ChatTests.move deleted file mode 100644 index 9ab58b194695a..0000000000000 --- a/sui_programmability/examples/nfts/tests/ChatTests.move +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module NFTs::ChatTests { - use NFTs::Chat::{Self, Chat}; - use std::ascii::Self; - use Sui::TestScenario::Self; - - const USER1_ADDRESS: address = @0xA001; - const METADATA: vector = vector[0u8]; - const HELLO: vector = vector[72, 101, 108, 108, 111]; // "Hello" in ASCII. - - #[test] - fun test_chat() { - let scenario = &mut TestScenario::begin(&USER1_ADDRESS); - { - Chat::post( - @0xC001, // This should be an application object ID. - HELLO, - METADATA, // Some metadata (it could be empty). - TestScenario::ctx(scenario) - ); - }; - - TestScenario::next_tx(scenario, &USER1_ADDRESS); - { - assert!(TestScenario::can_take_owned(scenario), 0); - let chat = TestScenario::take_owned(scenario); // if can remove, object exists - assert!(Chat::text(&chat) == ascii::string(HELLO), 0); - TestScenario::return_owned(scenario, chat); - } - } -} diff --git a/sui_programmability/examples/nfts/tests/DiscountCouponTests.move b/sui_programmability/examples/nfts/tests/DiscountCouponTests.move deleted file mode 100644 index 7bcfe7d82e98f..0000000000000 --- a/sui_programmability/examples/nfts/tests/DiscountCouponTests.move +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module NFTs::DiscountCouponTests { - use NFTs::DiscountCoupon::{Self, DiscountCoupon}; - use Sui::Coin::{Self, Coin}; - use Sui::SUI::SUI; - use Sui::TestScenario::Self; - use Sui::TxContext::TxContext; - - const ISSUER_ADDRESS: address = @0xA001; - const USER1_ADDRESS: address = @0xB001; - - // Error codes. - // const MINT_FAILED: u64 = 0; - // const TRANSFER_FAILED: u64 = 1; - - // Initializes the "state of the world" that mimics what should - // be available in Sui genesis state (e.g., mints and distributes - // coins to users). - fun init(ctx: &mut TxContext) { - let coin = Coin::mint_for_testing(100, ctx); - Coin::transfer(coin, ISSUER_ADDRESS); - } - - #[test] - fun test_mint_then_transfer() { - let scenario = &mut TestScenario::begin(&ISSUER_ADDRESS); - { - init(TestScenario::ctx(scenario)); - }; - - // Mint and transfer NFT + top up recipient's address. - TestScenario::next_tx(scenario, &ISSUER_ADDRESS); - { - let coin = TestScenario::take_owned>(scenario); - DiscountCoupon::mint_and_topup(coin, 10, 1648820870, USER1_ADDRESS, TestScenario::ctx(scenario)); - }; - - TestScenario::next_tx(scenario, &USER1_ADDRESS); - { - assert!(TestScenario::can_take_owned(scenario), 0); - let nft_coupon = TestScenario::take_owned(scenario); // if can remove, object exists - assert!(DiscountCoupon::issuer(&nft_coupon) == ISSUER_ADDRESS, 0); - TestScenario::return_owned(scenario, nft_coupon); - } - } -} diff --git a/sui_programmability/examples/nfts/tests/SharedAuctionTests.move b/sui_programmability/examples/nfts/tests/SharedAuctionTests.move deleted file mode 100644 index f5c47c6d0d3dd..0000000000000 --- a/sui_programmability/examples/nfts/tests/SharedAuctionTests.move +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -#[test_only] -module NFTs::SharedAuctionTests { - use std::vector; - - use Sui::Coin::{Self, Coin}; - use Sui::SUI::SUI; - use Sui::ID::VersionedID; - use Sui::TestScenario::Self; - use Sui::TxContext::{Self, TxContext}; - - use NFTs::SharedAuction; - use NFTs::AuctionLib::Auction; - - - const COIN_VALUE: u64 = 100; - - // Error codes. - const EWRONG_ITEM_VALUE: u64 = 1; - const EWRONG_COIN_VALUE: u64 = 2; - - // Example of an object type that could be sold at an auction. - struct SomeItemToSell has key, store { - id: VersionedID, - value: u64, - } - - // Initializes the "state of the world" that mimics what should - // be available in Sui genesis state (e.g., mints and distributes - // coins to users). - fun init(ctx: &mut TxContext, bidders: vector
) { - while (!vector::is_empty(&bidders)) { - let bidder = vector::pop_back(&mut bidders); - let coin = Coin::mint_for_testing(COIN_VALUE, ctx); - Coin::transfer(coin, bidder); - }; - } - - #[test] - fun simple_auction_test() { - let admin = @0xABBA; // needed only to initialize "state of the world" - let owner = @0xACE; - let bidder1 = @0xFACE; - let bidder2 = @0xCAFE; - - - let scenario = &mut TestScenario::begin(&admin); - { - let bidders = vector::empty(); - vector::push_back(&mut bidders, bidder1); - vector::push_back(&mut bidders, bidder2); - init(TestScenario::ctx(scenario), bidders); - }; - - // a transaction by the item owner to put it for auction - TestScenario::next_tx(scenario, &owner); - let ctx = TestScenario::ctx(scenario); - { - let to_sell = SomeItemToSell { - id: TxContext::new_id(ctx), - value: 42, - }; - SharedAuction::create_auction(to_sell, ctx); - }; - - // a transaction by the first bidder to put a bid - TestScenario::next_tx(scenario, &bidder1); - { - let coin = TestScenario::take_owned>(scenario); - let auction_wrapper = TestScenario::take_shared>(scenario); - let auction = TestScenario::borrow_mut(&mut auction_wrapper); - - SharedAuction::bid(coin, auction, TestScenario::ctx(scenario)); - - TestScenario::return_shared(scenario, auction_wrapper); - }; - - // a transaction by the second bidder to put a bid (a bid will - // fail as it has the same value as that of the first - // bidder's) - TestScenario::next_tx(scenario, &bidder2); - { - let coin = TestScenario::take_owned>(scenario); - let auction_wrapper = TestScenario::take_shared>(scenario); - let auction = TestScenario::borrow_mut(&mut auction_wrapper); - - SharedAuction::bid(coin, auction, TestScenario::ctx(scenario)); - - TestScenario::return_shared(scenario, auction_wrapper); - }; - - // a transaction by the second bidder to verify that the funds - // have been returned (as a result of the failed bid). - TestScenario::next_tx(scenario, &bidder2); - { - let coin = TestScenario::take_owned>(scenario); - - assert!(Coin::value(&coin) == COIN_VALUE, EWRONG_COIN_VALUE); - - TestScenario::return_owned(scenario, coin); - }; - - // a transaction by the owner to end auction - TestScenario::next_tx(scenario, &owner); - { - let auction_wrapper = TestScenario::take_shared>(scenario); - let auction = TestScenario::borrow_mut(&mut auction_wrapper); - - // pass auction as mutable reference as its a shared - // object that cannot be deleted - SharedAuction::end_auction(auction, TestScenario::ctx(scenario)); - - TestScenario::return_shared(scenario, auction_wrapper); - }; - - // a transaction to check if the first bidder won (as the - // second bidder's bid was the same as that of the first one) - TestScenario::next_tx(scenario, &bidder1); - { - let acquired_item = TestScenario::take_owned(scenario); - - assert!(acquired_item.value == 42, EWRONG_ITEM_VALUE); - - TestScenario::return_owned(scenario, acquired_item); - }; - } -} diff --git a/sui_programmability/examples/nfts/tests/AuctionTests.move b/sui_programmability/examples/nfts/tests/auction_tests.move similarity index 50% rename from sui_programmability/examples/nfts/tests/AuctionTests.move rename to sui_programmability/examples/nfts/tests/auction_tests.move index f785c9a683554..16775f84c5354 100644 --- a/sui_programmability/examples/nfts/tests/AuctionTests.move +++ b/sui_programmability/examples/nfts/tests/auction_tests.move @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module NFTs::AuctionTests { +module nfts::auction_tests { use std::vector; - use Sui::Coin::{Self, Coin}; - use Sui::SUI::SUI; - use Sui::ID::{Self, VersionedID}; - use Sui::TestScenario::Self; - use Sui::TxContext::{Self, TxContext}; + use sui::coin::{Self, Coin}; + use sui::sui::SUI; + use sui::id::{Self, VersionedID}; + use sui::test_scenario::Self; + use sui::tx_context::{Self, TxContext}; - use NFTs::Auction::{Self, Bid}; - use NFTs::AuctionLib::Auction; + use nfts::auction::{Self, Bid}; + use nfts::auction_lib::Auction; // Error codes. const EWRONG_ITEM_VALUE: u64 = 1; @@ -29,8 +29,8 @@ module NFTs::AuctionTests { fun init(ctx: &mut TxContext, bidders: vector
) { while (!vector::is_empty(&bidders)) { let bidder = vector::pop_back(&mut bidders); - let coin = Coin::mint_for_testing(100, ctx); - Coin::transfer(coin, bidder); + let coin = coin::mint_for_testing(100, ctx); + coin::transfer(coin, bidder); }; } @@ -42,88 +42,88 @@ module NFTs::AuctionTests { let bidder2 = @0xCAFE; - let scenario = &mut TestScenario::begin(&auctioneer); + let scenario = &mut test_scenario::begin(&auctioneer); { let bidders = vector::empty(); vector::push_back(&mut bidders, bidder1); vector::push_back(&mut bidders, bidder2); - init(TestScenario::ctx(scenario), bidders); + init(test_scenario::ctx(scenario), bidders); }; // a transaction by the item owner to put it for auction - TestScenario::next_tx(scenario, &owner); - let ctx = TestScenario::ctx(scenario); + test_scenario::next_tx(scenario, &owner); + let ctx = test_scenario::ctx(scenario); let to_sell = SomeItemToSell { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), value: 42, }; // generate unique auction ID (it would be more natural to // generate one in crate_auction and return it, but we cannot // do this at the moment) - let id = TxContext::new_id(ctx); + let id = tx_context::new_id(ctx); // we need to dereference (copy) right here rather wherever // auction_id is used - otherwise id would still be considered // borrowed and could not be passed argument to a function // consuming it - let auction_id = *ID::inner(&id); - Auction::create_auction(to_sell, id, auctioneer, ctx); + let auction_id = *id::inner(&id); + auction::create_auction(to_sell, id, auctioneer, ctx); // a transaction by the first bidder to create and put a bid - TestScenario::next_tx(scenario, &bidder1); + test_scenario::next_tx(scenario, &bidder1); { - let coin = TestScenario::take_owned>(scenario); + let coin = test_scenario::take_owned>(scenario); - Auction::bid(coin, auction_id, auctioneer, TestScenario::ctx(scenario)); + auction::bid(coin, auction_id, auctioneer, test_scenario::ctx(scenario)); }; // a transaction by the auctioneer to update state of the auction - TestScenario::next_tx(scenario, &auctioneer); + test_scenario::next_tx(scenario, &auctioneer); { - let auction = TestScenario::take_owned>(scenario); + let auction = test_scenario::take_owned>(scenario); - let bid = TestScenario::take_owned(scenario); - Auction::update_auction(&mut auction, bid, TestScenario::ctx(scenario)); + let bid = test_scenario::take_owned(scenario); + auction::update_auction(&mut auction, bid, test_scenario::ctx(scenario)); - TestScenario::return_owned(scenario, auction); + test_scenario::return_owned(scenario, auction); }; // a transaction by the second bidder to create and put a bid (a // bid will fail as it has the same value as that of the first // bidder's) - TestScenario::next_tx(scenario, &bidder2); + test_scenario::next_tx(scenario, &bidder2); { - let coin = TestScenario::take_owned>(scenario); + let coin = test_scenario::take_owned>(scenario); - Auction::bid(coin, auction_id, auctioneer, TestScenario::ctx(scenario)); + auction::bid(coin, auction_id, auctioneer, test_scenario::ctx(scenario)); }; // a transaction by the auctioneer to update state of the auction - TestScenario::next_tx(scenario, &auctioneer); + test_scenario::next_tx(scenario, &auctioneer); { - let auction = TestScenario::take_owned>(scenario); + let auction = test_scenario::take_owned>(scenario); - let bid = TestScenario::take_owned(scenario); - Auction::update_auction(&mut auction, bid, TestScenario::ctx(scenario)); + let bid = test_scenario::take_owned(scenario); + auction::update_auction(&mut auction, bid, test_scenario::ctx(scenario)); - TestScenario::return_owned(scenario, auction); + test_scenario::return_owned(scenario, auction); }; // a transaction by the auctioneer to end auction - TestScenario::next_tx(scenario, &auctioneer); + test_scenario::next_tx(scenario, &auctioneer); { - let auction = TestScenario::take_owned>(scenario); + let auction = test_scenario::take_owned>(scenario); - Auction::end_auction(auction, TestScenario::ctx(scenario)); + auction::end_auction(auction, test_scenario::ctx(scenario)); }; // a transaction to check if the first bidder won (as the // second bidder's bid was the same as that of the first one) - TestScenario::next_tx(scenario, &bidder1); + test_scenario::next_tx(scenario, &bidder1); { - let acquired_item = TestScenario::take_owned(scenario); + let acquired_item = test_scenario::take_owned(scenario); assert!(acquired_item.value == 42, EWRONG_ITEM_VALUE); - TestScenario::return_owned(scenario, acquired_item); + test_scenario::return_owned(scenario, acquired_item); }; } } diff --git a/sui_programmability/examples/nfts/tests/chat_tests.move b/sui_programmability/examples/nfts/tests/chat_tests.move new file mode 100644 index 0000000000000..c2a75e77c69f1 --- /dev/null +++ b/sui_programmability/examples/nfts/tests/chat_tests.move @@ -0,0 +1,34 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module nfts::chat_tests { + use nfts::chat::{Self, Chat}; + use std::ascii::Self; + use sui::test_scenario::Self; + + const USER1_ADDRESS: address = @0xA001; + const METADATA: vector = vector[0u8]; + const HELLO: vector = vector[72, 101, 108, 108, 111]; // "Hello" in ASCII. + + #[test] + fun test_chat() { + let scenario = &mut test_scenario::begin(&USER1_ADDRESS); + { + chat::post( + @0xC001, // This should be an application object ID. + HELLO, + METADATA, // Some metadata (it could be empty). + test_scenario::ctx(scenario) + ); + }; + + test_scenario::next_tx(scenario, &USER1_ADDRESS); + { + assert!(test_scenario::can_take_owned(scenario), 0); + let chat = test_scenario::take_owned(scenario); // if can remove, object exists + assert!(chat::text(&chat) == ascii::string(HELLO), 0); + test_scenario::return_owned(scenario, chat); + } + } +} diff --git a/sui_programmability/examples/nfts/tests/CrossChainAirdropTests.move b/sui_programmability/examples/nfts/tests/cross_chain_airdrop_tests.move similarity index 71% rename from sui_programmability/examples/nfts/tests/CrossChainAirdropTests.move rename to sui_programmability/examples/nfts/tests/cross_chain_airdrop_tests.move index 42a7308ba64e1..1b1d39ff89ec5 100644 --- a/sui_programmability/examples/nfts/tests/CrossChainAirdropTests.move +++ b/sui_programmability/examples/nfts/tests/cross_chain_airdrop_tests.move @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 #[test_only] -module NFTs::CrossChainAirdropTests { - use NFTs::CrossChainAirdrop::{Self, CrossChainAirdropOracle, ERC721}; - use Sui::ID::{VersionedID}; - use Sui::TestScenario::{Self, Scenario}; +module nfts::cross_chain_airdrop_tests { + use nfts::cross_chain_airdrop::{Self, CrossChainAirdropOracle, ERC721}; + use sui::id::{VersionedID}; + use sui::test_scenario::{Self, Scenario}; // Error codes @@ -48,20 +48,20 @@ module NFTs::CrossChainAirdropTests { } fun init(): (Scenario, address) { - let scenario = TestScenario::begin(&ORACLE_ADDRESS); + let scenario = test_scenario::begin(&ORACLE_ADDRESS); { - let ctx = TestScenario::ctx(&mut scenario); - CrossChainAirdrop::test_init(ctx); + let ctx = test_scenario::ctx(&mut scenario); + cross_chain_airdrop::test_init(ctx); }; (scenario, ORACLE_ADDRESS) } fun claim_token(scenario: &mut Scenario, oracle_address: &address, token_id: u64) { - TestScenario::next_tx(scenario, oracle_address); + test_scenario::next_tx(scenario, oracle_address); { - let oracle = TestScenario::take_owned(scenario); - let ctx = TestScenario::ctx(scenario); - CrossChainAirdrop::claim( + let oracle = test_scenario::take_owned(scenario); + let ctx = test_scenario::ctx(scenario); + cross_chain_airdrop::claim( &mut oracle, RECIPIENT_ADDRESS, SOURCE_CONTRACT_ADDRESS, @@ -70,13 +70,13 @@ module NFTs::CrossChainAirdropTests { TOKEN_URI, ctx, ); - TestScenario::return_owned(scenario, oracle); + test_scenario::return_owned(scenario, oracle); }; } 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_take_owned(scenario) + test_scenario::next_tx(scenario, owner); + test_scenario::can_take_owned(scenario) } } diff --git a/sui_programmability/examples/nfts/tests/discount_coupon_tests.move b/sui_programmability/examples/nfts/tests/discount_coupon_tests.move new file mode 100644 index 0000000000000..4e3fb07248fae --- /dev/null +++ b/sui_programmability/examples/nfts/tests/discount_coupon_tests.move @@ -0,0 +1,49 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module nfts::discount_coupon_tests { + use nfts::discount_coupon::{Self, DiscountCoupon}; + use sui::coin::{Self, Coin}; + use sui::sui::SUI; + use sui::test_scenario::Self; + use sui::tx_context::TxContext; + + const ISSUER_ADDRESS: address = @0xA001; + const USER1_ADDRESS: address = @0xB001; + + // Error codes. + // const MINT_FAILED: u64 = 0; + // const TRANSFER_FAILED: u64 = 1; + + // Initializes the "state of the world" that mimics what should + // be available in Sui genesis state (e.g., mints and distributes + // coins to users). + fun init(ctx: &mut TxContext) { + let coin = coin::mint_for_testing(100, ctx); + coin::transfer(coin, ISSUER_ADDRESS); + } + + #[test] + fun test_mint_then_transfer() { + let scenario = &mut test_scenario::begin(&ISSUER_ADDRESS); + { + init(test_scenario::ctx(scenario)); + }; + + // Mint and transfer NFT + top up recipient's address. + test_scenario::next_tx(scenario, &ISSUER_ADDRESS); + { + let coin = test_scenario::take_owned>(scenario); + discount_coupon::mint_and_topup(coin, 10, 1648820870, USER1_ADDRESS, test_scenario::ctx(scenario)); + }; + + test_scenario::next_tx(scenario, &USER1_ADDRESS); + { + assert!(test_scenario::can_take_owned(scenario), 0); + let nft_coupon = test_scenario::take_owned(scenario); // if can remove, object exists + assert!(discount_coupon::issuer(&nft_coupon) == ISSUER_ADDRESS, 0); + test_scenario::return_owned(scenario, nft_coupon); + } + } +} diff --git a/sui_programmability/examples/nfts/tests/shared_auction_tests.move b/sui_programmability/examples/nfts/tests/shared_auction_tests.move new file mode 100644 index 0000000000000..5437f57dc8fde --- /dev/null +++ b/sui_programmability/examples/nfts/tests/shared_auction_tests.move @@ -0,0 +1,129 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test_only] +module nfts::shared_auction_tests { + use std::vector; + + use sui::coin::{Self, Coin}; + use sui::sui::SUI; + use sui::id::VersionedID; + use sui::test_scenario::Self; + use sui::tx_context::{Self, TxContext}; + + use nfts::shared_auction; + use nfts::auction_lib::Auction; + + + const COIN_VALUE: u64 = 100; + + // Error codes. + const EWRONG_ITEM_VALUE: u64 = 1; + const EWRONG_COIN_VALUE: u64 = 2; + + // Example of an object type that could be sold at an auction. + struct SomeItemToSell has key, store { + id: VersionedID, + value: u64, + } + + // Initializes the "state of the world" that mimics what should + // be available in Sui genesis state (e.g., mints and distributes + // coins to users). + fun init(ctx: &mut TxContext, bidders: vector
) { + while (!vector::is_empty(&bidders)) { + let bidder = vector::pop_back(&mut bidders); + let coin = coin::mint_for_testing(COIN_VALUE, ctx); + coin::transfer(coin, bidder); + }; + } + + #[test] + fun simple_auction_test() { + let admin = @0xABBA; // needed only to initialize "state of the world" + let owner = @0xACE; + let bidder1 = @0xFACE; + let bidder2 = @0xCAFE; + + + let scenario = &mut test_scenario::begin(&admin); + { + let bidders = vector::empty(); + vector::push_back(&mut bidders, bidder1); + vector::push_back(&mut bidders, bidder2); + init(test_scenario::ctx(scenario), bidders); + }; + + // a transaction by the item owner to put it for auction + test_scenario::next_tx(scenario, &owner); + let ctx = test_scenario::ctx(scenario); + { + let to_sell = SomeItemToSell { + id: tx_context::new_id(ctx), + value: 42, + }; + shared_auction::create_auction(to_sell, ctx); + }; + + // a transaction by the first bidder to put a bid + test_scenario::next_tx(scenario, &bidder1); + { + let coin = test_scenario::take_owned>(scenario); + let auction_wrapper = test_scenario::take_shared>(scenario); + let auction = test_scenario::borrow_mut(&mut auction_wrapper); + + shared_auction::bid(coin, auction, test_scenario::ctx(scenario)); + + test_scenario::return_shared(scenario, auction_wrapper); + }; + + // a transaction by the second bidder to put a bid (a bid will + // fail as it has the same value as that of the first + // bidder's) + test_scenario::next_tx(scenario, &bidder2); + { + let coin = test_scenario::take_owned>(scenario); + let auction_wrapper = test_scenario::take_shared>(scenario); + let auction = test_scenario::borrow_mut(&mut auction_wrapper); + + shared_auction::bid(coin, auction, test_scenario::ctx(scenario)); + + test_scenario::return_shared(scenario, auction_wrapper); + }; + + // a transaction by the second bidder to verify that the funds + // have been returned (as a result of the failed bid). + test_scenario::next_tx(scenario, &bidder2); + { + let coin = test_scenario::take_owned>(scenario); + + assert!(coin::value(&coin) == COIN_VALUE, EWRONG_COIN_VALUE); + + test_scenario::return_owned(scenario, coin); + }; + + // a transaction by the owner to end auction + test_scenario::next_tx(scenario, &owner); + { + let auction_wrapper = test_scenario::take_shared>(scenario); + let auction = test_scenario::borrow_mut(&mut auction_wrapper); + + // pass auction as mutable reference as its a shared + // object that cannot be deleted + shared_auction::end_auction(auction, test_scenario::ctx(scenario)); + + test_scenario::return_shared(scenario, auction_wrapper); + }; + + // a transaction to check if the first bidder won (as the + // second bidder's bid was the same as that of the first one) + test_scenario::next_tx(scenario, &bidder1); + { + let acquired_item = test_scenario::take_owned(scenario); + + assert!(acquired_item.value == 42, EWRONG_ITEM_VALUE); + + test_scenario::return_owned(scenario, acquired_item); + }; + } +} diff --git a/sui_programmability/examples/objects_tutorial/Move.toml b/sui_programmability/examples/objects_tutorial/Move.toml index 7447088d1bfbb..0961e5988465a 100644 --- a/sui_programmability/examples/objects_tutorial/Move.toml +++ b/sui_programmability/examples/objects_tutorial/Move.toml @@ -7,5 +7,4 @@ MoveStdlib = { local = "../../../crates/sui-framework/deps/move-stdlib/" } Sui = { local = "../../../crates/sui-framework/" } [addresses] -Tutorial = "0x0" - +tutorial = "0x0" diff --git a/sui_programmability/examples/objects_tutorial/sources/ColorObject.move b/sui_programmability/examples/objects_tutorial/sources/ColorObject.move deleted file mode 100644 index 8bd12cf20731e..0000000000000 --- a/sui_programmability/examples/objects_tutorial/sources/ColorObject.move +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -module Tutorial::ColorObject { - use Sui::ID::{Self, VersionedID}; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; - - struct ColorObject has key { - id: VersionedID, - red: u8, - green: u8, - blue: u8, - } - - // == Functions covered in Chapter 1 == - - fun new(red: u8, green: u8, blue: u8, ctx: &mut TxContext): ColorObject { - ColorObject { - id: TxContext::new_id(ctx), - red, - green, - blue, - } - } - - public entry fun create(red: u8, green: u8, blue: u8, ctx: &mut TxContext) { - let color_object = new(red, green, blue, ctx); - Transfer::transfer(color_object, TxContext::sender(ctx)) - } - - public fun get_color(self: &ColorObject): (u8, u8, u8) { - (self.red, self.green, self.blue) - } - - // == Functions covered in Chapter 2 == - - /// Copies the values of `from_object` into `into_object`. - public entry fun copy_into(from_object: &ColorObject, into_object: &mut ColorObject) { - into_object.red = from_object.red; - into_object.green = from_object.green; - into_object.blue = from_object.blue; - } - - public entry fun delete(object: ColorObject) { - let ColorObject { id, red: _, green: _, blue: _ } = object; - ID::delete(id); - } - - public entry fun transfer(object: ColorObject, recipient: address) { - Transfer::transfer(object, recipient) - } - - // == Functions covered in Chapter 3 == - - public entry fun freeze_object(object: ColorObject) { - Transfer::freeze_object(object) - } - - public entry fun create_immutable(red: u8, green: u8, blue: u8, ctx: &mut TxContext) { - let color_object = new(red, green, blue, ctx); - Transfer::freeze_object(color_object) - } - - public entry fun update( - object: &mut ColorObject, - red: u8, green: u8, blue: u8, - ) { - object.red = red; - object.green = green; - object.blue = blue; - } -} - -#[test_only] -module Tutorial::ColorObjectTests { - use Sui::TestScenario; - use Tutorial::ColorObject::{Self, ColorObject}; - use Sui::TxContext; - - // == Tests covered in Chapter 1 == - - #[test] - fun test_create() { - let owner = @0x1; - // Create a ColorObject and transfer it to @owner. - let scenario = &mut TestScenario::begin(&owner); - { - let ctx = TestScenario::ctx(scenario); - ColorObject::create(255, 0, 255, ctx); - }; - // Check that @not_owner does not own the just-created ColorObject. - let not_owner = @0x2; - TestScenario::next_tx(scenario, ¬_owner); - { - assert!(!TestScenario::can_take_owned(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::take_owned(scenario); - let (red, green, blue) = ColorObject::get_color(&object); - assert!(red == 255 && green == 0 && blue == 255, 0); - TestScenario::return_owned(scenario, object); - }; - } - - // == Tests covered in Chapter 2 == - - #[test] - fun test_copy_into() { - let owner = @0x1; - let scenario = &mut TestScenario::begin(&owner); - // Create two ColorObjects owned by `owner`, and obtain their IDs. - let (id1, id2) = { - let ctx = TestScenario::ctx(scenario); - ColorObject::create(255, 255, 255, ctx); - let id1 = TxContext::last_created_object_id(ctx); - ColorObject::create(0, 0, 0, ctx); - let id2 = TxContext::last_created_object_id(ctx); - (id1, id2) - }; - TestScenario::next_tx(scenario, &owner); - { - let obj1 = TestScenario::take_owned_by_id(scenario, id1); - let obj2 = TestScenario::take_owned_by_id(scenario, id2); - let (red, green, blue) = ColorObject::get_color(&obj1); - assert!(red == 255 && green == 255 && blue == 255, 0); - - ColorObject::copy_into(&obj2, &mut obj1); - TestScenario::return_owned(scenario, obj1); - TestScenario::return_owned(scenario, obj2); - }; - TestScenario::next_tx(scenario, &owner); - { - let obj1 = TestScenario::take_owned_by_id(scenario, id1); - let (red, green, blue) = ColorObject::get_color(&obj1); - assert!(red == 0 && green == 0 && blue == 0, 0); - TestScenario::return_owned(scenario, obj1); - } - } - - #[test] - fun test_delete() { - let owner = @0x1; - // Create a ColorObject and transfer it to @owner. - let scenario = &mut TestScenario::begin(&owner); - { - let ctx = TestScenario::ctx(scenario); - ColorObject::create(255, 0, 255, ctx); - }; - // Delete the ColorObject we just created. - TestScenario::next_tx(scenario, &owner); - { - let object = TestScenario::take_owned(scenario); - ColorObject::delete(object); - }; - // Verify that the object was indeed deleted. - TestScenario::next_tx(scenario, &owner); - { - assert!(!TestScenario::can_take_owned(scenario), 0); - } - } - - #[test] - fun test_transfer() { - let owner = @0x1; - // Create a ColorObject and transfer it to @owner. - let scenario = &mut TestScenario::begin(&owner); - { - let ctx = TestScenario::ctx(scenario); - ColorObject::create(255, 0, 255, ctx); - }; - // Transfer the object to recipient. - let recipient = @0x2; - TestScenario::next_tx(scenario, &owner); - { - let object = TestScenario::take_owned(scenario); - ColorObject::transfer(object, recipient); - }; - // Check that owner no longer owns the object. - TestScenario::next_tx(scenario, &owner); - { - assert!(!TestScenario::can_take_owned(scenario), 0); - }; - // Check that recipient now owns the object. - TestScenario::next_tx(scenario, &recipient); - { - assert!(TestScenario::can_take_owned(scenario), 0); - }; - } - - // == Tests covered in Chapter 3 == - - #[test] - fun test_immutable() { - let sender1 = @0x1; - let scenario = &mut TestScenario::begin(&sender1); - { - let ctx = TestScenario::ctx(scenario); - ColorObject::create_immutable(255, 0, 255, ctx); - }; - TestScenario::next_tx(scenario, &sender1); - { - // take_owned does not work for immutable objects. - assert!(!TestScenario::can_take_owned(scenario), 0); - }; - // Any sender can work. - let sender2 = @0x2; - TestScenario::next_tx(scenario, &sender2); - { - let object_wrapper = TestScenario::take_immutable(scenario); - let object = TestScenario::borrow(&object_wrapper); - let (red, green, blue) = ColorObject::get_color(object); - assert!(red == 255 && green == 0 && blue == 255, 0); - TestScenario::return_immutable(scenario, object_wrapper); - }; - } -} diff --git a/sui_programmability/examples/objects_tutorial/sources/color_object.move b/sui_programmability/examples/objects_tutorial/sources/color_object.move new file mode 100644 index 0000000000000..50a0137bbe666 --- /dev/null +++ b/sui_programmability/examples/objects_tutorial/sources/color_object.move @@ -0,0 +1,220 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +module tutorial::color_object { + use sui::id::{Self, VersionedID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + + struct ColorObject has key { + id: VersionedID, + red: u8, + green: u8, + blue: u8, + } + + // == Functions covered in Chapter 1 == + + fun new(red: u8, green: u8, blue: u8, ctx: &mut TxContext): ColorObject { + ColorObject { + id: tx_context::new_id(ctx), + red, + green, + blue, + } + } + + public entry fun create(red: u8, green: u8, blue: u8, ctx: &mut TxContext) { + let color_object = new(red, green, blue, ctx); + transfer::transfer(color_object, tx_context::sender(ctx)) + } + + public fun get_color(self: &ColorObject): (u8, u8, u8) { + (self.red, self.green, self.blue) + } + + // == Functions covered in Chapter 2 == + + /// Copies the values of `from_object` into `into_object`. + public entry fun copy_into(from_object: &ColorObject, into_object: &mut ColorObject) { + into_object.red = from_object.red; + into_object.green = from_object.green; + into_object.blue = from_object.blue; + } + + public entry fun delete(object: ColorObject) { + let ColorObject { id, red: _, green: _, blue: _ } = object; + id::delete(id); + } + + public entry fun transfer(object: ColorObject, recipient: address) { + transfer::transfer(object, recipient) + } + + // == Functions covered in Chapter 3 == + + public entry fun freeze_object(object: ColorObject) { + transfer::freeze_object(object) + } + + public entry fun create_immutable(red: u8, green: u8, blue: u8, ctx: &mut TxContext) { + let color_object = new(red, green, blue, ctx); + transfer::freeze_object(color_object) + } + + public entry fun update( + object: &mut ColorObject, + red: u8, green: u8, blue: u8, + ) { + object.red = red; + object.green = green; + object.blue = blue; + } +} + +#[test_only] +module tutorial::color_objectTests { + use sui::test_scenario; + use tutorial::color_object::{Self, ColorObject}; + use sui::tx_context; + + // == Tests covered in Chapter 1 == + + #[test] + fun test_create() { + let owner = @0x1; + // Create a ColorObject and transfer it to @owner. + let scenario = &mut test_scenario::begin(&owner); + { + let ctx = test_scenario::ctx(scenario); + color_object::create(255, 0, 255, ctx); + }; + // Check that @not_owner does not own the just-created ColorObject. + let not_owner = @0x2; + test_scenario::next_tx(scenario, ¬_owner); + { + assert!(!test_scenario::can_take_owned(scenario), 0); + }; + // Check that @owner indeed owns the just-created ColorObject. + // Also checks the value fields of the object. + test_scenario::next_tx(scenario, &owner); + { + let object = test_scenario::take_owned(scenario); + let (red, green, blue) = color_object::get_color(&object); + assert!(red == 255 && green == 0 && blue == 255, 0); + test_scenario::return_owned(scenario, object); + }; + } + + // == Tests covered in Chapter 2 == + + #[test] + fun test_copy_into() { + let owner = @0x1; + let scenario = &mut test_scenario::begin(&owner); + // Create two ColorObjects owned by `owner`, and obtain their IDs. + let (id1, id2) = { + let ctx = test_scenario::ctx(scenario); + color_object::create(255, 255, 255, ctx); + let id1 = tx_context::last_created_object_id(ctx); + color_object::create(0, 0, 0, ctx); + let id2 = tx_context::last_created_object_id(ctx); + (id1, id2) + }; + test_scenario::next_tx(scenario, &owner); + { + let obj1 = test_scenario::take_owned_by_id(scenario, id1); + let obj2 = test_scenario::take_owned_by_id(scenario, id2); + let (red, green, blue) = color_object::get_color(&obj1); + assert!(red == 255 && green == 255 && blue == 255, 0); + + color_object::copy_into(&obj2, &mut obj1); + test_scenario::return_owned(scenario, obj1); + test_scenario::return_owned(scenario, obj2); + }; + test_scenario::next_tx(scenario, &owner); + { + let obj1 = test_scenario::take_owned_by_id(scenario, id1); + let (red, green, blue) = color_object::get_color(&obj1); + assert!(red == 0 && green == 0 && blue == 0, 0); + test_scenario::return_owned(scenario, obj1); + } + } + + #[test] + fun test_delete() { + let owner = @0x1; + // Create a ColorObject and transfer it to @owner. + let scenario = &mut test_scenario::begin(&owner); + { + let ctx = test_scenario::ctx(scenario); + color_object::create(255, 0, 255, ctx); + }; + // Delete the ColorObject we just created. + test_scenario::next_tx(scenario, &owner); + { + let object = test_scenario::take_owned(scenario); + color_object::delete(object); + }; + // Verify that the object was indeed deleted. + test_scenario::next_tx(scenario, &owner); + { + assert!(!test_scenario::can_take_owned(scenario), 0); + } + } + + #[test] + fun test_transfer() { + let owner = @0x1; + // Create a ColorObject and transfer it to @owner. + let scenario = &mut test_scenario::begin(&owner); + { + let ctx = test_scenario::ctx(scenario); + color_object::create(255, 0, 255, ctx); + }; + // Transfer the object to recipient. + let recipient = @0x2; + test_scenario::next_tx(scenario, &owner); + { + let object = test_scenario::take_owned(scenario); + color_object::transfer(object, recipient); + }; + // Check that owner no longer owns the object. + test_scenario::next_tx(scenario, &owner); + { + assert!(!test_scenario::can_take_owned(scenario), 0); + }; + // Check that recipient now owns the object. + test_scenario::next_tx(scenario, &recipient); + { + assert!(test_scenario::can_take_owned(scenario), 0); + }; + } + + // == Tests covered in Chapter 3 == + + #[test] + fun test_immutable() { + let sender1 = @0x1; + let scenario = &mut test_scenario::begin(&sender1); + { + let ctx = test_scenario::ctx(scenario); + color_object::create_immutable(255, 0, 255, ctx); + }; + test_scenario::next_tx(scenario, &sender1); + { + // take_owned does not work for immutable objects. + assert!(!test_scenario::can_take_owned(scenario), 0); + }; + // Any sender can work. + let sender2 = @0x2; + test_scenario::next_tx(scenario, &sender2); + { + let object_wrapper = test_scenario::take_immutable(scenario); + let object = test_scenario::borrow(&object_wrapper); + let (red, green, blue) = color_object::get_color(object); + assert!(red == 255 && green == 0 && blue == 255, 0); + test_scenario::return_immutable(scenario, object_wrapper); + }; + } +} diff --git a/sui_programmability/examples/objects_tutorial/sources/SimpleWarrior.move b/sui_programmability/examples/objects_tutorial/sources/simple_warrior.move similarity index 71% rename from sui_programmability/examples/objects_tutorial/sources/SimpleWarrior.move rename to sui_programmability/examples/objects_tutorial/sources/simple_warrior.move index 114cffe432f28..aac9bdc896e1d 100644 --- a/sui_programmability/examples/objects_tutorial/sources/SimpleWarrior.move +++ b/sui_programmability/examples/objects_tutorial/sources/simple_warrior.move @@ -1,12 +1,12 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Tutorial::SimpleWarrior { +module tutorial::simple_warrior { use std::option::{Self, Option}; - use Sui::ID::VersionedID; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; + use sui::id::VersionedID; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; struct Sword has key, store { id: VersionedID, @@ -26,33 +26,33 @@ module Tutorial::SimpleWarrior { public entry fun create_sword(strength: u8, ctx: &mut TxContext) { let sword = Sword { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), strength, }; - Transfer::transfer(sword, TxContext::sender(ctx)) + transfer::transfer(sword, tx_context::sender(ctx)) } public entry fun create_shield(armor: u8, ctx: &mut TxContext) { let shield = Shield { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), armor, }; - Transfer::transfer(shield, TxContext::sender(ctx)) + transfer::transfer(shield, tx_context::sender(ctx)) } public entry fun create_warrior(ctx: &mut TxContext) { let warrior = SimpleWarrior { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), sword: option::none(), shield: option::none(), }; - Transfer::transfer(warrior, TxContext::sender(ctx)) + transfer::transfer(warrior, tx_context::sender(ctx)) } public entry fun equip_sword(warrior: &mut SimpleWarrior, sword: Sword, ctx: &mut TxContext) { if (option::is_some(&warrior.sword)) { let old_sword = option::extract(&mut warrior.sword); - Transfer::transfer(old_sword, TxContext::sender(ctx)); + transfer::transfer(old_sword, tx_context::sender(ctx)); }; option::fill(&mut warrior.sword, sword); } @@ -60,7 +60,7 @@ module Tutorial::SimpleWarrior { public entry fun equip_shield(warrior: &mut SimpleWarrior, shield: Shield, ctx: &mut TxContext) { if (option::is_some(&warrior.shield)) { let old_shield = option::extract(&mut warrior.shield); - Transfer::transfer(old_shield, TxContext::sender(ctx)); + transfer::transfer(old_shield, tx_context::sender(ctx)); }; option::fill(&mut warrior.shield, shield); } diff --git a/sui_programmability/examples/objects_tutorial/sources/TrustedSwap.move b/sui_programmability/examples/objects_tutorial/sources/trusted_swap.move similarity index 68% rename from sui_programmability/examples/objects_tutorial/sources/TrustedSwap.move rename to sui_programmability/examples/objects_tutorial/sources/trusted_swap.move index e1c375ff93cf0..7c00b98487afb 100644 --- a/sui_programmability/examples/objects_tutorial/sources/TrustedSwap.move +++ b/sui_programmability/examples/objects_tutorial/sources/trusted_swap.move @@ -1,13 +1,13 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -module Tutorial::TrustedSwap { - use Sui::Balance::{Self, Balance}; - use Sui::Coin::{Self, Coin}; - use Sui::ID::{Self, VersionedID}; - use Sui::SUI::SUI; - use Sui::Transfer; - use Sui::TxContext::{Self, TxContext}; +module tutorial::trusted_swap { + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin}; + use sui::id::{Self, VersionedID}; + use sui::sui::SUI; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; const MIN_FEE: u64 = 1000; @@ -26,28 +26,28 @@ module Tutorial::TrustedSwap { public entry fun create_object(scarcity: u8, style: u8, ctx: &mut TxContext) { let object = Object { - id: TxContext::new_id(ctx), + id: tx_context::new_id(ctx), scarcity, style, }; - Transfer::transfer(object, TxContext::sender(ctx)) + transfer::transfer(object, tx_context::sender(ctx)) } public entry fun transfer_object(object: Object, ctx: &mut TxContext) { - Transfer::transfer(object, TxContext::sender(ctx)) + transfer::transfer(object, tx_context::sender(ctx)) } /// Anyone owns an `Object` can request swapping their object. This object /// will be wrapped into `ObjectWrapper` and sent to `service_address`. public entry fun request_swap(object: Object, fee: Coin, service_address: address, ctx: &mut TxContext) { - assert!(Coin::value(&fee) >= MIN_FEE, 0); + assert!(coin::value(&fee) >= MIN_FEE, 0); let wrapper = ObjectWrapper { - id: TxContext::new_id(ctx), - original_owner: TxContext::sender(ctx), + id: tx_context::new_id(ctx), + original_owner: tx_context::sender(ctx), to_swap: object, - fee: Coin::into_balance(fee), + fee: coin::into_balance(fee), }; - Transfer::transfer(wrapper, service_address); + transfer::transfer(wrapper, service_address); } /// When the admin has two swap requests with objects that are trade-able, @@ -73,16 +73,16 @@ module Tutorial::TrustedSwap { } = wrapper2; // Perform the swap. - Transfer::transfer(object1, original_owner2); - Transfer::transfer(object2, original_owner1); + transfer::transfer(object1, original_owner2); + transfer::transfer(object2, original_owner1); // Service provider takes the fee. - let service_address = TxContext::sender(ctx); - Balance::join(&mut fee1, fee2); - Transfer::transfer(Coin::from_balance(fee1, ctx), service_address); + let service_address = tx_context::sender(ctx); + balance::join(&mut fee1, fee2); + transfer::transfer(coin::from_balance(fee1, ctx), service_address); // Effectively delete the wrapper objects. - ID::delete(id1); - ID::delete(id2); + id::delete(id1); + id::delete(id2); } } diff --git a/sui_programmability/examples/regulated_coin/Move.toml b/sui_programmability/examples/regulated_coin/Move.toml index 53c79fcf9f389..d4bc78323f967 100644 --- a/sui_programmability/examples/regulated_coin/Move.toml +++ b/sui_programmability/examples/regulated_coin/Move.toml @@ -3,8 +3,9 @@ name = "RegulatedCoin" version = "0.0.1" [dependencies] -Sui = { local = "../../framework" } +MoveStdlib = { local = "../../../crates/sui-framework/deps/move-stdlib/" } +Sui = { local = "../../../crates/sui-framework/" } [addresses] -RC = "0x0" -ABC = "0x0" +rc = "0x0" +abc = "0x0" diff --git a/sui_programmability/examples/regulated_coin/sources/RegulatedCoin.move b/sui_programmability/examples/regulated_coin/sources/regulated_coin.move similarity index 63% rename from sui_programmability/examples/regulated_coin/sources/RegulatedCoin.move rename to sui_programmability/examples/regulated_coin/sources/regulated_coin.move index e1436e5597cff..ec7963e7a5def 100644 --- a/sui_programmability/examples/regulated_coin/sources/RegulatedCoin.move +++ b/sui_programmability/examples/regulated_coin/sources/regulated_coin.move @@ -9,10 +9,10 @@ /// `borrow_mut()` and `zero()`. /// /// Each of the methods of this module requires a Witness struct to be sent. -module RC::RegulatedCoin { - use Sui::Balance::{Self, Balance}; - use Sui::TxContext::{Self, TxContext}; - use Sui::ID::VersionedID; +module rc::regulated_coin { + use sui::balance::{Self, Balance}; + use sui::tx_context::{Self, TxContext}; + use sui::id::VersionedID; /// The RegulatedCoin struct; holds a common `Balance` which is compatible /// with all the other Coins and methods, as well as the `creator` field, which @@ -25,7 +25,7 @@ module RC::RegulatedCoin { /// Get the `RegulatedCoin.balance.value` field; public fun value(c: &RegulatedCoin): u64 { - Balance::value(&c.balance) + balance::value(&c.balance) } /// Get the `RegulatedCoin.creator` field; @@ -47,20 +47,20 @@ module RC::RegulatedCoin { /// Author of the currency can restrict who is allowed to create new balances; public fun zero(_: T, creator: address, ctx: &mut TxContext): RegulatedCoin { - RegulatedCoin { id: TxContext::new_id(ctx), balance: Balance::zero(), creator } + RegulatedCoin { id: tx_context::new_id(ctx), balance: balance::zero(), creator } } /// Build a transferable `RegulatedCoin` from a `Balance`; public fun from_balance( _: T, balance: Balance, creator: address, ctx: &mut TxContext ): RegulatedCoin { - RegulatedCoin { id: TxContext::new_id(ctx), balance, creator } + RegulatedCoin { id: tx_context::new_id(ctx), balance, creator } } /// Destroy `RegulatedCoin` and return its `Balance`; public fun into_balance(_: T, coin: RegulatedCoin): Balance { let RegulatedCoin { balance, creator: _, id } = coin; - Sui::ID::delete(id); + sui::id::delete(id); balance } @@ -68,18 +68,18 @@ module RC::RegulatedCoin { /// Join Balances of a `RegulatedCoin` c1 and `RegulatedCoin` c2. public fun join(witness: T, c1: &mut RegulatedCoin, c2: RegulatedCoin) { - Balance::join(&mut c1.balance, into_balance(witness, c2)) + balance::join(&mut c1.balance, into_balance(witness, c2)) } /// Subtract `RegulatedCoin` with `value` from `RegulatedCoin`. /// /// This method does not provide any checks by default and can possibly lead to mocking - /// behavior of `RegulatedCoin::zero()` when a value is 0. So in case empty balances + /// behavior of `Regulatedcoin::zero()` when a value is 0. So in case empty balances /// should not be allowed, this method should be additionally protected against zero value. public fun split( witness: T, c1: &mut RegulatedCoin, creator: address, value: u64, ctx: &mut TxContext ): RegulatedCoin { - let balance = Balance::split(&mut c1.balance, value); + let balance = balance::split(&mut c1.balance, value); from_balance(witness, balance, creator, ctx) } } @@ -89,13 +89,13 @@ module RC::RegulatedCoin { /// - is managed account creation (only admins can create a new balance) /// - has a denylist for addresses managed by the coin admins /// - has restricted transfers which can not be taken by anyone except the recipient -module ABC::ABC { - use RC::RegulatedCoin::{Self as RCoin, RegulatedCoin as RCoin}; - use Sui::TxContext::{Self, TxContext}; - use Sui::Balance::{Self, Balance}; - use Sui::Coin::{Self, Coin, TreasuryCap}; - use Sui::ID::{Self, VersionedID}; - use Sui::Transfer; +module abc::abc { + use rc::regulated_coin::{Self as rcoin, RegulatedCoin as RCoin}; + use sui::tx_context::{Self, TxContext}; + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin, TreasuryCap}; + use sui::id::{Self, VersionedID}; + use sui::transfer; use std::vector; /// The ticker of ABC regulated token @@ -126,14 +126,14 @@ module ABC::ABC { /// /// Also creates a shared Registry which holds banned addresses. fun init(ctx: &mut TxContext) { - let treasury_cap = Coin::create_currency(ABC {}, ctx); - let sender = TxContext::sender(ctx); + let treasury_cap = coin::create_currency(ABC {}, ctx); + let sender = tx_context::sender(ctx); - Transfer::transfer(zero(sender, ctx), sender); - Transfer::transfer(treasury_cap, sender); + transfer::transfer(zero(sender, ctx), sender); + transfer::transfer(treasury_cap, sender); - Transfer::share_object(Registry { - id: TxContext::new_id(ctx), + transfer::share_object(Registry { + id: tx_context::new_id(ctx), banned: vector::empty(), swapped_amount: 0, }); @@ -156,19 +156,19 @@ module ABC::ABC { /// Create an empty `RCoin` instance for account `for`. TreasuryCap is passed for /// authentification purposes - only admin can create new accounts. public entry fun create(_: &TreasuryCap, for: address, ctx: &mut TxContext) { - Transfer::transfer(zero(for, ctx), for) + transfer::transfer(zero(for, ctx), for) } /// Mint more ABC. Requires TreasuryCap for authorization, so can only be done by admins. public entry fun mint(treasury: &mut TreasuryCap, owned: &mut RCoin, value: u64, _: &mut TxContext) { - Balance::join(borrow_mut(owned), Coin::mint_balance(value, treasury)) + balance::join(borrow_mut(owned), coin::mint_balance(value, treasury)) } /// Burn `value` amount of `RCoin`. Requires TreasuryCap for authorization, so can only be done by admins. /// /// TODO: Make TreasuryCap a part of Balance module instead of Coin. public entry fun burn(treasury: &mut TreasuryCap, owned: &mut RCoin, value: u64, ctx: &mut TxContext) { - Coin::burn(Coin::withdraw(borrow_mut(owned), value, ctx), treasury); + coin::burn(coin::withdraw(borrow_mut(owned), value, ctx), treasury); } /// Ban some address and forbid making any transactions from or to this address. @@ -184,16 +184,16 @@ module ABC::ABC { /// Fails if sender is not an creator of the `RegulatedCoin` or if any of the parties is in /// the ban list in Registry. public entry fun transfer(r: &Registry, coin: &mut RCoin, value: u64, to: address, ctx: &mut TxContext) { - let sender = TxContext::sender(ctx); + let sender = tx_context::sender(ctx); - assert!(RCoin::creator(coin) == sender, ENotOwner); + assert!(rcoin::creator(coin) == sender, ENotOwner); assert!(vector::contains(&r.banned, &to) == false, EAddressBanned); assert!(vector::contains(&r.banned, &sender) == false, EAddressBanned); - Transfer::transfer(Transfer { + transfer::transfer(Transfer { to, - id: TxContext::new_id(ctx), - balance: Balance::split(borrow_mut(coin), value), + id: tx_context::new_id(ctx), + balance: balance::split(borrow_mut(coin), value), }, to) } @@ -205,11 +205,11 @@ module ABC::ABC { public entry fun accept_transfer(r: &Registry, coin: &mut RCoin, transfer: Transfer, _: &mut TxContext) { let Transfer { id, balance, to } = transfer; - assert!(RCoin::creator(coin) == to, ENotOwner); + assert!(rcoin::creator(coin) == to, ENotOwner); assert!(vector::contains(&r.banned, &to) == false, EAddressBanned); - Balance::join(borrow_mut(coin), balance); - ID::delete(id) + balance::join(borrow_mut(coin), balance); + id::delete(id) } // === Public: Swap RegulatedCoin <-> Coin === @@ -221,15 +221,15 @@ module ABC::ABC { /// 1. `RegulatedCoin.creator` was banned; /// 2. `RegulatedCoin` is not owned by the tx sender; public entry fun take(r: &mut Registry, coin: &mut RCoin, value: u64, ctx: &mut TxContext) { - let sender = TxContext::sender(ctx); + let sender = tx_context::sender(ctx); - assert!(RCoin::creator(coin) == sender, ENotOwner); + assert!(rcoin::creator(coin) == sender, ENotOwner); assert!(vector::contains(&r.banned, &sender) == false, EAddressBanned); // Update swapped amount for Registry to keep track of non-regulated amounts. r.swapped_amount = r.swapped_amount + value; - Transfer::transfer(Coin::withdraw(borrow_mut(coin), value, ctx), TxContext::sender(ctx)); + transfer::transfer(coin::withdraw(borrow_mut(coin), value, ctx), tx_context::sender(ctx)); } /// Take `Coin` and put to the `RegulatedCoin`'s balance. @@ -238,27 +238,27 @@ module ABC::ABC { /// 1. `RegulatedCoin.creator` was banned; /// 2. `RegulatedCoin` is not owned by the tx sender; public entry fun put_back(r: &mut Registry, rc_coin: &mut RCoin, coin: Coin, ctx: &mut TxContext) { - let balance = Coin::into_balance(coin); - let sender = TxContext::sender(ctx); + let balance = coin::into_balance(coin); + let sender = tx_context::sender(ctx); - assert!(RCoin::creator(rc_coin) == sender, ENotOwner); + assert!(rcoin::creator(rc_coin) == sender, ENotOwner); assert!(vector::contains(&r.banned, &sender) == false, EAddressBanned); // Update swapped amount as in `swap_regulated`. - r.swapped_amount = r.swapped_amount - Balance::value(&balance); + r.swapped_amount = r.swapped_amount - balance::value(&balance); - Balance::join(borrow_mut(rc_coin), balance); + balance::join(borrow_mut(rc_coin), balance); } // === Private implementations accessors and type morphing === - fun borrow(coin: &RCoin): &Balance { RCoin::borrow(ABC {}, coin) } - fun borrow_mut(coin: &mut RCoin): &mut Balance { RCoin::borrow_mut(ABC {}, coin) } - fun zero(creator: address, ctx: &mut TxContext): RCoin { RCoin::zero(ABC {}, creator, ctx) } + fun borrow(coin: &RCoin): &Balance { rcoin::borrow(ABC {}, coin) } + fun borrow_mut(coin: &mut RCoin): &mut Balance { rcoin::borrow_mut(ABC {}, coin) } + fun zero(creator: address, ctx: &mut TxContext): RCoin { rcoin::zero(ABC {}, creator, ctx) } - fun into_balance(coin: RCoin): Balance { RCoin::into_balance(ABC {}, coin) } + fun into_balance(coin: RCoin): Balance { rcoin::into_balance(ABC {}, coin) } fun from_balance(balance: Balance, creator: address, ctx: &mut TxContext): RCoin { - RCoin::from_balance(ABC {}, balance, creator, ctx) + rcoin::from_balance(ABC {}, balance, creator, ctx) } // === Testing utilities === @@ -282,12 +282,12 @@ module ABC::ABC { /// | +-- test_different_account_fail /// | +-- test_not_owned_balance_fail /// ``` -module ABC::Tests { - use ABC::ABC::{Self, ABC, Registry}; - use RC::RegulatedCoin::{Self as RCoin, RegulatedCoin as RCoin}; +module abc::tests { + use abc::abc::{Self, ABC, Registry}; + use rc::regulated_coin::{Self as rcoin, RegulatedCoin as RCoin}; - use Sui::Coin::{Coin, TreasuryCap}; - use Sui::TestScenario::{Self, Scenario, next_tx, ctx}; + use sui::coin::{Coin, TreasuryCap}; + use sui::test_scenario::{Self, Scenario, next_tx, ctx}; // === Test handlers; this trick helps reusing scenarios == @@ -319,7 +319,7 @@ module ABC::Tests { // === Helpers and basic test organization === - fun scenario(): Scenario { TestScenario::begin(&@ABC) } + fun scenario(): Scenario { test_scenario::begin(&@ABC) } fun people(): (address, address, address) { (@0xABC, @0xE05, @0xFACE) } // Admin creates a regulated coin ABC and mints 1,000,000 of it. @@ -327,19 +327,19 @@ module ABC::Tests { let (admin, _, _) = people(); next_tx(test, &admin); { - ABC::init_for_testing(ctx(test)) + abc::init_for_testing(ctx(test)) }; next_tx(test, &admin); { - let cap = TestScenario::take_owned>(test); - let coin = TestScenario::take_owned>(test); + let cap = test_scenario::take_owned>(test); + let coin = test_scenario::take_owned>(test); - ABC::mint(&mut cap, &mut coin, 1000000, ctx(test)); + abc::mint(&mut cap, &mut coin, 1000000, ctx(test)); - assert!(RCoin::value(&coin) == 1000000, 0); + assert!(rcoin::value(&coin) == 1000000, 0); - TestScenario::return_owned(test, cap); - TestScenario::return_owned(test, coin); + test_scenario::return_owned(test, cap); + test_scenario::return_owned(test, coin); } } @@ -350,20 +350,20 @@ module ABC::Tests { test_minting_(test); next_tx(test, &admin); { - let cap = TestScenario::take_owned>(test); + let cap = test_scenario::take_owned>(test); - ABC::create(&cap, user1, ctx(test)); + abc::create(&cap, user1, ctx(test)); - TestScenario::return_owned(test, cap); + test_scenario::return_owned(test, cap); }; next_tx(test, &user1); { - let coin = TestScenario::take_owned>(test); + let coin = test_scenario::take_owned>(test); - assert!(RCoin::creator(&coin) == user1, 1); - assert!(RCoin::value(&coin) == 0, 2); + assert!(rcoin::creator(&coin) == user1, 1); + assert!(rcoin::value(&coin) == 0, 2); - TestScenario::return_owned(test, coin); + test_scenario::return_owned(test, coin); }; } @@ -375,28 +375,28 @@ module ABC::Tests { test_creation_(test); next_tx(test, &admin); { - let coin = TestScenario::take_owned>(test); - let reg = TestScenario::take_shared(test); - let reg_ref = TestScenario::borrow_mut(&mut reg); + let coin = test_scenario::take_owned>(test); + let reg = test_scenario::take_shared(test); + let reg_ref = test_scenario::borrow_mut(&mut reg); - ABC::transfer(reg_ref, &mut coin, 500000, user1, ctx(test)); + abc::transfer(reg_ref, &mut coin, 500000, user1, ctx(test)); - TestScenario::return_shared(test, reg); - TestScenario::return_owned(test, coin); + test_scenario::return_shared(test, reg); + test_scenario::return_owned(test, coin); }; next_tx(test, &user1); { - let coin = TestScenario::take_owned>(test); - let transfer = TestScenario::take_owned(test); - let reg = TestScenario::take_shared(test); - let reg_ref = TestScenario::borrow_mut(&mut reg); + let coin = test_scenario::take_owned>(test); + let transfer = test_scenario::take_owned(test); + let reg = test_scenario::take_shared(test); + let reg_ref = test_scenario::borrow_mut(&mut reg); - ABC::accept_transfer(reg_ref, &mut coin, transfer, ctx(test)); + abc::accept_transfer(reg_ref, &mut coin, transfer, ctx(test)); - assert!(RCoin::value(&coin) == 500000, 3); + assert!(rcoin::value(&coin) == 500000, 3); - TestScenario::return_shared(test, reg); - TestScenario::return_owned(test, coin); + test_scenario::return_shared(test, reg); + test_scenario::return_owned(test, coin); }; } @@ -407,15 +407,15 @@ module ABC::Tests { test_transfer_(test); next_tx(test, &admin); { - let coin = TestScenario::take_owned>(test); - let treasury_cap = TestScenario::take_owned>(test); + let coin = test_scenario::take_owned>(test); + let treasury_cap = test_scenario::take_owned>(test); - ABC::burn(&mut treasury_cap, &mut coin, 100000, ctx(test)); + abc::burn(&mut treasury_cap, &mut coin, 100000, ctx(test)); - assert!(RCoin::value(&coin) == 400000, 4); + assert!(rcoin::value(&coin) == 400000, 4); - TestScenario::return_owned(test, treasury_cap); - TestScenario::return_owned(test, coin); + test_scenario::return_owned(test, treasury_cap); + test_scenario::return_owned(test, coin); }; } @@ -427,22 +427,22 @@ module ABC::Tests { test_transfer_(test); next_tx(test, &user1); { - let coin = TestScenario::take_owned>(test); - let reg = TestScenario::take_shared(test); - let reg_ref = TestScenario::borrow_mut(&mut reg); + let coin = test_scenario::take_owned>(test); + let reg = test_scenario::take_shared(test); + let reg_ref = test_scenario::borrow_mut(&mut reg); - ABC::take(reg_ref, &mut coin, 100000, ctx(test)); + abc::take(reg_ref, &mut coin, 100000, ctx(test)); - assert!(ABC::swapped_amount(reg_ref) == 100000, 5); - assert!(RCoin::value(&coin) == 400000, 5); + assert!(abc::swapped_amount(reg_ref) == 100000, 5); + assert!(rcoin::value(&coin) == 400000, 5); - TestScenario::return_shared(test, reg); - TestScenario::return_owned(test, coin); + test_scenario::return_shared(test, reg); + test_scenario::return_owned(test, coin); }; next_tx(test, &user1); { - let coin = TestScenario::take_owned>(test); - Sui::Transfer::transfer(coin, user2); + let coin = test_scenario::take_owned>(test); + Sui::transfer::transfer(coin, user2); }; } @@ -454,20 +454,20 @@ module ABC::Tests { test_take_(test); next_tx(test, &user2); { - let coin = TestScenario::take_owned>(test); - Sui::Transfer::transfer(coin, admin); + let coin = test_scenario::take_owned>(test); + Sui::transfer::transfer(coin, admin); }; next_tx(test, &admin); { - let coin = TestScenario::take_owned>(test); - let reg_coin = TestScenario::take_owned>(test); - let reg = TestScenario::take_shared(test); - let reg_ref = TestScenario::borrow_mut(&mut reg); + let coin = test_scenario::take_owned>(test); + let reg_coin = test_scenario::take_owned>(test); + let reg = test_scenario::take_shared(test); + let reg_ref = test_scenario::borrow_mut(&mut reg); - ABC::put_back(reg_ref, &mut reg_coin, coin, ctx(test)); + abc::put_back(reg_ref, &mut reg_coin, coin, ctx(test)); - TestScenario::return_owned(test, reg_coin); - TestScenario::return_shared(test, reg); + test_scenario::return_owned(test, reg_coin); + test_scenario::return_shared(test, reg); } } @@ -478,14 +478,14 @@ module ABC::Tests { test_transfer_(test); next_tx(test, &admin); { - let cap = TestScenario::take_owned>(test); - let reg = TestScenario::take_shared(test); - let reg_ref = TestScenario::borrow_mut(&mut reg); + let cap = test_scenario::take_owned>(test); + let reg = test_scenario::take_shared(test); + let reg_ref = test_scenario::borrow_mut(&mut reg); - ABC::ban(&cap, reg_ref, user1, ctx(test)); + abc::ban(&cap, reg_ref, user1, ctx(test)); - TestScenario::return_shared(test, reg); - TestScenario::return_owned(test, cap); + test_scenario::return_shared(test, reg); + test_scenario::return_owned(test, cap); }; } @@ -496,14 +496,14 @@ module ABC::Tests { test_ban_(test); next_tx(test, &user1); { - let coin = TestScenario::take_owned>(test); - let reg = TestScenario::take_shared(test); - let reg_ref = TestScenario::borrow_mut(&mut reg); + let coin = test_scenario::take_owned>(test); + let reg = test_scenario::take_shared(test); + let reg_ref = test_scenario::borrow_mut(&mut reg); - ABC::transfer(reg_ref, &mut coin, 250000, user2, ctx(test)); + abc::transfer(reg_ref, &mut coin, 250000, user2, ctx(test)); - TestScenario::return_shared(test, reg); - TestScenario::return_owned(test, coin); + test_scenario::return_shared(test, reg); + test_scenario::return_owned(test, coin); }; } @@ -514,14 +514,14 @@ module ABC::Tests { test_ban_(test); next_tx(test, &admin); { - let coin = TestScenario::take_owned>(test); - let reg = TestScenario::take_shared(test); - let reg_ref = TestScenario::borrow_mut(&mut reg); + let coin = test_scenario::take_owned>(test); + let reg = test_scenario::take_shared(test); + let reg_ref = test_scenario::borrow_mut(&mut reg); - ABC::transfer(reg_ref, &mut coin, 250000, user1, ctx(test)); + abc::transfer(reg_ref, &mut coin, 250000, user1, ctx(test)); - TestScenario::return_shared(test, reg); - TestScenario::return_owned(test, coin); + test_scenario::return_shared(test, reg); + test_scenario::return_owned(test, coin); }; } @@ -533,19 +533,19 @@ module ABC::Tests { test_ban_(test); next_tx(test, &user1); { - let coin = TestScenario::take_owned>(test); - Sui::Transfer::transfer(coin, user2); + let coin = test_scenario::take_owned>(test); + Sui::transfer::transfer(coin, user2); }; next_tx(test, &user2); { - let coin = TestScenario::take_owned>(test); - let reg = TestScenario::take_shared(test); - let reg_ref = TestScenario::borrow_mut(&mut reg); + let coin = test_scenario::take_owned>(test); + let reg = test_scenario::take_shared(test); + let reg_ref = test_scenario::borrow_mut(&mut reg); - ABC::transfer(reg_ref, &mut coin, 500000, user1, ctx(test)); + abc::transfer(reg_ref, &mut coin, 500000, user1, ctx(test)); - TestScenario::return_shared(test, reg); - TestScenario::return_owned(test, coin); + test_scenario::return_shared(test, reg); + test_scenario::return_owned(test, coin); } } } diff --git a/wallet/src/ui/app/redux/slices/sui-objects/Coin.ts b/wallet/src/ui/app/redux/slices/sui-objects/Coin.ts index 2a59ac5843d6e..f518c70b9f8e5 100644 --- a/wallet/src/ui/app/redux/slices/sui-objects/Coin.ts +++ b/wallet/src/ui/app/redux/slices/sui-objects/Coin.ts @@ -16,12 +16,12 @@ import type { SuiAddress, } from '@mysten/sui.js'; -const COIN_TYPE = '0x2::Coin::Coin'; -const COIN_TYPE_ARG_REGEX = /^0x2::Coin::Coin<(.+)>$/; +const COIN_TYPE = '0x2::coin::Coin'; +const COIN_TYPE_ARG_REGEX = /^0x2::coin::Coin<(.+)>$/; export const DEFAULT_GAS_BUDGET_FOR_SPLIT = 1000; export const DEFAULT_GAS_BUDGET_FOR_MERGE = 500; export const DEFAULT_GAS_BUDGET_FOR_TRANSFER = 100; -export const GAS_TYPE_ARG = '0x2::SUI::SUI'; +export const GAS_TYPE_ARG = '0x2::sui::SUI'; export const GAS_SYMBOL = 'SUI'; // TODO use sdk diff --git a/wallet/src/ui/app/redux/slices/sui-objects/NFT.ts b/wallet/src/ui/app/redux/slices/sui-objects/NFT.ts index f17fe3cf52186..0e14fed0324ce 100644 --- a/wallet/src/ui/app/redux/slices/sui-objects/NFT.ts +++ b/wallet/src/ui/app/redux/slices/sui-objects/NFT.ts @@ -18,7 +18,7 @@ export class ExampleNFT { ): Promise { return await signer.executeMoveCall({ packageObjectId: '0x2', - module: 'DevNetNFT', + module: 'devnet_nft', function: 'mint', typeArguments: [], arguments: [