From e1e7d5925ff5bab74cb824d9333993661862a2db Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Fri, 23 Jun 2023 14:31:10 -0500 Subject: [PATCH 1/6] Add create_token method in token.move --- .../aptos-token-objects/doc/token.md | 37 +++++++++++++++++++ .../aptos-token-objects/sources/token.move | 16 ++++++++ .../ambassador/sources/ambassador.move | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/aptos-move/framework/aptos-token-objects/doc/token.md b/aptos-move/framework/aptos-token-objects/doc/token.md index 0b23237681a04..7783f5da977ce 100644 --- a/aptos-move/framework/aptos-token-objects/doc/token.md +++ b/aptos-move/framework/aptos-token-objects/doc/token.md @@ -16,6 +16,7 @@ token are: - [Struct `MutationEvent`](#0x4_token_MutationEvent) - [Constants](#@Constants_0) - [Function `create_common`](#0x4_token_create_common) +- [Function `create_token`](#0x4_token_create_token) - [Function `create_named_token`](#0x4_token_create_named_token) - [Function `create_from_account`](#0x4_token_create_from_account) - [Function `create_token_address`](#0x4_token_create_token_address) @@ -361,6 +362,42 @@ The token name is over the maximum length + + + + +## Function `create_token` + +Creates a new token object with a unique address and returns the ConstructorRef +for additional specialization. + + +
public fun create_token(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
+
+ + + +
+Implementation + + +
public fun create_token(
+    creator: &signer,
+    collection_name: String,
+    description: String,
+    name: String,
+    royalty: Option<Royalty>,
+    uri: String,
+): ConstructorRef {
+    let creator_address = signer::address_of(creator);
+    let constructor_ref = object::create_object(creator_address);
+    create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri);
+    constructor_ref
+}
+
+ + +
diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move index 2867bc18c2822..9614f2d9d2596 100644 --- a/aptos-move/framework/aptos-token-objects/sources/token.move +++ b/aptos-move/framework/aptos-token-objects/sources/token.move @@ -106,6 +106,22 @@ module aptos_token_objects::token { }; } + /// Creates a new token object with a unique address and returns the ConstructorRef + /// for additional specialization. + public fun create_token( + creator: &signer, + collection_name: String, + description: String, + name: String, + royalty: Option, + uri: String, + ): ConstructorRef { + let creator_address = signer::address_of(creator); + let constructor_ref = object::create_object(creator_address); + create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri); + constructor_ref + } + /// Creates a new token object from a token name and returns the ConstructorRef for /// additional specialization. public fun create_named_token( diff --git a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move index d60102db45134..bf238af05bc51 100644 --- a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move +++ b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move @@ -152,7 +152,7 @@ module token_objects::ambassador { // is used to generate the refs of the token. let uri = base_uri; string::append(&mut uri, string::utf8(RANK_BRONZE)); - let constructor_ref = token::create_named_token( + let constructor_ref = token::create_token( creator, collection, description, From 74fd59c492f4f29e7824465d616a1314af85d78f Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sun, 25 Jun 2023 17:44:34 -0500 Subject: [PATCH 2/6] add deprecated flag to create_token_from_account --- aptos-move/framework/aptos-token-objects/doc/aptos_token.md | 2 +- aptos-move/framework/aptos-token-objects/doc/token.md | 3 ++- .../framework/aptos-token-objects/sources/aptos_token.move | 2 +- aptos-move/framework/aptos-token-objects/sources/token.move | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md index 54c8cc83e58fc..5e8740af0c8f6 100644 --- a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md +++ b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md @@ -471,7 +471,7 @@ With an existing collection, directly mint a soul bound token into the recipient property_types: vector<String>, property_values: vector<vector<u8>>, ): ConstructorRef acquires AptosCollection { - let constructor_ref = token::create_from_account( + let constructor_ref = token::create_token( creator, collection, description, diff --git a/aptos-move/framework/aptos-token-objects/doc/token.md b/aptos-move/framework/aptos-token-objects/doc/token.md index 7783f5da977ce..3b63254bfefad 100644 --- a/aptos-move/framework/aptos-token-objects/doc/token.md +++ b/aptos-move/framework/aptos-token-objects/doc/token.md @@ -446,7 +446,8 @@ Creates a new token object from an account GUID and returns the ConstructorRef f additional specialization. -
public fun create_from_account(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
+
#[deprecated]
+public fun create_from_account(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
 
diff --git a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move index 17c77fa3fe3b4..894414c90e34e 100644 --- a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move +++ b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move @@ -199,7 +199,7 @@ module aptos_token_objects::aptos_token { property_types: vector, property_values: vector>, ): ConstructorRef acquires AptosCollection { - let constructor_ref = token::create_from_account( + let constructor_ref = token::create_token( creator, collection, description, diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move index 9614f2d9d2596..10225b99f9f42 100644 --- a/aptos-move/framework/aptos-token-objects/sources/token.move +++ b/aptos-move/framework/aptos-token-objects/sources/token.move @@ -140,6 +140,7 @@ module aptos_token_objects::token { constructor_ref } + #[deprecated] /// Creates a new token object from an account GUID and returns the ConstructorRef for /// additional specialization. public fun create_from_account( From d2b89cd99b52f6ea74a45789c5982de00e0086b3 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 09:36:26 -0700 Subject: [PATCH 3/6] Add test case and rename to create --- .../aptos-token-objects/doc/aptos_token.md | 28 +++++++++++++----- .../aptos-token-objects/doc/token.md | 10 +++---- .../sources/aptos_token.move | 27 ++++++++++++----- .../aptos-token-objects/sources/token.move | 29 +++++++++++++++++-- .../ambassador/sources/ambassador.move | 2 +- 5 files changed, 72 insertions(+), 24 deletions(-) diff --git a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md index 5e8740af0c8f6..26be0856e0e13 100644 --- a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md +++ b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md @@ -58,6 +58,7 @@ The key features are:
use 0x1::error;
+use 0x1::features;
 use 0x1::object;
 use 0x1::option;
 use 0x1::signer;
@@ -471,14 +472,25 @@ With an existing collection, directly mint a soul bound token into the recipient
     property_types: vector<String>,
     property_values: vector<vector<u8>>,
 ): ConstructorRef acquires AptosCollection {
-    let constructor_ref = token::create_token(
-        creator,
-        collection,
-        description,
-        name,
-        option::none(),
-        uri,
-    );
+    let constructor_ref = if (std::features::auids_enabled()) {
+        token::create(
+            creator,
+            collection,
+            description,
+            name,
+            option::none(),
+            uri,
+        )
+    } else {
+        token::create_from_account(
+            creator,
+            collection,
+            description,
+            name,
+            option::none(),
+            uri,
+        )
+    };
 
     let object_signer = object::generate_signer(&constructor_ref);
 
diff --git a/aptos-move/framework/aptos-token-objects/doc/token.md b/aptos-move/framework/aptos-token-objects/doc/token.md
index 3b63254bfefad..391ae97000cbd 100644
--- a/aptos-move/framework/aptos-token-objects/doc/token.md
+++ b/aptos-move/framework/aptos-token-objects/doc/token.md
@@ -16,7 +16,7 @@ token are:
 -  [Struct `MutationEvent`](#0x4_token_MutationEvent)
 -  [Constants](#@Constants_0)
 -  [Function `create_common`](#0x4_token_create_common)
--  [Function `create_token`](#0x4_token_create_token)
+-  [Function `create`](#0x4_token_create)
 -  [Function `create_named_token`](#0x4_token_create_named_token)
 -  [Function `create_from_account`](#0x4_token_create_from_account)
 -  [Function `create_token_address`](#0x4_token_create_token_address)
@@ -364,15 +364,15 @@ The token name is over the maximum length
 
 
 
-
+
 
-## Function `create_token`
+## Function `create`
 
 Creates a new token object with a unique address and returns the ConstructorRef
 for additional specialization.
 
 
-
public fun create_token(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
+
public fun create(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
 
@@ -381,7 +381,7 @@ for additional specialization. Implementation -
public fun create_token(
+
public fun create(
     creator: &signer,
     collection_name: String,
     description: String,
diff --git a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move
index 894414c90e34e..dc3f1ce0e9e34 100644
--- a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move
+++ b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move
@@ -199,14 +199,25 @@ module aptos_token_objects::aptos_token {
         property_types: vector,
         property_values: vector>,
     ): ConstructorRef acquires AptosCollection {
-        let constructor_ref = token::create_token(
-            creator,
-            collection,
-            description,
-            name,
-            option::none(),
-            uri,
-        );
+        let constructor_ref = if (std::features::auids_enabled()) {
+            token::create(
+                creator,
+                collection,
+                description,
+                name,
+                option::none(),
+                uri,
+            )
+        } else {
+            token::create_from_account(
+                creator,
+                collection,
+                description,
+                name,
+                option::none(),
+                uri,
+            )
+        };
 
         let object_signer = object::generate_signer(&constructor_ref);
 
diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move
index 10225b99f9f42..4899ccba46ca1 100644
--- a/aptos-move/framework/aptos-token-objects/sources/token.move
+++ b/aptos-move/framework/aptos-token-objects/sources/token.move
@@ -108,7 +108,7 @@ module aptos_token_objects::token {
 
     /// Creates a new token object with a unique address and returns the ConstructorRef
     /// for additional specialization.
-    public fun create_token(
+    public fun create(
         creator: &signer,
         collection_name: String,
         description: String,
@@ -531,7 +531,7 @@ module aptos_token_objects::token {
     }
 
     #[test(creator = @0x123)]
-    fun test_burn_and_delete(creator: &signer) acquires Token {
+    fun test_create_from_account_burn_and_delete(creator: &signer) acquires Token {
         use aptos_framework::account;
 
         let collection_name = string::utf8(b"collection name");
@@ -555,6 +555,31 @@ module aptos_token_objects::token {
         assert!(!object::is_object(token_addr), 2);
     }
 
+    #[test(creator = @0x123)]
+    fun test_create_burn_and_delete(creator: &signer) acquires Token {
+        use aptos_framework::account;
+
+        let collection_name = string::utf8(b"collection name");
+        let token_name = string::utf8(b"token name");
+
+        create_collection_helper(creator, collection_name, 1);
+        account::create_account_for_test(signer::address_of(creator));
+        let constructor_ref = create(
+            creator,
+            collection_name,
+            string::utf8(b"token description"),
+            token_name,
+            option::none(),
+            string::utf8(b"token uri"),
+        );
+        let burn_ref = generate_burn_ref(&constructor_ref);
+        let token_addr = object::address_from_constructor_ref(&constructor_ref);
+        assert!(exists(token_addr), 0);
+        burn(burn_ref);
+        assert!(!exists(token_addr), 1);
+        assert!(!object::is_object(token_addr), 2);
+    }
+
     #[test_only]
     fun create_collection_helper(creator: &signer, collection_name: String, max_supply: u64) {
         collection::create_fixed_collection(
diff --git a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move
index bf238af05bc51..d7a1057cb4da0 100644
--- a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move
+++ b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move
@@ -152,7 +152,7 @@ module token_objects::ambassador {
         // is used to generate the refs of the token.
         let uri = base_uri;
         string::append(&mut uri, string::utf8(RANK_BRONZE));
-        let constructor_ref = token::create_token(
+        let constructor_ref = token::create(
             creator,
             collection,
             description,

From a89a3d12fa959544d26af456d3df09821e424a41 Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Mon, 26 Jun 2023 09:42:13 -0700
Subject: [PATCH 4/6] Add feature flag condition in test case

---
 .../aptos-token-objects/sources/token.move    | 44 ++++++++++---------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move
index 4899ccba46ca1..947f5e5975268 100644
--- a/aptos-move/framework/aptos-token-objects/sources/token.move
+++ b/aptos-move/framework/aptos-token-objects/sources/token.move
@@ -557,27 +557,29 @@ module aptos_token_objects::token {
 
     #[test(creator = @0x123)]
     fun test_create_burn_and_delete(creator: &signer) acquires Token {
-        use aptos_framework::account;
-
-        let collection_name = string::utf8(b"collection name");
-        let token_name = string::utf8(b"token name");
-
-        create_collection_helper(creator, collection_name, 1);
-        account::create_account_for_test(signer::address_of(creator));
-        let constructor_ref = create(
-            creator,
-            collection_name,
-            string::utf8(b"token description"),
-            token_name,
-            option::none(),
-            string::utf8(b"token uri"),
-        );
-        let burn_ref = generate_burn_ref(&constructor_ref);
-        let token_addr = object::address_from_constructor_ref(&constructor_ref);
-        assert!(exists(token_addr), 0);
-        burn(burn_ref);
-        assert!(!exists(token_addr), 1);
-        assert!(!object::is_object(token_addr), 2);
+        if (std::features::auids_enabled()) {
+            use aptos_framework::account;
+
+            let collection_name = string::utf8(b"collection name");
+            let token_name = string::utf8(b"token name");
+
+            create_collection_helper(creator, collection_name, 1);
+            account::create_account_for_test(signer::address_of(creator));
+            let constructor_ref = create(
+                creator,
+                collection_name,
+                string::utf8(b"token description"),
+                token_name,
+                option::none(),
+                string::utf8(b"token uri"),
+            );
+            let burn_ref = generate_burn_ref(&constructor_ref);
+            let token_addr = object::address_from_constructor_ref(&constructor_ref);
+            assert!(exists(token_addr), 0);
+            burn(burn_ref);
+            assert!(!exists(token_addr), 1);
+            assert!(!object::is_object(token_addr), 2);
+        }
     }
 
     #[test_only]

From 92cd3fe8e0ba9cda6483bebc1c612e4797e5d491 Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Mon, 26 Jun 2023 10:19:01 -0700
Subject: [PATCH 5/6] enabled feature flag in the unit test

---
 .../aptos-token-objects/sources/token.move    | 52 ++++++++++---------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move
index 947f5e5975268..06e9bdfe529f4 100644
--- a/aptos-move/framework/aptos-token-objects/sources/token.move
+++ b/aptos-move/framework/aptos-token-objects/sources/token.move
@@ -555,31 +555,33 @@ module aptos_token_objects::token {
         assert!(!object::is_object(token_addr), 2);
     }
 
-    #[test(creator = @0x123)]
-    fun test_create_burn_and_delete(creator: &signer) acquires Token {
-        if (std::features::auids_enabled()) {
-            use aptos_framework::account;
-
-            let collection_name = string::utf8(b"collection name");
-            let token_name = string::utf8(b"token name");
-
-            create_collection_helper(creator, collection_name, 1);
-            account::create_account_for_test(signer::address_of(creator));
-            let constructor_ref = create(
-                creator,
-                collection_name,
-                string::utf8(b"token description"),
-                token_name,
-                option::none(),
-                string::utf8(b"token uri"),
-            );
-            let burn_ref = generate_burn_ref(&constructor_ref);
-            let token_addr = object::address_from_constructor_ref(&constructor_ref);
-            assert!(exists(token_addr), 0);
-            burn(burn_ref);
-            assert!(!exists(token_addr), 1);
-            assert!(!object::is_object(token_addr), 2);
-        }
+    #[test(creator = @0x123,fx = @std)]
+    fun test_create_burn_and_delete(creator: &signer, fx: signer) acquires Token {
+        use aptos_framework::account;
+        use std::features;
+
+        let feature = features::get_auids();
+        features::change_feature_flags(&fx, vector[feature], vector[]);
+
+        let collection_name = string::utf8(b"collection name");
+        let token_name = string::utf8(b"token name");
+
+        create_collection_helper(creator, collection_name, 1);
+        account::create_account_for_test(signer::address_of(creator));
+        let constructor_ref = create(
+            creator,
+            collection_name,
+            string::utf8(b"token description"),
+            token_name,
+            option::none(),
+            string::utf8(b"token uri"),
+        );
+        let burn_ref = generate_burn_ref(&constructor_ref);
+        let token_addr = object::address_from_constructor_ref(&constructor_ref);
+        assert!(exists(token_addr), 0);
+        burn(burn_ref);
+        assert!(!exists(token_addr), 1);
+        assert!(!object::is_object(token_addr), 2);
     }
 
     #[test_only]

From 075e642c53f6ee893b7eb9f910e839a14683d150 Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Mon, 26 Jun 2023 11:31:33 -0700
Subject: [PATCH 6/6] Enabling auid feature flag in ambassador unit tests

---
 .../framework/aptos-token-objects/doc/aptos_token.md     | 2 +-
 .../aptos-token-objects/sources/aptos_token.move         | 3 ++-
 .../token_objects/ambassador/sources/ambassador.move     | 9 +++++++--
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
index 26be0856e0e13..8414f43ddfb13 100644
--- a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
+++ b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
@@ -472,7 +472,7 @@ With an existing collection, directly mint a soul bound token into the recipient
     property_types: vector<String>,
     property_values: vector<vector<u8>>,
 ): ConstructorRef acquires AptosCollection {
-    let constructor_ref = if (std::features::auids_enabled()) {
+    let constructor_ref = if (features::auids_enabled()) {
         token::create(
             creator,
             collection,
diff --git a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move
index dc3f1ce0e9e34..f20cd7b600025 100644
--- a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move
+++ b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move
@@ -8,6 +8,7 @@
 /// * Metadata property type
 module aptos_token_objects::aptos_token {
     use std::error;
+    use std::features;
     use std::option::{Self, Option};
     use std::string::String;
     use std::signer;
@@ -199,7 +200,7 @@ module aptos_token_objects::aptos_token {
         property_types: vector,
         property_values: vector>,
     ): ConstructorRef acquires AptosCollection {
-        let constructor_ref = if (std::features::auids_enabled()) {
+        let constructor_ref = if (features::auids_enabled()) {
             token::create(
                 creator,
                 collection,
diff --git a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move
index d7a1057cb4da0..d540995aecc9f 100644
--- a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move
+++ b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move
@@ -283,8 +283,13 @@ module token_objects::ambassador {
         );
     }
 
-    #[test(creator = @0x123, user1 = @0x456)]
-    fun test_mint_burn(creator: &signer, user1: &signer) acquires AmbassadorToken, AmbassadorLevel {
+    #[test(creator = @0x123, user1 = @0x456, fx = @std)]
+    fun test_mint_burn(creator: &signer, user1: &signer, fx: signer) acquires AmbassadorToken, AmbassadorLevel {
+        use std::features;
+
+        let feature = features::get_auids();
+        features::change_feature_flags(&fx, vector[feature], vector[]);
+
         // ------------------------------------------
         // Creator creates the Ambassador Collection.
         // ------------------------------------------