difftreelog
Integration tests for setCollectionSponsor
in: master
6 files changed
node/src/chain_spec.rsdiffbeforeafterboth--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -193,7 +193,7 @@
offchain_schema: vec![],
schema_version: SchemaVersion::default(),
sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
- unconfirmed_sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
+ sponsor_confirmed: true,
const_on_chain_schema: vec![],
variable_on_chain_schema: vec![],
limits: CollectionLimits::default()
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -136,7 +136,7 @@
pub offchain_schema: Vec<u8>,
pub schema_version: SchemaVersion,
pub sponsor: AccountId, // Who pays fees. If set to default address, the fees are applied to the transaction sender
- pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship
+ pub sponsor_confirmed: bool, // False if sponsor address has not yet confirmed sponsorship. True otherwise.
pub limits: CollectionLimits, // Collection private restrictions
pub variable_on_chain_schema: Vec<u8>, //
pub const_on_chain_schema: Vec<u8>, //
@@ -591,7 +591,7 @@
offchain_schema: Vec::new(),
schema_version: SchemaVersion::ImageURL,
sponsor: T::AccountId::default(),
- unconfirmed_sponsor: T::AccountId::default(),
+ sponsor_confirmed: false,
variable_on_chain_schema: Vec::new(),
const_on_chain_schema: Vec::new(),
limits: CollectionLimits::default(),
@@ -869,7 +869,8 @@
let mut target_collection = <Collection<T>>::get(collection_id);
ensure!(sender == target_collection.owner, Error::<T>::NoPermission);
- target_collection.unconfirmed_sponsor = new_sponsor;
+ target_collection.sponsor = new_sponsor;
+ target_collection.sponsor_confirmed = false;
<Collection<T>>::insert(collection_id, target_collection);
Ok(())
@@ -889,10 +890,9 @@
ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);
let mut target_collection = <Collection<T>>::get(collection_id);
- ensure!(sender == target_collection.unconfirmed_sponsor, Error::<T>::ConfirmUnsetSponsorFail);
+ ensure!(sender == target_collection.sponsor, Error::<T>::ConfirmUnsetSponsorFail);
- target_collection.sponsor = target_collection.unconfirmed_sponsor;
- target_collection.unconfirmed_sponsor = T::AccountId::default();
+ target_collection.sponsor_confirmed = true;
<Collection<T>>::insert(collection_id, target_collection);
Ok(())
@@ -917,6 +917,7 @@
ensure!(sender == target_collection.owner, Error::<T>::NoPermission);
target_collection.sponsor = T::AccountId::default();
+ target_collection.sponsor_confirmed = false;
<Collection<T>>::insert(collection_id, target_collection);
Ok(())
@@ -2338,7 +2339,8 @@
Some(Call::create_item(collection_id, _owner, _properties)) => {
// check free create limit
- if <Collection<T>>::get(collection_id).limits.sponsored_data_size >= (_properties.len() as u32)
+ if (<Collection<T>>::get(collection_id).limits.sponsored_data_size >= (_properties.len() as u32)) &&
+ (<Collection<T>>::get(collection_id).sponsor_confirmed)
{
<Collection<T>>::get(collection_id).sponsor
} else {
@@ -2347,84 +2349,87 @@
}
Some(Call::transfer(_new_owner, collection_id, _item_id, _value)) => {
- let _collection_limits = <Collection<T>>::get(collection_id).limits;
- let _collection_mode = <Collection<T>>::get(collection_id).mode;
-
- // sponsor timeout
- let sponsor_transfer = match _collection_mode {
- CollectionMode::NFT => {
-
- // get correct limit
- let limit: u32 = if _collection_limits.sponsor_transfer_timeout > 0 {
- _collection_limits.sponsor_transfer_timeout
- } else {
- ChainLimit::get().nft_sponsor_transfer_timeout
- };
-
- let basket = <NftTransferBasket<T>>::get(collection_id, _item_id);
- let block_number = <system::Module<T>>::block_number() as T::BlockNumber;
- let limit_time = basket + limit.into();
- if block_number >= limit_time {
- <NftTransferBasket<T>>::insert(collection_id, _item_id, block_number);
- true
- }
- else {
- false
- }
- }
- CollectionMode::Fungible(_) => {
-
- // get correct limit
- let limit: u32 = if _collection_limits.sponsor_transfer_timeout > 0 {
- _collection_limits.sponsor_transfer_timeout
- } else {
- ChainLimit::get().fungible_sponsor_transfer_timeout
- };
-
- let mut basket = <FungibleTransferBasket<T>>::get(collection_id, _item_id);
- let block_number = <system::Module<T>>::block_number() as T::BlockNumber;
- if basket.iter().any(|i| i.address == _new_owner.clone())
- {
- let item = basket.iter_mut().find(|i| i.address == _new_owner.clone()).unwrap().clone();
- let limit_time = item.start_block + limit.into();
+ let mut sponsor_transfer = false;
+ if <Collection<T>>::get(collection_id).sponsor_confirmed {
+ let _collection_limits = <Collection<T>>::get(collection_id).limits;
+ let _collection_mode = <Collection<T>>::get(collection_id).mode;
+
+ // sponsor timeout
+ sponsor_transfer = match _collection_mode {
+ CollectionMode::NFT => {
+
+ // get correct limit
+ let limit: u32 = if _collection_limits.sponsor_transfer_timeout > 0 {
+ _collection_limits.sponsor_transfer_timeout
+ } else {
+ ChainLimit::get().nft_sponsor_transfer_timeout
+ };
+
+ let basket = <NftTransferBasket<T>>::get(collection_id, _item_id);
+ let block_number = <system::Module<T>>::block_number() as T::BlockNumber;
+ let limit_time = basket + limit.into();
if block_number >= limit_time {
- basket.retain(|x| x.address == item.address);
- basket.push(BasketItem { start_block: block_number, address: _new_owner.clone() });
- <FungibleTransferBasket<T>>::insert(collection_id, _item_id, basket);
+ <NftTransferBasket<T>>::insert(collection_id, _item_id, block_number);
true
}
else {
false
}
}
- else {
- basket.push(BasketItem { start_block: block_number, address: _new_owner.clone()});
- true
+ CollectionMode::Fungible(_) => {
+
+ // get correct limit
+ let limit: u32 = if _collection_limits.sponsor_transfer_timeout > 0 {
+ _collection_limits.sponsor_transfer_timeout
+ } else {
+ ChainLimit::get().fungible_sponsor_transfer_timeout
+ };
+
+ let mut basket = <FungibleTransferBasket<T>>::get(collection_id, _item_id);
+ let block_number = <system::Module<T>>::block_number() as T::BlockNumber;
+ if basket.iter().any(|i| i.address == _new_owner.clone())
+ {
+ let item = basket.iter_mut().find(|i| i.address == _new_owner.clone()).unwrap().clone();
+ let limit_time = item.start_block + limit.into();
+ if block_number >= limit_time {
+ basket.retain(|x| x.address == item.address);
+ basket.push(BasketItem { start_block: block_number, address: _new_owner.clone() });
+ <FungibleTransferBasket<T>>::insert(collection_id, _item_id, basket);
+ true
+ }
+ else {
+ false
+ }
+ }
+ else {
+ basket.push(BasketItem { start_block: block_number, address: _new_owner.clone()});
+ true
+ }
+ }
+ CollectionMode::ReFungible(_) => {
+
+ // get correct limit
+ let limit: u32 = if _collection_limits.sponsor_transfer_timeout > 0 {
+ _collection_limits.sponsor_transfer_timeout
+ } else {
+ ChainLimit::get().refungible_sponsor_transfer_timeout
+ };
+
+ let basket = <ReFungibleTransferBasket<T>>::get(collection_id, _item_id);
+ let block_number = <system::Module<T>>::block_number() as T::BlockNumber;
+ let limit_time = basket + limit.into();
+ if block_number >= limit_time {
+ <ReFungibleTransferBasket<T>>::insert(collection_id, _item_id, block_number);
+ true
+ } else {
+ false
+ }
}
- }
- CollectionMode::ReFungible(_) => {
-
- // get correct limit
- let limit: u32 = if _collection_limits.sponsor_transfer_timeout > 0 {
- _collection_limits.sponsor_transfer_timeout
- } else {
- ChainLimit::get().refungible_sponsor_transfer_timeout
- };
-
- let basket = <ReFungibleTransferBasket<T>>::get(collection_id, _item_id);
- let block_number = <system::Module<T>>::block_number() as T::BlockNumber;
- let limit_time = basket + limit.into();
- if block_number >= limit_time {
- <ReFungibleTransferBasket<T>>::insert(collection_id, _item_id, block_number);
- true
- } else {
+ _ => {
false
- }
- }
- _ => {
- false
- },
- };
+ },
+ };
+ }
if !sponsor_transfer {
T::AccountId::default()
runtime_types.jsondiffbeforeafterboth1{2 "Schedule": {3 "version": "u32",4 "put_code_per_byte_cost": "Gas",5 "grow_mem_cost": "Gas",6 "regular_op_cost": "Gas",7 "return_data_per_byte_cost": "Gas",8 "event_data_per_byte_cost": "Gas",9 "event_per_topic_cost": "Gas",10 "event_base_cost": "Gas",11 "call_base_cost": "Gas",12 "instantiate_base_cost": "Gas",13 "dispatch_base_cost": "Gas",14 "sandbox_data_read_cost": "Gas",15 "sandbox_data_write_cost": "Gas",16 "transfer_cost": "Gas",17 "instantiate_cost": "Gas",18 "max_event_topics": "u32",19 "max_stack_height": "u32",20 "max_memory_pages": "u32",21 "max_table_size": "u32",22 "enable_println": "bool",23 "max_subject_len": "u32"24 },25 "AccessMode": {26 "_enum": [27 "Normal",28 "WhiteList"29 ]30 },31 "DecimalPoints": "u8",32 "CollectionMode": {33 "_enum": {34 "Invalid": null,35 "NFT": null,36 "Fungible": "DecimalPoints",37 "ReFungible": "DecimalPoints"38 }39 },40 "Ownership": {41 "Owner": "AccountId",42 "Fraction": "u128"43 },44 "FungibleItemType": {45 "Collection": "CollectionId",46 "Owner": "AccountId",47 "Value": "u128"48 },49 "NftItemType": {50 "Collection": "CollectionId",51 "Owner": "AccountId",52 "ConstData": "Vec<u8>",53 "VariableData": "Vec<u8>"54 },55 "ReFungibleItemType": {56 "Collection": "CollectionId",57 "Owner": "Vec<Ownership<AccountId>>",58 "ConstData": "Vec<u8>",59 "VariableData": "Vec<u8>"60 },61 "CollectionType": {62 "Owner": "AccountId",63 "Mode": "CollectionMode",64 "Access": "AccessMode",65 "DecimalPoints": "DecimalPoints",66 "Name": "Vec<u16>",67 "Description": "Vec<u16>",68 "TokenPrefix": "Vec<u8>",69 "MintMode": "bool",70 "OffchainSchema": "Vec<u8>",71 "SchemaVersion": "SchemaVersion",72 "Sponsor": "AccountId",73 "UnconfirmedSponsor": "AccountId",74 "Limits": "CollectionLimits",75 "VariableOnChainSchema": "Vec<u8>",76 "ConstOnChainSchema": "Vec<u8>"77 },78 "ApprovePermissions": {79 "Approved": "AccountId",80 "Amount": "u128"81 },82 "RawData": "Vec<u8>",83 "Address": "AccountId",84 "LookupSource": "AccountId",85 "Weight": "u64",86 "CreateNftData": {87 "const_data": "Vec<u8>",88 "variable_data": "Vec<u8>" 89 },90 "CreateFungibleData": {},91 "CreateReFungibleData": {92 "const_data": "Vec<u8>",93 "variable_data": "Vec<u8>" 94 },95 "CreateItemData": {96 "_enum": {97 "NFT": "CreateNftData",98 "Fungible": "CreateFungibleData",99 "ReFungible": "CreateReFungibleData"100 }101 },102 "SchemaVersion": {103 "_enum": [104 "ImageURL",105 "Unique"106 ]107 },108 "CollectionId": "u32",109 "TokenId": "u32",110 "BasketItem": {111 "Address": "AccountId",112 "start_block": "BlockNumber"113 },114 "ChainLimits": {115 "collection_numbers_limit": "u32",116 "account_token_ownership_limit": "u32",117 "collections_admins_limit": "u64",118 "custom_data_limit": "u32",119 "nft_sponsor_timeout": "u32",120 "fungible_sponsor_timeout": "u32",121 "refungible_sponsor_timeout": "u32"122 },123 "CollectionLimits": {124 "AccountTokenOwnershipLimit": "u32",125 "SponsoredMintSize": "u32",126 "TokenLimit": "u32",127 "SponsorTimeout": "u32"128 }129 }130 1{2 "Schedule": {3 "version": "u32",4 "put_code_per_byte_cost": "Gas",5 "grow_mem_cost": "Gas",6 "regular_op_cost": "Gas",7 "return_data_per_byte_cost": "Gas",8 "event_data_per_byte_cost": "Gas",9 "event_per_topic_cost": "Gas",10 "event_base_cost": "Gas",11 "call_base_cost": "Gas",12 "instantiate_base_cost": "Gas",13 "dispatch_base_cost": "Gas",14 "sandbox_data_read_cost": "Gas",15 "sandbox_data_write_cost": "Gas",16 "transfer_cost": "Gas",17 "instantiate_cost": "Gas",18 "max_event_topics": "u32",19 "max_stack_height": "u32",20 "max_memory_pages": "u32",21 "max_table_size": "u32",22 "enable_println": "bool",23 "max_subject_len": "u32"24 },25 "AccessMode": {26 "_enum": [27 "Normal",28 "WhiteList"29 ]30 },31 "DecimalPoints": "u8",32 "CollectionMode": {33 "_enum": {34 "Invalid": null,35 "NFT": null,36 "Fungible": "DecimalPoints",37 "ReFungible": "DecimalPoints"38 }39 },40 "Ownership": {41 "Owner": "AccountId",42 "Fraction": "u128"43 },44 "FungibleItemType": {45 "Collection": "CollectionId",46 "Owner": "AccountId",47 "Value": "u128"48 },49 "NftItemType": {50 "Collection": "CollectionId",51 "Owner": "AccountId",52 "ConstData": "Vec<u8>",53 "VariableData": "Vec<u8>"54 },55 "ReFungibleItemType": {56 "Collection": "CollectionId",57 "Owner": "Vec<Ownership<AccountId>>",58 "ConstData": "Vec<u8>",59 "VariableData": "Vec<u8>"60 },61 "CollectionType": {62 "Owner": "AccountId",63 "Mode": "CollectionMode",64 "Access": "AccessMode",65 "DecimalPoints": "DecimalPoints",66 "Name": "Vec<u16>",67 "Description": "Vec<u16>",68 "TokenPrefix": "Vec<u8>",69 "MintMode": "bool",70 "OffchainSchema": "Vec<u8>",71 "SchemaVersion": "SchemaVersion",72 "Sponsor": "AccountId",73 "SponsorConfirmed": "bool",74 "Limits": "CollectionLimits",75 "VariableOnChainSchema": "Vec<u8>",76 "ConstOnChainSchema": "Vec<u8>"77 },78 "ApprovePermissions": {79 "Approved": "AccountId",80 "Amount": "u128"81 },82 "RawData": "Vec<u8>",83 "Address": "AccountId",84 "LookupSource": "AccountId",85 "Weight": "u64",86 "CreateNftData": {87 "const_data": "Vec<u8>",88 "variable_data": "Vec<u8>" 89 },90 "CreateFungibleData": {},91 "CreateReFungibleData": {92 "const_data": "Vec<u8>",93 "variable_data": "Vec<u8>" 94 },95 "CreateItemData": {96 "_enum": {97 "NFT": "CreateNftData",98 "Fungible": "CreateFungibleData",99 "ReFungible": "CreateReFungibleData"100 }101 },102 "SchemaVersion": {103 "_enum": [104 "ImageURL",105 "Unique"106 ]107 },108 "CollectionId": "u32",109 "TokenId": "u32",110 "BasketItem": {111 "Address": "AccountId",112 "start_block": "BlockNumber"113 },114 "ChainLimits": {115 "collection_numbers_limit": "u32",116 "account_token_ownership_limit": "u32",117 "collections_admins_limit": "u64",118 "custom_data_limit": "u32",119 "nft_sponsor_timeout": "u32",120 "fungible_sponsor_timeout": "u32",121 "refungible_sponsor_timeout": "u32"122 },123 "CollectionLimits": {124 "AccountTokenOwnershipLimit": "u32",125 "SponsoredMintSize": "u32",126 "TokenLimit": "u32",127 "SponsorTimeout": "u32"128 }129 }130 tests/src/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -1,55 +1,12 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";
-import { createCollectionExpectSuccess, createCollectionExpectFailure } from "./util/helpers";
+import { createCollectionExpectSuccess, createCollectionExpectFailure, destroyCollectionExpectSuccess, destroyCollectionExpectFailure } from "./util/helpers";
import type { AccountId, EventRecord } from '@polkadot/types/interfaces';
import privateKey from './substrate/privateKey';
-import { nullPublicKey } from './accounts';
chai.use(chaiAsPromised);
const expect = chai.expect;
-
-function getDestroyResult(events: EventRecord[]): boolean {
- let success: boolean = false;
- events.forEach(({ phase, event: { data, method, section } }) => {
- // console.log(` ${phase}: ${section}.${method}:: ${data}`);
- if (method == 'ExtrinsicSuccess') {
- success = true;
- }
- });
- return success;
-}
-
-async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
- await usingApi(async (api) => {
- // Run the DestroyCollection transaction
- const alicePrivateKey = privateKey(senderSeed);
- const tx = api.tx.nft.destroyCollection(collectionId);
- const events = await submitTransactionAsync(alicePrivateKey, tx);
- const result = getDestroyResult(events);
-
- // Get the collection
- const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
-
- // What to expect
- expect(result).to.be.true;
- expect(collection).to.be.not.null;
- expect(collection.Owner).to.be.equal(nullPublicKey);
- });
-}
-
-async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
- await usingApi(async (api) => {
- // Run the DestroyCollection transaction
- const alicePrivateKey = privateKey(senderSeed);
- const tx = api.tx.nft.destroyCollection(collectionId);
- const events = await submitTransactionAsync(alicePrivateKey, tx);
- const result = getDestroyResult(events);
-
- // What to expect
- expect(result).to.be.false;
- });
-}
describe('integration test: ext. destroyCollection():', () => {
it('NFT collection can be destroyed', async () => {
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -0,0 +1,78 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { default as usingApi } from "./substrate/substrate-api";
+import { createCollectionExpectSuccess, setCollectionSponsorExpectSuccess, destroyCollectionExpectSuccess, setCollectionSponsorExpectFailure } from "./util/helpers";
+import { Keyring } from "@polkadot/api";
+import { IKeyringPair } from "@polkadot/types/types";
+import type { AccountId } from '@polkadot/types/interfaces';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let bob: IKeyringPair;
+
+describe('integration test: ext. setCollectionSponsor():', () => {
+
+ before(async () => {
+ await usingApi(async (api) => {
+ const keyring = new Keyring({ type: 'sr25519' });
+ bob = keyring.addFromUri(`//Bob`);
+ });
+ });
+
+ it('Set NFT collection sponsor', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ });
+ it('Set Fungible collection sponsor', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ });
+ it('Set ReFungible collection sponsor', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ });
+
+ it('Set the same sponsor repeatedly', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ });
+ it('Replace collection sponsor', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+
+ const keyring = new Keyring({ type: 'sr25519' });
+ const charlie = keyring.addFromUri(`//Charlie`);
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
+ });
+});
+
+describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
+ before(async () => {
+ await usingApi(async (api) => {
+ const keyring = new Keyring({ type: 'sr25519' });
+ bob = keyring.addFromUri(`//Bob`);
+ });
+ });
+
+ it('(!negative test!) Add sponsor to a collection that never existed', async () => {
+ // Find the collection that never existed
+ const collectionId = 0;
+ await usingApi(async (api) => {
+ const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ });
+
+ await setCollectionSponsorExpectFailure(collectionId, bob.address);
+ });
+ it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await destroyCollectionExpectSuccess(collectionId);
+ await setCollectionSponsorExpectFailure(collectionId, bob.address);
+ });
+});
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -9,7 +9,7 @@
import { ApiPromise, Keyring } from "@polkadot/api";
import { default as usingApi, submitTransactionAsync } from "../substrate/substrate-api";
import privateKey from '../substrate/privateKey';
-import { alicesPublicKey } from "../accounts";
+import { alicesPublicKey, nullPublicKey } from "../accounts";
import { strToUTF16, utf16ToStr, hexToStr } from '../util/util';
import { IKeyringPair } from "@polkadot/types/types";
import { BigNumber } from 'bignumber.js';
@@ -121,4 +121,79 @@
bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());
} while (bal.toFixed() != '0');
return unused;
-}
\ No newline at end of file
+}
+
+function getDestroyResult(events: EventRecord[]): boolean {
+ let success: boolean = false;
+ events.forEach(({ phase, event: { data, method, section } }) => {
+ // console.log(` ${phase}: ${section}.${method}:: ${data}`);
+ if (method == 'ExtrinsicSuccess') {
+ success = true;
+ }
+ });
+ return success;
+}
+
+export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {
+ await usingApi(async (api) => {
+
+ // Run the transaction
+ const alicePrivateKey = privateKey('//Alice');
+ const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
+ const events = await submitTransactionAsync(alicePrivateKey, tx);
+ const result = getGenericResult(events);
+
+ // Get the collection
+ const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+
+ // What to expect
+ expect(result.success).to.be.true;
+ expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());
+ expect(collection.SponsorConfirmed).to.be.false;
+ });
+}
+
+export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
+ await usingApi(async (api) => {
+ // Run the DestroyCollection transaction
+ const alicePrivateKey = privateKey(senderSeed);
+ const tx = api.tx.nft.destroyCollection(collectionId);
+ const events = await submitTransactionAsync(alicePrivateKey, tx);
+ const result = getDestroyResult(events);
+
+ // What to expect
+ expect(result).to.be.false;
+ });
+}
+
+export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
+ await usingApi(async (api) => {
+ // Run the DestroyCollection transaction
+ const alicePrivateKey = privateKey(senderSeed);
+ const tx = api.tx.nft.destroyCollection(collectionId);
+ const events = await submitTransactionAsync(alicePrivateKey, tx);
+ const result = getDestroyResult(events);
+
+ // Get the collection
+ const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+
+ // What to expect
+ expect(result).to.be.true;
+ expect(collection).to.be.not.null;
+ expect(collection.Owner).to.be.equal(nullPublicKey);
+ });
+}
+
+export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string) {
+ await usingApi(async (api) => {
+
+ // Run the transaction
+ const alicePrivateKey = privateKey('//Alice');
+ const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
+ const events = await submitTransactionAsync(alicePrivateKey, tx);
+ const result = getGenericResult(events);
+
+ // What to expect
+ expect(result.success).to.be.false;
+ });
+}