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

difftreelog

source

tests/src/.outdated/enableContractSponsoring.test.ts4.0 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 usingApi from '../substrate/substrate-api';21import {deployFlipper, getFlipValue, toggleFlipValueExpectSuccess} from '../deprecated-helpers/contracthelpers';22import {23  enableContractSponsoringExpectFailure,24  enableContractSponsoringExpectSuccess,25  findUnusedAddress,26  setContractSponsoringRateLimitExpectSuccess,27} from '../deprecated-helpers/helpers';2829chai.use(chaiAsPromised);30const expect = chai.expect;3132// todo:playgrounds skipped ~ postponed33describe.skip('Integration Test enableContractSponsoring', () => {34  it('ensure tx fee is paid from endowment', async () => {35    await usingApi(async (api, privateKeyWrapper) => {36      const user = await findUnusedAddress(api, privateKeyWrapper);3738      const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);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, privateKeyWrapper) => {49      const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);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, privateKeyWrapper) => {58      const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);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, privateKeyWrapper) => {68      const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);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    await usingApi(async (api, privateKeyWrapper) => {83      alice = privateKeyWrapper('//Alice');84    });85  });8687  it('fails when called for non-contract address', async () => {88    await usingApi(async (api, privateKeyWrapper) => {89      const user = await findUnusedAddress(api, privateKeyWrapper);9091      await enableContractSponsoringExpectFailure(alice, user.address, true);92    });93  });9495  it('fails when called by non-owning user', async () => {96    await usingApi(async (api, privateKeyWrapper) => {97      const [flipper] = await deployFlipper(api, privateKeyWrapper);9899      await enableContractSponsoringExpectFailure(alice, flipper.address, true);100    });101  });102});