difftreelog
Merge branch 'develop' into feature/CORE-189
in: master
9 files changed
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -196,6 +196,7 @@
const_on_chain_schema: vec![],
variable_on_chain_schema: vec![],
limits: CollectionLimits::default(),
+ meta_update_permission: MetaUpdatePermission::ItemOwner,
transfers_enabled: true,
},
)],
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -43,7 +43,7 @@
OFFCHAIN_SCHEMA_LIMIT, MAX_TOKEN_PREFIX_LENGTH, MAX_COLLECTION_NAME_LENGTH,
MAX_COLLECTION_DESCRIPTION_LENGTH, AccessMode, Collection, CreateItemData, CollectionLimits,
CollectionId, CollectionMode, TokenId, SchemaVersion, SponsorshipState, Ownership, NftItemType,
- FungibleItemType, ReFungibleItemType,
+ MetaUpdatePermission, FungibleItemType, ReFungibleItemType,
};
#[cfg(test)]
@@ -145,6 +145,10 @@
BadCreateRefungibleCall,
/// Gas limit exceeded
OutOfGas,
+ /// Metadata update denied by collection settings
+ MetadataUpdateDenied,
+ /// Metadata update flag become unmutable with None option
+ MetadataFlagFrozen,
/// Collection settings not allowing items transferring
TransferNotAllowed,
/// Can't transfer tokens to ethereum zero address
@@ -541,6 +545,7 @@
variable_on_chain_schema: Vec::new(),
const_on_chain_schema: Vec::new(),
limits,
+ meta_update_permission: MetaUpdatePermission::default(),
transfers_enabled: true,
};
@@ -940,6 +945,36 @@
target_collection.save()
}
+ // TODO! transaction weight
+ /// Set meta_update_permission value for particular collection
+ ///
+ /// # Permissions
+ ///
+ /// * Collection Owner.
+ ///
+ /// # Arguments
+ ///
+ /// * collection_id: ID of the collection.
+ ///
+ /// * value: New flag value.
+ #[weight = <T as Config>::WeightInfo::burn_item()]
+ #[transactional]
+ pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {
+
+ let sender = ensure_signed(origin)?;
+ let mut target_collection = Self::get_collection(collection_id)?;
+
+ ensure!(
+ target_collection.meta_update_permission != MetaUpdatePermission::None,
+ Error::<T>::MetadataFlagFrozen
+ );
+ Self::check_owner_permissions(&target_collection, &sender)?;
+
+ target_collection.meta_update_permission = value;
+
+ target_collection.save()
+ }
+
/// Destroys a concrete instance of NFT.
///
/// # Permissions
@@ -1485,10 +1520,11 @@
Error::<T>::TokenVariableDataLimitExceeded
);
- // Modify permissions check
ensure!(
- Self::is_item_owner(sender, collection, item_id)?
- || Self::is_owner_or_admin_permissions(collection, sender)?,
+ (Self::is_item_owner(sender, collection, item_id)?
+ && collection.meta_update_permission == MetaUpdatePermission::ItemOwner)
+ || (Self::is_owner_or_admin_permissions(collection, sender)?
+ && collection.meta_update_permission == MetaUpdatePermission::Admin),
Error::<T>::NoPermission
);
@@ -1504,6 +1540,26 @@
Ok(())
}
+ pub fn meta_update_check(
+ sender: &T::CrossAccountId,
+ collection: &CollectionHandle<T>,
+ item_id: TokenId,
+ ) -> DispatchResult {
+ match collection.meta_update_permission {
+ MetaUpdatePermission::ItemOwner => ensure!(
+ Self::is_item_owner(sender, collection, item_id)?,
+ Error::<T>::NoPermission
+ ),
+ MetaUpdatePermission::Admin => ensure!(
+ Self::is_owner_or_admin_permissions(collection, sender)?,
+ Error::<T>::NoPermission
+ ),
+ MetaUpdatePermission::None => fail!(Error::<T>::MetadataUpdateDenied),
+ }
+
+ Ok(())
+ }
+
pub fn get_variable_metadata(
collection: &CollectionHandle<T>,
item_id: TokenId,
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -2005,56 +2005,285 @@
}
#[test]
-fn collection_transfer_flag_works() {
+fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {
new_test_ext().execute_with(|| {
- let origin1 = Origin::signed(1);
+ //default_limits();
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
- assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));
+ let origin1 = Origin::signed(1);
+
let data = default_nft_data();
- create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ create_test_item(1, &data.into());
- let origin1 = Origin::signed(1);
+ TemplateModule::set_meta_update_permission_flag(
+ origin1.clone(),
+ collection_id,
+ MetaUpdatePermission::ItemOwner,
+ );
- // default scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
+ let variable_data = b"ten chars.".to_vec();
+ assert_ok!(TemplateModule::set_variable_meta_data(
+ origin1,
+ collection_id,
+ 1,
+ variable_data.clone()
+ ));
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ assert_eq!(
+ TemplateModule::nft_item_id(collection_id, 1)
+ .unwrap()
+ .variable_data,
+ variable_data
+ );
});
}
#[test]
-fn collection_transfer_flag_works_neg() {
+fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {
new_test_ext().execute_with(|| {
+ // default_limits();
+
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+
let origin1 = Origin::signed(1);
+ let origin2 = Origin::signed(2);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
- assert_ok!(TemplateModule::set_transfers_enabled_flag(
- origin1, 1, false
+ assert_ok!(TemplateModule::set_mint_permission(
+ origin2.clone(),
+ collection_id,
+ true
+ ));
+ assert_ok!(TemplateModule::add_to_white_list(
+ origin2.clone(),
+ collection_id,
+ account(1)
));
let data = default_nft_data();
- create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ create_test_item(1, &data.into());
- let origin1 = Origin::signed(1);
+ assert_ok!(TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::ItemOwner,
+ ));
- // default scenario
+ let variable_data = b"ten chars.++".to_vec();
assert_noop!(
- TemplateModule::transfer(origin1, account(2), 1, 1, 1000),
- Error::<Test>::TransferNotAllowed
+ TemplateModule::set_variable_meta_data(
+ origin2,
+ collection_id,
+ 1,
+ variable_data.clone()
+ ),
+ Error::<Test>::TokenVariableDataLimitExceeded
);
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::balance_count(1, 2), 0);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ #[test]
+ fn collection_transfer_flag_works() {
+ new_test_ext().execute_with(|| {
+ let origin1 = Origin::signed(1);
+
+ let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+
+ let origin1 = Origin::signed(1);
+
+ // default scenario
+ assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
+ assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
+ assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(TemplateModule::balance_count(1, 2), 1);
+
+ assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ });
+ }
+
+ #[test]
+ fn set_variable_meta_data_on_nft_with_admin_flag() {
+ new_test_ext().execute_with(|| {
+ // default_limits();
+
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+
+ let origin1 = Origin::signed(1);
+ let origin2 = Origin::signed(2);
+
+ assert_ok!(TemplateModule::set_mint_permission(
+ origin2.clone(),
+ collection_id,
+ true
+ ));
+ assert_ok!(TemplateModule::add_to_white_list(
+ origin2.clone(),
+ collection_id,
+ account(1)
+ ));
+
+ assert_ok!(TemplateModule::add_collection_admin(
+ origin2.clone(),
+ collection_id,
+ account(1)
+ ));
+
+ let data = default_nft_data();
+ create_test_item(1, &data.into());
+
+ assert_ok!(TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::Admin,
+ ));
+
+ let variable_data = b"test set_variable_meta_data method.".to_vec();
+ assert_ok!(TemplateModule::set_variable_meta_data(
+ origin1,
+ collection_id,
+ 1,
+ variable_data.clone()
+ ));
+
+ assert_eq!(
+ TemplateModule::nft_item_id(collection_id, 1)
+ .unwrap()
+ .variable_data,
+ variable_data
+ );
+ });
+ }
+
+ #[test]
+ fn set_variable_meta_data_on_nft_with_admin_flag_neg() {
+ new_test_ext().execute_with(|| {
+ // default_limits();
+
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+
+ let origin1 = Origin::signed(1);
+ let origin2 = Origin::signed(2);
+
+ assert_ok!(TemplateModule::set_mint_permission(
+ origin2.clone(),
+ collection_id,
+ true
+ ));
+ assert_ok!(TemplateModule::add_to_white_list(
+ origin2.clone(),
+ collection_id,
+ account(1)
+ ));
+
+ let data = default_nft_data();
+ create_test_item(1, &data.into());
+
+ assert_ok!(TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::Admin,
+ ));
+
+ let variable_data = b"test set_variable_meta_data method.".to_vec();
+ assert_noop!(
+ TemplateModule::set_variable_meta_data(
+ origin1,
+ collection_id,
+ 1,
+ variable_data.clone()
+ ),
+ Error::<Test>::NoPermission
+ );
+ });
+ }
+
+ #[test]
+ fn set_variable_meta_flag_after_freeze() {
+ new_test_ext().execute_with(|| {
+ // default_limits();
+
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+
+ let origin2 = Origin::signed(2);
+
+ assert_ok!(TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::None,
+ ));
+ assert_noop!(
+ TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::Admin
+ ),
+ Error::<Test>::MetadataFlagFrozen
+ );
+ });
+ }
+
+ #[test]
+ fn set_variable_meta_data_on_nft_with_none_flag_neg() {
+ new_test_ext().execute_with(|| {
+ // default_limits();
+
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
+ let origin1 = Origin::signed(1);
+
+ let data = default_nft_data();
+ create_test_item(1, &data.into());
+
+ assert_ok!(TemplateModule::set_meta_update_permission_flag(
+ origin1.clone(),
+ collection_id,
+ MetaUpdatePermission::None,
+ ));
+
+ let variable_data = b"test set_variable_meta_data method.".to_vec();
+ assert_noop!(
+ TemplateModule::set_variable_meta_data(
+ origin1.clone(),
+ collection_id,
+ 1,
+ variable_data.clone()
+ ),
+ Error::<Test>::MetadataUpdateDenied
+ );
+ });
+ }
+
+ #[test]
+ fn collection_transfer_flag_works_neg() {
+ new_test_ext().execute_with(|| {
+ let origin1 = Origin::signed(1);
+
+ let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ assert_ok!(TemplateModule::set_transfers_enabled_flag(
+ origin1, 1, false
+ ));
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+
+ let origin1 = Origin::signed(1);
+
+ // default scenario
+ assert_noop!(
+ TemplateModule::transfer(origin1, account(2), 1, 1, 1000),
+ Error::<Test>::TransferNotAllowed
+ );
+ assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::balance_count(1, 2), 0);
+
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ });
+ }
});
}
primitives/nft/src/lib.rsdiffbeforeafterboth--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -185,6 +185,7 @@
pub limits: CollectionLimits<T::BlockNumber>, // Collection private restrictions
pub variable_on_chain_schema: Vec<u8>, //
pub const_on_chain_schema: Vec<u8>, //
+ pub meta_update_permission: MetaUpdatePermission,
pub transfers_enabled: bool,
}
@@ -305,6 +306,20 @@
pub pieces: u128,
}
+#[derive(Encode, Decode, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub enum MetaUpdatePermission {
+ ItemOwner,
+ Admin,
+ None,
+}
+
+impl Default for MetaUpdatePermission {
+ fn default() -> Self {
+ Self::ItemOwner
+ }
+}
+
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub enum CreateItemData {
runtime_types.jsondiffbeforeafterboth1{2 "CrossAccountId": {3 "_enum": {4 "substrate": "AccountId",5 "ethereum": "H160"6 }7 },8 "AccessMode": {9 "_enum": [10 "Normal",11 "WhiteList"12 ]13 },14 "CallSpec": {15 "Module": "u32",16 "Method": "u32"17 },18 "DecimalPoints": "u8",19 "CollectionMode": {20 "_enum": {21 "Invalid": null,22 "NFT": null,23 "Fungible": "DecimalPoints",24 "ReFungible": null25 }26 },27 "Ownership": {28 "Owner": "CrossAccountId",29 "Fraction": "u128"30 },31 "FungibleItemType": {32 "Value": "u128"33 },34 "NftItemType": {35 "Owner": "CrossAccountId",36 "ConstData": "Vec<u8>",37 "VariableData": "Vec<u8>"38 },39 "ReFungibleItemType": {40 "Owner": "Vec<Ownership<CrossAccountId>>",41 "ConstData": "Vec<u8>",42 "VariableData": "Vec<u8>"43 },44 "SponsorshipState": {45 "_enum": {46 "disabled": null,47 "unconfirmed": "AccountId",48 "confirmed": "AccountId"49 }50 },51 "Collection": {52 "Owner": "AccountId",53 "Mode": "CollectionMode",54 "Access": "AccessMode",55 "DecimalPoints": "DecimalPoints",56 "Name": "Vec<u16>",57 "Description": "Vec<u16>",58 "TokenPrefix": "Vec<u8>",59 "MintMode": "bool",60 "OffchainSchema": "Vec<u8>",61 "SchemaVersion": "SchemaVersion",62 "Sponsorship": "SponsorshipState",63 "Limits": "CollectionLimits",64 "VariableOnChainSchema": "Vec<u8>",65 "ConstOnChainSchema": "Vec<u8>",66 "TransfersEnabled": "bool"67 },68 "RawData": "Vec<u8>",69 "Address": "MultiAddress",70 "LookupSource": "MultiAddress",71 "Weight": "u64",72 "CreateNftData": {73 "const_data": "Vec<u8>",74 "variable_data": "Vec<u8>" 75 },76 "CreateFungibleData": {77 "value": "u128"78 },79 "CreateReFungibleData": {80 "const_data": "Vec<u8>",81 "variable_data": "Vec<u8>",82 "pieces": "u128"83 },84 "CreateItemData": {85 "_enum": {86 "NFT": "CreateNftData",87 "Fungible": "CreateFungibleData",88 "ReFungible": "CreateReFungibleData"89 }90 },91 "SchemaVersion": {92 "_enum": [93 "ImageURL",94 "Unique"95 ]96 },97 "CollectionId": "u32",98 "TokenId": "u32",99 "ChainLimits": {100 "CollectionNumbersLimit": "u32",101 "AccountTokenOwnershipLimit": "u32",102 "CollectionAdminsLimit": "u64",103 "CustomDataLimit": "u32",104 "NftSponsorTimeout": "u32",105 "FungibleSponsorTimeout": "u32",106 "RefungibleSponsorTimeout": "u32",107 "OffchainSchemaLimit": "u32",108 "VariableOnChainSchemaLimit": "u32",109 "ConstOnChainSchemaLimit": "u32"110 },111 "CollectionLimits": {112 "AccountTokenOwnershipLimit": "u32",113 "SponsoredDataSize": "u32",114 "SponsoredDataRateLimit": "Option<BlockNumber>",115 "TokenLimit": "u32",116 "SponsorTimeout": "u32",117 "OwnerCanTransfer": "bool",118 "OwnerCanDestroy": "bool"119 }120}1{2 "CrossAccountId": {3 "_enum": {4 "substrate": "AccountId",5 "ethereum": "H160"6 }7 },8 "AccessMode": {9 "_enum": [10 "Normal",11 "WhiteList"12 ]13 },14 "CallSpec": {15 "Module": "u32",16 "Method": "u32"17 },18 "DecimalPoints": "u8",19 "CollectionMode": {20 "_enum": {21 "Invalid": null,22 "NFT": null,23 "Fungible": "DecimalPoints",24 "ReFungible": null25 }26 },27 "Ownership": {28 "Owner": "CrossAccountId",29 "Fraction": "u128"30 },31 "FungibleItemType": {32 "Value": "u128"33 },34 "NftItemType": {35 "Owner": "CrossAccountId",36 "ConstData": "Vec<u8>",37 "VariableData": "Vec<u8>"38 },39 "ReFungibleItemType": {40 "Owner": "Vec<Ownership<CrossAccountId>>",41 "ConstData": "Vec<u8>",42 "VariableData": "Vec<u8>"43 },44 "SponsorshipState": {45 "_enum": {46 "disabled": null,47 "unconfirmed": "AccountId",48 "confirmed": "AccountId"49 }50 },51 "Collection": {52 "Owner": "AccountId",53 "Mode": "CollectionMode",54 "Access": "AccessMode",55 "DecimalPoints": "DecimalPoints",56 "Name": "Vec<u16>",57 "Description": "Vec<u16>",58 "TokenPrefix": "Vec<u8>",59 "MintMode": "bool",60 "OffchainSchema": "Vec<u8>",61 "SchemaVersion": "SchemaVersion",62 "Sponsorship": "SponsorshipState",63 "Limits": "CollectionLimits",64 "VariableOnChainSchema": "Vec<u8>",65 "ConstOnChainSchema": "Vec<u8>",66 "MetaUpdatePermission": "MetaUpdatePermission",67 "TransfersEnabled": "bool"68 },69 "RawData": "Vec<u8>",70 "Address": "MultiAddress",71 "LookupSource": "MultiAddress",72 "Weight": "u64",73 "CreateNftData": {74 "const_data": "Vec<u8>",75 "variable_data": "Vec<u8>" 76 },77 "CreateFungibleData": {78 "value": "u128"79 },80 "CreateReFungibleData": {81 "const_data": "Vec<u8>",82 "variable_data": "Vec<u8>",83 "pieces": "u128"84 },85 "CreateItemData": {86 "_enum": {87 "NFT": "CreateNftData",88 "Fungible": "CreateFungibleData",89 "ReFungible": "CreateReFungibleData"90 }91 },92 "SchemaVersion": {93 "_enum": [94 "ImageURL",95 "Unique"96 ]97 },98 "MetaUpdatePermission": {99 "_enum": [100 "ItemOwner",101 "Admin",102 "None" 103 ]104 },105 "CollectionId": "u32",106 "TokenId": "u32",107 "ChainLimits": {108 "CollectionNumbersLimit": "u32",109 "AccountTokenOwnershipLimit": "u32",110 "CollectionAdminsLimit": "u64",111 "CustomDataLimit": "u32",112 "NftSponsorTimeout": "u32",113 "FungibleSponsorTimeout": "u32",114 "RefungibleSponsorTimeout": "u32",115 "OffchainSchemaLimit": "u32",116 "VariableOnChainSchemaLimit": "u32",117 "ConstOnChainSchemaLimit": "u32"118 },119 "CollectionLimits": {120 "AccountTokenOwnershipLimit": "u32",121 "SponsoredDataSize": "u32",122 "SponsoredDataRateLimit": "Option<BlockNumber>",123 "TokenLimit": "u32",124 "SponsorTimeout": "u32",125 "OwnerCanTransfer": "bool",126 "OwnerCanDestroy": "bool"127 }128}tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -4,7 +4,6 @@
//
import { ApiPromise } from '@polkadot/api';
-import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
tests/src/collision-tests/adminLimitsOff.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/adminLimitsOff.test.ts
+++ b/tests/src/collision-tests/adminLimitsOff.test.ts
@@ -1,5 +1,4 @@
import { IKeyringPair } from '@polkadot/types/types';
-import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
tests/src/metadataUpdate.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/metadataUpdate.test.ts
@@ -0,0 +1,204 @@
+
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import usingApi from './substrate/substrate-api';
+import {
+ createItemExpectSuccess,
+ createCollectionExpectSuccess,
+ enablePublicMintingExpectSuccess,
+ enableWhiteListExpectSuccess,
+ setMetadataUpdatePermissionFlagExpectSuccess,
+ setVariableMetaDataExpectSuccess,
+ setMintPermissionExpectSuccess,
+ addToWhiteListExpectSuccess,
+ addCollectionAdminExpectSuccess,
+ setVariableMetaDataExpectFailure,
+ setMetadataUpdatePermissionFlagExpectFailure,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+
+describe('Metadata update permissions with ItemOwner flag', () => {
+ it('ItemOwner can set variable metadata with ItemOwner permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');
+
+ await setVariableMetaDataExpectSuccess(Alice, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('Admin can\'n set variable metadata with ItemOwner permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');
+
+ await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
+ await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
+
+ await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('User can\'n set variable metadata with ItemOwner permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');
+
+ await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
+ await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+});
+
+describe('Metadata update permissions with Admin flag', () => {
+ it('Admin can set variable metadata with Admin permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');
+
+ await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
+ await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
+
+ await setVariableMetaDataExpectSuccess(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('User can\'n can set variable metadata with Admin permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');
+
+ await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
+ await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
+
+ await setVariableMetaDataExpectSuccess(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('ItemOwner can\'n can set variable metadata with Admin permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ await enablePublicMintingExpectSuccess(Alice, nftCollectionId);
+ await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
+ await enableWhiteListExpectSuccess(Alice, nftCollectionId);
+ const newNftTokenId = await createItemExpectSuccess(Bob, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');
+
+ await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+});
+
+describe('Metadata update permissions with None flag', () => {
+ it('Nobody can set variable metadata with None flag (Regular)', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');
+
+ await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('Nobody can set variable metadata with None flag (Admin)', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');
+
+ await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
+ await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
+
+ await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('Nobody can set variable metadata with None flag (ItemOwner)', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');
+
+ await setVariableMetaDataExpectFailure(Alice, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('Nobody can set variable metadata flag after freeze', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');
+ await setMetadataUpdatePermissionFlagExpectFailure(Alice, nftCollectionId, 'Admin');
+ });
+ });
+});
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -525,6 +525,28 @@
});
}
+export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getGenericResult(events);
+
+ expect(result.success).to.be.true;
+ });
+}
+
+export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);
+ const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getGenericResult(events);
+
+ expect(result.success).to.be.false;
+ });
+}
+
export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {
await usingApi(async (api) => {
const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);