git.delta.rocks / unique-network / refs/commits / ff11a705d0b0

difftreelog

Merge branch 'develop' into feature/NFTPAR-243_enableContractSponsoring

Yaroslav Bolyukin2021-02-04parents: #f8edc89 #104a9a3.patch.diff
in: master

12 files changed

added.devcontainer/Dockerfilediffbeforeafterboth

no changes

added.devcontainer/devcontainer.jsondiffbeforeafterboth

no changes

modifiedREADME.mddiffbeforeafterboth
5656
57```bash57```bash
58rustup toolchain install 1.49.058rustup toolchain install 1.49.0
59rustup toolchain install nightly-2020-10-0159rustup toolchain install nightly-2020-01-27
60rustup default nightly-2021-01-2760rustup default nightly-2021-01-27
61```61```
6262
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
11221122
1123 // Check approval1123 // Check approval
1124 let mut approval: u128 = 0;1124 let mut approval: u128 = 0;
1125 if <Allowances<T>>::contains_key(collection_id, (item_id, &from, &recipient)) {1125 if <Allowances<T>>::contains_key(collection_id, (item_id, &from, &sender)) {
1126 approval = <Allowances<T>>::get(collection_id, (item_id, &from, &recipient));1126 approval = <Allowances<T>>::get(collection_id, (item_id, &from, &sender));
1127 ensure!(approval >= value, Error::<T>::TokenValueNotEnough);1127 ensure!(approval >= value, Error::<T>::TokenValueNotEnough);
1128 appoved_transfer = true;1128 appoved_transfer = true;
1129 }1129 }
11441144
1145 // Reduce approval by transferred amount or remove if remaining approval drops to 01145 // Reduce approval by transferred amount or remove if remaining approval drops to 0
1146 if approval.checked_sub(value).unwrap_or(0) > 0 {1146 if approval.checked_sub(value).unwrap_or(0) > 0 {
1147 <Allowances<T>>::insert(collection_id, (item_id, &from, &recipient), approval - value);1147 <Allowances<T>>::insert(collection_id, (item_id, &from, &sender), approval - value);
1148 }1148 }
1149 else {1149 else {
1150 <Allowances<T>>::remove(collection_id, (item_id, &from, &recipient));1150 <Allowances<T>>::remove(collection_id, (item_id, &from, &sender));
1151 }1151 }
11521152
1153 match target_collection.mode1153 match target_collection.mode
modifiedtests/README.mddiffbeforeafterboth
22
3## How to run3## How to run
44
51. Run `npm install`.51. Run `yarn install`.
62. Setup a test node. You can do it using `docker-compose up -d` in parent directory.62. Setup a test node. You can do it using `docker-compose up -d` in parent directory.
73. Optional step - configure tests with env variables or by editing [configuration file](src/config.ts).73. Optional step - configure tests with env variables or by editing [configuration file](src/config.ts).
84. Run `npm test`.84. Run `yarn test`.
99
1010
modifiedtests/package.jsondiffbeforeafterboth
25 "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",25 "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",
26 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",26 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
27 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",27 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
28 "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",
28 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",29 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
29 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",30 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
31 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",
30 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",32 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
31 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",33 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",
32 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",34 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
35 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",37 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
36 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",38 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",
37 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",39 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
38 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts"40 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
41 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts"
39 },42 },
40 "author": "",43 "author": "",
41 "license": "SEE LICENSE IN ../LICENSE",44 "license": "SEE LICENSE IN ../LICENSE",
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.
4//4//
5
6import { assert } from 'chai';5import { ApiPromise } from '@polkadot/api';
6import BN from 'bn.js';
7import chai from 'chai';
7import { alicesPublicKey } from './accounts';8import chaiAsPromised from 'chai-as-promised';
8import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';
9import usingApi from './substrate/substrate-api';10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
10import waitNewBlocks from './substrate/wait-new-blocks';11import {
1112 createCollectionExpectSuccess,
13 destroyCollectionExpectSuccess,
14 IReFungibleTokenDataType,
15} from './util/helpers';
16
17chai.use(chaiAsPromised);
12const idCollection = 12;18const expect = chai.expect;
19
20interface ITokenDataType {
21 Owner: number[];
22 ConstData: number[];
23 VariableData: number[];
24}
25
26describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
27 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {
28 await usingApi(async (api: ApiPromise) => {
29 const collectionId = await createCollectionExpectSuccess();
30 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
31 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
32 const Alice = privateKey('//Alice');
33 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
34 const createMultipleItemsTx = await api.tx.nft
35 .createMultipleItems(collectionId, Alice.address, args);
36 await submitTransactionAsync(Alice, createMultipleItemsTx);
37 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
38 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
39 const token1Data = await api.query.nft.nftItemList(collectionId, 1) as unknown as ITokenDataType;
40 const token2Data = await api.query.nft.nftItemList(collectionId, 2) as unknown as ITokenDataType;
41 const token3Data = await api.query.nft.nftItemList(collectionId, 3) as unknown as ITokenDataType;
42
43 expect(token1Data.Owner.toString()).to.be.equal(Alice.address);
44 expect(token2Data.Owner.toString()).to.be.equal(Alice.address);
45 expect(token3Data.Owner.toString()).to.be.equal(Alice.address);
46
47 expect(token1Data.ConstData.toString()).to.be.equal('0x31');
48 expect(token2Data.ConstData.toString()).to.be.equal('0x32');
49 expect(token3Data.ConstData.toString()).to.be.equal('0x33');
50
51 expect(token1Data.VariableData.toString()).to.be.equal('0x31');
52 expect(token2Data.VariableData.toString()).to.be.equal('0x32');
53 expect(token3Data.VariableData.toString()).to.be.equal('0x33');
54 });
55 });
56
57 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {
58 await usingApi(async (api: ApiPromise) => {
59 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
60 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
61 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
62 const Alice = privateKey('//Alice');
63 const args = [
64 { Refungible: ['0x31', '0x31'] },
65 { Refungible: ['0x32', '0x32'] },
66 { Refungible: ['0x33', '0x33'] },
67 ];
68 const createMultipleItemsTx = await api.tx.nft
69 .createMultipleItems(collectionId, Alice.address, args);
70 await submitTransactionAsync(Alice, createMultipleItemsTx);
71 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
72 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
73 const token1Data = await api.query.nft.reFungibleItemList(collectionId, 1) as unknown as IReFungibleTokenDataType;
74 const token2Data = await api.query.nft.reFungibleItemList(collectionId, 2) as unknown as IReFungibleTokenDataType;
75 const token3Data = await api.query.nft.reFungibleItemList(collectionId, 3) as unknown as IReFungibleTokenDataType;
76
77 expect(token1Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);
78 expect(token1Data.Owner[0].Fraction.toNumber()).to.be.equal(1);
79
80 expect(token2Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);
81 expect(token2Data.Owner[0].Fraction.toNumber()).to.be.equal(1);
82
83 expect(token3Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);
84 expect(token3Data.Owner[0].Fraction.toNumber()).to.be.equal(1);
85
86 expect(token1Data.ConstData.toString()).to.be.equal('0x31');
87 expect(token2Data.ConstData.toString()).to.be.equal('0x32');
88 expect(token3Data.ConstData.toString()).to.be.equal('0x33');
89
90 expect(token1Data.VariableData.toString()).to.be.equal('0x31');
91 expect(token2Data.VariableData.toString()).to.be.equal('0x32');
92 expect(token3Data.VariableData.toString()).to.be.equal('0x33');
93 });
94 });
95});
1396
14describe.skip('integration test: ext. createMultipleItems():', () => {97describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
15 it('Create two NFT tokens in active NFT collection', async () => {98 it('Create token with not existing type', async () => {
16 await usingApi(async (api) => {99 await usingApi(async (api: ApiPromise) => {
17 const AitemListIndex = await api.query.nft.itemListIndex(idCollection);100 const collectionId = await createCollectionExpectSuccess();
18 console.log(`itemListIndex count (before): ${AitemListIndex}`);101 const Alice = privateKey('//Alice');
102 try {
19 const args = ['NFT', 'NFT'];103 const args = [{ invalid: null }, { invalid: null }, { invalid: null }];
20 const alicePrivateKey = privateKey('//Alice');
21 const createMultipleItems = await api.tx.nft104 const createMultipleItemsTx = await api.tx.nft
22 .createMultipleItems(idCollection, alicesPublicKey, args)105 .createMultipleItems(collectionId, Alice.address, args);
23 .signAndSend(alicePrivateKey);
24 // tslint:disable-next-line: no-unused-expression
25 assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');
26 console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);
27 await waitNewBlocks(api);
28 const BitemListIndex = await api.query.nft.itemListIndex(idCollection);106 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
29 console.log(`itemListIndex count (after): ${BitemListIndex}`);
30 if (BitemListIndex === AitemListIndex) { assert.fail('Corret token not added in collection!'); }107 } catch (e) {
108 // tslint:disable-next-line:no-unused-expression
109 expect(e).to.be.exist;
110 }
31 });111 });
32 });112 });
113
33 it('(!negative test!) Create two Fungible tokens in active NFT collection', async () => {114 it('Create token in not existing collection', async () => {
34 await usingApi(async (api) => {115 await usingApi(async (api: ApiPromise) => {
35 const AitemListIndex = await api.query.nft.itemListIndex(idCollection);116 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
36 console.log(`itemListIndex count (before): ${AitemListIndex}`);
37 const args = ['Fungible', 'Fungible'];
38 const alicePrivateKey = privateKey('//Alice');117 const Alice = privateKey('//Alice');
39 const createMultipleItems = await api.tx.nft118 const createMultipleItemsTx = await api.tx.nft
40 .createMultipleItems(idCollection, alicesPublicKey, args)119 .createMultipleItems(collectionId, Alice.address, ['NFT', 'NFT', 'NFT']);
41 .signAndSend(alicePrivateKey);
42 // tslint:disable-next-line: no-unused-expression
43 assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');
44 console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);
45 await waitNewBlocks(api);
46 const BitemListIndex = await api.query.nft.itemListIndex(idCollection);120 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
47 console.log(`itemListIndex count (after): ${BitemListIndex}`);
48 if (BitemListIndex > AitemListIndex) { assert.fail('Incorrect token added in collection!'); }
49 });121 });
50 });122 });
123
51 it('(!negative test!) Create two ReFungible tokens in active NFT collection', async () => {124 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {
52 await usingApi(async (api) => {125 await usingApi(async (api: ApiPromise) => {
126 // NFT
53 const AitemListIndex = await api.query.nft.itemListIndex(idCollection);127 const collectionId = await createCollectionExpectSuccess();
54 console.log(`itemListIndex count (before): ${AitemListIndex}`);
55 const args = ['ReFungible', 'ReFungible'];128 const Alice = privateKey('//Alice');
56 const alicePrivateKey = privateKey('//Alice');129 const args = [
130 { nft: ['A'.repeat(2049), 'A'.repeat(2049)] },
131 { nft: ['B'.repeat(2049), 'B'.repeat(2049)] },
132 { nft: ['C'.repeat(2049), 'C'.repeat(2049)] },
133 ];
57 const createMultipleItems = await api.tx.nft134 const createMultipleItemsTx = await api.tx.nft
58 .createMultipleItems(idCollection, alicesPublicKey, args)135 .createMultipleItems(collectionId, Alice.address, args);
59 .signAndSend(alicePrivateKey);
60 // tslint:disable-next-line: no-unused-expression
61 assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');136 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
137
138 // ReFungible
139 const collectionIdReFungible =
62 console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);140 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
141 const argsReFungible = [
63 await waitNewBlocks(api);142 { ReFungible: ['1'.repeat(2049), '1'.repeat(2049)] },
143 { ReFungible: ['2'.repeat(2049), '2'.repeat(2049)] },
144 { ReFungible: ['3'.repeat(2049), '3'.repeat(2049)] },
145 ];
64 const BitemListIndex = await api.query.nft.itemListIndex(idCollection);146 const createMultipleItemsTxFungible = await api.tx.nft
65 console.log(`itemListIndex count (after): ${BitemListIndex}`);147 .createMultipleItems(collectionIdReFungible, Alice.address, argsReFungible);
66 if (BitemListIndex > AitemListIndex) { assert.fail('Incorrect token added in collection!'); }148 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTxFungible)).to.be.rejected;
67 });149 });
68 });150 });
151
152 it('Create tokens with different types', async () => {
153 await usingApi(async (api: ApiPromise) => {
154 const collectionId = await createCollectionExpectSuccess();
155 const Alice = privateKey('//Alice');
156 const createMultipleItemsTx = await api.tx.nft
157 .createMultipleItems(collectionId, Alice.address, ['NFT', 'Fungible', 'ReFungible']);
158 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
159 // garbage collection :-D
160 await destroyCollectionExpectSuccess(collectionId);
161 });
162 });
163
164 it('Create tokens with different data limits <> maximum data limit', async () => {
165 await usingApi(async (api: ApiPromise) => {
166 const collectionId = await createCollectionExpectSuccess();
167 const Alice = privateKey('//Alice');
168 const args = [
169 { nft: ['A', 'A'] },
170 { nft: ['B', 'B'.repeat(2049)] },
171 { nft: ['C'.repeat(2049), 'C'] },
172 ];
173 const createMultipleItemsTx = await api.tx.nft
174 .createMultipleItems(collectionId, Alice.address, args);
175 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
176 });
177 });
69});178});
70179
addedtests/src/removeFromWhiteList.test.tsdiffbeforeafterboth

