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

difftreelog

source

tests/src/eth/base.test.ts4.7 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 {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.00002;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('0x58800161').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});