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 addToContractWhiteList', () => {2021 it(`Add an address to a contract white list`, async () => {22 await usingApi(async api => {23 const bob = privateKey("//Bob");24 const [contract, deployer] = await deployFlipper(api);2526 const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();27 const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);28 const addEvents = await submitTransactionAsync(deployer, addTx);29 const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();3031 expect(getGenericResult(addEvents).success).to.be.true;32 expect(whiteListedBefore).to.be.false;33 expect(whiteListedAfter).to.be.true;34 });35 });3637 it(`Adding same address to white list repeatedly should not produce errors`, async () => {38 await usingApi(async api => {39 const bob = privateKey("//Bob");40 const [contract, deployer] = await deployFlipper(api);4142 const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();43 const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);44 const addEvents = await submitTransactionAsync(deployer, addTx);45 const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();46 const addAgainEvents = await submitTransactionAsync(deployer, addTx);47 const whiteListedAgainAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();4849 expect(getGenericResult(addEvents).success).to.be.true;50 expect(whiteListedBefore).to.be.false;51 expect(whiteListedAfter).to.be.true;52 expect(getGenericResult(addAgainEvents).success).to.be.true;53 expect(whiteListedAgainAfter).to.be.true;54 });55 });56});5758describe('Negative Integration Test addToContractWhiteList', () => {5960 it(`Add an address to a white list of a non-contract`, async () => {61 await usingApi(async api => {62 const alice = privateKey("//Bob");63 const bob = privateKey("//Bob");64 const charlieGuineaPig = privateKey("//Charlie");6566 const whiteListedBefore = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();67 const addTx = api.tx.nft.addToContractWhiteList(charlieGuineaPig.address, bob.address);68 await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;69 const whiteListedAfter = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();7071 expect(whiteListedBefore).to.be.false;72 expect(whiteListedAfter).to.be.false;73 });74 });7576 it(`Add to a contract white list using a non-owner address`, async () => {77 await usingApi(async api => {78 const bob = privateKey("//Bob");79 const [contract, deployer] = await deployFlipper(api);8081 const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();82 const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);83 await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;84 const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();8586 expect(whiteListedBefore).to.be.false;87 expect(whiteListedAfter).to.be.false;88 });89 });9091});