git.delta.rocks / unique-network / refs/commits / 3db00dc56ee4

difftreelog

source

tests/src/enableContractSponsoring.test.ts3.6 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 {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import privateKey from './substrate/privateKey';21import usingApi from './substrate/substrate-api';22import {deployFlipper, getFlipValue, toggleFlipValueExpectSuccess} from './util/contracthelpers';23import {24  enableContractSponsoringExpectFailure,25  enableContractSponsoringExpectSuccess,26  findUnusedAddress,27  setContractSponsoringRateLimitExpectSuccess,28} from './util/helpers';2930chai.use(chaiAsPromised);31const expect = chai.expect;3233describe.skip('Integration Test enableContractSponsoring', () => {34  it('ensure tx fee is paid from endowment', async () => {35    await usingApi(async (api) => {36      const user = await findUnusedAddress(api);3738      const [flipper, deployer] = await deployFlipper(api);39      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);40      await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);41      await toggleFlipValueExpectSuccess(user, flipper);4243      expect(await getFlipValue(flipper, deployer)).to.be.false;44    });45  });4647  it('ensure it can be enabled twice', async () => {48    await usingApi(async (api) => {49      const [flipper, deployer] = await deployFlipper(api);5051      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);52      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);53    });54  });5556  it('ensure it can be disabled twice', async () => {57    await usingApi(async (api) => {58      const [flipper, deployer] = await deployFlipper(api);5960      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);61      await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);62      await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);63    });64  });6566  it('ensure it can be re-enabled', async () => {67    await usingApi(async (api) => {68      const [flipper, deployer] = await deployFlipper(api);6970      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);71      await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);72      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);73    });74  });7576});7778describe.skip('Negative Integration Test enableContractSponsoring', () => {79  let alice: IKeyringPair;8081  before(async () => {82    alice = privateKey('//Alice');83  });8485  it('fails when called for non-contract address', async () => {86    await usingApi(async (api) => {87      const user = await findUnusedAddress(api);8889      await enableContractSponsoringExpectFailure(alice, user.address, true);90    });91  });9293  it('fails when called by non-owning user', async () => {94    await usingApi(async (api) => {95      const [flipper] = await deployFlipper(api);9697      await enableContractSponsoringExpectFailure(alice, flipper.address, true);98    });99  });100});