git.delta.rocks / unique-network / refs/commits / 798647f756b4

difftreelog

source

tests/src/addToContractAllowList.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  deployFlipper,12} from './util/contracthelpers';13import {14  getGenericResult,15} from './util/helpers';1617chai.use(chaiAsPromised);18const expect = chai.expect;1920describe.skip('Integration Test addToContractAllowList', () => {2122  it('Add an address to a contract allow list', async () => {23    await usingApi(async api => {24      const bob = privateKey('//Bob');25      const [contract, deployer] = await deployFlipper(api);2627      const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();28      const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);29      const addEvents = await submitTransactionAsync(deployer, addTx);30      const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();3132      expect(getGenericResult(addEvents).success).to.be.true;33      expect(allowListedBefore).to.be.false;34      expect(allowListedAfter).to.be.true;35    });36  });3738  it('Adding same address to allow 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 allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();44      const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);45      const addEvents = await submitTransactionAsync(deployer, addTx);46      const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();47      const addAgainEvents = await submitTransactionAsync(deployer, addTx);48      const allowListedAgainAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();4950      expect(getGenericResult(addEvents).success).to.be.true;51      expect(allowListedBefore).to.be.false;52      expect(allowListedAfter).to.be.true;53      expect(getGenericResult(addAgainEvents).success).to.be.true;54      expect(allowListedAgainAfter).to.be.true;55    });56  });57});5859describe.skip('Negative Integration Test addToContractAllowList', () => {6061  it('Add an address to a allow 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 allowListedBefore = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();68      const addTx = api.tx.unique.addToContractAllowList(charlieGuineaPig.address, bob.address);69      await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;70      const allowListedAfter = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();7172      expect(allowListedBefore).to.be.false;73      expect(allowListedAfter).to.be.false;74    });75  });7677  it('Add to a contract allow list using a non-owner address', async () => {78    await usingApi(async api => {79      const bob = privateKey('//Bob');80      const [contract] = await deployFlipper(api);8182      const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();83      const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);84      await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;85      const allowListedAfter = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();8687      expect(allowListedBefore).to.be.false;88      expect(allowListedAfter).to.be.false;89    });90  });9192});