difftreelog
test(structure) refactor properties and nesting
in: master
7 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -33,7 +33,9 @@
"loadTransfer": "ts-node src/transfer.nload.ts",
"testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",
"testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",
- "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
+ "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",
+ "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
+ "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
"testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",
"testMigrationStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
"testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
tests/src/nesting/graphs.test.tsdiffbeforeafterboth--- a/tests/src/nesting/graphs.test.ts
+++ b/tests/src/nesting/graphs.test.ts
@@ -14,7 +14,7 @@
* ```
*/
async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise<number> {
- const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT'}));
+ const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', limits: {nestingRule: 'Owner'}}));
const {collectionId} = getCreateCollectionResult(events);
await executeTransaction(api, sender, api.tx.unique.createMultipleItemsEx(collectionId, {NFT: Array(8).fill({owner: {Substrate: sender.address}})}));
@@ -32,20 +32,26 @@
return collectionId;
}
-describe('graphs', () => {
- it('ouroboros can\'t be created in graph', async () => {
+describe('Graphs', () => {
+ it('Ouroboros can\'t be created in a complex graph', async () => {
await usingApi(async api => {
const alice = privateKey('//Alice');
const collection = await buildComplexObjectGraph(api, alice);
// to self
- await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)))
- .to.be.rejectedWith(/structure\.OuroborosDetected/);
+ await expect(
+ executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)),
+ 'first transaction',
+ ).to.be.rejectedWith(/structure\.OuroborosDetected/);
// to nested part of graph
- await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)))
- .to.be.rejectedWith(/structure\.OuroborosDetected/);
- await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 8), collection, 2, 1)))
- .to.be.rejectedWith(/structure\.OuroborosDetected/);
+ await expect(
+ executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)),
+ 'second transaction',
+ ).to.be.rejectedWith(/structure\.OuroborosDetected/);
+ await expect(
+ executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 8), collection, 2, 1)),
+ 'third transaction',
+ ).to.be.rejectedWith(/structure\.OuroborosDetected/);
});
});
});
tests/src/nesting/migration-check.test.tsdiffbeforeafterboth--- a/tests/src/nesting/migration-check.test.ts
+++ b/tests/src/nesting/migration-check.test.ts
@@ -18,7 +18,7 @@
});
});
- it('Preserves collection settings', async () => {
+ it('Preserves collection settings after migration', async () => {
let oldVersion: number;
let collectionId: number;
let collectionOld: any;
@@ -71,6 +71,7 @@
});
} catch (_) {
connectionFailCounter++;
+ console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);
await new Promise(resolve => setTimeout(resolve, 12000));
}
}
tests/src/nesting/nest.test.tsdiffbeforeafterboth5import {5import {6 addToAllowListExpectSuccess,6 addToAllowListExpectSuccess,7 createCollectionExpectSuccess,7 createCollectionExpectSuccess,8 createItemExpectFailure, 9 createItemExpectSuccess,8 createItemExpectSuccess,10 enableAllowListExpectSuccess,9 enableAllowListExpectSuccess,11 enablePublicMintingExpectSuccess,10 enablePublicMintingExpectSuccess,12 getTokenOwner, 11 getTokenOwner, 13 getTopmostTokenOwner, 12 getTopmostTokenOwner, 13 normalizeAccountId, 14 setCollectionLimitsExpectSuccess, 14 setCollectionLimitsExpectSuccess, 15 transferExpectFailure, 15 transferExpectFailure, 16 transferExpectSuccess, 16 transferExpectSuccess, 29 });29 });30 });30 });313132 // ---------- Non-Fungible ----------3334 // todo refactor names35 // todo remove excessive bundling, leave it for a single test36 it('NFT: allows to nest/unnest token if nesting rule is Owner', async () => {32 it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {37 await usingApi(async api => {33 await usingApi(async api => {38 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});34 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});39 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});35 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});49 45 50 // Nest46 // Nest51 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});47 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});52 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});48 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});53 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});49 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});545055 // Move bundle to different user51 // Move bundle to different user56 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});52 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});63 });59 });64 });60 });6162 // ---------- Non-Fungible ----------6364 it('NFT: allows an Owner to nest/unnest their token', async () => {65 await usingApi(async api => {66 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});67 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});68 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');6970 // Create a nested token71 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});72 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});73 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});7475 // Create a token to be nested and nest76 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');77 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});78 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});79 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});80 });81 });658266 it('NFT: allows to nest/unnest token if Owner-Restricted', async () => {83 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {67 await usingApi(async api => {84 await usingApi(async api => {68 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});85 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});69 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});86 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});74 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});91 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});75 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});92 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});769377 // Create a token to be nested94 // Create a token to be nested and nest78 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');95 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');79 80 // Nest81 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});96 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});82 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});97 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});83 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});98 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});8485 // Move bundle to different user86 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});87 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});88 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});89 90 // Unnest91 await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});92 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});93 });99 });94 });100 });9510196 // ---------- Fungible ----------102 // ---------- Fungible ----------9710398 it('Fungible: allows to nest/unnest token if Owner', async () => {104 it('Fungible: allows an Owner to nest/unnest their token', async () => {99 await usingApi(async api => {105 await usingApi(async api => {100 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});106 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});101 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});107 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});111 {Fungible: {Value: 10}},117 {Fungible: {Value: 10}},112 ))).to.not.be.rejected;118 ))).to.not.be.rejected;113119114 // Create a token to be nested120 // Nest a new token115 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');121 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');116 // Nest117 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');122 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');118 // Move bundle to different user119 await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});120 // Unnest121 await transferFromExpectSuccess(collectionFT, newToken, bob, targetAddress, {Substrate: bob.address}, 1, 'Fungible');122 });123 });123 });124 });124125125 it('Fungible: allows to nest/unnest token if Owner-Restricted', async () => {126 it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {126 await usingApi(async api => {127 await usingApi(async api => {127 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});128 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});128 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});129 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});139 {Fungible: {Value: 10}},140 {Fungible: {Value: 10}},140 ))).to.not.be.rejected;141 ))).to.not.be.rejected;141142142 // Create a token to be nested143 // Nest a new token143 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');144 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');144 // Nest145 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');145 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');146 // Move bundle to different user147 await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});148 // Unnest149 await transferFromExpectSuccess(collectionFT, newToken, bob, targetAddress, {Substrate: bob.address}, 1, 'Fungible');150 });146 });151 });147 });152148153 // ---------- Re-Fungible ----------149 // ---------- Re-Fungible ----------154150155 it('ReFungible: allows to nest/unnest token if Owner', async () => {151 it('ReFungible: allows an Owner to nest/unnest their token', async () => {156 await usingApi(async api => {152 await usingApi(async api => {157 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});153 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});158 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});154 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});165 await expect(executeTransaction(api, alice, api.tx.unique.createItem(161 await expect(executeTransaction(api, alice, api.tx.unique.createItem(166 collectionRFT, 162 collectionRFT, 167 targetAddress, 163 targetAddress, 168 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},164 {ReFungible: {const_data: [], pieces: 100}},169 ))).to.not.be.rejected;165 ))).to.not.be.rejected;170166171 // Create a token to be nested167 // Nest a new token172 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');168 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');173 // Nest174 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');169 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');175 // Move bundle to different user176 await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});177 // Unnest178 await transferFromExpectSuccess(collectionRFT, newToken, bob, targetAddress, {Substrate: bob.address}, 100, 'ReFungible');179 });170 });180 });171 });181172182 it('ReFungible: allows to nest/unnest token if Owner-Restricted', async () => {173 it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {183 await usingApi(async api => {174 await usingApi(async api => {184 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});175 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});185 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});176 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});193 await expect(executeTransaction(api, alice, api.tx.unique.createItem(184 await expect(executeTransaction(api, alice, api.tx.unique.createItem(194 collectionRFT, 185 collectionRFT, 195 targetAddress,186 targetAddress,196 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},187 {ReFungible: {const_data: [], pieces: 100}},197 ))).to.not.be.rejected;188 ))).to.not.be.rejected;198189199 // Create a token to be nested190 // Nest a new token200 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');191 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');201 // Nest202 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');192 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');203 // Move bundle to different user204 await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});205 // Unnest206 await transferFromExpectSuccess(collectionRFT, newToken, bob, targetAddress, {Substrate: bob.address}, 100, 'ReFungible');207 });193 });208 });194 });209});195});216 });202 });217 });203 });204205 it('Disallows excessive token nesting', async () => {206 await usingApi(async api => {207 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});208 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});209 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');210211 // Create a nested-token matryoshka212 const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});213 const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});214 // The nesting depth is limited by 2215 await expect(executeTransaction(216 api, alice, 217 api.tx.unique.createItem(218 collection, 219 {Ethereum: tokenIdToAddress(collection, nestedToken2)}, 220 {nft: {const_data: [], variable_data: []}} as any,221 ),222 ), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/); // OuroborosDetected?223224 expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});225 });226 });218227219 // ---------- Non-Fungible ----------228 // ---------- Non-Fungible ----------220229230 {Ethereum: tokenIdToAddress(collection, targetToken)}, 241 {Ethereum: tokenIdToAddress(collection, targetToken)}, 231 {nft: {const_data: [], variable_data: []}} as any,242 {nft: {const_data: [], variable_data: []}} as any,232 ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);243 ),244 ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);233245234 // Create a token to be nested246 // Create a token to be nested235 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');247 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');236 // Try to nest248 // Try to nest237 await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)}); // todo to.be.rejected249 await expect(executeTransaction(250 api, alice, 251 api.tx.unique.transfer(252 normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,253 ),254 ), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/); // todo to.be.rejected for all238 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});255 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});239 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});256 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});240 });257 });241 });258 });242259243 it('NFT: disallows to nest token if not Owner', async () => {260 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {244 await usingApi(async api => {261 await usingApi(async api => {245 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});262 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});246 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});263 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});253 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');270 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');254271255 // Try to create a nested token in the wrong collection272 // Try to create a nested token in the wrong collection256 await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});273 await expect(executeTransaction(274 api, alice, 275 api.tx.unique.createItem(276 collection, 277 {Ethereum: tokenIdToAddress(collection, targetToken)}, 278 {nft: {const_data: [], variable_data: []}} as any,279 ),280 ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/); // todo NestingIsDisabled?257281258 // Try to create and nest a token in the wrong collection282 // Try to create and nest a token in the wrong collection259 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');283 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');260 await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});284 await expect(executeTransaction(285 api, alice, 286 api.tx.unique.transfer(287 normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,288 ),289 ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);261 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});290 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});262 });291 });263 });292 });264293265 it('NFT: disallows to nest token if not Owner (Restricted nesting)', async () => {294 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {266 await usingApi(async api => {295 await usingApi(async api => {267 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});296 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});268 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});297 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});275 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');304 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');276305277 // Try to create a nested token in the wrong collection306 // Try to create a nested token in the wrong collection278 await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});307 await expect(executeTransaction(308 api, alice, 309 api.tx.unique.createItem(310 collection, 311 {Ethereum: tokenIdToAddress(collection, targetToken)}, 312 {nft: {const_data: [], variable_data: []}} as any,313 ),314 ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);279315280 // Try to create and nest a token in the wrong collection316 // Try to create and nest a token in the wrong collection281 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');317 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');282 await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});318 await expect(executeTransaction(319 api, alice, 320 api.tx.unique.transfer(321 normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,322 ),323 ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);283 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});324 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});284 });325 });285 });326 });286327287 it('NFT: disallows to nest token to an unlisted collection', async () => {328 it('NFT: disallows to nest token in an unlisted collection', async () => {288 await usingApi(async api => {329 await usingApi(async api => {289 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});330 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});290 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});331 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});293 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');334 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');294335295 // Try to create a nested token in the wrong collection336 // Try to create a nested token in the wrong collection296 await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});337 await expect(executeTransaction(338 api, alice, 339 api.tx.unique.createItem(340 collection, 341 {Ethereum: tokenIdToAddress(collection, targetToken)}, 342 {nft: {const_data: [], variable_data: []}} as any,343 ),344 ), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);297345298 // Try to create and nest a token in the wrong collection346 // Try to create and nest a token in the wrong collection299 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');347 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');300 await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});348 await expect(executeTransaction(349 api, alice, 350 api.tx.unique.transfer(351 normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,352 ),353 ), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);301 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});354 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});302 });355 });303 });356 });319 targetAddress, 374 targetAddress, 320 {Fungible: {Value: 10}},375 {Fungible: {Value: 10}},321 ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);376 )377 ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);322378323 // Create a token to be nested379 // Create a token to be nested324 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');380 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');325 // Try to nest381 // Try to nest326 await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);382 await expect(executeTransaction(383 api, alice, 384 api.tx.unique.transfer(385 normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,386 ),387 ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);327 });388 });328 });389 });329390330 it('Fungible: disallows to nest token if not Owner', async () => {391 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {331 await usingApi(async api => {392 await usingApi(async api => {332 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});393 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});333 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});394 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});347 collectionFT, 410 collectionFT, 348 targetAddress, 411 targetAddress, 349 {Fungible: {Value: 10}},412 {Fungible: {Value: 10}},350 ))).to.be.rejected;413 )414 ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);351415352 // Try to create and nest a token in the wrong collection416 // Try to create and nest a token in the wrong collection353 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');417 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');354 await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);418 await expect(executeTransaction(419 api, alice, 420 api.tx.unique.transfer(421 normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,422 ),423 ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);355 });424 });356 });425 });357426358 it('Fungible: disallows to nest token if not Owner (Restricted nesting)', async () => {427 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {359 await usingApi(async api => {428 await usingApi(async api => {360 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});429 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});361 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}}); // todo clear redundant restrictions430 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}}); // todo clear redundant restrictions?362431363 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);432 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);364 await enableAllowListExpectSuccess(alice, collectionNFT);433 await enableAllowListExpectSuccess(alice, collectionNFT);383 });452 });384 });453 });385454386 it('Fungible: disallows to nest token to an unlisted collection', async () => {455 it('Fungible: disallows to nest token in an unlisted collection', async () => {387 await usingApi(async api => {456 await usingApi(async api => {388 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});457 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});389 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});458 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});422 await expect(executeTransaction(api, alice, api.tx.unique.createItem(491 await expect(executeTransaction(api, alice, api.tx.unique.createItem(423 collectionRFT, 492 collectionRFT, 424 targetAddress, 493 targetAddress, 425 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},494 {ReFungible: {const_data: [], pieces: 100}},426 ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);495 ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);427496428 // Create a token to be nested497 // Create a token to be nested432 });501 });433 });502 });434503435 it('ReFungible: disallows to nest token if not Owner', async () => {504 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {436 await usingApi(async api => {505 await usingApi(async api => {437 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});506 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});438 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});507 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});451 await expect(executeTransaction(api, alice, api.tx.unique.createItem(520 await expect(executeTransaction(api, alice, api.tx.unique.createItem(452 collectionRFT, 521 collectionRFT, 453 targetAddress, 522 targetAddress, 454 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},523 {ReFungible: {const_data: [], pieces: 100}},455 ))).to.be.rejected;524 ))).to.be.rejected;456525457 // Try to create and nest a token in the wrong collection526 // Try to create and nest a token in the wrong collection460 });529 });461 });530 });462531463 it('ReFungible: disallows to nest token if not Owner (Restricted nesting)', async () => {532 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {464 await usingApi(async api => {533 await usingApi(async api => {465 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});534 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});466 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}});535 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}});479 await expect(executeTransaction(api, alice, api.tx.unique.createItem(548 await expect(executeTransaction(api, alice, api.tx.unique.createItem(480 collectionRFT, 549 collectionRFT, 481 targetAddress, 550 targetAddress, 482 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},551 {ReFungible: {const_data: [], pieces: 100}},483 ))).to.be.rejected;552 ))).to.be.rejected;484553485 // Try to create and nest a token in the wrong collection554 // Try to create and nest a token in the wrong collection503 await expect(executeTransaction(api, alice, api.tx.unique.createItem(572 await expect(executeTransaction(api, alice, api.tx.unique.createItem(504 collectionRFT, 573 collectionRFT, 505 targetAddress, 574 targetAddress, 506 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},575 {ReFungible: {const_data: [], pieces: 100}},507 ))).to.be.rejected;576 ))).to.be.rejected;508577509 // Try to create and nest a token in the wrong collection578 // Try to create and nest a token in the wrong collectiontests/src/nesting/properties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/properties.test.ts
+++ b/tests/src/nesting/properties.test.ts
@@ -51,13 +51,13 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setCollectionProperties(collectionId, [{key: 'black hole'}]),
+ api.tx.unique.setCollectionProperties(collectionId, [{key: 'black_hole'}]),
)).to.not.be.rejected;
- const properties = (await api.rpc.unique.collectionProperties(collectionId, ['electron', 'black hole'])).toJSON();
+ const properties = (await api.rpc.unique.collectionProperties(collectionId, ['electron', 'black_hole'])).toHuman();
expect(properties).to.be.deep.equal([
- {key: `0x${Buffer.from('electron').toString('hex')}`, value: `0x${Buffer.from('come bond').toString('hex')}`},
- {key: `0x${Buffer.from('black hole').toString('hex')}`, value: `0x${Buffer.from('').toString('hex')}`},
+ {key: 'electron', value: 'come bond'},
+ {key: 'black_hole', value: ''},
]);
});
});
@@ -69,20 +69,20 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black hole'}]),
+ api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole'}]),
)).to.not.be.rejected;
// Mutate the properties
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'bonded'}, {key: 'black hole', value: 'LIGO'}]),
+ api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'bonded'}, {key: 'black_hole', value: 'LIGO'}]),
)).to.not.be.rejected;
- const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black hole'])).toJSON();
+ const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black_hole'])).toHuman();
expect(properties).to.be.deep.equal([
- {key: `0x${Buffer.from('electron').toString('hex')}`, value: `0x${Buffer.from('bonded').toString('hex')}`},
- {key: `0x${Buffer.from('black hole').toString('hex')}`, value: `0x${Buffer.from('LIGO').toString('hex')}`},
+ {key: 'electron', value: 'bonded'},
+ {key: 'black_hole', value: 'LIGO'},
]);
});
});
@@ -94,7 +94,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black hole', value: 'LIGO'}]),
+ api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]),
)).to.not.be.rejected;
await expect(executeTransaction(
@@ -103,9 +103,9 @@
api.tx.unique.deleteCollectionProperties(collection, ['electron']),
)).to.not.be.rejected;
- const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black hole'])).toJSON();
+ const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black_hole'])).toHuman();
expect(properties).to.be.deep.equal([
- {key: `0x${Buffer.from('black hole').toString('hex')}`, value: `0x${Buffer.from('LIGO').toString('hex')}`},
+ {key: 'black_hole', value: 'LIGO'},
]);
});
});
@@ -126,7 +126,7 @@
await expect(executeTransaction(
api,
bob,
- api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black hole', value: 'LIGO'}]),
+ api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]),
)).to.be.rejectedWith(/common\.NoPermission/);
const properties = (await api.query.common.collectionProperties(collection)).toJSON();
@@ -158,7 +158,7 @@
alice,
api.tx.unique.setCollectionProperties(collection, [
{key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))},
- {key: 'black hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))},
+ {key: 'black_hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))},
]),
)).to.be.rejectedWith(/common\.NoSpaceForProperty/);
@@ -174,7 +174,7 @@
const propertiesToBeSet = [];
for (let i = 0; i < 65; i++) {
propertiesToBeSet.push({
- key: 'electron ' + i,
+ key: 'electron_' + i,
value: Math.random() > 0.5 ? 'high' : 'low',
});
}
@@ -190,6 +190,55 @@
expect(properties.consumedSpace).to.equal(0);
});
});
+
+ it('Fails to set properties with invalid names', async () => {
+ await usingApi(async api => {
+ const collection = await createCollectionExpectSuccess();
+
+ const invalidProperties = [
+ [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],
+ [{key: 'Mr.Sandman', value: 'Bring me a gene'}],
+ [{key: 'déjà vu', value: 'hmm...'}],
+ ];
+
+ for (let i = 0; i < invalidProperties.length; i++) {
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.setCollectionProperties(collection, invalidProperties[i]),
+ ), `on rejecting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
+ }
+
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.setCollectionProperties(collection, [{key: '', value: 'nothing must not exist'}]),
+ ), `on rejecting an unnamed property`).to.be.rejectedWith(/common\.EmptyPropertyKey/);
+
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.setCollectionProperties(collection, [
+ {key: 'CRISPR-Cas9', value: 'rewriting nature!'}
+ ]),
+ ), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;
+
+ const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat('CRISPR-Cas9').concat('');
+
+ const properties = (await api.rpc.unique.collectionProperties(collection, keys)).toHuman();
+ expect(properties).to.be.deep.equal([
+ {key: 'CRISPR-Cas9', value: 'rewriting nature!'},
+ ]);
+
+ for (let i = 0; i < invalidProperties.length; i++) {
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.deleteCollectionProperties(collection, invalidProperties[i].map(propertySet => propertySet.key)),
+ ), `on trying to delete the non-existent badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
+ }
+ });
+ });
});
// ---------- ACCESS RIGHTS
@@ -228,10 +277,10 @@
api.tx.unique.setPropertyPermissions(collection, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]),
)).to.not.be.rejected;
- const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery', 'mindgame'])).toJSON();
+ const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery', 'mindgame'])).toHuman();
expect(propertyRights).to.be.deep.equal([
- {key: `0x${Buffer.from('skullduggery').toString('hex')}`, permission: {'mutable': true, 'collectionAdmin': false, 'tokenOwner': false}},
- {key: `0x${Buffer.from('mindgame').toString('hex')}`, permission: {'mutable': false, 'collectionAdmin': true, 'tokenOwner': false}},
+ {key: 'skullduggery', permission: {'mutable': true, 'collectionAdmin': false, 'tokenOwner': false}},
+ {key: 'mindgame', permission: {'mutable': false, 'collectionAdmin': true, 'tokenOwner': false}},
]);
});
});
@@ -252,9 +301,9 @@
api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]),
)).to.not.be.rejected;
- const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();
+ const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();
expect(propertyRights).to.be.deep.equal([
- {key: `0x${Buffer.from('skullduggery').toString('hex')}`, permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},
+ {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},
]);
});
});
@@ -290,7 +339,7 @@
const constitution = [];
for (let i = 0; i < 65; i++) {
constitution.push({
- key: 'property ' + i,
+ key: 'property_' + i,
permission: Math.random() > 0.5 ? {mutable: true, collectionAdmin: true, tokenOwner: true} : {},
});
}
@@ -322,9 +371,51 @@
api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {}}]),
)).to.be.rejectedWith(/common\.NoPermission/);
- const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();
+ const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();
expect(propertyRights).to.deep.equal([
- {key: `0x${Buffer.from('skullduggery').toString('hex')}`, permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},
+ {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},
+ ]);
+ });
+ });
+
+ it('Prevents adding properties with invalid names', async () => {
+ await usingApi(async api => {
+ const collection = await createCollectionExpectSuccess();
+
+ const invalidProperties = [
+ [{key: 'skullduggery', permission: {tokenOwner: true}}, {key: 'im possible', permission: {collectionAdmin: true}}],
+ [{key: 'G#4', permission: {tokenOwner: true}}],
+ [{key: 'HÆMILTON', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}],
+ ];
+
+ for (let i = 0; i < invalidProperties.length; i++) {
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.setPropertyPermissions(collection, invalidProperties[i]),
+ ), `on setting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
+ }
+
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.setPropertyPermissions(collection, [{key: '', permission: {}}]),
+ ), `on rejecting an unnamed property`).to.be.rejectedWith(/common\.EmptyPropertyKey/);
+
+ const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.setPropertyPermissions(collection, [
+ {key: correctKey, permission: {collectionAdmin: true}},
+ ]),
+ ), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;
+
+ const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat(correctKey).concat('');
+
+ const propertyRights = (await api.rpc.unique.propertyPermissions(collection, keys)).toHuman();
+ expect(propertyRights).to.be.deep.equal([
+ {key: correctKey, permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},
]);
});
});
@@ -361,7 +452,7 @@
await transferExpectSuccess(collection, token, alice, charlie);
});
- it('Reads properties of a token', async () => {
+ it('Reads yet empty properties of a token', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess();
const token = await createItemExpectSuccess(alice, collection, 'NFT');
@@ -381,7 +472,7 @@
let i = 0;
for (const permission of permissions) {
for (const signer of permission.signers) {
- const key = i + ' ' + signer.address;
+ const key = i + '_' + signer.address;
propertyKeys.push(key);
await expect(executeTransaction(
@@ -400,11 +491,11 @@
i++;
}
- const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toJSON() as any[];
- const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toJSON().properties as any[];
+ const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];
+ const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];
for (let i = 0; i < properties.length; i++) {
- expect(properties[i].value).to.be.equal(`0x${Buffer.from('Serotonin increase').toString('hex')}`);
- expect(tokensData[i].value).to.be.equal(`0x${Buffer.from('Serotonin increase').toString('hex')}`);
+ expect(properties[i].value).to.be.equal('Serotonin increase');
+ expect(tokensData[i].value).to.be.equal('Serotonin increase');
}
});
});
@@ -417,7 +508,7 @@
if (!permission.permission.mutable) continue;
for (const signer of permission.signers) {
- const key = i + ' ' + signer.address;
+ const key = i + '_' + signer.address;
propertyKeys.push(key);
await expect(executeTransaction(
@@ -442,11 +533,11 @@
i++;
}
- const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toJSON() as any[];
- const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toJSON().properties as any[];
+ const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];
+ const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];
for (let i = 0; i < properties.length; i++) {
- expect(properties[i].value).to.be.equal(`0x${Buffer.from('Serotonin stable').toString('hex')}`);
- expect(tokensData[i].value).to.be.equal(`0x${Buffer.from('Serotonin stable').toString('hex')}`);
+ expect(properties[i].value).to.be.equal('Serotonin stable');
+ expect(tokensData[i].value).to.be.equal('Serotonin stable');
}
});
});
@@ -460,7 +551,7 @@
if (!permission.permission.mutable) continue;
for (const signer of permission.signers) {
- const key = i + ' ' + signer.address;
+ const key = i + '_' + signer.address;
propertyKeys.push(key);
await expect(executeTransaction(
@@ -532,13 +623,13 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: i, permission: passage.permission}]),
+ api.tx.unique.setPropertyPermissions(collection, [{key: `${i}`, permission: passage.permission}]),
), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;
await expect(executeTransaction(
api,
signer,
- api.tx.unique.setTokenProperties(collection, token, [{key: i, value: 'Serotonin increase'}]),
+ api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin increase'}]),
), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;
i++;
@@ -558,17 +649,16 @@
await expect(executeTransaction(
api,
forbiddance.sinner,
- api.tx.unique.setTokenProperties(collection, token, [{key: i, value: 'Serotonin down'}]),
+ api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin down'}]),
), `on failing to change property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);
await expect(executeTransaction(
api,
forbiddance.sinner,
- api.tx.unique.deleteTokenProperties(collection, token, [forbiddance.permission]),
+ api.tx.unique.deleteTokenProperties(collection, token, [`${i}`]),
), `on failing to delete property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);
}
- // todo RPC?
const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
expect(properties.consumedSpace).to.be.equal(originalSpace);
});
@@ -584,7 +674,7 @@
await expect(executeTransaction(
api,
permission.signers[0],
- api.tx.unique.setTokenProperties(collection, token, [{key: i, value: 'Serotonin down'}]),
+ api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin down'}]),
), `on failing to change property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);
await expect(executeTransaction(
@@ -594,7 +684,6 @@
), `on failing to delete property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);
}
- // todo RPC?
const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
expect(properties.consumedSpace).to.be.equal(originalSpace);
});
@@ -632,8 +721,8 @@
api,
alice,
api.tx.unique.setPropertyPermissions(collection, [
- {key: 'a holy book', permission: {collectionAdmin: true, tokenOwner: true}},
- {key: 'young years', permission: {collectionAdmin: true, tokenOwner: true}},
+ {key: 'a_holy_book', permission: {collectionAdmin: true, tokenOwner: true}},
+ {key: 'young_years', permission: {collectionAdmin: true, tokenOwner: true}},
]),
), 'on setting a new non-permitted property').to.not.be.rejected;
@@ -643,7 +732,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setCollectionProperties(collection, [{key: 'a holy book', value: 'word '.repeat(6554)}]),
+ api.tx.unique.setCollectionProperties(collection, [{key: 'a_holy_book', value: 'word '.repeat(6554)}]),
)).to.be.rejected;
}
@@ -651,12 +740,12 @@
api,
alice,
api.tx.unique.setTokenProperties(collection, token, [
- {key: 'a holy book', value: 'word '.repeat(3277)},
- {key: 'young years', value: 'neverending'.repeat(1490)},
+ {key: 'a_holy_book', value: 'word '.repeat(3277)},
+ {key: 'young_years', value: 'neverending'.repeat(1490)},
]),
)).to.be.rejectedWith(/common\.NoSpaceForProperty/);
- expect((await api.rpc.unique.tokenProperties(collection, token, ['a holy book', 'young years'])).toJSON()).to.be.empty;
+ expect((await api.rpc.unique.tokenProperties(collection, token, ['a_holy_book', 'young years'])).toJSON()).to.be.empty;
const propertiesMap = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
expect(propertiesMap.consumedSpace).to.be.equal(originalSpace);
});
tests/src/nesting/unnest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/unnest.test.ts
+++ b/tests/src/nesting/unnest.test.ts
@@ -6,11 +6,13 @@
createCollectionExpectSuccess,
createItemExpectFailure,
createItemExpectSuccess,
+ getBalance,
getTokenOwner,
getTopmostTokenOwner,
normalizeAccountId,
setCollectionLimitsExpectSuccess,
transferExpectSuccess,
+ transferFromExpectSuccess,
} from '../util/helpers';
import {IKeyringPair} from '@polkadot/types/types';
@@ -25,7 +27,7 @@
});
});
- it('Allows the owner to successfully unnest a token', async () => {
+ it('NFT: allows the owner to successfully unnest a token', async () => {
await usingApi(async api => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
@@ -40,7 +42,7 @@
api,
alice,
api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(alice), collection, nestedToken, 1),
- )).to.not.be.rejected;
+ ), 'while unnesting').to.not.be.rejected;
expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
// Nest and burn
@@ -48,13 +50,64 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.burnFrom(collection, normalizeAccountId(alice.address), nestedToken, 1),
- )).to.not.be.rejected;
- await expect(getTokenOwner(api, collection, nestedToken)).to.be.rejected; // 'owner == null'
+ api.tx.unique.burnFrom(collection, normalizeAccountId(targetAddress), nestedToken, 1),
+ ), 'while burning').to.not.be.rejected;
+ await expect(getTokenOwner(api, collection, nestedToken)).to.be.rejected;
});
});
- // todo refungible-fungible test just in case
+ it('Fungible: allows the owner to successfully unnest a token', async () => {
+ await usingApi(async api => {
+ const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
+ const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
+
+ const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ const nestedToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
+
+ // Nest and unnest
+ await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');
+ await transferFromExpectSuccess(collectionFT, nestedToken, alice, targetAddress, alice, 1, 'Fungible');
+
+ // Nest and burn
+ await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');
+ const balanceBefore = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.burnFrom(collectionFT, normalizeAccountId(targetAddress), nestedToken, 1),
+ ), 'while burning').to.not.be.rejected;
+ const balanceAfter = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);
+ expect(balanceAfter + BigInt(1)).to.be.equal(balanceBefore);
+ });
+ });
+
+ it('ReFungible: allows the owner to successfully unnest a token', async () => {
+ await usingApi(async api => {
+ const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+ const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
+ const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
+
+ const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ const nestedToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
+
+ // Nest and unnest
+ await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');
+ await transferFromExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, alice, 1, 'ReFungible');
+
+ // Nest and burn
+ await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');
+ await expect(executeTransaction(
+ api,
+ alice,
+ api.tx.unique.burnFrom(collectionRFT, normalizeAccountId(targetAddress), nestedToken, 1),
+ ), 'while burning').to.not.be.rejected;
+ const balance = await getBalance(api, collectionRFT, normalizeAccountId(targetAddress), nestedToken);
+ expect(balance).to.be.equal(0n);
+ });
+ });
});
describe('Negative Test: Unnesting', () => {
@@ -80,8 +133,7 @@
api,
bob,
api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(bob), collection, nestedToken, 1),
- )).to.be.rejectedWith(/^common\.ApprovedValueTooLow$/);
- //await transferFromExpectSuccess(collection, nestedToken, bob, targetAddress, {Substrate: bob.address});
+ ), 'while unnesting').to.be.rejectedWith(/^structure\.DepthLimit$/); // todo ApprovedValueTooLow?
expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
// Try to burn
@@ -89,31 +141,15 @@
api,
bob,
api.tx.unique.burnFrom(collection, normalizeAccountId(bob.address), nestedToken, 1),
- )).to.not.be.rejectedWith(/^common\.ApprovedValueTooLow$/);
+ ), 'while burning').to.not.be.rejectedWith(/^common\.ApprovedValueTooLow$/);
expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
});
});
- it('Disallows excessive token nesting', async () => {
- await usingApi(async api => {
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
- const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
-
- // Create a nested token matryoshka
- const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
- const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});
- // The nesting depth is limited by 2
- await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken2)});
+ // todo another test for creating excessive depth matryoshka with Ethereum?
- expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});
- });
- });
-
- // todo another test for creating excessive depth matryoshka with Ethereum, move this one to nest ^
-
// Recursive nesting
- it('Prevents ouroboros creation', async () => {
+ it('Prevents Ouroboros creation', async () => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -903,7 +903,7 @@
const from = normalizeAccountId(accountFrom);
const to = normalizeAccountId(accountTo);
let balanceBefore = 0n;
- if (type === 'Fungible') {
+ if (type === 'Fungible' || type === 'ReFungible') {
balanceBefore = await getBalance(api, collectionId, to, tokenId);
}
const transferFromTx = api.tx.unique.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);
@@ -923,7 +923,7 @@
}
}
if (type === 'ReFungible') {
- expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(BigInt(value));
+ expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(balanceBefore + BigInt(value));
}
});
}