1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {default as usingApi} from './substrate/substrate-api';21import {22 createCollectionExpectSuccess,23 createItemExpectSuccess,24 transferExpectFailure,25 transferFromExpectSuccess,26 burnItemExpectFailure,27 burnFromExpectSuccess,28 setCollectionLimitsExpectSuccess,29} from './util/helpers';30import { usingPlaygrounds } from './util/playgrounds';3132chai.use(chaiAsPromised);33const expect = chai.expect;3435let donor: IKeyringPair;3637before(async () => {38 await usingPlaygrounds(async (_, privateKeyWrapper) => {39 donor = privateKeyWrapper('//Alice');40 });41});4243describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {44 let alice: IKeyringPair;45 let bob: IKeyringPair;46 let charlie: IKeyringPair;4748 before(async () => {49 await usingPlaygrounds(async (helper) => {50 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);51 });52 });5354 it('admin transfers other user\'s token', async () => {55 await usingPlaygrounds(async (helper) => {56 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});57 const setLimitsResult = await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});58 const limits = await helper.collection.getEffectiveLimits(collectionId);59 expect(limits.ownerCanTransfer).to.be.true;6061 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});62 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});63 await expect(transferResult()).to.be.rejected;6465 const res = await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address});66 const newTokenOwner = await helper.nft.getTokenOwner(collectionId, tokenId);67 expect(newTokenOwner.Substrate).to.be.equal(charlie.address);68 });69 });7071 it('admin burns other user\'s token', async () => {72 await usingPlaygrounds(async (helper) => {73 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});7475 const setLimitsResult = await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});76 const limits = await helper.collection.getEffectiveLimits(collectionId);77 expect(limits.ownerCanTransfer).to.be.true;7879 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});80 const burnTxFailed = async () => helper.nft.burnToken(alice, collectionId, tokenId);8182 await expect(burnTxFailed()).to.be.rejected;8384 const burnResult = await helper.nft.burnToken(bob, collectionId, tokenId);85 const token = await helper.nft.getToken(collectionId, tokenId);86 expect(token).to.be.null;87 });88 });89});