From 242bfed1c0811a974f8d9bca28487b133f774158 Mon Sep 17 00:00:00 2001 From: Max Andreev Date: Mon, 05 Dec 2022 15:55:14 +0000 Subject: [PATCH] Add zero transfer tests from substrate --- --- a/tests/src/fungible.test.ts +++ b/tests/src/fungible.test.ts @@ -15,7 +15,7 @@ // along with Unique Network. If not, see . import {IKeyringPair} from '@polkadot/types/types'; -import {itSub, usingPlaygrounds, expect} from './util'; +import {itSub, usingPlaygrounds, expect, requirePalletsOrSkip, Pallets} from './util'; const U128_MAX = (1n << 128n) - 1n; @@ -145,3 +145,42 @@ expect(await collection.getBalance(ethAcc)).to.be.equal(10n); }); }); + +describe('Fungible negative tests', () => { + let donor: IKeyringPair; + let alice: IKeyringPair; + let bob: IKeyringPair; + let charlie: IKeyringPair; + + before(async function() { + await usingPlaygrounds(async (helper, privateKey) => { + requirePalletsOrSkip(this, helper, [Pallets.Fungible]); + + donor = await privateKey({filename: __filename}); + [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor); + }); + }); + + itSub('Cannot transfer incorrect amount of tokens', async ({helper}) => { + const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}); + const nonExistingCollection = helper.ft.getCollectionObject(99999); + await collection.mint(alice, 10n, {Substrate: bob.address}); + + // 1. Alice cannot transfer Bob's token: + await expect(collection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.ZeroTransferNotAllowed'); + await expect(collection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow'); + await expect(collection.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow'); + await expect(collection.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow'); + + // 2. Alice cannot transfer non-existing token: + await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.CollectionNotFound'); + await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.CollectionNotFound'); + + // 3. Zero transfer not allowed: + await expect(collection.transfer(bob, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.ZeroTransferNotAllowed'); + + expect(await collection.getBalance({Substrate: alice.address})).to.eq(0n); + expect(await collection.getBalance({Substrate: bob.address})).to.eq(10n); + expect(await collection.getBalance({Substrate: charlie.address})).to.eq(0n); + }); +}); --- a/tests/src/refungible.test.ts +++ b/tests/src/refungible.test.ts @@ -275,16 +275,19 @@ const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address}); const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address}); - // Alice cannot transfer Bob's token: + // 1. Alice cannot transfer Bob's token: await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejected; await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejected; await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejected; await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejected; - // Alice cannot transfer non-existing token: + // 2. Alice cannot transfer non-existing token: await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejected; await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejected; + // 3. Zero transfer not allowed: + await expect(tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.ZeroTransferNotAllowed'); + expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]); expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]); expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n); -- gitstuff