difftreelog
Tests refactoring WIP
in: master
4 files changed
tests/src/nesting/nest.test.tsdiffbeforeafterboth28 });28 });29 });29 });303031 /// TODO move31 itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {32 itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {32 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const targetToken = await collection.mintToken(alice);34 const targetToken = await collection.mintToken(alice);58 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});59 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});59 });60 });6061 itSub('Transfers an already bundled token', async ({helper}) => {62 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});63 const tokenA = await collection.mintToken(alice);64 const tokenB = await collection.mintToken(alice);6566 // Create a nested token67 const tokenC = await collection.mintToken(alice, tokenA.nestingAccount());68 expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());6970 // Transfer the nested token to another token71 await expect(tokenC.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount())).to.be.fulfilled;72 expect(await tokenC.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});73 expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());74 });7576 itSub('Checks token children', async ({helper}) => {77 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});78 const collectionB = await helper.ft.mintCollection(alice);7980 const targetToken = await collectionA.mintToken(alice);81 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');8283 // Create a nested NFT token84 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());85 expect(await targetToken.getChildren()).to.have.deep.members([86 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},87 ], 'Children contents check at nesting #1').and.be.length(1, 'Children length check at nesting #1');8889 // Create then nest90 const tokenB = await collectionA.mintToken(alice);91 await tokenB.nest(alice, targetToken);92 expect(await targetToken.getChildren()).to.have.deep.members([93 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},94 {tokenId: tokenB.tokenId, collectionId: collectionA.collectionId},95 ], 'Children contents check at nesting #2').and.be.length(2, 'Children length check at nesting #2');9697 // Move token B to a different user outside the nesting tree98 await tokenB.unnest(alice, targetToken, {Substrate: bob.address});99 expect(await targetToken.getChildren()).to.be.have.deep.members([100 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},101 ], 'Children contents check at nesting #3 (unnesting)').and.be.length(1, 'Children length check at nesting #3 (unnesting)');102103 // Create a fungible token in another collection and then nest104 await collectionB.mint(alice, 10n);105 await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);106 expect(await targetToken.getChildren()).to.be.have.deep.members([107 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},108 {tokenId: 0, collectionId: collectionB.collectionId},109 ], 'Children contents check at nesting #4 (from another collection)')110 .and.be.length(2, 'Children length check at nesting #4 (from another collection)');111112 // Move part of the fungible token inside token A deeper in the nesting tree113 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);114 expect(await targetToken.getChildren()).to.be.have.deep.members([115 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},116 {tokenId: 0, collectionId: collectionB.collectionId},117 ], 'Children contents check at nesting #5 (deeper)').and.be.length(2, 'Children length check at nesting #5 (deeper)');118 expect(await tokenA.getChildren()).to.be.have.deep.members([119 {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)');121122 // Move the remaining part of the fungible token inside token A deeper in the nesting tree123 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);124 expect(await targetToken.getChildren()).to.be.have.deep.members([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)');127 expect(await tokenA.getChildren()).to.be.have.deep.members([128 {tokenId: 0, collectionId: collectionB.collectionId},129 ], 'Children contents check at nesting #6.5 (deeper)').and.be.length(1, 'Children length check at nesting #6.5 (deeper)');130 });131});61});13262133describe('Integration Test: Various token type nesting', () => {63describe('Integration Test: Various token type nesting', () => {tests/src/sub/nesting/common.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';19import {UniqueNFTCollection, UniqueRFTCollection} from '../../util/playgrounds/unique';19import {UniqueNFTCollection, UniqueRFTCollection} from '../../util/playgrounds/unique';20import {itEth} from '../../eth/util';212022describe('Nesting', () => {23 let alice: IKeyringPair;21let alice: IKeyringPair;242225 before(async () => {23before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {24 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = await privateKey({filename: __filename});25 const donor = await privateKey({filename: __filename});28 [alice] = await helper.arrange.createAccounts([50n], donor);26 [alice] = await helper.arrange.createAccounts([100n], donor);29 });30 });27 });28});312932 [30[33 {mode: 'nft' as const, requiredPallets: []},31 {mode: 'nft' as const, requiredPallets: []},34 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},32 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},35 ].map(testCase => {33].map(testCase => {36 itSub.ifWithPallets(`Owner can nest ${testCase.mode.toUpperCase()}`, testCase.requiredPallets, async ({helper}) => {34 itSub.ifWithPallets(`Owner can nest ${testCase.mode.toUpperCase()} in NFT`, testCase.requiredPallets, async ({helper}) => {37 // Only NFT allows nesting, permissions should be set:38 const aliceNFTCollection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});39 const targetToken = await aliceNFTCollection.mintToken(alice);4041 const collectionForNesting = await helper[testCase.mode].mintCollection(alice);4243 // 1. Alice can immediately create nested token:44 const nestedToken1 = testCase.mode === 'nft'45 ? await (collectionForNesting as UniqueNFTCollection).mintToken(alice, targetToken.nestingAccount())46 : await (collectionForNesting as UniqueRFTCollection).mintToken(alice, 10n, targetToken.nestingAccount());47 expect(await nestedToken1.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});48 expect(await nestedToken1.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());4950 // 2. Alice can mint and nest token:51 const nestedToken2 = await collectionForNesting.mintToken(alice);52 await nestedToken2.nest(alice, targetToken);53 expect(await nestedToken2.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});54 expect(await nestedToken2.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());55 });56 });5758 itSub('Owner can nest FT', async ({helper}) => {59 // Only NFT allows nesting, permissions should be set:35 // Only NFT allows nesting, permissions should be set:60 const aliceNFTCollection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});36 const aliceNFTCollection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});61 const targetToken = await aliceNFTCollection.mintToken(alice);37 const targetToken = await aliceNFTCollection.mintToken(alice);623863 const collectionForNesting = await helper.ft.mintCollection(alice);39 const collectionForNesting = await helper[testCase.mode].mintCollection(alice);644065 // 1. Alice can immediately create nested tokens:41 // 1. Alice can immediately create nested token:66 await collectionForNesting.mint(alice, 100n, targetToken.nestingAccount());42 const nestedToken1 = testCase.mode === 'nft'43 ? await (collectionForNesting as UniqueNFTCollection).mintToken(alice, targetToken.nestingAccount())44 : await (collectionForNesting as UniqueRFTCollection).mintToken(alice, 10n, targetToken.nestingAccount());67 expect(await collectionForNesting.getTop10Owners()).deep.eq([targetToken.nestingAccount().toLowerCase()]);45 expect(await nestedToken1.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});68 expect(await collectionForNesting.getBalance(targetToken.nestingAccount())).eq(100n);46 expect(await nestedToken1.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());694770 // 2. Alice can mint and nest token:48 // 2. Alice can mint and nest token:71 await collectionForNesting.mint(alice, 100n);49 const nestedToken2 = await collectionForNesting.mintToken(alice);72 await collectionForNesting.transfer(alice, targetToken.nestingAccount(), 50n);50 await nestedToken2.nest(alice, targetToken);51 expect(await nestedToken2.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});73 expect(await collectionForNesting.getBalance(targetToken.nestingAccount())).eq(150n);52 expect(await nestedToken2.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());74 });53 });75});54});765577describe('Nesting negative', () => {78 let alice: IKeyringPair;795680 before(async () => {57itSub('Owner can nest FT in NFT', async ({helper}) => {81 await usingPlaygrounds(async (helper, privateKey) => {82 const donor = await privateKey({filename: __filename});58 // Only NFT allows nesting, permissions should be set:83 [alice] = await helper.arrange.createAccounts([50n], donor);59 const aliceNFTCollection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});84 });85 });60 const targetToken = await aliceNFTCollection.mintToken(alice);866187 [62 const collectionForNesting = await helper.ft.mintCollection(alice);88 {mode: 'nft' as const, requiredPallets: []},89 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},90 ].map(testCase => {91 itSub.ifWithPallets(`Owner cannot nest ${testCase.mode.toUpperCase()} if nesting not allowed`, testCase.requiredPallets, async ({helper}) => {92 // Create default collection, permissions are not set:93 const aliceNFTCollection = await helper.nft.mintCollection(alice);94 const targetToken = await aliceNFTCollection.mintToken(alice);956396 const collectionForNesting = await helper[testCase.mode].mintCollection(alice);64 // 1. Alice can immediately create nested tokens:65 await collectionForNesting.mint(alice, 100n, targetToken.nestingAccount());66 expect(await collectionForNesting.getTop10Owners()).deep.eq([targetToken.nestingAccount().toLowerCase()]);67 expect(await collectionForNesting.getBalance(targetToken.nestingAccount())).eq(100n);976898 // 1. Alice cannot create immediately nested tokens:69 // 2. Alice can mint and nest token:99 const nestingTx = testCase.mode === 'nft'70 await collectionForNesting.mint(alice, 100n);100 ? (collectionForNesting as UniqueNFTCollection).mintToken(alice, targetToken.nestingAccount())71 await collectionForNesting.transfer(alice, targetToken.nestingAccount(), 50n);101 : (collectionForNesting as UniqueRFTCollection).mintToken(alice, 10n, targetToken.nestingAccount());72 expect(await collectionForNesting.getBalance(targetToken.nestingAccount())).eq(150n);102 await expect(nestingTx).to.be.rejectedWith('common.UserIsNotAllowedToNest');73});10374104 // 2. Alice cannot mint and nest token:105 const nestedToken2 = await collectionForNesting.mintToken(alice);106 await expect(nestedToken2.nest(alice, targetToken)).to.be.rejectedWith('common.UserIsNotAllowedToNest');107 });108 });10975110 itSub('Owner cannot nest FT if nesting not allowed', async ({helper}) => {76itSub.ifWithPallets('Owner can transferFrom nested tokens', [Pallets.ReFungible], async ({helper}) => {111 // Create default collection, permissions are not set:77 const collectionToNest = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});112 const aliceNFTCollection = await helper.nft.mintCollection(alice);78 const tokenA = await collectionToNest.mintToken(alice);113 const targetToken = await aliceNFTCollection.mintToken(alice);79 const tokenB = await collectionToNest.mintToken(alice);11480115 const collectionForNesting = await helper.ft.mintCollection(alice);81 // Create a nested token82 const nftCollectionToBeNested = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});83 const rftCollectionToBeNested = await helper.rft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});84 const ftCollectionToBeNested = await helper.ft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});11685117 // 1. Alice cannot create immediately nested tokens:86 const nestedNFT = await nftCollectionToBeNested.mintToken(alice, tokenA.nestingAccount());87 const nestedRFT = await rftCollectionToBeNested.mintToken(alice, 100n, tokenA.nestingAccount());118 await expect(collectionForNesting.mint(alice, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest');88 const _nestedFT = await ftCollectionToBeNested.mint(alice, 100n, tokenA.nestingAccount());89 expect(await nestedNFT.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());90 expect(await nestedRFT.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());91 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);11992120 // 2. Alice can mint and nest token:93 // Transfer the nested token to another token121 await collectionForNesting.mint(alice, 100n);94 await nestedNFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount());122 await expect(collectionForNesting.transfer(alice, targetToken.nestingAccount(), 50n)).to.be.rejectedWith('common.UserIsNotAllowedToNest');95 await nestedRFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);123 });96 await ftCollectionToBeNested.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);12497125 itSub.ifWithPallets('Cannot nest to a future collection', [Pallets.ReFungible], async ({helper}) => {98 expect(await nestedNFT.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});126 const nonExistingCollectionId = await helper.collection.getTotalCount() + 1000;99 expect(await nestedNFT.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());127 const futureToken = helper.nft.getTokenObject(nonExistingCollectionId, 1);128100129 const nftCollectionForNesting = await helper.nft.mintCollection(alice);101 expect(await nestedRFT.getBalance(tokenB.nestingAccount())).to.equal(25n);130 const rftCollectionForNesting = await helper.rft.mintCollection(alice);131 const ftCollectionForNesting = await helper.ft.mintCollection(alice);102 expect(await nestedRFT.getBalance(tokenA.nestingAccount())).to.equal(75n);132103133 // 1. Alice cannot create nested token to future token104 expect(await ftCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);134 await expect(nftCollectionForNesting.mintToken(alice, futureToken.nestingAccount())).to.be.rejectedWith('CollectionNotFound');105 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);135 await expect(rftCollectionForNesting.mintToken(alice, 10n, futureToken.nestingAccount())).to.be.rejectedWith('CollectionNotFound');136 await expect(ftCollectionForNesting.mint(alice, 10n, futureToken.nestingAccount())).to.be.rejectedWith('CollectionNotFound');137138 // 2. Alice cannot mint and nest token:139 const nft = await nftCollectionForNesting.mintToken(alice);140 const rft = await rftCollectionForNesting.mintToken(alice, 100n);141 const _ft = await ftCollectionForNesting.mint(alice, 100n);142 await expect(nft.transfer(alice, futureToken.nestingAccount())).to.be.rejectedWith('CollectionNotFound');143 await expect(rft.transfer(alice, futureToken.nestingAccount())).to.be.rejectedWith('CollectionNotFound');144 await expect(ftCollectionForNesting.transfer(alice, futureToken.nestingAccount(), 50n)).to.be.rejectedWith('CollectionNotFound');145 });146147 itSub.ifWithPallets('Cannot nest to a future token in a NFT collection', [Pallets.ReFungible], async ({helper}) => {148 const {collectionId} = await helper.nft.mintCollection(alice);149 // To avoid UserIsNotAllowedToNest error150 await helper.collection.setPermissions(alice, collectionId, {nesting: {collectionAdmin: true}});151 const futureToken = helper.nft.getTokenObject(collectionId, 1);152153 const nftCollectionForNesting = await helper.nft.mintCollection(alice);154 const rftCollectionForNesting = await helper.rft.mintCollection(alice);155 const ftCollectionForNesting = await helper.ft.mintCollection(alice);156157 // 1. Alice cannot create nested token to future token158 await expect(nftCollectionForNesting.mintToken(alice, futureToken.nestingAccount())).to.be.rejectedWith('TokenNotFound');159 await expect(rftCollectionForNesting.mintToken(alice, 10n, futureToken.nestingAccount())).to.be.rejectedWith('TokenNotFound');160 await expect(ftCollectionForNesting.mint(alice, 10n, futureToken.nestingAccount())).to.be.rejectedWith('TokenNotFound');161162 // 2. Alice cannot mint and nest token:163 const nft = await nftCollectionForNesting.mintToken(alice);164 const rft = await rftCollectionForNesting.mintToken(alice, 100n);165 const _ft = await ftCollectionForNesting.mint(alice, 100n);166 await expect(nft.transfer(alice, futureToken.nestingAccount())).to.be.rejectedWith('TokenNotFound');167 await expect(rft.transfer(alice, futureToken.nestingAccount())).to.be.rejectedWith('TokenNotFound');168 await expect(ftCollectionForNesting.transfer(alice, futureToken.nestingAccount(), 50n)).to.be.rejectedWith('TokenNotFound');169 });170171 itEth.ifWithPallets('Cannot nest to collection address', [Pallets.ReFungible], async({helper}) => {172 const existingCollection = await helper.nft.mintCollection(alice);173 const existingCollectionAddress = helper.ethAddress.fromCollectionId(existingCollection.collectionId);174 const futureCollectionAddress = helper.ethAddress.fromCollectionId(99999999);175176 const nftCollectionForNesting = await helper.nft.mintCollection(alice);177178 // 1. Alice cannot create nested token to collection address179 await expect(nftCollectionForNesting.mintToken(alice, {Ethereum: existingCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');180 await expect(nftCollectionForNesting.mintToken(alice, {Ethereum: futureCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');181182 // 2. Alice cannot mint and nest token to collection address:183 const nft = await nftCollectionForNesting.mintToken(alice);184 await expect(nft.transfer(alice, {Ethereum: existingCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');185 await expect(nft.transfer(alice, {Ethereum: futureCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');186 });187188 itEth.ifWithPallets('Cannot nest in RFT or FT', [Pallets.ReFungible], async ({helper}) => {189 // Create default collection, permissions are not set:190 const rftCollection = await helper.rft.mintCollection(alice);191 const ftCollection = await helper.ft.mintCollection(alice);192193 const rftToken = await rftCollection.mintToken(alice);194 const _ftToken = await ftCollection.mint(alice, 100n);195196 const collectionForNesting = await helper.nft.mintCollection(alice);197198 // 1. Alice cannot create immediately nested tokens:199 await expect(collectionForNesting.mintToken(alice, rftToken.nestingAccount())).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');200 await expect(collectionForNesting.mintToken(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');201202 // 2. Alice cannot mint and nest token:203 const nestedToken2 = await collectionForNesting.mintToken(alice);204 await expect(nestedToken2.nest(alice, rftToken)).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');205 await expect(ftCollection.transfer(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');206 });207});106});208107tests/src/sub/nesting/e2e.test.tsdiffbeforeafterbothno changes
tests/src/sub/nesting/negative.test.tsdiffbeforeafterbothno changes