difftreelog
Add zero transfer tests from substrate
in: master
2 files changed
tests/src/fungible.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';18import {itSub, usingPlaygrounds, expect, requirePalletsOrSkip, Pallets} from './util';191920const U128_MAX = (1n << 128n) - 1n;20const U128_MAX = (1n << 128n) - 1n;2121146 });146 });147});147});148149describe('Fungible negative tests', () => {150 let donor: IKeyringPair;151 let alice: IKeyringPair;152 let bob: IKeyringPair;153 let charlie: IKeyringPair;154155 before(async function() {156 await usingPlaygrounds(async (helper, privateKey) => {157 requirePalletsOrSkip(this, helper, [Pallets.Fungible]);158159 donor = await privateKey({filename: __filename});160 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);161 });162 });163164 itSub('Cannot transfer incorrect amount of tokens', async ({helper}) => {165 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});166 const nonExistingCollection = helper.ft.getCollectionObject(99999);167 await collection.mint(alice, 10n, {Substrate: bob.address});168169 // 1. Alice cannot transfer Bob's token:170 await expect(collection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.ZeroTransferNotAllowed');171 await expect(collection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');172 await expect(collection.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');173 await expect(collection.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');174 175 // 2. Alice cannot transfer non-existing token:176 await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.CollectionNotFound');177 await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.CollectionNotFound');178179 // 3. Zero transfer not allowed:180 await expect(collection.transfer(bob, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.ZeroTransferNotAllowed');181182 expect(await collection.getBalance({Substrate: alice.address})).to.eq(0n);183 expect(await collection.getBalance({Substrate: bob.address})).to.eq(10n);184 expect(await collection.getBalance({Substrate: charlie.address})).to.eq(0n);185 });186});148187tests/src/refungible.test.tsdiffbeforeafterboth--- 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);