git.delta.rocks / unique-network / refs/commits / 2dd0a6af978d

difftreelog

add sub tests for nesting

Trubnikov Sergey2023-05-05parent: #bea0737.patch.diff
in: master

8 files changed

deletedtests/src/NativeFungible.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/nativeFungible.test.tsdiffbeforeafterboth
117 expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;117 expect(balanceOwnerBefore - 50n > balanceOwnerAfter).to.be.true;
118 expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;118 expect(balanceReceiverBefore === balanceReceiverAfter - 50n).to.be.true;
119119
120 await expect(contract.methods.transferFrom(receiver, receiver, 50).call({from: owner})).to.be.rejectedWith('no permission');120 await expect(contract.methods.transferFrom(receiver, receiver, 50).call({from: owner})).to.be.rejectedWith('ApprovedValueTooLow');
121 });121 });
122});122});
123123
addedtests/src/nativeFungible.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/nesting/unnest.test.tsdiffbeforeafterboth
47 await expect(nestedToken.getOwner()).to.be.rejected;47 await expect(nestedToken.getOwner()).to.be.rejected;
48 });48 });
49
50 itSub('NativeFungible: allows the owner to successfully unnest a token', async ({helper}) => {
51 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
52 const targetToken = await collection.mintToken(alice);
53
54 const collectionFT = helper.ft.getCollectionObject(0);
55
56 // Nest
57 await collectionFT.transfer(alice, targetToken.nestingAccount(), 10n);
58 // Unnest
59 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;
60
61 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
62 });
4963
50 itSub('Fungible: allows the owner to successfully unnest a token', async ({helper}) => {64 itSub('Fungible: allows the owner to successfully unnest a token', async ({helper}) => {
51 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});65 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
modifiedtests/src/sub/nesting/common.test.tsdiffbeforeafterboth
88 });88 });
89});89});
90
91[
92 {restrictedMode: true},
93 {restrictedMode: false},
94].map(testCase => {
95 itSub(`Token owner can nest Native FT in NFT if "tokenOwner" permission set ${testCase.restrictedMode ? 'in restricted mode': ''}`, async ({helper}) => {
96 // Only NFT allows nesting, permissions should be set:
97 const targetNFTCollection = await helper.nft.mintCollection(alice);
98 const targetTokenBob = await targetNFTCollection.mintToken(alice, {Substrate: bob.address});
99
100 const collectionForNesting = helper.ft.getCollectionObject(0);
101 // permissions should be set:
102 await targetNFTCollection.setPermissions(alice, {
103 nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionForNesting.collectionId] : null},
104 });
105
106 // Alice can mint and nest token:
107 await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);
108 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(50n);
109 });
110});
90111
91112
92itSub.ifWithPallets('Owner can unnest tokens using transferFrom', [Pallets.ReFungible], async ({helper}) => {113itSub.ifWithPallets('Owner can unnest tokens using transferFrom', [Pallets.ReFungible], async ({helper}) => {
98 const nftCollectionToBeNested = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});119 const nftCollectionToBeNested = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
99 const rftCollectionToBeNested = await helper.rft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});120 const rftCollectionToBeNested = await helper.rft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
100 const ftCollectionToBeNested = await helper.ft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});121 const ftCollectionToBeNested = await helper.ft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
122 const nativeFtCollectionToBeNested = helper.ft.getCollectionObject(0);
101123
102 const nestedNFT = await nftCollectionToBeNested.mintToken(alice, tokenA.nestingAccount());124 const nestedNFT = await nftCollectionToBeNested.mintToken(alice, tokenA.nestingAccount());
103 const nestedRFT = await rftCollectionToBeNested.mintToken(alice, 100n, tokenA.nestingAccount());125 const nestedRFT = await rftCollectionToBeNested.mintToken(alice, 100n, tokenA.nestingAccount());
104 const _nestedFT = await ftCollectionToBeNested.mint(alice, 100n, tokenA.nestingAccount());126 const _nestedFT = await ftCollectionToBeNested.mint(alice, 100n, tokenA.nestingAccount());
127 await nativeFtCollectionToBeNested.transfer(alice, tokenA.nestingAccount(), 100n);
105 expect(await nestedNFT.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());128 expect(await nestedNFT.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());
106 expect(await nestedRFT.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());129 expect(await nestedRFT.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());
107 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);130 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);
131 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);
108132
109 // Transfer the nested token to another token133 // Transfer the nested token to another token
110 await nestedNFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount());134 await nestedNFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount());
111 await nestedRFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);135 await nestedRFT.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);
112 await ftCollectionToBeNested.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);136 await ftCollectionToBeNested.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);
137 await nativeFtCollectionToBeNested.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount(), 25n);
113138
114 expect(await nestedNFT.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});139 expect(await nestedNFT.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});
115 expect(await nestedNFT.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());140 expect(await nestedNFT.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());
120 expect(await ftCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);145 expect(await ftCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);
121 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);146 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);
147
148 expect(await nativeFtCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);
149 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);
122});150});
123151
modifiedtests/src/sub/nesting/e2e.test.tsdiffbeforeafterboth
32 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);
3536
36 const targetToken = await collectionA.mintToken(alice);37 const targetToken = await collectionA.mintToken(alice);
37 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');
73 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},74 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},
74 ]).and.has.length(3);75 ]).and.has.length(3);
76
77 // Nest native fungible token into another collection
78 await collectionD.transfer(alice, targetToken.nestingAccount(), 2n);
79 expect(await targetToken.getChildren()).to.have.deep.members([
80 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},
81 {tokenId: 0, collectionId: collectionB.collectionId},
82 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},
83 {tokenId: 0, collectionId: collectionD.collectionId},
84 ]).and.has.length(4);
7585
76 // Burn all nested pieces86 // Burn all nested pieces
77 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);87 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);
78 expect(await targetToken.getChildren()).to.have.deep.members([88 expect(await targetToken.getChildren()).to.have.deep.members([
79 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},89 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},
80 {tokenId: 0, collectionId: collectionB.collectionId},90 {tokenId: 0, collectionId: collectionB.collectionId},
91 {tokenId: 0, collectionId: collectionD.collectionId},
81 ])92 ])
82 .and.has.length(2);93 .and.has.length(3);
8394
84 // Move part of the fungible token inside token A deeper in the nesting tree95 // Move part of the fungible token inside token A deeper in the nesting tree
85 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);96 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);
86 expect(await targetToken.getChildren()).to.be.have.deep.members([97 expect(await targetToken.getChildren()).to.be.have.deep.members([
87 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},98 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},
88 {tokenId: 0, collectionId: collectionB.collectionId},99 {tokenId: 0, collectionId: collectionB.collectionId},
100 {tokenId: 0, collectionId: collectionD.collectionId},
89 ]).and.has.length(2);101 ]).and.has.length(3);
90 // Nested token also has children now:102 // Nested token also has children now:
91 expect(await tokenA.getChildren()).to.have.deep.members([103 expect(await tokenA.getChildren()).to.have.deep.members([
92 {tokenId: 0, collectionId: collectionB.collectionId},104 {tokenId: 0, collectionId: collectionB.collectionId},
96 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);108 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);
97 expect(await targetToken.getChildren()).to.have.deep.members([109 expect(await targetToken.getChildren()).to.have.deep.members([
98 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},110 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},
111 {tokenId: 0, collectionId: collectionD.collectionId},
99 ]).and.has.length(1);112 ]).and.has.length(2);
100 expect(await tokenA.getChildren()).to.have.deep.members([113 expect(await tokenA.getChildren()).to.have.deep.members([
101 {tokenId: 0, collectionId: collectionB.collectionId},114 {tokenId: 0, collectionId: collectionB.collectionId},
102 ]).and.has.length(1);115 ]).and.has.length(1);
modifiedtests/src/sub/nesting/nesting.negative.test.tsdiffbeforeafterboth
53 });53 });
54});54});
5555
56[
57 {mode: 'ft'},
58 {mode: 'nativeFt'},
59].map(testCase => {
56itSub('Owner cannot nest FT if nesting is disabled', async ({helper}) => {60 itSub(`Owner cannot nest [${testCase.mode}] if nesting is disabled`, async ({helper}) => {
57 // Create default collection, permissions are not set:61 // Create default collection, permissions are not set:
58 const aliceNFTCollection = await helper.nft.mintCollection(alice);62 const aliceNFTCollection = await helper.nft.mintCollection(alice);
59 const targetToken = await aliceNFTCollection.mintToken(alice);63 const targetToken = await aliceNFTCollection.mintToken(alice);
6064
61 const collectionForNesting = await helper.ft.mintCollection(alice);65 const collectionForNesting = testCase.mode === 'ft' ? await helper.ft.mintCollection(alice) : helper.ft.getCollectionObject(0);
6266
63 // 1. Alice cannot create immediately nested tokens:67 // Alice cannot create immediately nested tokens:
64 await expect(collectionForNesting.mint(alice, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest');68 await expect(testCase.mode === 'ft'
69 ? collectionForNesting.mint(alice, 100n, targetToken.nestingAccount())
70 : collectionForNesting.transfer(alice, targetToken.nestingAccount(), 100n)).to.be.rejectedWith('common.UserIsNotAllowedToNest');
6571
66 // 2. Alice can mint and nest token:72 // Alice can mint and nest token:
73 if (testCase.mode === 'ft') {
67 await collectionForNesting.mint(alice, 100n);74 await collectionForNesting.mint(alice, 100n);
75 }
68 await expect(collectionForNesting.transfer(alice, targetToken.nestingAccount(), 50n)).to.be.rejectedWith('common.UserIsNotAllowedToNest');76 await expect(collectionForNesting.transfer(alice, targetToken.nestingAccount(), 50n)).to.be.rejectedWith('common.UserIsNotAllowedToNest');
69});77 });
78});
7079
71[80[
72 {mode: 'nft' as const},81 {mode: 'nft' as const},
73 {mode: 'rft' as const},82 {mode: 'rft' as const},
74 {mode: 'ft' as const},83 {mode: 'ft' as const},
84 {mode: 'native ft' as const},
75].map(testCase => {85].map(testCase => {
76 itSub(`Non-owner and non-admin cannot nest ${testCase.mode.toUpperCase()} in someone else's tokens`, async ({helper}) => {86 itSub(`Non-owner and non-admin cannot nest ${testCase.mode.toUpperCase()} in someone else's tokens`, async ({helper}) => {
77 const targetCollection = await helper.nft.mintCollection(alice, {permissions:87 const targetCollection = await helper.nft.mintCollection(alice, {permissions:
78 {nesting: {tokenOwner: true, collectionAdmin: true}},88 {nesting: {tokenOwner: true, collectionAdmin: true}},
79 });89 });
80 const targetToken = await targetCollection.mintToken(alice);90 const targetToken = await targetCollection.mintToken(alice);
8191
82 const nestedCollectionBob = await helper[testCase.mode].mintCollection(bob);92 const nestedCollectionBob = await (
93 testCase.mode === 'native ft'
94 ? helper.ft.getCollectionObject(0)
95 : helper[testCase.mode].mintCollection(bob)
96 );
8397
84 let nestedTokenBob: UniqueNFToken | UniqueRFToken;98 let nestedTokenBob: UniqueNFToken | UniqueRFToken;
85 switch (testCase.mode) {99 switch (testCase.mode) {
86 case 'nft': nestedTokenBob = await (nestedCollectionBob as UniqueNFTCollection).mintToken(bob); break;100 case 'nft': nestedTokenBob = await (nestedCollectionBob as UniqueNFTCollection).mintToken(bob); break;
87 case 'rft': nestedTokenBob = await (nestedCollectionBob as UniqueRFTCollection).mintToken(bob, 100n); break;101 case 'rft': nestedTokenBob = await (nestedCollectionBob as UniqueRFTCollection).mintToken(bob, 100n); break;
88 case 'ft': await (nestedCollectionBob as UniqueFTCollection).mint(bob, 100n); break;102 case 'ft': await (nestedCollectionBob as UniqueFTCollection).mint(bob, 100n); break;
103 case 'native ft': break;
89 }104 }
90105
91 // Bob non-owner of targetToken and non admin of targetCollection, so106 // Bob non-owner of targetToken and non admin of targetCollection, so
94 case 'nft': await expect((nestedCollectionBob as UniqueNFTCollection).mintToken(bob, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;109 case 'nft': await expect((nestedCollectionBob as UniqueNFTCollection).mintToken(bob, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
95 case 'rft': await expect((nestedCollectionBob as UniqueRFTCollection).mintToken(bob, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;110 case 'rft': await expect((nestedCollectionBob as UniqueRFTCollection).mintToken(bob, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
96 case 'ft': await expect((nestedCollectionBob as UniqueFTCollection).mint(bob, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;111 case 'ft': await expect((nestedCollectionBob as UniqueFTCollection).mint(bob, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
112 case 'native ft': break;
97 }113 }
98114
99 // 2. cannot nest existing token:115 // 2. cannot nest existing token:
100 switch (testCase.mode) {116 switch (testCase.mode) {
101 case 'nft':117 case 'nft':
102 case 'rft': await expect(nestedTokenBob!.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;118 case 'rft': await expect(nestedTokenBob!.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
103 case 'ft': await expect((nestedCollectionBob as UniqueFTCollection).transfer(bob, targetToken.nestingAccount(), 100n)).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;119 case 'ft': await expect((nestedCollectionBob as UniqueFTCollection).transfer(bob, targetToken.nestingAccount(), 100n)).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
120 case 'native ft': await expect((nestedCollectionBob as UniqueFTCollection).transfer(bob, targetToken.nestingAccount(), 100n)).to.be.rejectedWith('common.UserIsNotAllowedToNest'); break;
104 }121 }
105 });122 });
106});123});
140 const nftCollectionForNesting = await helper.nft.mintCollection(alice);157 const nftCollectionForNesting = await helper.nft.mintCollection(alice);
141 const rftCollectionForNesting = await helper.rft.mintCollection(alice);158 const rftCollectionForNesting = await helper.rft.mintCollection(alice);
142 const ftCollectionForNesting = await helper.ft.mintCollection(alice);159 const ftCollectionForNesting = await helper.ft.mintCollection(alice);
160 const nativeFtCollectionForNesting = helper.ft.getCollectionObject(0);
143161
144 const testCases = [162 const testCases = [
145 {token: tokenFromNonExistingCollection, error: 'CollectionNotFound'},163 {token: tokenFromNonExistingCollection, error: 'CollectionNotFound'},
160 await expect(nft.transfer(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);178 await expect(nft.transfer(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);
161 await expect(rft.transfer(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);179 await expect(rft.transfer(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);
162 await expect(ftCollectionForNesting.transfer(alice, testCase.token.nestingAccount(), 50n)).to.be.rejectedWith(testCase.error);180 await expect(ftCollectionForNesting.transfer(alice, testCase.token.nestingAccount(), 50n)).to.be.rejectedWith(testCase.error);
181 await expect(nativeFtCollectionForNesting.transfer(alice, testCase.token.nestingAccount(), 50n)).to.be.rejectedWith(testCase.error);
163 }182 }
164});183});
165184
184 // Create default collection, permissions are not set:203 // Create default collection, permissions are not set:
185 const rftCollection = await helper.rft.mintCollection(alice);204 const rftCollection = await helper.rft.mintCollection(alice);
186 const ftCollection = await helper.ft.mintCollection(alice);205 const ftCollection = await helper.ft.mintCollection(alice);
206 const nativeFtCollection = helper.ft.getCollectionObject(0);
187207
188 const rftToken = await rftCollection.mintToken(alice);208 const rftToken = await rftCollection.mintToken(alice);
189 const _ftToken = await ftCollection.mint(alice, 100n);209 const _ftToken = await ftCollection.mint(alice, 100n);
193 // 1. Alice cannot create immediately nested tokens:213 // 1. Alice cannot create immediately nested tokens:
194 await expect(collectionForNesting.mintToken(alice, rftToken.nestingAccount())).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');214 await expect(collectionForNesting.mintToken(alice, rftToken.nestingAccount())).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');
195 await expect(collectionForNesting.mintToken(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');215 await expect(collectionForNesting.mintToken(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');
216 await expect(collectionForNesting.mintToken(alice, {Ethereum: helper.ethAddress.fromTokenId(nativeFtCollection.collectionId, 0)})).to.be.rejectedWith('common.UnsupportedOperation');
196217
197 // 2. Alice cannot mint and nest token:218 // 2. Alice cannot mint and nest token:
198 const nestedToken2 = await collectionForNesting.mintToken(alice);219 const nestedToken2 = await collectionForNesting.mintToken(alice);
199 await expect(nestedToken2.nest(alice, rftToken)).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');220 await expect(nestedToken2.nest(alice, rftToken)).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');
200 await expect(ftCollection.transfer(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');221 await expect(ftCollection.transfer(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');
222 await expect(nativeFtCollection.transfer(alice, {Ethereum: helper.ethAddress.fromTokenId(nativeFtCollection.collectionId, 0)})).to.be.rejectedWith('common.UnsupportedOperation');
201});223});
202224
203itSub('Cannot nest in restricted collection if collection is not in the list', async ({helper}) => {225itSub('Cannot nest in restricted collection if collection is not in the list', async ({helper}) => {
204 const {collectionId: allowedCollectionId} = await helper.nft.mintCollection(alice);226 const {collectionId: allowedCollectionId} = await helper.nft.mintCollection(alice);
205 const notAllowedCollectionNFT = await helper.nft.mintCollection(alice);227 const notAllowedCollectionNFT = await helper.nft.mintCollection(alice);
206 const notAllowedCollectionRFT = await helper.rft.mintCollection(alice);228 const notAllowedCollectionRFT = await helper.rft.mintCollection(alice);
207 const notAllowedCollectionFT = await helper.ft.mintCollection(alice);229 const notAllowedCollectionFT = await helper.ft.mintCollection(alice);
230 const notAllowedCollectionNativeFT = helper.ft.getCollectionObject(0);
208231
209 // Collection restricted to allowedCollectionId232 // Collection restricted to allowedCollectionId
210 const restrictedCollectionA = await helper.nft.mintCollection(alice, {permissions:233 const restrictedCollectionA = await helper.nft.mintCollection(alice, {permissions:
229 await expect(notAllowedCollectionRFT.mintToken(alice, 100n, targetTokenB.nestingAccount())).to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);252 await expect(notAllowedCollectionRFT.mintToken(alice, 100n, targetTokenB.nestingAccount())).to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
230 await expect(notAllowedCollectionFT.mint(alice, 100n, targetTokenA.nestingAccount())).to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);253 await expect(notAllowedCollectionFT.mint(alice, 100n, targetTokenA.nestingAccount())).to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
231 await expect(notAllowedCollectionFT.mint(alice, 100n, targetTokenB.nestingAccount())).to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);254 await expect(notAllowedCollectionFT.mint(alice, 100n, targetTokenB.nestingAccount())).to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
255 await expect(notAllowedCollectionNativeFT.transfer(alice, targetTokenA.nestingAccount(), 100n)).to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
256 await expect(notAllowedCollectionNativeFT.transfer(alice, targetTokenB.nestingAccount(), 100n)).to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
232});257});
233258
234itSub('Cannot create nesting chains greater than 5', async ({helper}) => {259itSub('Cannot create nesting chains greater than 5', async ({helper}) => {
modifiedtests/src/sub/nesting/unnesting.negative.test.tsdiffbeforeafterboth
52 });52 });
5353
54 [54 [
55 {restrictedMode: true},55 {mode: 'ft' as const},
56 {restrictedMode: false},56 {mode: 'native ft' as const},
57 ].map(testCase => {57 ].map(md => [
58 {mode: md.mode, restrictedMode: true},
59 {mode: md.mode, restrictedMode: false},
60 ].map(testCase => {
58 itSub(`Fungible: disallows a non-Owner to unnest someone else's token ${testCase.restrictedMode ? '(Restricted nesting)' : ''}`, async ({helper}) => {61 itSub.only(`Fungible: disallows a non-Owner to unnest someone else's token [${testCase.mode}${testCase.restrictedMode ? ' (Restricted nesting)' : ''}]`, async ({helper}) => {
59 const collectionNFT = await helper.nft.mintCollection(alice);62 const collectionNFT = await helper.nft.mintCollection(alice);
60 const collectionFT = await helper.ft.mintCollection(alice);63 const collectionFT = await (
64 testCase.mode === 'ft'
65 ? helper.ft.mintCollection(alice)
66 : helper.ft.getCollectionObject(0)
67 );
61 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});68 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});
6269
63 await collectionNFT.setPermissions(alice, {nesting: {70 await collectionNFT.setPermissions(alice, {nesting: {
64 collectionAdmin: true, tokenOwner: true, restricted: testCase.restrictedMode ? [collectionFT.collectionId] : null,71 collectionAdmin: true, tokenOwner: true, restricted: testCase.restrictedMode ? [collectionFT.collectionId] : null,
65 }});72 }});
6673
67 // Nest some tokens as Alice into Bob's token74 // Nest some tokens as Alice into Bob's token
68 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());75 await (
76 testCase.mode === 'ft'
77 ? collectionFT.mint(alice, 5n, targetToken.nestingAccount())
78 : collectionFT.transfer(alice, targetToken.nestingAccount(), 5n)
79 );
6980
70 // Try to pull it out as Alice still81 // Try to pull it out as Alice still
71 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))82 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))
72 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);83 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
73 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);84 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
74 });85 });
75 });86 }));
76});87});
7788