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
--- /dev/null
+++ b/tests/src/collision-tests/admVsOwnerData.test.ts
@@ -0,0 +1,54 @@
+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 the data in the token: ', () => {
+  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 () => {
+    await usingApi(async (api) => {
+      const AliceData = [31];
+      const BobData = [32];
+      const collectionId = await createCollectionExpectSuccess();
+      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, changeAdminTx);
+      const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
+      //
+      // tslint:disable-next-line: max-line-length
+      const AliceTx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(AliceData).toString('hex'));
+      // tslint:disable-next-line: max-line-length
+      const BobTx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(BobData).toString('hex'));
+      await Promise.all
+      ([
+        AliceTx.signAndSend(Alice),
+        BobTx.signAndSend(Bob),
+      ]);
+      const item: any = await api.query.nft.nftItemList(collectionId, itemId);
+      expect(Array.from(item.VariableData)).to.deep.equal(Array.from([]));
+      const blockHash = await api.query.system.number();
+      console.log(`blockHash: ${blockHash}`);
+    });
+  });
+});
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
after · tests/src/collision-tests/turnsOffMinting.test.ts
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 waitNewBlocks from '../substrate/wait-new-blocks';
7import {
8  addToWhiteListExpectSuccess,
9  createCollectionExpectSuccess,
10  setMintPermissionExpectSuccess,
11} from '../util/helpers';
12
13chai.use(chaiAsPromised);
14const expect = chai.expect;
15let Alice: IKeyringPair;
16let Bob: IKeyringPair;
17let Ferdie: IKeyringPair;
18
19before(async () => {
20  await usingApi(async () => {
21    Alice = privateKey('//Alice');
22    Bob = privateKey('//Bob');
23    Ferdie = privateKey('//Ferdie');
24  });
25});
26
27describe('Turns off minting mode: ', () => {
28  // tslint:disable-next-line: max-line-length
29  it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => {
30    await usingApi(async (api) => {
31      const collectionId = await createCollectionExpectSuccess();
32      await setMintPermissionExpectSuccess(Alice, collectionId, true);
33      await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);
34      //
35      const mintItem = api.tx.nft.createItem(collectionId, Ferdie.address, 'NFT');
36      const offMinting = api.tx.nft.setMintPermission(collectionId, false);
37      await Promise.all
38      ([
39        mintItem.signAndSend(Ferdie),
40        offMinting.signAndSend(Alice),
41      ]);
42      const itemList: any = await api.query.nft.nftItemList(collectionId, mintItem);
43      expect(itemList.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM');
44      const blockHash = await api.query.system.number();
45      console.log(`blockHash: ${blockHash}`);
46    });
47  });
48});