From e0a488b67f055a667a7270dcfb2d08902bc7d3a3 Mon Sep 17 00:00:00 2001 From: Jamie Date: Mon, 27 Jun 2022 11:25:20 +0900 Subject: [PATCH] Fixed test error --- packages/caver-core-method/src/index.js | 2 +- .../caver.transaction/ethereumDynamicFee.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/caver-core-method/src/index.js b/packages/caver-core-method/src/index.js index 533c162f5..1cf035e50 100644 --- a/packages/caver-core-method/src/index.js +++ b/packages/caver-core-method/src/index.js @@ -461,7 +461,7 @@ const buildSendFunc = (method, isSendTx) => async (...args) => { // The TxTypeEthereumDynamicFee transaction does not use the gasPrice field, // so we need to check `maxPriorityFeePerGas` and `maxFeePerGas` field instead of `gasPrice`. - const isDynamicFeeTx = payload.params[0].type === TX_TYPE_STRING.TxTypeEthereumDynamicFee + const isDynamicFeeTx = isSendTx && (payload.params[0].type === TX_TYPE_STRING.TxTypeEthereumDynamicFee) const filledDynamicGasFeeTx = isDynamicFeeTx && payload.params[0].maxPriorityFeePerGas !== undefined && payload.params[0].maxFeePerGas !== undefined diff --git a/test/packages/caver.transaction/ethereumDynamicFee.js b/test/packages/caver.transaction/ethereumDynamicFee.js index 71958e6cf..cbdbff751 100644 --- a/test/packages/caver.transaction/ethereumDynamicFee.js +++ b/test/packages/caver.transaction/ethereumDynamicFee.js @@ -906,7 +906,7 @@ describe('TxTypeEthereumDynamicFee', () => { await tx.fillTransaction() expect(getMaxPriorityFeePerGasSpy).to.have.been.calledOnce - expect(getHeaderByNumberSpy).to.have.been.calledOnce + expect(getHeaderByNumberSpy).not.to.have.been.calledOnce // getHeader only when maxFeePerGas is empty to get baseFee. expect(getNonceSpy).not.to.have.been.calledOnce expect(getChainIdSpy).not.to.have.been.calledOnce }).timeout(200000) @@ -915,9 +915,14 @@ describe('TxTypeEthereumDynamicFee', () => { transactionObj.nonce = '0x3a' delete transactionObj.maxFeePerGas const tx = caver.transaction.ethereumDynamicFee.create(transactionObj) - const expectedMaxFeePerGas = utils.toHex( - utils.hexToNumber(baseFee) * 2 + utils.hexToNumber(transactionObj.maxPriorityFeePerGas) - ) + + let expectedMaxFeePerGas + const latestHeader = await caver.rpc.klay.getHeaderByNumber('latest') + if (latestHeader.baseFeePerGas && caver.utils.hexToNumber(latestHeader.baseFeePerGas) > 0) { + expectedMaxFeePerGas = caver.utils.toHex(caver.utils.hexToNumber(latestHeader.baseFeePerGas) * 2) + } else { + expectedMaxFeePerGas = await caver.rpc.klay.getGasPrice() + } await tx.fillTransaction()