difftreelog
test(sub/nesting) children checking + orderliness
in: master
6 files changed
tests/package.jsondiffbeforeafterboth39 "testParallelFull": "yarn testParallel && yarn testSequential",39 "testParallelFull": "yarn testParallel && yarn testSequential",40 "testParallel": "yarn _testParallel './src/**/*.test.ts'",40 "testParallel": "yarn _testParallel './src/**/*.test.ts'",41 "testSequential": "yarn _test './src/**/*.seqtest.ts'",41 "testSequential": "yarn _test './src/**/*.seqtest.ts'",42 "testStructure": "yarn setup && yarn _test ./**/nesting/*.*test.ts",42 "testStructure": "yarn _test ./**/nesting/*.*test.ts",43 "testEth": "yarn setup && yarn _test './**/eth/**/*.*test.ts'",43 "testEth": "yarn _test './**/eth/**/*.*test.ts'",44 "testEthNesting": "yarn setup && yarn _test './**/eth/nesting/**/*.*test.ts'",44 "testEthNesting": "yarn _test './**/eth/nesting/**/*.*test.ts'",45 "testEthFractionalizer": "yarn setup && yarn _test './**/eth/fractionalizer/**/*.*test.ts'",45 "testEthFractionalizer": "yarn _test './**/eth/fractionalizer/**/*.*test.ts'",46 "testEthMarketplace": "yarn setup && yarn _test './**/eth/marketplace/**/*.*test.ts'",46 "testEthMarketplace": "yarn _test './**/eth/marketplace/**/*.*test.ts'",47 "testSub": "yarn _test './**/sub/**/*.*test.ts'",48 "testSubNesting": "yarn _test './**/sub/nesting/**/*.*test.ts'",47 "testEvent": "yarn setup && yarn _test ./src/check-event/*.*test.ts",49 "testEvent": "yarn _test ./src/check-event/*.*test.ts",48 "testEthPayable": "yarn _test './**/eth/payable.test.ts'",50 "testEthPayable": "yarn _test './**/eth/payable.test.ts'",49 "testEvmCoder": "yarn _test './**/eth/evmCoder.test.ts'",51 "testEvmCoder": "yarn _test './**/eth/evmCoder.test.ts'",50 "testNesting": "yarn _test ./**/nest.test.ts",52 "testNesting": "yarn _test ./**/nest.test.ts",tests/src/sub/nesting/admin.test.tsdiffbeforeafterboth17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '../../util';18import {expect, itSub, usingPlaygrounds} from '../../util';191920describe('Collection admin', () => {20describe('Nesting by collection admin', () => {21 let alice: IKeyringPair;21 let alice: IKeyringPair;22 let bob: IKeyringPair;22 let bob: IKeyringPair;23 let charlie: IKeyringPair;23 let charlie: IKeyringPair;tests/src/sub/nesting/common.test.tsdiffbeforeafterboth21let alice: IKeyringPair;21let alice: IKeyringPair;22let bob: IKeyringPair;22let bob: IKeyringPair;232324before(async () => {24describe('Common nesting tests', () => {25 await usingPlaygrounds(async (helper, privateKey) => {25 before(async () => {26 const donor = await privateKey({url: import.meta.url});26 await usingPlaygrounds(async (helper, privateKey) => {27 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);27 const donor = await privateKey({url: import.meta.url});28 });28 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);29});29 });3030 });31[3132 {mode: 'nft' as const, restrictedMode: true, requiredPallets: []},32 [33 {mode: 'nft' as const, restrictedMode: false, requiredPallets: []},33 {mode: 'nft' as const, restrictedMode: true, requiredPallets: []},34 {mode: 'rft' as const, restrictedMode: true, requiredPallets: [Pallets.ReFungible]},34 {mode: 'nft' as const, restrictedMode: false, requiredPallets: []},35 {mode: 'rft' as const, restrictedMode: false, requiredPallets: [Pallets.ReFungible]},35 {mode: 'rft' as const, restrictedMode: true, requiredPallets: [Pallets.ReFungible]},36].map(testCase => {36 {mode: 'rft' as const, restrictedMode: false, requiredPallets: [Pallets.ReFungible]},37 itSub.ifWithPallets(`Token owner can nest ${testCase.mode.toUpperCase()} in NFT if "tokenOwner" permission set ${testCase.restrictedMode ? 'in restricted mode': ''}`, testCase.requiredPallets, async ({helper}) => {37 ].map(testCase => {38 // Only NFT can be target for nesting in38 itSub.ifWithPallets(`Token owner can nest ${testCase.mode.toUpperCase()} in NFT if "tokenOwner" permission set ${testCase.restrictedMode ? 'in restricted mode': ''}`, testCase.requiredPallets, async ({helper}) => {39 const targetNFTCollection = await helper.nft.mintCollection(alice);39 // Only NFT can be target for nesting in40 const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});40 const targetNFTCollection = await helper.nft.mintCollection(alice);4141 const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});42 const collectionForNesting = await helper[testCase.mode].mintCollection(bob);4243 // permissions should be set:43 const collectionForNesting = await helper[testCase.mode].mintCollection(bob);44 await targetNFTCollection.setPermissions(alice, {44 // permissions should be set:45 nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},45 await targetNFTCollection.setPermissions(alice, {46 });46 nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},4747 });48 // 1. Bob can immediately create nested token:4849 const nestedToken1 = testCase.mode === 'nft'49 // 1. Bob can immediately create nested token:50 ? await (collectionForNesting as UniqueNFTCollection).mintToken(bob, targetTokenBob.nestingAccount())50 const nestedToken1 = testCase.mode === 'nft'51 : await (collectionForNesting as UniqueRFTCollection).mintToken(bob, 10n, targetTokenBob.nestingAccount());51 ? await (collectionForNesting as UniqueNFTCollection).mintToken(bob, targetTokenBob.nestingAccount())52 expect(await nestedToken1.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});52 : await (collectionForNesting as UniqueRFTCollection).mintToken(bob, 10n, targetTokenBob.nestingAccount());53 expect(await nestedToken1.getOwner()).to.be.deep.equal(targetTokenBob.nestingAccount().toLowerCase());53 expect(await nestedToken1.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});5454 expect(await nestedToken1.getOwner()).to.be.deep.equal(targetTokenBob.nestingAccount().toLowerCase());55 // 2. Bob can mint and nest token:5556 const nestedToken2 = await collectionForNesting.mintToken(bob);56 // 2. Bob can mint and nest token:57 await nestedToken2.nest(bob, targetTokenBob);57 const nestedToken2 = await collectionForNesting.mintToken(bob);58 expect(await nestedToken2.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});58 await nestedToken2.nest(bob, targetTokenBob);59 expect(await nestedToken2.getOwner()).to.be.deep.equal(targetTokenBob.nestingAccount().toLowerCase());59 expect(await nestedToken2.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});60 });60 expect(await nestedToken2.getOwner()).to.be.deep.equal(targetTokenBob.nestingAccount().toLowerCase());61});61 });6262 });636364[6465 {restrictedMode: true},65 [66 {restrictedMode: false},66 {restrictedMode: true},67].map(testCase => {67 {restrictedMode: false},68 itSub(`Token owner can nest FT in NFT if "tokenOwner" permission set ${testCase.restrictedMode ? 'in restricted mode': ''}`, async ({helper}) => {68 ].map(testCase => {69 // Only NFT allows nesting, permissions should be set:69 itSub(`Token owner can nest FT in NFT if "tokenOwner" permission set ${testCase.restrictedMode ? 'in restricted mode': ''}`, async ({helper}) => {70 const targetNFTCollection = await helper.nft.mintCollection(alice);70 // Only NFT allows nesting, permissions should be set:71 const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});71 const targetNFTCollection = await helper.nft.mintCollection(alice);7272 const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});73 const collectionForNesting = await helper.ft.mintCollection(bob);7374 // permissions should be set:74 const collectionForNesting = await helper.ft.mintCollection(bob);75 await targetNFTCollection.setPermissions(alice, {75 // permissions should be set:76 nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},76 await targetNFTCollection.setPermissions(alice, {77 });77 nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},7878 });79 // 1. Alice can immediately create nested tokens:7980 await collectionForNesting.mint(bob, 100n, targetTokenBob.nestingAccount());80 // 1. Alice can immediately create nested tokens:81 expect(await collectionForNesting.getTop10Owners()).deep.eq([targetTokenBob.nestingAccount().toLowerCase()]);81 await collectionForNesting.mint(bob, 100n, targetTokenBob.nestingAccount());82 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(100n);82 expect(await collectionForNesting.getTop10Owners()).deep.eq([targetTokenBob.nestingAccount().toLowerCase()]);8383 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(100n);84 // 2. Alice can mint and nest token:8485 await collectionForNesting.mint(bob, 100n);85 // 2. Alice can mint and nest token:86 await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);86 await collectionForNesting.mint(bob, 100n);87 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(150n);87 await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);88 });88 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(150n);89});89 expect(await targetTokenBob.getChildren()).to.be.deep.equal([{collectionId: collectionForNesting.collectionId, tokenId: 0}]);9090 });91[91 });92 {restrictedMode: true},9293 {restrictedMode: false},93 [94].map(testCase => {94 {restrictedMode: true},95 itSub(`Token owner can nest Native FT in NFT if "tokenOwner" permission set ${testCase.restrictedMode ? 'in restricted mode': ''}`, async ({helper}) => {95 {restrictedMode: false},96 // Only NFT allows nesting, permissions should be set:96 ].map(testCase => {97 const targetNFTCollection = await helper.nft.mintCollection(alice);97 itSub(`Token owner can nest Native FT in NFT if "tokenOwner" permission set ${testCase.restrictedMode ? 'in restricted mode': ''}`, async ({helper}) => {98 const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});98 // Only NFT allows nesting, permissions should be set:9999 const targetNFTCollection = await helper.nft.mintCollection(alice);100 const collectionForNesting = helper.ft.getCollectionObject(0);100 const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});101 // permissions should be set:101 expect(await targetTokenBob.getChildren()).to.be.empty;102 await targetNFTCollection.setPermissions(alice, {102103 nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},103 const collectionForNesting = helper.ft.getCollectionObject(0);104 });104 // permissions should be set:105105 await targetNFTCollection.setPermissions(alice, {106 // Bob can nest Native FT into their NFT:106 nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},107 await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);107 });108 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(50n);108109 });109 // Bob can nest Native FT into their NFT:110});110 await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);111 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(50n);112 expect(await targetTokenBob.getChildren()).to.be.deep.equal([{collectionId: 0, tokenId: 0}]);113 });114 });111115112116113itSub.ifWithPallets('Owner can unnest tokens using transferFrom', [Pallets.ReFungible], async ({helper}) => {117 itSub.ifWithPallets('Owner can unnest tokens using transferFrom', [Pallets.ReFungible], async ({helper}) => {130 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);134 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);131 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);135 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);136137 expect(await tokenA.getChildren()).to.be.length(4);138 expect(await tokenB.getChildren()).to.be.length(0);132139133 // Transfer the nested token to another token140 // Transfer the nested token to another token134 await nestedNFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount());141 await nestedNFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount());148 expect(await nativeFtCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);155 expect(await nativeFtCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);149 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);156 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);157158 // RFT, FT, and native FT159 expect(await tokenA.getChildren()).to.be.length(3);160 // NFT, RFT, FT, and native FT161 expect(await tokenB.getChildren()).to.be.length(4);150});162 });163});151164tests/src/sub/nesting/e2e.test.tsdiffbeforeafterboth32 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});32 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const collectionB = await helper.ft.mintCollection(alice);33 const collectionB = await helper.ft.mintCollection(alice);34 const collectionC = await helper.rft.mintCollection(alice);34 const collectionC = await helper.rft.mintCollection(alice);35 const collectionD = helper.ft.getCollectionObject(0);35 const collectionNative = helper.ft.getCollectionObject(0);363637 const targetToken = await collectionA.mintToken(alice);37 const targetToken = await collectionA.mintToken(alice);38 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');38 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');75 ]).and.has.length(3);75 ]).and.has.length(3);767677 // Nest native fungible token into another collection77 // Nest native fungible token into another collection78 await collectionD.transfer(alice, targetToken.nestingAccount(), 2n);78 await collectionNative.transfer(alice, targetToken.nestingAccount(), 2n);79 expect(await targetToken.getChildren()).to.have.deep.members([79 expect(await targetToken.getChildren()).to.have.deep.members([80 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},80 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},81 {tokenId: 0, collectionId: collectionB.collectionId},81 {tokenId: 0, collectionId: collectionB.collectionId},82 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},82 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},83 {tokenId: 0, collectionId: collectionD.collectionId},83 {tokenId: 0, collectionId: collectionNative.collectionId},84 ]).and.has.length(4);84 ]).and.has.length(4);858586 // Burn all nested pieces86 // Burn all nested pieces87 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);87 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);88 expect(await targetToken.getChildren()).to.have.deep.members([88 expect(await targetToken.getChildren()).to.have.deep.members([89 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},89 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},90 {tokenId: 0, collectionId: collectionB.collectionId},90 {tokenId: 0, collectionId: collectionB.collectionId},91 {tokenId: 0, collectionId: collectionD.collectionId},91 {tokenId: 0, collectionId: collectionNative.collectionId},92 ])92 ])93 .and.has.length(3);93 .and.has.length(3);949497 expect(await targetToken.getChildren()).to.be.have.deep.members([97 expect(await targetToken.getChildren()).to.be.have.deep.members([98 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},98 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},99 {tokenId: 0, collectionId: collectionB.collectionId},99 {tokenId: 0, collectionId: collectionB.collectionId},100 {tokenId: 0, collectionId: collectionD.collectionId},100 {tokenId: 0, collectionId: collectionNative.collectionId},101 ]).and.has.length(3);101 ]).and.has.length(3);102 // Nested token also has children now:102 // Nested token also has children now:103 expect(await tokenA.getChildren()).to.have.deep.members([103 expect(await tokenA.getChildren()).to.have.deep.members([108 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);108 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);109 expect(await targetToken.getChildren()).to.have.deep.members([109 expect(await targetToken.getChildren()).to.have.deep.members([110 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},110 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},111 {tokenId: 0, collectionId: collectionD.collectionId},111 {tokenId: 0, collectionId: collectionNative.collectionId},112 ]).and.has.length(2);112 ]).and.has.length(2);113 expect(await tokenA.getChildren()).to.have.deep.members([113 expect(await tokenA.getChildren()).to.have.deep.members([114 {tokenId: 0, collectionId: collectionB.collectionId},114 {tokenId: 0, collectionId: collectionB.collectionId},tests/src/sub/nesting/nesting.negative.test.tsdiffbeforeafterboth23let bob: IKeyringPair;23let bob: IKeyringPair;24let charlie: IKeyringPair;24let charlie: IKeyringPair;252526describe('Negative Test: Nesting', () => {26before(async () => {27 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = await privateKey({url: import.meta.url});29 const donor = await privateKey({url: import.meta.url});283 expect(await token.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});284 expect(await token.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});284 expect(await token.getChildren()).to.has.length(0);285 expect(await token.getChildren()).to.has.length(0);285});286 });287});286288tests/src/sub/nesting/refungible.test.tsdiffbeforeafterboth17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from '../../util';18import {expect, itSub, Pallets, usingPlaygrounds} from '../../util';191920// ReFungible specific nesting tests20describe('ReFungible-specific nesting tests', () => {21let alice: IKeyringPair;21 let alice: IKeyringPair;222223before(async () => {23 before(async () => {585859 expect(await rft.getTopmostOwner()).deep.equal({Substrate: alice.address});59 expect(await rft.getTopmostOwner()).deep.equal({Substrate: alice.address});60});60 });61});6162