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

difftreelog

source

tests/src/.outdated/overflow.test.ts3.5 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 {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX} from '../deprecated-helpers/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526// todo:playgrounds skipped ~ postponed27describe.skip('Integration Test fungible overflows', () => {28  let alice: IKeyringPair;29  let bob: IKeyringPair;30  let charlie: IKeyringPair;3132  before(async () => {33    await usingApi(async (api, privateKeyWrapper) => {34      alice = privateKeyWrapper('//Alice');35      bob = privateKeyWrapper('//Bob');36      charlie = privateKeyWrapper('//Charlie');37    });38  });3940  it('fails when overflows on transfer', async () => {41    await usingApi(async api => {42      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});4344      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});45      await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');4647      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: 1n});48      await transferExpectFailure(fungibleCollectionId, 0, alice, bob, 1);4950      expect(await getBalance(api, fungibleCollectionId, alice.address, 0)).to.equal(1n);51      expect(await getBalance(api, fungibleCollectionId, bob.address, 0)).to.equal(U128_MAX);52    });53  });5455  it('fails when overflows on transferFrom', async () => {56    await usingApi(async api => {57      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});58      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});59      await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, U128_MAX);60      await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');6162      expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);63      expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(0n);6465      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});66      await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, 1n);67      await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);6869      expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);70      expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(1n);71    });72  });73});