git.delta.rocks / unique-network / refs/commits / 77a7be634bdd

difftreelog

CORE-410 Adapt rest token property test for ReFungible collection

Trubnikov Sergey2022-07-01parent: #c5c3942.patch.diff
in: master

1 file changed

modifiedtests/src/nesting/properties.test.tsdiffbeforeafterboth
616// ---------- TOKEN PROPERTIES616// ---------- TOKEN PROPERTIES
617617
618describe('Integration Test: Token Properties', () => {618describe('Integration Test: Token Properties', () => {
619 let collection: number;
620 let token: number;
621 let nestedToken: number;
622 let permissions: {permission: any, signers: IKeyringPair[]}[];619 let permissions: {permission: any, signers: IKeyringPair[]}[];
623620
624 before(async () => {621 before(async () => {
625 await usingApi(async (api, privateKeyWrapper) => {622 await usingApi(async (api, privateKeyWrapper) => {
626 alice = privateKeyWrapper('//Alice');623 alice = privateKeyWrapper('//Alice'); // collection owner
627 bob = privateKeyWrapper('//Bob');624 bob = privateKeyWrapper('//Bob'); // collection admin
628 charlie = privateKeyWrapper('//Charlie');625 charlie = privateKeyWrapper('//Charlie'); // token owner
629626
630 permissions = [627 permissions = [
631 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob]},628 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob]},
638 });635 });
639 });636 });
640637
641 beforeEach(async () => {
642 await usingApi(async () => {
643 collection = await createCollectionExpectSuccess();
644 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});
645
646 token = await createItemExpectSuccess(alice, collection, 'NFT');
647 nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, token)});
648
649 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
650 await transferExpectSuccess(collection, token, alice, charlie); });
651 });
652
653 it('Reads yet empty properties of a token', async () => {638 async function testReadsYetEmptyProperties(mode: CollectionMode) {
654 await usingApi(async api => {639 await usingApi(async api => {
655 const collection = await createCollectionExpectSuccess();640 const collection = await createCollectionExpectSuccess({mode: mode});
656 const token = await createItemExpectSuccess(alice, collection, 'NFT');641 const token = await createItemExpectSuccess(alice, collection, mode.type);
657 642
658 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();643 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
659 expect(properties.map).to.be.empty;644 expect(properties.map).to.be.empty;
662 const tokenData = (await api.rpc.unique.tokenData(collection, token, ['anything'])).toJSON().properties;647 const tokenData = (await api.rpc.unique.tokenData(collection, token, ['anything'])).toJSON().properties;
663 expect(tokenData).to.be.empty;648 expect(tokenData).to.be.empty;
664 });649 });
665 });650 }
651 it('Reads yet empty properties of a token (NFT)', async () => {
652 await testReadsYetEmptyProperties({type: 'NFT'});
653 });
654 it('Reads yet empty properties of a token (ReFungible)', async () => {
655 await testReadsYetEmptyProperties({type: 'ReFungible'});
656 });
666657
667 it('Assigns properties to a token according to permissions', async () => {658 async function testAssignPropertiesAccordingToPermissions(mode: CollectionMode, pieces: number) {
668 await usingApi(async api => {659 await usingApi(async api => {
660 const collection = await createCollectionExpectSuccess({mode: mode});
661 const token = await createItemExpectSuccess(alice, collection, mode.type);
662 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
663 await transferExpectSuccess(collection, token, alice, charlie, pieces, mode.type);
664
669 const propertyKeys: string[] = [];665 const propertyKeys: string[] = [];
670 let i = 0;666 let i = 0;
696 expect(tokensData[i].value).to.be.equal('Serotonin increase');692 expect(tokensData[i].value).to.be.equal('Serotonin increase');
697 }693 }
698 });694 });
699 });695 }
700696 it('Assigns properties to a token according to permissions (NFT)', async () => {
697 await testAssignPropertiesAccordingToPermissions({type: 'NFT'}, 1);
698 });
701 it.only('Assigns properties to a token according to permissions (ReFungible)', async () => {699 it('Assigns properties to a token according to permissions (ReFungible)', async () => {
702 await usingApi(async api => {700 await testAssignPropertiesAccordingToPermissions({type: 'ReFungible'}, 100);
703 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
704 const token = await createItemExpectSuccess(alice, collection, 'ReFungible');
705 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
706 await transferExpectSuccess(collection, token, alice, charlie, 1, 'ReFungible');
707
708 const propertyKeys: string[] = [];
709 let i = 0;
710 for (const permission of permissions) {
711 for (const signer of permission.signers) {
712 const key = i + '_' + signer.address;
713 propertyKeys.push(key);
714
715 await expect(executeTransaction(
716 api,
717 alice,
718 api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]),
719 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;
720
721 await expect(executeTransaction(
722 api,
723 signer,
724 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin increase'}]),
725 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;
726 }
727
728 i++;
729 }
730
731 // const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];
732 // const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];
733 // for (let i = 0; i < properties.length; i++) {
734 // expect(properties[i].value).to.be.equal('Serotonin increase');
735 // expect(tokensData[i].value).to.be.equal('Serotonin increase');
736 // }
737 });
738 });701 });
739702
740 it('Changes properties of a token according to permissions', async () => {703 async function testChangesPropertiesAccordingPermission(mode: CollectionMode, pieces: number) {
741 await usingApi(async api => {704 await usingApi(async api => {
705 const collection = await createCollectionExpectSuccess({mode: mode});
706 const token = await createItemExpectSuccess(alice, collection, mode.type);
707 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
708 await transferExpectSuccess(collection, token, alice, charlie, pieces, mode.type);
709
742 const propertyKeys: string[] = [];710 const propertyKeys: string[] = [];
743 let i = 0;711 let i = 0;
777 expect(tokensData[i].value).to.be.equal('Serotonin stable');745 expect(tokensData[i].value).to.be.equal('Serotonin stable');
778 }746 }
779 });747 });
780 });748 }
749 it('Changes properties of a token according to permissions (NFT)', async () => {
750 await testChangesPropertiesAccordingPermission({type: 'NFT'}, 1);
751 });
752 it('Changes properties of a token according to permissions (ReFungible)', async () => {
753 await testChangesPropertiesAccordingPermission({type: 'ReFungible'}, 100);
754 });
781755
782 it('Deletes properties of a token according to permissions', async () => {756 async function testDeletePropertiesAccordingPermission(mode: CollectionMode, pieces: number) {
783 await usingApi(async api => {757 await usingApi(async api => {
758 const collection = await createCollectionExpectSuccess({mode: mode});
759 const token = await createItemExpectSuccess(alice, collection, mode.type);
760 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
761 await transferExpectSuccess(collection, token, alice, charlie, pieces, mode.type);
762
784 const propertyKeys: string[] = [];763 const propertyKeys: string[] = [];
785 let i = 0;764 let i = 0;
819 expect(tokensData).to.be.empty;798 expect(tokensData).to.be.empty;
820 expect((await api.query.nonfungible.tokenProperties(collection, token)).toJSON().consumedSpace).to.be.equal(0);799 expect((await api.query.nonfungible.tokenProperties(collection, token)).toJSON().consumedSpace).to.be.equal(0);
821 });800 });
822 });801 }
802 it('Deletes properties of a token according to permissions (NFT)', async () => {
803 await testDeletePropertiesAccordingPermission({type: 'NFT'}, 1);
804 });
805 it('Deletes properties of a token according to permissions (ReFungible)', async () => {
806 await testDeletePropertiesAccordingPermission({type: 'ReFungible'}, 100);
807 });
823808
824 it('Assigns properties to a nested token according to permissions', async () => {809 it('Assigns properties to a nested token according to permissions', async () => {
825 await usingApi(async api => {810 await usingApi(async api => {
964 });949 });
965 });950 });
966951
967 beforeEach(async () => {952 async function prepare(mode: CollectionMode, pieces: number) {
968 collection = await createCollectionExpectSuccess();953 collection = await createCollectionExpectSuccess({mode: mode});
969 token = await createItemExpectSuccess(alice, collection, 'NFT');954 token = await createItemExpectSuccess(alice, collection, mode.type);
970 await addCollectionAdminExpectSuccess(alice, collection, bob.address);955 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
971 await transferExpectSuccess(collection, token, alice, charlie);956 await transferExpectSuccess(collection, token, alice, charlie, pieces, mode.type);
972 957
973 await usingApi(async api => {958 await usingApi(async api => {
974 let i = 0;959 let i = 0;
992977
993 originalSpace = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON().consumedSpace as number;978 originalSpace = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON().consumedSpace as number;
994 });979 });
995 });980 }
996981
997 it('Forbids changing/deleting properties of a token if the user is outside of permissions', async () => {982 async function testForbidsChangingDeletingPropertiesUserOutsideOfPermissions(mode: CollectionMode, pieces: number) {
983 await prepare(mode, pieces);
984
998 await usingApi(async api => {985 await usingApi(async api => {
999 let i = -1;986 let i = -1;
1017 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();1004 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
1018 expect(properties.consumedSpace).to.be.equal(originalSpace);1005 expect(properties.consumedSpace).to.be.equal(originalSpace);
1019 });1006 });
1020 });1007 }
1008 it('Forbids changing/deleting properties of a token if the user is outside of permissions (NFT)', async () => {
1009 await testForbidsChangingDeletingPropertiesUserOutsideOfPermissions({type: 'NFT'}, 1);
1010 });
1011 it('Forbids changing/deleting properties of a token if the user is outside of permissions (ReFungible)', async () => {
1012 await testForbidsChangingDeletingPropertiesUserOutsideOfPermissions({type: 'ReFungible'}, 100);
1013 });
10211014
1022 it('Forbids changing/deleting properties of a token if the property is permanent (immutable)', async () => {1015 async function testForbidsChangingDeletingPropertiesIfPropertyImmutable(mode: CollectionMode, pieces: number) {
1016 await prepare(mode, pieces);
1017
1023 await usingApi(async api => {1018 await usingApi(async api => {
1024 let i = -1;1019 let i = -1;
1042 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();1037 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
1043 expect(properties.consumedSpace).to.be.equal(originalSpace);1038 expect(properties.consumedSpace).to.be.equal(originalSpace);
1044 });1039 });
1045 });1040 }
1041 it('Forbids changing/deleting properties of a token if the property is permanent (immutable) (NFT)', async () => {
1042 await testForbidsChangingDeletingPropertiesIfPropertyImmutable({type: 'NFT'}, 1);
1043 });
1044 it('Forbids changing/deleting properties of a token if the property is permanent (immutable) (ReFungible)', async () => {
1045 await testForbidsChangingDeletingPropertiesIfPropertyImmutable({type: 'ReFungible'}, 100);
1046 });
10461047
1047 it('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission', async () => {1048 async function testForbidsAddingPropertiesIfPropertyNotDeclared(mode: CollectionMode, pieces: number) {
1049 await prepare(mode, pieces);
1050
1048 await usingApi(async api => {1051 await usingApi(async api => {
1049 await expect(executeTransaction(1052 await expect(executeTransaction(
1068 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();1071 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
1069 expect(properties.consumedSpace).to.be.equal(originalSpace);1072 expect(properties.consumedSpace).to.be.equal(originalSpace);
1070 });1073 });
1071 });1074 }
1075 it('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission (NFT)', async () => {
1076 await testForbidsAddingPropertiesIfPropertyNotDeclared({type: 'NFT'}, 1);
1077 });
1078 it('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission (ReFungible)', async () => {
1079 await testForbidsAddingPropertiesIfPropertyNotDeclared({type: 'ReFungible'}, 100);
1080 });
10721081
1073 it('Forbids adding too many properties to a token', async () => {1082 async function testForbidsAddingTooManyProperties(mode: CollectionMode, pieces: number) {
1083 await prepare(mode, pieces);
1084
1074 await usingApi(async api => {1085 await usingApi(async api => {
1075 await expect(executeTransaction(1086 await expect(executeTransaction(
1104 const propertiesMap = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();1115 const propertiesMap = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
1105 expect(propertiesMap.consumedSpace).to.be.equal(originalSpace);1116 expect(propertiesMap.consumedSpace).to.be.equal(originalSpace);
1106 });1117 });
1107 });1118 }
1119 it('Forbids adding too many properties to a token (NFT)', async () => {
1120 await testForbidsAddingTooManyProperties({type: 'NFT'}, 1);
1121 });
1122 it('Forbids adding too many properties to a token (ReFungible)', async () => {
1123 await testForbidsAddingTooManyProperties({type: 'ReFungible'}, 100);
1124 });
1108});1125});
11091126