git.delta.rocks / unique-network / refs/commits / 2be6b4ddbf24

difftreelog

test ownerCanTransfer allows only transferFrom/burnFrom

Daniel Shiposha2022-06-29parent: #6ed42b0.patch.diff
in: master

3 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -60,6 +60,7 @@
     "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",
     "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
     "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",
+    "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",
     "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",
     "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
     "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",
addedtests/src/adminTransferAndBurn.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/adminTransferAndBurn.test.ts
@@ -0,0 +1,72 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import {default as usingApi} from './substrate/substrate-api';
+import {
+  createCollectionExpectSuccess,
+  createItemExpectSuccess,
+  transferExpectFailure,
+  transferFromExpectSuccess,
+  burnItemExpectFailure,
+  burnFromExpectSuccess,
+  setCollectionLimitsExpectSuccess,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+  let charlie: IKeyringPair;
+
+  before(async () => {
+    await usingApi(async (api, privateKeyWrapper) => {
+      alice = privateKeyWrapper('//Alice');
+      bob = privateKeyWrapper('//Bob');
+      charlie = privateKeyWrapper('//Charlie');
+    });
+  });
+
+  it('admin transfers other user\'s token', async () => {
+    await usingApi(async () => {
+      const collectionId = await createCollectionExpectSuccess();
+      await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
+
+      const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Substrate: bob.address});
+
+      await transferExpectFailure(collectionId, tokenId, alice, charlie);
+
+      await transferFromExpectSuccess(collectionId, tokenId, alice, bob, charlie, 1);
+    });
+  });
+
+  it('admin burns other user\'s token', async () => {
+    await usingApi(async () => {
+      const collectionId = await createCollectionExpectSuccess();
+      await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
+
+      const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Substrate: bob.address});
+
+      await burnItemExpectFailure(alice, collectionId, tokenId);
+
+      await burnFromExpectSuccess(alice, bob, collectionId, tokenId);
+    });
+  });
+})
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
830 });830 });
831}831}
832
833export async function burnItemExpectFailure(sender: IKeyringPair, collectionId: number, tokenId: number, value: number | bigint = 1) {
834 await usingApi(async (api) => {
835 const tx = api.tx.unique.burnItem(collectionId, tokenId, value);
836
837 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
838 const result = getCreateCollectionResult(events);
839 // tslint:disable-next-line:no-unused-expression
840 expect(result.success).to.be.false;
841 });
842}
843
844export async function burnFromExpectSuccess(sender: IKeyringPair, from: IKeyringPair | CrossAccountId, collectionId: number, tokenId: number, value: number | bigint = 1) {
845 await usingApi(async (api) => {
846 const tx = api.tx.unique.burnFrom(collectionId, normalizeAccountId(from), tokenId, value);
847 const events = await submitTransactionAsync(sender, tx);
848 return getGenericResult(events).success;
849 });
850}
832851
833export async function852export async function
834approve(853approve(