git.delta.rocks / unique-network / refs/commits / 6c48590c156a

difftreelog

source

tests/src/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 './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526describe.skip('Integration Test fungible overflows', () => {27  let alice: IKeyringPair;28  let bob: IKeyringPair;29  let charlie: IKeyringPair;3031  before(async () => {32    await usingApi(async (api, privateKeyWrapper) => {33      alice = privateKeyWrapper('//Alice');34      bob = privateKeyWrapper('//Bob');35      charlie = privateKeyWrapper('//Charlie');36    });37  });3839  it('fails when overflows on transfer', async () => {40    await usingApi(async api => {41      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});4243      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});44      await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');4546      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: 1n});47      await transferExpectFailure(fungibleCollectionId, 0, alice, bob, 1);4849      expect(await getBalance(api, fungibleCollectionId, alice.address, 0)).to.equal(1n);50      expect(await getBalance(api, fungibleCollectionId, bob.address, 0)).to.equal(U128_MAX);51    });52  });5354  it('fails when overflows on transferFrom', async () => {55    await usingApi(async api => {56      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});57      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});58      await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, U128_MAX);59      await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');6061      expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);62      expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(0n);6364      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});65      await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, 1n);66      await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);6768      expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);69      expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(1n);70    });71  });72});