difftreelog
Merge pull request #317 from UniqueNetwork/feature/CORE-238
in: master
CORE-283 add effective_collection_limits
9 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9760,6 +9760,55 @@
]
[[package]]
+name = "sc-consensus-epochs"
+version = "0.10.0-dev"
+source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.17#22d40c761a985482f93bbbea5ba4199bdba74f8e"
+dependencies = [
+ "fork-tree",
+ "parity-scale-codec",
+ "sc-client-api",
+ "sc-consensus",
+ "sp-blockchain",
+ "sp-runtime",
+]
+
+[[package]]
+name = "sc-consensus-manual-seal"
+version = "0.10.0-dev"
+source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.17#22d40c761a985482f93bbbea5ba4199bdba74f8e"
+dependencies = [
+ "assert_matches",
+ "async-trait",
+ "futures 0.3.21",
+ "jsonrpc-core",
+ "jsonrpc-core-client",
+ "jsonrpc-derive",
+ "log",
+ "parity-scale-codec",
+ "sc-client-api",
+ "sc-consensus",
+ "sc-consensus-aura",
+ "sc-consensus-babe",
+ "sc-consensus-epochs",
+ "sc-transaction-pool",
+ "sc-transaction-pool-api",
+ "serde",
+ "sp-api",
+ "sp-blockchain",
+ "sp-consensus",
+ "sp-consensus-aura",
+ "sp-consensus-babe",
+ "sp-consensus-slots",
+ "sp-core",
+ "sp-inherents",
+ "sp-keystore",
+ "sp-runtime",
+ "sp-timestamp",
+ "substrate-prometheus-endpoint",
+ "thiserror",
+]
+
+[[package]]
name = "sc-consensus-slots"
version = "0.10.0-dev"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.18#fc3fd073d3a0acf9933c3994b660ebd7b5833f65"
@@ -12212,7 +12261,7 @@
"chrono",
"lazy_static",
"matchers",
- "parking_lot 0.11.2",
+ "parking_lot 0.10.2",
"regex",
"serde",
"serde_json",
client/rpc/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use std::sync::Arc;1819use codec::Decode;20use jsonrpc_core::{Error as RpcError, ErrorCode, Result};21use jsonrpc_derive::rpc;22use up_data_structs::{Collection, CollectionId, CollectionStats, TokenId};23use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};24use sp_blockchain::HeaderBackend;25use up_rpc::UniqueApi as UniqueRuntimeApi;2627#[rpc]28pub trait UniqueApi<BlockHash, CrossAccountId, AccountId> {29 #[rpc(name = "unique_accountTokens")]30 fn account_tokens(31 &self,32 collection: CollectionId,33 account: CrossAccountId,34 at: Option<BlockHash>,35 ) -> Result<Vec<TokenId>>;36 #[rpc(name = "unique_tokenExists")]37 fn token_exists(38 &self,39 collection: CollectionId,40 token: TokenId,41 at: Option<BlockHash>,42 ) -> Result<bool>;4344 #[rpc(name = "unique_tokenOwner")]45 fn token_owner(46 &self,47 collection: CollectionId,48 token: TokenId,49 at: Option<BlockHash>,50 ) -> Result<Option<CrossAccountId>>;51 #[rpc(name = "unique_constMetadata")]52 fn const_metadata(53 &self,54 collection: CollectionId,55 token: TokenId,56 at: Option<BlockHash>,57 ) -> Result<Vec<u8>>;58 #[rpc(name = "unique_variableMetadata")]59 fn variable_metadata(60 &self,61 collection: CollectionId,62 token: TokenId,63 at: Option<BlockHash>,64 ) -> Result<Vec<u8>>;6566 #[rpc(name = "unique_collectionTokens")]67 fn collection_tokens(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;68 #[rpc(name = "unique_accountBalance")]69 fn account_balance(70 &self,71 collection: CollectionId,72 account: CrossAccountId,73 at: Option<BlockHash>,74 ) -> Result<u32>;75 #[rpc(name = "unique_balance")]76 fn balance(77 &self,78 collection: CollectionId,79 account: CrossAccountId,80 token: TokenId,81 at: Option<BlockHash>,82 ) -> Result<String>;83 #[rpc(name = "unique_allowance")]84 fn allowance(85 &self,86 collection: CollectionId,87 sender: CrossAccountId,88 spender: CrossAccountId,89 token: TokenId,90 at: Option<BlockHash>,91 ) -> Result<String>;9293 #[rpc(name = "unique_adminlist")]94 fn adminlist(95 &self,96 collection: CollectionId,97 at: Option<BlockHash>,98 ) -> Result<Vec<CrossAccountId>>;99 #[rpc(name = "unique_allowlist")]100 fn allowlist(101 &self,102 collection: CollectionId,103 at: Option<BlockHash>,104 ) -> Result<Vec<CrossAccountId>>;105 #[rpc(name = "unique_allowed")]106 fn allowed(107 &self,108 collection: CollectionId,109 user: CrossAccountId,110 at: Option<BlockHash>,111 ) -> Result<bool>;112 #[rpc(name = "unique_lastTokenId")]113 fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;114 #[rpc(name = "unique_collectionById")]115 fn collection_by_id(116 &self,117 collection: CollectionId,118 at: Option<BlockHash>,119 ) -> Result<Option<Collection<AccountId>>>;120 #[rpc(name = "unique_collectionStats")]121 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;122}123124pub struct Unique<C, P> {125 client: Arc<C>,126 _marker: std::marker::PhantomData<P>,127}128129impl<C, P> Unique<C, P> {130 pub fn new(client: Arc<C>) -> Self {131 Self {132 client,133 _marker: Default::default(),134 }135 }136}137138pub enum Error {139 RuntimeError,140}141142impl From<Error> for i64 {143 fn from(e: Error) -> i64 {144 match e {145 Error::RuntimeError => 1,146 }147 }148}149150macro_rules! pass_method {151 (152 $method_name:ident($($name:ident: $ty:ty),* $(,)?) -> $result:ty $(=> $mapper:expr)?153 $(; changed_in $ver:expr, $changed_method_name:ident ($($changed_name:expr), * $(,)?) => $fixer:expr)*154 ) => {155 fn $method_name(156 &self,157 $(158 $name: $ty,159 )*160 at: Option<<Block as BlockT>::Hash>,161 ) -> Result<$result> {162 let api = self.client.runtime_api();163 let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));164 let _api_version = if let Ok(Some(api_version)) =165 api.api_version::<dyn UniqueRuntimeApi<Block, CrossAccountId, AccountId>>(&at)166 {167 api_version168 } else {169 // unreachable for our runtime170 return Err(RpcError {171 code: ErrorCode::InvalidParams,172 message: "Api is not available".into(),173 data: None,174 })175 };176177 let result = $(if _api_version < $ver {178 api.$changed_method_name(&at, $($changed_name),*).map(|r| r.map($fixer))179 } else)*180 { api.$method_name(&at, $($name),*) };181182 let result = result.map_err(|e| RpcError {183 code: ErrorCode::ServerError(Error::RuntimeError.into()),184 message: "Unable to query".into(),185 data: Some(format!("{:?}", e).into()),186 })?;187 result.map_err(|e| RpcError {188 code: ErrorCode::InvalidParams,189 message: "Runtime returned error".into(),190 data: Some(format!("{:?}", e).into()),191 })$(.map($mapper))?192 }193 };194}195196#[allow(deprecated)]197impl<C, Block, CrossAccountId, AccountId>198 UniqueApi<<Block as BlockT>::Hash, CrossAccountId, AccountId> for Unique<C, Block>199where200 Block: BlockT,201 AccountId: Decode,202 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,203 C::Api: UniqueRuntimeApi<Block, CrossAccountId, AccountId>,204 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,205{206 pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>);207 pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool);208 pass_method!(209 token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>;210 changed_in 2, token_owner_before_version_2(collection, token) => |u| Some(u)211 );212 pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);213 pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);214 pass_method!(collection_tokens(collection: CollectionId) -> u32);215 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);216 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());217 pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());218219 pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>);220 pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>);221 pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool);222 pass_method!(last_token_id(collection: CollectionId) -> TokenId);223 pass_method!(collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>);224 pass_method!(collection_stats() -> CollectionStats);225}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use std::sync::Arc;1819use codec::Decode;20use jsonrpc_core::{Error as RpcError, ErrorCode, Result};21use jsonrpc_derive::rpc;22use up_data_structs::{Collection, CollectionId, CollectionStats, CollectionLimits, TokenId};23use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};24use sp_blockchain::HeaderBackend;25use up_rpc::UniqueApi as UniqueRuntimeApi;2627#[rpc]28pub trait UniqueApi<BlockHash, CrossAccountId, AccountId> {29 #[rpc(name = "unique_accountTokens")]30 fn account_tokens(31 &self,32 collection: CollectionId,33 account: CrossAccountId,34 at: Option<BlockHash>,35 ) -> Result<Vec<TokenId>>;36 #[rpc(name = "unique_tokenExists")]37 fn token_exists(38 &self,39 collection: CollectionId,40 token: TokenId,41 at: Option<BlockHash>,42 ) -> Result<bool>;4344 #[rpc(name = "unique_tokenOwner")]45 fn token_owner(46 &self,47 collection: CollectionId,48 token: TokenId,49 at: Option<BlockHash>,50 ) -> Result<Option<CrossAccountId>>;51 #[rpc(name = "unique_constMetadata")]52 fn const_metadata(53 &self,54 collection: CollectionId,55 token: TokenId,56 at: Option<BlockHash>,57 ) -> Result<Vec<u8>>;58 #[rpc(name = "unique_variableMetadata")]59 fn variable_metadata(60 &self,61 collection: CollectionId,62 token: TokenId,63 at: Option<BlockHash>,64 ) -> Result<Vec<u8>>;6566 #[rpc(name = "unique_collectionTokens")]67 fn collection_tokens(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;68 #[rpc(name = "unique_accountBalance")]69 fn account_balance(70 &self,71 collection: CollectionId,72 account: CrossAccountId,73 at: Option<BlockHash>,74 ) -> Result<u32>;75 #[rpc(name = "unique_balance")]76 fn balance(77 &self,78 collection: CollectionId,79 account: CrossAccountId,80 token: TokenId,81 at: Option<BlockHash>,82 ) -> Result<String>;83 #[rpc(name = "unique_allowance")]84 fn allowance(85 &self,86 collection: CollectionId,87 sender: CrossAccountId,88 spender: CrossAccountId,89 token: TokenId,90 at: Option<BlockHash>,91 ) -> Result<String>;9293 #[rpc(name = "unique_adminlist")]94 fn adminlist(95 &self,96 collection: CollectionId,97 at: Option<BlockHash>,98 ) -> Result<Vec<CrossAccountId>>;99 #[rpc(name = "unique_allowlist")]100 fn allowlist(101 &self,102 collection: CollectionId,103 at: Option<BlockHash>,104 ) -> Result<Vec<CrossAccountId>>;105 #[rpc(name = "unique_allowed")]106 fn allowed(107 &self,108 collection: CollectionId,109 user: CrossAccountId,110 at: Option<BlockHash>,111 ) -> Result<bool>;112 #[rpc(name = "unique_lastTokenId")]113 fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;114 #[rpc(name = "unique_collectionById")]115 fn collection_by_id(116 &self,117 collection: CollectionId,118 at: Option<BlockHash>,119 ) -> Result<Option<Collection<AccountId>>>;120 #[rpc(name = "unique_collectionStats")]121 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;122 #[rpc(name = "unique_effectiveCollectionLimits")]123 fn effective_collection_limits(124 &self,125 collection_id: CollectionId,126 at: Option<BlockHash>,127 ) -> Result<Option<CollectionLimits>>;128}129130pub struct Unique<C, P> {131 client: Arc<C>,132 _marker: std::marker::PhantomData<P>,133}134135impl<C, P> Unique<C, P> {136 pub fn new(client: Arc<C>) -> Self {137 Self {138 client,139 _marker: Default::default(),140 }141 }142}143144pub enum Error {145 RuntimeError,146}147148impl From<Error> for i64 {149 fn from(e: Error) -> i64 {150 match e {151 Error::RuntimeError => 1,152 }153 }154}155156macro_rules! pass_method {157 (158 $method_name:ident($($name:ident: $ty:ty),* $(,)?) -> $result:ty $(=> $mapper:expr)?159 $(; changed_in $ver:expr, $changed_method_name:ident ($($changed_name:expr), * $(,)?) => $fixer:expr)*160 ) => {161 fn $method_name(162 &self,163 $(164 $name: $ty,165 )*166 at: Option<<Block as BlockT>::Hash>,167 ) -> Result<$result> {168 let api = self.client.runtime_api();169 let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));170 let _api_version = if let Ok(Some(api_version)) =171 api.api_version::<dyn UniqueRuntimeApi<Block, CrossAccountId, AccountId>>(&at)172 {173 api_version174 } else {175 // unreachable for our runtime176 return Err(RpcError {177 code: ErrorCode::InvalidParams,178 message: "Api is not available".into(),179 data: None,180 })181 };182183 let result = $(if _api_version < $ver {184 api.$changed_method_name(&at, $($changed_name),*).map(|r| r.map($fixer))185 } else)*186 { api.$method_name(&at, $($name),*) };187188 let result = result.map_err(|e| RpcError {189 code: ErrorCode::ServerError(Error::RuntimeError.into()),190 message: "Unable to query".into(),191 data: Some(format!("{:?}", e).into()),192 })?;193 result.map_err(|e| RpcError {194 code: ErrorCode::InvalidParams,195 message: "Runtime returned error".into(),196 data: Some(format!("{:?}", e).into()),197 })$(.map($mapper))?198 }199 };200}201202#[allow(deprecated)]203impl<C, Block, CrossAccountId, AccountId>204 UniqueApi<<Block as BlockT>::Hash, CrossAccountId, AccountId> for Unique<C, Block>205where206 Block: BlockT,207 AccountId: Decode,208 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,209 C::Api: UniqueRuntimeApi<Block, CrossAccountId, AccountId>,210 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,211{212 pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>);213 pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool);214 pass_method!(215 token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>;216 changed_in 2, token_owner_before_version_2(collection, token) => |u| Some(u)217 );218 pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);219 pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);220 pass_method!(collection_tokens(collection: CollectionId) -> u32);221 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);222 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());223 pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());224225 pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>);226 pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>);227 pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool);228 pass_method!(last_token_id(collection: CollectionId) -> TokenId);229 pass_method!(collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>);230 pass_method!(collection_stats() -> CollectionStats);231 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>);232}pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -33,7 +33,7 @@
TokenId, Weight, WithdrawReasons, CollectionStats, MAX_TOKEN_OWNERSHIP, CollectionMode,
NFT_SPONSOR_TRANSFER_TIMEOUT, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT, CUSTOM_DATA_LIMIT, CollectionLimits,
- CustomDataLimit, CreateCollectionData, SponsorshipState, CreateItemExData,
+ CustomDataLimit, CreateCollectionData, SponsorshipState, CreateItemExData, SponsoringRateLimit,
};
pub use pallet::*;
use sp_core::H160;
@@ -417,6 +417,39 @@
alive: created.0 - destroyed.0,
}
}
+
+ pub fn effective_collection_limits(collection: CollectionId) -> Option<CollectionLimits> {
+ let collection = <CollectionById<T>>::get(collection);
+ if collection.is_none() {
+ return None;
+ }
+
+ let collection = collection.unwrap();
+ let limits = collection.limits;
+ let effective_limits = CollectionLimits {
+ account_token_ownership_limit: Some(limits.account_token_ownership_limit()),
+ sponsored_data_size: Some(limits.sponsored_data_size()),
+ sponsored_data_rate_limit: Some(
+ limits
+ .sponsored_data_rate_limit
+ .unwrap_or(SponsoringRateLimit::SponsoringDisabled),
+ ),
+ token_limit: Some(limits.token_limit()),
+ sponsor_transfer_timeout: Some(limits.sponsor_transfer_timeout(
+ match collection.mode {
+ CollectionMode::NFT => NFT_SPONSOR_TRANSFER_TIMEOUT,
+ CollectionMode::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
+ CollectionMode::ReFungible => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
+ },
+ )),
+ sponsor_approve_timeout: Some(limits.sponsor_approve_timeout()),
+ owner_can_transfer: Some(limits.owner_can_transfer()),
+ owner_can_destroy: Some(limits.owner_can_destroy()),
+ transfers_enabled: Some(limits.transfers_enabled()),
+ };
+
+ Some(effective_limits)
+ }
}
impl<T: Config> Pallet<T> {
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -16,7 +16,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use up_data_structs::{CollectionId, TokenId, Collection, CollectionStats};
+use up_data_structs::{CollectionId, TokenId, Collection, CollectionStats, CollectionLimits};
use sp_std::vec::Vec;
use sp_core::H160;
use codec::Decode;
@@ -59,5 +59,6 @@
fn last_token_id(collection: CollectionId) -> Result<TokenId>;
fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>>;
fn collection_stats() -> Result<CollectionStats>;
+ fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;
}
}
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -69,6 +69,10 @@
fn collection_stats() -> Result<CollectionStats, DispatchError> {
Ok(<pallet_common::Pallet<Runtime>>::collection_stats())
}
+
+ fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {
+ Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))
+ }
}
impl sp_api::Core<Block> for Runtime {
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -67,6 +67,7 @@
"testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
"testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
"testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
+ "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.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",
"polkadot-types-from-defs": "echo 'export default {}' > src/interfaces/lookup.ts && ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",
"polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",
tests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-rpc.ts
+++ b/tests/src/interfaces/augment-api-rpc.ts
@@ -1,7 +1,7 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
-import type { PalletEvmAccountBasicCrossAccountIdRepr, UpDataStructsCollection, UpDataStructsCollectionStats } from './unique';
+import type { PalletEvmAccountBasicCrossAccountIdRepr, UpDataStructsCollection, UpDataStructsCollectionStats, UpDataStructsCollectionStats } from './unique';
import type { AugmentedRpc } from '@polkadot/rpc-core/types';
import type { Metadata, StorageKey } from '@polkadot/types';
import type { Bytes, HashMap, Json, Null, Option, Text, U256, U64, Vec, bool, u128, u32, u64 } from '@polkadot/types-codec';
@@ -604,6 +604,10 @@
**/
constMetadata: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Bytes>>;
/**
+ * Get effective collection limits
+ **/
+ effectiveCollectionLimits: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<UpDataStructsCollectionLimits>>>;
+ /**
* Get last token id
**/
lastTokenId: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<u32>>;
tests/src/interfaces/unique/definitions.tsdiffbeforeafterboth--- a/tests/src/interfaces/unique/definitions.ts
+++ b/tests/src/interfaces/unique/definitions.ts
@@ -55,5 +55,6 @@
collectionById: fun('Get collection by specified id', [collectionParam], 'Option<UpDataStructsCollection>'),
collectionStats: fun('Get collection stats', [], 'UpDataStructsCollectionStats'),
allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),
+ effectiveCollectionLimits: fun('Get effective collection limits', [collectionParam], 'Option<UpDataStructsCollectionLimits>'),
},
};
tests/src/limits.test.tsdiffbeforeafterboth--- a/tests/src/limits.test.ts
+++ b/tests/src/limits.test.ts
@@ -395,4 +395,73 @@
expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);
});
+
+ it('Effective collection limits', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+
+ { // Check that limits is undefined
+ const collection = await api.rpc.unique.collectionById(collectionId);
+ expect(collection.isSome).to.be.true;
+ const limits = collection.unwrap().limits;
+ expect(limits).to.be.any;
+
+ expect(limits.accountTokenOwnershipLimit.toHuman()).to.be.null;
+ expect(limits.sponsoredDataSize.toHuman()).to.be.null;
+ expect(limits.sponsoredDataRateLimit.toHuman()).to.be.null;
+ expect(limits.tokenLimit.toHuman()).to.be.null;
+ expect(limits.sponsorTransferTimeout.toHuman()).to.be.null;
+ expect(limits.sponsorApproveTimeout.toHuman()).to.be.null;
+ expect(limits.ownerCanTransfer.toHuman()).to.be.null;
+ expect(limits.ownerCanDestroy.toHuman()).to.be.null;
+ expect(limits.transfersEnabled.toHuman()).to.be.null;
+ }
+
+ { // Check that limits is undefined for non-existent collection
+ const limits = await api.rpc.unique.effectiveCollectionLimits(11111);
+ expect(limits.toHuman()).to.be.null;
+ }
+
+ { // Check that default values defined for collection limits
+ const limitsOpt = await api.rpc.unique.effectiveCollectionLimits(collectionId);
+ expect(limitsOpt.isNone).to.be.false;
+ const limits = limitsOpt.unwrap();
+
+ expect(limits.accountTokenOwnershipLimit.toHuman()).to.be.eq('100,000');
+ expect(limits.sponsoredDataSize.toHuman()).to.be.eq('2,048');
+ expect(limits.sponsoredDataRateLimit.toHuman()).to.be.eq('SponsoringDisabled');
+ expect(limits.tokenLimit.toHuman()).to.be.eq('4,294,967,295');
+ expect(limits.sponsorTransferTimeout.toHuman()).to.be.eq('5');
+ expect(limits.sponsorApproveTimeout.toHuman()).to.be.eq('5');
+ expect(limits.ownerCanTransfer.toHuman()).to.be.true;
+ expect(limits.ownerCanDestroy.toHuman()).to.be.true;
+ expect(limits.transfersEnabled.toHuman()).to.be.true;
+ }
+
+ { //Check the values for collection limits
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {
+ accountTokenOwnershipLimit: 99_999,
+ sponsoredDataSize: 1024,
+ tokenLimit: 123,
+ transfersEnabled: false,
+ });
+
+ const limitsOpt = await api.rpc.unique.effectiveCollectionLimits(collectionId);
+ expect(limitsOpt.isNone).to.be.false;
+ const limits = limitsOpt.unwrap();
+
+ expect(limits.accountTokenOwnershipLimit.toHuman()).to.be.eq('99,999');
+ expect(limits.sponsoredDataSize.toHuman()).to.be.eq('1,024');
+ expect(limits.sponsoredDataRateLimit.toHuman()).to.be.eq('SponsoringDisabled');
+ expect(limits.tokenLimit.toHuman()).to.be.eq('123');
+ expect(limits.sponsorTransferTimeout.toHuman()).to.be.eq('5');
+ expect(limits.sponsorApproveTimeout.toHuman()).to.be.eq('5');
+ expect(limits.ownerCanTransfer.toHuman()).to.be.true;
+ expect(limits.ownerCanDestroy.toHuman()).to.be.true;
+ expect(limits.transfersEnabled.toHuman()).to.be.false;
+ }
+ });
+ });
});
+
+