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
140 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');140 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
141 });141 });
142
143 itSub('RFT: cannot burn non-owned token pieces', async ({helper}) => {
144 const collection = await helper.rft.mintCollection(alice);
145 const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
146 const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
147
148 // 1. Cannot burn non-owned token:
149 await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
150 await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
151 // 2. Cannot burn non-existing token:
152 await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
153 await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
154 // 3. Can burn zero amount of owned tokens (EIP-20)
155 await aliceToken.burn(alice, 0n);
156
157 // 4. Storage is not corrupted:
158 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
159 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
160
161 // 4.1 Tokens can be transfered:
162 await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
163 await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
164 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
165 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
166 });
142167
143 itSub('Transfer a burned token', async ({helper}) => {168 itSub('Transfer a burned token', async ({helper}) => {
144 const collection = await helper.nft.mintCollection(alice);169 const collection = await helper.nft.mintCollection(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);