git.delta.rocks / unique-network / refs/commits / 903c7da37bfa

difftreelog

test(sub/nesting) children checking + orderliness

Fahrrader2023-05-17parent: #a8ddb93.patch.diff
in: master

6 files changed

modifiedtests/package.jsondiffbeforeafterboth
39 "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",
modifiedtests/src/sub/nesting/admin.test.tsdiffbeforeafterboth
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {expect, itSub, usingPlaygrounds} from '../../util';18import {expect, itSub, usingPlaygrounds} from '../../util';
1919
20describe('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;
modifiedtests/src/sub/nesting/common.test.tsdiffbeforeafterboth
21let alice: IKeyringPair;21let alice: IKeyringPair;
22let bob: IKeyringPair;22let bob: IKeyringPair;
2323
24before(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[31
32 {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 in
40 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);42
43 // 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:48
49 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:55
56 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 });
6363
64[64
65 {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);73
74 // 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:79
80 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:84
85 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},92
93 {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, {102
103 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);108
109 });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 });
111115
112116
113itSub.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);
136
137 expect(await tokenA.getChildren()).to.be.length(4);
138 expect(await tokenB.getChildren()).to.be.length(0);
132139
133 // Transfer the nested token to another token140 // Transfer the nested token to another token
134 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);
157
158 // RFT, FT, and native FT
159 expect(await tokenA.getChildren()).to.be.length(3);
160 // NFT, RFT, FT, and native FT
161 expect(await tokenB.getChildren()).to.be.length(4);
150});162 });
163});
151164
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);35 const collectionNative = helper.ft.getCollectionObject(0);
3636
37 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);
7676
77 // Nest native fungible token into another collection77 // Nest native fungible token into another collection
78 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);
8585
86 // Burn all nested pieces86 // Burn all nested pieces
87 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);
9494
97 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},
modifiedtests/src/sub/nesting/nesting.negative.test.tsdiffbeforeafterboth
23let bob: IKeyringPair;23let bob: IKeyringPair;
24let charlie: IKeyringPair;24let charlie: IKeyringPair;
2525
26describe('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});
286288
modifiedtests/src/sub/nesting/refungible.test.tsdiffbeforeafterboth
17import {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';
1919
20// ReFungible specific nesting tests20describe('ReFungible-specific nesting tests', () => {
21let alice: IKeyringPair;21 let alice: IKeyringPair;
2222
23before(async () => {23 before(async () => {
5858
59 expect(await rft.getTopmostOwner()).deep.equal({Substrate: alice.address});59 expect(await rft.getTopmostOwner()).deep.equal({Substrate: alice.address});
60});60 });
61});
6162