git.delta.rocks / unique-network / refs/commits / 21f171f02141

difftreelog

source

tests/src/overflow.test.ts3.4 KiBsourcehistory
1import { IKeyringPair } from "@polkadot/types/types";2import chai from 'chai';3import chaiAsPromised from "chai-as-promised";4import privateKey from "./substrate/privateKey";5import usingApi from "./substrate/substrate-api";6import { approveExpectFail, approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getFungibleBalance, transferExpectFail, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX } from "./util/helpers";78chai.use(chaiAsPromised);9const expect = chai.expect;1011describe('Integration Test fungible overflows', () => {12    let alice: IKeyringPair;13    let bob: IKeyringPair;14    let charlie: IKeyringPair;1516    before(async () => {17        await usingApi(async () => {18            alice = privateKey('//Alice');19            bob = privateKey('//Bob');20            charlie = privateKey('//Charlie');21        });22    });2324    it('fails when overflows on transfer', async () => {25        await usingApi(async () => {26            const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });2728            await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });29            await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');3031            await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 1n });32            await transferExpectFail(fungibleCollectionId, 0, alice, bob, 1, 'Fungible');3334            expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);35            expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);36        });37    });3839    it('fails on allowance overflow', async () => {40        await usingApi(async () => {41            const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });4243            await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });44            await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);45            await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);46        });47    });4849    it('fails when overflows on transferFrom', async () => {50        await usingApi(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    });68});