From 52a7d15dab0fa1e11d85d6f483437d93173e0629 Mon Sep 17 00:00:00 2001 From: Logan Nguyen Date: Thu, 20 Jun 2024 13:24:13 -0400 Subject: [PATCH] fix: reworked gas comparison logic (#2611) Signed-off-by: Logan Nguyen --- packages/server/tests/acceptance/rpc_batch1.spec.ts | 10 ++++++---- packages/server/tests/acceptance/rpc_batch2.spec.ts | 4 +++- packages/server/tests/helpers/assertions.ts | 10 ++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/server/tests/acceptance/rpc_batch1.spec.ts b/packages/server/tests/acceptance/rpc_batch1.spec.ts index e1f6009769..f49154e5b4 100644 --- a/packages/server/tests/acceptance/rpc_batch1.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch1.spec.ts @@ -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; @@ -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; @@ -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 () { @@ -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 () { @@ -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 () { @@ -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 () { diff --git a/packages/server/tests/acceptance/rpc_batch2.spec.ts b/packages/server/tests/acceptance/rpc_batch2.spec.ts index 0d06065487..6810c2af55 100644 --- a/packages/server/tests/acceptance/rpc_batch2.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch2.spec.ts @@ -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; @@ -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]; @@ -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); } diff --git a/packages/server/tests/helpers/assertions.ts b/packages/server/tests/helpers/assertions.ts index 7f564c3941..4a7eb1de3d 100644 --- a/packages/server/tests/helpers/assertions.ts +++ b/packages/server/tests/helpers/assertions.ts @@ -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); }