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
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 {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';17import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';
18import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';18import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
19import reFungibleTokenAbi from './reFungibleTokenAbi.json';
2019
21import chai from 'chai';20import chai from 'chai';
22import chaiAsPromised from 'chai-as-promised';21import chaiAsPromised from 'chai-as-promised';
34 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;33 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
3534
36 const address = tokenIdToAddress(collectionId, tokenId);35 const address = tokenIdToAddress(collectionId, tokenId);
37 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});36 const contract = uniqueRefungibleToken(web3, address, caller);
38 const totalSupply = await contract.methods.totalSupply().call();37 const totalSupply = await contract.methods.totalSupply().call();
3938
40 expect(totalSupply).to.equal('200');39 expect(totalSupply).to.equal('200');
50 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;49 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
5150
52 const address = tokenIdToAddress(collectionId, tokenId);51 const address = tokenIdToAddress(collectionId, tokenId);
53 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});52 const contract = uniqueRefungibleToken(web3, address, caller);
54 const balance = await contract.methods.balanceOf(caller).call();53 const balance = await contract.methods.balanceOf(caller).call();
5554
56 expect(balance).to.equal('200');55 expect(balance).to.equal('200');
66 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;65 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
6766
68 const address = tokenIdToAddress(collectionId, tokenId);67 const address = tokenIdToAddress(collectionId, tokenId);
69 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});68 const contract = uniqueRefungibleToken(web3, address, caller);
70 const decimals = await contract.methods.decimals().call();69 const decimals = await contract.methods.decimals().call();
7170
72 expect(decimals).to.equal('0');71 expect(decimals).to.equal('0');
229228
230 const spender = createEthAccount(web3);229 const spender = createEthAccount(web3);
231230
232 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});231 const contract = uniqueRefungibleToken(web3, address, owner);
233232
234 {233 {
235 const result = await contract.methods.approve(spender, 100).send({from: owner});234 const result = await contract.methods.approve(spender, 100).send({from: owner});
270 const receiver = createEthAccount(web3);269 const receiver = createEthAccount(web3);
271270
272 const address = tokenIdToAddress(collectionId, tokenId);271 const address = tokenIdToAddress(collectionId, tokenId);
273 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});272 const contract = uniqueRefungibleToken(web3, address, owner);
274273
275 await contract.methods.approve(spender, 100).send();274 await contract.methods.approve(spender, 100).send();
276275
324 await transferBalanceToEth(api, alice, receiver);323 await transferBalanceToEth(api, alice, receiver);
325324
326 const address = tokenIdToAddress(collectionId, tokenId);325 const address = tokenIdToAddress(collectionId, tokenId);
327 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});326 const contract = uniqueRefungibleToken(web3, address, owner);
328327
329 {328 {
330 const result = await contract.methods.transfer(receiver, 50).send({from: owner});329 const result = await contract.methods.transfer(receiver, 50).send({from: owner});
367 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;366 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
368367
369 const address = tokenIdToAddress(collectionId, tokenId);368 const address = tokenIdToAddress(collectionId, tokenId);
370 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});369 const contract = uniqueRefungibleToken(web3, address, owner);
371370
372 await contract.methods.repartition(200).send({from: owner});371 await contract.methods.repartition(200).send({from: owner});
373 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);372 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);
397 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;396 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
398397
399 const address = tokenIdToAddress(collectionId, tokenId);398 const address = tokenIdToAddress(collectionId, tokenId);
400 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});399 const contract = uniqueRefungibleToken(web3, address, owner);
401400
402 const result = await contract.methods.repartition(200).send();401 const result = await contract.methods.repartition(200).send();
403 const events = normalizeEvents(result.events);402 const events = normalizeEvents(result.events);
426 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;425 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
427426
428 const address = tokenIdToAddress(collectionId, tokenId);427 const address = tokenIdToAddress(collectionId, tokenId);
429 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});428 const contract = uniqueRefungibleToken(web3, address, owner);
430429
431 const result = await contract.methods.repartition(50).send();430 const result = await contract.methods.repartition(50).send();
432 const events = normalizeEvents(result.events);431 const events = normalizeEvents(result.events);
456455
457 const address = tokenIdToAddress(collectionId, tokenId);456 const address = tokenIdToAddress(collectionId, tokenId);
458457
459 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});458 const tokenContract = uniqueRefungibleToken(web3, address, caller);
460 await tokenContract.methods.repartition(2).send();459 await tokenContract.methods.repartition(2).send();
461 await tokenContract.methods.transfer(receiver, 1).send();460 await tokenContract.methods.transfer(receiver, 1).send();
462461
488 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;487 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
489488
490 const address = tokenIdToAddress(collectionId, tokenId);489 const address = tokenIdToAddress(collectionId, tokenId);
491 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});490 const contract = uniqueRefungibleToken(web3, address, owner);
492491
493 const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));492 const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));
494 expect(cost < BigInt(0.2 * Number(UNIQUE)));493 expect(cost < BigInt(0.2 * Number(UNIQUE)));
505 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;504 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
506505
507 const address = tokenIdToAddress(collectionId, tokenId);506 const address = tokenIdToAddress(collectionId, tokenId);
508 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});507 const contract = uniqueRefungibleToken(web3, address, owner);
509508
510 await contract.methods.approve(spender, 100).send({from: owner});509 await contract.methods.approve(spender, 100).send({from: owner});
511510
524 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;523 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
525524
526 const address = tokenIdToAddress(collectionId, tokenId);525 const address = tokenIdToAddress(collectionId, tokenId);
527 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});526 const contract = uniqueRefungibleToken(web3, address, owner);
528527
529 const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));528 const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));
530 expect(cost < BigInt(0.2 * Number(UNIQUE)));529 expect(cost < BigInt(0.2 * Number(UNIQUE)));
542 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;541 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
543542
544 const address = tokenIdToAddress(collectionId, tokenId);543 const address = tokenIdToAddress(collectionId, tokenId);
545 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);544 const contract = uniqueRefungibleToken(web3, address);
546545
547 const events = await recordEvents(contract, async () => {546 const events = await recordEvents(contract, async () => {
548 expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;547 expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;
573 expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;572 expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;
574573
575 const address = tokenIdToAddress(collectionId, tokenId);574 const address = tokenIdToAddress(collectionId, tokenId);
576 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);575 const contract = uniqueRefungibleToken(web3, address);
577576
578 const events = await recordEvents(contract, async () => {577 const events = await recordEvents(contract, async () => {
579 expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver}, 51n)).to.be.true;578 expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver}, 51n)).to.be.true;
611 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;610 const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
612611
613 const address = tokenIdToAddress(collectionId, tokenId);612 const address = tokenIdToAddress(collectionId, tokenId);
614 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);613 const contract = uniqueRefungibleToken(web3, address);
615614
616 const events = await recordEvents(contract, async () => {615 const events = await recordEvents(contract, async () => {
617 expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver}, 51n)).to.be.true;616 expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver}, 51n)).to.be.true;
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
172 });172 });
173}173}
174174
175export function uniqueRefungibleToken(web3: Web3, tokenAddress: string, owner: string) {175export function uniqueRefungibleToken(web3: Web3, tokenAddress: string, owner: string | undefined = undefined) {
176 return new web3.eth.Contract(refungibleTokenAbi as any, tokenAddress, {176 return new web3.eth.Contract(refungibleTokenAbi as any, tokenAddress, {
177 from: owner,177 from: owner,
178 ...GAS_ARGS,178 ...GAS_ARGS,