git.delta.rocks / unique-network / refs/commits / e5c09cb43ca9

difftreelog

source

tests/src/collision-tests/admVsOwnerChanges.test.ts2.3 KiBsourcehistory
1import { IKeyringPair } from '@polkadot/types/types';
2import chai from 'chai';
3import chaiAsPromised from 'chai-as-promised';
4import { alicesPublicKey, bobsPublicKey } from '../accounts';
5import getBalance from '../substrate/get-balance';
6import privateKey from '../substrate/privateKey';
7import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
8import waitNewBlocks from '../substrate/wait-new-blocks';
9import {
10  createCollectionExpectSuccess,
11  createItemExpectSuccess,
12  setCollectionSponsorExpectSuccess,
13} from '../util/helpers';
14
15chai.use(chaiAsPromised);
16const expect = chai.expect;
17let Alice: IKeyringPair;
18let Bob: IKeyringPair;
19let Ferdie: IKeyringPair;
20
21before(async () => {
22  await usingApi(async () => {
23    Alice = privateKey('//Alice');
24    Bob = privateKey('//Bob');
25    Ferdie = privateKey('//Ferdie');
26  });
27});
28
29describe('Admin vs Owner changes token: ', () => {
30  // tslint:disable-next-line: max-line-length
31  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 () => {
32    await usingApi(async (api) => {
33      const collectionId = await createCollectionExpectSuccess();
34      const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
35      await submitTransactionAsync(Alice, changeAdminTxBob);
36      const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
37      const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);
38      await submitTransactionAsync(Bob, changeAdminTxFerdie);
39      const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');
40      //
41      const changeOwner = api.tx.nft.transferFrom(Ferdie.address, Bob.address, collectionId, itemId, 1);
42      const approve = api.tx.nft.approve(Bob.address, collectionId, itemId, 1);
43      const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);
44      await Promise.all
45      ([
46        changeOwner.signAndSend(Alice),
47        approve.signAndSend(Bob),
48        sendItem.signAndSend(Ferdie),
49      ]);
50      const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);
51      expect(itemBefore.Owner).not.to.be.eq(Bob.address);
52      await timeoutPromise(20000);
53    });
54  });
55});