git.delta.rocks / unique-network / refs/commits / e2bfa5307037

difftreelog

test rmrk integration

Fahrrader2022-06-09parent: #7af7cfe.patch.diff
in: master

1 file changed

modifiedtests/src/rmrk/rmrk.test.tsdiffbeforeafterboth
2import privateKey from '../substrate/privateKey';2import privateKey from '../substrate/privateKey';
3import usingApi, {executeTransaction} from '../substrate/substrate-api';3import usingApi, {executeTransaction} from '../substrate/substrate-api';
4import {4import {
5 createCollectionExpectSuccess,
6 createItemExpectSuccess,
5 getCreateCollectionResult,7 getCreateCollectionResult,
6 getDetailedCollectionInfo,8 getDetailedCollectionInfo,
7 getGenericResult,9 getGenericResult,
10 normalizeAccountId,
8} from '../util/helpers';11} from '../util/helpers';
9import {IKeyringPair} from '@polkadot/types/types';12import {IKeyringPair} from '@polkadot/types/types';
13import {ApiPromise} from '@polkadot/api';
1014
11let alice: IKeyringPair;15let alice: IKeyringPair;
12let bob: IKeyringPair;16let bob: IKeyringPair;
17
18async function createRmrkCollection(api: ApiPromise, sender: IKeyringPair): Promise<{uniqueId: number, rmrkId: number}> {
19 const tx = api.tx.rmrkCore.createCollection('metadata', null, 'symbol');
20 const events = await executeTransaction(api, sender, tx);
21
22 const uniqueResult = getCreateCollectionResult(events);
23 const rmrkResult = getGenericResult(events, 'rmrkCore', 'CollectionCreated', (data) => {
24 return parseInt(data[1].toString(), 10);
25 });
26
27 return {
28 uniqueId: uniqueResult.collectionId,
29 rmrkId: rmrkResult.data!,
30 };
31}
32
33async function createRmrkNft(api: ApiPromise, sender: IKeyringPair, collectionId: number): Promise<number> {
34 const tx = api.tx.rmrkCore.mintNft(
35 sender.address,
36 collectionId,
37 sender.address,
38 null,
39 'nft-metadata',
40 true,
41 );
42 const events = await executeTransaction(api, sender, tx);
43 const result = getGenericResult(events, 'rmrkCore', 'NftMinted', (data) => {
44 return parseInt(data[2].toString(), 10);
45 });
46
47 return result.data!;
48}
49
50describe('RMRK External Integration Test', () => {
51 before(async () => {
52 await usingApi(async () => {
53 alice = privateKey('//Alice');
54 });
55 });
56
57 it('Creates a new RMRK collection that is mapped to a different ID and is tagged as external', async () => {
58 await usingApi(async api => {
59 // throwaway collection to bump last Unique collection ID to test ID mapping
60 await createCollectionExpectSuccess();
61
62 const collectionIds = await createRmrkCollection(api, alice);
63
64 expect(collectionIds.rmrkId).to.be.lessThan(collectionIds.uniqueId, 'collection ID mapping');
65
66 const collection = (await getDetailedCollectionInfo(api, collectionIds.uniqueId))!;
67 expect(collection.readOnly.toHuman(), 'tagged external').to.be.true;
68 });
69 });
70});
1371
14describe('RMRK External Integration Test', () => {72describe('Negative Integration Test: External Collections, Internal Ops', () => {
73 let uniqueCollectionId: number;
74 let rmrkCollectionId: number;
75 let rmrkNftId: number;
76
15 before(async () => {77 before(async () => {
16 await usingApi(async () => {78 await usingApi(async api => {
17 alice = privateKey('//Alice');79 alice = privateKey('//Alice');
18 bob = privateKey('//Bob');80 bob = privateKey('//Bob');
81
82 const collectionIds = await createRmrkCollection(api, alice);
83 uniqueCollectionId = collectionIds.uniqueId;
84 rmrkCollectionId = collectionIds.rmrkId;
85
86 rmrkNftId = await createRmrkNft(api, alice, rmrkCollectionId);
19 });87 });
20 });88 });
2189
22 it('Creates a new RMRK collection that is tagged as external', async () => {90 it('[Negative] Forbids Unique operations with an external collection, handled by dispatch_call', async () => {
23 await usingApi(async api => {91 await usingApi(async api => {
92 // Collection item creation
93
94 const txCreateItem = api.tx.unique.createItem(uniqueCollectionId, normalizeAccountId(alice), 'NFT');
95 await expect(executeTransaction(api, alice, txCreateItem), 'creating item')
96 .to.be.rejectedWith(/common\.CollectionIsExternal/);
97
98 const txCreateMultipleItems = api.tx.unique.createMultipleItems(uniqueCollectionId, normalizeAccountId(alice), [{NFT: {}}, {NFT: {}}]);
99 await expect(executeTransaction(api, alice, txCreateMultipleItems), 'creating multiple')
100 .to.be.rejectedWith(/common\.CollectionIsExternal/);
101
102 const txCreateMultipleItemsEx = api.tx.unique.createMultipleItemsEx(uniqueCollectionId, {NFT: [{}]});
103 await expect(executeTransaction(api, alice, txCreateMultipleItemsEx), 'creating multiple ex')
104 .to.be.rejectedWith(/common\.CollectionIsExternal/);
105
106 // Collection properties
107
24 const tx = api.tx.rmrkCore.createCollection('no-limit-metadata', null, 'no-limit-symbol');108 const txSetCollectionProperties = api.tx.unique.setCollectionProperties(uniqueCollectionId, [{key: 'a', value: '1'}, {key: 'b'}]);
109 await expect(executeTransaction(api, alice, txSetCollectionProperties), 'setting collection properties')
110 .to.be.rejectedWith(/common\.CollectionIsExternal/);
111
25 const events = await executeTransaction(api, alice, tx);112 const txDeleteCollectionProperties = api.tx.unique.deleteCollectionProperties(uniqueCollectionId, ['a']);
113 await expect(executeTransaction(api, alice, txDeleteCollectionProperties), 'deleting collection properties')
114 .to.be.rejectedWith(/common\.CollectionIsExternal/);
115
116 const txSetPropertyPermissions = api.tx.unique.setPropertyPermissions(uniqueCollectionId, [{key: 'a', permission: {mutable: true}}]);
117 await expect(executeTransaction(api, alice, txSetPropertyPermissions), 'setting property permissions')
118 .to.be.rejectedWith(/common\.CollectionIsExternal/);
119
120 // NFT
121
26 const result = getCreateCollectionResult(events);122 const txBurn = api.tx.unique.burnItem(uniqueCollectionId, rmrkNftId, 1);
123 await expect(executeTransaction(api, alice, txBurn), 'burning').to.be.rejectedWith(/common\.CollectionIsExternal/);
27124
28 const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;125 const txBurnFrom = api.tx.unique.burnFrom(uniqueCollectionId, normalizeAccountId(alice), rmrkNftId, 1);
29 expect(collection.readOnly.toHuman()).to.be.true;126 await expect(executeTransaction(api, alice, txBurnFrom), 'burning-from').to.be.rejectedWith(/common\.CollectionIsExternal/);
127
128 const txTransfer = api.tx.unique.transfer(normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);
129 await expect(executeTransaction(api, alice, txTransfer), 'transferring').to.be.rejectedWith(/common\.CollectionIsExternal/);
130
131 const txApprove = api.tx.unique.approve(normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);
132 await expect(executeTransaction(api, alice, txApprove), 'approving').to.be.rejectedWith(/common\.CollectionIsExternal/);
133
134 const txTransferFrom = api.tx.unique.transferFrom(normalizeAccountId(alice), normalizeAccountId(bob), uniqueCollectionId, rmrkNftId, 1);
135 await expect(executeTransaction(api, alice, txTransferFrom), 'transferring-from').to.be.rejectedWith(/common\.CollectionIsExternal/);
136
137 // NFT properties
138
139 const txSetTokenProperties = api.tx.unique.setTokenProperties(uniqueCollectionId, rmrkNftId, [{key: 'a', value: '2'}]);
140 await expect(executeTransaction(api, alice, txSetTokenProperties), 'setting token properties')
141 .to.be.rejectedWith(/common\.CollectionIsExternal/);
142
143 const txDeleteTokenProperties = api.tx.unique.deleteTokenProperties(uniqueCollectionId, rmrkNftId, ['a']);
144 await expect(executeTransaction(api, alice, txDeleteTokenProperties), 'deleting token properties')
145 .to.be.rejectedWith(/common\.CollectionIsExternal/);
30 });146 });
31 });147 });
32148
33 it('[Negative] Forbids NFT operations with an external collection', async () => {149 it('[Negative] Forbids Unique collection operations with an external collection', async () => {
34 await usingApi(async api => {150 await usingApi(async api => {
151 const txDestroyCollection = api.tx.unique.destroyCollection(uniqueCollectionId);
152 await expect(executeTransaction(api, alice, txDestroyCollection), 'destroying collection')
153 .to.be.rejectedWith(/common\.CollectionIsExternal/);
154
155 // Allow list
156
35 const tx1 = api.tx.rmrkCore.createCollection('metadata', null, 'symbol');157 const txAddAllowList = api.tx.unique.addToAllowList(uniqueCollectionId, normalizeAccountId(bob));
158 await expect(executeTransaction(api, alice, txAddAllowList), 'adding to allow list')
159 .to.be.rejectedWith(/common\.CollectionIsExternal/);
160
36 const events1 = await executeTransaction(api, alice, tx1);161 const txRemoveAllowList = api.tx.unique.removeFromAllowList(uniqueCollectionId, normalizeAccountId(bob));
162 await expect(executeTransaction(api, alice, txRemoveAllowList), 'removing from allowlist')
163 .to.be.rejectedWith(/common\.CollectionIsExternal/);
164
165 // Owner / Admin / Sponsor
37166
38 const resultUnique1 = getCreateCollectionResult(events1);167 const txChangeOwner = api.tx.unique.changeCollectionOwner(uniqueCollectionId, bob.address);
168 await expect(executeTransaction(api, alice, txChangeOwner), 'changing owner')
169 .to.be.rejectedWith(/common\.CollectionIsExternal/);
170
39 const uniqueCollectionId = resultUnique1.collectionId;171 const txAddAdmin = api.tx.unique.addCollectionAdmin(uniqueCollectionId, normalizeAccountId(bob));
40
41 const resultRmrk1 = getGenericResult(events1, 'rmrkCore', 'CollectionCreated', (data) => {
42 return parseInt(data[1].toString(), 10);172 await expect(executeTransaction(api, alice, txAddAdmin), 'adding admin')
43 });173 .to.be.rejectedWith(/common\.CollectionIsExternal/);
174
44 const rmrkCollectionId: number = resultRmrk1.data!;175 const txRemoveAdmin = api.tx.unique.removeCollectionAdmin(uniqueCollectionId, normalizeAccountId(bob));
176 await expect(executeTransaction(api, alice, txRemoveAdmin), 'removing admin')
177 .to.be.rejectedWith(/common\.CollectionIsExternal/);
45178
46 const tx2 = api.tx.rmrkCore.mintNft(179 const txAddCollectionSponsor = api.tx.unique.setCollectionSponsor(uniqueCollectionId, bob.address);
47 alice.address,180 await expect(executeTransaction(api, alice, txAddCollectionSponsor), 'setting sponsor')
48 rmrkCollectionId,181 .to.be.rejectedWith(/common\.CollectionIsExternal/);
49 alice.address,182
50 null,
51 'nft-metadata',
52 true,
53 );
54 const events2 = await executeTransaction(api, alice, tx2);183 const txConfirmCollectionSponsor = api.tx.unique.confirmSponsorship(uniqueCollectionId);
184 await expect(executeTransaction(api, alice, txConfirmCollectionSponsor), 'confirming sponsor')
185 .to.be.rejectedWith(/common\.CollectionIsExternal/);
186
187 const txRemoveCollectionSponsor = api.tx.unique.removeCollectionSponsor(uniqueCollectionId);
188 await expect(executeTransaction(api, alice, txRemoveCollectionSponsor), 'removing sponsor')
189 .to.be.rejectedWith(/common\.CollectionIsExternal/);
190
191 // Limits / permissions / transfers
192
55 const result2 = getGenericResult(events2, 'rmrkCore', 'NftMinted', (data) => {193 const txSetTransfers = api.tx.unique.setTransfersEnabledFlag(uniqueCollectionId, true);
56 return parseInt(data[2].toString(), 10);194 await expect(executeTransaction(api, alice, txSetTransfers), 'setting transfers enabled flag')
57 });195 .to.be.rejectedWith(/common\.CollectionIsExternal/);
196
58 const rmrkNftId: number = result2.data!;197 const txSetLimits = api.tx.unique.setCollectionLimits(uniqueCollectionId, {transfersEnabled: false});
198 await expect(executeTransaction(api, alice, txSetLimits), 'setting collection limits')
199 .to.be.rejectedWith(/common\.CollectionIsExternal/);
59200
60 const tx3 = api.tx.unique.burnItem(uniqueCollectionId, rmrkNftId, 1);201 const txSetPermissions = api.tx.unique.setCollectionPermissions(uniqueCollectionId, {access: 'AllowList'});
61 await expect(executeTransaction(api, alice, tx3)).to.be.rejectedWith(/common\.CollectionIsExternal/);202 await expect(executeTransaction(api, alice, txSetPermissions), 'setting collection permissions')
203 .to.be.rejectedWith(/common\.CollectionIsExternal/);
62 });204 });
63 });205 });
64});206});
207
208describe('Negative Integration Test: Internal Collections, External Ops', () => {
209 let collectionId: number;
210 let nftId: number;
211
212 before(async () => {
213 await usingApi(async () => {
214 alice = privateKey('//Alice');
215 bob = privateKey('//Bob');
216
217 collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
218 nftId = await createItemExpectSuccess(alice, collectionId, 'NFT');
219 });
220 });
221
222 it('[Negative] Forbids RMRK operations with the internal collection and NFT (due to the lack of mapping)', async () => {
223 await usingApi(async api => {
224 const txChangeOwner = api.tx.rmrkCore.changeCollectionIssuer(collectionId, bob.address);
225 await expect(executeTransaction(api, alice, txChangeOwner), 'changing collection issuer')
226 .to.be.rejectedWith(/rmrkCore\.CollectionUnknown/);
227
228 const txBurnItem = api.tx.rmrkCore.burnNft(collectionId, nftId);
229 await expect(executeTransaction(api, alice, txBurnItem), 'burning NFT').to.be.rejectedWith(/rmrkCore\.CollectionUnknown/);
230 });
231 });
232});