git.delta.rocks / unique-network / refs/commits / e2d9909ea360

difftreelog

source

tests/src/enableContractSponsoring.test.ts3.9 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 './util/contracthelpers';22import {23  enableContractSponsoringExpectFailure,24  enableContractSponsoringExpectSuccess,25  findUnusedAddress,26  setContractSponsoringRateLimitExpectSuccess,27} from './util/helpers';2829chai.use(chaiAsPromised);30const expect = chai.expect;3132describe.skip('Integration Test enableContractSponsoring', () => {33  it('ensure tx fee is paid from endowment', async () => {34    await usingApi(async (api, privateKeyWrapper) => {35      const user = await findUnusedAddress(api, privateKeyWrapper);3637      const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);38      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);39      await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);40      await toggleFlipValueExpectSuccess(user, flipper);4142      expect(await getFlipValue(flipper, deployer)).to.be.false;43    });44  });4546  it('ensure it can be enabled twice', async () => {47    await usingApi(async (api, privateKeyWrapper) => {48      const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);4950      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);51      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);52    });53  });5455  it('ensure it can be disabled twice', async () => {56    await usingApi(async (api, privateKeyWrapper) => {57      const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);5859      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);60      await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);61      await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);62    });63  });6465  it('ensure it can be re-enabled', async () => {66    await usingApi(async (api, privateKeyWrapper) => {67      const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);6869      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);70      await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);71      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);72    });73  });7475});7677describe.skip('Negative Integration Test enableContractSponsoring', () => {78  let alice: IKeyringPair;7980  before(async () => {81    await usingApi(async (api, privateKeyWrapper) => {82      alice = privateKeyWrapper('//Alice');83    });84  });8586  it('fails when called for non-contract address', async () => {87    await usingApi(async (api, privateKeyWrapper) => {88      const user = await findUnusedAddress(api, privateKeyWrapper);8990      await enableContractSponsoringExpectFailure(alice, user.address, true);91    });92  });9394  it('fails when called by non-owning user', async () => {95    await usingApi(async (api, privateKeyWrapper) => {96      const [flipper] = await deployFlipper(api, privateKeyWrapper);9798      await enableContractSponsoringExpectFailure(alice, flipper.address, true);99    });100  });101});