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 createCollectionExpectSuccess,8 createItemExpectSuccess,9 normalizeAccountId,10 waitNewBlocks,11} from '../util/helpers';1213chai.use(chaiAsPromised);14const expect = chai.expect;15let Alice: IKeyringPair;16let Bob: IKeyringPair;17let Ferdie: IKeyringPair;1819before(async () => {20 await usingApi(async () => {21 Alice = privateKey('//Alice');22 Bob = privateKey('//Bob');23 Ferdie = privateKey('//Ferdie');24 });25});2627describe('Admin vs Owner changes token: ', () => {28 29 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 () => {30 31 await usingApi(async (api) => {32 const collectionId = await createCollectionExpectSuccess();33 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));34 await submitTransactionAsync(Alice, changeAdminTxBob);35 const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Ferdie.address));36 await submitTransactionAsync(Bob, changeAdminTxFerdie);37 const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');38 39 const changeOwner = api.tx.nft.transferFrom(normalizeAccountId(Ferdie.address), normalizeAccountId(Bob.address), collectionId, itemId, 1);40 const approve = api.tx.nft.approve(normalizeAccountId(Bob.address), collectionId, itemId, 1);41 const sendItem = api.tx.nft.transfer(normalizeAccountId(Alice.address), collectionId, itemId, 1);42 await Promise.all([43 changeOwner.signAndSend(Alice),44 approve.signAndSend(Bob),45 sendItem.signAndSend(Ferdie),46 ]);47 const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);48 expect(itemBefore.Owner).not.to.be.eq(Bob.address);49 await waitNewBlocks(2);50 });51 });52});