git.delta.rocks / unique-network / refs/commits / 915ff113b0bb

difftreelog

refactor use rpcs instead of api.query.common

Yaroslav Bolyukin2021-11-17parent: #516bf2b.patch.diff
in: master

33 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
3use 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}
92107
93pub struct Nft<C, P> {108pub struct Nft<C, P> {
160175
161 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}
165183
modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
19pub 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());
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
12 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>;
8282
83 fn deref(&self) -> &Self::Target {83 fn deref(&self) -> &Self::Target {
84 &self.collection84 &self.collection
311 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 >;
317317
345 QueryKind = ValueQuery,345 QueryKind = ValueQuery,
346 >;346 >;
347
348 /// Not used by code, exists only to provide some types to metadata
349 #[pallet::storage]
350 pub type DummyStorageValue<T> = StorageValue<Value = (CollectionStats, CollectionId, TokenId), QueryKind = OptionQuery>;
347}351}
348352
349impl<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}
359385
360impl<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,
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
91}91}
9292
93impl<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>,
modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
25fn 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 collection
114 .sponsorship114 .sponsorship
115 .sponsor()115 .sponsor()
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
42 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)?;
191191
192 // Create new collection192 // Create new collection
193 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 };
209209
210 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 params
214 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 };
221221
939 }939 }
940}940}
941
942// 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}
955941
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
133133
134// unchecked calls skips any permission checks134// unchecked calls skips any permission checks
135impl<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>,
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
156156
157// unchecked calls skips any permission checks157// unchecked calls skips any permission checks
158impl<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>,
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
207207
208#[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 char
217 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 restrictions
222 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}
416
417#[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}
416424
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
1#![cfg_attr(not(feature = "std"), no_std)]1#![cfg_attr(not(feature = "std"), no_std)]
22
3use 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;
3232
33 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}
3841
modifiedruntime/src/lib.rsdiffbeforeafterboth
1040 .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 }
10521061
1053 impl sp_api::Core<Block> for Runtime {1062 impl sp_api::Core<Block> for Runtime {
modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
8import 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';
1212
13chai.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');
2222
23 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);
2525
26 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');
4040
41 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);
4343
44 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));44 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
modifiedtests/src/addToAllowList.test.tsdiffbeforeafterboth
18 normalizeAccountId,18 normalizeAccountId,
19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,
20 addToAllowListExpectFail,20 addToAllowListExpectFail,
21 getCreatedCollectionCount,
21} from './util/helpers';22} from './util/helpers';
2223
23chai.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-bitwise
58 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');
6061
61 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));62 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));
modifiedtests/src/approve.test.tsdiffbeforeafterboth
18 transferExpectSuccess,18 transferExpectSuccess,
19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,
20 adminApproveFromExpectSuccess,20 adminApproveFromExpectSuccess,
21 getCreatedCollectionCount,
21} from './util/helpers';22} from './util/helpers';
2223
23chai.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 // nft
97 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 // fungible
100 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 // reFungible
103 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 });
modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
22 setMintPermissionExpectFailure,22 setMintPermissionExpectFailure,
23 destroyCollectionExpectFailure,23 destroyCollectionExpectFailure,
24 setPublicAccessModeExpectSuccess,24 setPublicAccessModeExpectSuccess,
25 queryCollectionExpectSuccess,
25} from './util/helpers';26} from './util/helpers';
2627
27chai.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');
3637
37 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);
3940
40 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);
4243
43 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');
5556
56 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);
5859
59 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;
6465
65 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');
7677
77 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);
7980
80 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);
8283
83 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);
8586
86 // 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 owner
118 const bob = privateKey('//Bob');119 const bob = privateKey('//Bob');
119 const charlie = privateKey('//Charlie');120 const charlie = privateKey('//Charlie');
120121
121 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);
123124
124 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);
126127
127 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);
129130
130 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);
132133
133 // ownership lost134 // ownership lost
134 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;
149150
150 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);
152153
153 // 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;
168169
169 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);
171172
172 // 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');
197198
198 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);
200201
201 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;
206207
207 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);
209210
210 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');211 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');
modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
20 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 existed
336 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 });
340341
341 await confirmSponsorshipExpectFailure(collectionId, '//Bob');342 await confirmSponsorshipExpectFailure(collectionId, '//Bob');
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
228 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);
230230
231 expect(await isAllowlisted(collectionId, bob.address)).to.be.false;231 expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;
232232
233 {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;
238238
239 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;
246246
247 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 });
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
20 getLastTokenId,20 getLastTokenId,
21 getVariableMetadata,21 getVariableMetadata,
22 getConstMetadata,22 getConstMetadata,
23 getCreatedCollectionCount,
23} from './util/helpers';24} from './util/helpers';
2425
25chai.use(chaiAsPromised);26chai.use(chaiAsPromised);
273274
274 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.nft
278 .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;
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
13 destroyCollectionExpectFailure,13 destroyCollectionExpectFailure,
14 setCollectionLimitsExpectSuccess,14 setCollectionLimitsExpectSuccess,
15 addCollectionAdminExpectSuccess,15 addCollectionAdminExpectSuccess,
16 getCreatedCollectionCount,
16} from './util/helpers';17} from './util/helpers';
1718
18chai.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 existed
49 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 });
modifiedtests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth
1// Auto-generated via `yarn polkadot-types-from-chain`, do not edit1// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
2/* eslint-disable */2/* eslint-disable */
33
4import 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 amount
373 **/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 collection
377 **/
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 allowlist
377 **/381 **/
380 * Get amount of specific account token384 * Get amount of specific account token
381 **/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 id
389 **/
390 collectionById: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<NftDataStructsCollection>>>;
391 /**
392 * Get collection stats
393 **/
394 collectionStats: AugmentedRpc<(at?: Hash | string | Uint8Array) => Observable<NftDataStructsCollectionStats>>;
383 /**395 /**
384 * Get tokens contained in collection396 * Get tokens contained in collection
385 **/397 **/
modifiedtests/src/interfaces/augment-types.tsdiffbeforeafterboth
2/* eslint-disable */2/* eslint-disable */
33
4import 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;
modifiedtests/src/interfaces/nft/definitions.tsdiffbeforeafterboth
40 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'),
modifiedtests/src/interfaces/nft/types.tsdiffbeforeafterboth
48 readonly dummyCollectionMode: u32;48 readonly dummyCollectionMode: u32;
49}49}
50
51/** @name NftDataStructsCollectionStats */
52export interface NftDataStructsCollectionStats extends Struct {
53 readonly created: u32;
54 readonly destroyed: u32;
55 readonly alive: u32;
56}
5057
51/** @name NftDataStructsCreateItemData */58/** @name NftDataStructsCreateItemData */
52export interface NftDataStructsCreateItemData extends Struct {59export interface NftDataStructsCreateItemData extends Struct {
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
8import 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';
1212
13chai.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 Bob
25 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 Bob
49 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));49 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
modifiedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
18 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 existed
99 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 });
103104
104 await removeCollectionSponsorExpectFailure(collectionId);105 await removeCollectionSponsorExpectFailure(collectionId);
modifiedtests/src/removeFromAllowList.test.tsdiffbeforeafterboth
37 });37 });
3838
39 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);
4444
45 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 });
4949
104 });104 });
105105
106 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 });
116116
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
11 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 existed
78 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 });
8283
83 await setCollectionSponsorExpectFailure(collectionId, bob.address);84 await setCollectionSponsorExpectFailure(collectionId, bob.address);
modifiedtests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth
12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,
13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,
14 addCollectionAdminExpectSuccess,14 addCollectionAdminExpectSuccess,
15 queryCollectionExpectSuccess,
16 getCreatedCollectionCount,
15} from './util/helpers';17} from './util/helpers';
1618
17chai.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: radix
74 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;
modifiedtests/src/setPublicAccessMode.test.tsdiffbeforeafterboth
19 enableAllowListExpectSuccess,19 enableAllowListExpectSuccess,
20 normalizeAccountId,20 normalizeAccountId,
21 addCollectionAdminExpectSuccess,21 addCollectionAdminExpectSuccess,
22 getCreatedCollectionCount,
22} from './util/helpers';23} from './util/helpers';
2324
24chai.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: radix
63 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 });
modifiedtests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth
12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,
13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,
14 addCollectionAdminExpectSuccess,14 addCollectionAdminExpectSuccess,
15 queryCollectionExpectSuccess,
16 getCreatedCollectionCount,
15} from './util/helpers';17} from './util/helpers';
1618
17chai.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);
5456
55 });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);
8082
81 });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: radix
90 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;
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
19 transferExpectFailure,19 transferExpectFailure,
20 transferExpectSuccess,20 transferExpectSuccess,
21 addCollectionAdminExpectSuccess,21 addCollectionAdminExpectSuccess,
22 getCreatedCollectionCount,
22} from './util/helpers';23} from './util/helpers';
2324
24let 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 // nft
135 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 // fungible
138 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 // reFungible
141 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 });
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
19 transferFromExpectSuccess,19 transferFromExpectSuccess,
20 burnItemExpectSuccess,20 burnItemExpectSuccess,
21 setCollectionLimitsExpectSuccess,21 setCollectionLimitsExpectSuccess,
22 getCreatedCollectionCount,
22} from './util/helpers';23} from './util/helpers';
2324
24chai.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 // nft
112 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);
114115
115 await transferFromExpectFail(nftCollectionCount + 1, 1, bob, alice, charlie, 1);116 await transferFromExpectFail(nftCollectionCount + 1, 1, bob, alice, charlie, 1);
116117
117 // fungible118 // fungible
118 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);
120121
121 await transferFromExpectFail(fungibleCollectionCount + 1, 0, bob, alice, charlie, 1);122 await transferFromExpectFail(fungibleCollectionCount + 1, 0, bob, alice, charlie, 1);
122 // reFungible123 // reFungible
123 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);
125126
126 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, bob, alice, charlie, 1);127 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, bob, alice, charlie, 1);
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
269 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 transaction
272 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();272 const collectionCountBefore = await getCreatedCollectionCount(api);
273273
274 // Run the CreateCollection transaction274 // Run the CreateCollection transaction
275 const alicePrivateKey = privateKey('//Alice');275 const alicePrivateKey = privateKey('//Alice');
288 const result = getCreateCollectionResult(events);288 const result = getCreateCollectionResult(events);
289289
290 // Get number of collections after the transaction290 // Get number of collections after the transaction
291 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();291 const collectionCountAfter = await getCreatedCollectionCount(api);
292292
293 // Get the collection293 // Get the collection
294 const collection = (await api.query.common.collectionById(result.collectionId)).unwrap();294 const collection = await queryCollectionExpectSuccess(api, result.collectionId);
295295
296 // What to expect296 // What to expect
297 // tslint:disable-next-line:no-unused-expression297 // tslint:disable-next-line:no-unused-expression
325325
326 await usingApi(async (api) => {326 await usingApi(async (api) => {
327 // Get number of collections before the transaction327 // Get number of collections before the transaction
328 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();328 const collectionCountBefore = await getCreatedCollectionCount(api);
329329
330 // Run the CreateCollection transaction330 // Run the CreateCollection transaction
331 const alicePrivateKey = privateKey('//Alice');331 const alicePrivateKey = privateKey('//Alice');
334 const result = getCreateCollectionResult(events);334 const result = getCreateCollectionResult(events);
335335
336 // Get number of collections after the transaction336 // Get number of collections after the transaction
337 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();337 const collectionCountAfter = await getCreatedCollectionCount(api);
338338
339 // What to expect339 // What to expect
340 // tslint:disable-next-line:no-unused-expression340 // tslint:disable-next-line:no-unused-expression
364}364}
365365
366export 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;
399399
400 // What to expect400 // What to expect
401 expect((await api.query.common.collectionById(collectionId)).isNone).to.be.true;401 expect(await getDetailedCollectionInfo(api, collectionId)).to.be.null;
402 });402 });
403}403}
404404
432 const result = getGenericResult(events);432 const result = getGenericResult(events);
433433
434 // Get the collection434 // Get the collection
435 const collection = (await api.query.common.collectionById(collectionId)).unwrap();435 const collection = await queryCollectionExpectSuccess(api, collectionId);
436436
437 // What to expect437 // What to expect
438 expect(result.success).to.be.true;438 expect(result.success).to.be.true;
452 const result = getGenericResult(events);452 const result = getGenericResult(events);
453453
454 // Get the collection454 // Get the collection
455 const collection = (await api.query.common.collectionById(collectionId)).unwrap();455 const collection = await queryCollectionExpectSuccess(api, collectionId);
456456
457 // What to expect457 // What to expect
458 expect(result.success).to.be.true;458 expect(result.success).to.be.true;
490 const result = getGenericResult(events);490 const result = getGenericResult(events);
491491
492 // Get the collection492 // Get the collection
493 const collection = (await api.query.common.collectionById(collectionId)).unwrap();493 const collection = await queryCollectionExpectSuccess(api, collectionId);
494494
495 // What to expect495 // What to expect
496 expect(result.success).to.be.true;496 expect(result.success).to.be.true;
1057 const result = getGenericResult(events);1057 const result = getGenericResult(events);
10581058
1059 // Get the collection1059 // Get the collection
1060 const collection = (await api.query.common.collectionById(collectionId)).unwrap();1060 const collection = await queryCollectionExpectSuccess(api, collectionId);
10611061
1062 // What to expect1062 // What to expect
1063 // tslint:disable-next-line:no-unused-expression1063 // tslint:disable-next-line:no-unused-expression
1105 expect(result.success).to.be.true;1105 expect(result.success).to.be.true;
11061106
1107 // Get the collection1107 // Get the collection
1108 const collection = (await api.query.common.collectionById(collectionId)).unwrap();1108 const collection = await queryCollectionExpectSuccess(api, collectionId);
11091109
1110 expect(collection.mintMode.toHuman()).to.be.equal(enabled);1110 expect(collection.mintMode.toHuman()).to.be.equal(enabled);
1111 });1111 });
1137 });1137 });
1138}1138}
11391139
1140export 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}
11451143
1146export 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;
11491147
1150 // Run the transaction1148 // Run the transaction
1151 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;
11551153
1156 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;1154 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;
1157 });1155 });
1158}1156}
11591157
1160export 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) => {
11621160
1163 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;1161 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;
11641162
1165 // Run the transaction1163 // Run the transaction
1166 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;
11701168
1171 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;1169 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;
1172 });1170 });
1173}1171}
11741172
12141212
1215export 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};
12191217
1220export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1218export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {
1221 // set global object - collectionsCount1219 // set global object - collectionsCount
1222 return (await api.query.common.createdCollectionCount()).toNumber();1220 return (await api.rpc.nft.collectionStats()).created.toNumber();
1223};1221};
12241222
1225export 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}
12281226
1229export async function waitNewBlocks(blocksCount = 1): Promise<void> {1227export async function waitNewBlocks(blocksCount = 1): Promise<void> {