difftreelog
fix nesting depth limit tests
in: master
2 files changed
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -25,7 +25,7 @@
dispatch_unique_runtime!(collection.token_owner(token))
}
fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {
- let budget = up_data_structs::budget::Value::new(5);
+ let budget = up_data_structs::budget::Value::new(10);
Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))
}
@@ -210,7 +210,7 @@
Ok(
pallet_nonfungible::TokenChildren::<Runtime>::iter_prefix((collection_id, nft_id))
- .filter_map(|(child_id, is_child)|
+ .filter_map(|(child_id, is_child)|
match is_child {
true => Some(RmrkNftChild {
collection_id: child_id.0.0,
tests/src/nesting/nest.test.tsdiffbeforeafterboth1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {6 addToAllowListExpectSuccess,7 createCollectionExpectSuccess,8 createItemExpectSuccess,9 enableAllowListExpectSuccess,10 enablePublicMintingExpectSuccess,11 getTokenOwner, 12 getTopmostTokenOwner,13 setCollectionLimitsExpectSuccess, 14 transferExpectFailure, 15 transferExpectSuccess, 16 transferFromExpectSuccess,17} from '../util/helpers';18import {IKeyringPair} from '@polkadot/types/types';1920let alice: IKeyringPair;21let bob: IKeyringPair;2223describe('Integration Test: Nesting', () => {24 before(async () => {25 await usingApi(async () => {26 alice = privateKey('//Alice');27 bob = privateKey('//Bob');28 });29 });3031 it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {32 await usingApi(async api => {33 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});34 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});35 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3637 // Create a nested token38 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});39 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});40 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4142 // Create a token to be nested43 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');44 45 // Nest46 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});47 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});48 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4950 // Move bundle to different user51 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});52 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});53 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5455 // Unnest56 await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});57 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});58 });59 });6061 // ---------- Non-Fungible ----------6263 it('NFT: allows an Owner to nest/unnest their token', async () => {64 await usingApi(async api => {65 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});66 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});67 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');6869 // Create a nested token70 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});71 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});72 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});7374 // Create a token to be nested and nest75 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');76 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});77 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});78 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});79 });80 });8182 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {83 await usingApi(async api => {84 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});85 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});86 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');8788 // Create a nested token89 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});90 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});91 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});9293 // Create a token to be nested and nest94 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');95 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});96 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});97 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});98 });99 });100101 // ---------- Fungible ----------102103 it('Fungible: allows an Owner to nest/unnest their token', async () => {104 await usingApi(async api => {105 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});106 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});107 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});108 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};109110 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});111112 // Create a nested token113 await expect(executeTransaction(api, alice, api.tx.unique.createItem(114 collectionFT, 115 targetAddress, 116 {Fungible: {Value: 10}},117 ))).to.not.be.rejected;118119 // Nest a new token120 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');121 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');122 });123 });124125 it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {126 await usingApi(async api => {127 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});128 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});129 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};130131 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});132133 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});134135 // Create a nested token136 await expect(executeTransaction(api, alice, api.tx.unique.createItem(137 collectionFT, 138 targetAddress, 139 {Fungible: {Value: 10}},140 ))).to.not.be.rejected;141142 // Nest a new token143 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');144 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');145 });146 });147148 // ---------- Re-Fungible ----------149150 it('ReFungible: allows an Owner to nest/unnest their token', async () => {151 await usingApi(async api => {152 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});153 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});154 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});155 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};156157 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});158159 // Create a nested token160 await expect(executeTransaction(api, alice, api.tx.unique.createItem(161 collectionRFT, 162 targetAddress, 163 {ReFungible: {const_data: [], pieces: 100}},164 ))).to.not.be.rejected;165166 // Nest a new token167 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');168 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');169 });170 });171172 it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {173 await usingApi(async api => {174 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});175 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});176 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};177178 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});179180 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});181182 // Create a nested token183 await expect(executeTransaction(api, alice, api.tx.unique.createItem(184 collectionRFT, 185 targetAddress,186 {ReFungible: {const_data: [], pieces: 100}},187 ))).to.not.be.rejected;188189 // Nest a new token190 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');191 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');192 });193 });194});195196describe('Negative Test: Nesting', async() => {197 before(async () => {198 await usingApi(async () => {199 alice = privateKey('//Alice');200 bob = privateKey('//Bob');201 });202 });203204 it('Disallows excessive token nesting', async () => {205 await usingApi(async api => {206 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});207 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});208 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');209210 // Create a nested-token matryoshka211 const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});212 const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});213 // The nesting depth is limited by 2214 await expect(executeTransaction(api, alice, api.tx.unique.createItem(215 collection, 216 {Ethereum: tokenIdToAddress(collection, nestedToken2)}, 217 {nft: {const_data: [], variable_data: []}} as any,218 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);219220 expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});221 });222 });223224 // ---------- Non-Fungible ----------225226 it('NFT: disallows to nest token if nesting is disabled', async () => {227 await usingApi(async api => {228 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});229 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Disabled'});230 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');231232 // Try to create a nested token233 await expect(executeTransaction(api, alice, api.tx.unique.createItem(234 collection, 235 {Ethereum: tokenIdToAddress(collection, targetToken)}, 236 {nft: {const_data: [], variable_data: []}} as any,237 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);238239 // Create a token to be nested240 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');241 // Try to nest242 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);243 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});244 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});245 });246 });247248 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {249 await usingApi(async api => {250 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});251 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});252253 await addToAllowListExpectSuccess(alice, collection, bob.address);254 await enableAllowListExpectSuccess(alice, collection);255 await enablePublicMintingExpectSuccess(alice, collection);256257 // Create a token to attempt to be nested into258 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');259260 // Try to create a nested token in the wrong collection261 await expect(executeTransaction(api, alice, api.tx.unique.createItem(262 collection, 263 {Ethereum: tokenIdToAddress(collection, targetToken)}, 264 {nft: {const_data: [], variable_data: []}} as any,265 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);266267 // Try to create and nest a token in the wrong collection268 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');269 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);270 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});271 });272 });273274 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {275 await usingApi(async api => {276 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});277 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});278279 await addToAllowListExpectSuccess(alice, collection, bob.address);280 await enableAllowListExpectSuccess(alice, collection);281 await enablePublicMintingExpectSuccess(alice, collection);282283 // Create a token to attempt to be nested into284 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');285286 // Try to create a nested token in the wrong collection287 await expect(executeTransaction(api, alice, api.tx.unique.createItem(288 collection, 289 {Ethereum: tokenIdToAddress(collection, targetToken)}, 290 {nft: {const_data: [], variable_data: []}} as any,291 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);292293 // Try to create and nest a token in the wrong collection294 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');295 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);296 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});297 });298 });299300 it('NFT: disallows to nest token in an unlisted collection', async () => {301 await usingApi(async api => {302 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});303 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});304305 // Create a token to attempt to be nested into306 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');307308 // Try to create a nested token in the wrong collection309 await expect(executeTransaction(api, alice, api.tx.unique.createItem(310 collection, 311 {Ethereum: tokenIdToAddress(collection, targetToken)}, 312 {nft: {const_data: [], variable_data: []}} as any,313 )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);314315 // Try to create and nest a token in the wrong collection316 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');317 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);318 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});319 });320 });321322 // ---------- Fungible ----------323324 it('Fungible: disallows to nest token if nesting is disabled', async () => {325 await usingApi(async api => {326 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});327 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});328 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');329 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};330331 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});332333 // Try to create a nested token334 await expect(executeTransaction(api, alice, api.tx.unique.createItem(335 collectionFT, 336 targetAddress, 337 {Fungible: {Value: 10}},338 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);339 340 // Create a token to be nested341 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');342 // Try to nest343 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);344345 // Create another token to be nested346 const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');347 // Try to nest inside a fungible token348 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionFT, newToken)}, collectionFT, newToken2, 1)), 'while nesting new token inside fungible').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);349 });350 });351352 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {353 await usingApi(async api => {354 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});355 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});356357 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);358 await enableAllowListExpectSuccess(alice, collectionNFT);359 await enablePublicMintingExpectSuccess(alice, collectionNFT);360361 // Create a token to attempt to be nested into362 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');363 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};364365 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});366367 // Try to create a nested token in the wrong collection368 await expect(executeTransaction(api, alice, api.tx.unique.createItem(369 collectionFT, 370 targetAddress, 371 {Fungible: {Value: 10}},372 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);373374 // Try to create and nest a token in the wrong collection375 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');376 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);377 });378 });379380 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {381 await usingApi(async api => {382 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});383 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);384 await enableAllowListExpectSuccess(alice, collectionNFT);385 await enablePublicMintingExpectSuccess(alice, collectionNFT);386387 // Create a token to attempt to be nested into388 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');389 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};390391 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});392 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});393394 // Try to create a nested token in the wrong collection395 await expect(executeTransaction(api, alice, api.tx.unique.createItem(396 collectionFT, 397 targetAddress, 398 {Fungible: {Value: 10}},399 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);400401 // Try to create and nest a token in the wrong collection402 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');403 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);404 });405 });406407 it('Fungible: disallows to nest token in an unlisted collection', async () => {408 await usingApi(async api => {409 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});410 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});411412 // Create a token to attempt to be nested into413 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');414 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};415416 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});417418 // Try to create a nested token in the wrong collection419 await expect(executeTransaction(api, alice, api.tx.unique.createItem(420 collectionFT, 421 targetAddress, 422 {Fungible: {Value: 10}},423 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);424425 // Try to create and nest a token in the wrong collection426 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');427 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);428 });429 });430431 // ---------- Re-Fungible ----------432433 it('ReFungible: disallows to nest token if nesting is disabled', async () => {434 await usingApi(async api => {435 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});436 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});437 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');438 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};439440 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});441442 // Create a nested token443 await expect(executeTransaction(api, alice, api.tx.unique.createItem(444 collectionRFT, 445 targetAddress, 446 {ReFungible: {const_data: [], pieces: 100}},447 )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);448449 // Create a token to be nested450 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');451 // Try to nest452 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);453 // Try to nest454 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);455456 // Create another token to be nested457 const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');458 // Try to nest inside a fungible token459 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionRFT, newToken)}, collectionRFT, newToken2, 1)), 'while nesting new token inside refungible').to.be.rejectedWith(/refungible\.RefungibleDisallowsNesting/);460 });461 });462463 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {464 await usingApi(async api => {465 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});466 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});467468 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);469 await enableAllowListExpectSuccess(alice, collectionNFT);470 await enablePublicMintingExpectSuccess(alice, collectionNFT);471472 // Create a token to attempt to be nested into473 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');474 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};475476 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});477478 // Try to create a nested token in the wrong collection479 await expect(executeTransaction(api, alice, api.tx.unique.createItem(480 collectionRFT, 481 targetAddress, 482 {ReFungible: {const_data: [], pieces: 100}},483 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);484485 // Try to create and nest a token in the wrong collection486 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');487 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);488 });489 });490491 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {492 await usingApi(async api => {493 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});494 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);495 await enableAllowListExpectSuccess(alice, collectionNFT);496 await enablePublicMintingExpectSuccess(alice, collectionNFT);497498 // Create a token to attempt to be nested into499 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');500 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};501502 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});503 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});504505 // Try to create a nested token in the wrong collection506 await expect(executeTransaction(api, alice, api.tx.unique.createItem(507 collectionRFT, 508 targetAddress, 509 {ReFungible: {const_data: [], pieces: 100}},510 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);511512 // Try to create and nest a token in the wrong collection513 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');514 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);515 });516 });517518 it('ReFungible: disallows to nest token to an unlisted collection', async () => {519 await usingApi(async api => {520 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});521 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});522523 // Create a token to attempt to be nested into524 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');525 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};526527 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});528529 // Try to create a nested token in the wrong collection530 await expect(executeTransaction(api, alice, api.tx.unique.createItem(531 collectionRFT, 532 targetAddress, 533 {ReFungible: {const_data: [], pieces: 100}},534 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);535536 // Try to create and nest a token in the wrong collection537 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');538 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);539 });540 });541});1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {6 addToAllowListExpectSuccess,7 createCollectionExpectSuccess,8 createItemExpectSuccess,9 enableAllowListExpectSuccess,10 enablePublicMintingExpectSuccess,11 getTokenOwner,12 getTopmostTokenOwner,13 setCollectionLimitsExpectSuccess,14 transferExpectFailure,15 transferExpectSuccess,16 transferFromExpectSuccess,17} from '../util/helpers';18import {IKeyringPair} from '@polkadot/types/types';1920let alice: IKeyringPair;21let bob: IKeyringPair;2223describe('Integration Test: Nesting', () => {24 before(async () => {25 await usingApi(async () => {26 alice = privateKey('//Alice');27 bob = privateKey('//Bob');28 });29 });3031 it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {32 await usingApi(async api => {33 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});34 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});35 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3637 // Create a nested token38 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});39 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});40 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4142 // Create a token to be nested43 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');4445 // Nest46 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});47 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});48 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4950 // Move bundle to different user51 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});52 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});53 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5455 // Unnest56 await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});57 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});58 });59 });6061 // ---------- Non-Fungible ----------6263 it('NFT: allows an Owner to nest/unnest their token', async () => {64 await usingApi(async api => {65 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});66 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});67 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');6869 // Create a nested token70 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});71 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});72 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});7374 // Create a token to be nested and nest75 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');76 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});77 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});78 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});79 });80 });8182 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {83 await usingApi(async api => {84 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});85 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});86 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');8788 // Create a nested token89 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});90 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});91 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});9293 // Create a token to be nested and nest94 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');95 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});96 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});97 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});98 });99 });100101 // ---------- Fungible ----------102103 it('Fungible: allows an Owner to nest/unnest their token', async () => {104 await usingApi(async api => {105 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});106 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});107 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});108 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};109110 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});111112 // Create a nested token113 await expect(executeTransaction(api, alice, api.tx.unique.createItem(114 collectionFT,115 targetAddress,116 {Fungible: {Value: 10}},117 ))).to.not.be.rejected;118119 // Nest a new token120 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');121 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');122 });123 });124125 it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {126 await usingApi(async api => {127 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});128 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});129 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};130131 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});132133 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});134135 // Create a nested token136 await expect(executeTransaction(api, alice, api.tx.unique.createItem(137 collectionFT,138 targetAddress,139 {Fungible: {Value: 10}},140 ))).to.not.be.rejected;141142 // Nest a new token143 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');144 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');145 });146 });147148 // ---------- Re-Fungible ----------149150 it('ReFungible: allows an Owner to nest/unnest their token', async () => {151 await usingApi(async api => {152 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});153 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});154 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});155 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};156157 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});158159 // Create a nested token160 await expect(executeTransaction(api, alice, api.tx.unique.createItem(161 collectionRFT,162 targetAddress,163 {ReFungible: {const_data: [], pieces: 100}},164 ))).to.not.be.rejected;165166 // Nest a new token167 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');168 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');169 });170 });171172 it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {173 await usingApi(async api => {174 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});175 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});176 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};177178 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});179180 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});181182 // Create a nested token183 await expect(executeTransaction(api, alice, api.tx.unique.createItem(184 collectionRFT,185 targetAddress,186 {ReFungible: {const_data: [], pieces: 100}},187 ))).to.not.be.rejected;188189 // Nest a new token190 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');191 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');192 });193 });194});195196describe('Negative Test: Nesting', async() => {197 before(async () => {198 await usingApi(async () => {199 alice = privateKey('//Alice');200 bob = privateKey('//Bob');201 });202 });203204 it('Disallows excessive token nesting', async () => {205 await usingApi(async api => {206 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});207 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});208 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');209210 const maxNestingLevel = 5;211 let prevToken = targetToken;212213 // Create a nested-token matryoshka214 for (let i = 0; i < maxNestingLevel; i++) {215 const nestedToken = await createItemExpectSuccess(216 alice,217 collection,218 'NFT',219 {Ethereum: tokenIdToAddress(collection, prevToken)},220 );221222 prevToken = nestedToken;223 }224225 // The nesting depth is limited by `maxNestingLevel`226 await expect(executeTransaction(api, alice, api.tx.unique.createItem(227 collection,228 {Ethereum: tokenIdToAddress(collection, prevToken)},229 {nft: {const_data: [], variable_data: []}} as any,230 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);231232 expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});233 });234 });235236 // ---------- Non-Fungible ----------237238 it('NFT: disallows to nest token if nesting is disabled', async () => {239 await usingApi(async api => {240 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});241 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Disabled'});242 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');243244 // Try to create a nested token245 await expect(executeTransaction(api, alice, api.tx.unique.createItem(246 collection,247 {Ethereum: tokenIdToAddress(collection, targetToken)},248 {nft: {const_data: [], variable_data: []}} as any,249 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);250251 // Create a token to be nested252 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');253 // Try to nest254 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);255 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});256 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});257 });258 });259260 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {261 await usingApi(async api => {262 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});263 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});264265 await addToAllowListExpectSuccess(alice, collection, bob.address);266 await enableAllowListExpectSuccess(alice, collection);267 await enablePublicMintingExpectSuccess(alice, collection);268269 // Create a token to attempt to be nested into270 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');271272 // Try to create a nested token in the wrong collection273 await expect(executeTransaction(api, alice, api.tx.unique.createItem(274 collection,275 {Ethereum: tokenIdToAddress(collection, targetToken)},276 {nft: {const_data: [], variable_data: []}} as any,277 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);278279 // Try to create and nest a token in the wrong collection280 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');281 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);282 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});283 });284 });285286 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {287 await usingApi(async api => {288 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});289 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});290291 await addToAllowListExpectSuccess(alice, collection, bob.address);292 await enableAllowListExpectSuccess(alice, collection);293 await enablePublicMintingExpectSuccess(alice, collection);294295 // Create a token to attempt to be nested into296 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');297298 // Try to create a nested token in the wrong collection299 await expect(executeTransaction(api, alice, api.tx.unique.createItem(300 collection,301 {Ethereum: tokenIdToAddress(collection, targetToken)},302 {nft: {const_data: [], variable_data: []}} as any,303 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);304305 // Try to create and nest a token in the wrong collection306 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');307 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);308 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});309 });310 });311312 it('NFT: disallows to nest token in an unlisted collection', async () => {313 await usingApi(async api => {314 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});315 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});316317 // Create a token to attempt to be nested into318 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');319320 // Try to create a nested token in the wrong collection321 await expect(executeTransaction(api, alice, api.tx.unique.createItem(322 collection,323 {Ethereum: tokenIdToAddress(collection, targetToken)},324 {nft: {const_data: [], variable_data: []}} as any,325 )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);326327 // Try to create and nest a token in the wrong collection328 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');329 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);330 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});331 });332 });333334 // ---------- Fungible ----------335336 it('Fungible: disallows to nest token if nesting is disabled', async () => {337 await usingApi(async api => {338 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});339 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});340 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');341 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};342343 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});344345 // Try to create a nested token346 await expect(executeTransaction(api, alice, api.tx.unique.createItem(347 collectionFT,348 targetAddress,349 {Fungible: {Value: 10}},350 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);351352 // Create a token to be nested353 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');354 // Try to nest355 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);356357 // Create another token to be nested358 const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');359 // Try to nest inside a fungible token360 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionFT, newToken)}, collectionFT, newToken2, 1)), 'while nesting new token inside fungible').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);361 });362 });363364 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {365 await usingApi(async api => {366 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});367 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});368369 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);370 await enableAllowListExpectSuccess(alice, collectionNFT);371 await enablePublicMintingExpectSuccess(alice, collectionNFT);372373 // Create a token to attempt to be nested into374 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');375 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};376377 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});378379 // Try to create a nested token in the wrong collection380 await expect(executeTransaction(api, alice, api.tx.unique.createItem(381 collectionFT,382 targetAddress,383 {Fungible: {Value: 10}},384 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);385386 // Try to create and nest a token in the wrong collection387 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');388 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);389 });390 });391392 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {393 await usingApi(async api => {394 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});395 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);396 await enableAllowListExpectSuccess(alice, collectionNFT);397 await enablePublicMintingExpectSuccess(alice, collectionNFT);398399 // Create a token to attempt to be nested into400 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');401 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};402403 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});404 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});405406 // Try to create a nested token in the wrong collection407 await expect(executeTransaction(api, alice, api.tx.unique.createItem(408 collectionFT,409 targetAddress,410 {Fungible: {Value: 10}},411 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);412413 // Try to create and nest a token in the wrong collection414 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');415 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);416 });417 });418419 it('Fungible: disallows to nest token in an unlisted collection', async () => {420 await usingApi(async api => {421 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});422 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});423424 // Create a token to attempt to be nested into425 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');426 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};427428 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});429430 // Try to create a nested token in the wrong collection431 await expect(executeTransaction(api, alice, api.tx.unique.createItem(432 collectionFT,433 targetAddress,434 {Fungible: {Value: 10}},435 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);436437 // Try to create and nest a token in the wrong collection438 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');439 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);440 });441 });442443 // ---------- Re-Fungible ----------444445 it('ReFungible: disallows to nest token if nesting is disabled', async () => {446 await usingApi(async api => {447 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});448 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});449 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');450 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};451452 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});453454 // Create a nested token455 await expect(executeTransaction(api, alice, api.tx.unique.createItem(456 collectionRFT,457 targetAddress,458 {ReFungible: {const_data: [], pieces: 100}},459 )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);460461 // Create a token to be nested462 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');463 // Try to nest464 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);465 // Try to nest466 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);467468 // Create another token to be nested469 const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');470 // Try to nest inside a fungible token471 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionRFT, newToken)}, collectionRFT, newToken2, 1)), 'while nesting new token inside refungible').to.be.rejectedWith(/refungible\.RefungibleDisallowsNesting/);472 });473 });474475 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {476 await usingApi(async api => {477 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});478 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});479480 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);481 await enableAllowListExpectSuccess(alice, collectionNFT);482 await enablePublicMintingExpectSuccess(alice, collectionNFT);483484 // Create a token to attempt to be nested into485 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');486 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};487488 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});489490 // Try to create a nested token in the wrong collection491 await expect(executeTransaction(api, alice, api.tx.unique.createItem(492 collectionRFT,493 targetAddress,494 {ReFungible: {const_data: [], pieces: 100}},495 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);496497 // Try to create and nest a token in the wrong collection498 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');499 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);500 });501 });502503 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {504 await usingApi(async api => {505 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});506 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);507 await enableAllowListExpectSuccess(alice, collectionNFT);508 await enablePublicMintingExpectSuccess(alice, collectionNFT);509510 // Create a token to attempt to be nested into511 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');512 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};513514 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});515 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});516517 // Try to create a nested token in the wrong collection518 await expect(executeTransaction(api, alice, api.tx.unique.createItem(519 collectionRFT,520 targetAddress,521 {ReFungible: {const_data: [], pieces: 100}},522 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);523524 // Try to create and nest a token in the wrong collection525 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');526 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);527 });528 });529530 it('ReFungible: disallows to nest token to an unlisted collection', async () => {531 await usingApi(async api => {532 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});533 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});534535 // Create a token to attempt to be nested into536 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');537 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};538539 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});540541 // Try to create a nested token in the wrong collection542 await expect(executeTransaction(api, alice, api.tx.unique.createItem(543 collectionRFT,544 targetAddress,545 {ReFungible: {const_data: [], pieces: 100}},546 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);547548 // Try to create and nest a token in the wrong collection549 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');550 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);551 });552 });553});