-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2176 from rsksmart/fix_eth_gasPrice_method
Updating how eth_gasPrice is calculated
- Loading branch information
Showing
8 changed files
with
136 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
rskj-core/src/test/java/org/ethereum/facade/EthereumImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* This file is part of RskJ | ||
* Copyright (C) 2023 RSK Labs Ltd. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.facade; | ||
|
||
import co.rsk.core.Coin; | ||
import org.ethereum.core.Block; | ||
import org.ethereum.core.Blockchain; | ||
import org.ethereum.listener.CompositeEthereumListener; | ||
import org.ethereum.listener.GasPriceTracker; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class EthereumImplTest { | ||
|
||
|
||
@Test | ||
void getGasPrice_returns_GasPriceTrackerValue_when_feeMarketWorking_is_true() { | ||
GasPriceTracker gasPriceTracker = mock(GasPriceTracker.class); | ||
|
||
when(gasPriceTracker.isFeeMarketWorking()).thenReturn(true); | ||
when(gasPriceTracker.getGasPrice()).thenReturn(Coin.valueOf(10)); | ||
|
||
Ethereum ethereum = new EthereumImpl(null, null, new CompositeEthereumListener(), null, gasPriceTracker, 1); | ||
Coin price = ethereum.getGasPrice(); | ||
|
||
assertEquals(10, price.asBigInteger().intValue()); | ||
} | ||
|
||
@Test | ||
void getGasPrice_returns_correctedBestBlockValue_when_feeMarketWorking_is_false() { | ||
GasPriceTracker gasPriceTracker = mock(GasPriceTracker.class); | ||
Blockchain blockchain = mock(Blockchain.class); | ||
double minGasPriceMultiplier = 1.2; | ||
Block bestBlock = mock(Block.class); | ||
|
||
when(gasPriceTracker.isFeeMarketWorking()).thenReturn(false); | ||
when(bestBlock.getMinimumGasPrice()).thenReturn(Coin.valueOf(10)); | ||
when(blockchain.getBestBlock()).thenReturn(bestBlock); | ||
|
||
Ethereum ethereum = new EthereumImpl(null, null, new CompositeEthereumListener(), blockchain, gasPriceTracker, minGasPriceMultiplier); | ||
Coin price = ethereum.getGasPrice(); | ||
|
||
assertEquals(12, price.asBigInteger().intValue()); | ||
} | ||
} |