difftreelog
Add zero transfer tests from substrate
in: master
2 files changed
tests/src/fungible.test.tsdiffbeforeafterboth--- a/tests/src/fungible.test.ts
+++ b/tests/src/fungible.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
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);
+ });
+});
tests/src/refungible.test.tsdiffbeforeafterboth275 const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});275 const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});276 const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});276 const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});277277278 // Alice cannot transfer Bob's token:278 // 1. Alice cannot transfer Bob's token:279 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejected;279 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejected;280 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejected;280 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejected;281 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejected;281 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejected;282 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejected;282 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejected;283 283 284 // Alice cannot transfer non-existing token:284 // 2. Alice cannot transfer non-existing token:285 await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejected;285 await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejected;286 await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejected;286 await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejected;287288 // 3. Zero transfer not allowed:289 await expect(tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.ZeroTransferNotAllowed');287290288 expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);291 expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);289 expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);292 expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);