difftreelog
destroyCollection migrated
in: master
1 file changed
tests/src/destroyCollection.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {default as usingApi} from './substrate/substrate-api';18import {19 Pallets,20} from './util/helpers';21import {createCollectionExpectSuccess,21import {itSub, expect, usingPlaygrounds} from './util/playgrounds';22 destroyCollectionExpectSuccess,23 destroyCollectionExpectFailure,24 setCollectionLimitsExpectSuccess,25 addCollectionAdminExpectSuccess,26 getCreatedCollectionCount,27 createItemExpectSuccess,28 requirePallets,29 Pallets,30} from './util/helpers';3132chai.use(chaiAsPromised);332234describe('integration test: ext. destroyCollection():', () => {23describe('integration test: ext. destroyCollection():', () => {24 let alice: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = privateKey('//Alice');29 [alice] = await helper.arrange.createAccounts([100n], donor);30 });31 });3235 it('NFT collection can be destroyed', async () => {33 itSub('NFT collection can be destroyed', async ({helper}) => {36 const collectionId = await createCollectionExpectSuccess();34 const collection = await helper.nft.mintCollection(alice, {35 name: 'test',36 description: 'test',37 tokenPrefix: 'test',38 });37 await destroyCollectionExpectSuccess(collectionId);39 await collection.burn(alice);40 expect(await collection.getData()).to.be.null;38 });41 });39 it('Fungible collection can be destroyed', async () => {42 itSub('Fungible collection can be destroyed', async ({helper}) => {40 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});43 const collection = await helper.ft.mintCollection(alice, {44 name: 'test',45 description: 'test',46 tokenPrefix: 'test',47 }, 0);41 await destroyCollectionExpectSuccess(collectionId);48 await collection.burn(alice);49 expect(await collection.getData()).to.be.null;42 });50 });43 it('ReFungible collection can be destroyed', async function() {51 itSub.ifWithPallets('ReFungible collection can be destroyed', [Pallets.ReFungible], async ({helper}) => {44 await requirePallets(this, [Pallets.ReFungible]);4546 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});52 const collection = await helper.rft.mintCollection(alice, {53 name: 'test',54 description: 'test',55 tokenPrefix: 'test',56 });47 await destroyCollectionExpectSuccess(collectionId);57 await collection.burn(alice);58 expect(await collection.getData()).to.be.null;48 });59 });49});60});506151describe('(!negative test!) integration test: ext. destroyCollection():', () => {62describe('(!negative test!) integration test: ext. destroyCollection():', () => {52 let alice: IKeyringPair;63 let alice: IKeyringPair;53 let bob: IKeyringPair;64 let bob: IKeyringPair;546555 before(async () => {66 before(async () => {56 await usingApi(async (api, privateKeyWrapper) => {67 await usingPlaygrounds(async (helper, privateKey) => {57 alice = privateKeyWrapper('//Alice');68 const donor = privateKey('//Alice');58 bob = privateKeyWrapper('//Bob');69 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);59 });70 });60 });71 });617262 it('(!negative test!) Destroy a collection that never existed', async () => {73 itSub('(!negative test!) Destroy a collection that never existed', async ({helper}) => {74 const collectionId = 1_000_000;63 await usingApi(async (api) => {75 await expect(helper.collection.burn(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);64 // Find the collection that never existed65 const collectionId = await getCreatedCollectionCount(api) + 1;66 await destroyCollectionExpectFailure(collectionId);67 });68 });76 });69 it('(!negative test!) Destroy a collection that has already been destroyed', async () => {77 itSub('(!negative test!) Destroy a collection that has already been destroyed', async ({helper}) => {70 const collectionId = await createCollectionExpectSuccess();78 const collection = await helper.nft.mintCollection(alice, {79 name: 'test',80 description: 'test',81 tokenPrefix: 'test',82 });71 await destroyCollectionExpectSuccess(collectionId);83 await collection.burn(alice);72 await destroyCollectionExpectFailure(collectionId);84 await expect(collection.burn(alice)).to.be.rejectedWith(/common\.CollectionNotFound/);73 });85 });74 it('(!negative test!) Destroy a collection using non-owner account', async () => {86 itSub('(!negative test!) Destroy a collection using non-owner account', async ({helper}) => {75 const collectionId = await createCollectionExpectSuccess();87 const collection = await helper.nft.mintCollection(alice, {88 name: 'test',89 description: 'test',90 tokenPrefix: 'test',91 });76 await destroyCollectionExpectFailure(collectionId, '//Bob');92 await expect(collection.burn(bob)).to.be.rejectedWith(/common\.NoPermission/);77 await destroyCollectionExpectSuccess(collectionId, '//Alice');78 });93 });79 it('(!negative test!) Destroy a collection using collection admin account', async () => {94 itSub('(!negative test!) Destroy a collection using collection admin account', async ({helper}) => {80 const collectionId = await createCollectionExpectSuccess();95 const collection = await helper.nft.mintCollection(alice, {96 name: 'test',97 description: 'test',98 tokenPrefix: 'test',99 });81 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);100 await collection.addAdmin(alice, {Substrate: bob.address});82 await destroyCollectionExpectFailure(collectionId, '//Bob');101 await expect(collection.burn(bob)).to.be.rejectedWith(/common\.NoPermission/);83 });102 });84 it('fails when OwnerCanDestroy == false', async () => {103 itSub('fails when OwnerCanDestroy == false', async ({helper}) => {85 const collectionId = await createCollectionExpectSuccess();104 const collection = await helper.nft.mintCollection(alice, {86 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanDestroy: false});105 name: 'test',87106 description: 'test',107 tokenPrefix: 'test',108 limits: {109 ownerCanDestroy: false,110 },111 });88 await destroyCollectionExpectFailure(collectionId, '//Alice');112 await expect(collection.burn(alice)).to.be.rejectedWith(/common\.NoPermission/);89 });113 });90 it('fails when a collection still has a token', async () => {114 itSub('fails when a collection still has a token', async ({helper}) => {91 const collectionId = await createCollectionExpectSuccess();115 const collection = await helper.nft.mintCollection(alice, {116 name: 'test',117 description: 'test',118 tokenPrefix: 'test',119 });92 await createItemExpectSuccess(alice, collectionId, 'NFT');120 await collection.mintToken(alice, {Substrate: alice.address});9394 await destroyCollectionExpectFailure(collectionId, '//Alice');121 await expect(collection.burn(alice)).to.be.rejectedWith(/common\.CantDestroyNotEmptyCollection/);95 });122 });96});123});97124