difftreelog
tests: fix collection info getting
in: master
10 files changed
tests/package.jsondiffbeforeafterboth44 "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",tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth21 const alice = privateKey('//Alice');
21 const alice = privateKey('//Alice');22 const bob = privateKey('//Bob');
22 const bob = privateKey('//Bob');23
2324 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
2627 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
4142 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
4445 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
45 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);tests/src/change-collection-owner.test.tsdiffbeforeafterboth19 const alice = privateKey('//Alice');19 const alice = privateKey('//Alice');20 const bob = privateKey('//Bob');20 const bob = privateKey('//Bob');212122 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);242425 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);272728 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;434344 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);464647 // 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.)tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth19 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 Bob25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);tests/src/setCollectionLimits.test.tsdiffbeforeafterboth616162 // tslint:disable-next-line:no-unused-expression62 // tslint:disable-next-line:no-unused-expression63 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});tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth36 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);535354 });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;tests/src/setOffchainSchema.test.tsdiffbeforeafterboth36 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);36 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);37 const collection = await queryCollectionExpectSuccess(collectionId);37 const collection = await queryCollectionExpectSuccess(collectionId);383839 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});4242tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth36 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
5354 });
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;tests/src/types.tsdiffbeforeafterboth13 Description: [BN, BN]; // utf1613 Description: [BN, BN]; // utf1614 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 };tests/src/util/helpers.tsdiffbeforeafterboth212 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);212 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);213213214 // Get the collection214 // Get the collection215 const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();215 const collection: any = (await api.query.nft.collectionById(result.collectionId)).toJSON();216216217 // What to expect217 // What to expect218 // tslint:disable-next-line:no-unused-expression218 // tslint:disable-next-line:no-unused-expression324 const result = getDestroyResult(events);324 const result = getDestroyResult(events);325325326 // Get the collection326 // Get the collection327 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();327 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();328328329 // What to expect329 // What to expect330 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}335334336export 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}341340373 const result = getGenericResult(events);372 const result = getGenericResult(events);374373375 // Get the collection374 // Get the collection376 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();375 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();377376378 // What to expect377 // What to expect379 expect(result.success).to.be.true;378 expect(result.success).to.be.true;392 const result = getGenericResult(events);391 const result = getGenericResult(events);393392394 // Get the collection393 // Get the collection395 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();394 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();396395397 // What to expect396 // What to expect398 expect(result.success).to.be.true;397 expect(result.success).to.be.true;431 const result = getGenericResult(events);430 const result = getGenericResult(events);432431433 // Get the collection432 // Get the collection434 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();433 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();435434436 // What to expect435 // What to expect437 expect(result.success).to.be.true;436 expect(result.success).to.be.true;838 const result = getGenericResult(events);837 const result = getGenericResult(events);839838840 // Get the collection839 // Get the collection841 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();840 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();842841843 // What to expect842 // What to expect844 // tslint:disable-next-line:no-unused-expression843 // tslint:disable-next-line:no-unused-expression864 const result = getGenericResult(events);863 const result = getGenericResult(events);865864866 // Get the collection865 // Get the collection867 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();866 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();868867869 // What to expect868 // What to expect870 // tslint:disable-next-line:no-unused-expression869 // tslint:disable-next-line:no-unused-expression946945947export 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};951950952export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {951export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {956955957export 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