difftreelog
test(nesting) collection admin test suite
in: master
2 files changed
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -98,7 +98,7 @@
...encodeIntBE(collection),
...encodeIntBE(token),
]);
- return Web3.utils.toChecksumAddress('0x' + buf.toString('hex'));
+ return Web3.utils.toChecksumAddress('0x' + buf.toString('hex')).toLowerCase();
}
export function tokenIdToCross(collection: number, token: number): CrossAccountId {
return {
tests/src/nesting/nest.test.tsdiffbeforeafterboth2import {tokenIdToAddress} from '../eth/util/helpers';2import {tokenIdToAddress} from '../eth/util/helpers';3import usingApi, {executeTransaction} from '../substrate/substrate-api';3import usingApi, {executeTransaction} from '../substrate/substrate-api';4import {4import {5 addCollectionAdminExpectSuccess,5 addToAllowListExpectSuccess,6 addToAllowListExpectSuccess,6 createCollectionExpectSuccess,7 createCollectionExpectSuccess,7 createItemExpectSuccess,8 createItemExpectSuccess,21let alice: IKeyringPair;22let alice: IKeyringPair;22let bob: IKeyringPair;23let bob: IKeyringPair;232424describe('Integration Test: Nesting', () => {25describe('Integration Test: Composite nesting tests', () => {25 before(async () => {26 before(async () => {26 await usingApi(async (api, privateKeyWrapper) => {27 await usingApi(async (_, privateKeyWrapper) => {27 alice = privateKeyWrapper('//Alice');28 alice = privateKeyWrapper('//Alice');28 bob = privateKeyWrapper('//Bob');29 bob = privateKeyWrapper('//Bob');29 });30 });145 ], 'Children contents check at deeper nesting');146 ], 'Children contents check at deeper nesting');146 });147 });147 });148 });149});148150151describe('Integration Test: Various token type nesting', async () => {152 before(async () => {153 await usingApi(async (_, privateKeyWrapper) => {154 alice = privateKeyWrapper('//Alice');155 bob = privateKeyWrapper('//Bob');156 });157 });158159 it('Admin (NFT): allows an Admin to nest a token', async () => {160 await usingApi(async api => {161 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});162 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {admin: true}});163 await addCollectionAdminExpectSuccess(alice, collection, bob.address);164 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');165166 // Create a nested token167 const nestedToken = await createItemExpectSuccess(bob, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});168 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});169 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});170171 // Create a token to be nested and nest172 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');173 await transferExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)});174 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});175 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});176 });177 });178179 it('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async () => {180 await usingApi(async api => {181 const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});182 await addCollectionAdminExpectSuccess(alice, collectionA, bob.address);183 const collectionB = await createCollectionExpectSuccess({mode: {type: 'NFT'}});184 await addCollectionAdminExpectSuccess(alice, collectionB, bob.address);185 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {admin: true, restricted:[collectionA, collectionB]}});186 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');187188 // Create a nested token189 const nestedToken = await createItemExpectSuccess(bob, collectionB, 'NFT', {Ethereum: tokenIdToAddress(collectionA, targetToken)});190 expect(await getTopmostTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Substrate: alice.address});191 expect(await getTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});192193 // Create a token to be nested and nest194 const newToken = await createItemExpectSuccess(bob, collectionB, 'NFT');195 await transferExpectSuccess(collectionB, newToken, bob, {Ethereum: tokenIdToAddress(collectionA, targetToken)});196 expect(await getTopmostTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Substrate: alice.address});197 expect(await getTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});198 });199 });200149 // ---------- Non-Fungible ----------201 // ---------- Non-Fungible ----------150202283335284describe('Negative Test: Nesting', async() => {336describe('Negative Test: Nesting', async() => {285 before(async () => {337 before(async () => {286 await usingApi(async (api, privateKeyWrapper) => {338 await usingApi(async (_, privateKeyWrapper) => {287 alice = privateKeyWrapper('//Alice');339 alice = privateKeyWrapper('//Alice');288 bob = privateKeyWrapper('//Bob');340 bob = privateKeyWrapper('//Bob');289 });341 });318 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);370 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);319371320 expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});372 expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});373 });374 });375376 // ---------- Admin ------------377378 it('Admin (NFT): disallows an Admin to operate nesting when only TokenOwner is allowed', async () => {379 await usingApi(async api => {380 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});381 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});382 await addCollectionAdminExpectSuccess(alice, collection, bob.address);383 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');384385 // Try to create a nested token as collection admin when it's disallowed386 await expect(executeTransaction(api, bob, api.tx.unique.createItem(387 collection,388 {Ethereum: tokenIdToAddress(collection, targetToken)},389 {nft: {const_data: [], variable_data: []}} as any,390 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);391392 // Try to create and nest a token in the wrong collection393 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');394 await expect(executeTransaction(api, bob, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);395 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});396 });397 });398399 it('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async () => {400 await usingApi(async api => {401 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});402 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {admin: true}});403 await addToAllowListExpectSuccess(alice, collection, bob.address);404 await enableAllowListExpectSuccess(alice, collection);405 await enablePublicMintingExpectSuccess(alice, collection);406 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');407408 // Try to create a nested token as collection admin when it's disallowed409 await expect(executeTransaction(api, bob, api.tx.unique.createItem(410 collection,411 {Ethereum: tokenIdToAddress(collection, targetToken)},412 {nft: {const_data: [], variable_data: []}} as any,413 )), 'while creating nested token').to.be.rejectedWith(/common\.AddressNotInAllowlist/); // todo is this right?414415 // Try to create and nest a token in the wrong collection416 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');417 await expect(executeTransaction(api, bob, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);418 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});419 });420 });421422 it('Admin (NFT): disallows an Admin to nest and unnest someone else\'s token', async () => {423 await usingApi(async api => {424 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});425 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {admin: true}});426427 await addToAllowListExpectSuccess(alice, collection, bob.address);428 await enableAllowListExpectSuccess(alice, collection);429 await enablePublicMintingExpectSuccess(alice, collection);430431 // Create a token to attempt to be nested into432 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');433 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};434435 // Try to nest somebody else's token436 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');437 await expect(executeTransaction(438 api, 439 alice, 440 api.tx.unique.transfer(targetAddress, collection, newToken, 1),441 ), 'while nesting another\'s token token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);442 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});443444 // Nest a token as admin and try to unnest it, now belonging to someone else445 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);446 await expect(executeTransaction(447 api, 448 alice, 449 api.tx.unique.transferFrom(targetAddress, normalizeAccountId(alice), collection, nestedToken, 1),450 ), 'while unnesting another\'s token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);451 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal(targetAddress);452 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});453 });454 });455456 it('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async () => {457 await usingApi(async api => {458 const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});459 const collectionB = await createCollectionExpectSuccess({mode: {type: 'NFT'}});460 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {admin: true, restricted:[collectionA]}});461462 // Create a token to attempt to be nested into463 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');464465 // Try to create and nest a token in the wrong collection466 const newToken = await createItemExpectSuccess(alice, collectionB, 'NFT');467 await expect(executeTransaction(468 api, 469 alice, 470 api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionA, targetToken)}, collectionB, newToken, 1),471 ), 'while nesting a foreign token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);472 expect(await getTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Substrate: alice.address});321 });473 });322 });474 });323475