difftreelog
OwnerCanTransfer flag
in: master
10 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1164,6 +1164,7 @@
old_limit: &CollectionLimits,
mut new_limit: CollectionLimits,
) -> Result<CollectionLimits, DispatchError> {
+ let limits = old_limit;
limit_default!(old_limit, new_limit,
account_token_ownership_limit => ensure!(
new_limit <= MAX_TOKEN_OWNERSHIP,
@@ -1190,6 +1191,7 @@
),
sponsor_approve_timeout => {},
owner_can_transfer => ensure!(
+ !limits.owner_can_transfer_instaled() ||
old_limit || !new_limit,
<Error<T>>::OwnerPermissionsCantBeReverted,
),
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -409,7 +409,10 @@
.min(MAX_SPONSOR_TIMEOUT)
}
pub fn owner_can_transfer(&self) -> bool {
- self.owner_can_transfer.unwrap_or(true)
+ self.owner_can_transfer.unwrap_or(false)
+ }
+ pub fn owner_can_transfer_instaled(&self) -> bool {
+ self.owner_can_transfer.is_some()
}
pub fn owner_can_destroy(&self) -> bool {
self.owner_can_destroy.unwrap_or(true)
tests/src/approve.test.tsdiffbeforeafterboth1// 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 {ApiPromise} from '@polkadot/api';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import {default as usingApi} from './substrate/substrate-api';22import {23 approveExpectFail,24 approveExpectSuccess,25 createCollectionExpectSuccess,26 createItemExpectSuccess,27 destroyCollectionExpectSuccess,28 setCollectionLimitsExpectSuccess,29 transferExpectSuccess,30 addCollectionAdminExpectSuccess,31 adminApproveFromExpectSuccess,32 getCreatedCollectionCount,33 transferFromExpectSuccess,34 transferFromExpectFail,35} from './util/helpers';3637chai.use(chaiAsPromised);3839describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {40 let alice: IKeyringPair;41 let bob: IKeyringPair;42 let charlie: IKeyringPair;4344 before(async () => {45 await usingApi(async (api, privateKeyWrapper) => {46 alice = privateKeyWrapper('//Alice');47 bob = privateKeyWrapper('//Bob');48 charlie = privateKeyWrapper('//Charlie');49 });50 });5152 it('Execute the extrinsic and check approvedList', async () => {53 const nftCollectionId = await createCollectionExpectSuccess();54 // nft55 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');56 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);57 // fungible58 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});59 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');60 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);61 // reFungible62 const reFungibleCollectionId =63 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});64 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');65 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);66 });6768 it('Remove approval by using 0 amount', async () => {69 const nftCollectionId = await createCollectionExpectSuccess();70 // nft71 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');72 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1);73 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0);74 // fungible75 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});76 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');77 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);78 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);79 // reFungible80 const reFungibleCollectionId =81 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});82 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');83 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);84 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);85 });8687 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {88 const collectionId = await createCollectionExpectSuccess();89 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);9091 await adminApproveFromExpectSuccess(collectionId, itemId, alice, bob.address, charlie.address);92 });93});9495describe('Normal user can approve other users to transfer:', () => {96 let alice: IKeyringPair;97 let bob: IKeyringPair;98 let charlie: IKeyringPair;99100 before(async () => {101 await usingApi(async (api, privateKeyWrapper) => {102 alice = privateKeyWrapper('//Alice');103 bob = privateKeyWrapper('//Bob');104 charlie = privateKeyWrapper('//Charlie');105 });106 }); 107108 it('NFT', async () => {109 const collectionId = await createCollectionExpectSuccess();110 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);111 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);112 });113114 it('Fungible up to an approved amount', async () => {115 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});116 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 117 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);118 });119120 it('ReFungible up to an approved amount', async () => {121 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});122 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);123 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);124 });125});126127describe('Approved users can transferFrom up to approved amount:', () => {128 let alice: IKeyringPair;129 let bob: IKeyringPair;130 let charlie: IKeyringPair;131132 before(async () => {133 await usingApi(async (api, privateKeyWrapper) => {134 alice = privateKeyWrapper('//Alice');135 bob = privateKeyWrapper('//Bob');136 charlie = privateKeyWrapper('//Charlie');137 });138 }); 139140 it('NFT', async () => {141 const collectionId = await createCollectionExpectSuccess();142 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);143 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);144 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');145 });146147 it('Fungible up to an approved amount', async () => {148 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});149 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 150 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);151 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');152 });153154 it('ReFungible up to an approved amount', async () => {155 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});156 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);157 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);158 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');159 });160});161162describe('Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:', () => {163 let alice: IKeyringPair;164 let bob: IKeyringPair;165 let charlie: IKeyringPair;166167 before(async () => {168 await usingApi(async (api, privateKeyWrapper) => {169 alice = privateKeyWrapper('//Alice');170 bob = privateKeyWrapper('//Bob');171 charlie = privateKeyWrapper('//Charlie');172 });173 }); 174175 it('NFT', async () => {176 const collectionId = await createCollectionExpectSuccess();177 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);178 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);179 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');180 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);181 });182183 it('Fungible up to an approved amount', async () => {184 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});185 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 186 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);187 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');188 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);189 });190191 it('ReFungible up to an approved amount', async () => {192 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});193 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);194 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);195 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');196 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);197 });198});199200describe('Approved amount decreases by the transferred amount.:', () => {201 let alice: IKeyringPair;202 let bob: IKeyringPair;203 let charlie: IKeyringPair;204 let dave: IKeyringPair;205206 before(async () => {207 await usingApi(async (api, privateKeyWrapper) => {208 alice = privateKeyWrapper('//Alice');209 bob = privateKeyWrapper('//Bob');210 charlie = privateKeyWrapper('//Charlie');211 dave = privateKeyWrapper('//Dave');212 });213 }); 214215 it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {216 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});217 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address); 218 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 10);219 await transferFromExpectSuccess(collectionId, itemId, bob, alice, charlie, 2, 'Fungible');220 await transferFromExpectSuccess(collectionId, itemId, bob, alice, dave, 8, 'Fungible');221 });222});223224describe('User may clear the approvals to approving for 0 amount:', () => {225 let alice: IKeyringPair;226 let bob: IKeyringPair;227 let charlie: IKeyringPair;228229 before(async () => {230 await usingApi(async (api, privateKeyWrapper) => {231 alice = privateKeyWrapper('//Alice');232 bob = privateKeyWrapper('//Bob');233 charlie = privateKeyWrapper('//Charlie');234 });235 });236237 it('NFT', async () => {238 const collectionId = await createCollectionExpectSuccess();239 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT');240 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1);241 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 0);242 await transferFromExpectFail(collectionId, itemId, bob, bob, charlie, 1);243 });244245 it('Fungible', async () => {246 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});247 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');248 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);249 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);250 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, bob, charlie, 1);251 });252253 it('ReFungible', async () => {254 const reFungibleCollectionId =255 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});256 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');257 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);258 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);259 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, bob, charlie, 1);260 });261});262263describe('User cannot approve for the amount greater than they own:', () => {264 let alice: IKeyringPair;265 let bob: IKeyringPair;266 let charlie: IKeyringPair;267268 before(async () => {269 await usingApi(async (api, privateKeyWrapper) => {270 alice = privateKeyWrapper('//Alice');271 bob = privateKeyWrapper('//Bob');272 charlie = privateKeyWrapper('//Charlie');273 });274 });275276 it('1 for NFT', async () => {277 const collectionId = await createCollectionExpectSuccess();278 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);279 await approveExpectFail(collectionId, itemId, bob, charlie, 2);280 });281282 it('Fungible', async () => {283 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});284 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');285 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, charlie, 11);286 });287288 it('ReFungible', async () => {289 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});290 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');291 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, charlie, 101);292 });293});294295describe('Administrator and collection owner do not need approval in order to execute TransferFrom:', () => {296 let alice: IKeyringPair;297 let bob: IKeyringPair;298 let charlie: IKeyringPair;299 let dave: IKeyringPair;300301 before(async () => {302 await usingApi(async (api, privateKeyWrapper) => {303 alice = privateKeyWrapper('//Alice');304 bob = privateKeyWrapper('//Bob');305 charlie = privateKeyWrapper('//Charlie');306 dave = privateKeyWrapper('//Dave');307 });308 }); 309310 it('NFT', async () => {311 const collectionId = await createCollectionExpectSuccess();312 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', charlie.address);313 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'NFT');314 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);315 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'NFT');316 });317318 it('Fungible up to an approved amount', async () => {319 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});320 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', charlie.address); 321 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'Fungible');322 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);323 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'Fungible');324 });325326 it('ReFungible up to an approved amount', async () => {327 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});328 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', charlie.address);329 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'ReFungible');330 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);331 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'ReFungible');332 });333});334335describe('Repeated approvals add up', () => {336 let alice: IKeyringPair;337 let bob: IKeyringPair;338 let charlie: IKeyringPair;339 let dave: IKeyringPair;340341 before(async () => {342 await usingApi(async (api, privateKeyWrapper) => {343 alice = privateKeyWrapper('//Alice');344 bob = privateKeyWrapper('//Bob');345 charlie = privateKeyWrapper('//Charlie');346 dave = privateKeyWrapper('//Dave');347 });348 }); 349350 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {351 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});352 await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address);353 await approveExpectSuccess(collectionId, 0, alice, bob.address, 1);354 await approveExpectSuccess(collectionId, 0, alice, charlie.address, 1);355 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);356 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);357 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));358 });359360 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async () => {361 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});362 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', alice.address);363 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1);364 await approveExpectSuccess(collectionId, itemId, alice, charlie.address, 1);365 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);366 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);367 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));368 });369370 // Canceled by changing approve logic371 it.skip('Cannot approve for more than total user`s amount (owned: 10, approval 1: 5 - should succeed, approval 2: 6 - should fail). Fungible', async () => {372 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});373 await createItemExpectSuccess(alice, collectionId, 'Fungible', dave.address);374 await approveExpectSuccess(collectionId, 0, dave, bob.address, 5);375 await approveExpectFail(collectionId, 0, dave, charlie, 6);376 });377378 // Canceled by changing approve logic379 it.skip('Cannot approve for more than total users amount (owned: 100, approval 1: 50 - should succeed, approval 2: 51 - should fail). ReFungible', async () => {380 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});381 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', dave.address);382 await approveExpectSuccess(collectionId, itemId, dave, bob.address, 50);383 await approveExpectFail(collectionId, itemId, dave, charlie, 51);384 });385});386387describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {388 let alice: IKeyringPair;389 let bob: IKeyringPair;390 let charlie: IKeyringPair;391392 before(async () => {393 await usingApi(async (api, privateKeyWrapper) => {394 alice = privateKeyWrapper('//Alice');395 bob = privateKeyWrapper('//Bob');396 charlie = privateKeyWrapper('//Charlie');397 });398 });399400 it('can be called by collection admin on non-owned item', async () => {401 const collectionId = await createCollectionExpectSuccess();402 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);403404 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);405 await adminApproveFromExpectSuccess(collectionId, itemId, bob, alice.address, charlie.address);406 });407});408409describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {410 let alice: IKeyringPair;411 let bob: IKeyringPair;412 let charlie: IKeyringPair;413414 before(async () => {415 await usingApi(async (api, privateKeyWrapper) => {416 alice = privateKeyWrapper('//Alice');417 bob = privateKeyWrapper('//Bob');418 charlie = privateKeyWrapper('//Charlie');419 });420 });421422 it('Approve for a collection that does not exist', async () => {423 await usingApi(async (api: ApiPromise) => {424 // nft425 const nftCollectionCount = await getCreatedCollectionCount(api);426 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);427 // fungible428 const fungibleCollectionCount = await getCreatedCollectionCount(api);429 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);430 // reFungible431 const reFungibleCollectionCount = await getCreatedCollectionCount(api);432 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);433 });434 });435436 it('Approve for a collection that was destroyed', async () => {437 // nft438 const nftCollectionId = await createCollectionExpectSuccess();439 await destroyCollectionExpectSuccess(nftCollectionId);440 await approveExpectFail(nftCollectionId, 1, alice, bob);441 // fungible442 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});443 await destroyCollectionExpectSuccess(fungibleCollectionId);444 await approveExpectFail(fungibleCollectionId, 0, alice, bob);445 // reFungible446 const reFungibleCollectionId =447 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});448 await destroyCollectionExpectSuccess(reFungibleCollectionId);449 await approveExpectFail(reFungibleCollectionId, 1, alice, bob);450 });451452 it('Approve transfer of a token that does not exist', async () => {453 // nft454 const nftCollectionId = await createCollectionExpectSuccess();455 await approveExpectFail(nftCollectionId, 2, alice, bob);456 // reFungible457 const reFungibleCollectionId =458 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});459 await approveExpectFail(reFungibleCollectionId, 2, alice, bob);460 });461462 it('Approve using the address that does not own the approved token', async () => {463 const nftCollectionId = await createCollectionExpectSuccess();464 // nft465 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');466 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice);467 // fungible468 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});469 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');470 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice);471 // reFungible472 const reFungibleCollectionId =473 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});474 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');475 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice);476 });477478 it('should fail if approved more ReFungibles than owned', async () => {479 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});480 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible');481 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible');482 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100);483 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101);484 });485486 it('should fail if approved more Fungibles than owned', async () => {487 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});488 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible');489 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible');490 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10);491 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11);492 });493494 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {495 const collectionId = await createCollectionExpectSuccess();496 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);497 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});498499 await approveExpectFail(collectionId, itemId, alice, charlie);500 });501});tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -23,6 +23,7 @@
normalizeAccountId,
addCollectionAdminExpectSuccess,
getBalance,
+ setCollectionLimitsExpectSuccess,
isTokenExists,
} from './util/helpers';
@@ -149,6 +150,7 @@
it('Burn item in NFT collection', async () => {
const createMode = 'NFT';
const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -167,6 +169,7 @@
it('Burn item in Fungible collection', async () => {
const createMode = 'Fungible';
const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -189,6 +192,7 @@
it('Burn item in ReFungible collection', async () => {
const createMode = 'ReFungible';
const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
tests/src/eth/crossTransfer.test.tsdiffbeforeafterboth--- a/tests/src/eth/crossTransfer.test.ts
+++ b/tests/src/eth/crossTransfer.test.ts
@@ -18,6 +18,7 @@
createFungibleItemExpectSuccess,
transferExpectSuccess,
transferFromExpectSuccess,
+ setCollectionLimitsExpectSuccess,
createItemExpectSuccess} from '../util/helpers';
import {collectionIdToAddress,
createEthAccountWithBalance,
@@ -35,6 +36,7 @@
const alice = privateKeyWrapper('//Alice');
const bob = privateKeyWrapper('//Bob');
const charlie = privateKeyWrapper('//Charlie');
+ await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');
await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');
@@ -48,6 +50,7 @@
});
const alice = privateKeyWrapper('//Alice');
const bob = privateKeyWrapper('//Bob');
+ await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
const bobProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const aliceProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
@@ -71,6 +74,7 @@
const alice = privateKeyWrapper('//Alice');
const bob = privateKeyWrapper('//Bob');
const charlie = privateKeyWrapper('//Charlie');
+ await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');
await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');
@@ -85,6 +89,7 @@
const alice = privateKeyWrapper('//Alice');
const bob = privateKeyWrapper('//Bob');
const charlie = privateKeyWrapper('//Charlie');
+ await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
const bobProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const aliceProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
tests/src/limits.test.tsdiffbeforeafterboth--- a/tests/src/limits.test.ts
+++ b/tests/src/limits.test.ts
@@ -406,6 +406,7 @@
it('Effective collection limits', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
{ // Check that limits is undefined
const collection = await api.rpc.unique.collectionById(collectionId);
@@ -419,7 +420,7 @@
expect(limits.tokenLimit.toHuman()).to.be.null;
expect(limits.sponsorTransferTimeout.toHuman()).to.be.null;
expect(limits.sponsorApproveTimeout.toHuman()).to.be.null;
- expect(limits.ownerCanTransfer.toHuman()).to.be.null;
+ expect(limits.ownerCanTransfer.toHuman()).to.be.true;
expect(limits.ownerCanDestroy.toHuman()).to.be.null;
expect(limits.transfersEnabled.toHuman()).to.be.null;
}
tests/src/nesting/graphs.test.tsdiffbeforeafterboth--- a/tests/src/nesting/graphs.test.ts
+++ b/tests/src/nesting/graphs.test.ts
@@ -3,7 +3,7 @@
import {expect} from 'chai';
import {tokenIdToCross} from '../eth/util/helpers';
import usingApi, {executeTransaction} from '../substrate/substrate-api';
-import {getCreateCollectionResult, transferExpectSuccess} from '../util/helpers';
+import {getCreateCollectionResult, transferExpectSuccess, setCollectionLimitsExpectSuccess} from '../util/helpers';
/**
* ```dot
@@ -36,6 +36,7 @@
await usingApi(async (api, privateKeyWrapper) => {
const alice = privateKeyWrapper('//Alice');
const collection = await buildComplexObjectGraph(api, alice);
+ await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
// to self
await expect(
tests/src/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -15,6 +15,7 @@
transferExpectFailure,
transferExpectSuccess,
transferFromExpectSuccess,
+ setCollectionLimitsExpectSuccess,
} from '../util/helpers';
import {IKeyringPair} from '@polkadot/types/types';
@@ -92,6 +93,7 @@
it('Checks token children', async () => {
await usingApi(async api => {
const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionA, {ownerCanTransfer: true});
await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {tokenOwner: true}});
const collectionB = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
tests/src/transferFrom.test.tsdiffbeforeafterboth--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -99,6 +99,7 @@
it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
const collectionId = await createCollectionExpectSuccess();
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
await transferFromExpectSuccess(collectionId, itemId, alice, bob, charlie);
@@ -257,6 +258,7 @@
await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
+ await setCollectionLimitsExpectSuccess(alice, nftCollectionId, {ownerCanTransfer: true});
const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);
await approveExpectFail(nftCollectionId, newNftTokenId, alice, bob);
@@ -266,6 +268,7 @@
it('transferFrom burnt token before approve Fungible', async () => {
await usingApi(async () => {
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ await setCollectionLimitsExpectSuccess(alice, fungibleCollectionId, {ownerCanTransfer: true});
const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);
await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
@@ -276,6 +279,7 @@
it('transferFrom burnt token before approve ReFungible', async () => {
await usingApi(async () => {
const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ await setCollectionLimitsExpectSuccess(alice, reFungibleCollectionId, {ownerCanTransfer: true});
const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);
await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, alice, bob);
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -921,6 +921,18 @@
});
}
+export async function adminApproveFromExpectFail(
+ collectionId: number,
+ tokenId: number, admin: IKeyringPair, owner: CrossAccountId | string, approved: CrossAccountId | string, amount: number | bigint = 1,
+) {
+ await usingApi(async (api: ApiPromise) => {
+ const approveUniqueTx = api.tx.unique.approve(normalizeAccountId(approved), collectionId, tokenId, amount);
+ const events = await expect(submitTransactionAsync(admin, approveUniqueTx)).to.be.rejected;
+ const result = getGenericResult(events);
+ expect(result.success).to.be.false;
+ });
+}
+
export async function
getFreeBalance(account: IKeyringPair): Promise<bigint> {
let balance = 0n;