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

no changes

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
--- /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}`);
+    });
+  });
+});