123456import { 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 { approveExpectFail, approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getFungibleBalance, transferExpectFail, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX } from "./util/helpers";1213chai.use(chaiAsPromised);14const expect = chai.expect;1516describe('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 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });3132 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });33 await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');3435 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 1n });36 await transferExpectFail(fungibleCollectionId, 0, alice, bob, 1, 'Fungible');3738 expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);39 expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);40 });4142 it('fails on allowance overflow', async () => {43 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });4445 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });46 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);47 await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);48 });4950 it('fails when overflows on transferFrom', async () => {51 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });5253 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });54 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);55 await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');5657 expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);58 expect(await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).to.equal(0n);5960 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });61 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, 1n);62 await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);6364 expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);65 expect(await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).to.equal(0n);66 });67});