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

difftreelog

source

tests/src/setContractSponsoringRateLimit.test.ts3.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 privateKey from './substrate/privateKey';19import usingApi from './substrate/substrate-api';20import waitNewBlocks from './substrate/wait-new-blocks';21import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from './util/contracthelpers';22import {23  enableContractSponsoringExpectSuccess,24  findUnusedAddress,25  setContractSponsoringRateLimitExpectFailure,26  setContractSponsoringRateLimitExpectSuccess,27} from './util/helpers';2829describe.skip('Integration Test setContractSponsoringRateLimit', () => {30  it('ensure sponsored contract can\'t be called twice without pause for free', async () => {31    await usingApi(async (api) => {32      const user = await findUnusedAddress(api);3334      const [flipper, deployer] = await deployFlipper(api);35      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);36      await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 10);37      await toggleFlipValueExpectSuccess(user, flipper);38      await toggleFlipValueExpectFailure(user, flipper);39    });40  });4142  it('ensure sponsored contract can be called twice with pause for free', async () => {43    await usingApi(async (api) => {44      const user = await findUnusedAddress(api);4546      const [flipper, deployer] = await deployFlipper(api);47      await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);48      await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);49      await toggleFlipValueExpectSuccess(user, flipper);50      await waitNewBlocks(api, 1);51      await toggleFlipValueExpectSuccess(user, flipper);52    });53  });54});5556describe.skip('Negative Integration Test setContractSponsoringRateLimit', () => {57  let alice: IKeyringPair;5859  before(async () => {60    alice = privateKey('//Alice');61  });6263  it('fails when called for non-contract address', async () => {64    await usingApi(async (api) => {65      const user = await findUnusedAddress(api);6667      await setContractSponsoringRateLimitExpectFailure(alice, user.address, 1);68    });69  });7071  it('fails when called by non-owning user', async () => {72    await usingApi(async (api) => {73      const [flipper] = await deployFlipper(api);7475      await setContractSponsoringRateLimitExpectFailure(alice, flipper.address, 1);76    });77  });78});