difftreelog
refactor use rpcs instead of api.query.common
in: master
33 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -3,7 +3,7 @@
use codec::Decode;
use jsonrpc_core::{Error as RpcError, ErrorCode, Result};
use jsonrpc_derive::rpc;
-use nft_data_structs::{CollectionId, TokenId};
+use nft_data_structs::{Collection, CollectionId, CollectionStats, TokenId};
use sp_api::{BlockId, BlockT, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use up_rpc::NftApi as NftRuntimeApi;
@@ -86,8 +86,23 @@
collection: CollectionId,
at: Option<BlockHash>,
) -> Result<Vec<CrossAccountId>>;
+ #[rpc(name = "nft_allowed")]
+ fn allowed(
+ &self,
+ collection: CollectionId,
+ user: CrossAccountId,
+ at: Option<BlockHash>,
+ ) -> Result<bool>;
#[rpc(name = "nft_lastTokenId")]
fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;
+ #[rpc(name = "nft_collectionById")]
+ fn collection_by_id(
+ &self,
+ collection: CollectionId,
+ at: Option<BlockHash>,
+ ) -> Result<Option<Collection<AccountId>>>;
+ #[rpc(name = "nft_collectionStats")]
+ fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;
}
pub struct Nft<C, P> {
@@ -160,5 +175,8 @@
pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>);
pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>);
+ pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool);
pass_method!(last_token_id(collection: CollectionId) -> TokenId);
+ pass_method!(collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>);
+ pass_method!(collection_stats() -> CollectionStats);
}
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -19,7 +19,7 @@
pub fn create_collection_raw<T: Config, R>(
owner: T::AccountId,
mode: CollectionMode,
- handler: impl FnOnce(Collection<T>) -> Result<CollectionId, DispatchError>,
+ handler: impl FnOnce(Collection<T::AccountId>) -> Result<CollectionId, DispatchError>,
cast: impl FnOnce(CollectionHandle<T>) -> R,
) -> Result<R, DispatchError> {
T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -12,7 +12,7 @@
COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, ExistenceRequirement,
MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
COLLECTION_ADMINS_LIMIT, MetaUpdatePermission, Pays, PostDispatchInfo, TokenId, Weight,
- WithdrawReasons,
+ WithdrawReasons, CollectionStats,
};
pub use pallet::*;
use sp_core::H160;
@@ -26,7 +26,7 @@
#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]
pub struct CollectionHandle<T: Config> {
pub id: CollectionId,
- collection: Collection<T>,
+ collection: Collection<T::AccountId>,
pub recorder: pallet_evm_coder_substrate::SubstrateRecorder<T>,
}
impl<T: Config> CollectionHandle<T> {
@@ -78,7 +78,7 @@
}
}
impl<T: Config> Deref for CollectionHandle<T> {
- type Target = Collection<T>;
+ type Target = Collection<T::AccountId>;
fn deref(&self) -> &Self::Target {
&self.collection
@@ -311,7 +311,7 @@
pub type CollectionById<T> = StorageMap<
Hasher = Blake2_128Concat,
Key = CollectionId,
- Value = Collection<T>,
+ Value = Collection<<T as frame_system::Config>::AccountId>,
QueryKind = OptionQuery,
>;
@@ -344,6 +344,10 @@
Value = bool,
QueryKind = ValueQuery,
>;
+
+ /// Not used by code, exists only to provide some types to metadata
+ #[pallet::storage]
+ pub type DummyStorageValue<T> = StorageValue<Value = (CollectionStats, CollectionId, TokenId), QueryKind = OptionQuery>;
}
impl<T: Config> Pallet<T> {
@@ -355,10 +359,32 @@
);
Ok(())
}
+ pub fn adminlist(collection: CollectionId) -> Vec<T::CrossAccountId> {
+ <IsAdmin<T>>::iter_prefix((collection,))
+ .map(|(a, _)| a)
+ .collect()
+ }
+ pub fn allowlist(collection: CollectionId) -> Vec<T::CrossAccountId> {
+ <Allowlist<T>>::iter_prefix((collection,))
+ .map(|(a, _)| a)
+ .collect()
+ }
+ pub fn allowed(collection: CollectionId, user: T::CrossAccountId) -> bool {
+ <Allowlist<T>>::get((collection, user))
+ }
+ pub fn collection_stats() -> CollectionStats {
+ let created = <CreatedCollectionCount<T>>::get();
+ let destroyed = <DestroyedCollectionCount<T>>::get();
+ CollectionStats {
+ created: created.0,
+ destroyed: destroyed.0,
+ alive: created.0 - destroyed.0,
+ }
+ }
}
impl<T: Config> Pallet<T> {
- pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {
+ pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {
{
ensure!(
data.name.len() <= MAX_COLLECTION_NAME_LENGTH,
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -91,8 +91,8 @@
}
impl<T: Config> Pallet<T> {
- pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {
- PalletCommon::init_collection(data)
+ pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {
+ <PalletCommon<T>>::init_collection(data)
}
pub fn destroy_collection(
collection: FungibleHandle<T>,
pallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth--- a/pallets/nft/src/eth/sponsoring.rs
+++ b/pallets/nft/src/eth/sponsoring.rs
@@ -25,7 +25,7 @@
fn try_sponsor<T: Config>(
caller: &H160,
collection_id: CollectionId,
- collection: &Collection<T>,
+ collection: &Collection<T::AccountId>,
call: &[u8],
) -> Result<(), AnyError> {
let (method_id, mut reader) = AbiReader::new_call(call).map_err(|_| AnyError)?;
@@ -109,7 +109,7 @@
if !collection.sponsorship.confirmed() {
return None;
}
- if try_sponsor(who, collection_id, &collection, &call.1).is_ok() {
+ if try_sponsor::<T>(who, collection_id, &collection, &call.1).is_ok() {
return collection
.sponsorship
.sponsor()
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -42,8 +42,8 @@
CollectionId, CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,
};
use pallet_common::{
- account::CrossAccountId, CollectionHandle, IsAdmin, Pallet as PalletCommon,
- Error as CommonError, CommonWeightInfo, Allowlist,
+ account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,
+ CommonWeightInfo,
};
use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};
use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};
@@ -190,7 +190,7 @@
let who = ensure_signed(origin)?;
// Create new collection
- let new_collection = Collection::<T> {
+ let new_collection = Collection {
owner: who.clone(),
name: collection_name,
mode: mode.clone(),
@@ -208,14 +208,14 @@
};
let _id = match mode {
- CollectionMode::NFT => {PalletNonfungible::init_collection(new_collection)?},
+ CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(new_collection)?},
CollectionMode::Fungible(decimal_points) => {
// check params
ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);
- PalletFungible::init_collection(new_collection)?
+ <PalletFungible<T>>::init_collection(new_collection)?
}
CollectionMode::ReFungible => {
- PalletRefungible::init_collection(new_collection)?
+ <PalletRefungible<T>>::init_collection(new_collection)?
}
};
@@ -936,19 +936,5 @@
target_collection.save()
}
- }
-}
-
-// TODO: limit returned entries?
-impl<T: Config> Pallet<T> {
- pub fn adminlist(collection: CollectionId) -> Vec<T::CrossAccountId> {
- <IsAdmin<T>>::iter_prefix((collection,))
- .map(|(a, _)| a)
- .collect()
- }
- pub fn allowlist(collection: CollectionId) -> Vec<T::CrossAccountId> {
- <Allowlist<T>>::iter_prefix((collection,))
- .map(|(a, _)| a)
- .collect()
}
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -133,8 +133,8 @@
// unchecked calls skips any permission checks
impl<T: Config> Pallet<T> {
- pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {
- PalletCommon::init_collection(data)
+ pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {
+ <PalletCommon<T>>::init_collection(data)
}
pub fn destroy_collection(
collection: NonfungibleHandle<T>,
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -156,8 +156,8 @@
// unchecked calls skips any permission checks
impl<T: Config> Pallet<T> {
- pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {
- PalletCommon::init_collection(data)
+ pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {
+ <PalletCommon<T>>::init_collection(data)
}
pub fn destroy_collection(
collection: RefungibleHandle<T>,
primitives/nft/src/lib.rsdiffbeforeafterboth--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -207,8 +207,8 @@
#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
-pub struct Collection<T: frame_system::Config> {
- pub owner: T::AccountId,
+pub struct Collection<AccountId> {
+ pub owner: AccountId,
pub mode: CollectionMode,
pub access: AccessMode,
pub name: Vec<u16>, // 64 include null escape char
@@ -217,7 +217,7 @@
pub mint_mode: bool,
pub offchain_schema: Vec<u8>,
pub schema_version: SchemaVersion,
- pub sponsorship: SponsorshipState<T::AccountId>,
+ pub sponsorship: SponsorshipState<AccountId>,
pub limits: CollectionLimits, // Collection private restrictions
pub variable_on_chain_schema: Vec<u8>, //
pub const_on_chain_schema: Vec<u8>, //
@@ -413,3 +413,11 @@
CreateItemData::Fungible(item)
}
}
+
+#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]
+#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
+pub struct CollectionStats {
+ pub created: u32,
+ pub destroyed: u32,
+ pub alive: u32,
+}
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -1,6 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use nft_data_structs::{CollectionId, TokenId};
+use nft_data_structs::{CollectionId, TokenId, Collection, CollectionStats};
use sp_std::vec::Vec;
use sp_core::H160;
use codec::Decode;
@@ -32,6 +32,9 @@
fn adminlist(collection: CollectionId) -> Vec<CrossAccountId>;
fn allowlist(collection: CollectionId) -> Vec<CrossAccountId>;
+ fn allowed(collection: CollectionId, user: CrossAccountId) -> bool;
fn last_token_id(collection: CollectionId) -> TokenId;
+ fn collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>;
+ fn collection_stats() -> CollectionStats;
}
}
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -1040,14 +1040,23 @@
.or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))
}
fn adminlist(collection: CollectionId) -> Vec<CrossAccountId> {
- <pallet_nft::Pallet<Runtime>>::adminlist(collection)
+ <pallet_common::Pallet<Runtime>>::adminlist(collection)
}
fn allowlist(collection: CollectionId) -> Vec<CrossAccountId> {
- <pallet_nft::Pallet<Runtime>>::allowlist(collection)
+ <pallet_common::Pallet<Runtime>>::allowlist(collection)
+ }
+ fn allowed(collection: CollectionId, user: CrossAccountId) -> bool {
+ <pallet_common::Pallet<Runtime>>::allowed(collection, user)
}
fn last_token_id(collection: CollectionId) -> TokenId {
dispatch_nft_runtime!(collection.last_token_id())
}
+ fn collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>> {
+ <pallet_common::CollectionById<Runtime>>::get(collection)
+ }
+ fn collection_stats() -> CollectionStats {
+ <pallet_common::Pallet<Runtime>>::collection_stats()
+ }
}
impl sp_api::Core<Block> for Runtime {
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -8,7 +8,7 @@
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId} from './util/helpers';
+import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -20,7 +20,7 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.equal(alice.address);
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
@@ -38,7 +38,7 @@
const bob = privateKey('//Bob');
const charlie = privateKey('//CHARLIE');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.equal(alice.address);
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
tests/src/addToAllowList.test.tsdiffbeforeafterboth--- a/tests/src/addToAllowList.test.ts
+++ b/tests/src/addToAllowList.test.ts
@@ -18,6 +18,7 @@
normalizeAccountId,
addCollectionAdminExpectSuccess,
addToAllowListExpectFail,
+ getCreatedCollectionCount,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -55,7 +56,7 @@
it('Allow list an address in the collection that does not exist', async () => {
await usingApi(async (api) => {
// tslint:disable-next-line: no-bitwise
- const collectionId = ((await api.query.common.createdCollectionCount()).toNumber()) + 1;
+ const collectionId = await getCreatedCollectionCount(api) + 1;
const bob = privateKey('//Bob');
const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));
tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -18,6 +18,7 @@
transferExpectSuccess,
addCollectionAdminExpectSuccess,
adminApproveFromExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -94,13 +95,13 @@
it('Approve for a collection that does not exist', async () => {
await usingApi(async (api: ApiPromise) => {
// nft
- const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const nftCollectionCount = await getCreatedCollectionCount(api);
await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);
// fungible
- const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const fungibleCollectionCount = await getCreatedCollectionCount(api);
await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);
// reFungible
- const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const reFungibleCollectionCount = await getCreatedCollectionCount(api);
await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);
});
});
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -22,6 +22,7 @@
setMintPermissionExpectFailure,
destroyCollectionExpectFailure,
setPublicAccessModeExpectSuccess,
+ queryCollectionExpectSuccess,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -34,13 +35,13 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection =await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
- const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
});
});
@@ -53,7 +54,7 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
@@ -62,7 +63,7 @@
const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
});
});
@@ -74,13 +75,13 @@
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
- const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
// After changing the owner of the collection, all privileged methods are available to the new owner
@@ -118,20 +119,20 @@
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
- const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);
await submitTransactionAsync(bob, changeOwnerTx2);
// ownership lost
- const collectionAfterOwnerChange2 = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collectionAfterOwnerChange2 = await queryCollectionExpectSuccess(api, collectionId);
expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);
});
});
@@ -147,7 +148,7 @@
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);
// Verifying that nothing bad happened (network is live, new collections can be created, etc.)
@@ -166,7 +167,7 @@
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);
// Verifying that nothing bad happened (network is live, new collections can be created, etc.)
@@ -195,7 +196,7 @@
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
@@ -204,7 +205,7 @@
const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -20,6 +20,7 @@
addToAllowListExpectSuccess,
normalizeAccountId,
addCollectionAdminExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
@@ -335,7 +336,7 @@
// Find the collection that never existed
let collectionId = 0;
await usingApi(async (api) => {
- collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
+ collectionId = await getCreatedCollectionCount(api) + 1;
});
await confirmSponsorshipExpectFailure(collectionId, '//Bob');
tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -228,7 +228,7 @@
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
await submitTransactionAsync(alice, changeAdminTx);
- expect(await isAllowlisted(collectionId, bob.address)).to.be.false;
+ expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;
{
const transferTx = contract.tx.toggleAllowList(value, gasLimit, collectionId, bob.address, true);
@@ -236,7 +236,7 @@
const result = getGenericResult(events);
expect(result.success).to.be.true;
- expect(await isAllowlisted(collectionId, bob.address)).to.be.true;
+ expect(await isAllowlisted(api, collectionId, bob.address)).to.be.true;
}
{
const transferTx = contract.tx.toggleAllowList(value, gasLimit, collectionId, bob.address, false);
@@ -244,7 +244,7 @@
const result = getGenericResult(events);
expect(result.success).to.be.true;
- expect(await isAllowlisted(collectionId, bob.address)).to.be.false;
+ expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;
}
});
});
tests/src/createMultipleItems.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//5import {ApiPromise} from '@polkadot/api';6import {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {12 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 getGenericResult,15 normalizeAccountId,16 setCollectionLimitsExpectSuccess,17 addCollectionAdminExpectSuccess,18 getBalance,19 getTokenOwner,20 getLastTokenId,21 getVariableMetadata,22 getConstMetadata,23} from './util/helpers';2425chai.use(chaiAsPromised);26const expect = chai.expect;2728describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {29 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {30 await usingApi(async (api: ApiPromise) => {31 const collectionId = await createCollectionExpectSuccess();32 const itemsListIndexBefore = await getLastTokenId(api, collectionId);33 expect(itemsListIndexBefore).to.be.equal(0);34 const alice = privateKey('//Alice');35 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];36 const createMultipleItemsTx = api.tx.nft37 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);38 await submitTransactionAsync(alice, createMultipleItemsTx);39 const itemsListIndexAfter = await getLastTokenId(api, collectionId);40 expect(itemsListIndexAfter).to.be.equal(3);4142 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));43 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));44 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));4546 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);47 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);48 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);4950 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);51 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);52 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);53 });54 });5556 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {57 await usingApi(async (api: ApiPromise) => {58 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});59 const itemsListIndexBefore = await getLastTokenId(api, collectionId);60 expect(itemsListIndexBefore).to.be.equal(0);61 const alice = privateKey('//Alice');62 const args = [63 {Fungible: {value: 1}},64 {Fungible: {value: 2}},65 {Fungible: {value: 3}},66 ];67 const createMultipleItemsTx = api.tx.nft68 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);69 await submitTransactionAsync(alice, createMultipleItemsTx);70 const token1Data = await getBalance(api, collectionId, alice.address, 0);7172 expect(token1Data).to.be.equal(6n); // 1 + 2 + 373 });74 });7576 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {77 await usingApi(async (api: ApiPromise) => {78 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});79 const itemsListIndexBefore = await getLastTokenId(api, collectionId);80 expect(itemsListIndexBefore).to.be.equal(0);81 const alice = privateKey('//Alice');82 const args = [83 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},84 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},85 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},86 ];87 const createMultipleItemsTx = api.tx.nft88 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);89 await submitTransactionAsync(alice, createMultipleItemsTx);90 const itemsListIndexAfter = await getLastTokenId(api, collectionId);91 expect(itemsListIndexAfter).to.be.equal(3);9293 expect(await getBalance(api, collectionId, alice.address, 1)).to.be.equal(1n);94 expect(await getBalance(api, collectionId, alice.address, 2)).to.be.equal(1n);95 expect(await getBalance(api, collectionId, alice.address, 3)).to.be.equal(1n);9697 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);98 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);99 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);100101 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);102 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);103 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);104 });105 });106107 it('Can mint amount of items equals to collection limits', async () => {108 await usingApi(async (api) => {109 const alice = privateKey('//Alice');110111 const collectionId = await createCollectionExpectSuccess();112 await setCollectionLimitsExpectSuccess(alice, collectionId, {113 tokenLimit: 2,114 });115 const args = [116 {NFT: ['A', 'A']},117 {NFT: ['B', 'B']},118 ];119 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);120 const events = await submitTransactionAsync(alice, createMultipleItemsTx);121 const result = getGenericResult(events);122 expect(result.success).to.be.true;123 });124 });125});126127describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {128129 let alice: IKeyringPair;130 let bob: IKeyringPair;131132 before(async () => {133 await usingApi(async () => {134 alice = privateKey('//Alice');135 bob = privateKey('//Bob');136 });137 });138139 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {140 await usingApi(async (api: ApiPromise) => {141 const collectionId = await createCollectionExpectSuccess();142 const itemsListIndexBefore = await getLastTokenId(api, collectionId);143 expect(itemsListIndexBefore).to.be.equal(0);144 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);145 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];146 const createMultipleItemsTx = api.tx.nft147 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);148 await submitTransactionAsync(bob, createMultipleItemsTx);149 const itemsListIndexAfter = await getLastTokenId(api, collectionId);150 expect(itemsListIndexAfter).to.be.equal(3);151152 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));153 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));154 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));155156 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);157 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);158 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);159160 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);161 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);162 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);163 });164 });165166 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {167 await usingApi(async (api: ApiPromise) => {168 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});169 const itemsListIndexBefore = await getLastTokenId(api, collectionId);170 expect(itemsListIndexBefore).to.be.equal(0);171 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);172 const args = [173 {Fungible: {value: 1}},174 {Fungible: {value: 2}},175 {Fungible: {value: 3}},176 ];177 const createMultipleItemsTx = api.tx.nft178 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);179 await submitTransactionAsync(bob, createMultipleItemsTx);180 const token1Data = await getBalance(api, collectionId, bob.address, 0);181182 expect(token1Data).to.be.equal(6n); // 1 + 2 + 3183 });184 });185186 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {187 await usingApi(async (api: ApiPromise) => {188 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});189 const itemsListIndexBefore = await getLastTokenId(api, collectionId);190 expect(itemsListIndexBefore).to.be.equal(0);191 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);192 const args = [193 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},194 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},195 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},196 ];197 const createMultipleItemsTx = api.tx.nft198 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);199 await submitTransactionAsync(bob, createMultipleItemsTx);200 const itemsListIndexAfter = await getLastTokenId(api, collectionId);201 expect(itemsListIndexAfter).to.be.equal(3);202203 expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);204 expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(1n);205 expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(1n);206207 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);208 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);209 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);210211 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);212 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);213 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);214 });215 });216});217218describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {219220 let alice: IKeyringPair;221 let bob: IKeyringPair;222223 before(async () => {224 await usingApi(async () => {225 alice = privateKey('//Alice');226 bob = privateKey('//Bob');227 });228 });229230 it('Regular user cannot create items in active NFT collection', async () => {231 await usingApi(async (api: ApiPromise) => {232 const collectionId = await createCollectionExpectSuccess();233 const itemsListIndexBefore = await getLastTokenId(api, collectionId);234 expect(itemsListIndexBefore).to.be.equal(0);235 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];236 const createMultipleItemsTx = api.tx.nft237 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);238 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;239 });240 });241242 it('Regular user cannot create items in active Fungible collection', async () => {243 await usingApi(async (api: ApiPromise) => {244 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});245 const itemsListIndexBefore = await getLastTokenId(api, collectionId);246 expect(itemsListIndexBefore).to.be.equal(0);247 const args = [248 {Fungible: {value: 1}},249 {Fungible: {value: 2}},250 {Fungible: {value: 3}},251 ];252 const createMultipleItemsTx = api.tx.nft253 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);254 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;255 });256 });257258 it('Regular user cannot create items in active ReFungible collection', async () => {259 await usingApi(async (api: ApiPromise) => {260 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});261 const itemsListIndexBefore = await getLastTokenId(api, collectionId);262 expect(itemsListIndexBefore).to.be.equal(0);263 const args = [264 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},265 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},266 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},267 ];268 const createMultipleItemsTx = api.tx.nft269 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);270 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;271 });272 });273274 it('Create token in not existing collection', async () => {275 await usingApi(async (api: ApiPromise) => {276 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;277 const createMultipleItemsTx = api.tx.nft278 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);279 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;280 });281 });282283 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {284 await usingApi(async (api: ApiPromise) => {285 // NFT286 const collectionId = await createCollectionExpectSuccess();287 const alice = privateKey('//Alice');288 const args = [289 {NFT: ['A'.repeat(2049), 'A'.repeat(2049)]},290 {NFT: ['B'.repeat(2049), 'B'.repeat(2049)]},291 {NFT: ['C'.repeat(2049), 'C'.repeat(2049)]},292 ];293 const createMultipleItemsTx = api.tx.nft294 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);295 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;296297 // ReFungible298 const collectionIdReFungible =299 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});300 const argsReFungible = [301 {ReFungible: ['1'.repeat(2049), '1'.repeat(2049), 10]},302 {ReFungible: ['2'.repeat(2049), '2'.repeat(2049), 10]},303 {ReFungible: ['3'.repeat(2049), '3'.repeat(2049), 10]},304 ];305 const createMultipleItemsTxFungible = api.tx.nft306 .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);307 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;308 });309 });310311 it('Create tokens with different types', async () => {312 await usingApi(async (api: ApiPromise) => {313 const collectionId = await createCollectionExpectSuccess();314 const createMultipleItemsTx = api.tx.nft315 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'Fungible', 'ReFungible']);316 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;317 // garbage collection :-D318 await destroyCollectionExpectSuccess(collectionId);319 });320 });321322 it('Create tokens with different data limits <> maximum data limit', async () => {323 await usingApi(async (api: ApiPromise) => {324 const collectionId = await createCollectionExpectSuccess();325 const args = [326 {NFT: ['A', 'A']},327 {NFT: ['B', 'B'.repeat(2049)]},328 {NFT: ['C'.repeat(2049), 'C']},329 ];330 const createMultipleItemsTx = await api.tx.nft331 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);332 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;333 });334 });335336 it('Fails when minting tokens exceeds collectionLimits amount', async () => {337 await usingApi(async (api) => {338339 const collectionId = await createCollectionExpectSuccess();340 await setCollectionLimitsExpectSuccess(alice, collectionId, {341 tokenLimit: 1,342 });343 const args = [344 {NFT: ['A', 'A']},345 {NFT: ['B', 'B']},346 ];347 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);348 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;349 });350 });351});1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//5import {ApiPromise} from '@polkadot/api';6import {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {12 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 getGenericResult,15 normalizeAccountId,16 setCollectionLimitsExpectSuccess,17 addCollectionAdminExpectSuccess,18 getBalance,19 getTokenOwner,20 getLastTokenId,21 getVariableMetadata,22 getConstMetadata,23 getCreatedCollectionCount,24} from './util/helpers';2526chai.use(chaiAsPromised);27const expect = chai.expect;2829describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {30 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {31 await usingApi(async (api: ApiPromise) => {32 const collectionId = await createCollectionExpectSuccess();33 const itemsListIndexBefore = await getLastTokenId(api, collectionId);34 expect(itemsListIndexBefore).to.be.equal(0);35 const alice = privateKey('//Alice');36 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];37 const createMultipleItemsTx = api.tx.nft38 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);39 await submitTransactionAsync(alice, createMultipleItemsTx);40 const itemsListIndexAfter = await getLastTokenId(api, collectionId);41 expect(itemsListIndexAfter).to.be.equal(3);4243 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));44 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));45 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));4647 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);48 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);49 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);5051 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);52 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);53 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);54 });55 });5657 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {58 await usingApi(async (api: ApiPromise) => {59 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});60 const itemsListIndexBefore = await getLastTokenId(api, collectionId);61 expect(itemsListIndexBefore).to.be.equal(0);62 const alice = privateKey('//Alice');63 const args = [64 {Fungible: {value: 1}},65 {Fungible: {value: 2}},66 {Fungible: {value: 3}},67 ];68 const createMultipleItemsTx = api.tx.nft69 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);70 await submitTransactionAsync(alice, createMultipleItemsTx);71 const token1Data = await getBalance(api, collectionId, alice.address, 0);7273 expect(token1Data).to.be.equal(6n); // 1 + 2 + 374 });75 });7677 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {78 await usingApi(async (api: ApiPromise) => {79 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});80 const itemsListIndexBefore = await getLastTokenId(api, collectionId);81 expect(itemsListIndexBefore).to.be.equal(0);82 const alice = privateKey('//Alice');83 const args = [84 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},85 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},86 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},87 ];88 const createMultipleItemsTx = api.tx.nft89 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);90 await submitTransactionAsync(alice, createMultipleItemsTx);91 const itemsListIndexAfter = await getLastTokenId(api, collectionId);92 expect(itemsListIndexAfter).to.be.equal(3);9394 expect(await getBalance(api, collectionId, alice.address, 1)).to.be.equal(1n);95 expect(await getBalance(api, collectionId, alice.address, 2)).to.be.equal(1n);96 expect(await getBalance(api, collectionId, alice.address, 3)).to.be.equal(1n);9798 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);99 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);100 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);101102 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);103 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);104 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);105 });106 });107108 it('Can mint amount of items equals to collection limits', async () => {109 await usingApi(async (api) => {110 const alice = privateKey('//Alice');111112 const collectionId = await createCollectionExpectSuccess();113 await setCollectionLimitsExpectSuccess(alice, collectionId, {114 tokenLimit: 2,115 });116 const args = [117 {NFT: ['A', 'A']},118 {NFT: ['B', 'B']},119 ];120 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);121 const events = await submitTransactionAsync(alice, createMultipleItemsTx);122 const result = getGenericResult(events);123 expect(result.success).to.be.true;124 });125 });126});127128describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {129130 let alice: IKeyringPair;131 let bob: IKeyringPair;132133 before(async () => {134 await usingApi(async () => {135 alice = privateKey('//Alice');136 bob = privateKey('//Bob');137 });138 });139140 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {141 await usingApi(async (api: ApiPromise) => {142 const collectionId = await createCollectionExpectSuccess();143 const itemsListIndexBefore = await getLastTokenId(api, collectionId);144 expect(itemsListIndexBefore).to.be.equal(0);145 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);146 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];147 const createMultipleItemsTx = api.tx.nft148 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);149 await submitTransactionAsync(bob, createMultipleItemsTx);150 const itemsListIndexAfter = await getLastTokenId(api, collectionId);151 expect(itemsListIndexAfter).to.be.equal(3);152153 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));154 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));155 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));156157 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);158 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);159 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);160161 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);162 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);163 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);164 });165 });166167 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {168 await usingApi(async (api: ApiPromise) => {169 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});170 const itemsListIndexBefore = await getLastTokenId(api, collectionId);171 expect(itemsListIndexBefore).to.be.equal(0);172 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);173 const args = [174 {Fungible: {value: 1}},175 {Fungible: {value: 2}},176 {Fungible: {value: 3}},177 ];178 const createMultipleItemsTx = api.tx.nft179 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);180 await submitTransactionAsync(bob, createMultipleItemsTx);181 const token1Data = await getBalance(api, collectionId, bob.address, 0);182183 expect(token1Data).to.be.equal(6n); // 1 + 2 + 3184 });185 });186187 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {188 await usingApi(async (api: ApiPromise) => {189 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});190 const itemsListIndexBefore = await getLastTokenId(api, collectionId);191 expect(itemsListIndexBefore).to.be.equal(0);192 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);193 const args = [194 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},195 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},196 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},197 ];198 const createMultipleItemsTx = api.tx.nft199 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);200 await submitTransactionAsync(bob, createMultipleItemsTx);201 const itemsListIndexAfter = await getLastTokenId(api, collectionId);202 expect(itemsListIndexAfter).to.be.equal(3);203204 expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);205 expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(1n);206 expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(1n);207208 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);209 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);210 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);211212 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);213 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);214 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);215 });216 });217});218219describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {220221 let alice: IKeyringPair;222 let bob: IKeyringPair;223224 before(async () => {225 await usingApi(async () => {226 alice = privateKey('//Alice');227 bob = privateKey('//Bob');228 });229 });230231 it('Regular user cannot create items in active NFT collection', async () => {232 await usingApi(async (api: ApiPromise) => {233 const collectionId = await createCollectionExpectSuccess();234 const itemsListIndexBefore = await getLastTokenId(api, collectionId);235 expect(itemsListIndexBefore).to.be.equal(0);236 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];237 const createMultipleItemsTx = api.tx.nft238 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);239 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;240 });241 });242243 it('Regular user cannot create items in active Fungible collection', async () => {244 await usingApi(async (api: ApiPromise) => {245 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});246 const itemsListIndexBefore = await getLastTokenId(api, collectionId);247 expect(itemsListIndexBefore).to.be.equal(0);248 const args = [249 {Fungible: {value: 1}},250 {Fungible: {value: 2}},251 {Fungible: {value: 3}},252 ];253 const createMultipleItemsTx = api.tx.nft254 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);255 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;256 });257 });258259 it('Regular user cannot create items in active ReFungible collection', async () => {260 await usingApi(async (api: ApiPromise) => {261 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});262 const itemsListIndexBefore = await getLastTokenId(api, collectionId);263 expect(itemsListIndexBefore).to.be.equal(0);264 const args = [265 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},266 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},267 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},268 ];269 const createMultipleItemsTx = api.tx.nft270 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);271 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;272 });273 });274275 it('Create token in not existing collection', async () => {276 await usingApi(async (api: ApiPromise) => {277 const collectionId = await getCreatedCollectionCount(api) + 1;278 const createMultipleItemsTx = api.tx.nft279 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);280 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;281 });282 });283284 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {285 await usingApi(async (api: ApiPromise) => {286 // NFT287 const collectionId = await createCollectionExpectSuccess();288 const alice = privateKey('//Alice');289 const args = [290 {NFT: ['A'.repeat(2049), 'A'.repeat(2049)]},291 {NFT: ['B'.repeat(2049), 'B'.repeat(2049)]},292 {NFT: ['C'.repeat(2049), 'C'.repeat(2049)]},293 ];294 const createMultipleItemsTx = api.tx.nft295 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);296 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;297298 // ReFungible299 const collectionIdReFungible =300 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});301 const argsReFungible = [302 {ReFungible: ['1'.repeat(2049), '1'.repeat(2049), 10]},303 {ReFungible: ['2'.repeat(2049), '2'.repeat(2049), 10]},304 {ReFungible: ['3'.repeat(2049), '3'.repeat(2049), 10]},305 ];306 const createMultipleItemsTxFungible = api.tx.nft307 .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);308 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;309 });310 });311312 it('Create tokens with different types', async () => {313 await usingApi(async (api: ApiPromise) => {314 const collectionId = await createCollectionExpectSuccess();315 const createMultipleItemsTx = api.tx.nft316 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'Fungible', 'ReFungible']);317 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;318 // garbage collection :-D319 await destroyCollectionExpectSuccess(collectionId);320 });321 });322323 it('Create tokens with different data limits <> maximum data limit', async () => {324 await usingApi(async (api: ApiPromise) => {325 const collectionId = await createCollectionExpectSuccess();326 const args = [327 {NFT: ['A', 'A']},328 {NFT: ['B', 'B'.repeat(2049)]},329 {NFT: ['C'.repeat(2049), 'C']},330 ];331 const createMultipleItemsTx = await api.tx.nft332 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);333 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;334 });335 });336337 it('Fails when minting tokens exceeds collectionLimits amount', async () => {338 await usingApi(async (api) => {339340 const collectionId = await createCollectionExpectSuccess();341 await setCollectionLimitsExpectSuccess(alice, collectionId, {342 tokenLimit: 1,343 });344 const args = [345 {NFT: ['A', 'A']},346 {NFT: ['B', 'B']},347 ];348 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);349 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;350 });351 });352});tests/src/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -13,6 +13,7 @@
destroyCollectionExpectFailure,
setCollectionLimitsExpectSuccess,
addCollectionAdminExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -46,7 +47,7 @@
it('(!negative test!) Destroy a collection that never existed', async () => {
await usingApi(async (api) => {
// Find the collection that never existed
- const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
+ const collectionId = await getCreatedCollectionCount(api) + 1;
await destroyCollectionExpectFailure(collectionId);
});
});
tests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-rpc.ts
+++ b/tests/src/interfaces/augment-api-rpc.ts
@@ -1,7 +1,7 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
-import type { NftDataStructsCollectionId, NftDataStructsTokenId, PalletCommonAccountBasicCrossAccountIdRepr } from './nft';
+import type { NftDataStructsCollection, NftDataStructsCollectionId, NftDataStructsCollectionStats, NftDataStructsTokenId, PalletCommonAccountBasicCrossAccountIdRepr } from './nft';
import type { Bytes, HashMap, Json, Metadata, Null, Option, StorageKey, Text, U256, U64, Vec, bool, u128, u32, u64 } from '@polkadot/types';
import type { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';
import type { EpochAuthorship } from '@polkadot/types/interfaces/babe';
@@ -373,6 +373,10 @@
**/
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>>;
/**
+ * Check if user is allowed to use collection
+ **/
+ allowed: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, account: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, at?: Hash | string | Uint8Array) => Observable<bool>>;
+ /**
* Get allowlist
**/
allowlist: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Vec<PalletCommonAccountBasicCrossAccountIdRepr>>>;
@@ -381,6 +385,14 @@
**/
balance: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, account: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, tokenId: NftDataStructsTokenId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<u128>>;
/**
+ * Get collection by specified id
+ **/
+ collectionById: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<NftDataStructsCollection>>>;
+ /**
+ * Get collection stats
+ **/
+ collectionStats: AugmentedRpc<(at?: Hash | string | Uint8Array) => Observable<NftDataStructsCollectionStats>>;
+ /**
* Get tokens contained in collection
**/
collectionTokens: AugmentedRpc<(collection: NftDataStructsCollectionId | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Vec<NftDataStructsTokenId>>>;
tests/src/interfaces/augment-types.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-types.ts
+++ b/tests/src/interfaces/augment-types.ts
@@ -2,7 +2,7 @@
/* eslint-disable */
import type { EthereumBlock, EthereumLog, EthereumReceipt, EthereumTransactionLegacyTransaction, EvmCoreErrorExitReason, FpRpcTransactionStatus } from './ethereum';
-import type { NftDataStructsAccessMode, NftDataStructsCollection, NftDataStructsCollectionId, NftDataStructsCollectionLimits, NftDataStructsCollectionMode, NftDataStructsCreateItemData, NftDataStructsMetaUpdatePermission, NftDataStructsSchemaVersion, NftDataStructsSponsorshipState, NftDataStructsTokenId, PalletCommonAccountBasicCrossAccountIdRepr, PalletNonfungibleItemData, PalletRefungibleItemData, PalletUnqSchedulerCallSpec, PalletUnqSchedulerReleases, PalletUnqSchedulerScheduledV2 } from './nft';
+import type { NftDataStructsAccessMode, NftDataStructsCollection, NftDataStructsCollectionId, NftDataStructsCollectionLimits, NftDataStructsCollectionMode, NftDataStructsCollectionStats, NftDataStructsCreateItemData, NftDataStructsMetaUpdatePermission, NftDataStructsSchemaVersion, NftDataStructsSponsorshipState, NftDataStructsTokenId, PalletCommonAccountBasicCrossAccountIdRepr, PalletNonfungibleItemData, PalletRefungibleItemData, PalletUnqSchedulerCallSpec, PalletUnqSchedulerReleases, PalletUnqSchedulerScheduledV2 } from './nft';
import type { CumulusPalletDmpQueueConfigData, CumulusPalletDmpQueuePageIndexData, CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, CumulusPalletXcmpQueueInboundStatus, CumulusPalletXcmpQueueOutboundStatus, CumulusPalletXcmpQueueQueueConfigData, CumulusPrimitivesParachainInherentParachainInherentData, PolkadotParachainPrimitivesXcmpMessageFormat, PolkadotPrimitivesV1AbridgedHostConfiguration, PolkadotPrimitivesV1PersistedValidationData } from './polkadot';
import 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';
import type { AssetApproval, AssetApprovalKey, AssetBalance, AssetDestroyWitness, AssetDetails, AssetMetadata, TAssetBalance, TAssetDepositBalance } from '@polkadot/types/interfaces/assets';
@@ -627,6 +627,7 @@
NftDataStructsCollectionId: NftDataStructsCollectionId;
NftDataStructsCollectionLimits: NftDataStructsCollectionLimits;
NftDataStructsCollectionMode: NftDataStructsCollectionMode;
+ NftDataStructsCollectionStats: NftDataStructsCollectionStats;
NftDataStructsCreateItemData: NftDataStructsCreateItemData;
NftDataStructsMetaUpdatePermission: NftDataStructsMetaUpdatePermission;
NftDataStructsSchemaVersion: NftDataStructsSchemaVersion;
tests/src/interfaces/nft/definitions.tsdiffbeforeafterboth--- a/tests/src/interfaces/nft/definitions.ts
+++ b/tests/src/interfaces/nft/definitions.ts
@@ -40,6 +40,9 @@
constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),
variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),
tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'),
+ collectionById: fun('Get collection by specified id', [collectionParam], 'Option<NftDataStructsCollection>'),
+ collectionStats: fun('Get collection stats', [], 'NftDataStructsCollectionStats'),
+ allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),
},
types: {
PalletCommonAccountBasicCrossAccountIdRepr: {
@@ -64,6 +67,11 @@
constOnChainSchema: 'Vec<u8>',
metaUpdatePermission: 'NftDataStructsMetaUpdatePermission',
},
+ NftDataStructsCollectionStats: {
+ created: 'u32',
+ destroyed: 'u32',
+ alive: 'u32',
+ },
NftDataStructsCollectionId: 'u32',
NftDataStructsTokenId: 'u32',
PalletNonfungibleItemData: mkDummy('NftItemData'),
tests/src/interfaces/nft/types.tsdiffbeforeafterboth--- a/tests/src/interfaces/nft/types.ts
+++ b/tests/src/interfaces/nft/types.ts
@@ -48,6 +48,13 @@
readonly dummyCollectionMode: u32;
}
+/** @name NftDataStructsCollectionStats */
+export interface NftDataStructsCollectionStats extends Struct {
+ readonly created: u32;
+ readonly destroyed: u32;
+ readonly alive: u32;
+}
+
/** @name NftDataStructsCreateItemData */
export interface NftDataStructsCreateItemData extends Struct {
readonly dummyCreateItemData: u32;
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -8,7 +8,7 @@
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId} from './util/helpers';
+import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -19,7 +19,7 @@
const collectionId = await createCollectionExpectSuccess();
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
// first - add collection admin Bob
const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
@@ -43,7 +43,7 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.eq(alice.address);
// first - add collection admin Bob
const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -18,6 +18,7 @@
removeCollectionSponsorExpectFailure,
normalizeAccountId,
addCollectionAdminExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
@@ -98,7 +99,7 @@
// Find the collection that never existed
let collectionId = 0;
await usingApi(async (api) => {
- collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
+ collectionId = await getCreatedCollectionCount(api) + 1;
});
await removeCollectionSponsorExpectFailure(collectionId);
tests/src/removeFromAllowList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromAllowList.test.ts
+++ b/tests/src/removeFromAllowList.test.ts
@@ -37,13 +37,13 @@
});
it('ensure bob is not in allowlist after removal', async () => {
- await usingApi(async () => {
+ await usingApi(async api => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableAllowListExpectSuccess(alice, collectionId);
await addToAllowListExpectSuccess(alice, collectionId, bob.address);
await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));
- expect(await isAllowlisted(collectionId, bob.address)).to.be.false;
+ expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;
});
});
@@ -104,13 +104,13 @@
});
it('ensure address is not in allowlist after removal', async () => {
- await usingApi(async () => {
+ await usingApi(async api => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableAllowListExpectSuccess(alice, collectionId);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));
- expect(await isAllowlisted(collectionId, charlie.address)).to.be.false;
+ expect(await isAllowlisted(api, collectionId, charlie.address)).to.be.false;
});
});
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -11,6 +11,7 @@
destroyCollectionExpectSuccess,
setCollectionSponsorExpectFailure,
addCollectionAdminExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
@@ -77,7 +78,7 @@
// Find the collection that never existed
let collectionId = 0;
await usingApi(async (api) => {
- collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
+ collectionId = await getCreatedCollectionCount(api) + 1;
});
await setCollectionSponsorExpectFailure(collectionId, bob.address);
tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setConstOnChainSchema.test.ts
+++ b/tests/src/setConstOnChainSchema.test.ts
@@ -12,6 +12,8 @@
createCollectionExpectSuccess,
destroyCollectionExpectSuccess,
addCollectionAdminExpectSuccess,
+ queryCollectionExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -37,7 +39,7 @@
it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.eq(alice.address);
const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
await submitTransactionAsync(alice, setShema);
@@ -47,7 +49,7 @@
it('Collection admin can set the scheme', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.eq(alice.address);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
@@ -60,7 +62,7 @@
const collectionId = await createCollectionExpectSuccess();
const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
await submitTransactionAsync(alice, setShema);
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.constOnChainSchema.toString()).to.be.eq(shema);
});
});
@@ -71,7 +73,7 @@
it('Set a non-existent collection', async () => {
await usingApi(async (api) => {
// tslint:disable-next-line: radix
- const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
+ const collectionId = await getCreatedCollectionCount(api) + 1;
const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;
});
@@ -97,7 +99,7 @@
it('Execute method not on behalf of the collection owner', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.eq(alice.address);
const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;
tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth--- a/tests/src/setPublicAccessMode.test.ts
+++ b/tests/src/setPublicAccessMode.test.ts
@@ -19,6 +19,7 @@
enableAllowListExpectSuccess,
normalizeAccountId,
addCollectionAdminExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -60,7 +61,7 @@
it('Set a non-existent collection', async () => {
await usingApi(async (api: ApiPromise) => {
// tslint:disable-next-line: radix
- const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
+ const collectionId = await getCreatedCollectionCount(api) + 1;
const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setVariableOnChainSchema.test.ts
+++ b/tests/src/setVariableOnChainSchema.test.ts
@@ -12,6 +12,8 @@
createCollectionExpectSuccess,
destroyCollectionExpectSuccess,
addCollectionAdminExpectSuccess,
+ queryCollectionExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -37,7 +39,7 @@
it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.eq(alice.address);
const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
await submitTransactionAsync(alice, setSchema);
@@ -49,7 +51,7 @@
const collectionId = await createCollectionExpectSuccess();
const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
await submitTransactionAsync(alice, setSchema);
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);
});
@@ -61,7 +63,7 @@
it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.eq(alice.address);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
@@ -75,7 +77,7 @@
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
await submitTransactionAsync(bob, setSchema);
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);
});
@@ -87,7 +89,7 @@
it('Set a non-existent collection', async () => {
await usingApi(async (api) => {
// tslint:disable-next-line: radix
- const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
+ const collectionId = await getCreatedCollectionCount(api) + 1;
const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
});
@@ -113,7 +115,7 @@
it('Execute method not on behalf of the collection owner', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.eq(alice.address);
const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;
tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -19,6 +19,7 @@
transferExpectFailure,
transferExpectSuccess,
addCollectionAdminExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
let alice: IKeyringPair;
@@ -132,13 +133,13 @@
it('Transfer with not existed collection_id', async () => {
await usingApi(async (api) => {
// nft
- const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const nftCollectionCount = await getCreatedCollectionCount(api);
await transferExpectFailure(nftCollectionCount + 1, 1, alice, bob, 1);
// fungible
- const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const fungibleCollectionCount = await getCreatedCollectionCount(api);
await transferExpectFailure(fungibleCollectionCount + 1, 0, alice, bob, 1);
// reFungible
- const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const reFungibleCollectionCount = await getCreatedCollectionCount(api);
await transferExpectFailure(reFungibleCollectionCount + 1, 1, alice, bob, 1);
});
});
tests/src/transferFrom.test.tsdiffbeforeafterboth--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -19,6 +19,7 @@
transferFromExpectSuccess,
burnItemExpectSuccess,
setCollectionLimitsExpectSuccess,
+ getCreatedCollectionCount,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -109,18 +110,18 @@
it('transferFrom for a collection that does not exist', async () => {
await usingApi(async (api: ApiPromise) => {
// nft
- const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const nftCollectionCount = await getCreatedCollectionCount(api);
await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);
await transferFromExpectFail(nftCollectionCount + 1, 1, bob, alice, charlie, 1);
// fungible
- const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const fungibleCollectionCount = await getCreatedCollectionCount(api);
await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);
await transferFromExpectFail(fungibleCollectionCount + 1, 0, bob, alice, charlie, 1);
// reFungible
- const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ const reFungibleCollectionCount = await getCreatedCollectionCount(api);
await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);
await transferFromExpectFail(reFungibleCollectionCount + 1, 1, bob, alice, charlie, 1);
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -269,7 +269,7 @@
let collectionId = 0;
await usingApi(async (api) => {
// Get number of collections before the transaction
- const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();
+ const collectionCountBefore = await getCreatedCollectionCount(api);
// Run the CreateCollection transaction
const alicePrivateKey = privateKey('//Alice');
@@ -288,10 +288,10 @@
const result = getCreateCollectionResult(events);
// Get number of collections after the transaction
- const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();
+ const collectionCountAfter = await getCreatedCollectionCount(api);
// Get the collection
- const collection = (await api.query.common.collectionById(result.collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, result.collectionId);
// What to expect
// tslint:disable-next-line:no-unused-expression
@@ -325,7 +325,7 @@
await usingApi(async (api) => {
// Get number of collections before the transaction
- const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();
+ const collectionCountBefore = await getCreatedCollectionCount(api);
// Run the CreateCollection transaction
const alicePrivateKey = privateKey('//Alice');
@@ -334,7 +334,7 @@
const result = getCreateCollectionResult(events);
// Get number of collections after the transaction
- const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();
+ const collectionCountAfter = await getCreatedCollectionCount(api);
// What to expect
// tslint:disable-next-line:no-unused-expression
@@ -364,7 +364,7 @@
}
export async function findNotExistingCollection(api: ApiPromise): Promise<number> {
- const totalNumber = (await api.query.common.createdCollectionCount()).toNumber();
+ const totalNumber = await getCreatedCollectionCount(api);
const newCollection: number = totalNumber + 1;
return newCollection;
}
@@ -398,7 +398,7 @@
expect(result).to.be.true;
// What to expect
- expect((await api.query.common.collectionById(collectionId)).isNone).to.be.true;
+ expect(await getDetailedCollectionInfo(api, collectionId)).to.be.null;
});
}
@@ -432,7 +432,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
// What to expect
expect(result.success).to.be.true;
@@ -452,7 +452,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
// What to expect
expect(result.success).to.be.true;
@@ -490,7 +490,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
// What to expect
expect(result.success).to.be.true;
@@ -1057,7 +1057,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
// What to expect
// tslint:disable-next-line:no-unused-expression
@@ -1105,7 +1105,7 @@
expect(result.success).to.be.true;
// Get the collection
- const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.mintMode.toHuman()).to.be.equal(enabled);
});
@@ -1137,15 +1137,13 @@
});
}
-export async function isAllowlisted(collectionId: number, address: string | CrossAccountId) {
- return await usingApi(async (api) => {
- return (await api.query.common.allowlist(collectionId, normalizeAccountId(address))).toJSON();
- });
+export async function isAllowlisted(api: ApiPromise, collectionId: number, address: string | CrossAccountId) {
+ return (await api.rpc.nft.allowed(collectionId, normalizeAccountId(address))).toJSON();
}
export async function addToAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {
await usingApi(async (api) => {
- expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.false;
+ expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.false;
// Run the transaction
const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));
@@ -1153,14 +1151,14 @@
const result = getGenericResult(events);
expect(result.success).to.be.true;
- expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;
+ expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;
});
}
export async function addToAllowListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
await usingApi(async (api) => {
- expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;
+ expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;
// Run the transaction
const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));
@@ -1168,7 +1166,7 @@
const result = getGenericResult(events);
expect(result.success).to.be.true;
- expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;
+ expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;
});
}
@@ -1214,16 +1212,16 @@
export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)
: Promise<NftDataStructsCollection | null> => {
- return (await api.query.common.collectionById(collectionId)).unwrapOr(null);
+ return (await api.rpc.nft.collectionById(collectionId)).unwrapOr(null);
};
export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {
// set global object - collectionsCount
- return (await api.query.common.createdCollectionCount()).toNumber();
+ return (await api.rpc.nft.collectionStats()).created.toNumber();
};
export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<NftDataStructsCollection> {
- return (await api.query.common.collectionById(collectionId)).unwrap();
+ return (await api.rpc.nft.collectionById(collectionId)).unwrap();
}
export async function waitNewBlocks(blocksCount = 1): Promise<void> {