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 deployFlipper7} from "./util/contracthelpers";8import {9 getGenericResult10} from "./util/helpers"1112chai.use(chaiAsPromised);13const expect = chai.expect;1415describe('Integration Test addToContractWhiteList', () => {1617 it(`Add an address to a contract white list`, async () => {18 await usingApi(async api => {19 const bob = privateKey("//Bob");20 const [contract, deployer] = await deployFlipper(api);2122 const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();23 const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);24 const addEvents = await submitTransactionAsync(deployer, addTx);25 const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();2627 expect(getGenericResult(addEvents).success).to.be.true;28 expect(whiteListedBefore).to.be.false;29 expect(whiteListedAfter).to.be.true;30 });31 });3233 it(`Adding same address to white list repeatedly should not produce errors`, async () => {34 await usingApi(async api => {35 const bob = privateKey("//Bob");36 const [contract, deployer] = await deployFlipper(api);3738 const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();39 const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);40 const addEvents = await submitTransactionAsync(deployer, addTx);41 const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();42 const addAgainEvents = await submitTransactionAsync(deployer, addTx);43 const whiteListedAgainAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();4445 expect(getGenericResult(addEvents).success).to.be.true;46 expect(whiteListedBefore).to.be.false;47 expect(whiteListedAfter).to.be.true;48 expect(getGenericResult(addAgainEvents).success).to.be.true;49 expect(whiteListedAgainAfter).to.be.true;50 });51 });52});5354describe('Negative Integration Test addToContractWhiteList', () => {5556 it(`Add an address to a white list of a non-contract`, async () => {57 await usingApi(async api => {58 const alice = privateKey("//Bob");59 const bob = privateKey("//Bob");60 const charlieGuineaPig = privateKey("//Charlie");6162 const whiteListedBefore = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();63 const addTx = api.tx.nft.addToContractWhiteList(charlieGuineaPig.address, bob.address);64 await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;65 const whiteListedAfter = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();6667 expect(whiteListedBefore).to.be.false;68 expect(whiteListedAfter).to.be.false;69 });70 });7172 it(`Add to a contract white list using a non-owner address`, async () => {73 await usingApi(async api => {74 const bob = privateKey("//Bob");75 const [contract, deployer] = await deployFlipper(api);7677 const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();78 const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);79 await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;80 const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();8182 expect(whiteListedBefore).to.be.false;83 expect(whiteListedAfter).to.be.false;84 });85 });8687});