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

difftreelog

source

tests/src/overflow.test.ts2.9 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi from './substrate/substrate-api';11import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX} from './util/helpers';1213chai.use(chaiAsPromised);14const expect = chai.expect;1516describe.skip('Integration Test fungible overflows', () => {17  let alice: IKeyringPair;18  let bob: IKeyringPair;19  let charlie: IKeyringPair;2021  before(async () => {22    await usingApi(async () => {23      alice = privateKey('//Alice');24      bob = privateKey('//Bob');25      charlie = privateKey('//Charlie');26    });27  });2829  it('fails when overflows on transfer', async () => {30    await usingApi(async api => {31      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});3233      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});34      await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');3536      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: 1n});37      await transferExpectFailure(fungibleCollectionId, 0, alice, bob, 1);3839      expect(await getBalance(api, fungibleCollectionId, alice.address, 0)).to.equal(1n);40      expect(await getBalance(api, fungibleCollectionId, bob.address, 0)).to.equal(U128_MAX);41    });42  });4344  it('fails when overflows on transferFrom', async () => {45    await usingApi(async api => {46      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});47      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});48      await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, U128_MAX);49      await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');5051      expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);52      expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(0n);5354      await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});55      await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, 1n);56      await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);5758      expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);59      expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(1n);60    });61  });62});