Skip to content

Commit

Permalink
Merge branch 'main' into 2379-estimate_gas-does-not-reflect-changes-i…
Browse files Browse the repository at this point in the history
…n-mirror-node

Signed-off-by: Victor Yanev <[email protected]>

# Conflicts:
#	packages/relay/src/lib/precheck.ts
  • Loading branch information
victor-yanev committed Jun 11, 2024
1 parent e6b6adf commit 4b03396
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 36 deletions.
20 changes: 20 additions & 0 deletions packages/relay/tests/lib/eth/eth-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { CacheService } from '../../../src/lib/services/cacheService/cacheService';
import pino from 'pino';
import { Registry } from 'prom-client';
Expand Down
66 changes: 30 additions & 36 deletions packages/relay/tests/lib/precheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

import { Assertion, expect } from 'chai';
import { expect } from 'chai';
import { Registry } from 'prom-client';
import { Hbar, HbarUnit } from '@hashgraph/sdk';
const registry = new Registry();
Expand All @@ -29,13 +29,15 @@ import { blobVersionedHash, contractAddress1, expectedError, mockData, signTrans
import { MirrorNodeClient } from '../../src/lib/clients';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { ethers } from 'ethers';
import { Transaction, ethers } from 'ethers';
import constants from '../../src/lib/constants';
import { JsonRpcError, predefined } from '../../src';
import { CacheService } from '../../src/lib/services/cacheService/cacheService';
import { ONE_TINYBAR_IN_WEI_HEX } from './eth/eth-config';
const logger = pino();

const limitOrderPostFix = '?order=desc&limit=1';
const transactionsPostFix = '?transactions=false';

describe('Precheck', async function () {
const txWithMatchingChainId =
Expand All @@ -59,10 +61,18 @@ describe('Precheck', async function () {
const parsedTxWithValueLessThanOneTinybarAndNotEmptyData = ethers.Transaction.from(
txWithValueLessThanOneTinybarAndNotEmptyData,
);
const oneTinyBar = ethers.parseUnits('1', 10);

const defaultGasPrice = 720_000_000_000;
const defaultGasLimit = 1_000_000;
const defaultChainId = Number('0x12a');
const defaultTx = {
gasLimit: defaultGasLimit,
gasPrice: defaultGasPrice,
chainId: defaultChainId,
maxFeePerGas: null,
maxPriorityFeePerGas: null,
};

let precheck: Precheck;
let mock: MockAdapter;

Expand Down Expand Up @@ -101,7 +111,7 @@ describe('Precheck', async function () {
let hasError = false;
try {
precheck.value(parsedTxWithValueLessThanOneTinybar);
} catch (e) {
} catch (e: any) {
expect(e).to.exist;
expect(e.code).to.eq(-32602);
expect(e.message).to.eq('Value below 10_000_000_000 wei which is 1 tinybar');
Expand Down Expand Up @@ -167,12 +177,6 @@ describe('Precheck', async function () {
});

describe('gasLimit', async function () {
const defaultTx = {
value: oneTinyBar,
gasPrice: defaultGasPrice,
chainId: defaultChainId,
};

function testFailingGasLimitPrecheck(gasLimits, errorCode) {
for (const gasLimit of gasLimits) {
it(`should fail for gasLimit: ${gasLimit}`, async function () {
Expand Down Expand Up @@ -393,13 +397,6 @@ describe('Precheck', async function () {

describe('nonce', async function () {
const defaultNonce = 3;
const defaultTx = {
value: oneTinyBar,
gasPrice: defaultGasPrice,
chainId: defaultChainId,
nonce: defaultNonce,
};

const mirrorAccount = {
ethereum_nonce: defaultNonce,
};
Expand Down Expand Up @@ -450,25 +447,22 @@ describe('Precheck', async function () {
});

describe('account', async function () {
const defaultNonce = 3;
const defaultTx = {
value: oneTinyBar,
gasPrice: defaultGasPrice,
chainId: defaultChainId,
nonce: defaultNonce,
from: mockData.accountEvmAddress,
};

const signed = await signTransaction(defaultTx);
const parsedTx = ethers.Transaction.from(signed);
let parsedTx: Transaction;
let mirrorAccount: any;
const defaultNonce: number = 3;

const mirrorAccount = {
evm_address: mockData.accountEvmAddress,
ethereum_nonce: defaultNonce,
};
before(async () => {
const wallet = ethers.Wallet.createRandom();
const signed = await wallet.signTransaction({ ...defaultTx, from: wallet.address, nonce: defaultNonce });
parsedTx = ethers.Transaction.from(signed);
mirrorAccount = {
evm_address: parsedTx.from,
ethereum_nonce: defaultNonce,
};
});

it(`should fail for missing account`, async function () {
mock.onGet(`accounts/${mockData.accountEvmAddress}${limitOrderPostFix}`).reply(404, mockData.notFound);
mock.onGet(`accounts/${parsedTx.from}${transactionsPostFix}`).reply(404, mockData.notFound);

try {
await precheck.verifyAccount(parsedTx);
Expand All @@ -477,12 +471,12 @@ describe('Precheck', async function () {
expect(e).to.exist;
expect(e.code).to.eq(-32001);
expect(e.name).to.eq('Resource not found');
expect(e.message).to.contain(mockData.accountEvmAddress);
expect(e.message).to.contain(parsedTx.from);
}
});

it(`should not fail for matched account`, async function () {
mock.onGet(`accounts/${mockData.accountEvmAddress}${limitOrderPostFix}`).reply(200, mirrorAccount);
mock.onGet(`accounts/${parsedTx.from}${transactionsPostFix}`).reply(200, mirrorAccount);
const account = await precheck.verifyAccount(parsedTx);

expect(account.ethereum_nonce).to.eq(defaultNonce);
Expand Down Expand Up @@ -583,7 +577,7 @@ describe('Precheck', async function () {

describe('transactionType', async function () {
const defaultTx = {
value: oneTinyBar,
value: ONE_TINYBAR_IN_WEI_HEX,
gasPrice: defaultGasPrice,
gasLimit: defaultGasLimit,
chainId: defaultChainId,
Expand Down

0 comments on commit 4b03396

Please sign in to comment.