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
after · tests/src/adminTransferAndBurn.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {default as usingApi} from './substrate/substrate-api';21import {22  createCollectionExpectSuccess,23  createItemExpectSuccess,24  transferExpectFailure,25  transferFromExpectSuccess,26  burnItemExpectFailure,27  burnFromExpectSuccess,28  setCollectionLimitsExpectSuccess,29} from './util/helpers';3031chai.use(chaiAsPromised);32const expect = chai.expect;3334describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {35  let alice: IKeyringPair;36  let bob: IKeyringPair;37  let charlie: IKeyringPair;3839  before(async () => {40    await usingApi(async (api, privateKeyWrapper) => {41      alice = privateKeyWrapper('//Alice');42      bob = privateKeyWrapper('//Bob');43      charlie = privateKeyWrapper('//Charlie');44    });45  });4647  it('admin transfers other user\'s token', async () => {48    await usingApi(async () => {49      const collectionId = await createCollectionExpectSuccess();50      await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});5152      const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Substrate: bob.address});5354      await transferExpectFailure(collectionId, tokenId, alice, charlie);5556      await transferFromExpectSuccess(collectionId, tokenId, alice, bob, charlie, 1);57    });58  });5960  it('admin burns other user\'s token', async () => {61    await usingApi(async () => {62      const collectionId = await createCollectionExpectSuccess();63      await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});6465      const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Substrate: bob.address});6667      await burnItemExpectFailure(alice, collectionId, tokenId);6869      await burnFromExpectSuccess(alice, bob, collectionId, tokenId);70    });71  });72})
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -830,6 +830,25 @@
   });
 }
 
+export async function burnItemExpectFailure(sender: IKeyringPair, collectionId: number, tokenId: number, value: number | bigint = 1) {
+  await usingApi(async (api) => {
+    const tx = api.tx.unique.burnItem(collectionId, tokenId, value);
+
+    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+    const result = getCreateCollectionResult(events);
+    // tslint:disable-next-line:no-unused-expression
+    expect(result.success).to.be.false;
+  });
+}
+
+export async function burnFromExpectSuccess(sender: IKeyringPair, from: IKeyringPair | CrossAccountId, collectionId: number, tokenId: number, value: number | bigint = 1) {
+  await usingApi(async (api) => {
+    const tx = api.tx.unique.burnFrom(collectionId, normalizeAccountId(from), tokenId, value);
+    const events = await submitTransactionAsync(sender, tx);
+    return getGenericResult(events).success;
+  });
+}
+
 export async function
 approve(
   api: ApiPromise,