git.delta.rocks / unique-network / refs/commits / 05b679abd400

difftreelog

source

tests/src/setVariableOnChainSchema.test.ts3.8 KiBsourcehistory
1//
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4//
5
6import { Keyring } from '@polkadot/api';
7import { IKeyringPair } from '@polkadot/types/types';
8import chai from 'chai';
9import chaiAsPromised from 'chai-as-promised';
10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
11import {
12  createCollectionExpectSuccess,
13  destroyCollectionExpectSuccess,
14} from './util/helpers';
15
16chai.use(chaiAsPromised);
17const expect = chai.expect;
18
19let Alice: IKeyringPair;
20let Bob: IKeyringPair;
21let Schema: any;
22let largeSchema: any;
23
24before(async () => {
25  await usingApi(async (api) => {
26    const keyring = new Keyring({ type: 'sr25519' });
27    Alice = keyring.addFromUri('//Alice');
28    Bob = keyring.addFromUri('//Bob');
29    Schema = '0x31';
30    largeSchema = new Array(4097).fill(0xff);
31
32  });
33});
34describe('Integration Test ext. setVariableOnChainSchema()', () => {
35
36  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
37      await usingApi(async (api) => {
38      const collectionId = await createCollectionExpectSuccess();
39      const collection: any = (await api.query.nft.collection(collectionId));
40      expect(collection.Owner.toString()).to.be.eq(Alice.address);
41      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
42      await submitTransactionAsync(Alice, setSchema);
43    });
44  });
45
46  it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
47      await usingApi(async (api) => {
48        const collectionId = await createCollectionExpectSuccess();
49        const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
50        await submitTransactionAsync(Alice, setSchema);
51        const collection: any = (await api.query.nft.collection(collectionId));
52        expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
53
54    });
55  });
56});
57
58describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {
59
60  it('Set a non-existent collection', async () => {
61    await usingApi(async (api) => {
62      // tslint:disable-next-line: radix
63      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
64      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
65      await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
66    });
67  });
68
69  it('Set a previously deleted collection', async () => {
70    await usingApi(async (api) => {
71      const collectionId = await createCollectionExpectSuccess();
72      await destroyCollectionExpectSuccess(collectionId);
73      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
74      await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
75    });
76  });
77
78  it('Set invalid data in schema (size too large:> 1024b)', async () => {
79    await usingApi(async (api) => {
80      const collectionId = await createCollectionExpectSuccess();
81      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);
82      await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
83    });
84  });
85
86  it('Execute method not on behalf of the collection owner', async () => {
87    await usingApi(async (api) => {
88      const collectionId = await createCollectionExpectSuccess();
89      const collection: any = (await api.query.nft.collection(collectionId));
90      expect(collection.Owner.toString()).to.be.eq(Alice.address);
91      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
92      await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;
93    });
94  });
95
96});