difftreelog
test(refungible-pallet) add tests for ERC-721 EVM API
in: master
3 files 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} from '../util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, 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 = new web3.eth.Contract(reFungibleAbi as any, collectionIdAddress, {from: caller, ...GAS_ARGS});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 = new web3.eth.Contract(reFungibleAbi as any, collectionIdAddress, {from: caller, ...GAS_ARGS});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 = new web3.eth.Contract(reFungibleAbi as any, collectionIdAddress, {from: caller, ...GAS_ARGS});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 = new web3.eth.Contract(reFungibleAbi as any, collectionIdAddress, {from: caller, ...GAS_ARGS});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 });99});100101describe('Refungible: Plain calls', () => {102 itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {103 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);104 const helper = evmCollectionHelpers(web3, owner);105 let result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();106 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);107 const receiver = createEthAccount(web3);108 const contract = evmCollection(web3, owner, collectionIdAddress);109 const nextTokenId = await contract.methods.nextTokenId().call();110111 expect(nextTokenId).to.be.equal('1');112 result = await contract.methods.mintWithTokenURI(113 receiver,114 nextTokenId,115 'Test URI',116 ).send();117118 const events = normalizeEvents(result.events);119120 expect(events).to.include.deep.members([121 {122 address: collectionIdAddress,123 event: 'Transfer',124 args: {125 from: '0x0000000000000000000000000000000000000000',126 to: receiver,127 tokenId: nextTokenId,128 },129 },130 ]);131132 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');133 });134135 itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {136 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);137 const helper = evmCollectionHelpers(web3, caller);138 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();139 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);140 const contract = new web3.eth.Contract(reFungibleAbi as any, collectionIdAddress, {from: caller, ...GAS_ARGS});141142 const receiver = createEthAccount(web3);143144 {145 const nextTokenId = await contract.methods.nextTokenId().call();146 expect(nextTokenId).to.be.equal('1');147 const result = await contract.methods.mintBulkWithTokenURI(148 receiver,149 [150 [nextTokenId, 'Test URI 0'],151 [+nextTokenId + 1, 'Test URI 1'],152 [+nextTokenId + 2, 'Test URI 2'],153 ],154 ).send();155 const events = normalizeEvents(result.events);156157 expect(events).to.include.deep.members([158 {159 address: collectionIdAddress,160 event: 'Transfer',161 args: {162 from: '0x0000000000000000000000000000000000000000',163 to: receiver,164 tokenId: nextTokenId,165 },166 },167 {168 address: collectionIdAddress,169 event: 'Transfer',170 args: {171 from: '0x0000000000000000000000000000000000000000',172 to: receiver,173 tokenId: String(+nextTokenId + 1),174 },175 },176 {177 address: collectionIdAddress,178 event: 'Transfer',179 args: {180 from: '0x0000000000000000000000000000000000000000',181 to: receiver,182 tokenId: String(+nextTokenId + 2),183 },184 },185 ]);186187 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');188 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');189 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');190 }191 });192});193194describe('Common metadata', () => {195 itWeb3('Returns collection name', async ({api, web3, privateKeyWrapper}) => {196 const collection = await createCollectionExpectSuccess({197 name: 'token name',198 mode: {type: 'ReFungible'},199 });200 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);201202 const address = collectionIdToAddress(collection);203 const contract = new web3.eth.Contract(reFungibleAbi as any, address, {from: caller, ...GAS_ARGS});204 const name = await contract.methods.name().call();205206 expect(name).to.equal('token name');207 });208209 itWeb3('Returns symbol name', async ({api, web3, privateKeyWrapper}) => {210 const collection = await createCollectionExpectSuccess({211 tokenPrefix: 'TOK',212 mode: {type: 'ReFungible'},213 });214 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);215216 const address = collectionIdToAddress(collection);217 const contract = new web3.eth.Contract(reFungibleAbi as any, address, {from: caller, ...GAS_ARGS});218 const symbol = await contract.methods.symbol().call();219220 expect(symbol).to.equal('TOK');221 });222});tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -74,7 +74,7 @@
});
// FIXME: Need erc721 for ReFubgible.
-describe.skip('Check ERC721 token URI for ReFungible', () => {
+describe('Check ERC721 token URI for ReFungible', () => {
itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const helper = evmCollectionHelpers(web3, owner);
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -31,7 +31,7 @@
import collectionHelpersAbi from '../collectionHelpersAbi.json';
import fungibleAbi from '../fungibleAbi.json';
import nonFungibleAbi from '../nonFungibleAbi.json';
-import refungibleAbi from '../refungibleAbi.json';
+import refungibleAbi from '../reFungibleAbi.json';
import contractHelpersAbi from './contractHelpersAbi.json';
export const GAS_ARGS = {gas: 2500000};