git.delta.rocks / unique-network / refs/commits / 242bfed1c081

difftreelog

Add zero transfer tests from substrate

Max Andreev2022-12-05parent: #f66a1ba.patch.diff
in: master

2 files changed

modifiedtests/src/fungible.test.tsdiffbeforeafterboth
15// 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/>.
1616
17import {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';
1919
20const U128_MAX = (1n << 128n) - 1n;20const U128_MAX = (1n << 128n) - 1n;
2121
146 });146 });
147});147});
148
149describe('Fungible negative tests', () => {
150 let donor: IKeyringPair;
151 let alice: IKeyringPair;
152 let bob: IKeyringPair;
153 let charlie: IKeyringPair;
154
155 before(async function() {
156 await usingPlaygrounds(async (helper, privateKey) => {
157 requirePalletsOrSkip(this, helper, [Pallets.Fungible]);
158
159 donor = await privateKey({filename: __filename});
160 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
161 });
162 });
163
164 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});
168
169 // 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');
178
179 // 3. Zero transfer not allowed:
180 await expect(collection.transfer(bob, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.ZeroTransferNotAllowed');
181
182 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});
148187
modifiedtests/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);