difftreelog
tests: fix collection info getting
in: master
10 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -44,7 +44,7 @@
"testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
"testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",
"testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",
- "setVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts"
+ "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts"
},
"author": "",
"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.tsdiffbeforeafterboth--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -19,13 +19,13 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const collection: any = (await api.query.nft.collection(collectionId));
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collection.Owner.toString()).to.be.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
- const collectionAfterOwnerChange: any = (await api.query.nft.collection(collectionId));
+ const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collectionAfterOwnerChange.Owner.toString()).to.be.eq(bob.address);
});
});
@@ -41,7 +41,7 @@
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange: any = (await api.query.nft.collection(collectionId));
+ const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collectionAfterOwnerChange.Owner.toString()).to.be.eq(alice.address);
// Verifying that nothing bad happened (network is live, new collections can be created, etc.)
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -19,7 +19,7 @@
const collectionId = await createCollectionExpectSuccess();
const Alice = privateKey('//Alice');
const Bob = privateKey('//Bob');
- const collection: any = (await api.query.nft.collection(collectionId));
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collection.Owner.toString()).to.be.eq(Alice.address);
// first - add collection admin Bob
const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -61,12 +61,12 @@
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- expect(collectionInfo.Limits.AccountTokenOwnershipLimit.toNumber()).to.be.equal(accountTokenOwnershipLimit);
- expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredDataSize);
- expect(collectionInfo.Limits.TokenLimit.toNumber()).to.be.equal(tokenLimit);
- expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsorTimeout);
- expect(collectionInfo.Limits.OwnerCanTransfer.valueOf()).to.be.true;
- expect(collectionInfo.Limits.OwnerCanDestroy.valueOf()).to.be.true;
+ expect(collectionInfo.Limits.AccountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);
+ expect(collectionInfo.Limits.SponsoredDataSize).to.be.equal(sponsoredDataSize);
+ expect(collectionInfo.Limits.TokenLimit).to.be.equal(tokenLimit);
+ expect(collectionInfo.Limits.SponsorTimeout).to.be.equal(sponsorTimeout);
+ expect(collectionInfo.Limits.OwnerCanTransfer).to.be.true;
+ expect(collectionInfo.Limits.OwnerCanDestroy).to.be.true;
});
});
});
tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setConstOnChainSchema.test.ts
+++ b/tests/src/setConstOnChainSchema.test.ts
@@ -36,7 +36,7 @@
it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection: any = (await api.query.nft.collection(collectionId));
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collection.Owner.toString()).to.be.eq(Alice.address);
const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
await submitTransactionAsync(Alice, setShema);
@@ -48,7 +48,7 @@
const collectionId = await createCollectionExpectSuccess();
const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
await submitTransactionAsync(Alice, setShema);
- const collection: any = (await api.query.nft.collection(collectionId));
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);
});
@@ -86,7 +86,7 @@
it('Execute method not on behalf of the collection owner', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection: any = (await api.query.nft.collection(collectionId));
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collection.Owner.toString()).to.be.eq(Alice.address);
const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;
tests/src/setOffchainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setOffchainSchema.test.ts
+++ b/tests/src/setOffchainSchema.test.ts
@@ -36,7 +36,7 @@
await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);
const collection = await queryCollectionExpectSuccess(collectionId);
- expect(Array.from(collection.OffchainSchema)).to.be.deep.equal(DATA);
+ expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
});
});
tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setVariableOnChainSchema.test.ts
+++ b/tests/src/setVariableOnChainSchema.test.ts
@@ -1,96 +1,96 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import { Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import {
- createCollectionExpectSuccess,
- destroyCollectionExpectSuccess,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Schema: any;
-let largeSchema: any;
-
-before(async () => {
- await usingApi(async (api) => {
- const keyring = new Keyring({ type: 'sr25519' });
- Alice = keyring.addFromUri('//Alice');
- Bob = keyring.addFromUri('//Bob');
- Schema = '0x31';
- largeSchema = new Array(4097).fill(0xff);
-
- });
-});
-describe('Integration Test ext. setVariableOnChainSchema()', () => {
-
- it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const collection: any = (await api.query.nft.collection(collectionId));
- expect(collection.Owner.toString()).to.be.eq(Alice.address);
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await submitTransactionAsync(Alice, setSchema);
- });
- });
-
- it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await submitTransactionAsync(Alice, setSchema);
- const collection: any = (await api.query.nft.collection(collectionId));
- expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
-
- });
- });
-});
-
-describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {
-
- it('Set a non-existent collection', async () => {
- await usingApi(async (api) => {
- // tslint:disable-next-line: radix
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
- });
- });
-
- it('Set a previously deleted collection', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- await destroyCollectionExpectSuccess(collectionId);
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
- });
- });
-
- it('Set invalid data in schema (size too large:> 1024b)', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);
- await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
- });
- });
-
- it('Execute method not on behalf of the collection owner', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const collection: any = (await api.query.nft.collection(collectionId));
- expect(collection.Owner.toString()).to.be.eq(Alice.address);
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;
- });
- });
-
-});
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import { Keyring } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import {
+ createCollectionExpectSuccess,
+ destroyCollectionExpectSuccess,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Schema: any;
+let largeSchema: any;
+
+before(async () => {
+ await usingApi(async (api) => {
+ const keyring = new Keyring({ type: 'sr25519' });
+ Alice = keyring.addFromUri('//Alice');
+ Bob = keyring.addFromUri('//Bob');
+ Schema = '0x31';
+ largeSchema = new Array(4097).fill(0xff);
+
+ });
+});
+describe('Integration Test ext. setVariableOnChainSchema()', () => {
+
+ it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ expect(collection.Owner.toString()).to.be.eq(Alice.address);
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
+ await submitTransactionAsync(Alice, setSchema);
+ });
+ });
+
+ it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
+ await submitTransactionAsync(Alice, setSchema);
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
+
+ });
+ });
+});
+
+describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {
+
+ it('Set a non-existent collection', async () => {
+ await usingApi(async (api) => {
+ // tslint:disable-next-line: radix
+ const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
+ await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
+ });
+ });
+
+ it('Set a previously deleted collection', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ await destroyCollectionExpectSuccess(collectionId);
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
+ await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
+ });
+ });
+
+ it('Set invalid data in schema (size too large:> 1024b)', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);
+ await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
+ });
+ });
+
+ it('Execute method not on behalf of the collection owner', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ expect(collection.Owner.toString()).to.be.eq(Alice.address);
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
+ await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;
+ });
+ });
+
+});
tests/src/types.tsdiffbeforeafterboth--- a/tests/src/types.ts
+++ b/tests/src/types.ts
@@ -13,10 +13,11 @@
Description: [BN, BN]; // utf16
isReFungible: boolean;
Limits: {
- AccountTokenOwnershipLimit: BN;
- SponsoredMintSize: BN;
- TokenLimit: BN;
- SponsorTimeout: BN;
+ AccountTokenOwnershipLimit: number;
+ SponsoredDataSize: number;
+ SponsoredDataRateLimit?: number,
+ TokenLimit: number;
+ SponsorTimeout: number;
OwnerCanTransfer: boolean;
OwnerCanDestroy: boolean;
};
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -212,7 +212,7 @@
const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
// Get the collection
- const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();
+ const collection: any = (await api.query.nft.collectionById(result.collectionId)).toJSON();
// What to expect
// tslint:disable-next-line:no-unused-expression
@@ -324,18 +324,17 @@
const result = getDestroyResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
// What to expect
expect(result).to.be.true;
- expect(collection).to.be.not.null;
- expect(collection.Owner).to.be.equal(nullPublicKey);
+ expect(collection).to.be.null;
});
}
export async function queryCollectionLimits(collectionId: number) {
return await usingApi(async (api) => {
- return ((await api.query.nft.collection(collectionId)).toJSON() as any).Limits;
+ return ((await api.query.nft.collectionById(collectionId)).toJSON() as any).Limits;
});
}
@@ -373,7 +372,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
// What to expect
expect(result.success).to.be.true;
@@ -392,7 +391,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
// What to expect
expect(result.success).to.be.true;
@@ -431,7 +430,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
// What to expect
expect(result.success).to.be.true;
@@ -838,7 +837,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
// What to expect
// tslint:disable-next-line:no-unused-expression
@@ -864,7 +863,7 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
// What to expect
// tslint:disable-next-line:no-unused-expression
@@ -946,7 +945,7 @@
export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)
: Promise<ICollectionInterface | null> => {
- return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;
+ return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;
};
export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {
@@ -956,6 +955,6 @@
export async function queryCollectionExpectSuccess(collectionId: number): Promise<ICollectionInterface> {
return await usingApi(async (api) => {
- return (await api.query.nft.collection(collectionId)) as unknown as ICollectionInterface;
+ return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;
});
}