git.delta.rocks / unique-network / refs/commits / 2f762b2117bd

difftreelog

Add regungible burn test and fix fungible zero transfer test

Max Andreev2022-12-06parent: #d0fe2e9.patch.diff
in: master

2 files changed

modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -140,6 +140,31 @@
     await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
   });
 
+  itSub('RFT: cannot burn non-owned token pieces', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice);
+    const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+    const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+    // 1. Cannot burn non-owned token:
+    await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
+    // 2. Cannot burn non-existing token:
+    await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
+    await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
+    // 3. Can burn zero amount of owned tokens (EIP-20)
+    await aliceToken.burn(alice, 0n);
+
+    // 4. Storage is not corrupted:
+    expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+    expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+
+    // 4.1 Tokens can be transfered:
+    await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
+    await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
+    expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+    expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+  });
+
   itSub('Transfer a burned token', async ({helper}) => {
     const collection = await helper.nft.mintCollection(alice);
     const token = await collection.mintToken(alice);
modifiedtests/src/fungible.test.tsdiffbeforeafterboth
166 const nonExistingCollection = helper.ft.getCollectionObject(99999);166 const nonExistingCollection = helper.ft.getCollectionObject(99999);
167 await collection.mint(alice, 10n, {Substrate: bob.address});167 await collection.mint(alice, 10n, {Substrate: bob.address});
168168
169 // 1. Alice cannot transfer Bob's token:169 // 1. Alice cannot transfer more than 0 tokens if balance low:
170 await expect(collection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
171 await expect(collection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');170 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');171 await expect(collection.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
174 172
175 // 2. Alice cannot transfer non-existing token:173 // 2. Alice cannot transfer non-existing token:
178176
179 // 3. Zero transfer allowed (EIP-20):177 // 3. Zero transfer allowed (EIP-20):
180 await collection.transfer(bob, {Substrate: charlie.address}, 0n);178 await collection.transfer(bob, {Substrate: charlie.address}, 0n);
179 // 3.1 even if the balance = 0
180 await collection.transfer(alice, {Substrate: charlie.address}, 0n);
181181
182 expect(await collection.getBalance({Substrate: alice.address})).to.eq(0n);182 expect(await collection.getBalance({Substrate: alice.address})).to.eq(0n);
183 expect(await collection.getBalance({Substrate: bob.address})).to.eq(10n);183 expect(await collection.getBalance({Substrate: bob.address})).to.eq(10n);