git.delta.rocks / unique-network / refs/commits / 2df3f6b6e145

difftreelog

source

tests/src/.outdated/addToContractAllowList.test.ts4.7 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';20import {deployFlipper} from '../deprecated-helpers/contracthelpers';21import {getGenericResult} from '../deprecated-helpers/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526// todo:playgrounds skipped ~ postponed27describe.skip('Integration Test addToContractAllowList', () => {2829  it('Add an address to a contract allow list', async () => {30    await usingApi(async (api, privateKeyWrapper) => {31      const bob = privateKeyWrapper('//Bob');32      const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);3334      const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();35      const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);36      const addEvents = await submitTransactionAsync(deployer, addTx);37      const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();3839      expect(getGenericResult(addEvents).success).to.be.true;40      expect(allowListedBefore).to.be.false;41      expect(allowListedAfter).to.be.true;42    });43  });4445  it('Adding same address to allow list repeatedly should not produce errors', async () => {46    await usingApi(async (api, privateKeyWrapper) => {47      const bob = privateKeyWrapper('//Bob');48      const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);4950      const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();51      const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);52      const addEvents = await submitTransactionAsync(deployer, addTx);53      const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();54      const addAgainEvents = await submitTransactionAsync(deployer, addTx);55      const allowListedAgainAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();5657      expect(getGenericResult(addEvents).success).to.be.true;58      expect(allowListedBefore).to.be.false;59      expect(allowListedAfter).to.be.true;60      expect(getGenericResult(addAgainEvents).success).to.be.true;61      expect(allowListedAgainAfter).to.be.true;62    });63  });64});6566describe.skip('Negative Integration Test addToContractAllowList', () => {6768  it('Add an address to a allow list of a non-contract', async () => {69    await usingApi(async (api, privateKeyWrapper) => {70      const alice = privateKeyWrapper('//Bob');71      const bob = privateKeyWrapper('//Bob');72      const charlieGuineaPig = privateKeyWrapper('//Charlie');7374      const allowListedBefore = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();75      const addTx = api.tx.unique.addToContractAllowList(charlieGuineaPig.address, bob.address);76      await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;77      const allowListedAfter = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();7879      expect(allowListedBefore).to.be.false;80      expect(allowListedAfter).to.be.false;81    });82  });8384  it('Add to a contract allow list using a non-owner address', async () => {85    await usingApi(async (api, privateKeyWrapper) => {86      const bob = privateKeyWrapper('//Bob');87      const [contract] = await deployFlipper(api, privateKeyWrapper);8889      const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();90      const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);91      await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;92      const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();9394      expect(allowListedBefore).to.be.false;95      expect(allowListedAfter).to.be.false;96    });97  });9899});