diff --git a/nimbus/rpc/rpc_utils.nim b/nimbus/rpc/rpc_utils.nim index 5439e8d86..bf16f1ae3 100644 --- a/nimbus/rpc/rpc_utils.nim +++ b/nimbus/rpc/rpc_utils.nim @@ -80,6 +80,16 @@ proc calculateMedianGasPrice*(chain: CoreDbRef): GasInt else: result = prices[middle] + # TODO: This should properly incorporate the base fee in the block data, + # and recommend a gas fee that likely gets the block to confirm. + # This also has to work on Genesis where no prior transaction data exists. + # For compatibility with `kurtosis-tech/ethereum-package`, set this to a + # sane minimum for compatibility to unblock testing. + # Note: When this is fixed, update `tests/graphql/queries.toml` and + # re-enable the "query.gasPrice" test case (remove `skip = true`). + const minGasPrice = 30_000_000_000.GasInt + result = max(result, minGasPrice) + proc unsignedTx*(tx: TransactionArgs, chain: CoreDbRef, defaultNonce: AccountNonce): Transaction {.gcsafe, raises: [CatchableError].} = if tx.to.isSome: diff --git a/tests/graphql/queries.toml b/tests/graphql/queries.toml index 34bdab24d..55278c955 100644 --- a/tests/graphql/queries.toml +++ b/tests/graphql/queries.toml @@ -333,6 +333,7 @@ [[units]] name = "query.gasPrice" + skip = true code = """ { gasPrice diff --git a/tests/test_rpc.nim b/tests/test_rpc.nim index 6e016256d..85b383b5a 100644 --- a/tests/test_rpc.nim +++ b/tests/test_rpc.nim @@ -113,8 +113,8 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv com = com) vmState.stateDB.setCode(ks2, code) - vmState.stateDB.addBalance(signer, 9_000_000_000.u256) - + vmState.stateDB.addBalance( + signer, 1.u256 * 1_000_000_000.u256 * 1_000_000_000.u256) # 1 ETH # Test data created for eth_getProof tests let regularAcc = ethAddr("0x0000000000000000000000000000000000000001") @@ -136,7 +136,7 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv unsignedTx1 = Transaction( txType : TxLegacy, nonce : 0, - gasPrice: 1_100, + gasPrice: 30_000_000_000, gasLimit: 70_000, value : 1.u256, to : some(zeroAddress) @@ -144,7 +144,7 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv unsignedTx2 = Transaction( txType : TxLegacy, nonce : 1, - gasPrice: 1_200, + gasPrice: 30_000_000_100, gasLimit: 70_000, value : 2.u256, to : some(zeroAddress) @@ -160,7 +160,7 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv for txIndex, tx in txs: let sender = tx.getSender() let rc = vmState.processTransaction(tx, sender, vmHeader) - doAssert(rc.isOk, "Invalid transaction") + doAssert(rc.isOk, "Invalid transaction: " & rc.error) vmState.receipts[txIndex] = makeReceipt(vmState, tx.txType) let @@ -314,7 +314,7 @@ proc rpcMain*() = test "eth_gasPrice": let res = await client.eth_gasPrice() - check res == w3Qty(0x47E'u64) + check res == w3Qty(30_000_000_050) # Avg of `unsignedTx1` / `unsignedTx2` test "eth_accounts": let res = await client.eth_accounts()