git.delta.rocks / unique-network / refs/commits / 5202fc8f6f12

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 changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);
37      await submitTransactionAsync(Bob, changeAdminTxFerdie);
38      const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');
39      //
40      const changeOwner = api.tx.nft.transferFrom(Ferdie.address, Bob.address, collectionId, itemId, 1);
41      const approve = api.tx.nft.approve(Bob.address, collectionId, itemId, 1);
42      const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);
43      await Promise.all
44      ([
45        changeOwner.signAndSend(Alice),
46        approve.signAndSend(Bob),
47        sendItem.signAndSend(Ferdie),
48      ]);
49      const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);
50      expect(itemBefore.Owner.toString()).not.to.be.eq(Bob.address);
51      const blockHash = await api.query.system.number();
52      console.log(`blockHash: ${blockHash}`);
53    });
54  });
55});