From 15c21abe7df6027bfa1f7c82b4bfb1e6ecfb1771 Mon Sep 17 00:00:00 2001 From: Grigoriy Simonov Date: Thu, 11 Aug 2022 09:44:00 +0000 Subject: [PATCH] chore: refactor RFT token tests --- --- a/tests/src/eth/reFungible.test.ts +++ b/tests/src/eth/reFungible.test.ts @@ -15,8 +15,7 @@ // along with Unique Network. If not, see . import {createCollectionExpectSuccess, UNIQUE} from '../util/helpers'; -import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress} from './util/helpers'; -import reFungibleTokenAbi from './reFungibleTokenAbi.json'; +import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress, uniqueRefungibleToken} from './util/helpers'; import {expect} from 'chai'; describe('Refungible: Information getting', () => { @@ -84,7 +83,7 @@ await contract.methods.mint(caller, tokenId).send(); const tokenAddress = tokenIdToAddress(collectionId, tokenId); - const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS}); + const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller); await tokenContract.methods.repartition(2).send(); await tokenContract.methods.transfer(receiver, 1).send(); @@ -108,7 +107,7 @@ await contract.methods.mint(caller, tokenId).send(); const tokenAddress = tokenIdToAddress(collectionId, tokenId); - const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS}); + const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller); await tokenContract.methods.repartition(2).send(); await tokenContract.methods.transfer(receiver, 1).send(); @@ -250,7 +249,7 @@ await contract.methods.mint(caller, tokenId).send(); 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(15).send(); { @@ -345,7 +344,7 @@ await contract.methods.mint(caller, tokenId).send(); const tokenAddress = tokenIdToAddress(collectionId, tokenId); - const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS}); + const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller); await tokenContract.methods.repartition(2).send(); await tokenContract.methods.transfer(receiver, 1).send(); @@ -377,7 +376,7 @@ await contract.methods.mint(caller, tokenId).send(); const tokenAddress = tokenIdToAddress(collectionId, tokenId); - const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS}); + const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller); await tokenContract.methods.repartition(2).send(); --- 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 . 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; --- 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, -- gitstuff