1import { IKeyringPair } from '@polkadot/types/types';2import chai from 'chai';3import chaiAsPromised from 'chai-as-promised';4import privateKey from '../substrate/privateKey';5import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';6import {7 addCollectionAdminExpectSuccess,8 approveExpectSuccess,9 createCollectionExpectSuccess,10 createItemExpectSuccess,11 transferFromExpectSuccess,12 transferExpectSuccess,13 normalizeAccountId,14} from '../util/helpers';1516chai.use(chaiAsPromised);17const expect = chai.expect;18let Alice: IKeyringPair;19let Bob: IKeyringPair;20let Ferdie: IKeyringPair;2122before(async () => {23 await usingApi(async () => {24 Alice = privateKey('//Alice');25 Bob = privateKey('//Bob');26 Ferdie = privateKey('//Ferdie');27 });28});2930describe('Admin vs Owner changes token: ', () => {31 32 it('The collection admin changes the owner of the token and in the same block the current owner transfers the token to another address ', async () => {33 34 await usingApi(async (api) => {35 const collectionId = await createCollectionExpectSuccess();36 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));37 await submitTransactionAsync(Alice, changeAdminTxBob);38 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));39 const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Ferdie.address));40 await submitTransactionAsync(Bob, changeAdminTxFerdie);41 const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');42 43 const changeOwner = api.tx.nft.transferFrom(normalizeAccountId(Ferdie.address), normalizeAccountId(Bob.address), collectionId, itemId, 1);44 const approve = api.tx.nft.approve(normalizeAccountId(Bob.address), collectionId, itemId, 1);45 const sendItem = api.tx.nft.transfer(normalizeAccountId(Alice.address), collectionId, itemId, 1);46 await Promise.all([47 changeOwner.signAndSend(Alice),48 approve.signAndSend(Bob),49 sendItem.signAndSend(Ferdie),50 ]);51 const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);52 expect(itemBefore.Owner).not.to.be.eq(Bob.address);53 await timeoutPromise(20000);54 });55 });56});