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

difftreelog

feature/NFTPAR-218

Antz0x0z2021-02-19parent: #6ea0c80.patch.diff
in: master
collision tests

5 files changed

addedtests/src/collision-tests/admVsOwnerChanges.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/collision-tests/admVsOwnerChanges.test.ts
@@ -0,0 +1,55 @@
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { alicesPublicKey, bobsPublicKey } from '../accounts';
+import getBalance from '../substrate/get-balance';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import waitNewBlocks from '../substrate/wait-new-blocks';
+import {
+  createCollectionExpectSuccess,
+  createItemExpectSuccess,
+  setCollectionSponsorExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Ferdie: IKeyringPair;
+
+before(async () => {
+  await usingApi(async () => {
+    Alice = privateKey('//Alice');
+    Bob = privateKey('//Bob');
+    Ferdie = privateKey('//Ferdie');
+  });
+});
+
+describe('Admin vs Owner changes token: ', () => {
+  // tslint:disable-next-line: max-line-length
+  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 () => {
+    await usingApi(async (api) => {
+      const collectionId = await createCollectionExpectSuccess();
+      const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, changeAdminTxBob);
+      const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);
+      await submitTransactionAsync(Bob, changeAdminTxFerdie);
+      const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');
+      //
+      const changeOwner = api.tx.nft.transferFrom(Ferdie.address, Bob.address, collectionId, itemId, 1);
+      const approve = api.tx.nft.approve(Bob.address, collectionId, itemId, 1);
+      const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);
+      await Promise.all
+      ([
+        changeOwner.signAndSend(Alice),
+        approve.signAndSend(Bob),
+        sendItem.signAndSend(Ferdie),
+      ]);
+      const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);
+      expect(itemBefore.Owner.toString()).not.to.be.eq(Bob.address);
+      const blockHash = await api.query.system.number();
+      console.log(`blockHash: ${blockHash}`);
+    });
+  });
+});
addedtests/src/collision-tests/admVsOwnerData.test.tsdiffbeforeafterboth
after · tests/src/collision-tests/admVsOwnerData.test.ts
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 the data in the token: ', () => {
30  it('The collection admin changes the data in the token and in the same block the token owner also changes the data in it ', async () => {
31    await usingApi(async (api) => {
32      const AliceData = [31];
33      const BobData = [32];
34      const collectionId = await createCollectionExpectSuccess();
35      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
36      await submitTransactionAsync(Alice, changeAdminTx);
37      const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
38      //
39      // tslint:disable-next-line: max-line-length
40      const AliceTx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(AliceData).toString('hex'));
41      // tslint:disable-next-line: max-line-length
42      const BobTx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(BobData).toString('hex'));
43      await Promise.all
44      ([
45        AliceTx.signAndSend(Alice),
46        BobTx.signAndSend(Bob),
47      ]);
48      const item: any = await api.query.nft.nftItemList(collectionId, itemId);
49      expect(Array.from(item.VariableData)).to.deep.equal(Array.from([]));
50      const blockHash = await api.query.system.number();
51      console.log(`blockHash: ${blockHash}`);
52    });
53  });
54});
addedtests/src/collision-tests/admVsOwnerTake.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/collision-tests/admVsOwnerTake.test.ts
@@ -0,0 +1,51 @@
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { alicesPublicKey, bobsPublicKey } from '../accounts';
+import getBalance from '../substrate/get-balance';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import waitNewBlocks from '../substrate/wait-new-blocks';
+import {
+  createCollectionExpectSuccess,
+  createItemExpectSuccess,
+  setCollectionSponsorExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Ferdie: IKeyringPair;
+
+before(async () => {
+  await usingApi(async () => {
+    Alice = privateKey('//Alice');
+    Bob = privateKey('//Bob');
+    Ferdie = privateKey('//Ferdie');
+  });
+});
+
+describe('Admin vs Owner take token: ', () => {
+  // tslint:disable-next-line: max-line-length
+  it('The collection admin burns the token and in the same block the token owner performs a transaction on it ', async () => {
+    await usingApi(async (api) => {
+      const collectionId = await createCollectionExpectSuccess();
+      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, changeAdminTx);
+      const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
+      //
+      const sendItem = api.tx.nft.transfer(Ferdie.address, collectionId, itemId, 1);
+      const burnItem = api.tx.nft.burnItem(collectionId, itemId, 1);
+      await Promise.all
+      ([
+        sendItem.signAndSend(Bob),
+        burnItem.signAndSend(Alice),
+      ]);
+      const itemBurn: any = await api.query.nft.nftItemList(collectionId, itemId);
+      expect(itemBurn.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM');
+      const blockHash = await api.query.system.number();
+      console.log(`blockHash: ${blockHash}`);
+    });
+  });
+});
addedtests/src/collision-tests/sponsorPayments.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/collision-tests/sponsorPayments.test.ts
@@ -0,0 +1,58 @@
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { alicesPublicKey, bobsPublicKey } from '../accounts';
+import getBalance from '../substrate/get-balance';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import waitNewBlocks from '../substrate/wait-new-blocks';
+import {
+  confirmSponsorshipExpectSuccess,
+  createCollectionExpectSuccess,
+  createItemExpectSuccess,
+  setCollectionSponsorExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Ferdie: IKeyringPair;
+
+before(async () => {
+  await usingApi(async () => {
+    Alice = privateKey('//Alice');
+    Bob = privateKey('//Bob');
+    Ferdie = privateKey('//Ferdie');
+  });
+});
+
+describe('Payment of commission if one block: ', () => {
+  // tslint:disable-next-line: max-line-length
+  it('Payment of commission if one block contains transactions for payment from the sponsor\'s balance and his (sponsor\'s) exclusion from the collection ', async () => {
+    await usingApi(async (api) => {
+      const collectionId = await createCollectionExpectSuccess();
+      const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, changeAdminTxBob);
+      const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
+      await setCollectionSponsorExpectSuccess(collectionId, Bob.address);
+      await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
+      //
+      const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+      const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);
+      const revokeSponsor = api.tx.nft.removeCollectionSponsor(collectionId);
+      await Promise.all
+      ([
+        sendItem.signAndSend(Bob),
+        revokeSponsor.signAndSend(Alice),
+      ]);
+      const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+      // tslint:disable-next-line:no-unused-expression
+      expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true;
+      // tslint:disable-next-line:no-unused-expression
+      expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true;
+      const blockHash = await api.query.system.number();
+      console.log(`blockHash: ${blockHash}`);
+    });
+  });
+});
addedtests/src/collision-tests/turnsOffMinting.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/collision-tests/turnsOffMinting.test.ts
@@ -0,0 +1,48 @@
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import waitNewBlocks from '../substrate/wait-new-blocks';
+import {
+  addToWhiteListExpectSuccess,
+  createCollectionExpectSuccess,
+  setMintPermissionExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Ferdie: IKeyringPair;
+
+before(async () => {
+  await usingApi(async () => {
+    Alice = privateKey('//Alice');
+    Bob = privateKey('//Bob');
+    Ferdie = privateKey('//Ferdie');
+  });
+});
+
+describe('Turns off minting mode: ', () => {
+  // tslint:disable-next-line: max-line-length
+  it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => {
+    await usingApi(async (api) => {
+      const collectionId = await createCollectionExpectSuccess();
+      await setMintPermissionExpectSuccess(Alice, collectionId, true);
+      await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);
+      //
+      const mintItem = api.tx.nft.createItem(collectionId, Ferdie.address, 'NFT');
+      const offMinting = api.tx.nft.setMintPermission(collectionId, false);
+      await Promise.all
+      ([
+        mintItem.signAndSend(Ferdie),
+        offMinting.signAndSend(Alice),
+      ]);
+      const itemList: any = await api.query.nft.nftItemList(collectionId, mintItem);
+      expect(itemList.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM');
+      const blockHash = await api.query.system.number();
+      console.log(`blockHash: ${blockHash}`);
+    });
+  });
+});