git.delta.rocks / unique-network / refs/commits / 026d602cee67

difftreelog

tests: add tests for setOffchainSchema

Yaroslav Bolyukin2021-02-15parent: #4833587.patch.diff
in: master

2 files changed

modifiedtests/package.jsondiffbeforeafterboth
41 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",41 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
42 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",42 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
43 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",43 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
44 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",
44 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts"45 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts"
45 },46 },
46 "author": "",47 "author": "",
addedtests/src/setOffchainSchema.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/setOffchainSchema.test.ts
@@ -0,0 +1,80 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import usingApi from './substrate/substrate-api';
+import {
+  createCollectionExpectSuccess,
+  destroyCollectionExpectSuccess,
+  findNotExistingCollection,
+  queryCollectionExpectSuccess,
+  setOffchainSchemaExpectFailure,
+  setOffchainSchemaExpectSuccess,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+const DATA = [1, 2, 3, 4];
+
+describe('Integration Test setOffchainSchema', () => {
+  let alice: IKeyringPair;
+
+  before(async () => {
+    await usingApi(async () => {
+      alice = privateKey('//Alice');
+    });
+  });
+
+  it('execute setOffchainSchema, verify data was set', async () => {
+    const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+    await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);
+    const collection = await queryCollectionExpectSuccess(collectionId);
+
+    expect(Array.from(collection.OffchainSchema)).to.be.deep.equal(DATA);
+  });
+});
+
+describe('Negative Integration Test setOffchainSchema', () => {
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+
+  let validCollectionId: number;
+
+  before(async () => {
+    await usingApi(async () => {
+      alice = privateKey('//Alice');
+      bob = privateKey('//Bob');
+
+      validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+    });
+  });
+
+  it('fails on not existing collection id', async () => {
+    const nonExistingCollectionId = await usingApi(findNotExistingCollection);
+
+    await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);
+  });
+
+  it('fails on destroyed collection id', async () => {
+    const destroyedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+    await destroyCollectionExpectSuccess(destroyedCollectionId);
+
+    await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);
+  });
+
+  it('fails on too long data', async () => {
+    const tooLongData = new Array(4097).fill(0xff);
+
+    await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);
+  });
+
+  it('fails on execution by non-owner', async () => {
+    await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);
+  });
+});