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});1// 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, UNIQUE} from '../util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress} from './util/helpers';19import reFungibleTokenAbi from './reFungibleTokenAbi.json';20import {expect} from 'chai';2122describe('Refungible: Information getting', () => {23 itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {24 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);25 const helper = evmCollectionHelpers(web3, caller);26 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();27 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);28 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});29 const nextTokenId = await contract.methods.nextTokenId().call();30 await contract.methods.mint(caller, nextTokenId).send();31 const totalSupply = await contract.methods.totalSupply().call();32 expect(totalSupply).to.equal('1');33 });3435 itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {36 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);37 const helper = evmCollectionHelpers(web3, caller);38 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();39 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);40 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});4142 {43 const nextTokenId = await contract.methods.nextTokenId().call();44 await contract.methods.mint(caller, nextTokenId).send();45 }46 {47 const nextTokenId = await contract.methods.nextTokenId().call();48 await contract.methods.mint(caller, nextTokenId).send();49 }50 {51 const nextTokenId = await contract.methods.nextTokenId().call();52 await contract.methods.mint(caller, nextTokenId).send();53 }5455 const balance = await contract.methods.balanceOf(caller).call();5657 expect(balance).to.equal('3');58 });5960 itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {61 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);62 const helper = evmCollectionHelpers(web3, caller);63 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();64 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);65 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});6667 const tokenId = await contract.methods.nextTokenId().call();68 await contract.methods.mint(caller, tokenId).send();6970 const owner = await contract.methods.ownerOf(tokenId).call();7172 expect(owner).to.equal(caller);73 });7475 itWeb3('ownerOf after burn', async ({api, web3, privateKeyWrapper}) => {76 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);77 const receiver = createEthAccount(web3);78 const helper = evmCollectionHelpers(web3, caller);79 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();80 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);81 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});8283 const tokenId = await contract.methods.nextTokenId().call();84 await contract.methods.mint(caller, tokenId).send();8586 const tokenAddress = tokenIdToAddress(collectionId, tokenId);87 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});8889 await tokenContract.methods.repartition(2).send();90 await tokenContract.methods.transfer(receiver, 1).send();9192 await tokenContract.methods.burnFrom(caller, 1).send();9394 const owner = await contract.methods.ownerOf(tokenId).call();9596 expect(owner).to.equal(receiver);97 });9899 itWeb3('ownerOf for partial ownership', async ({api, web3, privateKeyWrapper}) => {100 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);101 const receiver = createEthAccount(web3);102 const helper = evmCollectionHelpers(web3, caller);103 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();104 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);105 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});106107 const tokenId = await contract.methods.nextTokenId().call();108 await contract.methods.mint(caller, tokenId).send();109110 const tokenAddress = tokenIdToAddress(collectionId, tokenId);111 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});112113 await tokenContract.methods.repartition(2).send();114 await tokenContract.methods.transfer(receiver, 1).send();115116 const owner = await contract.methods.ownerOf(tokenId).call();117118 expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');119 });120});121122describe('Refungible: Plain calls', () => {123 itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {124 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);125 const helper = evmCollectionHelpers(web3, owner);126 let result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();127 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);128 const receiver = createEthAccount(web3);129 const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});130 const nextTokenId = await contract.methods.nextTokenId().call();131132 expect(nextTokenId).to.be.equal('1');133 result = await contract.methods.mintWithTokenURI(134 receiver,135 nextTokenId,136 'Test URI',137 ).send();138139 const events = normalizeEvents(result.events);140141 expect(events).to.include.deep.members([142 {143 address: collectionIdAddress,144 event: 'Transfer',145 args: {146 from: '0x0000000000000000000000000000000000000000',147 to: receiver,148 tokenId: nextTokenId,149 },150 },151 ]);152153 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');154 });155156 itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {157 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);158 const helper = evmCollectionHelpers(web3, caller);159 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();160 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);161 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});162163 const receiver = createEthAccount(web3);164165 {166 const nextTokenId = await contract.methods.nextTokenId().call();167 expect(nextTokenId).to.be.equal('1');168 const result = await contract.methods.mintBulkWithTokenURI(169 receiver,170 [171 [nextTokenId, 'Test URI 0'],172 [+nextTokenId + 1, 'Test URI 1'],173 [+nextTokenId + 2, 'Test URI 2'],174 ],175 ).send();176 const events = normalizeEvents(result.events);177178 expect(events).to.include.deep.members([179 {180 address: collectionIdAddress,181 event: 'Transfer',182 args: {183 from: '0x0000000000000000000000000000000000000000',184 to: receiver,185 tokenId: nextTokenId,186 },187 },188 {189 address: collectionIdAddress,190 event: 'Transfer',191 args: {192 from: '0x0000000000000000000000000000000000000000',193 to: receiver,194 tokenId: String(+nextTokenId + 1),195 },196 },197 {198 address: collectionIdAddress,199 event: 'Transfer',200 args: {201 from: '0x0000000000000000000000000000000000000000',202 to: receiver,203 tokenId: String(+nextTokenId + 2),204 },205 },206 ]);207208 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');209 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');210 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');211 }212 });213214 itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {215 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);216 const helper = evmCollectionHelpers(web3, caller);217 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();218 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);219 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});220221 const tokenId = await contract.methods.nextTokenId().call();222 await contract.methods.mint(caller, tokenId).send();223 {224 const result = await contract.methods.burn(tokenId).send();225 const events = normalizeEvents(result.events);226 expect(events).to.include.deep.members([227 {228 address: collectionIdAddress,229 event: 'Transfer',230 args: {231 from: caller,232 to: '0x0000000000000000000000000000000000000000',233 tokenId: tokenId.toString(),234 },235 },236 ]);237 }238 });239240 itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {241 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);242 const helper = evmCollectionHelpers(web3, caller);243 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();244 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);245 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});246247 const receiver = createEthAccount(web3);248249 const tokenId = await contract.methods.nextTokenId().call();250 await contract.methods.mint(caller, tokenId).send();251252 const address = tokenIdToAddress(collectionId, tokenId);253 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});254 await tokenContract.methods.repartition(15).send();255256 {257 const erc20Events = await recordEvents(tokenContract, async () => {258 const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();259 const events = normalizeEvents(result.events);260 expect(events).to.include.deep.members([261 {262 address: collectionIdAddress,263 event: 'Transfer',264 args: {265 from: caller,266 to: receiver,267 tokenId: tokenId.toString(),268 },269 },270 ]);271 });272 273 expect(erc20Events).to.include.deep.members([274 {275 address,276 event: 'Transfer',277 args: {278 from: caller,279 to: receiver,280 value: '15',281 },282 },283 ]);284 }285286 {287 const balance = await contract.methods.balanceOf(receiver).call();288 expect(+balance).to.equal(1);289 }290291 {292 const balance = await contract.methods.balanceOf(caller).call();293 expect(+balance).to.equal(0);294 }295 });296297 itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {298 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);299 const helper = evmCollectionHelpers(web3, caller);300 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();301 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);302 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});303304 const receiver = createEthAccount(web3);305306 const tokenId = await contract.methods.nextTokenId().call();307 await contract.methods.mint(caller, tokenId).send();308309 {310 const result = await contract.methods.transfer(receiver, tokenId).send();311 const events = normalizeEvents(result.events);312 expect(events).to.include.deep.members([313 {314 address: collectionIdAddress,315 event: 'Transfer',316 args: {317 from: caller,318 to: receiver,319 tokenId: tokenId.toString(),320 },321 },322 ]);323 }324325 {326 const balance = await contract.methods.balanceOf(caller).call();327 expect(+balance).to.equal(0);328 }329330 {331 const balance = await contract.methods.balanceOf(receiver).call();332 expect(+balance).to.equal(1);333 }334 });335336 itWeb3('transfer event on transfer from partial ownership to full ownership', async ({api, web3, privateKeyWrapper}) => {337 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);338 const receiver = createEthAccount(web3);339 const helper = evmCollectionHelpers(web3, caller);340 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();341 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);342 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});343344 const tokenId = await contract.methods.nextTokenId().call();345 await contract.methods.mint(caller, tokenId).send();346347 const tokenAddress = tokenIdToAddress(collectionId, tokenId);348 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});349350 await tokenContract.methods.repartition(2).send();351 await tokenContract.methods.transfer(receiver, 1).send();352353 const events = await recordEvents(contract, async () => 354 await tokenContract.methods.transfer(receiver, 1).send());355 expect(events).to.deep.equal([356 {357 address: collectionIdAddress,358 event: 'Transfer',359 args: {360 from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',361 to: receiver,362 tokenId: tokenId.toString(),363 },364 },365 ]);366 });367368 itWeb3('transfer event on transfer from full ownership to partial ownership', async ({api, web3, privateKeyWrapper}) => {369 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);370 const receiver = createEthAccount(web3);371 const helper = evmCollectionHelpers(web3, caller);372 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();373 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);374 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});375376 const tokenId = await contract.methods.nextTokenId().call();377 await contract.methods.mint(caller, tokenId).send();378379 const tokenAddress = tokenIdToAddress(collectionId, tokenId);380 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});381382 await tokenContract.methods.repartition(2).send();383 384 const events = await recordEvents(contract, async () => 385 await tokenContract.methods.transfer(receiver, 1).send());386 387 expect(events).to.deep.equal([388 {389 address: collectionIdAddress,390 event: 'Transfer',391 args: {392 from: caller,393 to: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',394 tokenId: tokenId.toString(),395 },396 },397 ]);398 });399});400401describe('RFT: Fees', () => {402 itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {403 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);404 const helper = evmCollectionHelpers(web3, caller);405 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();406 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);407 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});408409 const receiver = createEthAccount(web3);410411 const tokenId = await contract.methods.nextTokenId().call();412 await contract.methods.mint(caller, tokenId).send();413414 const cost = await recordEthFee(api, caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());415 expect(cost < BigInt(0.2 * Number(UNIQUE)));416 expect(cost > 0n);417 });418419 itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {420 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);421 const helper = evmCollectionHelpers(web3, caller);422 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();423 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);424 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});425426 const receiver = createEthAccount(web3);427428 const tokenId = await contract.methods.nextTokenId().call();429 await contract.methods.mint(caller, tokenId).send();430431 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send());432 expect(cost < BigInt(0.2 * Number(UNIQUE)));433 expect(cost > 0n);434 });435});436437describe('Common metadata', () => {438 itWeb3('Returns collection name', async ({api, web3, privateKeyWrapper}) => {439 const collection = await createCollectionExpectSuccess({440 name: 'token name',441 mode: {type: 'ReFungible'},442 });443 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);444445 const address = collectionIdToAddress(collection);446 const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});447 const name = await contract.methods.name().call();448449 expect(name).to.equal('token name');450 });451452 itWeb3('Returns symbol name', async ({api, web3, privateKeyWrapper}) => {453 const collection = await createCollectionExpectSuccess({454 tokenPrefix: 'TOK',455 mode: {type: 'ReFungible'},456 });457 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);458459 const address = collectionIdToAddress(collection);460 const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});461 const symbol = await contract.methods.symbol().call();462463 expect(symbol).to.equal('TOK');464 });465});