git.delta.rocks / unique-network / refs/commits / 70da175fb9fe

difftreelog

source

tests/src/collision-tests/admVsOwnerChanges.test.ts2.1 KiBsourcehistory
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} from '../util/helpers';1011chai.use(chaiAsPromised);12const expect = chai.expect;13let Alice: IKeyringPair;14let Bob: IKeyringPair;15let Ferdie: IKeyringPair;1617before(async () => {18  await usingApi(async () => {19    Alice = privateKey('//Alice');20    Bob = privateKey('//Bob');21    Ferdie = privateKey('//Ferdie');22  });23});2425describe('Admin vs Owner changes token: ', () => {26  // tslint:disable-next-line: max-line-length27  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 () => {28    await usingApi(async (api) => {29      const collectionId = await createCollectionExpectSuccess();30      const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);31      await submitTransactionAsync(Alice, changeAdminTxBob);32      const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));33      const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);34      await submitTransactionAsync(Bob, changeAdminTxFerdie);35      const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');36      //37      const changeOwner = api.tx.nft.transferFrom(Ferdie.address, Bob.address, collectionId, itemId, 1);38      const approve = api.tx.nft.approve(Bob.address, collectionId, itemId, 1);39      const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);40      await Promise.all([41        changeOwner.signAndSend(Alice),42        approve.signAndSend(Bob),43        sendItem.signAndSend(Ferdie),44      ]);45      const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);46      expect(itemBefore.Owner).not.to.be.eq(Bob.address);47      await timeoutPromise(20000);48    });49  });50});