difftreelog
Fix addToWhiteList tests
in: master
3 files changed
tests/src/addToWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToWhiteList.test.ts
+++ b/tests/src/addToWhiteList.test.ts
@@ -1,3 +1,4 @@
+import { IKeyringPair } from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
@@ -14,49 +15,38 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-describe('Integration Test ext. addToWhiteList()', () => {
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
- it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
+describe.only('Integration Test ext. addToWhiteList()', () => {
+
+ before(async () => {
await usingApi(async (api) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const collectionId = await createCollectionExpectSuccess();
- const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
- // tslint:disable-next-line: no-unused-expression
- expect(whiteListedBefore).to.be.false;
- // tslint:disable-next-line: no-unused-expression
- expect(whiteListedAfter).to.be.true;
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
});
});
+ it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ });
+
it('Whitelisted minting: list restrictions', async () => {
- await usingApi(async (api) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const collectionId = await createCollectionExpectSuccess();
- const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
- // tslint:disable-next-line: no-unused-expression
- expect(whiteListedBefore).to.be.false;
- // tslint:disable-next-line: no-unused-expression
- expect(whiteListedAfter).to.be.true;
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
- });
+ const collectionId = await createCollectionExpectSuccess();
+ await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enablePublicMintingExpectSuccess(Alice, collectionId);
+ await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
});
});
-describe('Negative Integration Test ext. addToWhiteList()', () => {
+describe.only('Negative Integration Test ext. addToWhiteList()', () => {
it('White list an address in the collection that does not exist', async () => {
await usingApi(async (api) => {
- const Alice = privateKey('//Alice');
// tslint:disable-next-line: no-bitwise
- const collectionId = (1 << 32) - 1;
+ const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
const Bob = privateKey('//Bob');
const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address);
tests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth1import chai from "chai";2import chaiAsPromised from 'chai-as-promised';3import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";4import privateKey from "./substrate/privateKey";5import {6 deployFlipper,7 getFlipValue8} from "./util/contracthelpers";9import {10 getGenericResult11} from "./util/helpers"1213chai.use(chaiAsPromised);14const expect = chai.expect;1516const value = 0;17const gasLimit = 3000n * 1000000n;1819describe('Integration Test toggleContractWhiteList', () => {2021 it(`Enable white list contract mode`, async () => {22 await usingApi(async api => {23 const [contract, deployer] = await deployFlipper(api);2425 const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();26 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);27 const enableEvents = await submitTransactionAsync(deployer, enableWhiteListTx);28 const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();2930 expect(getGenericResult(enableEvents).success).to.be.true;31 expect(enabledBefore).to.be.false;32 expect(enabled).to.be.true;33 });34 });3536 it.only(`Only whitelisted account can call contract`, async () => {37 await usingApi(async api => {38 const bob = privateKey("//Bob");3940 const [contract, deployer] = await deployFlipper(api);4142 let flipValueBefore = await getFlipValue(contract, deployer);43 const flip = contract.exec('flip', value, gasLimit);44 await submitTransactionAsync(bob, flip);45 const flipValueAfter = await getFlipValue(contract,deployer);46 expect(flipValueAfter).to.be.eq(!flipValueBefore, `Anyone can call new contract.`);4748 const deployerCanFlip = async () => {49 let flipValueBefore = await getFlipValue(contract, deployer);50 const deployerFlip = contract.exec('flip', value, gasLimit);51 await submitTransactionAsync(deployer, deployerFlip);52 const aliceFlip1Response = await getFlipValue(contract, deployer);53 expect(aliceFlip1Response).to.be.eq(!flipValueBefore, `Deployer always can flip.`);54 };55 await deployerCanFlip();5657 flipValueBefore = await getFlipValue(contract, deployer);58 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);59 const enableResult = await submitTransactionAsync(deployer, enableWhiteListTx);60 const flipWithEnabledWhiteList = contract.exec('flip', value, gasLimit);61 await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledWhiteList)).to.be.rejected;62 const flipValueAfterEnableWhiteList = await getFlipValue(contract, deployer);63 expect(flipValueAfterEnableWhiteList).to.be.eq(flipValueBefore, `Enabling whitelist doesn't make it possible to call contract for everyone.`);6465 await deployerCanFlip();6667 flipValueBefore = await getFlipValue(contract, deployer);68 const addBobToWhiteListTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);69 const addBobResult = await submitTransactionAsync(deployer, addBobToWhiteListTx);70 const flipWithWhitelistedBob = contract.exec('flip', value, gasLimit);71 await submitTransactionAsync(bob, flipWithWhitelistedBob);72 const flipAfterWhiteListed = await getFlipValue(contract,deployer);73 expect(flipAfterWhiteListed).to.be.eq(!flipValueBefore, `Bob was whitelisted, now he can flip.`);7475 await deployerCanFlip();7677 flipValueBefore = await getFlipValue(contract, deployer);78 const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);79 const removeBobResult = await submitTransactionAsync(deployer, removeBobFromWhiteListTx);80 const bobRemoved = contract.exec('flip', value, gasLimit);81 await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;82 const afterBobRemoved = await getFlipValue(contract, deployer);83 expect(afterBobRemoved).to.be.eq(flipValueBefore, `Bob can't call contract, now when he is removeed from white list.`);8485 await deployerCanFlip();8687 flipValueBefore = await getFlipValue(contract, deployer);88 const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);89 const disableWhiteListResult = await submitTransactionAsync(deployer, disableWhiteListTx);90 const whiteListDisabledFlip = contract.exec('flip', value, gasLimit);91 await submitTransactionAsync(bob, whiteListDisabledFlip);92 const afterWhiteListDisabled = await getFlipValue(contract,deployer);93 expect(afterWhiteListDisabled).to.be.eq(!flipValueBefore, `Anyone can call contract with disabled whitelist.`);9495 });96 });9798 it(`Enabling white list repeatedly should not produce errors`, async () => {99 await usingApi(async api => {100 const [contract, deployer] = await deployFlipper(api);101102 const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();103 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);104 const enableEvents = await submitTransactionAsync(deployer, enableWhiteListTx);105 const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();106 const enableAgainEvents = await submitTransactionAsync(deployer, enableWhiteListTx);107 const enabledAgain = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();108109 expect(getGenericResult(enableEvents).success).to.be.true;110 expect(enabledBefore).to.be.false;111 expect(enabled).to.be.true;112 expect(getGenericResult(enableAgainEvents).success).to.be.true;113 expect(enabledAgain).to.be.true;114 });115 });116117});118119describe('Negative Integration Test toggleContractWhiteList', () => {120121 it(`Enable white list for a non-contract`, async () => {122 await usingApi(async api => {123 const alice = privateKey("//Alice");124 const bobGuineaPig = privateKey("//Bob");125126 const enabledBefore = (await api.query.nft.contractWhiteListEnabled(bobGuineaPig.address)).toJSON();127 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(bobGuineaPig.address, true);128 await expect(submitTransactionExpectFailAsync(alice, enableWhiteListTx)).to.be.rejected;129 const enabled = (await api.query.nft.contractWhiteListEnabled(bobGuineaPig.address)).toJSON();130131 expect(enabledBefore).to.be.false;132 expect(enabled).to.be.false;133 });134 });135136 it(`Enable white list using a non-owner address`, async () => {137 await usingApi(async api => {138 const bob = privateKey("//Bob");139 const [contract, deployer] = await deployFlipper(api);140141 const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();142 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);143 await expect(submitTransactionExpectFailAsync(bob, enableWhiteListTx)).to.be.rejected;144 const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();145146 expect(enabledBefore).to.be.false;147 expect(enabled).to.be.false;148 });149 });150151});1import chai from "chai";2import chaiAsPromised from 'chai-as-promised';3import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";4import privateKey from "./substrate/privateKey";5import {6 deployFlipper,7 getFlipValue8} from "./util/contracthelpers";9import {10 getGenericResult11} from "./util/helpers"1213chai.use(chaiAsPromised);14const expect = chai.expect;1516const value = 0;17const gasLimit = 3000n * 1000000n;1819describe('Integration Test toggleContractWhiteList', () => {2021 it(`Enable white list contract mode`, async () => {22 await usingApi(async api => {23 const [contract, deployer] = await deployFlipper(api);2425 const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();26 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);27 const enableEvents = await submitTransactionAsync(deployer, enableWhiteListTx);28 const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();2930 expect(getGenericResult(enableEvents).success).to.be.true;31 expect(enabledBefore).to.be.false;32 expect(enabled).to.be.true;33 });34 });3536 it(`Only whitelisted account can call contract`, async () => {37 await usingApi(async api => {38 const bob = privateKey("//Bob");3940 const [contract, deployer] = await deployFlipper(api);4142 let flipValueBefore = await getFlipValue(contract, deployer);43 const flip = contract.exec('flip', value, gasLimit);44 await submitTransactionAsync(bob, flip);45 const flipValueAfter = await getFlipValue(contract,deployer);46 expect(flipValueAfter).to.be.eq(!flipValueBefore, `Anyone can call new contract.`);4748 const deployerCanFlip = async () => {49 let flipValueBefore = await getFlipValue(contract, deployer);50 const deployerFlip = contract.exec('flip', value, gasLimit);51 await submitTransactionAsync(deployer, deployerFlip);52 const aliceFlip1Response = await getFlipValue(contract, deployer);53 expect(aliceFlip1Response).to.be.eq(!flipValueBefore, `Deployer always can flip.`);54 };55 await deployerCanFlip();5657 flipValueBefore = await getFlipValue(contract, deployer);58 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);59 const enableResult = await submitTransactionAsync(deployer, enableWhiteListTx);60 const flipWithEnabledWhiteList = contract.exec('flip', value, gasLimit);61 await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledWhiteList)).to.be.rejected;62 const flipValueAfterEnableWhiteList = await getFlipValue(contract, deployer);63 expect(flipValueAfterEnableWhiteList).to.be.eq(flipValueBefore, `Enabling whitelist doesn't make it possible to call contract for everyone.`);6465 await deployerCanFlip();6667 flipValueBefore = await getFlipValue(contract, deployer);68 const addBobToWhiteListTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);69 const addBobResult = await submitTransactionAsync(deployer, addBobToWhiteListTx);70 const flipWithWhitelistedBob = contract.exec('flip', value, gasLimit);71 await submitTransactionAsync(bob, flipWithWhitelistedBob);72 const flipAfterWhiteListed = await getFlipValue(contract,deployer);73 expect(flipAfterWhiteListed).to.be.eq(!flipValueBefore, `Bob was whitelisted, now he can flip.`);7475 await deployerCanFlip();7677 flipValueBefore = await getFlipValue(contract, deployer);78 const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);79 const removeBobResult = await submitTransactionAsync(deployer, removeBobFromWhiteListTx);80 const bobRemoved = contract.exec('flip', value, gasLimit);81 await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;82 const afterBobRemoved = await getFlipValue(contract, deployer);83 expect(afterBobRemoved).to.be.eq(flipValueBefore, `Bob can't call contract, now when he is removeed from white list.`);8485 await deployerCanFlip();8687 flipValueBefore = await getFlipValue(contract, deployer);88 const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);89 const disableWhiteListResult = await submitTransactionAsync(deployer, disableWhiteListTx);90 const whiteListDisabledFlip = contract.exec('flip', value, gasLimit);91 await submitTransactionAsync(bob, whiteListDisabledFlip);92 const afterWhiteListDisabled = await getFlipValue(contract,deployer);93 expect(afterWhiteListDisabled).to.be.eq(!flipValueBefore, `Anyone can call contract with disabled whitelist.`);9495 });96 });9798 it(`Enabling white list repeatedly should not produce errors`, async () => {99 await usingApi(async api => {100 const [contract, deployer] = await deployFlipper(api);101102 const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();103 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);104 const enableEvents = await submitTransactionAsync(deployer, enableWhiteListTx);105 const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();106 const enableAgainEvents = await submitTransactionAsync(deployer, enableWhiteListTx);107 const enabledAgain = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();108109 expect(getGenericResult(enableEvents).success).to.be.true;110 expect(enabledBefore).to.be.false;111 expect(enabled).to.be.true;112 expect(getGenericResult(enableAgainEvents).success).to.be.true;113 expect(enabledAgain).to.be.true;114 });115 });116117});118119describe('Negative Integration Test toggleContractWhiteList', () => {120121 it(`Enable white list for a non-contract`, async () => {122 await usingApi(async api => {123 const alice = privateKey("//Alice");124 const bobGuineaPig = privateKey("//Bob");125126 const enabledBefore = (await api.query.nft.contractWhiteListEnabled(bobGuineaPig.address)).toJSON();127 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(bobGuineaPig.address, true);128 await expect(submitTransactionExpectFailAsync(alice, enableWhiteListTx)).to.be.rejected;129 const enabled = (await api.query.nft.contractWhiteListEnabled(bobGuineaPig.address)).toJSON();130131 expect(enabledBefore).to.be.false;132 expect(enabled).to.be.false;133 });134 });135136 it(`Enable white list using a non-owner address`, async () => {137 await usingApi(async api => {138 const bob = privateKey("//Bob");139 const [contract, deployer] = await deployFlipper(api);140141 const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();142 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);143 await expect(submitTransactionExpectFailAsync(bob, enableWhiteListTx)).to.be.rejected;144 const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();145146 expect(enabledBefore).to.be.false;147 expect(enabled).to.be.false;148 });149 });150151});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -550,17 +550,21 @@
export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
await usingApi(async (api) => {
+ const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();
+
// Run the transaction
const tx = api.tx.nft.addToWhiteList(collectionId, address);
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
- // Get the collection
- const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+ const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();
// What to expect
expect(result.success).to.be.true;
- expect(collection.MintMode).to.be.equal(true);
+ // tslint:disable-next-line: no-unused-expression
+ expect(whiteListedBefore).to.be.false;
+ // tslint:disable-next-line: no-unused-expression
+ expect(whiteListedAfter).to.be.true;
});
}