difftreelog
refactor use rpcs instead of api.query.common
in: master
33 files changed
client/rpc/src/lib.rsdiffbeforeafterboth3use codec::Decode;3use codec::Decode;4use jsonrpc_core::{Error as RpcError, ErrorCode, Result};4use jsonrpc_core::{Error as RpcError, ErrorCode, Result};5use jsonrpc_derive::rpc;5use jsonrpc_derive::rpc;6use nft_data_structs::{CollectionId, TokenId};6use nft_data_structs::{Collection, CollectionId, CollectionStats, TokenId};7use sp_api::{BlockId, BlockT, ProvideRuntimeApi};7use sp_api::{BlockId, BlockT, ProvideRuntimeApi};8use sp_blockchain::HeaderBackend;8use sp_blockchain::HeaderBackend;9use up_rpc::NftApi as NftRuntimeApi;9use up_rpc::NftApi as NftRuntimeApi;86 collection: CollectionId,86 collection: CollectionId,87 at: Option<BlockHash>,87 at: Option<BlockHash>,88 ) -> Result<Vec<CrossAccountId>>;88 ) -> Result<Vec<CrossAccountId>>;89 #[rpc(name = "nft_allowed")]90 fn allowed(91 &self,92 collection: CollectionId,93 user: CrossAccountId,94 at: Option<BlockHash>,95 ) -> Result<bool>;89 #[rpc(name = "nft_lastTokenId")]96 #[rpc(name = "nft_lastTokenId")]90 fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;97 fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;98 #[rpc(name = "nft_collectionById")]99 fn collection_by_id(100 &self,101 collection: CollectionId,102 at: Option<BlockHash>,103 ) -> Result<Option<Collection<AccountId>>>;104 #[rpc(name = "nft_collectionStats")]105 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;91}106}9210793pub struct Nft<C, P> {108pub struct Nft<C, P> {160175161 pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>);176 pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>);162 pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>);177 pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>);178 pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool);163 pass_method!(last_token_id(collection: CollectionId) -> TokenId);179 pass_method!(last_token_id(collection: CollectionId) -> TokenId);180 pass_method!(collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>);181 pass_method!(collection_stats() -> CollectionStats);164}182}165183pallets/common/src/benchmarking.rsdiffbeforeafterboth19pub fn create_collection_raw<T: Config, R>(19pub fn create_collection_raw<T: Config, R>(20 owner: T::AccountId,20 owner: T::AccountId,21 mode: CollectionMode,21 mode: CollectionMode,22 handler: impl FnOnce(Collection<T>) -> Result<CollectionId, DispatchError>,22 handler: impl FnOnce(Collection<T::AccountId>) -> Result<CollectionId, DispatchError>,23 cast: impl FnOnce(CollectionHandle<T>) -> R,23 cast: impl FnOnce(CollectionHandle<T>) -> R,24) -> Result<R, DispatchError> {24) -> Result<R, DispatchError> {25 T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());25 T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());pallets/common/src/lib.rsdiffbeforeafterboth12 COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, ExistenceRequirement,12 COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, ExistenceRequirement,13 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH,13 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH,14 COLLECTION_ADMINS_LIMIT, MetaUpdatePermission, Pays, PostDispatchInfo, TokenId, Weight,14 COLLECTION_ADMINS_LIMIT, MetaUpdatePermission, Pays, PostDispatchInfo, TokenId, Weight,15 WithdrawReasons,15 WithdrawReasons, CollectionStats,16};16};17pub use pallet::*;17pub use pallet::*;18use sp_core::H160;18use sp_core::H160;26#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]26#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]27pub struct CollectionHandle<T: Config> {27pub struct CollectionHandle<T: Config> {28 pub id: CollectionId,28 pub id: CollectionId,29 collection: Collection<T>,29 collection: Collection<T::AccountId>,30 pub recorder: pallet_evm_coder_substrate::SubstrateRecorder<T>,30 pub recorder: pallet_evm_coder_substrate::SubstrateRecorder<T>,31}31}32impl<T: Config> CollectionHandle<T> {32impl<T: Config> CollectionHandle<T> {78 }78 }79}79}80impl<T: Config> Deref for CollectionHandle<T> {80impl<T: Config> Deref for CollectionHandle<T> {81 type Target = Collection<T>;81 type Target = Collection<T::AccountId>;828283 fn deref(&self) -> &Self::Target {83 fn deref(&self) -> &Self::Target {84 &self.collection84 &self.collection311 pub type CollectionById<T> = StorageMap<311 pub type CollectionById<T> = StorageMap<312 Hasher = Blake2_128Concat,312 Hasher = Blake2_128Concat,313 Key = CollectionId,313 Key = CollectionId,314 Value = Collection<T>,314 Value = Collection<<T as frame_system::Config>::AccountId>,315 QueryKind = OptionQuery,315 QueryKind = OptionQuery,316 >;316 >;317317345 QueryKind = ValueQuery,345 QueryKind = ValueQuery,346 >;346 >;347348 /// Not used by code, exists only to provide some types to metadata349 #[pallet::storage]350 pub type DummyStorageValue<T> = StorageValue<Value = (CollectionStats, CollectionId, TokenId), QueryKind = OptionQuery>;347}351}348352349impl<T: Config> Pallet<T> {353impl<T: Config> Pallet<T> {355 );359 );356 Ok(())360 Ok(())357 }361 }362 pub fn adminlist(collection: CollectionId) -> Vec<T::CrossAccountId> {363 <IsAdmin<T>>::iter_prefix((collection,))364 .map(|(a, _)| a)365 .collect()366 }367 pub fn allowlist(collection: CollectionId) -> Vec<T::CrossAccountId> {368 <Allowlist<T>>::iter_prefix((collection,))369 .map(|(a, _)| a)370 .collect()371 }372 pub fn allowed(collection: CollectionId, user: T::CrossAccountId) -> bool {373 <Allowlist<T>>::get((collection, user))374 }375 pub fn collection_stats() -> CollectionStats {376 let created = <CreatedCollectionCount<T>>::get();377 let destroyed = <DestroyedCollectionCount<T>>::get();378 CollectionStats {379 created: created.0,380 destroyed: destroyed.0,381 alive: created.0 - destroyed.0,382 }383 }358}384}359385360impl<T: Config> Pallet<T> {386impl<T: Config> Pallet<T> {361 pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {387 pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {362 {388 {363 ensure!(389 ensure!(364 data.name.len() <= MAX_COLLECTION_NAME_LENGTH,390 data.name.len() <= MAX_COLLECTION_NAME_LENGTH,pallets/fungible/src/lib.rsdiffbeforeafterboth91}91}929293impl<T: Config> Pallet<T> {93impl<T: Config> Pallet<T> {94 pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {94 pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {95 PalletCommon::init_collection(data)95 <PalletCommon<T>>::init_collection(data)96 }96 }97 pub fn destroy_collection(97 pub fn destroy_collection(98 collection: FungibleHandle<T>,98 collection: FungibleHandle<T>,pallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth25fn try_sponsor<T: Config>(25fn try_sponsor<T: Config>(26 caller: &H160,26 caller: &H160,27 collection_id: CollectionId,27 collection_id: CollectionId,28 collection: &Collection<T>,28 collection: &Collection<T::AccountId>,29 call: &[u8],29 call: &[u8],30) -> Result<(), AnyError> {30) -> Result<(), AnyError> {31 let (method_id, mut reader) = AbiReader::new_call(call).map_err(|_| AnyError)?;31 let (method_id, mut reader) = AbiReader::new_call(call).map_err(|_| AnyError)?;109 if !collection.sponsorship.confirmed() {109 if !collection.sponsorship.confirmed() {110 return None;110 return None;111 }111 }112 if try_sponsor(who, collection_id, &collection, &call.1).is_ok() {112 if try_sponsor::<T>(who, collection_id, &collection, &call.1).is_ok() {113 return collection113 return collection114 .sponsorship114 .sponsorship115 .sponsor()115 .sponsor()pallets/nft/src/lib.rsdiffbeforeafterboth42 CollectionId, CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,42 CollectionId, CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,43};43};44use pallet_common::{44use pallet_common::{45 account::CrossAccountId, CollectionHandle, IsAdmin, Pallet as PalletCommon,45 account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,46 Error as CommonError, CommonWeightInfo, Allowlist,46 CommonWeightInfo,47};47};48use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};48use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};49use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};49use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};190 let who = ensure_signed(origin)?;190 let who = ensure_signed(origin)?;191191192 // Create new collection192 // Create new collection193 let new_collection = Collection::<T> {193 let new_collection = Collection {194 owner: who.clone(),194 owner: who.clone(),195 name: collection_name,195 name: collection_name,196 mode: mode.clone(),196 mode: mode.clone(),208 };208 };209209210 let _id = match mode {210 let _id = match mode {211 CollectionMode::NFT => {PalletNonfungible::init_collection(new_collection)?},211 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(new_collection)?},212 CollectionMode::Fungible(decimal_points) => {212 CollectionMode::Fungible(decimal_points) => {213 // check params213 // check params214 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);214 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);215 PalletFungible::init_collection(new_collection)?215 <PalletFungible<T>>::init_collection(new_collection)?216 }216 }217 CollectionMode::ReFungible => {217 CollectionMode::ReFungible => {218 PalletRefungible::init_collection(new_collection)?218 <PalletRefungible<T>>::init_collection(new_collection)?219 }219 }220 };220 };221221939 }939 }940}940}941942// TODO: limit returned entries?943impl<T: Config> Pallet<T> {944 pub fn adminlist(collection: CollectionId) -> Vec<T::CrossAccountId> {945 <IsAdmin<T>>::iter_prefix((collection,))946 .map(|(a, _)| a)947 .collect()948 }949 pub fn allowlist(collection: CollectionId) -> Vec<T::CrossAccountId> {950 <Allowlist<T>>::iter_prefix((collection,))951 .map(|(a, _)| a)952 .collect()953 }954}955941pallets/nonfungible/src/lib.rsdiffbeforeafterboth133133134// unchecked calls skips any permission checks134// unchecked calls skips any permission checks135impl<T: Config> Pallet<T> {135impl<T: Config> Pallet<T> {136 pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {136 pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {137 PalletCommon::init_collection(data)137 <PalletCommon<T>>::init_collection(data)138 }138 }139 pub fn destroy_collection(139 pub fn destroy_collection(140 collection: NonfungibleHandle<T>,140 collection: NonfungibleHandle<T>,pallets/refungible/src/lib.rsdiffbeforeafterboth156156157// unchecked calls skips any permission checks157// unchecked calls skips any permission checks158impl<T: Config> Pallet<T> {158impl<T: Config> Pallet<T> {159 pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {159 pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {160 PalletCommon::init_collection(data)160 <PalletCommon<T>>::init_collection(data)161 }161 }162 pub fn destroy_collection(162 pub fn destroy_collection(163 collection: RefungibleHandle<T>,163 collection: RefungibleHandle<T>,primitives/nft/src/lib.rsdiffbeforeafterboth207207208#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]208#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]209#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]209#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]210pub struct Collection<T: frame_system::Config> {210pub struct Collection<AccountId> {211 pub owner: T::AccountId,211 pub owner: AccountId,212 pub mode: CollectionMode,212 pub mode: CollectionMode,213 pub access: AccessMode,213 pub access: AccessMode,214 pub name: Vec<u16>, // 64 include null escape char214 pub name: Vec<u16>, // 64 include null escape char217 pub mint_mode: bool,217 pub mint_mode: bool,218 pub offchain_schema: Vec<u8>,218 pub offchain_schema: Vec<u8>,219 pub schema_version: SchemaVersion,219 pub schema_version: SchemaVersion,220 pub sponsorship: SponsorshipState<T::AccountId>,220 pub sponsorship: SponsorshipState<AccountId>,221 pub limits: CollectionLimits, // Collection private restrictions221 pub limits: CollectionLimits, // Collection private restrictions222 pub variable_on_chain_schema: Vec<u8>, //222 pub variable_on_chain_schema: Vec<u8>, //223 pub const_on_chain_schema: Vec<u8>, //223 pub const_on_chain_schema: Vec<u8>, //414 }414 }415}415}416417#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]418#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]419pub struct CollectionStats {420 pub created: u32,421 pub destroyed: u32,422 pub alive: u32,423}416424primitives/rpc/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]1#![cfg_attr(not(feature = "std"), no_std)]223use nft_data_structs::{CollectionId, TokenId};3use nft_data_structs::{CollectionId, TokenId, Collection, CollectionStats};4use sp_std::vec::Vec;4use sp_std::vec::Vec;5use sp_core::H160;5use sp_core::H160;6use codec::Decode;6use codec::Decode;323233 fn adminlist(collection: CollectionId) -> Vec<CrossAccountId>;33 fn adminlist(collection: CollectionId) -> Vec<CrossAccountId>;34 fn allowlist(collection: CollectionId) -> Vec<CrossAccountId>;34 fn allowlist(collection: CollectionId) -> Vec<CrossAccountId>;35 fn allowed(collection: CollectionId, user: CrossAccountId) -> bool;35 fn last_token_id(collection: CollectionId) -> TokenId;36 fn last_token_id(collection: CollectionId) -> TokenId;37 fn collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>;38 fn collection_stats() -> CollectionStats;36 }39 }37}40}3841runtime/src/lib.rsdiffbeforeafterboth1040 .or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))1040 .or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))1041 }1041 }1042 fn adminlist(collection: CollectionId) -> Vec<CrossAccountId> {1042 fn adminlist(collection: CollectionId) -> Vec<CrossAccountId> {1043 <pallet_nft::Pallet<Runtime>>::adminlist(collection)1043 <pallet_common::Pallet<Runtime>>::adminlist(collection)1044 }1044 }1045 fn allowlist(collection: CollectionId) -> Vec<CrossAccountId> {1045 fn allowlist(collection: CollectionId) -> Vec<CrossAccountId> {1046 <pallet_nft::Pallet<Runtime>>::allowlist(collection)1046 <pallet_common::Pallet<Runtime>>::allowlist(collection)1047 }1047 }1048 fn allowed(collection: CollectionId, user: CrossAccountId) -> bool {1049 <pallet_common::Pallet<Runtime>>::allowed(collection, user)1050 }1048 fn last_token_id(collection: CollectionId) -> TokenId {1051 fn last_token_id(collection: CollectionId) -> TokenId {1049 dispatch_nft_runtime!(collection.last_token_id())1052 dispatch_nft_runtime!(collection.last_token_id())1050 }1053 }1054 fn collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>> {1055 <pallet_common::CollectionById<Runtime>>::get(collection)1056 }1057 fn collection_stats() -> CollectionStats {1058 <pallet_common::Pallet<Runtime>>::collection_stats()1059 }1051 }1060 }105210611053 impl sp_api::Core<Block> for Runtime {1062 impl sp_api::Core<Block> for Runtime {tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth8import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId} from './util/helpers';11import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';121213chai.use(chaiAsPromised);13chai.use(chaiAsPromised);14const expect = chai.expect;14const expect = chai.expect;20 const alice = privateKey('//Alice');20 const alice = privateKey('//Alice');21 const bob = privateKey('//Bob');21 const bob = privateKey('//Bob');222223 const collection = (await api.query.common.collectionById(collectionId)).unwrap();23 const collection = await queryCollectionExpectSuccess(api, collectionId);24 expect(collection.owner.toString()).to.be.equal(alice.address);24 expect(collection.owner.toString()).to.be.equal(alice.address);252526 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));26 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));38 const bob = privateKey('//Bob');38 const bob = privateKey('//Bob');39 const charlie = privateKey('//CHARLIE');39 const charlie = privateKey('//CHARLIE');404041 const collection = (await api.query.common.collectionById(collectionId)).unwrap();41 const collection = await queryCollectionExpectSuccess(api, collectionId);42 expect(collection.owner.toString()).to.be.equal(alice.address);42 expect(collection.owner.toString()).to.be.equal(alice.address);434344 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));44 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));tests/src/addToAllowList.test.tsdiffbeforeafterboth18 normalizeAccountId,18 normalizeAccountId,19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,20 addToAllowListExpectFail,20 addToAllowListExpectFail,21 getCreatedCollectionCount,21} from './util/helpers';22} from './util/helpers';222323chai.use(chaiAsPromised);24chai.use(chaiAsPromised);55 it('Allow list an address in the collection that does not exist', async () => {56 it('Allow list an address in the collection that does not exist', async () => {56 await usingApi(async (api) => {57 await usingApi(async (api) => {57 // tslint:disable-next-line: no-bitwise58 // tslint:disable-next-line: no-bitwise58 const collectionId = ((await api.query.common.createdCollectionCount()).toNumber()) + 1;59 const collectionId = await getCreatedCollectionCount(api) + 1;59 const bob = privateKey('//Bob');60 const bob = privateKey('//Bob');606161 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));62 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));tests/src/approve.test.tsdiffbeforeafterboth18 transferExpectSuccess,18 transferExpectSuccess,19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,20 adminApproveFromExpectSuccess,20 adminApproveFromExpectSuccess,21 getCreatedCollectionCount,21} from './util/helpers';22} from './util/helpers';222323chai.use(chaiAsPromised);24chai.use(chaiAsPromised);94 it('Approve for a collection that does not exist', async () => {95 it('Approve for a collection that does not exist', async () => {95 await usingApi(async (api: ApiPromise) => {96 await usingApi(async (api: ApiPromise) => {96 // nft97 // nft97 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();98 const nftCollectionCount = await getCreatedCollectionCount(api);98 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);99 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);99 // fungible100 // fungible100 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();101 const fungibleCollectionCount = await getCreatedCollectionCount(api);101 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);102 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);102 // reFungible103 // reFungible103 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();104 const reFungibleCollectionCount = await getCreatedCollectionCount(api);104 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);105 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);105 });106 });106 });107 });tests/src/change-collection-owner.test.tsdiffbeforeafterboth22 setMintPermissionExpectFailure,22 setMintPermissionExpectFailure,23 destroyCollectionExpectFailure,23 destroyCollectionExpectFailure,24 setPublicAccessModeExpectSuccess,24 setPublicAccessModeExpectSuccess,25 queryCollectionExpectSuccess,25} from './util/helpers';26} from './util/helpers';262727chai.use(chaiAsPromised);28chai.use(chaiAsPromised);34 const alice = privateKey('//Alice');35 const alice = privateKey('//Alice');35 const bob = privateKey('//Bob');36 const bob = privateKey('//Bob');363737 const collection = (await api.query.common.collectionById(collectionId)).unwrap();38 const collection =await queryCollectionExpectSuccess(api, collectionId);38 expect(collection.owner.toString()).to.be.deep.eq(alice.address);39 expect(collection.owner.toString()).to.be.deep.eq(alice.address);394040 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);41 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);41 await submitTransactionAsync(alice, changeOwnerTx);42 await submitTransactionAsync(alice, changeOwnerTx);424343 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();44 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);44 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);45 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);45 });46 });46 });47 });53 const alice = privateKey('//Alice');54 const alice = privateKey('//Alice');54 const bob = privateKey('//Bob');55 const bob = privateKey('//Bob');555656 const collection = (await api.query.common.collectionById(collectionId)).unwrap();57 const collection = await queryCollectionExpectSuccess(api, collectionId);57 expect(collection.owner.toString()).to.be.deep.eq(alice.address);58 expect(collection.owner.toString()).to.be.deep.eq(alice.address);585959 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);60 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);62 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);63 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);63 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;64 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;646565 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();66 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);66 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);67 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);67 });68 });68 });69 });74 const bob = privateKey('//Bob');75 const bob = privateKey('//Bob');75 const charlie = privateKey('//Charlie');76 const charlie = privateKey('//Charlie');767777 const collection = (await api.query.common.collectionById(collectionId)).unwrap();78 const collection = await queryCollectionExpectSuccess(api, collectionId);78 expect(collection.owner.toString()).to.be.deep.eq(alice.address);79 expect(collection.owner.toString()).to.be.deep.eq(alice.address);798080 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);81 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);81 await submitTransactionAsync(alice, changeOwnerTx);82 await submitTransactionAsync(alice, changeOwnerTx);828383 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();84 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);84 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);85 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);858686 // After changing the owner of the collection, all privileged methods are available to the new owner87 // After changing the owner of the collection, all privileged methods are available to the new owner118 const bob = privateKey('//Bob');119 const bob = privateKey('//Bob');119 const charlie = privateKey('//Charlie');120 const charlie = privateKey('//Charlie');120121121 const collection = (await api.query.common.collectionById(collectionId)).unwrap();122 const collection = await queryCollectionExpectSuccess(api, collectionId);122 expect(collection.owner.toString()).to.be.deep.eq(alice.address);123 expect(collection.owner.toString()).to.be.deep.eq(alice.address);123124124 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);125 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);125 await submitTransactionAsync(alice, changeOwnerTx);126 await submitTransactionAsync(alice, changeOwnerTx);126127127 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();128 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);128 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);129 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);129130130 const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);131 const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);131 await submitTransactionAsync(bob, changeOwnerTx2);132 await submitTransactionAsync(bob, changeOwnerTx2);132133133 // ownership lost134 // ownership lost134 const collectionAfterOwnerChange2 = (await api.query.common.collectionById(collectionId)).unwrap();135 const collectionAfterOwnerChange2 = await queryCollectionExpectSuccess(api, collectionId);135 expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);136 expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);136 });137 });137 });138 });147 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);148 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);148 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;149 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;149150150 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();151 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);151 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);152 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);152153153 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)154 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)166 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);167 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);167 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;168 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;168169169 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();170 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);170 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);171 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);171172172 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)173 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)195 const bob = privateKey('//Bob');196 const bob = privateKey('//Bob');196 const charlie = privateKey('//Charlie');197 const charlie = privateKey('//Charlie');197198198 const collection = (await api.query.common.collectionById(collectionId)).unwrap();199 const collection = await queryCollectionExpectSuccess(api, collectionId);199 expect(collection.owner.toString()).to.be.deep.eq(alice.address);200 expect(collection.owner.toString()).to.be.deep.eq(alice.address);200201201 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);202 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);204 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);205 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);205 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;206 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;206207207 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();208 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);208 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);209 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);209210210 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');211 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');tests/src/confirmSponsorship.test.tsdiffbeforeafterboth20 addToAllowListExpectSuccess,20 addToAllowListExpectSuccess,21 normalizeAccountId,21 normalizeAccountId,22 addCollectionAdminExpectSuccess,22 addCollectionAdminExpectSuccess,23 getCreatedCollectionCount,23} from './util/helpers';24} from './util/helpers';24import {Keyring} from '@polkadot/api';25import {Keyring} from '@polkadot/api';25import {IKeyringPair} from '@polkadot/types/types';26import {IKeyringPair} from '@polkadot/types/types';335 // Find the collection that never existed336 // Find the collection that never existed336 let collectionId = 0;337 let collectionId = 0;337 await usingApi(async (api) => {338 await usingApi(async (api) => {338 collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;339 collectionId = await getCreatedCollectionCount(api) + 1;339 });340 });340341341 await confirmSponsorshipExpectFailure(collectionId, '//Bob');342 await confirmSponsorshipExpectFailure(collectionId, '//Bob');tests/src/contracts.test.tsdiffbeforeafterboth228 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);228 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);229 await submitTransactionAsync(alice, changeAdminTx);229 await submitTransactionAsync(alice, changeAdminTx);230230231 expect(await isAllowlisted(collectionId, bob.address)).to.be.false;231 expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;232232233 {233 {234 const transferTx = contract.tx.toggleAllowList(value, gasLimit, collectionId, bob.address, true);234 const transferTx = contract.tx.toggleAllowList(value, gasLimit, collectionId, bob.address, true);235 const events = await submitTransactionAsync(alice, transferTx);235 const events = await submitTransactionAsync(alice, transferTx);236 const result = getGenericResult(events);236 const result = getGenericResult(events);237 expect(result.success).to.be.true;237 expect(result.success).to.be.true;238238239 expect(await isAllowlisted(collectionId, bob.address)).to.be.true;239 expect(await isAllowlisted(api, collectionId, bob.address)).to.be.true;240 }240 }241 {241 {242 const transferTx = contract.tx.toggleAllowList(value, gasLimit, collectionId, bob.address, false);242 const transferTx = contract.tx.toggleAllowList(value, gasLimit, collectionId, bob.address, false);243 const events = await submitTransactionAsync(alice, transferTx);243 const events = await submitTransactionAsync(alice, transferTx);244 const result = getGenericResult(events);244 const result = getGenericResult(events);245 expect(result.success).to.be.true;245 expect(result.success).to.be.true;246246247 expect(await isAllowlisted(collectionId, bob.address)).to.be.false;247 expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;248 }248 }249 });249 });250 });250 });tests/src/createMultipleItems.test.tsdiffbeforeafterboth20 getLastTokenId,20 getLastTokenId,21 getVariableMetadata,21 getVariableMetadata,22 getConstMetadata,22 getConstMetadata,23 getCreatedCollectionCount,23} from './util/helpers';24} from './util/helpers';242525chai.use(chaiAsPromised);26chai.use(chaiAsPromised);273274274 it('Create token in not existing collection', async () => {275 it('Create token in not existing collection', async () => {275 await usingApi(async (api: ApiPromise) => {276 await usingApi(async (api: ApiPromise) => {276 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;277 const collectionId = await getCreatedCollectionCount(api) + 1;277 const createMultipleItemsTx = api.tx.nft278 const createMultipleItemsTx = api.tx.nft278 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);279 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);279 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;280 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;tests/src/destroyCollection.test.tsdiffbeforeafterboth13 destroyCollectionExpectFailure,13 destroyCollectionExpectFailure,14 setCollectionLimitsExpectSuccess,14 setCollectionLimitsExpectSuccess,15 addCollectionAdminExpectSuccess,15 addCollectionAdminExpectSuccess,16 getCreatedCollectionCount,16} from './util/helpers';17} from './util/helpers';171818chai.use(chaiAsPromised);19chai.use(chaiAsPromised);46 it('(!negative test!) Destroy a collection that never existed', async () => {47 it('(!negative test!) Destroy a collection that never existed', async () => {47 await usingApi(async (api) => {48 await usingApi(async (api) => {48 // Find the collection that never existed49 // Find the collection that never existed49 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;50 const collectionId = await getCreatedCollectionCount(api) + 1;50 await destroyCollectionExpectFailure(collectionId);51 await destroyCollectionExpectFailure(collectionId);51 });52 });52 });53 });tests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth1// Auto-generated via `yarn polkadot-types-from-chain`, do not edit1// Auto-generated via `yarn polkadot-types-from-chain`, do not edit2/* eslint-disable */2/* eslint-disable */334import type { NftDataStructsCollectionId, NftDataStructsTokenId, PalletCommonAccountBasicCrossAccountIdRepr } from './nft';4import type { NftDataStructsCollection, NftDataStructsCollectionId, NftDataStructsCollectionStats, NftDataStructsTokenId, PalletCommonAccountBasicCrossAccountIdRepr } from './nft';5import type { Bytes, HashMap, Json, Metadata, Null, Option, StorageKey, Text, U256, U64, Vec, bool, u128, u32, u64 } from '@polkadot/types';5import type { Bytes, HashMap, Json, Metadata, Null, Option, StorageKey, Text, U256, U64, Vec, bool, u128, u32, u64 } from '@polkadot/types';6import type { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';6import type { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';7import type { EpochAuthorship } from '@polkadot/types/interfaces/babe';7import type { EpochAuthorship } from '@polkadot/types/interfaces/babe';372 * Get allowed amount372 * Get allowed amount373 **/373 **/374 allowance: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, sender: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, spender: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, tokenId: NftDataStructsTokenId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<u128>>;374 allowance: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, sender: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, spender: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, tokenId: NftDataStructsTokenId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<u128>>;375 /**376 * Check if user is allowed to use collection377 **/378 allowed: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, account: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, at?: Hash | string | Uint8Array) => Observable<bool>>;375 /**379 /**376 * Get allowlist380 * Get allowlist377 **/381 **/380 * Get amount of specific account token384 * Get amount of specific account token381 **/385 **/382 balance: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, account: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, tokenId: NftDataStructsTokenId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<u128>>;386 balance: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, account: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, tokenId: NftDataStructsTokenId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<u128>>;387 /**388 * Get collection by specified id389 **/390 collectionById: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<NftDataStructsCollection>>>;391 /**392 * Get collection stats393 **/394 collectionStats: AugmentedRpc<(at?: Hash | string | Uint8Array) => Observable<NftDataStructsCollectionStats>>;383 /**395 /**384 * Get tokens contained in collection396 * Get tokens contained in collection385 **/397 **/tests/src/interfaces/augment-types.tsdiffbeforeafterboth2/* eslint-disable */2/* eslint-disable */334import type { EthereumBlock, EthereumLog, EthereumReceipt, EthereumTransactionLegacyTransaction, EvmCoreErrorExitReason, FpRpcTransactionStatus } from './ethereum';4import type { EthereumBlock, EthereumLog, EthereumReceipt, EthereumTransactionLegacyTransaction, EvmCoreErrorExitReason, FpRpcTransactionStatus } from './ethereum';5import type { NftDataStructsAccessMode, NftDataStructsCollection, NftDataStructsCollectionId, NftDataStructsCollectionLimits, NftDataStructsCollectionMode, NftDataStructsCreateItemData, NftDataStructsMetaUpdatePermission, NftDataStructsSchemaVersion, NftDataStructsSponsorshipState, NftDataStructsTokenId, PalletCommonAccountBasicCrossAccountIdRepr, PalletNonfungibleItemData, PalletRefungibleItemData, PalletUnqSchedulerCallSpec, PalletUnqSchedulerReleases, PalletUnqSchedulerScheduledV2 } from './nft';5import type { NftDataStructsAccessMode, NftDataStructsCollection, NftDataStructsCollectionId, NftDataStructsCollectionLimits, NftDataStructsCollectionMode, NftDataStructsCollectionStats, NftDataStructsCreateItemData, NftDataStructsMetaUpdatePermission, NftDataStructsSchemaVersion, NftDataStructsSponsorshipState, NftDataStructsTokenId, PalletCommonAccountBasicCrossAccountIdRepr, PalletNonfungibleItemData, PalletRefungibleItemData, PalletUnqSchedulerCallSpec, PalletUnqSchedulerReleases, PalletUnqSchedulerScheduledV2 } from './nft';6import type { CumulusPalletDmpQueueConfigData, CumulusPalletDmpQueuePageIndexData, CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, CumulusPalletXcmpQueueInboundStatus, CumulusPalletXcmpQueueOutboundStatus, CumulusPalletXcmpQueueQueueConfigData, CumulusPrimitivesParachainInherentParachainInherentData, PolkadotParachainPrimitivesXcmpMessageFormat, PolkadotPrimitivesV1AbridgedHostConfiguration, PolkadotPrimitivesV1PersistedValidationData } from './polkadot';6import type { CumulusPalletDmpQueueConfigData, CumulusPalletDmpQueuePageIndexData, CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, CumulusPalletXcmpQueueInboundStatus, CumulusPalletXcmpQueueOutboundStatus, CumulusPalletXcmpQueueQueueConfigData, CumulusPrimitivesParachainInherentParachainInherentData, PolkadotParachainPrimitivesXcmpMessageFormat, PolkadotPrimitivesV1AbridgedHostConfiguration, PolkadotPrimitivesV1PersistedValidationData } from './polkadot';7import type { BitVec, Bool, Bytes, Data, I128, I16, I256, I32, I64, I8, Json, Null, Raw, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, USize, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types';7import type { BitVec, Bool, Bytes, Data, I128, I16, I256, I32, I64, I8, Json, Null, Raw, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, USize, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types';8import type { AssetApproval, AssetApprovalKey, AssetBalance, AssetDestroyWitness, AssetDetails, AssetMetadata, TAssetBalance, TAssetDepositBalance } from '@polkadot/types/interfaces/assets';8import type { AssetApproval, AssetApprovalKey, AssetBalance, AssetDestroyWitness, AssetDetails, AssetMetadata, TAssetBalance, TAssetDepositBalance } from '@polkadot/types/interfaces/assets';627 NftDataStructsCollectionId: NftDataStructsCollectionId;627 NftDataStructsCollectionId: NftDataStructsCollectionId;628 NftDataStructsCollectionLimits: NftDataStructsCollectionLimits;628 NftDataStructsCollectionLimits: NftDataStructsCollectionLimits;629 NftDataStructsCollectionMode: NftDataStructsCollectionMode;629 NftDataStructsCollectionMode: NftDataStructsCollectionMode;630 NftDataStructsCollectionStats: NftDataStructsCollectionStats;630 NftDataStructsCreateItemData: NftDataStructsCreateItemData;631 NftDataStructsCreateItemData: NftDataStructsCreateItemData;631 NftDataStructsMetaUpdatePermission: NftDataStructsMetaUpdatePermission;632 NftDataStructsMetaUpdatePermission: NftDataStructsMetaUpdatePermission;632 NftDataStructsSchemaVersion: NftDataStructsSchemaVersion;633 NftDataStructsSchemaVersion: NftDataStructsSchemaVersion;tests/src/interfaces/nft/definitions.tsdiffbeforeafterboth40 constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),40 constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),41 variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),41 variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),42 tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'),42 tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'),43 collectionById: fun('Get collection by specified id', [collectionParam], 'Option<NftDataStructsCollection>'),44 collectionStats: fun('Get collection stats', [], 'NftDataStructsCollectionStats'),45 allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),43 },46 },44 types: {47 types: {45 PalletCommonAccountBasicCrossAccountIdRepr: {48 PalletCommonAccountBasicCrossAccountIdRepr: {64 constOnChainSchema: 'Vec<u8>',67 constOnChainSchema: 'Vec<u8>',65 metaUpdatePermission: 'NftDataStructsMetaUpdatePermission',68 metaUpdatePermission: 'NftDataStructsMetaUpdatePermission',66 },69 },70 NftDataStructsCollectionStats: {71 created: 'u32',72 destroyed: 'u32',73 alive: 'u32',74 },67 NftDataStructsCollectionId: 'u32',75 NftDataStructsCollectionId: 'u32',68 NftDataStructsTokenId: 'u32',76 NftDataStructsTokenId: 'u32',69 PalletNonfungibleItemData: mkDummy('NftItemData'),77 PalletNonfungibleItemData: mkDummy('NftItemData'),tests/src/interfaces/nft/types.tsdiffbeforeafterboth48 readonly dummyCollectionMode: u32;48 readonly dummyCollectionMode: u32;49}49}5051/** @name NftDataStructsCollectionStats */52export interface NftDataStructsCollectionStats extends Struct {53 readonly created: u32;54 readonly destroyed: u32;55 readonly alive: u32;56}505751/** @name NftDataStructsCreateItemData */58/** @name NftDataStructsCreateItemData */52export interface NftDataStructsCreateItemData extends Struct {59export interface NftDataStructsCreateItemData extends Struct {tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth8import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId} from './util/helpers';11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';121213chai.use(chaiAsPromised);13chai.use(chaiAsPromised);14const expect = chai.expect;14const expect = chai.expect;19 const collectionId = await createCollectionExpectSuccess();19 const collectionId = await createCollectionExpectSuccess();20 const alice = privateKey('//Alice');20 const alice = privateKey('//Alice');21 const bob = privateKey('//Bob');21 const bob = privateKey('//Bob');22 const collection = (await api.query.common.collectionById(collectionId)).unwrap();22 const collection = await queryCollectionExpectSuccess(api, collectionId);23 expect(collection.owner.toString()).to.be.deep.eq(alice.address);23 expect(collection.owner.toString()).to.be.deep.eq(alice.address);24 // first - add collection admin Bob24 // first - add collection admin Bob25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));43 const alice = privateKey('//Alice');43 const alice = privateKey('//Alice');44 const bob = privateKey('//Bob');44 const bob = privateKey('//Bob');45 const charlie = privateKey('//Charlie');45 const charlie = privateKey('//Charlie');46 const collection = (await api.query.common.collectionById(collectionId)).unwrap();46 const collection = await queryCollectionExpectSuccess(api, collectionId);47 expect(collection.owner.toString()).to.be.eq(alice.address);47 expect(collection.owner.toString()).to.be.eq(alice.address);48 // first - add collection admin Bob48 // first - add collection admin Bob49 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));49 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth18 removeCollectionSponsorExpectFailure,18 removeCollectionSponsorExpectFailure,19 normalizeAccountId,19 normalizeAccountId,20 addCollectionAdminExpectSuccess,20 addCollectionAdminExpectSuccess,21 getCreatedCollectionCount,21} from './util/helpers';22} from './util/helpers';22import {Keyring} from '@polkadot/api';23import {Keyring} from '@polkadot/api';23import {IKeyringPair} from '@polkadot/types/types';24import {IKeyringPair} from '@polkadot/types/types';98 // Find the collection that never existed99 // Find the collection that never existed99 let collectionId = 0;100 let collectionId = 0;100 await usingApi(async (api) => {101 await usingApi(async (api) => {101 collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;102 collectionId = await getCreatedCollectionCount(api) + 1;102 });103 });103104104 await removeCollectionSponsorExpectFailure(collectionId);105 await removeCollectionSponsorExpectFailure(collectionId);tests/src/removeFromAllowList.test.tsdiffbeforeafterboth37 });37 });383839 it('ensure bob is not in allowlist after removal', async () => {39 it('ensure bob is not in allowlist after removal', async () => {40 await usingApi(async () => {40 await usingApi(async api => {41 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});41 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});42 await enableAllowListExpectSuccess(alice, collectionId);42 await enableAllowListExpectSuccess(alice, collectionId);43 await addToAllowListExpectSuccess(alice, collectionId, bob.address);43 await addToAllowListExpectSuccess(alice, collectionId, bob.address);444445 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));45 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));46 expect(await isAllowlisted(collectionId, bob.address)).to.be.false;46 expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;47 });47 });48 });48 });4949104 });104 });105105106 it('ensure address is not in allowlist after removal', async () => {106 it('ensure address is not in allowlist after removal', async () => {107 await usingApi(async () => {107 await usingApi(async api => {108 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});108 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});109 await enableAllowListExpectSuccess(alice, collectionId);109 await enableAllowListExpectSuccess(alice, collectionId);110 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);110 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);111 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);111 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);112 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));112 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));113 expect(await isAllowlisted(collectionId, charlie.address)).to.be.false;113 expect(await isAllowlisted(api, collectionId, charlie.address)).to.be.false;114 });114 });115 });115 });116116tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth11 destroyCollectionExpectSuccess,11 destroyCollectionExpectSuccess,12 setCollectionSponsorExpectFailure,12 setCollectionSponsorExpectFailure,13 addCollectionAdminExpectSuccess,13 addCollectionAdminExpectSuccess,14 getCreatedCollectionCount,14} from './util/helpers';15} from './util/helpers';15import {Keyring} from '@polkadot/api';16import {Keyring} from '@polkadot/api';16import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';77 // Find the collection that never existed78 // Find the collection that never existed78 let collectionId = 0;79 let collectionId = 0;79 await usingApi(async (api) => {80 await usingApi(async (api) => {80 collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;81 collectionId = await getCreatedCollectionCount(api) + 1;81 });82 });828383 await setCollectionSponsorExpectFailure(collectionId, bob.address);84 await setCollectionSponsorExpectFailure(collectionId, bob.address);tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 addCollectionAdminExpectSuccess,14 addCollectionAdminExpectSuccess,15 queryCollectionExpectSuccess,16 getCreatedCollectionCount,15} from './util/helpers';17} from './util/helpers';161817chai.use(chaiAsPromised);19chai.use(chaiAsPromised);37 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {39 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {38 await usingApi(async (api) => {40 await usingApi(async (api) => {39 const collectionId = await createCollectionExpectSuccess();41 const collectionId = await createCollectionExpectSuccess();40 const collection = (await api.query.common.collectionById(collectionId)).unwrap();42 const collection = await queryCollectionExpectSuccess(api, collectionId);41 expect(collection.owner.toString()).to.be.eq(alice.address);43 expect(collection.owner.toString()).to.be.eq(alice.address);42 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);44 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);43 await submitTransactionAsync(alice, setShema);45 await submitTransactionAsync(alice, setShema);47 it('Collection admin can set the scheme', async () => {49 it('Collection admin can set the scheme', async () => {48 await usingApi(async (api) => {50 await usingApi(async (api) => {49 const collectionId = await createCollectionExpectSuccess();51 const collectionId = await createCollectionExpectSuccess();50 const collection = (await api.query.common.collectionById(collectionId)).unwrap();52 const collection = await queryCollectionExpectSuccess(api, collectionId);51 expect(collection.owner.toString()).to.be.eq(alice.address);53 expect(collection.owner.toString()).to.be.eq(alice.address);52 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);54 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);53 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);55 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);60 const collectionId = await createCollectionExpectSuccess();62 const collectionId = await createCollectionExpectSuccess();61 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);63 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);62 await submitTransactionAsync(alice, setShema);64 await submitTransactionAsync(alice, setShema);63 const collection = (await api.query.common.collectionById(collectionId)).unwrap();65 const collection = await queryCollectionExpectSuccess(api, collectionId);64 expect(collection.constOnChainSchema.toString()).to.be.eq(shema);66 expect(collection.constOnChainSchema.toString()).to.be.eq(shema);65 });67 });66 });68 });71 it('Set a non-existent collection', async () => {73 it('Set a non-existent collection', async () => {72 await usingApi(async (api) => {74 await usingApi(async (api) => {73 // tslint:disable-next-line: radix75 // tslint:disable-next-line: radix74 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;76 const collectionId = await getCreatedCollectionCount(api) + 1;75 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);77 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);76 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;78 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;77 });79 });97 it('Execute method not on behalf of the collection owner', async () => {99 it('Execute method not on behalf of the collection owner', async () => {98 await usingApi(async (api) => {100 await usingApi(async (api) => {99 const collectionId = await createCollectionExpectSuccess();101 const collectionId = await createCollectionExpectSuccess();100 const collection = (await api.query.common.collectionById(collectionId)).unwrap();102 const collection = await queryCollectionExpectSuccess(api, collectionId);101 expect(collection.owner.toString()).to.be.eq(alice.address);103 expect(collection.owner.toString()).to.be.eq(alice.address);102 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);104 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);103 await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;105 await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth19 enableAllowListExpectSuccess,19 enableAllowListExpectSuccess,20 normalizeAccountId,20 normalizeAccountId,21 addCollectionAdminExpectSuccess,21 addCollectionAdminExpectSuccess,22 getCreatedCollectionCount,22} from './util/helpers';23} from './util/helpers';232424chai.use(chaiAsPromised);25chai.use(chaiAsPromised);60 it('Set a non-existent collection', async () => {61 it('Set a non-existent collection', async () => {61 await usingApi(async (api: ApiPromise) => {62 await usingApi(async (api: ApiPromise) => {62 // tslint:disable-next-line: radix63 // tslint:disable-next-line: radix63 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;64 const collectionId = await getCreatedCollectionCount(api) + 1;64 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');65 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');65 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;66 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;66 });67 });tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 addCollectionAdminExpectSuccess,14 addCollectionAdminExpectSuccess,15 queryCollectionExpectSuccess,16 getCreatedCollectionCount,15} from './util/helpers';17} from './util/helpers';161817chai.use(chaiAsPromised);19chai.use(chaiAsPromised);37 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {39 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {38 await usingApi(async (api) => {40 await usingApi(async (api) => {39 const collectionId = await createCollectionExpectSuccess();41 const collectionId = await createCollectionExpectSuccess();40 const collection = (await api.query.common.collectionById(collectionId)).unwrap();42 const collection = await queryCollectionExpectSuccess(api, collectionId);41 expect(collection.owner.toString()).to.be.eq(alice.address);43 expect(collection.owner.toString()).to.be.eq(alice.address);42 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);44 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);43 await submitTransactionAsync(alice, setSchema);45 await submitTransactionAsync(alice, setSchema);49 const collectionId = await createCollectionExpectSuccess();51 const collectionId = await createCollectionExpectSuccess();50 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);52 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);51 await submitTransactionAsync(alice, setSchema);53 await submitTransactionAsync(alice, setSchema);52 const collection = (await api.query.common.collectionById(collectionId)).unwrap();54 const collection = await queryCollectionExpectSuccess(api, collectionId);53 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);55 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);545655 });57 });61 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {63 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {62 await usingApi(async (api) => {64 await usingApi(async (api) => {63 const collectionId = await createCollectionExpectSuccess();65 const collectionId = await createCollectionExpectSuccess();64 const collection = (await api.query.common.collectionById(collectionId)).unwrap();66 const collection = await queryCollectionExpectSuccess(api, collectionId);65 expect(collection.owner.toString()).to.be.eq(alice.address);67 expect(collection.owner.toString()).to.be.eq(alice.address);66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);68 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);67 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);69 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);75 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);77 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);76 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);78 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);77 await submitTransactionAsync(bob, setSchema);79 await submitTransactionAsync(bob, setSchema);78 const collection = (await api.query.common.collectionById(collectionId)).unwrap();80 const collection = await queryCollectionExpectSuccess(api, collectionId);79 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);81 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);808281 });83 });87 it('Set a non-existent collection', async () => {89 it('Set a non-existent collection', async () => {88 await usingApi(async (api) => {90 await usingApi(async (api) => {89 // tslint:disable-next-line: radix91 // tslint:disable-next-line: radix90 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;92 const collectionId = await getCreatedCollectionCount(api) + 1;91 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);93 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);92 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;94 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;93 });95 });113 it('Execute method not on behalf of the collection owner', async () => {115 it('Execute method not on behalf of the collection owner', async () => {114 await usingApi(async (api) => {116 await usingApi(async (api) => {115 const collectionId = await createCollectionExpectSuccess();117 const collectionId = await createCollectionExpectSuccess();116 const collection = (await api.query.common.collectionById(collectionId)).unwrap();118 const collection = await queryCollectionExpectSuccess(api, collectionId);117 expect(collection.owner.toString()).to.be.eq(alice.address);119 expect(collection.owner.toString()).to.be.eq(alice.address);118 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);120 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);119 await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;121 await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;tests/src/transfer.test.tsdiffbeforeafterboth19 transferExpectFailure,19 transferExpectFailure,20 transferExpectSuccess,20 transferExpectSuccess,21 addCollectionAdminExpectSuccess,21 addCollectionAdminExpectSuccess,22 getCreatedCollectionCount,22} from './util/helpers';23} from './util/helpers';232424let alice: IKeyringPair;25let alice: IKeyringPair;132 it('Transfer with not existed collection_id', async () => {133 it('Transfer with not existed collection_id', async () => {133 await usingApi(async (api) => {134 await usingApi(async (api) => {134 // nft135 // nft135 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();136 const nftCollectionCount = await getCreatedCollectionCount(api);136 await transferExpectFailure(nftCollectionCount + 1, 1, alice, bob, 1);137 await transferExpectFailure(nftCollectionCount + 1, 1, alice, bob, 1);137 // fungible138 // fungible138 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();139 const fungibleCollectionCount = await getCreatedCollectionCount(api);139 await transferExpectFailure(fungibleCollectionCount + 1, 0, alice, bob, 1);140 await transferExpectFailure(fungibleCollectionCount + 1, 0, alice, bob, 1);140 // reFungible141 // reFungible141 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();142 const reFungibleCollectionCount = await getCreatedCollectionCount(api);142 await transferExpectFailure(reFungibleCollectionCount + 1, 1, alice, bob, 1);143 await transferExpectFailure(reFungibleCollectionCount + 1, 1, alice, bob, 1);143 });144 });144 });145 });tests/src/transferFrom.test.tsdiffbeforeafterboth19 transferFromExpectSuccess,19 transferFromExpectSuccess,20 burnItemExpectSuccess,20 burnItemExpectSuccess,21 setCollectionLimitsExpectSuccess,21 setCollectionLimitsExpectSuccess,22 getCreatedCollectionCount,22} from './util/helpers';23} from './util/helpers';232424chai.use(chaiAsPromised);25chai.use(chaiAsPromised);109 it('transferFrom for a collection that does not exist', async () => {110 it('transferFrom for a collection that does not exist', async () => {110 await usingApi(async (api: ApiPromise) => {111 await usingApi(async (api: ApiPromise) => {111 // nft112 // nft112 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();113 const nftCollectionCount = await getCreatedCollectionCount(api);113 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);114 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);114115115 await transferFromExpectFail(nftCollectionCount + 1, 1, bob, alice, charlie, 1);116 await transferFromExpectFail(nftCollectionCount + 1, 1, bob, alice, charlie, 1);116117117 // fungible118 // fungible118 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();119 const fungibleCollectionCount = await getCreatedCollectionCount(api);119 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);120 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);120121121 await transferFromExpectFail(fungibleCollectionCount + 1, 0, bob, alice, charlie, 1);122 await transferFromExpectFail(fungibleCollectionCount + 1, 0, bob, alice, charlie, 1);122 // reFungible123 // reFungible123 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();124 const reFungibleCollectionCount = await getCreatedCollectionCount(api);124 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);125 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);125126126 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, bob, alice, charlie, 1);127 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, bob, alice, charlie, 1);tests/src/util/helpers.tsdiffbeforeafterboth269 let collectionId = 0;269 let collectionId = 0;270 await usingApi(async (api) => {270 await usingApi(async (api) => {271 // Get number of collections before the transaction271 // Get number of collections before the transaction272 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();272 const collectionCountBefore = await getCreatedCollectionCount(api);273273274 // Run the CreateCollection transaction274 // Run the CreateCollection transaction275 const alicePrivateKey = privateKey('//Alice');275 const alicePrivateKey = privateKey('//Alice');288 const result = getCreateCollectionResult(events);288 const result = getCreateCollectionResult(events);289289290 // Get number of collections after the transaction290 // Get number of collections after the transaction291 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();291 const collectionCountAfter = await getCreatedCollectionCount(api);292292293 // Get the collection293 // Get the collection294 const collection = (await api.query.common.collectionById(result.collectionId)).unwrap();294 const collection = await queryCollectionExpectSuccess(api, result.collectionId);295295296 // What to expect296 // What to expect297 // tslint:disable-next-line:no-unused-expression297 // tslint:disable-next-line:no-unused-expression325325326 await usingApi(async (api) => {326 await usingApi(async (api) => {327 // Get number of collections before the transaction327 // Get number of collections before the transaction328 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();328 const collectionCountBefore = await getCreatedCollectionCount(api);329329330 // Run the CreateCollection transaction330 // Run the CreateCollection transaction331 const alicePrivateKey = privateKey('//Alice');331 const alicePrivateKey = privateKey('//Alice');334 const result = getCreateCollectionResult(events);334 const result = getCreateCollectionResult(events);335335336 // Get number of collections after the transaction336 // Get number of collections after the transaction337 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();337 const collectionCountAfter = await getCreatedCollectionCount(api);338338339 // What to expect339 // What to expect340 // tslint:disable-next-line:no-unused-expression340 // tslint:disable-next-line:no-unused-expression364}364}365365366export async function findNotExistingCollection(api: ApiPromise): Promise<number> {366export async function findNotExistingCollection(api: ApiPromise): Promise<number> {367 const totalNumber = (await api.query.common.createdCollectionCount()).toNumber();367 const totalNumber = await getCreatedCollectionCount(api);368 const newCollection: number = totalNumber + 1;368 const newCollection: number = totalNumber + 1;369 return newCollection;369 return newCollection;370}370}398 expect(result).to.be.true;398 expect(result).to.be.true;399399400 // What to expect400 // What to expect401 expect((await api.query.common.collectionById(collectionId)).isNone).to.be.true;401 expect(await getDetailedCollectionInfo(api, collectionId)).to.be.null;402 });402 });403}403}404404432 const result = getGenericResult(events);432 const result = getGenericResult(events);433433434 // Get the collection434 // Get the collection435 const collection = (await api.query.common.collectionById(collectionId)).unwrap();435 const collection = await queryCollectionExpectSuccess(api, collectionId);436436437 // What to expect437 // What to expect438 expect(result.success).to.be.true;438 expect(result.success).to.be.true;452 const result = getGenericResult(events);452 const result = getGenericResult(events);453453454 // Get the collection454 // Get the collection455 const collection = (await api.query.common.collectionById(collectionId)).unwrap();455 const collection = await queryCollectionExpectSuccess(api, collectionId);456456457 // What to expect457 // What to expect458 expect(result.success).to.be.true;458 expect(result.success).to.be.true;490 const result = getGenericResult(events);490 const result = getGenericResult(events);491491492 // Get the collection492 // Get the collection493 const collection = (await api.query.common.collectionById(collectionId)).unwrap();493 const collection = await queryCollectionExpectSuccess(api, collectionId);494494495 // What to expect495 // What to expect496 expect(result.success).to.be.true;496 expect(result.success).to.be.true;1057 const result = getGenericResult(events);1057 const result = getGenericResult(events);105810581059 // Get the collection1059 // Get the collection1060 const collection = (await api.query.common.collectionById(collectionId)).unwrap();1060 const collection = await queryCollectionExpectSuccess(api, collectionId);106110611062 // What to expect1062 // What to expect1063 // tslint:disable-next-line:no-unused-expression1063 // tslint:disable-next-line:no-unused-expression1105 expect(result.success).to.be.true;1105 expect(result.success).to.be.true;110611061107 // Get the collection1107 // Get the collection1108 const collection = (await api.query.common.collectionById(collectionId)).unwrap();1108 const collection = await queryCollectionExpectSuccess(api, collectionId);110911091110 expect(collection.mintMode.toHuman()).to.be.equal(enabled);1110 expect(collection.mintMode.toHuman()).to.be.equal(enabled);1111 });1111 });1137 });1137 });1138}1138}113911391140export async function isAllowlisted(collectionId: number, address: string | CrossAccountId) {1140export async function isAllowlisted(api: ApiPromise, collectionId: number, address: string | CrossAccountId) {1141 return await usingApi(async (api) => {1141 return (await api.rpc.nft.allowed(collectionId, normalizeAccountId(address))).toJSON();1142 return (await api.query.common.allowlist(collectionId, normalizeAccountId(address))).toJSON();1143 });1144}1142}114511431146export async function addToAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {1144export async function addToAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {1147 await usingApi(async (api) => {1145 await usingApi(async (api) => {1148 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.false;1146 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.false;114911471150 // Run the transaction1148 // Run the transaction1151 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));1149 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));1152 const events = await submitTransactionAsync(sender, tx);1150 const events = await submitTransactionAsync(sender, tx);1153 const result = getGenericResult(events);1151 const result = getGenericResult(events);1154 expect(result.success).to.be.true;1152 expect(result.success).to.be.true;115511531156 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;1154 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;1157 });1155 });1158}1156}115911571160export async function addToAllowListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1158export async function addToAllowListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1161 await usingApi(async (api) => {1159 await usingApi(async (api) => {116211601163 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;1161 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;116411621165 // Run the transaction1163 // Run the transaction1166 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));1164 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));1167 const events = await submitTransactionAsync(sender, tx);1165 const events = await submitTransactionAsync(sender, tx);1168 const result = getGenericResult(events);1166 const result = getGenericResult(events);1169 expect(result.success).to.be.true;1167 expect(result.success).to.be.true;117011681171 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;1169 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;1172 });1170 });1173}1171}11741172121412121215export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1213export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1216 : Promise<NftDataStructsCollection | null> => {1214 : Promise<NftDataStructsCollection | null> => {1217 return (await api.query.common.collectionById(collectionId)).unwrapOr(null);1215 return (await api.rpc.nft.collectionById(collectionId)).unwrapOr(null);1218};1216};121912171220export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1218export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1221 // set global object - collectionsCount1219 // set global object - collectionsCount1222 return (await api.query.common.createdCollectionCount()).toNumber();1220 return (await api.rpc.nft.collectionStats()).created.toNumber();1223};1221};122412221225export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<NftDataStructsCollection> {1223export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<NftDataStructsCollection> {1226 return (await api.query.common.collectionById(collectionId)).unwrap();1224 return (await api.rpc.nft.collectionById(collectionId)).unwrap();1227}1225}122812261229export async function waitNewBlocks(blocksCount = 1): Promise<void> {1227export async function waitNewBlocks(blocksCount = 1): Promise<void> {