no changes

addedtests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
123123
124 // console.log('transactionStatus', transactionStatus, 'events', events);124 // console.log('transactionStatus', transactionStatus, 'events', events);
125125
126 if (transactionStatus == TransactionStatus.Success) {126 if (transactionStatus === TransactionStatus.Success) {
127 resolve(events);127 resolve(events);
128 } else if (transactionStatus == TransactionStatus.Fail) {128 } else if (transactionStatus === TransactionStatus.Fail) {
129 reject(events);129 reject(events);
130 }130 }
131 });131 });
modifiedtests/src/util/contracthelpers.tsdiffbeforeafterboth
55
6import chai from "chai";6import chai from "chai";
7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';
8import { submitTransactionAsync } from "../substrate/substrate-api";8import { submitTransactionAsync, submitTransactionExpectFailAsync } from "../substrate/substrate-api";
9import fs from "fs";9import fs from "fs";
10import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from "@polkadot/api-contract";10import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from "@polkadot/api-contract";
11import { IKeyringPair } from "@polkadot/types/types";11import { IKeyringPair } from "@polkadot/types/types";
100 expect(result.success).to.be.true;100 expect(result.success).to.be.true;
101}101}
102
103export async function toggleFlipValueExpectFailure(sender: IKeyringPair, contract: Contract) {
104 const tx = contract.tx.flip(value, gasLimit);
105 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
106}
102107
103function instantiateTransferContract(alice: IKeyringPair, blueprint: Blueprint) : Promise<any> {108function instantiateTransferContract(alice: IKeyringPair, blueprint: Blueprint) : Promise<any> {
104 return new Promise<any>(async (resolve, reject) => {109 return new Promise<any>(async (resolve, reject) => {
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
51 Value: BN;51 Value: BN;
52}52}
5353
54interface IReFungibleTokenDataType {54export interface IReFungibleTokenDataType {
55 Owner: IReFungibleOwner[];55 Owner: IReFungibleOwner[];
56 ConstData: number[];56 ConstData: number[];
57 VariableData: number[];57 VariableData: number[];
414 });414 });
415}415}
416
417export async function setContractSponsoringRateLimitExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {
418 await usingApi(async (api) => {
419 const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);
420 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
421 const result = getGenericResult(events);
422
423 expect(result.success).to.be.false;
424 });
425}
416426
417export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {427export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {
418 await usingApi(async (api) => {428 await usingApi(async (api) => {
492 }502 }
493 const transferFromTx = await api.tx.nft.transferFrom(503 const transferFromTx = await api.tx.nft.transferFrom(
494 accountFrom.address, accountTo.address, collectionId, tokenId, value);504 accountFrom.address, accountTo.address, collectionId, tokenId, value);
495 const events = await submitTransactionAsync(accountFrom, transferFromTx);505 const events = await submitTransactionAsync(accountApproved, transferFromTx);
496 const result = getCreateItemResult(events);506 const result = getCreateItemResult(events);
497 // tslint:disable-next-line:no-unused-expression507 // tslint:disable-next-line:no-unused-expression
498 expect(result.success).to.be.true;508 expect(result.success).to.be.true;
635 return newItemId;645 return newItemId;
636}646}
637647
638export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {648export async function setPublicAccessModeExpectSuccess(
649 sender: IKeyringPair, collectionId: number,
650 accessMode: 'Normal' | 'WhiteList',
651) {
639 await usingApi(async (api) => {652 await usingApi(async (api) => {
640653
641 // Run the transaction654 // Run the transaction
642 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');655 const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);
643 const events = await submitTransactionAsync(sender, tx);656 const events = await submitTransactionAsync(sender, tx);
644 const result = getGenericResult(events);657 const result = getGenericResult(events);
645658
649 // What to expect662 // What to expect
650 // tslint:disable-next-line:no-unused-expression663 // tslint:disable-next-line:no-unused-expression
651 expect(result.success).to.be.true;664 expect(result.success).to.be.true;
652 expect(collection.Access).to.be.equal('WhiteList');665 expect(collection.Access).to.be.equal(accessMode);
653 });666 });
654}667}
668
669export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
670 await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');
671}
672
673export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
674 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');
675}
655676
656export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {677export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {
657 await usingApi(async (api) => {678 await usingApi(async (api) => {
670 });691 });
671}692}
693
694export async function isWhitelisted(collectionId: number, address: string) {
695 let whitelisted: boolean = false;
696 await usingApi(async (api) => {
697 whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;
698 });
699 return whitelisted;
700}
672701
673export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {702export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
674 await usingApi(async (api) => {703 await usingApi(async (api) => {
692 });721 });
693}722}
723
724export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
725 await usingApi(async (api) => {
726 // Run the transaction
727 const tx = api.tx.nft.removeFromWhiteList(collectionId, address);
728 const events = await submitTransactionAsync(sender, tx);
729 const result = getGenericResult(events);
730
731 // What to expect
732 // tslint:disable-next-line:no-unused-expression
733 expect(result.success).to.be.true;
734 });
735}
736
737export async function removeFromWhiteListExpectFailure(sender: IKeyringPair, collectionId: number, address: string) {
738 await usingApi(async (api) => {
739 // Run the transaction
740 const tx = api.tx.nft.removeFromWhiteList(collectionId, address);
741 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
742 const result = getGenericResult(events);
743
744 // What to expect
745 // tslint:disable-next-line:no-unused-expression
746 expect(result.success).to.be.false;
747 });
748}
694749
695export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)750export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)
696 : Promise<ICollectionInterface | null> => {751 : Promise<ICollectionInterface | null> => {