git.delta.rocks / unique-network / refs/commits / 7c95ae985972

difftreelog

CORE-161. Change collection owner integration tests

str-mv2021-07-29parent: #e961e84.patch.diff
in: master

3 files changed

modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
8import privateKey from './substrate/privateKey';8import privateKey from './substrate/privateKey';
9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
10import { createCollectionExpectSuccess, addCollectionAdminExpectSuccess } from './util/helpers';10import { createCollectionExpectSuccess,
11 addCollectionAdminExpectSuccess,
12 setCollectionSponsorExpectSuccess,
13 confirmSponsorshipExpectSuccess,
14 removeCollectionSponsorExpectSuccess,
15 enableWhiteListExpectSuccess,
16 setMintPermissionExpectSuccess,
17 destroyCollectionExpectSuccess,
18} from './util/helpers';
1119
12chai.use(chaiAsPromised);20chai.use(chaiAsPromised);
31 });39 });
32});40});
41
42describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {
43 it('Changing the owner of the collection is not allowed for the former owner', async () => {
44 await usingApi(async api => {
45 const collectionId = await createCollectionExpectSuccess();
46 const alice = privateKey('//Alice');
47 const bob = privateKey('//Bob');
48
49 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
50 expect(collection.Owner).to.be.deep.eq(alice.address);
51
52 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
53 await submitTransactionAsync(alice, changeOwnerTx);
54
55 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
56 await expect(submitTransactionAsync(alice, badChangeOwnerTx)).to.be.rejected;
57
58 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
59 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
60 });
61 });
62
63 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {
64 await usingApi(async api => {
65 const collectionId = await createCollectionExpectSuccess();
66 const alice = privateKey('//Alice');
67 const bob = privateKey('//Bob');
68 const charlie = privateKey('//Charlie');
69
70 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
71 expect(collection.Owner).to.be.deep.eq(alice.address);
72
73 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
74 await submitTransactionAsync(alice, changeOwnerTx);
75
76 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
77 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
78
79 // After changing the owner of the collection, all privileged methods are available to the new owner
80 // The new owner of the collection has access to sponsorship management operations in the collection
81 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');
82 await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');
83 await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');
84
85 // The new owner of the collection has access to operations for managing the collection parameters
86 const collectionLimits = {
87 AccountTokenOwnershipLimit: 1,
88 SponsoredMintSize: 1,
89 TokenLimit: 1,
90 SponsorTimeout: 1,
91 OwnerCanTransfer: true,
92 OwnerCanDestroy: true,
93 };
94 const tx1 = api.tx.nft.setCollectionLimits(
95 collectionId,
96 collectionLimits,
97 );
98 await submitTransactionAsync(bob, tx1);
99
100 await enableWhiteListExpectSuccess(bob, collectionId);
101 await setMintPermissionExpectSuccess(bob, collectionId, true);
102 await destroyCollectionExpectSuccess(collectionId, '//Bob');
103 });
104 });
105});
33106
34describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {107describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
35 it('Not owner can\'t change owner.', async () => {108 it('Not owner can\'t change owner.', async () => {
82 });155 });
83 });156 });
157
158 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {
159 await usingApi(async api => {
160 const collectionId = await createCollectionExpectSuccess();
161 const alice = privateKey('//Alice');
162 const bob = privateKey('//Bob');
163 const charlie = privateKey('//Charlie');
164
165 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
166 expect(collection.Owner).to.be.deep.eq(alice.address);
167
168 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
169 await submitTransactionAsync(alice, changeOwnerTx);
170
171 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
172 await expect(submitTransactionAsync(alice, badChangeOwnerTx)).to.be.rejected;
173
174 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
175 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
176
177 await expect(setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Alice')).to.be.rejected;
178 await expect(confirmSponsorshipExpectSuccess(collectionId, '//Alice')).to.be.rejected;
179 await expect(removeCollectionSponsorExpectSuccess(collectionId, '//Alice')).to.be.rejected;
180
181 const collectionLimits = {
182 AccountTokenOwnershipLimit: 1,
183 SponsoredMintSize: 1,
184 TokenLimit: 1,
185 SponsorTimeout: 1,
186 OwnerCanTransfer: true,
187 OwnerCanDestroy: true,
188 };
189 const tx1 = api.tx.nft.setCollectionLimits(
190 collectionId,
191 collectionLimits,
192 );
193 await expect(submitTransactionAsync(alice, tx1)).to.be.rejected;
194
195 await expect(enableWhiteListExpectSuccess(alice, collectionId)).to.be.rejected;
196 await expect(setMintPermissionExpectSuccess(alice, collectionId, true)).to.be.rejected;
197 await expect(destroyCollectionExpectSuccess(collectionId, '//Alice')).to.be.rejected;
198 });
199 });
84});200});
85201
modifiedtests/src/setChainLimits.test.tsdiffbeforeafterboth
13 IChainLimits,13 IChainLimits,
14} from './util/helpers';14} from './util/helpers';
1515
16describe.only('Negative Integration Test setChainLimits', () => {16describe('Negative Integration Test setChainLimits', () => {
17 let alice: IKeyringPair;17 let alice: IKeyringPair;
18 let bob: IKeyringPair;18 let bob: IKeyringPair;
19 let dave: IKeyringPair;19 let dave: IKeyringPair;
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
431 });431 });
432}432}
433433
434export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {434export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {
435 await usingApi(async (api) => {435 await usingApi(async (api) => {
436436
437 // Run the transaction437 // Run the transaction
438 const alicePrivateKey = privateKey('//Alice');438 const senderPrivateKey = privateKey(sender);
439 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);439 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
440 const events = await submitTransactionAsync(alicePrivateKey, tx);440 const events = await submitTransactionAsync(senderPrivateKey, tx);
441 const result = getGenericResult(events);441 const result = getGenericResult(events);
442442
443 // Get the collection443 // Get the collection
451 });451 });
452}452}
453453
454export async function removeCollectionSponsorExpectSuccess(collectionId: number) {454export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {
455 await usingApi(async (api) => {455 await usingApi(async (api) => {
456456
457 // Run the transaction457 // Run the transaction
458 const alicePrivateKey = privateKey('//Alice');458 const alicePrivateKey = privateKey(sender);
459 const tx = api.tx.nft.removeCollectionSponsor(collectionId);459 const tx = api.tx.nft.removeCollectionSponsor(collectionId);
460 const events = await submitTransactionAsync(alicePrivateKey, tx);460 const events = await submitTransactionAsync(alicePrivateKey, tx);
461 const result = getGenericResult(events);461 const result = getGenericResult(events);