git.delta.rocks / unique-network / refs/commits / c01b00c42ad2

difftreelog

source

tests/src/eth/base.test.ts4.6 KiBsourcehistory
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 {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee, usingWeb3} from './util/helpers';18import {expect} from 'chai';19import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';20import nonFungibleAbi from './nonFungibleAbi.json';21import privateKey from '../substrate/privateKey';22import {Contract} from 'web3-eth-contract';23import Web3 from 'web3';2425describe('Contract calls', () => {26  itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {27    const deployer = await createEthAccountWithBalance(api, web3);28    const flipper = await deployFlipper(web3, deployer);2930    const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));31    expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;32  });3334  itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {35    const userA = await createEthAccountWithBalance(api, web3);36    const userB = createEthAccount(web3);3738    const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));39    const balanceB = await ethBalanceViaSub(api, userB);40    expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;41  });4243  itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {44    const caller = await createEthAccountWithBalance(api, web3);45    const receiver = createEthAccount(web3);4647    const alice = privateKey('//Alice');48    const collection = await createCollectionExpectSuccess({49      mode: {type: 'NFT'},50    });51    const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});5253    const address = collectionIdToAddress(collection);54    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});5556    const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));5758    const fee = Number(cost) / Number(UNIQUE);59    const expectedFee = 0.15;60    const tolerance = 0.00002;6162    expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);63  });64});6566describe('ERC165 tests', async () => {67  // https://eips.ethereum.org/EIPS/eip-1656869  let collection: number;70  let minter: string;7172  function contract(web3: Web3): Contract {73    return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});74  }7576  before(async () => {77    await usingWeb3 (async (web3) => {78      collection = await createCollectionExpectSuccess();79      minter = createEthAccount(web3);80    });81  });82  83  itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {84    expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;85  });8687  itWeb3('ERC721 support', async ({web3}) => {88    expect(await contract(web3).methods.supportsInterface('0x58800161').call()).to.be.true;89  });9091  itWeb3('ERC721Metadata support', async ({web3}) => {92    expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;93  });9495  itWeb3('ERC721Mintable support', async ({web3}) => {96    expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;97  });9899  itWeb3('ERC721Enumerable support', async ({web3}) => {100    expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;101  });102103  itWeb3('ERC721UniqueExtensions support', async ({web3}) => {104    expect(await contract(web3).methods.supportsInterface('0xe562194d').call()).to.be.true;105  });106107  itWeb3('ERC721Burnable support', async ({web3}) => {108    expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;109  });110111  itWeb3('ERC165 support', async ({web3}) => {112    expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;113  });114});