git.delta.rocks / unique-network / refs/commits / 4a53d88957b6

difftreelog

source

tests/src/addToContractWhiteList.test.ts3.9 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from "chai";7import chaiAsPromised from 'chai-as-promised';8import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";9import privateKey from "./substrate/privateKey";10import {11  deployFlipper12} from "./util/contracthelpers";13import {14  getGenericResult, normalizeAccountId15} from "./util/helpers"1617chai.use(chaiAsPromised);18const expect = chai.expect;1920describe('Integration Test addToContractWhiteList', () => {2122  it(`Add an address to a contract white list`, async () => {23    await usingApi(async api => {24      const bob = privateKey("//Bob");25      const [contract, deployer] = await deployFlipper(api);2627      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();28      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);29      const addEvents = await submitTransactionAsync(deployer, addTx);30      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();3132      expect(getGenericResult(addEvents).success).to.be.true;33      expect(whiteListedBefore).to.be.false;34      expect(whiteListedAfter).to.be.true;35    });36  });3738  it(`Adding same address to white list repeatedly should not produce errors`, async () => {39    await usingApi(async api => {40      const bob = privateKey("//Bob");41      const [contract, deployer] = await deployFlipper(api);4243      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();44      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);45      const addEvents = await submitTransactionAsync(deployer, addTx);46      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();47      const addAgainEvents = await submitTransactionAsync(deployer, addTx);48      const whiteListedAgainAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();4950      expect(getGenericResult(addEvents).success).to.be.true;51      expect(whiteListedBefore).to.be.false;52      expect(whiteListedAfter).to.be.true;53      expect(getGenericResult(addAgainEvents).success).to.be.true;54      expect(whiteListedAgainAfter).to.be.true;55    });56  });57});5859describe('Negative Integration Test addToContractWhiteList', () => {6061  it(`Add an address to a white list of a non-contract`, async () => {62    await usingApi(async api => {63      const alice = privateKey("//Bob");64      const bob = privateKey("//Bob");65      const charlieGuineaPig = privateKey("//Charlie");6667      const whiteListedBefore = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();68      const addTx = api.tx.nft.addToContractWhiteList(charlieGuineaPig.address, bob.address);69      await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;70      const whiteListedAfter = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();7172      expect(whiteListedBefore).to.be.false;73      expect(whiteListedAfter).to.be.false;74    });75  });7677  it(`Add to a contract white list using a non-owner address`, async () => {78    await usingApi(async api => {79      const bob = privateKey("//Bob");80      const [contract, deployer] = await deployFlipper(api);8182      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();83      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);84      await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;85      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();8687      expect(whiteListedBefore).to.be.false;88      expect(whiteListedAfter).to.be.false;89    });90  });9192});