Skip to content

Commit

Permalink
fix: reworked gas comparison logic (hashgraph#2611)
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
  • Loading branch information
quiet-node authored Jun 20, 2024
1 parent b5128bb commit 52a7d15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 6 additions & 4 deletions packages/server/tests/acceptance/rpc_batch1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
let mirrorContractDetails;
let requestId: string;
let account2Address: string;
let expectedGasPrice: string;

const CHAIN_ID = process.env.CHAIN_ID || '0x12a';
const INCORRECT_CHAIN_ID = 999;
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
this.beforeAll(async () => {
requestId = Utils.generateRequestId();
const requestIdPrefix = Utils.formatRequestIdMessage(requestId);
expectedGasPrice = await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_GAS_PRICE, [], requestId);

const initialAccount: AliasAccount = global.accounts[0];
const neededAccounts: number = 3;
Expand Down Expand Up @@ -463,7 +465,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
[mirrorBlock.hash.substring(0, 66), false],
requestId,
);
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, false);
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, expectedGasPrice, false);
});

it('@release should execute "eth_getBlockByHash", hydrated transactions = true', async function () {
Expand All @@ -474,7 +476,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
);
// Remove synthetic transactions
blockResult.transactions = blockResult.transactions.filter((transaction) => transaction.value !== '0x1234');
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, true);
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, expectedGasPrice, true);
});

it('should execute "eth_getBlockByHash" for non-existing block hash and hydrated transactions = false', async function () {
Expand Down Expand Up @@ -503,7 +505,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
);
// Remove synthetic transactions
blockResult.transactions = blockResult.transactions.filter((transaction) => transaction.value !== '0x1234');
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, false);
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, expectedGasPrice, false);
});

it('@release should execute "eth_getBlockByNumber", hydrated transactions = true', async function () {
Expand All @@ -514,7 +516,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
);
// Remove synthetic transactions
blockResult.transactions = blockResult.transactions.filter((transaction) => transaction.value !== '0x1234');
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, true);
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, expectedGasPrice, true);
});

it('should execute "eth_getBlockByNumber" for non existing block number and hydrated transactions = true', async function () {
Expand Down
4 changes: 3 additions & 1 deletion packages/server/tests/acceptance/rpc_batch2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
let tokenId;
let requestId;
let htsAddress;
let expectedGasPrice: string;
let basicContract: ethers.Contract;
let basicContractAddress: string;
let parentContractAddress: string;
Expand Down Expand Up @@ -92,6 +93,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
this.beforeAll(async () => {
requestId = Utils.generateRequestId();
const requestIdPrefix = Utils.formatRequestIdMessage(requestId);
expectedGasPrice = await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_GAS_PRICE, [], requestId);

const initialAccount: AliasAccount = global.accounts[0];

Expand Down Expand Up @@ -417,7 +419,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
const res = await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_GAS_PRICE, [], requestId);
expect(res).to.exist;
if (process.env.LOCAL_NODE && process.env.LOCAL_NODE !== 'false') {
expect(res).be.equal(ethers.toQuantity(Assertions.defaultGasPrice));
expect(res).be.equal(expectedGasPrice);
} else {
expect(Number(res)).to.be.gt(0);
}
Expand Down
10 changes: 8 additions & 2 deletions packages/server/tests/helpers/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ export default class Assertions {
* @param mirrorTransactions
* @param hydratedTransactions - aka showDetails flag
*/
public static block(relayResponse, mirrorNodeResponse, mirrorTransactions, hydratedTransactions = false) {
public static block(
relayResponse,
mirrorNodeResponse,
mirrorTransactions,
expectedGasPrice,
hydratedTransactions = false,
) {
// Assert static values
expect(relayResponse.baseFeePerGas).to.exist;

if (process.env.LOCAL_NODE && process.env.LOCAL_NODE !== 'false') {
expect(relayResponse.baseFeePerGas).to.be.equal(ethers.toQuantity(this.defaultGasPrice));
expect(relayResponse.baseFeePerGas).to.be.equal(expectedGasPrice);
} else {
expect(Number(relayResponse.baseFeePerGas)).to.be.gt(0);
}
Expand Down

0 comments on commit 52a7d15

Please sign in to comment.