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

difftreelog

Move test to .oudated

Maksandre2022-10-05parent: #1e8c54c.patch.diff
in: master

3 files changed

addedtests/src/.outdated/toggleContractAllowList.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/.outdated/toggleContractAllowList.test.ts
@@ -0,0 +1,167 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
+import {
+  deployFlipper,
+  getFlipValue,
+} from '../util/contracthelpers';
+import {
+  getGenericResult,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+const value = 0;
+const gasLimit = 3000n * 1000000n;
+
+// todo:playgrounds skipped ~ postpone
+describe.skip('Integration Test toggleContractAllowList', () => {
+
+  it('Enable allow list contract mode', async () => {
+    await usingApi(async (api, privateKeyWrapper) => {
+      const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
+
+      const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
+      const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
+      const enableEvents = await submitTransactionAsync(deployer, enableAllowListTx);
+      const enabled = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
+
+      expect(getGenericResult(enableEvents).success).to.be.true;
+      expect(enabledBefore).to.be.false;
+      expect(enabled).to.be.true;
+    });
+  });
+
+  it('Only allowlisted account can call contract', async () => {
+    await usingApi(async (api, privateKeyWrapper) => {
+      const bob = privateKeyWrapper('//Bob');
+
+      const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
+
+      let flipValueBefore = await getFlipValue(contract, deployer);
+      const flip = contract.tx.flip({value, gasLimit});
+      await submitTransactionAsync(bob, flip);
+      const flipValueAfter = await getFlipValue(contract,deployer);
+      expect(flipValueAfter).to.be.eq(!flipValueBefore, 'Anyone can call new contract.');
+
+      const deployerCanFlip = async () => {
+        const flipValueBefore = await getFlipValue(contract, deployer);
+        const deployerFlip = contract.tx.flip({value, gasLimit});
+        await submitTransactionAsync(deployer, deployerFlip);
+        const aliceFlip1Response = await getFlipValue(contract, deployer);
+        expect(aliceFlip1Response).to.be.eq(!flipValueBefore, 'Deployer always can flip.');
+      };
+      await deployerCanFlip();
+
+      flipValueBefore = await getFlipValue(contract, deployer);
+      const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
+      await submitTransactionAsync(deployer, enableAllowListTx);
+      const flipWithEnabledAllowList = contract.tx.flip({value, gasLimit});
+      await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledAllowList)).to.be.rejected;
+      const flipValueAfterEnableAllowList = await getFlipValue(contract, deployer);
+      expect(flipValueAfterEnableAllowList).to.be.eq(flipValueBefore, 'Enabling allowlist doesn\'t make it possible to call contract for everyone.');
+
+      await deployerCanFlip();
+
+      flipValueBefore = await getFlipValue(contract, deployer);
+      const addBobToAllowListTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);
+      await submitTransactionAsync(deployer, addBobToAllowListTx);
+      const flipWithAllowlistedBob = contract.tx.flip({value, gasLimit});
+      await submitTransactionAsync(bob, flipWithAllowlistedBob);
+      const flipAfterAllowListed = await getFlipValue(contract,deployer);
+      expect(flipAfterAllowListed).to.be.eq(!flipValueBefore, 'Bob was allowlisted, now he can flip.');
+
+      await deployerCanFlip();
+
+      flipValueBefore = await getFlipValue(contract, deployer);
+      const removeBobFromAllowListTx = api.tx.unique.removeFromContractAllowList(contract.address, bob.address);
+      await submitTransactionAsync(deployer, removeBobFromAllowListTx);
+      const bobRemoved = contract.tx.flip({value, gasLimit});
+      await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;
+      const afterBobRemoved = await getFlipValue(contract, deployer);
+      expect(afterBobRemoved).to.be.eq(flipValueBefore, 'Bob can\'t call contract, now when he is removeed from allow list.');
+
+      await deployerCanFlip();
+
+      flipValueBefore = await getFlipValue(contract, deployer);
+      const disableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, false);
+      await submitTransactionAsync(deployer, disableAllowListTx);
+      const allowListDisabledFlip = contract.tx.flip({value, gasLimit});
+      await submitTransactionAsync(bob, allowListDisabledFlip);
+      const afterAllowListDisabled = await getFlipValue(contract,deployer);
+      expect(afterAllowListDisabled).to.be.eq(!flipValueBefore, 'Anyone can call contract with disabled allowlist.');
+
+    });
+  });
+
+  it('Enabling allow list repeatedly should not produce errors', async () => {
+    await usingApi(async (api, privateKeyWrapper) => {
+      const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
+
+      const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
+      const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
+      const enableEvents = await submitTransactionAsync(deployer, enableAllowListTx);
+      const enabled = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
+      const enableAgainEvents = await submitTransactionAsync(deployer, enableAllowListTx);
+      const enabledAgain = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
+
+      expect(getGenericResult(enableEvents).success).to.be.true;
+      expect(enabledBefore).to.be.false;
+      expect(enabled).to.be.true;
+      expect(getGenericResult(enableAgainEvents).success).to.be.true;
+      expect(enabledAgain).to.be.true;
+    });
+  });
+
+});
+
+describe.skip('Negative Integration Test toggleContractAllowList', () => {
+
+  it('Enable allow list for a non-contract', async () => {
+    await usingApi(async (api, privateKeyWrapper) => {
+      const alice = privateKeyWrapper('//Alice');
+      const bobGuineaPig = privateKeyWrapper('//Bob');
+
+      const enabledBefore = (await api.query.unique.contractAllowListEnabled(bobGuineaPig.address)).toJSON();
+      const enableAllowListTx = api.tx.unique.toggleContractAllowList(bobGuineaPig.address, true);
+      await expect(submitTransactionExpectFailAsync(alice, enableAllowListTx)).to.be.rejected;
+      const enabled = (await api.query.unique.contractAllowListEnabled(bobGuineaPig.address)).toJSON();
+
+      expect(enabledBefore).to.be.false;
+      expect(enabled).to.be.false;
+    });
+  });
+
+  it('Enable allow list using a non-owner address', async () => {
+    await usingApi(async (api, privateKeyWrapper) => {
+      const bob = privateKeyWrapper('//Bob');
+      const [contract] = await deployFlipper(api, privateKeyWrapper);
+
+      const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
+      const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
+      await expect(submitTransactionExpectFailAsync(bob, enableAllowListTx)).to.be.rejected;
+      const enabled = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
+
+      expect(enabledBefore).to.be.false;
+      expect(enabled).to.be.false;
+    });
+  });
+
+});
deletedtests/src/toggleContractAllowList.test.tsdiffbeforeafterboth
before · tests/src/toggleContractAllowList.test.ts
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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {21  deployFlipper,22  getFlipValue,23} from './util/contracthelpers';24import {25  getGenericResult,26} from './util/helpers';2728chai.use(chaiAsPromised);29const expect = chai.expect;3031const value = 0;32const gasLimit = 3000n * 1000000n;3334// todo:playgrounds skipped ~ postpone35describe.skip('Integration Test toggleContractAllowList', () => {3637  it('Enable allow list contract mode', async () => {38    await usingApi(async (api, privateKeyWrapper) => {39      const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);4041      const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();42      const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);43      const enableEvents = await submitTransactionAsync(deployer, enableAllowListTx);44      const enabled = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();4546      expect(getGenericResult(enableEvents).success).to.be.true;47      expect(enabledBefore).to.be.false;48      expect(enabled).to.be.true;49    });50  });5152  it('Only allowlisted account can call contract', async () => {53    await usingApi(async (api, privateKeyWrapper) => {54      const bob = privateKeyWrapper('//Bob');5556      const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);5758      let flipValueBefore = await getFlipValue(contract, deployer);59      const flip = contract.tx.flip({value, gasLimit});60      await submitTransactionAsync(bob, flip);61      const flipValueAfter = await getFlipValue(contract,deployer);62      expect(flipValueAfter).to.be.eq(!flipValueBefore, 'Anyone can call new contract.');6364      const deployerCanFlip = async () => {65        const flipValueBefore = await getFlipValue(contract, deployer);66        const deployerFlip = contract.tx.flip({value, gasLimit});67        await submitTransactionAsync(deployer, deployerFlip);68        const aliceFlip1Response = await getFlipValue(contract, deployer);69        expect(aliceFlip1Response).to.be.eq(!flipValueBefore, 'Deployer always can flip.');70      };71      await deployerCanFlip();7273      flipValueBefore = await getFlipValue(contract, deployer);74      const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);75      await submitTransactionAsync(deployer, enableAllowListTx);76      const flipWithEnabledAllowList = contract.tx.flip({value, gasLimit});77      await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledAllowList)).to.be.rejected;78      const flipValueAfterEnableAllowList = await getFlipValue(contract, deployer);79      expect(flipValueAfterEnableAllowList).to.be.eq(flipValueBefore, 'Enabling allowlist doesn\'t make it possible to call contract for everyone.');8081      await deployerCanFlip();8283      flipValueBefore = await getFlipValue(contract, deployer);84      const addBobToAllowListTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);85      await submitTransactionAsync(deployer, addBobToAllowListTx);86      const flipWithAllowlistedBob = contract.tx.flip({value, gasLimit});87      await submitTransactionAsync(bob, flipWithAllowlistedBob);88      const flipAfterAllowListed = await getFlipValue(contract,deployer);89      expect(flipAfterAllowListed).to.be.eq(!flipValueBefore, 'Bob was allowlisted, now he can flip.');9091      await deployerCanFlip();9293      flipValueBefore = await getFlipValue(contract, deployer);94      const removeBobFromAllowListTx = api.tx.unique.removeFromContractAllowList(contract.address, bob.address);95      await submitTransactionAsync(deployer, removeBobFromAllowListTx);96      const bobRemoved = contract.tx.flip({value, gasLimit});97      await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;98      const afterBobRemoved = await getFlipValue(contract, deployer);99      expect(afterBobRemoved).to.be.eq(flipValueBefore, 'Bob can\'t call contract, now when he is removeed from allow list.');100101      await deployerCanFlip();102103      flipValueBefore = await getFlipValue(contract, deployer);104      const disableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, false);105      await submitTransactionAsync(deployer, disableAllowListTx);106      const allowListDisabledFlip = contract.tx.flip({value, gasLimit});107      await submitTransactionAsync(bob, allowListDisabledFlip);108      const afterAllowListDisabled = await getFlipValue(contract,deployer);109      expect(afterAllowListDisabled).to.be.eq(!flipValueBefore, 'Anyone can call contract with disabled allowlist.');110111    });112  });113114  it('Enabling allow list repeatedly should not produce errors', async () => {115    await usingApi(async (api, privateKeyWrapper) => {116      const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);117118      const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();119      const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);120      const enableEvents = await submitTransactionAsync(deployer, enableAllowListTx);121      const enabled = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();122      const enableAgainEvents = await submitTransactionAsync(deployer, enableAllowListTx);123      const enabledAgain = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();124125      expect(getGenericResult(enableEvents).success).to.be.true;126      expect(enabledBefore).to.be.false;127      expect(enabled).to.be.true;128      expect(getGenericResult(enableAgainEvents).success).to.be.true;129      expect(enabledAgain).to.be.true;130    });131  });132133});134135describe.skip('Negative Integration Test toggleContractAllowList', () => {136137  it('Enable allow list for a non-contract', async () => {138    await usingApi(async (api, privateKeyWrapper) => {139      const alice = privateKeyWrapper('//Alice');140      const bobGuineaPig = privateKeyWrapper('//Bob');141142      const enabledBefore = (await api.query.unique.contractAllowListEnabled(bobGuineaPig.address)).toJSON();143      const enableAllowListTx = api.tx.unique.toggleContractAllowList(bobGuineaPig.address, true);144      await expect(submitTransactionExpectFailAsync(alice, enableAllowListTx)).to.be.rejected;145      const enabled = (await api.query.unique.contractAllowListEnabled(bobGuineaPig.address)).toJSON();146147      expect(enabledBefore).to.be.false;148      expect(enabled).to.be.false;149    });150  });151152  it('Enable allow list using a non-owner address', async () => {153    await usingApi(async (api, privateKeyWrapper) => {154      const bob = privateKeyWrapper('//Bob');155      const [contract] = await deployFlipper(api, privateKeyWrapper);156157      const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();158      const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);159      await expect(submitTransactionExpectFailAsync(bob, enableAllowListTx)).to.be.rejected;160      const enabled = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();161162      expect(enabledBefore).to.be.false;163      expect(enabled).to.be.false;164    });165  });166167});
modifiedtests/tsconfig.jsondiffbeforeafterboth
--- a/tests/tsconfig.json
+++ b/tests/tsconfig.json
@@ -20,7 +20,7 @@
   "include": [
     "./src/**/*",
     "./src/interfaces/*.ts"
-, "src/.outdated/collision-tests"  ],
+  ],
   "exclude": [
     "./src/.outdated"
   ],