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

difftreelog

change-collection-owner migrated

rkv2022-09-09parent: #5401624.patch.diff
in: master

1 file changed

modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';
17import chai from 'chai';18import chai from 'chai';
18import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';
19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
20import {createCollectionExpectSuccess,20import {usingPlaygrounds} from './util/playgrounds';
21 addCollectionAdminExpectSuccess,
22 setCollectionSponsorExpectSuccess,
23 confirmSponsorshipExpectSuccess,
24 removeCollectionSponsorExpectSuccess,
25 enableAllowListExpectSuccess,
26 setMintPermissionExpectSuccess,
27 destroyCollectionExpectSuccess,
28 setCollectionSponsorExpectFailure,
29 confirmSponsorshipExpectFailure,
30 removeCollectionSponsorExpectFailure,
31 enableAllowListExpectFail,
32 setMintPermissionExpectFailure,
33 destroyCollectionExpectFailure,
34 setPublicAccessModeExpectSuccess,
35 queryCollectionExpectSuccess,
36} from './util/helpers';
3721
38chai.use(chaiAsPromised);22chai.use(chaiAsPromised);
39const expect = chai.expect;23const expect = chai.expect;
24
25let donor: IKeyringPair;
26
27before(async () => {
28 await usingPlaygrounds(async (_, privateKey) => {
29 donor = privateKey('//Alice');
30 });
31});
4032
41describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {33describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
34 let alice: IKeyringPair;
35 let bob: IKeyringPair;
36
37 before(async () => {
38 await usingPlaygrounds(async (helper) => {
39 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
40 });
41 });
42
42 it('Changing owner changes owner address', async () => {43 it('Changing owner changes owner address', async () => {
43 await usingApi(async (api, privateKeyWrapper) => {44 await usingPlaygrounds(async (helper) => {
44 const collectionId = await createCollectionExpectSuccess();45 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
45 const alice = privateKeyWrapper('//Alice');
46 const bob = privateKeyWrapper('//Bob');
47
48 const collection =await queryCollectionExpectSuccess(api, collectionId);46 const beforeChanging = await helper.collection.getData(collection.collectionId);
49 expect(collection.owner.toString()).to.be.deep.eq(alice.address);47 expect(beforeChanging?.normalizedOwner).to.be.equal(alice.address);
5048
51 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);49 await collection.changeOwner(alice, bob.address);
52 await submitTransactionAsync(alice, changeOwnerTx);
53
54 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);50 const afterChanging = await helper.collection.getData(collection.collectionId);
55 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);51 expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);
56 });52 });
57 });53 });
58});54});
5955
60describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {56describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {
57 let alice: IKeyringPair;
58 let bob: IKeyringPair;
59 let charlie: IKeyringPair;
60
61 before(async () => {
62 await usingPlaygrounds(async (helper) => {
63 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
64 });
65 });
66
61 it('Changing the owner of the collection is not allowed for the former owner', async () => {67 it('Changing the owner of the collection is not allowed for the former owner', async () => {
62 await usingApi(async (api, privateKeyWrapper) => {68 await usingPlaygrounds(async (helper) => {
63 const collectionId = await createCollectionExpectSuccess();
64 const alice = privateKeyWrapper('//Alice');
65 const bob = privateKeyWrapper('//Bob');
66
67 const collection = await queryCollectionExpectSuccess(api, collectionId);69 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
68 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
6970
70 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);71 await collection.changeOwner(alice, bob.address);
71 await submitTransactionAsync(alice, changeOwnerTx);
7272
73 const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);73 const changeOwnerTx = async () => collection.changeOwner(alice, alice.address);
74 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;74 await expect(changeOwnerTx()).to.be.rejected;
7575
76 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);76 const afterChanging = await helper.collection.getData(collection.collectionId);
77 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);77 expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);
78 });78 });
79 });79 });
8080
81 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {81 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {
82 await usingApi(async (api, privateKeyWrapper) => {82 await usingPlaygrounds(async (helper) => {
83 const collectionId = await createCollectionExpectSuccess();
84 const alice = privateKeyWrapper('//Alice');
85 const bob = privateKeyWrapper('//Bob');
86 const charlie = privateKeyWrapper('//Charlie');
87
88 const collection = await queryCollectionExpectSuccess(api, collectionId);83 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
89 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
90
91 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);84 await collection.changeOwner(alice, bob.address);
92 await submitTransactionAsync(alice, changeOwnerTx);
9385
94 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);86 const afterChanging = await helper.collection.getData(collection.collectionId);
95 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);87 expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);
9688
97 // After changing the owner of the collection, all privileged methods are available to the new owner
98 // The new owner of the collection has access to sponsorship management operations in the collection
99 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');89 await collection.setSponsor(bob, charlie.address);
100 await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');90 await collection.confirmSponsorship(charlie);
101 await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');91 await collection.removeSponsor(bob);
102
103 // The new owner of the collection has access to operations for managing the collection parameters
104 const collectionLimits = {92 const limits = {
105 accountTokenOwnershipLimit: 1,93 accountTokenOwnershipLimit: 1,
106 sponsoredMintSize: 1,
107 tokenLimit: 1,94 tokenLimit: 1,
108 sponsorTransferTimeout: 1,95 sponsorTransferTimeout: 1,
109 ownerCanTransfer: true,96 ownerCanDestroy: true,
110 ownerCanDestroy: true,97 ownerCanTransfer: true,
111 };98 };
99
100 await collection.setLimits(bob, limits);
112 const tx1 = api.tx.unique.setCollectionLimits(101 const gotLimits = await collection.getEffectiveLimits();
113 collectionId,
114 collectionLimits,
115 );
116 await submitTransactionAsync(bob, tx1);102 expect(gotLimits).to.be.deep.contains(limits);
117103
118 await setPublicAccessModeExpectSuccess(bob, collectionId, 'AllowList');104 await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});
105
119 await enableAllowListExpectSuccess(bob, collectionId);106 await collection.burn(bob);
120 await setMintPermissionExpectSuccess(bob, collectionId, true);107 const collectionData = await helper.collection.getData(collection.collectionId);
121 await destroyCollectionExpectSuccess(collectionId, '//Bob');108 expect(collectionData).to.be.null;
122 });109 });
123 });110 });
124111
125 it('New collectionOwner has access to changeCollectionOwner', async () => {112 it('New collectionOwner has access to changeCollectionOwner', async () => {
126 await usingApi(async (api, privateKeyWrapper) => {113 await usingPlaygrounds(async (helper) => {
127 const collectionId = await createCollectionExpectSuccess();
128 const alice = privateKeyWrapper('//Alice');
129 const bob = privateKeyWrapper('//Bob');
130 const charlie = privateKeyWrapper('//Charlie');
131
132 const collection = await queryCollectionExpectSuccess(api, collectionId);114 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
133 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
134
135 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);115 await collection.changeOwner(alice, bob.address);
136 await submitTransactionAsync(alice, changeOwnerTx);
137
138 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
139 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
140
141 const changeOwnerTx2 = api.tx.unique.changeCollectionOwner(collectionId, charlie.address);116 await collection.changeOwner(bob, charlie.address);
142 await submitTransactionAsync(bob, changeOwnerTx2);
143
144 // ownership lost
145 const collectionAfterOwnerChange2 = await queryCollectionExpectSuccess(api, collectionId);117 const collectionData = await collection.getData();
146 expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);118 expect(collectionData?.normalizedOwner).to.be.equal(charlie.address);
147 });119 });
148 });120 });
149});121});
150122
151describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {123describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
124 let alice: IKeyringPair;
125 let bob: IKeyringPair;
126 let charlie: IKeyringPair;
127
128 before(async () => {
129 await usingPlaygrounds(async (helper) => {
130 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
131 });
132 });
133
152 it('Not owner can\'t change owner.', async () => {134 it('Not owner can\'t change owner.', async () => {
153 await usingApi(async (api, privateKeyWrapper) => {135 await usingPlaygrounds(async (helper) => {
154 const collectionId = await createCollectionExpectSuccess();136 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
155 const alice = privateKeyWrapper('//Alice');
156 const bob = privateKeyWrapper('//Bob');
157
158 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);137 const changeOwnerTx = async () => collection.changeOwner(bob, bob.address);
159 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;138 await expect(changeOwnerTx()).to.be.rejected;
160
161 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
162 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);
163
164 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
165 await createCollectionExpectSuccess();
166 });139 });
167 });140 });
168141
169 it('Collection admin can\'t change owner.', async () => {142 it('Collection admin can\'t change owner.', async () => {
170 await usingApi(async (api, privateKeyWrapper) => {143 await usingPlaygrounds(async (helper) => {
171 const collectionId = await createCollectionExpectSuccess();144 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
172 const alice = privateKeyWrapper('//Alice');
173 const bob = privateKeyWrapper('//Bob');
174
175 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);145 await collection.addAdmin(alice, {Substrate: bob.address});
176
177 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);146 const changeOwnerTx = async () => collection.changeOwner(bob, bob.address);
178 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;147 await expect(changeOwnerTx()).to.be.rejected;
179
180 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
181 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);
182
183 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
184 await createCollectionExpectSuccess();
185 });148 });
186 });149 });
187150
188 it('Can\'t change owner of a non-existing collection.', async () => {151 it('Can\'t change owner of a non-existing collection.', async () => {
189 await usingApi(async (api, privateKeyWrapper) => {152 await usingPlaygrounds(async (helper) => {
190 const collectionId = (1<<32) - 1;153 const collectionId = (1 << 32) - 1;
191 const alice = privateKeyWrapper('//Alice');
192 const bob = privateKeyWrapper('//Bob');
193
194 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);154 const changeOwnerTx = async () => helper.collection.changeOwner(bob, collectionId, bob.address);
195 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;155 await expect(changeOwnerTx()).to.be.rejected;
196
197 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
198 await createCollectionExpectSuccess();
199 });156 });
200 });157 });
201158
202 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {159 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {
203 await usingApi(async (api, privateKeyWrapper) => {160 await usingPlaygrounds(async (helper) => {
204 const collectionId = await createCollectionExpectSuccess();161 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
205 const alice = privateKeyWrapper('//Alice');162 await collection.changeOwner(alice, bob.address);
163
206 const bob = privateKeyWrapper('//Bob');164 const changeOwnerTx = async () => collection.changeOwner(alice, alice.address);
207 const charlie = privateKeyWrapper('//Charlie');165 await expect(changeOwnerTx()).to.be.rejected;
208166
209 const collection = await queryCollectionExpectSuccess(api, collectionId);167 const afterChanging = await helper.collection.getData(collection.collectionId);
210 expect(collection.owner.toString()).to.be.deep.eq(alice.address);168 expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);
211169
212 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);170 const setSponsorTx = async () => collection.setSponsor(alice, charlie.address);
213 await submitTransactionAsync(alice, changeOwnerTx);171 const confirmSponsorshipTx = async () => collection.confirmSponsorship(alice);
214
215 const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);172 const removeSponsorTx = async () => collection.removeSponsor(alice);
216 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;173 await expect(setSponsorTx()).to.be.rejected;
217
218 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);
219 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);174 await expect(confirmSponsorshipTx()).to.be.rejected;
220
221 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');175 await expect(removeSponsorTx()).to.be.rejected;
222 await confirmSponsorshipExpectFailure(collectionId, '//Alice');
223 await removeCollectionSponsorExpectFailure(collectionId, '//Alice');
224176
225 const collectionLimits = {177 const limits = {
226 accountTokenOwnershipLimit: 1,178 accountTokenOwnershipLimit: 1,
227 sponsoredMintSize: 1,
228 tokenLimit: 1,179 tokenLimit: 1,
229 sponsorTransferTimeout: 1,180 sponsorTransferTimeout: 1,
230 ownerCanTransfer: true,181 ownerCanDestroy: true,
231 ownerCanDestroy: true,182 ownerCanTransfer: true,
232 };183 };
184
233 const tx1 = api.tx.unique.setCollectionLimits(185 const setLimitsTx = async () => collection.setLimits(alice, limits);
234 collectionId,
235 collectionLimits,
236 );
237 await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;186 await expect(setLimitsTx()).to.be.rejected;
238187
239 await enableAllowListExpectFail(alice, collectionId);188 const setPermissionTx = async () => collection.setPermissions(alice, {access: 'AllowList', mintMode: true});
189 await expect(setPermissionTx()).to.be.rejected;
190
240 await setMintPermissionExpectFailure(alice, collectionId, true);191 const burnTx = async () => collection.burn(alice);
241 await destroyCollectionExpectFailure(collectionId, '//Alice');192 await expect(burnTx()).to.be.rejected;
242 });193 });
243 });194 });
244});195});