difftreelog
Merge pull request #112 from usetech-llc/feature/NFTPAR-308_limited_owners_control
in: master
Limited owners control
7 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth382 AccountTokenLimitExceeded,382 AccountTokenLimitExceeded,383 /// Collection limit bounds per collection exceeded383 /// Collection limit bounds per collection exceeded384 CollectionLimitBoundsExceeded,384 CollectionLimitBoundsExceeded,385 /// Tried to enable permissions which are only permitted to be disabled386 OwnerPermissionsCantBeReverted,385 /// Schema data size limit bound exceeded387 /// Schema data size limit bound exceeded386 SchemaDataLimitExceeded,388 SchemaDataLimitExceeded,387 /// Maximum refungibility exceeded389 /// Maximum refungibility exceeded639 let sender = ensure_signed(origin)?;641 let sender = ensure_signed(origin)?;640 Self::check_owner_permissions(collection_id, sender)?;642 Self::check_owner_permissions(collection_id, sender)?;643644 let target_collection = <Collection<T>>::get(collection_id);645 if !target_collection.limits.owner_can_destroy {646 fail!(Error::<T>::NoPermission);647 }641648642 <AddressTokens<T>>::remove_prefix(collection_id);649 <AddressTokens<T>>::remove_prefix(collection_id);643 <Allowances<T>>::remove_prefix(collection_id);650 <Allowances<T>>::remove_prefix(collection_id);1024 let target_collection = <Collection<T>>::get(collection_id);1031 let target_collection = <Collection<T>>::get(collection_id);1025 ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||1032 ensure!(1033 Self::is_item_owner(sender.clone(), collection_id, item_id) ||1034 (1035 target_collection.limits.owner_can_transfer &&1026 Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1036 Self::is_owner_or_admin_permissions(collection_id, sender.clone())1037 ),1027 Error::<T>::NoPermission);1038 Error::<T>::NoPermission1039 );102810401100 let target_collection = <Collection<T>>::get(collection_id);1112 let target_collection = <Collection<T>>::get(collection_id);1101 ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||1113 ensure!(1114 Self::is_item_owner(sender.clone(), collection_id, item_id) ||1115 (1116 target_collection.limits.owner_can_transfer &&1102 Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1117 Self::is_owner_or_admin_permissions(collection_id, sender.clone())1118 ),1103 Error::<T>::NoPermission);1119 Error::<T>::NoPermission1120 );110411211158 // Transfer permissions check 1175 // Transfer permissions check 1159 ensure!(appoved_transfer || Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1176 ensure!(1177 appoved_transfer || 1178 (1179 target_collection.limits.owner_can_transfer &&1180 Self::is_owner_or_admin_permissions(collection_id, sender.clone())1181 ),1160 Error::<T>::NoPermission);1182 Error::<T>::NoPermission1183 );116111841524 pub fn set_collection_limits(1547 pub fn set_collection_limits(1525 origin,1548 origin,1526 collection_id: u32,1549 collection_id: u32,1527 limits: CollectionLimits,1550 new_limits: CollectionLimits,1528 ) -> DispatchResult {1551 ) -> DispatchResult {1529 let sender = ensure_signed(origin)?;1552 let sender = ensure_signed(origin)?;1530 Self::check_owner_permissions(collection_id, sender.clone())?;1553 Self::check_owner_permissions(collection_id, sender.clone())?;1531 let mut target_collection = <Collection<T>>::get(collection_id);1554 let mut target_collection = <Collection<T>>::get(collection_id);1555 let old_limits = target_collection.limits;1532 let chain_limits = ChainLimit::get();1556 let chain_limits = ChainLimit::get();1533 let climits = target_collection.limits;153415571535 // collection bounds1558 // collection bounds1536 ensure!(limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&1559 ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&1537 limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP, 1560 new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP && 1561 new_limits.sponsored_data_size <= chain_limits.custom_data_limit &&1562 new_limits.sponsored_mint_size <= chain_limits.custom_data_limit,1538 Error::<T>::CollectionLimitBoundsExceeded);1563 Error::<T>::CollectionLimitBoundsExceeded);153915641540 // token_limit check prev1565 // token_limit check prev1541 ensure!(climits.token_limit > limits.token_limit && 1566 ensure!(old_limits.token_limit >= new_limits.token_limit, Error::<T>::CollectionTokenLimitExceeded);1567 ensure!(new_limits.token_limit > 0, Error::<T>::CollectionTokenLimitExceeded);15681569 ensure!(1570 (old_limits.owner_can_transfer || !new_limits.owner_can_transfer) &&1542 limits.token_limit <= chain_limits.account_token_ownership_limit, 1571 (old_limits.owner_can_destroy || !new_limits.owner_can_destroy),1543 Error::<T>::AccountTokenLimitExceeded);1572 Error::<T>::OwnerPermissionsCantBeReverted,1573 );154415741545 target_collection.limits = limits;1575 target_collection.limits = new_limits;1546 <Collection<T>>::insert(collection_id, target_collection);1576 <Collection<T>>::insert(collection_id, target_collection);154715771548 Ok(())1578 Ok(())tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -3,6 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
import { ApiPromise } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
@@ -15,6 +16,7 @@
createFungibleItemExpectSuccess,
createItemExpectSuccess,
destroyCollectionExpectSuccess,
+ setCollectionLimitsExpectSuccess,
transferFromExpectSuccess,
U128_MAX,
} from './util/helpers';
@@ -23,10 +25,20 @@
const expect = chai.expect;
describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
+ let Alice: IKeyringPair;
+ let Bob: IKeyringPair;
+ let Charlie: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async (api) => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ Charlie = privateKey('//Charlie');
+ });
+ });
+
it('Execute the extrinsic and check approvedList', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
const nftCollectionId = await createCollectionExpectSuccess();
// nft
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -45,8 +57,6 @@
it('Remove approval by using 0 amount', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
const nftCollectionId = await createCollectionExpectSuccess();
// nft
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -65,13 +75,30 @@
await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);
});
});
+
+ it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
+
+ await approveExpectSuccess(collectionId, itemId, Alice, Charlie);
+ });
});
describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
+ let Alice: IKeyringPair;
+ let Bob: IKeyringPair;
+ let Charlie: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async (api) => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ Charlie = privateKey('//Charlie');
+ });
+ });
+
it('Approve for a collection that does not exist', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
// nft
const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);
@@ -86,8 +113,6 @@
it('Approve for a collection that was destroyed', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(nftCollectionId);
@@ -106,8 +131,6 @@
it('Approve transfer of a token that does not exist', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
await approveExpectFail(nftCollectionId, 2, Alice, Bob);
@@ -123,8 +146,6 @@
it('Approve using the address that does not own the approved token', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
const nftCollectionId = await createCollectionExpectSuccess();
// nft
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -140,4 +161,12 @@
await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);
});
});
+
+ it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
+ await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });
+
+ await approveExpectFail(collectionId, itemId, Alice, Charlie);
+ });
});
tests/src/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -3,10 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
+import { IKeyringPair } from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
import { default as usingApi } from "./substrate/substrate-api";
-import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure } from "./util/helpers";
+import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure, setCollectionLimitsExpectSuccess } from "./util/helpers";
chai.use(chaiAsPromised);
@@ -26,6 +28,14 @@
});
describe('(!negative test!) integration test: ext. destroyCollection():', () => {
+ let alice: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async (api) => {
+ alice = privateKey('//Alice');
+ });
+ });
+
it('(!negative test!) Destroy a collection that never existed', async () => {
await usingApi(async (api) => {
// Find the collection that never existed
@@ -43,4 +53,10 @@
await destroyCollectionExpectFailure(collectionId, '//Bob');
await destroyCollectionExpectSuccess(collectionId, '//Alice');
});
+ it('fails when OwnerCanDestroy == false', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });
+
+ await destroyCollectionExpectFailure(collectionId, '//Alice');
+ });
});
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -14,6 +14,8 @@
createCollectionExpectSuccess, getCreatedCollectionCount,
getCreateItemResult,
getDetailedCollectionInfo,
+ setCollectionLimitsExpectFailure,
+ setCollectionLimitsExpectSuccess,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -26,21 +28,8 @@
const accountTokenOwnershipLimit = 0;
const sponsoredDataSize = 0;
const sponsoredMintSize = 0;
-const tokenLimit = 0;
-
-describe('hooks', () => {
- before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri('//Alice');
- });
- });
- it('choose or create collection for testing', async () => {
- await usingApi(async () => {
- collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
- });
- });
-});
+const sponsorTimeout = 1;
+const tokenLimit = 1;
describe('setCollectionLimits positive', () => {
let tx;
@@ -48,6 +37,7 @@
await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
alice = keyring.addFromUri('//Alice');
+ collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
});
});
it('execute setCollectionLimits with predefined params ', async () => {
@@ -55,25 +45,28 @@
tx = api.tx.nft.setCollectionLimits(
collectionIdForTesting,
{
- accountTokenOwnershipLimit,
- sponsoredDataSize,
- sponsoredMintSize,
- tokenLimit,
+ AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+ SponsoredMintSize: sponsoredDataSize,
+ TokenLimit: tokenLimit,
+ SponsorTimeout: sponsorTimeout,
+ OwnerCanTransfer: true,
+ OwnerCanDestroy: true
},
);
const events = await submitTransactionAsync(alice, tx);
const result = getCreateItemResult(events);
+
+ // get collection limits defined previously
+ const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
+
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- });
- });
- it('get collection limits defined in previous test', async () => {
- await usingApi(async (api: ApiPromise) => {
- const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
expect(collectionInfo.Limits.AccountTokenOwnershipLimit.toNumber()).to.be.equal(accountTokenOwnershipLimit);
- expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredMintSize);
+ expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredDataSize);
expect(collectionInfo.Limits.TokenLimit.toNumber()).to.be.equal(tokenLimit);
- expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsoredDataSize);
+ expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsorTimeout);
+ expect(collectionInfo.Limits.OwnerCanTransfer.valueOf()).to.be.true;
+ expect(collectionInfo.Limits.OwnerCanDestroy.valueOf()).to.be.true;
});
});
});
@@ -85,6 +78,7 @@
const keyring = new Keyring({ type: 'sr25519' });
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
+ collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
});
});
it('execute setCollectionLimits for not exists collection', async () => {
@@ -131,4 +125,44 @@
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
+
+ it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {
+ AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+ SponsoredMintSize: sponsoredDataSize,
+ TokenLimit: tokenLimit,
+ SponsorTimeout: sponsorTimeout,
+ OwnerCanTransfer: false,
+ OwnerCanDestroy: true
+ });
+ await setCollectionLimitsExpectFailure(alice, collectionId, {
+ AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+ SponsoredMintSize: sponsoredDataSize,
+ TokenLimit: tokenLimit,
+ SponsorTimeout: sponsorTimeout,
+ OwnerCanTransfer: true,
+ OwnerCanDestroy: true
+ });
+ });
+
+ it('fails when trying to enable OwnerCanDestroy after it was disabled', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {
+ AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+ SponsoredMintSize: sponsoredDataSize,
+ TokenLimit: tokenLimit,
+ SponsorTimeout: sponsorTimeout,
+ OwnerCanTransfer: true,
+ OwnerCanDestroy: false
+ });
+ await setCollectionLimitsExpectFailure(alice, collectionId, {
+ AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+ SponsoredMintSize: sponsoredDataSize,
+ TokenLimit: tokenLimit,
+ SponsorTimeout: sponsorTimeout,
+ OwnerCanTransfer: true,
+ OwnerCanDestroy: true
+ });
+ });
});
tests/src/transferFrom.test.tsdiffbeforeafterboth--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -3,6 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
import { ApiPromise } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
@@ -18,17 +19,27 @@
transferFromExpectFail,
transferFromExpectSuccess,
burnItemExpectSuccess,
+ setCollectionLimitsExpectSuccess,
} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
+ let Alice: IKeyringPair;
+ let Bob: IKeyringPair;
+ let Charlie: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async (api) => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ Charlie = privateKey('//Charlie');
+ });
+ });
+
it('Execute the extrinsic and check nftItemList - owner of token', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -66,14 +77,30 @@
expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');
});
});
+
+ it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
+
+ await transferFromExpectSuccess(collectionId, itemId, Alice, Bob, Charlie);
+ });
});
describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
+ let Alice: IKeyringPair;
+ let Bob: IKeyringPair;
+ let Charlie: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async (api) => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ Charlie = privateKey('//Charlie');
+ });
+ });
+
it('transferFrom for a collection that does not exist', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
// nft
const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);
@@ -113,9 +140,6 @@
it('transferFrom for not approved address', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -137,9 +161,6 @@
it('transferFrom incorrect token count', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -164,9 +185,6 @@
it('execute transferFrom from account that is not owner of collection', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
const Dave = privateKey('//Dave');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
@@ -206,9 +224,6 @@
});
it( 'transferFrom burnt token before approve NFT', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -219,9 +234,6 @@
});
it( 'transferFrom burnt token before approve Fungible', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
@@ -232,9 +244,6 @@
});
it( 'transferFrom burnt token before approve ReFungible', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
@@ -246,9 +255,6 @@
it( 'transferFrom burnt token after approve NFT', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -259,9 +265,6 @@
});
it( 'transferFrom burnt token after approve Fungible', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
@@ -272,9 +275,6 @@
});
it( 'transferFrom burnt token after approve ReFungible', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
@@ -282,5 +282,13 @@
await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
});
- });
+ });
+
+ it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
+ await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });
+
+ await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);
+ });
});
tests/src/types.tsdiffbeforeafterboth--- a/tests/src/types.ts
+++ b/tests/src/types.ts
@@ -17,6 +17,8 @@
SponsoredMintSize: BN;
TokenLimit: BN;
SponsorTimeout: BN;
+ OwnerCanTransfer: boolean;
+ OwnerCanDestroy: boolean;
};
MintMode: boolean;
Mode: {
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -333,6 +333,36 @@
});
}
+export async function queryCollectionLimits(collectionId: number) {
+ return await usingApi(async (api) => {
+ return ((await api.query.nft.collection(collectionId)).toJSON() as any).Limits;
+ });
+}
+
+export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {
+ await usingApi(async (api) => {
+ const oldLimits = await queryCollectionLimits(collectionId);
+ const newLimits = { ...oldLimits as any, ...limits };
+ const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getGenericResult(events);
+
+ expect(result.success).to.be.true;
+ });
+}
+
+export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {
+ await usingApi(async (api) => {
+ const oldLimits = await queryCollectionLimits(collectionId);
+ const newLimits = { ...oldLimits as any, ...limits };
+ const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);
+ const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getGenericResult(events);
+
+ expect(result.success).to.be.false;
+ });
+}
+
export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {
await usingApi(async (api) => {