git.delta.rocks / unique-network / refs/commits / 15c21abe7df6

difftreelog

chore refactor RFT token tests

Grigoriy Simonov2022-08-11parent: #e256f7e.patch.diff
in: master

3 files changed

modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {createCollectionExpectSuccess, UNIQUE} from '../util/helpers';17import {createCollectionExpectSuccess, UNIQUE} from '../util/helpers';
18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress} from './util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress, uniqueRefungibleToken} from './util/helpers';
19import reFungibleTokenAbi from './reFungibleTokenAbi.json';
20import {expect} from 'chai';19import {expect} from 'chai';
2120
22describe('Refungible: Information getting', () => {21describe('Refungible: Information getting', () => {
84 await contract.methods.mint(caller, tokenId).send();83 await contract.methods.mint(caller, tokenId).send();
8584
86 const tokenAddress = tokenIdToAddress(collectionId, tokenId);85 const tokenAddress = tokenIdToAddress(collectionId, tokenId);
87 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});86 const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
8887
89 await tokenContract.methods.repartition(2).send();88 await tokenContract.methods.repartition(2).send();
90 await tokenContract.methods.transfer(receiver, 1).send();89 await tokenContract.methods.transfer(receiver, 1).send();
108 await contract.methods.mint(caller, tokenId).send();107 await contract.methods.mint(caller, tokenId).send();
109108
110 const tokenAddress = tokenIdToAddress(collectionId, tokenId);109 const tokenAddress = tokenIdToAddress(collectionId, tokenId);
111 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});110 const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
112111
113 await tokenContract.methods.repartition(2).send();112 await tokenContract.methods.repartition(2).send();
114 await tokenContract.methods.transfer(receiver, 1).send();113 await tokenContract.methods.transfer(receiver, 1).send();
250 await contract.methods.mint(caller, tokenId).send();249 await contract.methods.mint(caller, tokenId).send();
251250
252 const address = tokenIdToAddress(collectionId, tokenId);251 const address = tokenIdToAddress(collectionId, tokenId);
253 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});252 const tokenContract = uniqueRefungibleToken(web3, address, caller);
254 await tokenContract.methods.repartition(15).send();253 await tokenContract.methods.repartition(15).send();
255254
256 {255 {
345 await contract.methods.mint(caller, tokenId).send();344 await contract.methods.mint(caller, tokenId).send();
346345
347 const tokenAddress = tokenIdToAddress(collectionId, tokenId);346 const tokenAddress = tokenIdToAddress(collectionId, tokenId);
348 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});347 const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
349348
350 await tokenContract.methods.repartition(2).send();349 await tokenContract.methods.repartition(2).send();
351 await tokenContract.methods.transfer(receiver, 1).send();350 await tokenContract.methods.transfer(receiver, 1).send();
377 await contract.methods.mint(caller, tokenId).send();376 await contract.methods.mint(caller, tokenId).send();
378377
379 const tokenAddress = tokenIdToAddress(collectionId, tokenId);378 const tokenAddress = tokenIdToAddress(collectionId, tokenId);
380 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});379 const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
381380
382 await tokenContract.methods.repartition(2).send();381 await tokenContract.methods.repartition(2).send();
383 382
modifiedtests/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;
modifiedtests/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,