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