difftreelog
refactor(tests-nesting) use charlie instead of bob
in: master
1 file changed
tests/src/nesting/nest.test.tsdiffbeforeafterboth212122let alice: IKeyringPair;22let alice: IKeyringPair;23let bob: IKeyringPair;23let bob: IKeyringPair;24let charlie: IKeyringPair;242525describe('Integration Test: Composite nesting tests', () => {26describe('Integration Test: Composite nesting tests', () => {26 before(async () => {27 before(async () => {153 await usingApi(async (_, privateKeyWrapper) => {154 await usingApi(async (_, privateKeyWrapper) => {154 alice = privateKeyWrapper('//Alice');155 alice = privateKeyWrapper('//Alice');155 bob = privateKeyWrapper('//Bob');156 bob = privateKeyWrapper('//Bob');157 charlie = privateKeyWrapper('//Charlie');156 });158 });157 });159 });158160159 it('Admin (NFT): allows an Admin to nest a token', async () => {161 it('Admin (NFT): allows an Admin to nest a token', async () => {160 await usingApi(async api => {162 await usingApi(async api => {161 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});163 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});162 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});164 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});163 await addCollectionAdminExpectSuccess(alice, collection, bob.address);165 await addCollectionAdminExpectSuccess(alice, collection, charlie.address);164 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');166 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');165167166 // Create a nested token168 // Create a nested token167 const nestedToken = await createItemExpectSuccess(bob, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});169 const nestedToken = await createItemExpectSuccess(charlie, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});168 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});170 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()});171 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});170172171 // Create a token to be nested and nest173 // Create a token to be nested and nest172 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');174 const newToken = await createItemExpectSuccess(charlie, collection, 'NFT');173 await transferExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)});175 await transferExpectSuccess(collection, newToken, charlie, {Ethereum: tokenIdToAddress(collection, targetToken)});174 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});176 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()});177 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});176 });178 });179 it('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async () => {181 it('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async () => {180 await usingApi(async api => {182 await usingApi(async api => {181 const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});183 const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});182 await addCollectionAdminExpectSuccess(alice, collectionA, bob.address);184 await addCollectionAdminExpectSuccess(alice, collectionA, charlie.address);183 const collectionB = await createCollectionExpectSuccess({mode: {type: 'NFT'}});185 const collectionB = await createCollectionExpectSuccess({mode: {type: 'NFT'}});184 await addCollectionAdminExpectSuccess(alice, collectionB, bob.address);186 await addCollectionAdminExpectSuccess(alice, collectionB, charlie.address);185 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {collectionAdmin: true, restricted:[collectionA, collectionB]}});187 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {collectionAdmin: true, restricted:[collectionA, collectionB]}});186 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');188 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');187189188 // Create a nested token190 // Create a nested token189 const nestedToken = await createItemExpectSuccess(bob, collectionB, 'NFT', {Ethereum: tokenIdToAddress(collectionA, targetToken)});191 const nestedToken = await createItemExpectSuccess(charlie, collectionB, 'NFT', {Ethereum: tokenIdToAddress(collectionA, targetToken)});190 expect(await getTopmostTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Substrate: alice.address});192 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()});193 expect(await getTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});192194193 // Create a token to be nested and nest195 // Create a token to be nested and nest194 const newToken = await createItemExpectSuccess(bob, collectionB, 'NFT');196 const newToken = await createItemExpectSuccess(charlie, collectionB, 'NFT');195 await transferExpectSuccess(collectionB, newToken, bob, {Ethereum: tokenIdToAddress(collectionA, targetToken)});197 await transferExpectSuccess(collectionB, newToken, charlie, {Ethereum: tokenIdToAddress(collectionA, targetToken)});196 expect(await getTopmostTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Substrate: alice.address});198 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()});199 expect(await getTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});198 });200 });338 await usingApi(async (_, privateKeyWrapper) => {340 await usingApi(async (_, privateKeyWrapper) => {339 alice = privateKeyWrapper('//Alice');341 alice = privateKeyWrapper('//Alice');340 bob = privateKeyWrapper('//Bob');342 bob = privateKeyWrapper('//Bob');343 charlie = privateKeyWrapper('//Charlie');341 });344 });342 });345 });343346379 await usingApi(async api => {382 await usingApi(async api => {380 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});383 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});381 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});384 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});382 await addCollectionAdminExpectSuccess(alice, collection, bob.address);385 await addCollectionAdminExpectSuccess(alice, collection, charlie.address);383 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');386 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');384387385 // Try to create a nested token as collection admin when it's disallowed388 // Try to create a nested token as collection admin when it's disallowed386 await expect(executeTransaction(api, bob, api.tx.unique.createItem(389 await expect(executeTransaction(api, charlie, api.tx.unique.createItem(387 collection,390 collection,388 {Ethereum: tokenIdToAddress(collection, targetToken)},391 {Ethereum: tokenIdToAddress(collection, targetToken)},389 {nft: {const_data: [], variable_data: []}} as any,392 {nft: {const_data: [], variable_data: []}} as any,390 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);393 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);391394392 // Try to create and nest a token in the wrong collection395 // Try to create and nest a token in the wrong collection393 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');396 const newToken = await createItemExpectSuccess(charlie, 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/);397 await expect(executeTransaction(398 api, 399 charlie, 400 api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1),401 ), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);395 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});402 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: charlie.address});396 });403 });397 });404 });398405399 it('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async () => {406 it('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async () => {400 await usingApi(async api => {407 await usingApi(async api => {401 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});408 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});402 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});409 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});403 await addToAllowListExpectSuccess(alice, collection, bob.address);410 await addToAllowListExpectSuccess(alice, collection, charlie.address);404 await enableAllowListExpectSuccess(alice, collection);411 await enableAllowListExpectSuccess(alice, collection);405 await enablePublicMintingExpectSuccess(alice, collection);412 await enablePublicMintingExpectSuccess(alice, collection);406 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');413 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');407414408 // Try to create a nested token as collection admin when it's disallowed415 // Try to create a nested token as collection admin when it's disallowed409 await expect(executeTransaction(api, bob, api.tx.unique.createItem(416 await expect(executeTransaction(api, charlie, api.tx.unique.createItem(410 collection,417 collection,411 {Ethereum: tokenIdToAddress(collection, targetToken)},418 {Ethereum: tokenIdToAddress(collection, targetToken)},412 {nft: {const_data: [], variable_data: []}} as any,419 {nft: {const_data: [], variable_data: []}} as any,413 )), 'while creating nested token').to.be.rejectedWith(/common\.AddressNotInAllowlist/); // todo is this right?420 )), 'while creating nested token').to.be.rejectedWith(/common\.AddressNotInAllowlist/); // todo is this right?414421415 // Try to create and nest a token in the wrong collection422 // Try to create and nest a token in the wrong collection416 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');423 const newToken = await createItemExpectSuccess(charlie, 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/);424 await expect(executeTransaction(425 api, 426 charlie, 427 api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1),428 ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);418 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});429 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: charlie.address});419 });430 });420 });431 });421432424 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});435 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});425 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});436 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});426437427 await addToAllowListExpectSuccess(alice, collection, bob.address);438 await addToAllowListExpectSuccess(alice, collection, charlie.address);428 await enableAllowListExpectSuccess(alice, collection);439 await enableAllowListExpectSuccess(alice, collection);429 await enablePublicMintingExpectSuccess(alice, collection);440 await enablePublicMintingExpectSuccess(alice, collection);430441431 // Create a token to attempt to be nested into442 // Create a token to attempt to be nested into432 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');443 const targetToken = await createItemExpectSuccess(charlie, collection, 'NFT');433 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()};444 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()};434445435 // Try to nest somebody else's token446 // Try to nest somebody else's token436 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');447 const newToken = await createItemExpectSuccess(charlie, collection, 'NFT');437 await expect(executeTransaction(448 await expect(executeTransaction(438 api, 449 api, 439 alice, 450 alice, 440 api.tx.unique.transfer(targetAddress, collection, newToken, 1),451 api.tx.unique.transfer(targetAddress, collection, newToken, 1),441 ), 'while nesting another\'s token token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);452 ), '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});453 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: charlie.address});443454444 // Nest a token as admin and try to unnest it, now belonging to someone else455 // Nest a token as admin and try to unnest it, now belonging to someone else445 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);456 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);449 api.tx.unique.transferFrom(targetAddress, normalizeAccountId(alice), collection, nestedToken, 1),460 api.tx.unique.transferFrom(targetAddress, normalizeAccountId(alice), collection, nestedToken, 1),450 ), 'while unnesting another\'s token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);461 ), 'while unnesting another\'s token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);451 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal(targetAddress);462 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});463 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: charlie.address});453 });464 });454 });465 });455466