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

difftreelog

source

js-packages/tests/eth/nativeRpc/estimateGas.test.ts2.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 {expect, itEth, usingEthPlaygrounds} from '@unique/test-utils/eth/util.js';18import type {IKeyringPair} from '@polkadot/types/types';192021describe('Ethereum native RPC calls', () => {22  let donor: IKeyringPair;23  const NATIVE_TOKEN_ADDRESS = '0x17c4e6453cc49aaaaeaca894e6d9683e00000000';2425  before(async function() {26    await usingEthPlaygrounds(async (_, privateKey) => {27      donor = await privateKey({url: import.meta.url});28    });29  });3031  itEth('estimate gas', async ({helper}) => {32    const BALANCE = 100n;33    const BALANCE_TO_TRANSFER = 90n;3435    const owner = await helper.eth.createAccountWithBalance(donor, BALANCE);36    const recepient = helper.eth.createAccount();3738    const web3 = helper.getWeb3();39    // data: transfer(recepient, 90);40    const data = web3.eth.abi.encodeFunctionCall({41      name: 'transfer',42      type: 'function',43      inputs: [{44        type: 'address',45        name: 'to',46      },{47        type: 'uint256',48        name: 'amount',49      }],50    }, [recepient, (BALANCE_TO_TRANSFER * (10n ** 18n)).toString()]);5152    const estimateGas = await web3.eth.estimateGas({53      to: NATIVE_TOKEN_ADDRESS,54      value: '0x0',55      data,56      from: owner,57      maxFeePerGas: '0x14c9338c61d',58    });5960    expect(estimateGas).to.be.greaterThan(35000).and.to.be.lessThan(50000);61  });62});