difftreelog
eth/base migrated
in: master
1 file 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 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 {Contract} from 'web3-eth-contract';32import Web3 from 'web3';3334describe('Contract calls', () => {35 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api, privateKeyWrapper}) => {36 const deployer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);37 const flipper = await deployFlipper(web3, deployer);3839 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));40 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;41 });4243 itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api, privateKeyWrapper}) => {44 const userA = await createEthAccountWithBalance(api, web3, privateKeyWrapper);45 const userB = createEthAccount(web3);4647 const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));48 const balanceB = await ethBalanceViaSub(api, userB);49 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;50 });5152 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api, privateKeyWrapper}) => {53 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);54 const receiver = createEthAccount(web3);5556 const alice = privateKeyWrapper('//Alice');57 const collection = await createCollectionExpectSuccess({58 mode: {type: 'NFT'},59 });60 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});6162 const address = collectionIdToAddress(collection);63 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});6465 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));6667 const fee = Number(cost) / Number(UNIQUE);68 const expectedFee = 0.15;69 const tolerance = 0.001;7071 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);72 });73});7475describe('ERC165 tests', async () => {76 // https://eips.ethereum.org/EIPS/eip-1657778 let collection: number;79 let minter: string;8081 function contract(web3: Web3): Contract {82 return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});83 }8485 before(async () => {86 await usingWeb3 (async (web3) => {87 collection = await createCollectionExpectSuccess();88 minter = createEthAccount(web3);89 });90 });9192 itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {93 expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;94 });9596 itWeb3('ERC721 support', async ({web3}) => {97 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;98 });99100 itWeb3('ERC721Metadata support', async ({web3}) => {101 expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;102 });103104 itWeb3('ERC721Mintable support', async ({web3}) => {105 expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;106 });107108 itWeb3('ERC721Enumerable support', async ({web3}) => {109 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;110 });111112 itWeb3('ERC721UniqueExtensions support', async ({web3}) => {113 expect(await contract(web3).methods.supportsInterface('0xd74d154f').call()).to.be.true;114 });115116 itWeb3('ERC721Burnable support', async ({web3}) => {117 expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;118 });119120 itWeb3('ERC165 support', async ({web3}) => {121 expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;122 });123});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 ethBalanceViaSub,19 GAS_ARGS,20 recordEthFee,21} from './util/helpers';22import {Contract} from 'web3-eth-contract';2324import {IKeyringPair} from '@polkadot/types/types';25import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';26import {UNIQUE} from '../util/helpers';2728describe('Contract calls', () => {29 let donor: IKeyringPair;3031 before(async function() {32 await usingEthPlaygrounds(async (_helper, privateKey) => {33 donor = privateKey('//Alice');34 });35 });3637 itEth('Call of simple contract fee is less than 0.2 UNQ', async ({helper}) => {38 const deployer = await helper.eth.createAccountWithBalance(donor);39 const flipper = await helper.eth.deployFlipper(deployer);4041 const cost = await recordEthFee(helper.api!, deployer, () => flipper.methods.flip().send({from: deployer}));42 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;43 });4445 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {46 const userA = await helper.eth.createAccountWithBalance(donor);47 const userB = helper.eth.createAccount();48 const cost = await recordEthFee(helper.api!, userA, () => helper.web3!.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));49 const balanceB = await ethBalanceViaSub(helper.api!, userB);50 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;51 });5253 itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {54 const caller = await helper.eth.createAccountWithBalance(donor);55 const receiver = helper.eth.createAccount();5657 const [alice] = await helper.arrange.createAccounts([10n], donor);58 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});59 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});6061 const address = helper.ethAddress.fromCollectionId(collection.collectionId);62 const contract = helper.ethNativeContract.collection(address, 'nft', caller);6364 const cost = await recordEthFee(helper.api!, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));6566 const fee = Number(cost) / Number(UNIQUE);67 const expectedFee = 0.15;68 const tolerance = 0.001;6970 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);71 });72});7374describe('ERC165 tests', async () => {75 // https://eips.ethereum.org/EIPS/eip-1657677 let collection: number;78 let minter: string;7980 function contract(helper: EthUniqueHelper): Contract {81 return helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection), 'nft', minter);82 }8384 before(async () => {85 await usingEthPlaygrounds(async (helper, privateKey) => {86 const donor = privateKey('//Alice');87 const [alice] = await helper.arrange.createAccounts([10n], donor);88 ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}));89 minter = helper.eth.createAccount();90 });91 });9293 itEth('interfaceID == 0xffffffff always false', async ({helper}) => {94 expect(await contract(helper).methods.supportsInterface('0xffffffff').call()).to.be.false;95 });9697 itEth('ERC721 support', async ({helper}) => {98 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;99 });100101 itEth('ERC721Metadata support', async ({helper}) => {102 expect(await contract(helper).methods.supportsInterface('0x5b5e139f').call()).to.be.true;103 });104105 itEth('ERC721Mintable support', async ({helper}) => {106 expect(await contract(helper).methods.supportsInterface('0x68ccfe89').call()).to.be.true;107 });108109 itEth('ERC721Enumerable support', async ({helper}) => {110 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;111 });112113 itEth('ERC721UniqueExtensions support', async ({helper}) => {114 expect(await contract(helper).methods.supportsInterface('0xd74d154f').call()).to.be.true;115 });116117 itEth('ERC721Burnable support', async ({helper}) => {118 expect(await contract(helper).methods.supportsInterface('0x42966c68').call()).to.be.true;119 });120121 itEth('ERC165 support', async ({helper}) => {122 expect(await contract(helper).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;123 });124});