difftreelog
chore add check for ERC-20 transfer event on ERC-721 transfer method call
in: master
1 file changed
tests/src/eth/reFungible.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {createCollectionExpectSuccess, transfer, UNIQUE} from '../util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress} from './util/helpers';19import reFungibleAbi from './reFungibleAbi.json';20import reFungibleTokenAbi from './reFungibleTokenAbi.json';21import {expect} from 'chai';2223describe('Refungible: Information getting', () => {24 itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {25 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);26 const helper = evmCollectionHelpers(web3, caller);27 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();28 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);29 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});30 const nextTokenId = await contract.methods.nextTokenId().call();31 await contract.methods.mint(caller, nextTokenId).send();32 const totalSupply = await contract.methods.totalSupply().call();33 expect(totalSupply).to.equal('1');34 });3536 itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {37 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);38 const helper = evmCollectionHelpers(web3, caller);39 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();40 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);41 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});4243 {44 const nextTokenId = await contract.methods.nextTokenId().call();45 await contract.methods.mint(caller, nextTokenId).send();46 }47 {48 const nextTokenId = await contract.methods.nextTokenId().call();49 await contract.methods.mint(caller, nextTokenId).send();50 }51 {52 const nextTokenId = await contract.methods.nextTokenId().call();53 await contract.methods.mint(caller, nextTokenId).send();54 }5556 const balance = await contract.methods.balanceOf(caller).call();5758 expect(balance).to.equal('3');59 });6061 itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {62 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);63 const helper = evmCollectionHelpers(web3, caller);64 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();65 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);66 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});6768 const tokenId = await contract.methods.nextTokenId().call();69 await contract.methods.mint(caller, tokenId).send();7071 const owner = await contract.methods.ownerOf(tokenId).call();7273 expect(owner).to.equal(caller);74 });7576 itWeb3('ownerOf after burn', async ({api, web3, privateKeyWrapper}) => {77 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);78 const receiver = createEthAccount(web3);79 const helper = evmCollectionHelpers(web3, caller);80 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();81 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);82 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});8384 const tokenId = await contract.methods.nextTokenId().call();85 await contract.methods.mint(caller, tokenId).send();8687 const tokenAddress = tokenIdToAddress(collectionId, tokenId);88 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});8990 await tokenContract.methods.repartition(2).send();91 await tokenContract.methods.transfer(receiver, 1).send();9293 await tokenContract.methods.burnFrom(caller, 1).send();9495 const owner = await contract.methods.ownerOf(tokenId).call();9697 expect(owner).to.equal(receiver);98 });99100 itWeb3('ownerOf for partial ownership', async ({api, web3, privateKeyWrapper}) => {101 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);102 const receiver = createEthAccount(web3);103 const helper = evmCollectionHelpers(web3, caller);104 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();105 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);106 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});107108 const tokenId = await contract.methods.nextTokenId().call();109 await contract.methods.mint(caller, tokenId).send();110111 const tokenAddress = tokenIdToAddress(collectionId, tokenId);112 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});113114 await tokenContract.methods.repartition(2).send();115 await tokenContract.methods.transfer(receiver, 1).send();116117 const owner = await contract.methods.ownerOf(tokenId).call();118119 expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');120 });121});122123describe('Refungible: Plain calls', () => {124 itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {125 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);126 const helper = evmCollectionHelpers(web3, owner);127 let result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();128 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);129 const receiver = createEthAccount(web3);130 const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});131 const nextTokenId = await contract.methods.nextTokenId().call();132133 expect(nextTokenId).to.be.equal('1');134 result = await contract.methods.mintWithTokenURI(135 receiver,136 nextTokenId,137 'Test URI',138 ).send();139140 const events = normalizeEvents(result.events);141142 expect(events).to.include.deep.members([143 {144 address: collectionIdAddress,145 event: 'Transfer',146 args: {147 from: '0x0000000000000000000000000000000000000000',148 to: receiver,149 tokenId: nextTokenId,150 },151 },152 ]);153154 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');155 });156157 itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {158 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);159 const helper = evmCollectionHelpers(web3, caller);160 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();161 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);162 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});163164 const receiver = createEthAccount(web3);165166 {167 const nextTokenId = await contract.methods.nextTokenId().call();168 expect(nextTokenId).to.be.equal('1');169 const result = await contract.methods.mintBulkWithTokenURI(170 receiver,171 [172 [nextTokenId, 'Test URI 0'],173 [+nextTokenId + 1, 'Test URI 1'],174 [+nextTokenId + 2, 'Test URI 2'],175 ],176 ).send();177 const events = normalizeEvents(result.events);178179 expect(events).to.include.deep.members([180 {181 address: collectionIdAddress,182 event: 'Transfer',183 args: {184 from: '0x0000000000000000000000000000000000000000',185 to: receiver,186 tokenId: nextTokenId,187 },188 },189 {190 address: collectionIdAddress,191 event: 'Transfer',192 args: {193 from: '0x0000000000000000000000000000000000000000',194 to: receiver,195 tokenId: String(+nextTokenId + 1),196 },197 },198 {199 address: collectionIdAddress,200 event: 'Transfer',201 args: {202 from: '0x0000000000000000000000000000000000000000',203 to: receiver,204 tokenId: String(+nextTokenId + 2),205 },206 },207 ]);208209 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');210 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');211 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');212 }213 });214215 itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {216 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);217 const helper = evmCollectionHelpers(web3, caller);218 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();219 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);220 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});221222 const tokenId = await contract.methods.nextTokenId().call();223 await contract.methods.mint(caller, tokenId).send();224 {225 const result = await contract.methods.burn(tokenId).send();226 const events = normalizeEvents(result.events);227 expect(events).to.include.deep.members([228 {229 address: collectionIdAddress,230 event: 'Transfer',231 args: {232 from: caller,233 to: '0x0000000000000000000000000000000000000000',234 tokenId: tokenId.toString(),235 },236 },237 ]);238 }239 });240241 itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {242 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);243 const helper = evmCollectionHelpers(web3, caller);244 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();245 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);246 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});247248 const receiver = createEthAccount(web3);249250 const tokenId = await contract.methods.nextTokenId().call();251 await contract.methods.mint(caller, tokenId).send();252 {253 const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();254 const events = normalizeEvents(result.events);255 expect(events).to.include.deep.members([256 {257 address: collectionIdAddress,258 event: 'Transfer',259 args: {260 from: caller,261 to: receiver,262 tokenId: tokenId.toString(),263 },264 },265 ]);266 }267268 {269 const balance = await contract.methods.balanceOf(receiver).call();270 expect(+balance).to.equal(1);271 }272273 {274 const balance = await contract.methods.balanceOf(caller).call();275 expect(+balance).to.equal(0);276 }277 });278279 itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {280 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);281 const helper = evmCollectionHelpers(web3, caller);282 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();283 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);284 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});285286 const receiver = createEthAccount(web3);287288 const tokenId = await contract.methods.nextTokenId().call();289 await contract.methods.mint(caller, tokenId).send();290291 {292 const result = await contract.methods.transfer(receiver, tokenId).send();293 const events = normalizeEvents(result.events);294 expect(events).to.include.deep.members([295 {296 address: collectionIdAddress,297 event: 'Transfer',298 args: {299 from: caller,300 to: receiver,301 tokenId: tokenId.toString(),302 },303 },304 ]);305 }306307 {308 const balance = await contract.methods.balanceOf(caller).call();309 expect(+balance).to.equal(0);310 }311312 {313 const balance = await contract.methods.balanceOf(receiver).call();314 expect(+balance).to.equal(1);315 }316 });317318 itWeb3('transfer event on transfer from partial ownership to full ownership', async ({api, web3, privateKeyWrapper}) => {319 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);320 const receiver = createEthAccount(web3);321 const helper = evmCollectionHelpers(web3, caller);322 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();323 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);324 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});325326 const tokenId = await contract.methods.nextTokenId().call();327 await contract.methods.mint(caller, tokenId).send();328329 const tokenAddress = tokenIdToAddress(collectionId, tokenId);330 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});331332 await tokenContract.methods.repartition(2).send();333 await tokenContract.methods.transfer(receiver, 1).send();334335 const events = await recordEvents(contract, async () => 336 await tokenContract.methods.transfer(receiver, 1).send());337 expect(events).to.deep.equal([338 {339 address: collectionIdAddress,340 event: 'Transfer',341 args: {342 from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',343 to: receiver,344 tokenId: tokenId.toString(),345 },346 },347 ]);348 });349350 itWeb3('transfer event on transfer from full ownership to partial ownership', async ({api, web3, privateKeyWrapper}) => {351 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);352 const receiver = createEthAccount(web3);353 const helper = evmCollectionHelpers(web3, caller);354 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();355 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);356 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});357358 const tokenId = await contract.methods.nextTokenId().call();359 await contract.methods.mint(caller, tokenId).send();360361 const tokenAddress = tokenIdToAddress(collectionId, tokenId);362 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});363364 await tokenContract.methods.repartition(2).send();365 366 const events = await recordEvents(contract, async () => 367 await tokenContract.methods.transfer(receiver, 1).send());368 369 expect(events).to.deep.equal([370 {371 address: collectionIdAddress,372 event: 'Transfer',373 args: {374 from: caller,375 to: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',376 tokenId: tokenId.toString(),377 },378 },379 ]);380 });381});382383describe('RFT: Fees', () => {384 itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {385 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);386 const helper = evmCollectionHelpers(web3, caller);387 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();388 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);389 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});390391 const receiver = createEthAccount(web3);392393 const tokenId = await contract.methods.nextTokenId().call();394 await contract.methods.mint(caller, tokenId).send();395396 const cost = await recordEthFee(api, caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());397 expect(cost < BigInt(0.2 * Number(UNIQUE)));398 expect(cost > 0n);399 });400401 itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {402 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);403 const helper = evmCollectionHelpers(web3, caller);404 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();405 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);406 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});407408 const receiver = createEthAccount(web3);409410 const tokenId = await contract.methods.nextTokenId().call();411 await contract.methods.mint(caller, tokenId).send();412413 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send());414 expect(cost < BigInt(0.2 * Number(UNIQUE)));415 expect(cost > 0n);416 });417});418419describe('Common metadata', () => {420 itWeb3('Returns collection name', async ({api, web3, privateKeyWrapper}) => {421 const collection = await createCollectionExpectSuccess({422 name: 'token name',423 mode: {type: 'ReFungible'},424 });425 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);426427 const address = collectionIdToAddress(collection);428 const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});429 const name = await contract.methods.name().call();430431 expect(name).to.equal('token name');432 });433434 itWeb3('Returns symbol name', async ({api, web3, privateKeyWrapper}) => {435 const collection = await createCollectionExpectSuccess({436 tokenPrefix: 'TOK',437 mode: {type: 'ReFungible'},438 });439 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);440441 const address = collectionIdToAddress(collection);442 const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});443 const symbol = await contract.methods.symbol().call();444445 expect(symbol).to.equal('TOK');446 });447});