difftreelog
tests(nesting): refactor naming conventions for token addresses
in: master
7 files changed
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth240 }240 }241241242 fromTokenId(collectionId: number, tokenId: number): string {242 fromTokenId(collectionId: number, tokenId: number): string {243 return this.helper.util.getNestingTokenAddressRaw({collectionId, tokenId});243 return this.helper.util.getTokenAddress({collectionId, tokenId});244 }244 }245245246 normalizeAddress(address: string): string {246 normalizeAddress(address: string): string {tests/src/nesting/graphs.test.tsdiffbeforeafterboth64 'second transaction',64 'second transaction',65 ).to.be.rejectedWith(/structure\.OuroborosDetected/);65 ).to.be.rejectedWith(/structure\.OuroborosDetected/);66 await expect(66 await expect(67 tokens[1].transferFrom(alice, tokens[0].nestingAddress(), tokens[7].nestingAddress()),67 tokens[1].transferFrom(alice, tokens[0].nestingAccount(), tokens[7].nestingAccount()),68 'third transaction',68 'third transaction',69 ).to.be.rejectedWith(/structure\.OuroborosDetected/);69 ).to.be.rejectedWith(/structure\.OuroborosDetected/);70 });70 });tests/src/nesting/nest.test.tsdiffbeforeafterboth33 const targetToken = await collection.mintToken(alice);33 const targetToken = await collection.mintToken(alice);343435 // Create an immediately nested token35 // Create an immediately nested token36 const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());36 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());37 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});37 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});38 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());38 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());39 39 40 // Create a token to be nested40 // Create a token to be nested41 const newToken = await collection.mintToken(alice);41 const newToken = await collection.mintToken(alice);424243 // Nest43 // Nest44 await newToken.nest(alice, targetToken);44 await newToken.nest(alice, targetToken);45 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});45 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});46 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());46 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());474748 // Move bundle to different user48 // Move bundle to different user49 await targetToken.transfer(alice, {Substrate: bob.address});49 await targetToken.transfer(alice, {Substrate: bob.address});50 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});50 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});51 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());51 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());52 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});52 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});53 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());53 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());545455 // Unnest55 // Unnest56 await newToken.unnest(bob, targetToken, {Substrate: bob.address});56 await newToken.unnest(bob, targetToken, {Substrate: bob.address});64 const tokenB = await collection.mintToken(alice);64 const tokenB = await collection.mintToken(alice);656566 // Create a nested token66 // Create a nested token67 const tokenC = await collection.mintToken(alice, tokenA.nestingAddress());67 const tokenC = await collection.mintToken(alice, tokenA.nestingAccount());68 expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAddress());68 expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAccount());69 69 70 // Transfer the nested token to another token70 // Transfer the nested token to another token71 await expect(tokenC.transferFrom(alice, tokenA.nestingAddress(), tokenB.nestingAddress())).to.be.fulfilled;71 await expect(tokenC.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount())).to.be.fulfilled;72 expect(await tokenC.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});72 expect(await tokenC.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});73 expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAddress());73 expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAccount());74 });74 });757576 itSub('Checks token children', async ({helper}) => {76 itSub('Checks token children', async ({helper}) => {81 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');81 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');828283 // Create a nested NFT token83 // Create a nested NFT token84 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAddress());84 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());85 expect(await targetToken.getChildren()).to.have.deep.members([85 expect(await targetToken.getChildren()).to.have.deep.members([86 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},86 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},87 ], 'Children contents check at nesting #1').and.be.length(1, 'Children length check at nesting #1');87 ], 'Children contents check at nesting #1').and.be.length(1, 'Children length check at nesting #1');102102103 // Create a fungible token in another collection and then nest103 // Create a fungible token in another collection and then nest104 await collectionB.mint(alice, 10n);104 await collectionB.mint(alice, 10n);105 await collectionB.transfer(alice, targetToken.nestingAddress(), 2n);105 await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);106 expect(await targetToken.getChildren()).to.be.have.deep.members([106 expect(await targetToken.getChildren()).to.be.have.deep.members([107 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},107 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},108 {tokenId: 0, collectionId: collectionB.collectionId},108 {tokenId: 0, collectionId: collectionB.collectionId},109 ], 'Children contents check at nesting #4 (from another collection)')109 ], 'Children contents check at nesting #4 (from another collection)')110 .and.be.length(2, 'Children length check at nesting #4 (from another collection)');110 .and.be.length(2, 'Children length check at nesting #4 (from another collection)');111 111 112 // Move part of the fungible token inside token A deeper in the nesting tree112 // Move part of the fungible token inside token A deeper in the nesting tree113 await collectionB.transferFrom(alice, targetToken.nestingAddress(), tokenA.nestingAddress(), 1n);113 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);114 expect(await targetToken.getChildren()).to.be.have.deep.members([114 expect(await targetToken.getChildren()).to.be.have.deep.members([115 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},115 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},116 {tokenId: 0, collectionId: collectionB.collectionId},116 {tokenId: 0, collectionId: collectionB.collectionId},120 ], 'Children contents check at nesting #5.5 (deeper)').and.be.length(1, 'Children length check at nesting #5.5 (deeper)');120 ], 'Children contents check at nesting #5.5 (deeper)').and.be.length(1, 'Children length check at nesting #5.5 (deeper)');121121122 // Move the remaining part of the fungible token inside token A deeper in the nesting tree122 // Move the remaining part of the fungible token inside token A deeper in the nesting tree123 await collectionB.transferFrom(alice, targetToken.nestingAddress(), tokenA.nestingAddress(), 1n);123 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);124 expect(await targetToken.getChildren()).to.be.have.deep.members([124 expect(await targetToken.getChildren()).to.be.have.deep.members([125 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},125 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},126 ], 'Children contents check at nesting #6 (deeper)').and.be.length(1, 'Children length check at nesting #6 (deeper)');126 ], 'Children contents check at nesting #6 (deeper)').and.be.length(1, 'Children length check at nesting #6 (deeper)');148 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});148 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});149149150 // Create an immediately nested token150 // Create an immediately nested token151 const nestedToken = await collection.mintToken(bob, targetToken.nestingAddress());151 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());152 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});152 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});153 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());153 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());154154155 // Create a token to be nested and nest155 // Create a token to be nested and nest156 const newToken = await collection.mintToken(bob);156 const newToken = await collection.mintToken(bob);157 await newToken.nest(bob, targetToken);157 await newToken.nest(bob, targetToken);158 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});158 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});159 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());159 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());160 });160 });161161162 itSub('Admin (NFT): Admin and Token Owner can operate together', async ({helper}) => {162 itSub('Admin (NFT): Admin and Token Owner can operate together', async ({helper}) => {165 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});165 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});166166167 // Create an immediately nested token by an administrator167 // Create an immediately nested token by an administrator168 const nestedToken = await collection.mintToken(bob, targetToken.nestingAddress());168 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());169 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});169 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});170 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());170 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());171171172 // Create a token to be nested and nest172 // Create a token to be nested and nest173 const newToken = await collection.mintToken(alice, {Substrate: charlie.address});173 const newToken = await collection.mintToken(alice, {Substrate: charlie.address});174 await newToken.nest(charlie, targetToken);174 await newToken.nest(charlie, targetToken);175 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});175 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});176 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());176 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());177 });177 });178178179 itSub('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async ({helper}) => {179 itSub('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async ({helper}) => {185 const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});185 const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});186186187 // Create an immediately nested token187 // Create an immediately nested token188 const nestedToken = await collectionB.mintToken(bob, targetToken.nestingAddress());188 const nestedToken = await collectionB.mintToken(bob, targetToken.nestingAccount());189 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});189 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});190 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());190 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());191191192 // Create a token to be nested and nest192 // Create a token to be nested and nest193 const newToken = await collectionB.mintToken(bob);193 const newToken = await collectionB.mintToken(bob);194 await newToken.nest(bob, targetToken);194 await newToken.nest(bob, targetToken);195 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});195 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});196 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());196 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());197 });197 });198198199 // ---------- Non-Fungible ----------199 // ---------- Non-Fungible ----------202 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});202 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});203 await collection.addToAllowList(alice, {Substrate: charlie.address});203 await collection.addToAllowList(alice, {Substrate: charlie.address});204 const targetToken = await collection.mintToken(charlie);204 const targetToken = await collection.mintToken(charlie);205 await collection.addToAllowList(alice, targetToken.nestingAddress());205 await collection.addToAllowList(alice, targetToken.nestingAccount());206206207 // Create an immediately nested token207 // Create an immediately nested token208 const nestedToken = await collection.mintToken(charlie, targetToken.nestingAddress());208 const nestedToken = await collection.mintToken(charlie, targetToken.nestingAccount());209 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});209 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});210 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());210 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());211211212 // Create a token to be nested and nest212 // Create a token to be nested and nest213 const newToken = await collection.mintToken(charlie);213 const newToken = await collection.mintToken(charlie);214 await newToken.nest(charlie, targetToken);214 await newToken.nest(charlie, targetToken);215 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});215 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});216 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());216 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());217 });217 });218218219 itSub('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {219 itSub('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {224224225 await collectionA.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionB.collectionId]}});225 await collectionA.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionB.collectionId]}});226 await collectionA.addToAllowList(alice, {Substrate: charlie.address});226 await collectionA.addToAllowList(alice, {Substrate: charlie.address});227 await collectionA.addToAllowList(alice, targetToken.nestingAddress());227 await collectionA.addToAllowList(alice, targetToken.nestingAccount());228228229 await collectionB.setPermissions(alice, {access: 'AllowList', mintMode: true});229 await collectionB.setPermissions(alice, {access: 'AllowList', mintMode: true});230 await collectionB.addToAllowList(alice, {Substrate: charlie.address});230 await collectionB.addToAllowList(alice, {Substrate: charlie.address});231 await collectionB.addToAllowList(alice, targetToken.nestingAddress());231 await collectionB.addToAllowList(alice, targetToken.nestingAccount());232232233 // Create an immediately nested token233 // Create an immediately nested token234 const nestedToken = await collectionB.mintToken(charlie, targetToken.nestingAddress());234 const nestedToken = await collectionB.mintToken(charlie, targetToken.nestingAccount());235 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});235 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});236 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());236 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());237237238 // Create a token to be nested and nest238 // Create a token to be nested and nest239 const newToken = await collectionB.mintToken(charlie);239 const newToken = await collectionB.mintToken(charlie);240 await newToken.nest(charlie, targetToken);240 await newToken.nest(charlie, targetToken);241 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});241 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});242 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());242 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());243 });243 });244244245 // ---------- Fungible ----------245 // ---------- Fungible ----------250 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});250 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});251251252 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});252 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});253 await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());253 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());254254255 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});255 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});256 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});256 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});257 await collectionFT.addToAllowList(alice, targetToken.nestingAddress());257 await collectionFT.addToAllowList(alice, targetToken.nestingAccount());258258259 // Create an immediately nested token259 // Create an immediately nested token260 await collectionFT.mint(charlie, 5n, targetToken.nestingAddress());260 await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());261 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(5n);261 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);262262263 // Create a token to be nested and nest263 // Create a token to be nested and nest264 await collectionFT.mint(charlie, 5n);264 await collectionFT.mint(charlie, 5n);265 await collectionFT.transfer(charlie, targetToken.nestingAddress(), 2n);265 await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);266 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(7n);266 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);267 });267 });268268269 itSub('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {269 itSub('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {273273274 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionFT.collectionId]}});274 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionFT.collectionId]}});275 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});275 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});276 await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());276 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());277277278 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});278 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});279 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});279 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});280 await collectionFT.addToAllowList(alice, targetToken.nestingAddress());280 await collectionFT.addToAllowList(alice, targetToken.nestingAccount());281281282 // Create an immediately nested token282 // Create an immediately nested token283 await collectionFT.mint(charlie, 5n, targetToken.nestingAddress());283 await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());284 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(5n);284 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);285285286 // Create a token to be nested and nest286 // Create a token to be nested and nest287 await collectionFT.mint(charlie, 5n);287 await collectionFT.mint(charlie, 5n);288 await collectionFT.transfer(charlie, targetToken.nestingAddress(), 2n);288 await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);289 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(7n);289 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);290 });290 });291291292 // ---------- Re-Fungible ----------292 // ---------- Re-Fungible ----------297 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});297 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});298298299 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});299 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});300 await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());300 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());301301302 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});302 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});303 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});303 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});304 await collectionRFT.addToAllowList(alice, targetToken.nestingAddress());304 await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());305305306 // Create an immediately nested token306 // Create an immediately nested token307 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAddress());307 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());308 expect(await nestedToken.getBalance(targetToken.nestingAddress())).to.be.equal(5n);308 expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);309309310 // Create a token to be nested and nest310 // Create a token to be nested and nest311 const newToken = await collectionRFT.mintToken(charlie, 5n);311 const newToken = await collectionRFT.mintToken(charlie, 5n);312 await newToken.transfer(charlie, targetToken.nestingAddress(), 2n);312 await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);313 expect(await newToken.getBalance(targetToken.nestingAddress())).to.be.equal(2n);313 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);314 });314 });315315316 itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {316 itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {320320321 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});321 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});322 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});322 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});323 await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());323 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());324324325 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});325 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});326 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});326 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});327 await collectionRFT.addToAllowList(alice, targetToken.nestingAddress());327 await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());328328329 // Create an immediately nested token329 // Create an immediately nested token330 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAddress());330 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());331 expect(await nestedToken.getBalance(targetToken.nestingAddress())).to.be.equal(5n);331 expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);332332333 // Create a token to be nested and nest333 // Create a token to be nested and nest334 const newToken = await collectionRFT.mintToken(charlie, 5n);334 const newToken = await collectionRFT.mintToken(charlie, 5n);335 await newToken.transfer(charlie, targetToken.nestingAddress(), 2n);335 await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);336 expect(await newToken.getBalance(targetToken.nestingAddress())).to.be.equal(2n);336 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);337 });337 });338});338});339339356356357 // Create a nested-token matryoshka357 // Create a nested-token matryoshka358 for (let i = 0; i < maxNestingLevel; i++) {358 for (let i = 0; i < maxNestingLevel; i++) {359 token = await collection.mintToken(alice, token.nestingAddress());359 token = await collection.mintToken(alice, token.nestingAccount());360 }360 }361361362 // The nesting depth is limited by `maxNestingLevel`362 // The nesting depth is limited by `maxNestingLevel`363 await expect(collection.mintToken(alice, token.nestingAddress()))363 await expect(collection.mintToken(alice, token.nestingAccount()))364 .to.be.rejectedWith(/structure\.DepthLimit/);364 .to.be.rejectedWith(/structure\.DepthLimit/);365 expect(await token.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});365 expect(await token.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});366 expect(await token.getChildren()).to.be.length(0);366 expect(await token.getChildren()).to.be.length(0);374 const targetToken = await collection.mintToken(alice);374 const targetToken = await collection.mintToken(alice);375375376 // Try to create an immediately nested token as collection admin when it's disallowed376 // Try to create an immediately nested token as collection admin when it's disallowed377 await expect(collection.mintToken(bob, targetToken.nestingAddress()))377 await expect(collection.mintToken(bob, targetToken.nestingAccount()))378 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);378 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);379379380 // Try to create a token to be nested and nest380 // Try to create a token to be nested and nest390 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});390 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});391 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});391 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});392 await collection.addToAllowList(alice, {Substrate: bob.address});392 await collection.addToAllowList(alice, {Substrate: bob.address});393 await collection.addToAllowList(alice, targetToken.nestingAddress());393 await collection.addToAllowList(alice, targetToken.nestingAccount());394394395 // Try to create a nested token as token owner when it's disallowed395 // Try to create a nested token as token owner when it's disallowed396 await expect(collection.mintToken(bob, targetToken.nestingAddress()))396 await expect(collection.mintToken(bob, targetToken.nestingAccount()))397 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);397 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);398398399 // Try to create a token to be nested and nest399 // Try to create a token to be nested and nest410 //await collection.addAdmin(alice, {Substrate: bob.address});410 //await collection.addAdmin(alice, {Substrate: bob.address});411 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});411 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});412 await collection.addToAllowList(alice, {Substrate: bob.address});412 await collection.addToAllowList(alice, {Substrate: bob.address});413 await collection.addToAllowList(alice, targetToken.nestingAddress());413 await collection.addToAllowList(alice, targetToken.nestingAccount());414414415 // Try to nest somebody else's token415 // Try to nest somebody else's token416 const newToken = await collection.mintToken(bob);416 const newToken = await collection.mintToken(bob);417 await expect(newToken.nest(alice, targetToken))417 await expect(newToken.nest(alice, targetToken))418 .to.be.rejectedWith(/common\.NoPermission/);418 .to.be.rejectedWith(/common\.NoPermission/);419419420 // Try to unnest a token belonging to someone else as collection admin420 // Try to unnest a token belonging to someone else as collection admin421 const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());421 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());422 await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))422 await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))423 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);423 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);424424425 expect(await targetToken.getChildren()).to.be.length(1);425 expect(await targetToken.getChildren()).to.be.length(1);426 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});426 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});427 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());427 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());428 });428 });429429430 itSub('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async ({helper}) => {430 itSub('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async ({helper}) => {434 const targetToken = await collectionA.mintToken(alice);434 const targetToken = await collectionA.mintToken(alice);435435436 // Try to create a nested token from another collection436 // Try to create a nested token from another collection437 await expect(collectionB.mintToken(alice, targetToken.nestingAddress()))437 await expect(collectionB.mintToken(alice, targetToken.nestingAccount()))438 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);438 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);439439440 // Create a token in another collection yet to be nested and try to nest440 // Create a token in another collection yet to be nested and try to nest454 const targetToken = await collection.mintToken(alice);454 const targetToken = await collection.mintToken(alice);455455456 // Try to create a nested token as token owner when it's disallowed456 // Try to create a nested token as token owner when it's disallowed457 await expect(collection.mintToken(alice, targetToken.nestingAddress()))457 await expect(collection.mintToken(alice, targetToken.nestingAccount()))458 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);458 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);459459460 // Try to create a token to be nested and nest460 // Try to create a token to be nested and nest472472473 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});473 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});474 await collection.addToAllowList(alice, {Substrate: bob.address});474 await collection.addToAllowList(alice, {Substrate: bob.address});475 await collection.addToAllowList(alice, targetToken.nestingAddress());475 await collection.addToAllowList(alice, targetToken.nestingAccount());476476477 // Try to create a token to be nested and nest477 // Try to create a token to be nested and nest478 const newToken = await collection.mintToken(alice);478 const newToken = await collection.mintToken(alice);488488489 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});489 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});490 await collection.addToAllowList(alice, {Substrate: bob.address});490 await collection.addToAllowList(alice, {Substrate: bob.address});491 await collection.addToAllowList(alice, targetToken.nestingAddress());491 await collection.addToAllowList(alice, targetToken.nestingAccount());492492493 const collectionB = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true}});493 const collectionB = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true}});494 await collectionB.addToAllowList(alice, {Substrate: bob.address});494 await collectionB.addToAllowList(alice, {Substrate: bob.address});495 await collectionB.addToAllowList(alice, targetToken.nestingAddress());495 await collectionB.addToAllowList(alice, targetToken.nestingAccount());496496497 // Try to create a token to be nested and nest497 // Try to create a token to be nested and nest498 const newToken = await collectionB.mintToken(alice);498 const newToken = await collectionB.mintToken(alice);508 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});508 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});509509510 await collection.addToAllowList(alice, {Substrate: bob.address});510 await collection.addToAllowList(alice, {Substrate: bob.address});511 await collection.addToAllowList(alice, targetToken.nestingAddress());511 await collection.addToAllowList(alice, targetToken.nestingAccount());512512513 // Try to mint in own collection after allowlisting the accounts513 // Try to mint in own collection after allowlisting the accounts514 await expect(collection.mintToken(bob, targetToken.nestingAddress()))514 await expect(collection.mintToken(bob, targetToken.nestingAccount()))515 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);515 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);516 });516 });517517523 const targetToken = await collectionNFT.mintToken(alice);523 const targetToken = await collectionNFT.mintToken(alice);524524525 // Try to create an immediately nested token525 // Try to create an immediately nested token526 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAddress()))526 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))527 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);527 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);528528529 // Try to create a token to be nested and nest529 // Try to create a token to be nested and nest530 await collectionFT.mint(alice, 5n);530 await collectionFT.mint(alice, 5n);531 await expect(collectionFT.transfer(alice, targetToken.nestingAddress(), 2n))531 await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 2n))532 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);532 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);533 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);533 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);534 });534 });539 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});539 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});540540541 // Nest some tokens as Alice into Bob's token541 // Nest some tokens as Alice into Bob's token542 await collectionFT.mint(alice, 5n, targetToken.nestingAddress());542 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());543543544 // Try to pull it out544 // Try to pull it out545 await expect(collectionFT.transferFrom(alice, targetToken.nestingAddress(), {Substrate: bob.address}, 1n))545 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))546 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);546 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);547 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(5n);547 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);548 });548 });549549550 itSub('Fungible: disallows a non-Owner to unnest someone else\'s token (Restricted nesting)', async ({helper}) => {550 itSub('Fungible: disallows a non-Owner to unnest someone else\'s token (Restricted nesting)', async ({helper}) => {555 await collectionNFT.setPermissions(alice, {nesting: {collectionAdmin: true, tokenOwner: true, restricted: [collectionFT.collectionId]}});555 await collectionNFT.setPermissions(alice, {nesting: {collectionAdmin: true, tokenOwner: true, restricted: [collectionFT.collectionId]}});556556557 // Nest some tokens as Alice into Bob's token557 // Nest some tokens as Alice into Bob's token558 await collectionFT.mint(alice, 5n, targetToken.nestingAddress());558 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());559559560 // Try to pull it out as Alice still560 // Try to pull it out as Alice still561 await expect(collectionFT.transferFrom(alice, targetToken.nestingAddress(), {Substrate: bob.address}, 1n))561 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))562 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);562 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);563 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(5n);563 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);564 });564 });565565566 itSub('Fungible: disallows to nest token in an unlisted collection', async ({helper}) => {566 itSub('Fungible: disallows to nest token in an unlisted collection', async ({helper}) => {569 const targetToken = await collectionNFT.mintToken(alice);569 const targetToken = await collectionNFT.mintToken(alice);570570571 // Try to mint an immediately nested token571 // Try to mint an immediately nested token572 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAddress()))572 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))573 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);573 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);574574575 // Mint a token and try to nest it575 // Mint a token and try to nest it576 await collectionFT.mint(alice, 5n);576 await collectionFT.mint(alice, 5n);577 await expect(collectionFT.transfer(alice, targetToken.nestingAddress(), 1n))577 await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 1n))578 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);578 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);579579580 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(0n);580 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);581 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);581 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);582 });582 });583583589 const targetToken = await collectionNFT.mintToken(alice);589 const targetToken = await collectionNFT.mintToken(alice);590590591 // Try to create an immediately nested token591 // Try to create an immediately nested token592 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAddress()))592 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))593 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);593 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);594594595 // Try to create a token to be nested and nest595 // Try to create a token to be nested and nest596 const token = await collectionRFT.mintToken(alice, 5n);596 const token = await collectionRFT.mintToken(alice, 5n);597 await expect(token.transfer(alice, targetToken.nestingAddress(), 2n))597 await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))598 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);598 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);599 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);599 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);600 });600 });606606607 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});607 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});608 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});608 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});609 await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());609 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());610610611 // Try to create a token to be nested and nest611 // Try to create a token to be nested and nest612 const newToken = await collectionRFT.mintToken(alice);612 const newToken = await collectionRFT.mintToken(alice);613 await expect(newToken.transfer(bob, targetToken.nestingAddress())).to.be.rejectedWith(/common\.TokenValueTooLow/);613 await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);614614615 expect(await targetToken.getChildren()).to.be.length(0);615 expect(await targetToken.getChildren()).to.be.length(0);616 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);616 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);617617618 // Nest some tokens as Alice into Bob's token618 // Nest some tokens as Alice into Bob's token619 await newToken.transfer(alice, targetToken.nestingAddress());619 await newToken.transfer(alice, targetToken.nestingAccount());620620621 // Try to pull it out621 // Try to pull it out622 await expect(newToken.transferFrom(bob, targetToken.nestingAddress(), {Substrate: alice.address}, 1n))622 await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))623 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);623 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);624 expect(await newToken.getBalance(targetToken.nestingAddress())).to.be.equal(1n);624 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);625 });625 });626626627 itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {627 itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {631631632 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});632 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});633 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});633 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});634 await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());634 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());635635636 // Try to create a token to be nested and nest636 // Try to create a token to be nested and nest637 const newToken = await collectionRFT.mintToken(alice);637 const newToken = await collectionRFT.mintToken(alice);638 await expect(newToken.transfer(bob, targetToken.nestingAddress())).to.be.rejectedWith(/common\.TokenValueTooLow/);638 await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);639639640 expect(await targetToken.getChildren()).to.be.length(0);640 expect(await targetToken.getChildren()).to.be.length(0);641 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);641 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);642642643 // Nest some tokens as Alice into Bob's token643 // Nest some tokens as Alice into Bob's token644 await newToken.transfer(alice, targetToken.nestingAddress());644 await newToken.transfer(alice, targetToken.nestingAccount());645645646 // Try to pull it out646 // Try to pull it out647 await expect(newToken.transferFrom(bob, targetToken.nestingAddress(), {Substrate: alice.address}, 1n))647 await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))648 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);648 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);649 expect(await newToken.getBalance(targetToken.nestingAddress())).to.be.equal(1n);649 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);650 });650 });651651652 itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {652 itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {655 const targetToken = await collectionNFT.mintToken(alice);655 const targetToken = await collectionNFT.mintToken(alice);656656657 // Try to create an immediately nested token657 // Try to create an immediately nested token658 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAddress()))658 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))659 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);659 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);660660661 // Try to create a token to be nested and nest661 // Try to create a token to be nested and nest662 const token = await collectionRFT.mintToken(alice, 5n);662 const token = await collectionRFT.mintToken(alice, 5n);663 await expect(token.transfer(alice, targetToken.nestingAddress(), 2n))663 await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))664 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);664 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);665 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);665 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);666 });666 });tests/src/nesting/properties.test.tsdiffbeforeafterboth651 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});651 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});652 const collectionB = await helper.nft.mintCollection(alice);652 const collectionB = await helper.nft.mintCollection(alice);653 const targetToken = await collectionA.mintToken(alice);653 const targetToken = await collectionA.mintToken(alice);654 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAddress());654 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());655655656 await collectionB.addAdmin(alice, {Substrate: bob.address});656 await collectionB.addAdmin(alice, {Substrate: bob.address});657 await targetToken.transfer(alice, {Substrate: charlie.address});657 await targetToken.transfer(alice, {Substrate: charlie.address});692 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});692 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});693 const collectionB = await helper.nft.mintCollection(alice);693 const collectionB = await helper.nft.mintCollection(alice);694 const targetToken = await collectionA.mintToken(alice);694 const targetToken = await collectionA.mintToken(alice);695 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAddress());695 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());696696697 await collectionB.addAdmin(alice, {Substrate: bob.address});697 await collectionB.addAdmin(alice, {Substrate: bob.address});698 await targetToken.transfer(alice, {Substrate: charlie.address});698 await targetToken.transfer(alice, {Substrate: charlie.address});739 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});739 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});740 const collectionB = await helper.nft.mintCollection(alice);740 const collectionB = await helper.nft.mintCollection(alice);741 const targetToken = await collectionA.mintToken(alice);741 const targetToken = await collectionA.mintToken(alice);742 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAddress());742 const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());743743744 await collectionB.addAdmin(alice, {Substrate: bob.address});744 await collectionB.addAdmin(alice, {Substrate: bob.address});745 await targetToken.transfer(alice, {Substrate: charlie.address});745 await targetToken.transfer(alice, {Substrate: charlie.address});tests/src/nesting/unnest.test.tsdiffbeforeafterboth32 const targetToken = await collection.mintToken(alice);32 const targetToken = await collection.mintToken(alice);33 33 34 // Create a nested token34 // Create a nested token35 const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());35 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());363637 // Unnest37 // Unnest38 await expect(nestedToken.transferFrom(alice, targetToken.nestingAddress(), {Substrate: alice.address}), 'while unnesting').to.be.fulfilled;38 await expect(nestedToken.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}), 'while unnesting').to.be.fulfilled;39 expect(await nestedToken.getOwner()).to.be.deep.equal({Substrate: alice.address});39 expect(await nestedToken.getOwner()).to.be.deep.equal({Substrate: alice.address});404041 // Nest and burn41 // Nest and burn42 await nestedToken.nest(alice, targetToken);42 await nestedToken.nest(alice, targetToken);43 await expect(nestedToken.burnFrom(alice, targetToken.nestingAddress()), 'while burning').to.be.fulfilled;43 await expect(nestedToken.burnFrom(alice, targetToken.nestingAccount()), 'while burning').to.be.fulfilled;44 await expect(nestedToken.getOwner()).to.be.rejected;44 await expect(nestedToken.getOwner()).to.be.rejected;45 });45 });464651 const collectionFT = await helper.ft.mintCollection(alice);51 const collectionFT = await helper.ft.mintCollection(alice);52 52 53 // Nest and unnest53 // Nest and unnest54 await collectionFT.mint(alice, 10n, targetToken.nestingAddress());54 await collectionFT.mint(alice, 10n, targetToken.nestingAccount());55 await expect(collectionFT.transferFrom(alice, targetToken.nestingAddress(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;55 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;56 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(9n);56 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(9n);57 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(1n);57 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(1n);585859 // Nest and burn59 // Nest and burn60 await collectionFT.transfer(alice, targetToken.nestingAddress(), 5n);60 await collectionFT.transfer(alice, targetToken.nestingAccount(), 5n);61 await expect(collectionFT.burnTokensFrom(alice, targetToken.nestingAddress(), 6n), 'while burning').to.be.fulfilled;61 await expect(collectionFT.burnTokensFrom(alice, targetToken.nestingAccount(), 6n), 'while burning').to.be.fulfilled;62 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(4n);62 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(4n);63 expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(0n);63 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);64 expect(await targetToken.getChildren()).to.be.length(0);64 expect(await targetToken.getChildren()).to.be.length(0);65 });65 });666671 const collectionRFT = await helper.rft.mintCollection(alice);71 const collectionRFT = await helper.rft.mintCollection(alice);72 72 73 // Nest and unnest73 // Nest and unnest74 const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAddress());74 const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAccount());75 await expect(token.transferFrom(alice, targetToken.nestingAddress(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;75 await expect(token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;76 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(9n);76 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(9n);77 expect(await token.getBalance(targetToken.nestingAddress())).to.be.equal(1n);77 expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(1n);787879 // Nest and burn79 // Nest and burn80 await token.transfer(alice, targetToken.nestingAddress(), 5n);80 await token.transfer(alice, targetToken.nestingAccount(), 5n);81 await expect(token.burnFrom(alice, targetToken.nestingAddress(), 6n), 'while burning').to.be.fulfilled;81 await expect(token.burnFrom(alice, targetToken.nestingAccount(), 6n), 'while burning').to.be.fulfilled;82 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(4n);82 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(4n);83 expect(await token.getBalance(targetToken.nestingAddress())).to.be.equal(0n);83 expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);84 expect(await targetToken.getChildren()).to.be.length(0);84 expect(await targetToken.getChildren()).to.be.length(0);85 });85 });86});86});101 const targetToken = await collection.mintToken(alice);101 const targetToken = await collection.mintToken(alice);102102103 // Create a nested token103 // Create a nested token104 const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());104 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());105105106 // Try to unnest106 // Try to unnest107 await expect(nestedToken.unnest(bob, targetToken, {Substrate: alice.address})).to.be.rejectedWith(/common\.ApprovedValueTooLow/);107 await expect(nestedToken.unnest(bob, targetToken, {Substrate: alice.address})).to.be.rejectedWith(/common\.ApprovedValueTooLow/);108 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());108 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());109109110 // Try to burn110 // Try to burn111 await expect(nestedToken.burnFrom(bob, targetToken.nestingAddress())).to.be.rejectedWith(/common\.ApprovedValueTooLow/);111 await expect(nestedToken.burnFrom(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.ApprovedValueTooLow/);112 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());112 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());113 });113 });114114115 // todo another test for creating excessive depth matryoshka with Ethereum?115 // todo another test for creating excessive depth matryoshka with Ethereum?120 const targetToken = await collection.mintToken(alice);120 const targetToken = await collection.mintToken(alice);121121122 // Fail to create a nested token ouroboros122 // Fail to create a nested token ouroboros123 const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());123 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());124 await expect(targetToken.nest(alice, nestedToken)).to.be.rejectedWith(/^structure\.OuroborosDetected$/);124 await expect(targetToken.nest(alice, nestedToken)).to.be.rejectedWith(/^structure\.OuroborosDetected$/);125 });125 });126});126});tests/src/util/playgrounds/types.tsdiffbeforeafterboth109export interface IToken {109export interface IToken {110 collectionId: number;110 collectionId: number;111 tokenId: number;111 tokenId: number;112 //nestingAddress: () => {Ethereum: string};113}112}114113115export interface IBlock {114export interface IBlock {tests/src/util/playgrounds/unique.tsdiffbeforeafterboth55 RPC: 'rpc',55 RPC: 'rpc',56 };56 };575758 static getNestingTokenAddress(token: IToken) {58 static getTokenAccount(token: IToken) {59 return {Ethereum: this.getNestingTokenAddressRaw(token).toLowerCase()};59 return {Ethereum: this.getTokenAddress(token).toLowerCase()};60 }60 }616162 static getNestingTokenAddressRaw(token: IToken) {62 static getTokenAddress(token: IToken) {63 return nesting.tokenIdToAddress(token.collectionId, token.tokenId);63 return nesting.tokenIdToAddress(token.collectionId, token.tokenId);64 }64 }65651370 * @returns ```true``` if extrinsic success, otherwise ```false```1370 * @returns ```true``` if extrinsic success, otherwise ```false```1371 */1371 */1372 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken): Promise<boolean> {1372 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken): Promise<boolean> {1373 const rootTokenAddress = this.helper.util.getNestingTokenAddress(rootTokenObj);1373 const rootTokenAddress = this.helper.util.getTokenAccount(rootTokenObj);1374 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);1374 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);1375 if(!result) {1375 if(!result) {1376 throw Error('Unable to nest token!');1376 throw Error('Unable to nest token!');1388 * @returns ```true``` if extrinsic success, otherwise ```false```1388 * @returns ```true``` if extrinsic success, otherwise ```false```1389 */1389 */1390 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId): Promise<boolean> {1390 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId): Promise<boolean> {1391 const rootTokenAddress = this.helper.util.getNestingTokenAddress(rootTokenObj);1391 const rootTokenAddress = this.helper.util.getTokenAccount(rootTokenObj);1392 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);1392 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);1393 if(!result) {1393 if(!result) {1394 throw Error('Unable to unnest token!');1394 throw Error('Unable to unnest token!');2566 return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys);2566 return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys);2567 }2567 }256825682569 nestingAddress() {2569 nestingAccount() {2570 return this.collection.helper.util.getNestingTokenAddress(this);2570 return this.collection.helper.util.getTokenAccount(this);2571 }2571 }2572}2572}25732573