git.delta.rocks / unique-network / refs/commits / c4f8efb8f42d

difftreelog

added consts to `Unique` pallet

PraetorP2022-11-22parent: #d7cd036.patch.diff
in: master

6 files changed

modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -86,6 +86,8 @@
 use sp_std::{vec, vec::Vec};
 use up_data_structs::{
 	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
+	MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,
+	MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,
 	CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,
 	SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,
 	PropertyKeyPermission,
@@ -277,6 +279,46 @@
 	{
 		type Error = Error<T>;
 
+		#[doc = "Maximum number of levels of depth in the token nesting tree."]
+		const NESTING_BUDGET: u32 = NESTING_BUDGET;
+
+		#[doc = "Maximum length for collection name."]
+		const MAX_COLLECTION_NAME_LENGTH: u32 = MAX_COLLECTION_NAME_LENGTH;
+
+		#[doc = "Maximum length for collection description."]
+		const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = MAX_COLLECTION_DESCRIPTION_LENGTH;
+
+		#[doc = "Maximal token prefix length."]
+		const MAX_TOKEN_PREFIX_LENGTH: u32 = MAX_TOKEN_PREFIX_LENGTH;
+
+		#[doc = "Maximum admins per collection."]
+		const COLLECTION_ADMINS_LIMIT: u32 = COLLECTION_ADMINS_LIMIT;
+
+		#[doc = "Maximal lenght of property key."]
+		const MAX_PROPERTY_KEY_LENGTH: u32 = MAX_PROPERTY_KEY_LENGTH;
+
+		#[doc = "Maximal lenght of property value."]
+		const MAX_PROPERTY_VALUE_LENGTH: u32 = MAX_PROPERTY_VALUE_LENGTH;
+
+		#[doc = "Maximum properties that can be assigned to token."]
+		const MAX_PROPERTIES_PER_ITEM: u32 = MAX_PROPERTIES_PER_ITEM;
+
+		#[doc = "Maximum size for all collection properties."]
+		const MAX_COLLECTION_PROPERTIES_SIZE: u32 = MAX_COLLECTION_PROPERTIES_SIZE;
+
+		#[doc = "Maximum size for all token properties."]
+		const MAX_TOKEN_PROPERTIES_SIZE: u32 = MAX_TOKEN_PROPERTIES_SIZE;
+
+		#[doc = "Default NFT collection limit."]
+		const NFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::NFT);
+
+		#[doc = "Default RFT collection limit."]
+		const RFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::ReFungible);
+
+		#[doc = "Default FT collection limit."]
+		const FT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::Fungible(0));
+
+
 		pub fn deposit_event() = default;
 
 		fn on_initialize(_now: T::BlockNumber) -> Weight {
modifiedprimitives/data-structs/CHANGELOG.mddiffbeforeafterboth
--- a/primitives/data-structs/CHANGELOG.md
+++ b/primitives/data-structs/CHANGELOG.md
@@ -3,6 +3,7 @@
 All notable changes to this project will be documented in this file.
 
 <!-- bureaucrate goes here -->
+
 ## [v0.2.2] 2022-08-16
 
 ### Other changes
@@ -28,12 +29,19 @@
 multiple users into `RefungibleMultipleItems` call.
 
 ## [v0.2.0] - 2022-08-01
+
 ### Deprecated
+
 - `CreateReFungibleData::const_data`
 
 ## [v0.1.2] - 2022-07-25
+
 ### Added
+
 - Type aliases `CollectionName`, `CollectionDescription`, `CollectionTokenPrefix`
+
 ## [v0.1.1] - 2022-07-22
+
 ### Added
-- Аields with properties to `CreateReFungibleData` and `CreateRefungibleExData`.
\ No newline at end of file
+
+- Аields with properties to `CreateReFungibleData` and `CreateRefungibleExData`.
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -609,6 +609,24 @@
 }
 
 impl CollectionLimits {
+	pub fn with_default_limits(collection_type: CollectionMode) -> Self {
+		CollectionLimits {
+			account_token_ownership_limit: Some(ACCOUNT_TOKEN_OWNERSHIP_LIMIT),
+			sponsored_data_size: Some(CUSTOM_DATA_LIMIT),
+			sponsored_data_rate_limit: Some(SponsoringRateLimit::SponsoringDisabled),
+			token_limit: Some(COLLECTION_TOKEN_LIMIT),
+			sponsor_transfer_timeout: match collection_type {
+				CollectionMode::NFT => Some(NFT_SPONSOR_TRANSFER_TIMEOUT),
+				CollectionMode::ReFungible => Some(REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT),
+				CollectionMode::Fungible(_) => Some(FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT),
+			},
+			sponsor_approve_timeout: Some(SPONSOR_APPROVE_TIMEOUT),
+			owner_can_transfer: Some(false),
+			owner_can_destroy: Some(true),
+			transfers_enabled: Some(true),
+		}
+	}
+
 	/// Get effective value for [`account_token_ownership_limit`](self.account_token_ownership_limit).
 	pub fn account_token_ownership_limit(&self) -> u32 {
 		self.account_token_ownership_limit
modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -102,6 +102,7 @@
     "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
     "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",
     "benchMintingFee": "ts-node src/benchmarks/mintFee/benchmark.ts",
+    "testApiConsts": "mocha --timeout 9999999 -r ts-node/register ./**/apiConsts.test.ts",
     "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",
     "loadTransfer": "ts-node src/transfer.nload.ts",
     "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",
addedtests/src/apiConsts.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/apiConsts.test.ts
@@ -0,0 +1,108 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {ApiPromise} from '@polkadot/api';
+import {usingPlaygrounds, itSub, expect} from './util';
+
+
+const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;
+const MAX_COLLECTION_NAME_LENGTH = 64n;
+const COLLECTION_ADMINS_LIMIT = 5n;
+const MAX_COLLECTION_PROPERTIES_SIZE = 40960n;
+const MAX_TOKEN_PREFIX_LENGTH = 16n;
+const MAX_PROPERTY_KEY_LENGTH = 256n;
+const MAX_PROPERTY_VALUE_LENGTH = 32768n;
+const MAX_PROPERTIES_PER_ITEM = 64n;
+const MAX_TOKEN_PROPERTIES_SIZE = 32768n;
+const NESTING_BUDGET = 5n;
+
+const DEFAULT_COLLETCTION_LIMIT = {
+  accountTokenOwnershipLimit: '1,000,000',
+  sponsoredDataSize: '2,048',
+  sponsoredDataRateLimit: 'SponsoringDisabled',
+  tokenLimit: '4,294,967,295',
+  sponsorTransferTimeout: '5',
+  sponsorApproveTimeout: '5',
+  ownerCanTransfer: false,
+  ownerCanDestroy: true,
+  transfersEnabled: true,
+};
+
+describe('integration test: API UNIQUE consts', () => {
+  let api: ApiPromise;
+  
+  before(async () => {
+    await usingPlaygrounds(async (helper) => {
+      api = await helper.getApi();
+    });
+  });
+  
+  itSub('DEFAULT_NFT_COLLECTION_LIMITS', () => {
+    expect(api.consts.unique.nftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);
+  });
+  
+  itSub('DEFAULT_RFT_COLLECTION_LIMITS', () => {
+    expect(api.consts.unique.rftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);
+  });
+  
+  itSub('DEFAULT_FT_COLLECTION_LIMITS', () => {
+    expect(api.consts.unique.ftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);
+  });
+  
+  itSub('MAX_COLLECTION_NAME_LENGTH', () => {
+    checkConst(api.consts.unique.maxCollectionNameLength, MAX_COLLECTION_NAME_LENGTH);
+  });
+  
+  itSub('MAX_COLLECTION_DESCRIPTION_LENGTH', () => {
+    checkConst(api.consts.unique.maxCollectionDescriptionLength, MAX_COLLECTION_DESCRIPTION_LENGTH);
+  });
+  
+  itSub('MAX_COLLECTION_PROPERTIES_SIZE', () => {
+    checkConst(api.consts.unique.maxCollectionPropertiesSize, MAX_COLLECTION_PROPERTIES_SIZE);
+  });
+
+  itSub('MAX_TOKEN_PREFIX_LENGTH', () => {
+    checkConst(api.consts.unique.maxTokenPrefixLength, MAX_TOKEN_PREFIX_LENGTH);
+  });
+
+  itSub('MAX_PROPERTY_KEY_LENGTH', () => {
+    checkConst(api.consts.unique.maxPropertyKeyLength, MAX_PROPERTY_KEY_LENGTH);
+  });
+  
+  itSub('MAX_PROPERTY_VALUE_LENGTH', () => {
+    checkConst(api.consts.unique.maxPropertyValueLength, MAX_PROPERTY_VALUE_LENGTH);
+  });
+  
+  itSub('MAX_PROPERTIES_PER_ITEM', () => {
+    checkConst(api.consts.unique.maxPropertiesPerItem, MAX_PROPERTIES_PER_ITEM);
+  });
+  
+  itSub('NESTING_BUDGET', () => {
+    checkConst(api.consts.unique.nestingBudget, NESTING_BUDGET);
+  });
+  
+  itSub('MAX_TOKEN_PROPERTIES_SIZE', () => {
+    checkConst(api.consts.unique.maxTokenPropertiesSize, MAX_TOKEN_PROPERTIES_SIZE);
+  });
+  
+  itSub('COLLECTION_ADMINS_LIMIT', () => {
+    checkConst(api.consts.unique.collectionAdminsLimit, COLLECTION_ADMINS_LIMIT);
+  });
+});
+
+function checkConst<T>(constValue: any, expectedValue: T) {
+  expect(constValue.toBigInt()).equal(expectedValue);
+}
modifiedtests/src/interfaces/augment-api-consts.tsdiffbeforeafterboth
before · tests/src/interfaces/augment-api-consts.ts
1// Auto-generated via `yarn polkadot-types-from-chain`, do not edit2/* eslint-disable */34// import type lookup before we augment - in some environments5// this is required to allow for ambient/previous definitions6import '@polkadot/api-base/types/consts';78import type { ApiTypes, AugmentedConst } from '@polkadot/api-base/types';9import type { Option, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';10import type { Codec } from '@polkadot/types-codec/types';11import type { Perbill, Permill, Weight } from '@polkadot/types/interfaces/runtime';12import type { FrameSupportPalletId, FrameSystemLimitsBlockLength, FrameSystemLimitsBlockWeights, SpVersionRuntimeVersion, SpWeightsRuntimeDbWeight, XcmV1MultiLocation } from '@polkadot/types/lookup';1314export type __AugmentedConst<ApiType extends ApiTypes> = AugmentedConst<ApiType>;1516declare module '@polkadot/api-base/types/consts' {17  interface AugmentedConsts<ApiType extends ApiTypes> {18    appPromotion: {19      /**20       * Rate of return for interval in blocks defined in `RecalculationInterval`.21       **/22      intervalIncome: Perbill & AugmentedConst<ApiType>;23      /**24       * Decimals for the `Currency`.25       **/26      nominal: u128 & AugmentedConst<ApiType>;27      /**28       * The app's pallet id, used for deriving its sovereign account address.29       **/30      palletId: FrameSupportPalletId & AugmentedConst<ApiType>;31      /**32       * In parachain blocks.33       **/34      pendingInterval: u32 & AugmentedConst<ApiType>;35      /**36       * In relay blocks.37       **/38      recalculationInterval: u32 & AugmentedConst<ApiType>;39      /**40       * Generic const41       **/42      [key: string]: Codec;43    };44    balances: {45      /**46       * The minimum amount required to keep an account open.47       **/48      existentialDeposit: u128 & AugmentedConst<ApiType>;49      /**50       * The maximum number of locks that should exist on an account.51       * Not strictly enforced, but used for weight estimation.52       **/53      maxLocks: u32 & AugmentedConst<ApiType>;54      /**55       * The maximum number of named reserves that can exist on an account.56       **/57      maxReserves: u32 & AugmentedConst<ApiType>;58      /**59       * Generic const60       **/61      [key: string]: Codec;62    };63    common: {64      /**65       * Maximum admins per collection.66       **/67      collectionAdminsLimit: u32 & AugmentedConst<ApiType>;68      /**69       * Set price to create a collection.70       **/71      collectionCreationPrice: u128 & AugmentedConst<ApiType>;72      /**73       * Generic const74       **/75      [key: string]: Codec;76    };77    configuration: {78      defaultMinGasPrice: u64 & AugmentedConst<ApiType>;79      defaultWeightToFeeCoefficient: u32 & AugmentedConst<ApiType>;80      /**81       * Generic const82       **/83      [key: string]: Codec;84    };85    inflation: {86      /**87       * Number of blocks that pass between treasury balance updates due to inflation88       **/89      inflationBlockInterval: u32 & AugmentedConst<ApiType>;90      /**91       * Generic const92       **/93      [key: string]: Codec;94    };95    scheduler: {96      /**97       * The maximum weight that may be scheduled per block for any dispatchables.98       **/99      maximumWeight: Weight & AugmentedConst<ApiType>;100      /**101       * The maximum number of scheduled calls in the queue for a single block.102       **/103      maxScheduledPerBlock: u32 & AugmentedConst<ApiType>;104      /**105       * Generic const106       **/107      [key: string]: Codec;108    };109    system: {110      /**111       * Maximum number of block number to block hash mappings to keep (oldest pruned first).112       **/113      blockHashCount: u32 & AugmentedConst<ApiType>;114      /**115       * The maximum length of a block (in bytes).116       **/117      blockLength: FrameSystemLimitsBlockLength & AugmentedConst<ApiType>;118      /**119       * Block & extrinsics weights: base values and limits.120       **/121      blockWeights: FrameSystemLimitsBlockWeights & AugmentedConst<ApiType>;122      /**123       * The weight of runtime database operations the runtime can invoke.124       **/125      dbWeight: SpWeightsRuntimeDbWeight & AugmentedConst<ApiType>;126      /**127       * The designated SS58 prefix of this chain.128       * 129       * This replaces the "ss58Format" property declared in the chain spec. Reason is130       * that the runtime should know about the prefix in order to make use of it as131       * an identifier of the chain.132       **/133      ss58Prefix: u16 & AugmentedConst<ApiType>;134      /**135       * Get the chain's current version.136       **/137      version: SpVersionRuntimeVersion & AugmentedConst<ApiType>;138      /**139       * Generic const140       **/141      [key: string]: Codec;142    };143    timestamp: {144      /**145       * The minimum period between blocks. Beware that this is different to the *expected*146       * period that the block production apparatus provides. Your chosen consensus system will147       * generally work with this to determine a sensible block time. e.g. For Aura, it will be148       * double this period on default settings.149       **/150      minimumPeriod: u64 & AugmentedConst<ApiType>;151      /**152       * Generic const153       **/154      [key: string]: Codec;155    };156    tokens: {157      maxLocks: u32 & AugmentedConst<ApiType>;158      /**159       * The maximum number of named reserves that can exist on an account.160       **/161      maxReserves: u32 & AugmentedConst<ApiType>;162      /**163       * Generic const164       **/165      [key: string]: Codec;166    };167    transactionPayment: {168      /**169       * A fee mulitplier for `Operational` extrinsics to compute "virtual tip" to boost their170       * `priority`171       * 172       * This value is multipled by the `final_fee` to obtain a "virtual tip" that is later173       * added to a tip component in regular `priority` calculations.174       * It means that a `Normal` transaction can front-run a similarly-sized `Operational`175       * extrinsic (with no tip), by including a tip value greater than the virtual tip.176       * 177       * ```rust,ignore178       * // For `Normal`179       * let priority = priority_calc(tip);180       * 181       * // For `Operational`182       * let virtual_tip = (inclusion_fee + tip) * OperationalFeeMultiplier;183       * let priority = priority_calc(tip + virtual_tip);184       * ```185       * 186       * Note that since we use `final_fee` the multiplier applies also to the regular `tip`187       * sent with the transaction. So, not only does the transaction get a priority bump based188       * on the `inclusion_fee`, but we also amplify the impact of tips applied to `Operational`189       * transactions.190       **/191      operationalFeeMultiplier: u8 & AugmentedConst<ApiType>;192      /**193       * Generic const194       **/195      [key: string]: Codec;196    };197    treasury: {198      /**199       * Percentage of spare funds (if any) that are burnt per spend period.200       **/201      burn: Permill & AugmentedConst<ApiType>;202      /**203       * The maximum number of approvals that can wait in the spending queue.204       * 205       * NOTE: This parameter is also used within the Bounties Pallet extension if enabled.206       **/207      maxApprovals: u32 & AugmentedConst<ApiType>;208      /**209       * The treasury's pallet id, used for deriving its sovereign account ID.210       **/211      palletId: FrameSupportPalletId & AugmentedConst<ApiType>;212      /**213       * Fraction of a proposal's value that should be bonded in order to place the proposal.214       * An accepted proposal gets these back. A rejected proposal does not.215       **/216      proposalBond: Permill & AugmentedConst<ApiType>;217      /**218       * Maximum amount of funds that should be placed in a deposit for making a proposal.219       **/220      proposalBondMaximum: Option<u128> & AugmentedConst<ApiType>;221      /**222       * Minimum amount of funds that should be placed in a deposit for making a proposal.223       **/224      proposalBondMinimum: u128 & AugmentedConst<ApiType>;225      /**226       * Period between successive spends.227       **/228      spendPeriod: u32 & AugmentedConst<ApiType>;229      /**230       * Generic const231       **/232      [key: string]: Codec;233    };234    vesting: {235      /**236       * The minimum amount transferred to call `vested_transfer`.237       **/238      minVestedTransfer: u128 & AugmentedConst<ApiType>;239      /**240       * Generic const241       **/242      [key: string]: Codec;243    };244    xTokens: {245      /**246       * Base XCM weight.247       * 248       * The actually weight for an XCM message is `T::BaseXcmWeight +249       * T::Weigher::weight(&msg)`.250       **/251      baseXcmWeight: u64 & AugmentedConst<ApiType>;252      /**253       * Self chain location.254       **/255      selfLocation: XcmV1MultiLocation & AugmentedConst<ApiType>;256      /**257       * Generic const258       **/259      [key: string]: Codec;260    };261  } // AugmentedConsts262} // declare module