git.delta.rocks / unique-network / refs/commits / 8b9e1d8de76d

difftreelog

tests: fix collection info getting

Yaroslav Bolyukin2021-03-05parent: #353c1c6.patch.diff
in: master

10 files changed

modifiedtests/package.jsondiffbeforeafterboth
44 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",44 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
45 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",45 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",
46 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",46 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",
47 "setVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts"47 "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts"
48 },48 },
49 "author": "",49 "author": "",
50 "license": "SEE LICENSE IN ../LICENSE",50 "license": "SEE LICENSE IN ../LICENSE",
modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
21 const alice = privateKey('//Alice'); 21 const alice = privateKey('//Alice');
22 const bob = privateKey('//Bob'); 22 const bob = privateKey('//Bob');
23 23
24 const collection: any = (await api.query.nft.collection(collectionId)); 24 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
25 expect(collection.Owner.toString()).to.be.eq(alice.address); 25 expect(collection.Owner.toString()).to.be.eq(alice.address);
26 26
27 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, bob.address); 27 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, bob.address);
39 const Bob = privateKey('//Bob'); 39 const Bob = privateKey('//Bob');
40 const Charlie = privateKey('//CHARLIE'); 40 const Charlie = privateKey('//CHARLIE');
41 41
42 const collection: any = (await api.query.nft.collection(collectionId)); 42 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
43 expect(collection.Owner.toString()).to.be.eq(Alice.address); 43 expect(collection.Owner.toString()).to.be.eq(Alice.address);
44 44
45 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); 45 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
19 const alice = privateKey('//Alice');19 const alice = privateKey('//Alice');
20 const bob = privateKey('//Bob');20 const bob = privateKey('//Bob');
2121
22 const collection: any = (await api.query.nft.collection(collectionId));22 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
23 expect(collection.Owner.toString()).to.be.eq(alice.address);23 expect(collection.Owner.toString()).to.be.eq(alice.address);
2424
25 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);25 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
26 await submitTransactionAsync(alice, changeOwnerTx);26 await submitTransactionAsync(alice, changeOwnerTx);
2727
28 const collectionAfterOwnerChange: any = (await api.query.nft.collection(collectionId));28 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
29 expect(collectionAfterOwnerChange.Owner.toString()).to.be.eq(bob.address);29 expect(collectionAfterOwnerChange.Owner.toString()).to.be.eq(bob.address);
30 });30 });
31 });31 });
41 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);41 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
42 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;42 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
4343
44 const collectionAfterOwnerChange: any = (await api.query.nft.collection(collectionId));44 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
45 expect(collectionAfterOwnerChange.Owner.toString()).to.be.eq(alice.address);45 expect(collectionAfterOwnerChange.Owner.toString()).to.be.eq(alice.address);
4646
47 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)47 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
19 const collectionId = await createCollectionExpectSuccess();19 const collectionId = await createCollectionExpectSuccess();
20 const Alice = privateKey('//Alice');20 const Alice = privateKey('//Alice');
21 const Bob = privateKey('//Bob');21 const Bob = privateKey('//Bob');
22 const collection: any = (await api.query.nft.collection(collectionId));22 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
23 expect(collection.Owner.toString()).to.be.eq(Alice.address);23 expect(collection.Owner.toString()).to.be.eq(Alice.address);
24 // first - add collection admin Bob24 // first - add collection admin Bob
25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
6161
62 // tslint:disable-next-line:no-unused-expression62 // tslint:disable-next-line:no-unused-expression
63 expect(result.success).to.be.true;63 expect(result.success).to.be.true;
64 expect(collectionInfo.Limits.AccountTokenOwnershipLimit.toNumber()).to.be.equal(accountTokenOwnershipLimit);64 expect(collectionInfo.Limits.AccountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);
65 expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredDataSize);65 expect(collectionInfo.Limits.SponsoredDataSize).to.be.equal(sponsoredDataSize);
66 expect(collectionInfo.Limits.TokenLimit.toNumber()).to.be.equal(tokenLimit);66 expect(collectionInfo.Limits.TokenLimit).to.be.equal(tokenLimit);
67 expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsorTimeout);67 expect(collectionInfo.Limits.SponsorTimeout).to.be.equal(sponsorTimeout);
68 expect(collectionInfo.Limits.OwnerCanTransfer.valueOf()).to.be.true;68 expect(collectionInfo.Limits.OwnerCanTransfer).to.be.true;
69 expect(collectionInfo.Limits.OwnerCanDestroy.valueOf()).to.be.true;69 expect(collectionInfo.Limits.OwnerCanDestroy).to.be.true;
70 });70 });
71 });71 });
72});72});
modifiedtests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth
36 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {36 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
37 await usingApi(async (api) => {37 await usingApi(async (api) => {
38 const collectionId = await createCollectionExpectSuccess();38 const collectionId = await createCollectionExpectSuccess();
39 const collection: any = (await api.query.nft.collection(collectionId));39 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
40 expect(collection.Owner.toString()).to.be.eq(Alice.address);40 expect(collection.Owner.toString()).to.be.eq(Alice.address);
41 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);41 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
42 await submitTransactionAsync(Alice, setShema);42 await submitTransactionAsync(Alice, setShema);
48 const collectionId = await createCollectionExpectSuccess();48 const collectionId = await createCollectionExpectSuccess();
49 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);49 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
50 await submitTransactionAsync(Alice, setShema);50 await submitTransactionAsync(Alice, setShema);
51 const collection: any = (await api.query.nft.collection(collectionId));51 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
52 expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);52 expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);
5353
54 });54 });
86 it('Execute method not on behalf of the collection owner', async () => {86 it('Execute method not on behalf of the collection owner', async () => {
87 await usingApi(async (api) => {87 await usingApi(async (api) => {
88 const collectionId = await createCollectionExpectSuccess();88 const collectionId = await createCollectionExpectSuccess();
89 const collection: any = (await api.query.nft.collection(collectionId));89 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
90 expect(collection.Owner.toString()).to.be.eq(Alice.address);90 expect(collection.Owner.toString()).to.be.eq(Alice.address);
91 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);91 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
92 await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;92 await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;
modifiedtests/src/setOffchainSchema.test.tsdiffbeforeafterboth
36 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);36 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);
37 const collection = await queryCollectionExpectSuccess(collectionId);37 const collection = await queryCollectionExpectSuccess(collectionId);
3838
39 expect(Array.from(collection.OffchainSchema)).to.be.deep.equal(DATA);39 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
40 });40 });
41});41});
4242
modifiedtests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth
36 it('Run extrinsic with parameters of the collection id, set the scheme', async () => { 36 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
37 await usingApi(async (api) => { 37 await usingApi(async (api) => {
38 const collectionId = await createCollectionExpectSuccess(); 38 const collectionId = await createCollectionExpectSuccess();
39 const collection: any = (await api.query.nft.collection(collectionId)); 39 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
40 expect(collection.Owner.toString()).to.be.eq(Alice.address); 40 expect(collection.Owner.toString()).to.be.eq(Alice.address);
41 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema); 41 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
42 await submitTransactionAsync(Alice, setSchema); 42 await submitTransactionAsync(Alice, setSchema);
48 const collectionId = await createCollectionExpectSuccess(); 48 const collectionId = await createCollectionExpectSuccess();
49 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema); 49 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
50 await submitTransactionAsync(Alice, setSchema); 50 await submitTransactionAsync(Alice, setSchema);
51 const collection: any = (await api.query.nft.collection(collectionId)); 51 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
52 expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema); 52 expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
53 53
54 }); 54 });
86 it('Execute method not on behalf of the collection owner', async () => { 86 it('Execute method not on behalf of the collection owner', async () => {
87 await usingApi(async (api) => { 87 await usingApi(async (api) => {
88 const collectionId = await createCollectionExpectSuccess(); 88 const collectionId = await createCollectionExpectSuccess();
89 const collection: any = (await api.query.nft.collection(collectionId)); 89 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
90 expect(collection.Owner.toString()).to.be.eq(Alice.address); 90 expect(collection.Owner.toString()).to.be.eq(Alice.address);
91 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema); 91 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
92 await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected; 92 await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;
modifiedtests/src/types.tsdiffbeforeafterboth
13 Description: [BN, BN]; // utf1613 Description: [BN, BN]; // utf16
14 isReFungible: boolean;14 isReFungible: boolean;
15 Limits: {15 Limits: {
16 AccountTokenOwnershipLimit: BN;16 AccountTokenOwnershipLimit: number;
17 SponsoredMintSize: BN;17 SponsoredDataSize: number;
18 SponsoredDataRateLimit?: number,
18 TokenLimit: BN;19 TokenLimit: number;
19 SponsorTimeout: BN;20 SponsorTimeout: number;
20 OwnerCanTransfer: boolean;21 OwnerCanTransfer: boolean;
21 OwnerCanDestroy: boolean;22 OwnerCanDestroy: boolean;
22 };23 };
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
212 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);212 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
213213
214 // Get the collection214 // Get the collection
215 const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();215 const collection: any = (await api.query.nft.collectionById(result.collectionId)).toJSON();
216216
217 // What to expect217 // What to expect
218 // tslint:disable-next-line:no-unused-expression218 // tslint:disable-next-line:no-unused-expression
324 const result = getDestroyResult(events);324 const result = getDestroyResult(events);
325325
326 // Get the collection326 // Get the collection
327 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();327 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
328328
329 // What to expect329 // What to expect
330 expect(result).to.be.true;330 expect(result).to.be.true;
331 expect(collection).to.be.not.null;331 expect(collection).to.be.null;
332 expect(collection.Owner).to.be.equal(nullPublicKey);
333 });332 });
334}333}
335334
336export async function queryCollectionLimits(collectionId: number) {335export async function queryCollectionLimits(collectionId: number) {
337 return await usingApi(async (api) => {336 return await usingApi(async (api) => {
338 return ((await api.query.nft.collection(collectionId)).toJSON() as any).Limits;337 return ((await api.query.nft.collectionById(collectionId)).toJSON() as any).Limits;
339 });338 });
340}339}
341340
373 const result = getGenericResult(events);372 const result = getGenericResult(events);
374373
375 // Get the collection374 // Get the collection
376 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();375 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
377376
378 // What to expect377 // What to expect
379 expect(result.success).to.be.true;378 expect(result.success).to.be.true;
392 const result = getGenericResult(events);391 const result = getGenericResult(events);
393392
394 // Get the collection393 // Get the collection
395 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();394 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
396395
397 // What to expect396 // What to expect
398 expect(result.success).to.be.true;397 expect(result.success).to.be.true;
431 const result = getGenericResult(events);430 const result = getGenericResult(events);
432431
433 // Get the collection432 // Get the collection
434 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();433 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
435434
436 // What to expect435 // What to expect
437 expect(result.success).to.be.true;436 expect(result.success).to.be.true;
838 const result = getGenericResult(events);837 const result = getGenericResult(events);
839838
840 // Get the collection839 // Get the collection
841 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();840 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
842841
843 // What to expect842 // What to expect
844 // tslint:disable-next-line:no-unused-expression843 // tslint:disable-next-line:no-unused-expression
864 const result = getGenericResult(events);863 const result = getGenericResult(events);
865864
866 // Get the collection865 // Get the collection
867 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();866 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
868867
869 // What to expect868 // What to expect
870 // tslint:disable-next-line:no-unused-expression869 // tslint:disable-next-line:no-unused-expression
946945
947export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)946export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)
948 : Promise<ICollectionInterface | null> => {947 : Promise<ICollectionInterface | null> => {
949 return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;948 return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;
950};949};
951950
952export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {951export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {
956955
957export async function queryCollectionExpectSuccess(collectionId: number): Promise<ICollectionInterface> {956export async function queryCollectionExpectSuccess(collectionId: number): Promise<ICollectionInterface> {
958 return await usingApi(async (api) => {957 return await usingApi(async (api) => {
959 return (await api.query.nft.collection(collectionId)) as unknown as ICollectionInterface;958 return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;
960 });959 });
961}960}
962961