difftreelog
chore refactor RFT token tests
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, UNIQUE} from '../util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress, uniqueRefungibleToken} from './util/helpers';19import {expect} from 'chai';2021describe('Refungible: Information getting', () => {22 itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {23 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);24 const helper = evmCollectionHelpers(web3, caller);25 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();26 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);27 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});28 const nextTokenId = await contract.methods.nextTokenId().call();29 await contract.methods.mint(caller, nextTokenId).send();30 const totalSupply = await contract.methods.totalSupply().call();31 expect(totalSupply).to.equal('1');32 });3334 itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {35 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);36 const helper = evmCollectionHelpers(web3, caller);37 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();38 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);39 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});4041 {42 const nextTokenId = await contract.methods.nextTokenId().call();43 await contract.methods.mint(caller, nextTokenId).send();44 }45 {46 const nextTokenId = await contract.methods.nextTokenId().call();47 await contract.methods.mint(caller, nextTokenId).send();48 }49 {50 const nextTokenId = await contract.methods.nextTokenId().call();51 await contract.methods.mint(caller, nextTokenId).send();52 }5354 const balance = await contract.methods.balanceOf(caller).call();5556 expect(balance).to.equal('3');57 });5859 itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {60 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);61 const helper = evmCollectionHelpers(web3, caller);62 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();63 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);64 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});6566 const tokenId = await contract.methods.nextTokenId().call();67 await contract.methods.mint(caller, tokenId).send();6869 const owner = await contract.methods.ownerOf(tokenId).call();7071 expect(owner).to.equal(caller);72 });7374 itWeb3('ownerOf after burn', async ({api, web3, privateKeyWrapper}) => {75 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);76 const receiver = createEthAccount(web3);77 const helper = evmCollectionHelpers(web3, caller);78 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();79 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);80 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});8182 const tokenId = await contract.methods.nextTokenId().call();83 await contract.methods.mint(caller, tokenId).send();8485 const tokenAddress = tokenIdToAddress(collectionId, tokenId);86 const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);8788 await tokenContract.methods.repartition(2).send();89 await tokenContract.methods.transfer(receiver, 1).send();9091 await tokenContract.methods.burnFrom(caller, 1).send();9293 const owner = await contract.methods.ownerOf(tokenId).call();9495 expect(owner).to.equal(receiver);96 });9798 itWeb3('ownerOf for partial ownership', async ({api, web3, privateKeyWrapper}) => {99 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);100 const receiver = createEthAccount(web3);101 const helper = evmCollectionHelpers(web3, caller);102 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();103 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);104 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});105106 const tokenId = await contract.methods.nextTokenId().call();107 await contract.methods.mint(caller, tokenId).send();108109 const tokenAddress = tokenIdToAddress(collectionId, tokenId);110 const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);111112 await tokenContract.methods.repartition(2).send();113 await tokenContract.methods.transfer(receiver, 1).send();114115 const owner = await contract.methods.ownerOf(tokenId).call();116117 expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');118 });119});120121describe('Refungible: Plain calls', () => {122 itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {123 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);124 const helper = evmCollectionHelpers(web3, owner);125 let result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();126 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);127 const receiver = createEthAccount(web3);128 const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});129 const nextTokenId = await contract.methods.nextTokenId().call();130131 expect(nextTokenId).to.be.equal('1');132 result = await contract.methods.mintWithTokenURI(133 receiver,134 nextTokenId,135 'Test URI',136 ).send();137138 const events = normalizeEvents(result.events);139140 expect(events).to.include.deep.members([141 {142 address: collectionIdAddress,143 event: 'Transfer',144 args: {145 from: '0x0000000000000000000000000000000000000000',146 to: receiver,147 tokenId: nextTokenId,148 },149 },150 ]);151152 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');153 });154155 itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {156 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);157 const helper = evmCollectionHelpers(web3, caller);158 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();159 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);160 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});161162 const receiver = createEthAccount(web3);163164 {165 const nextTokenId = await contract.methods.nextTokenId().call();166 expect(nextTokenId).to.be.equal('1');167 const result = await contract.methods.mintBulkWithTokenURI(168 receiver,169 [170 [nextTokenId, 'Test URI 0'],171 [+nextTokenId + 1, 'Test URI 1'],172 [+nextTokenId + 2, 'Test URI 2'],173 ],174 ).send();175 const events = normalizeEvents(result.events);176177 expect(events).to.include.deep.members([178 {179 address: collectionIdAddress,180 event: 'Transfer',181 args: {182 from: '0x0000000000000000000000000000000000000000',183 to: receiver,184 tokenId: nextTokenId,185 },186 },187 {188 address: collectionIdAddress,189 event: 'Transfer',190 args: {191 from: '0x0000000000000000000000000000000000000000',192 to: receiver,193 tokenId: String(+nextTokenId + 1),194 },195 },196 {197 address: collectionIdAddress,198 event: 'Transfer',199 args: {200 from: '0x0000000000000000000000000000000000000000',201 to: receiver,202 tokenId: String(+nextTokenId + 2),203 },204 },205 ]);206207 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');208 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');209 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');210 }211 });212213 itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {214 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);215 const helper = evmCollectionHelpers(web3, caller);216 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();217 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);218 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});219220 const tokenId = await contract.methods.nextTokenId().call();221 await contract.methods.mint(caller, tokenId).send();222 {223 const result = await contract.methods.burn(tokenId).send();224 const events = normalizeEvents(result.events);225 expect(events).to.include.deep.members([226 {227 address: collectionIdAddress,228 event: 'Transfer',229 args: {230 from: caller,231 to: '0x0000000000000000000000000000000000000000',232 tokenId: tokenId.toString(),233 },234 },235 ]);236 }237 });238239 itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {240 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);241 const helper = evmCollectionHelpers(web3, caller);242 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();243 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);244 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});245246 const receiver = createEthAccount(web3);247248 const tokenId = await contract.methods.nextTokenId().call();249 await contract.methods.mint(caller, tokenId).send();250251 const address = tokenIdToAddress(collectionId, tokenId);252 const tokenContract = uniqueRefungibleToken(web3, address, caller);253 await tokenContract.methods.repartition(15).send();254255 {256 const erc20Events = await recordEvents(tokenContract, async () => {257 const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();258 const events = normalizeEvents(result.events);259 expect(events).to.include.deep.members([260 {261 address: collectionIdAddress,262 event: 'Transfer',263 args: {264 from: caller,265 to: receiver,266 tokenId: tokenId.toString(),267 },268 },269 ]);270 });271 272 expect(erc20Events).to.include.deep.members([273 {274 address,275 event: 'Transfer',276 args: {277 from: caller,278 to: receiver,279 value: '15',280 },281 },282 ]);283 }284285 {286 const balance = await contract.methods.balanceOf(receiver).call();287 expect(+balance).to.equal(1);288 }289290 {291 const balance = await contract.methods.balanceOf(caller).call();292 expect(+balance).to.equal(0);293 }294 });295296 itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {297 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);298 const helper = evmCollectionHelpers(web3, caller);299 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();300 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);301 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});302303 const receiver = createEthAccount(web3);304305 const tokenId = await contract.methods.nextTokenId().call();306 await contract.methods.mint(caller, tokenId).send();307308 {309 const result = await contract.methods.transfer(receiver, tokenId).send();310 const events = normalizeEvents(result.events);311 expect(events).to.include.deep.members([312 {313 address: collectionIdAddress,314 event: 'Transfer',315 args: {316 from: caller,317 to: receiver,318 tokenId: tokenId.toString(),319 },320 },321 ]);322 }323324 {325 const balance = await contract.methods.balanceOf(caller).call();326 expect(+balance).to.equal(0);327 }328329 {330 const balance = await contract.methods.balanceOf(receiver).call();331 expect(+balance).to.equal(1);332 }333 });334335 itWeb3('transfer event on transfer from partial ownership to full ownership', async ({api, web3, privateKeyWrapper}) => {336 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);337 const receiver = createEthAccount(web3);338 const helper = evmCollectionHelpers(web3, caller);339 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();340 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);341 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});342343 const tokenId = await contract.methods.nextTokenId().call();344 await contract.methods.mint(caller, tokenId).send();345346 const tokenAddress = tokenIdToAddress(collectionId, tokenId);347 const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);348349 await tokenContract.methods.repartition(2).send();350 await tokenContract.methods.transfer(receiver, 1).send();351352 const events = await recordEvents(contract, async () => 353 await tokenContract.methods.transfer(receiver, 1).send());354 expect(events).to.deep.equal([355 {356 address: collectionIdAddress,357 event: 'Transfer',358 args: {359 from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',360 to: receiver,361 tokenId: tokenId.toString(),362 },363 },364 ]);365 });366367 itWeb3('transfer event on transfer from full ownership to partial ownership', async ({api, web3, privateKeyWrapper}) => {368 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);369 const receiver = createEthAccount(web3);370 const helper = evmCollectionHelpers(web3, caller);371 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();372 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);373 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});374375 const tokenId = await contract.methods.nextTokenId().call();376 await contract.methods.mint(caller, tokenId).send();377378 const tokenAddress = tokenIdToAddress(collectionId, tokenId);379 const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);380381 await tokenContract.methods.repartition(2).send();382 383 const events = await recordEvents(contract, async () => 384 await tokenContract.methods.transfer(receiver, 1).send());385 386 expect(events).to.deep.equal([387 {388 address: collectionIdAddress,389 event: 'Transfer',390 args: {391 from: caller,392 to: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',393 tokenId: tokenId.toString(),394 },395 },396 ]);397 });398});399400describe('RFT: Fees', () => {401 itWeb3('transferFrom() 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.transferFrom(caller, receiver, tokenId).send());414 expect(cost < BigInt(0.2 * Number(UNIQUE)));415 expect(cost > 0n);416 });417418 itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {419 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);420 const helper = evmCollectionHelpers(web3, caller);421 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();422 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);423 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});424425 const receiver = createEthAccount(web3);426427 const tokenId = await contract.methods.nextTokenId().call();428 await contract.methods.mint(caller, tokenId).send();429430 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send());431 expect(cost < BigInt(0.2 * Number(UNIQUE)));432 expect(cost > 0n);433 });434});435436describe('Common metadata', () => {437 itWeb3('Returns collection name', async ({api, web3, privateKeyWrapper}) => {438 const collection = await createCollectionExpectSuccess({439 name: 'token name',440 mode: {type: 'ReFungible'},441 });442 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);443444 const address = collectionIdToAddress(collection);445 const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});446 const name = await contract.methods.name().call();447448 expect(name).to.equal('token name');449 });450451 itWeb3('Returns symbol name', async ({api, web3, privateKeyWrapper}) => {452 const collection = await createCollectionExpectSuccess({453 tokenPrefix: 'TOK',454 mode: {type: 'ReFungible'},455 });456 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);457458 const address = collectionIdToAddress(collection);459 const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});460 const symbol = await contract.methods.symbol().call();461462 expect(symbol).to.equal('TOK');463 });464});tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -15,8 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';
-import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
-import reFungibleTokenAbi from './reFungibleTokenAbi.json';
+import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
@@ -34,7 +33,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, caller);
const totalSupply = await contract.methods.totalSupply().call();
expect(totalSupply).to.equal('200');
@@ -50,7 +49,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, caller);
const balance = await contract.methods.balanceOf(caller).call();
expect(balance).to.equal('200');
@@ -66,7 +65,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, caller);
const decimals = await contract.methods.decimals().call();
expect(decimals).to.equal('0');
@@ -229,7 +228,7 @@
const spender = createEthAccount(web3);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
{
const result = await contract.methods.approve(spender, 100).send({from: owner});
@@ -270,7 +269,7 @@
const receiver = createEthAccount(web3);
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
await contract.methods.approve(spender, 100).send();
@@ -324,7 +323,7 @@
await transferBalanceToEth(api, alice, receiver);
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
{
const result = await contract.methods.transfer(receiver, 50).send({from: owner});
@@ -367,7 +366,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
await contract.methods.repartition(200).send({from: owner});
expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);
@@ -397,7 +396,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
const result = await contract.methods.repartition(200).send();
const events = normalizeEvents(result.events);
@@ -426,7 +425,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
const result = await contract.methods.repartition(50).send();
const events = normalizeEvents(result.events);
@@ -456,7 +455,7 @@
const address = tokenIdToAddress(collectionId, tokenId);
- const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});
+ const tokenContract = uniqueRefungibleToken(web3, address, caller);
await tokenContract.methods.repartition(2).send();
await tokenContract.methods.transfer(receiver, 1).send();
@@ -488,7 +487,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));
expect(cost < BigInt(0.2 * Number(UNIQUE)));
@@ -505,7 +504,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
await contract.methods.approve(spender, 100).send({from: owner});
@@ -524,7 +523,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+ const contract = uniqueRefungibleToken(web3, address, owner);
const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));
expect(cost < BigInt(0.2 * Number(UNIQUE)));
@@ -542,7 +541,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);
+ const contract = uniqueRefungibleToken(web3, address);
const events = await recordEvents(contract, async () => {
expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;
@@ -573,7 +572,7 @@
expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);
+ const contract = uniqueRefungibleToken(web3, address);
const events = await recordEvents(contract, async () => {
expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver}, 51n)).to.be.true;
@@ -611,7 +610,7 @@
const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
const address = tokenIdToAddress(collectionId, tokenId);
- const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);
+ const contract = uniqueRefungibleToken(web3, address);
const events = await recordEvents(contract, async () => {
expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver}, 51n)).to.be.true;
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -172,7 +172,7 @@
});
}
-export function uniqueRefungibleToken(web3: Web3, tokenAddress: string, owner: string) {
+export function uniqueRefungibleToken(web3: Web3, tokenAddress: string, owner: string | undefined = undefined) {
return new web3.eth.Contract(refungibleTokenAbi as any, tokenAddress, {
from: owner,
...GAS_ARGS,