git.delta.rocks / unique-network / refs/commits / 25d2901b8a5d

difftreelog

source

tests/src/eth/base.test.ts5.0 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  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';2627describe('Contract calls', () => {28  let donor: IKeyringPair;2930  before(async function() {31    await usingEthPlaygrounds(async (_helper, privateKey) => {32      donor = privateKey('//Alice');33    });34  });3536  itEth('Call of simple contract fee is less than 0.2 UNQ', async ({helper}) => {37    const deployer = await helper.eth.createAccountWithBalance(donor);38    const flipper = await helper.eth.deployFlipper(deployer);3940    const cost = await recordEthFee(helper.api!, deployer, () => flipper.methods.flip().send({from: deployer}));41    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;42  });4344  itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {45    const userA = await helper.eth.createAccountWithBalance(donor);46    const userB = helper.eth.createAccount();47    const cost = await recordEthFee(helper.api!, userA, () => helper.web3!.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));48    const balanceB = await ethBalanceViaSub(helper.api!, userB);49    expect(cost - balanceB < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;50  });5152  itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {53    const caller = await helper.eth.createAccountWithBalance(donor);54    const receiver = helper.eth.createAccount();5556    const [alice] = await helper.arrange.createAccounts([10n], donor);57    const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});58    const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});5960    const address = helper.ethAddress.fromCollectionId(collection.collectionId);61    const contract = helper.ethNativeContract.collection(address, 'nft', caller);6263    const cost = await recordEthFee(helper.api!, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));6465    const fee = Number(cost) / Number(helper.balance.getOneTokenNominal());66    const expectedFee = 0.15;67    const tolerance = 0.001;6869    expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);70  });71});7273describe('ERC165 tests', async () => {74  // https://eips.ethereum.org/EIPS/eip-1657576  let collection: number;77  let minter: string;7879  function contract(helper: EthUniqueHelper): Contract {80    return helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection), 'nft', minter);81  }8283  before(async () => {84    await usingEthPlaygrounds(async (helper, privateKey) => {85      const donor = privateKey('//Alice');86      const [alice] = await helper.arrange.createAccounts([10n], donor);87      ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}));88      minter = helper.eth.createAccount();89    });90  });9192  itEth('interfaceID == 0xffffffff always false', async ({helper}) => {93    expect(await contract(helper).methods.supportsInterface('0xffffffff').call()).to.be.false;94  });9596  itEth('ERC721 support', async ({helper}) => {97    expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;98  });99100  itEth('ERC721Metadata support', async ({helper}) => {101    expect(await contract(helper).methods.supportsInterface('0x5b5e139f').call()).to.be.true;102  });103104  itEth('ERC721Mintable support', async ({helper}) => {105    expect(await contract(helper).methods.supportsInterface('0x68ccfe89').call()).to.be.true;106  });107108  itEth('ERC721Enumerable support', async ({helper}) => {109    expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;110  });111112  itEth('ERC721UniqueExtensions support', async ({helper}) => {113    expect(await contract(helper).methods.supportsInterface('0xd74d154f').call()).to.be.true;114  });115116  itEth('ERC721Burnable support', async ({helper}) => {117    expect(await contract(helper).methods.supportsInterface('0x42966c68').call()).to.be.true;118  });119120  itEth('ERC165 support', async ({helper}) => {121    expect(await contract(helper).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;122  });123});