difftreelog
CORE-302 Move test to separate file
in: master
2 files changed
tests/src/eth/base.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 {18 collectionIdFromAddress, 19 collectionIdToAddress, 20 contractHelpers, 21 createEthAccount, 22 createEthAccountWithBalance, 23 deployFlipper, 24 ethBalanceViaSub, 25 GAS_ARGS, 26 itWeb3, 27 recordEthFee, 28 usingWeb3,29} from './util/helpers';30import {expect} from 'chai';31import {createCollectionExpectSuccess, createItemExpectSuccess, getCreatedCollectionCount, getDetailedCollectionInfo, UNIQUE} from '../util/helpers';32import nonFungibleAbi from './nonFungibleAbi.json';33import privateKey from '../substrate/privateKey';34import {Contract} from 'web3-eth-contract';35import Web3 from 'web3';3637describe('Contract calls', () => {38 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {39 const deployer = await createEthAccountWithBalance(api, web3);40 const flipper = await deployFlipper(web3, deployer);4142 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));43 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;44 });4546 itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {47 const userA = await createEthAccountWithBalance(api, web3);48 const userB = createEthAccount(web3);4950 const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));51 const balanceB = await ethBalanceViaSub(api, userB);52 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;53 });5455 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {56 const caller = await createEthAccountWithBalance(api, web3);57 const receiver = createEthAccount(web3);5859 const alice = privateKey('//Alice');60 const collection = await createCollectionExpectSuccess({61 mode: {type: 'NFT'},62 });63 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});6465 const address = collectionIdToAddress(collection);66 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});6768 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));6970 const fee = Number(cost) / Number(UNIQUE);71 const expectedFee = 0.15;72 const tolerance = 0.00002;7374 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);75 });76});7778describe('ERC165 tests', async () => {79 // https://eips.ethereum.org/EIPS/eip-1658081 let collection: number;82 let minter: string;8384 function contract(web3: Web3): Contract {85 return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});86 }8788 before(async () => {89 await usingWeb3 (async (web3) => {90 collection = await createCollectionExpectSuccess();91 minter = createEthAccount(web3);92 });93 });9495 itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {96 expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;97 });9899 itWeb3('ERC721 support', async ({web3}) => {100 expect(await contract(web3).methods.supportsInterface('0x58800161').call()).to.be.true;101 });102103 itWeb3('ERC721Metadata support', async ({web3}) => {104 expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;105 });106107 itWeb3('ERC721Mintable support', async ({web3}) => {108 expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;109 });110111 itWeb3('ERC721Enumerable support', async ({web3}) => {112 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;113 });114115 itWeb3('ERC721UniqueExtensions support', async ({web3}) => {116 expect(await contract(web3).methods.supportsInterface('0xd74d154f').call()).to.be.true;117 });118119 itWeb3('ERC721Burnable support', async ({web3}) => {120 expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;121 });122123 itWeb3('ERC165 support', async ({web3}) => {124 expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;125 });126});127128describe('Create collection from EVM', () => {129 itWeb3('Create collection', async ({api, web3}) => {130 const owner = await createEthAccountWithBalance(api, web3);131 const helpers = contractHelpers(web3, owner);132 const collectionName = 'CollectionEVM';133 const description = 'Some description';134 const tokenPrefix = 'token prefix';135136 const collectionCountBefore = await getCreatedCollectionCount(api);137 const result = await helpers.methods138 .create721Collection(collectionName, description, tokenPrefix)139 .send();140 const collectionCountAfter = await getCreatedCollectionCount(api);141142 const collectionId = collectionIdFromAddress(result.events[0].raw.topics[2]);143 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);144 expect(collectionId).to.be.eq(collectionCountAfter);145 146 const collection = (await getDetailedCollectionInfo(api, collectionId))!;147 expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);148 expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);149 expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);150 });151});1// 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 {18 collectionIdToAddress, 19 createEthAccount, 20 createEthAccountWithBalance, 21 deployFlipper, 22 ethBalanceViaSub, 23 GAS_ARGS, 24 itWeb3, 25 recordEthFee, 26 usingWeb3,27} from './util/helpers';28import {expect} from 'chai';29import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';30import nonFungibleAbi from './nonFungibleAbi.json';31import privateKey from '../substrate/privateKey';32import {Contract} from 'web3-eth-contract';33import Web3 from 'web3';3435describe('Contract calls', () => {36 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {37 const deployer = await createEthAccountWithBalance(api, web3);38 const flipper = await deployFlipper(web3, deployer);3940 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));41 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;42 });4344 itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {45 const userA = await createEthAccountWithBalance(api, web3);46 const userB = createEthAccount(web3);4748 const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));49 const balanceB = await ethBalanceViaSub(api, userB);50 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;51 });5253 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {54 const caller = await createEthAccountWithBalance(api, web3);55 const receiver = createEthAccount(web3);5657 const alice = privateKey('//Alice');58 const collection = await createCollectionExpectSuccess({59 mode: {type: 'NFT'},60 });61 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});6263 const address = collectionIdToAddress(collection);64 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});6566 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));6768 const fee = Number(cost) / Number(UNIQUE);69 const expectedFee = 0.15;70 const tolerance = 0.00002;7172 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);73 });74});7576describe('ERC165 tests', async () => {77 // https://eips.ethereum.org/EIPS/eip-1657879 let collection: number;80 let minter: string;8182 function contract(web3: Web3): Contract {83 return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});84 }8586 before(async () => {87 await usingWeb3 (async (web3) => {88 collection = await createCollectionExpectSuccess();89 minter = createEthAccount(web3);90 });91 });9293 itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {94 expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;95 });9697 itWeb3('ERC721 support', async ({web3}) => {98 expect(await contract(web3).methods.supportsInterface('0x58800161').call()).to.be.true;99 });100101 itWeb3('ERC721Metadata support', async ({web3}) => {102 expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;103 });104105 itWeb3('ERC721Mintable support', async ({web3}) => {106 expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;107 });108109 itWeb3('ERC721Enumerable support', async ({web3}) => {110 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;111 });112113 itWeb3('ERC721UniqueExtensions support', async ({web3}) => {114 expect(await contract(web3).methods.supportsInterface('0xd74d154f').call()).to.be.true;115 });116117 itWeb3('ERC721Burnable support', async ({web3}) => {118 expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;119 });120121 itWeb3('ERC165 support', async ({web3}) => {122 expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;123 });124});tests/src/eth/createCollection.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/createCollection.test.ts
@@ -0,0 +1,45 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {expect} from 'chai';
+import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';
+import {collectionIdFromAddress, contractHelpers, createEthAccountWithBalance, itWeb3} from './util/helpers';
+
+describe('Create collection from EVM', () => {
+ itWeb3('Create collection', async ({api, web3}) => {
+ const owner = await createEthAccountWithBalance(api, web3);
+ const helpers = contractHelpers(web3, owner);
+ const collectionName = 'CollectionEVM';
+ const description = 'Some description';
+ const tokenPrefix = 'token prefix';
+
+ const collectionCountBefore = await getCreatedCollectionCount(api);
+ const result = await helpers.methods
+ .create721Collection(collectionName, description, tokenPrefix)
+ .send();
+ const collectionCountAfter = await getCreatedCollectionCount(api);
+
+ const collectionId = collectionIdFromAddress(result.events[0].raw.topics[2]);
+ expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
+ expect(collectionId).to.be.eq(collectionCountAfter);
+
+ const collection = (await getDetailedCollectionInfo(api, collectionId))!;
+ expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);
+ expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);
+ expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);
+ expect(collection.schemaVersion.type).to.be.eq('ImageURL');
+ });
+});
\ No newline at end of file