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

difftreelog

Fix addToWhiteList tests

Greg Zaitsev2021-01-19parent: #6b02730.patch.diff
in: master

3 files changed

modifiedtests/src/addToWhiteList.test.tsdiffbeforeafterboth
1import { IKeyringPair } from '@polkadot/types/types';
1import chai from 'chai'; 2import chai from 'chai';
2import chaiAsPromised from 'chai-as-promised'; 3import chaiAsPromised from 'chai-as-promised';
3import privateKey from './substrate/privateKey'; 4import privateKey from './substrate/privateKey';
14chai.use(chaiAsPromised); 15chai.use(chaiAsPromised);
15const expect = chai.expect; 16const expect = chai.expect;
16 17
18let Alice: IKeyringPair;
19let Bob: IKeyringPair;
20
17describe('Integration Test ext. addToWhiteList()', () => { 21describe.only('Integration Test ext. addToWhiteList()', () => {
18 22
19 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => { 23 before(async () => {
20 await usingApi(async (api) => { 24 await usingApi(async (api) => {
21 const Alice = privateKey('//Alice'); 25 Alice = privateKey('//Alice');
22 const Bob = privateKey('//Bob'); 26 Bob = privateKey('//Bob');
23 const collectionId = await createCollectionExpectSuccess();
24 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
25 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
26 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
27 // tslint:disable-next-line: no-unused-expression
28 expect(whiteListedBefore).to.be.false;
29 // tslint:disable-next-line: no-unused-expression
30 expect(whiteListedAfter).to.be.true;
31 }); 27 });
32 }); 28 });
33 29
30 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
31 const collectionId = await createCollectionExpectSuccess();
32 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
33 });
34
34 it('Whitelisted minting: list restrictions', async () => { 35 it('Whitelisted minting: list restrictions', async () => {
35 await usingApi(async (api) => {
36 const Alice = privateKey('//Alice');
37 const Bob = privateKey('//Bob');
38 const collectionId = await createCollectionExpectSuccess(); 36 const collectionId = await createCollectionExpectSuccess();
39 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
40 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address); 37 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
41 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
42 // tslint:disable-next-line: no-unused-expression
43 expect(whiteListedBefore).to.be.false;
44 // tslint:disable-next-line: no-unused-expression
45 expect(whiteListedAfter).to.be.true;
46 await enableWhiteListExpectSuccess(Alice, collectionId); 38 await enableWhiteListExpectSuccess(Alice, collectionId);
47 await enablePublicMintingExpectSuccess(Alice, collectionId); 39 await enablePublicMintingExpectSuccess(Alice, collectionId);
48 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address); 40 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
49 });
50 }); 41 });
51}); 42});
52 43
53describe('Negative Integration Test ext. addToWhiteList()', () => { 44describe.only('Negative Integration Test ext. addToWhiteList()', () => {
54 45
55 it('White list an address in the collection that does not exist', async () => { 46 it('White list an address in the collection that does not exist', async () => {
56 await usingApi(async (api) => { 47 await usingApi(async (api) => {
57 const Alice = privateKey('//Alice');
58 // tslint:disable-next-line: no-bitwise 48 // tslint:disable-next-line: no-bitwise
59 const collectionId = (1 << 32) - 1; 49 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
60 const Bob = privateKey('//Bob'); 50 const Bob = privateKey('//Bob');
61 51
62 const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address); 52 const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address);
modifiedtests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth
33 });33 });
34 });34 });
3535
36 it.only(`Only whitelisted account can call contract`, async () => {36 it(`Only whitelisted account can call contract`, async () => {
37 await usingApi(async api => {37 await usingApi(async api => {
38 const bob = privateKey("//Bob");38 const bob = privateKey("//Bob");
3939
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
550export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {550export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
551 await usingApi(async (api) => {551 await usingApi(async (api) => {
552
553 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();
552554
553 // Run the transaction555 // Run the transaction
554 const tx = api.tx.nft.addToWhiteList(collectionId, address);556 const tx = api.tx.nft.addToWhiteList(collectionId, address);
555 const events = await submitTransactionAsync(sender, tx);557 const events = await submitTransactionAsync(sender, tx);
556 const result = getGenericResult(events);558 const result = getGenericResult(events);
557559
558 // Get the collection
559 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();560 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();
560561
561 // What to expect562 // What to expect
562 expect(result.success).to.be.true;563 expect(result.success).to.be.true;
564 // tslint:disable-next-line: no-unused-expression
565 expect(whiteListedBefore).to.be.false;
566 // tslint:disable-next-line: no-unused-expression
563 expect(collection.MintMode).to.be.equal(true);567 expect(whiteListedAfter).to.be.true;
564 });568 });
565}569}
566570