-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(smgp): adds context fetching callback to providers
- Loading branch information
Showing
11 changed files
with
182 additions
and
28 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
13 changes: 11 additions & 2 deletions
13
rskj-core/src/main/java/co/rsk/mine/gas/provider/StableMinGasPriceProvider.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
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
91 changes: 91 additions & 0 deletions
91
rskj-core/src/test/java/co/rsk/mine/gas/provider/onchain/OnChainMinGasPriceProviderTest.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,91 @@ | ||
package co.rsk.mine.gas.provider.onchain; | ||
|
||
import co.rsk.config.mining.OnChainMinGasPriceSystemConfig; | ||
import co.rsk.mine.gas.provider.MinGasPriceProvider; | ||
import co.rsk.mine.gas.provider.MinGasPriceProviderType; | ||
import co.rsk.util.HexUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import co.rsk.rpc.modules.eth.EthModule; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class OnChainMinGasPriceProviderTest { | ||
private final String oracle_address = "0xbffBD993FF1d229B0FfE55668F2009d20d4F7C5f"; | ||
private final String from_address = "0xbffBD993FF1d229B0FfE55668F2009d20d4F7C5f"; | ||
private final String data = "0x"; | ||
private final long fallback_minGasPrice_fake = 1234567890L; | ||
|
||
private EthModule ethModule_mock; | ||
private MinGasPriceProvider fallback_mock; | ||
private OnChainMinGasPriceSystemConfig onChainMinGasPriceSystemConfig_mock; | ||
|
||
private OnChainMinGasPriceProvider onChainMinGasPriceProvider; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
ethModule_mock = mock(EthModule.class); | ||
when(ethModule_mock.chainId()).thenReturn("0x21"); | ||
|
||
fallback_mock = mock(MinGasPriceProvider.class); | ||
when(fallback_mock.getType()).thenReturn(MinGasPriceProviderType.FIXED); | ||
when(fallback_mock.getMinGasPrice()).thenReturn(fallback_minGasPrice_fake); | ||
|
||
onChainMinGasPriceSystemConfig_mock = mock(OnChainMinGasPriceSystemConfig.class); | ||
when(onChainMinGasPriceSystemConfig_mock.address()).thenReturn(oracle_address); | ||
when(onChainMinGasPriceSystemConfig_mock.from()).thenReturn(from_address); | ||
when(onChainMinGasPriceSystemConfig_mock.data()).thenReturn(data); | ||
|
||
|
||
onChainMinGasPriceProvider = new OnChainMinGasPriceProvider( | ||
fallback_mock, | ||
onChainMinGasPriceSystemConfig_mock, | ||
() -> ethModule_mock | ||
); | ||
} | ||
|
||
@AfterEach | ||
public void afterEach() { | ||
ethModule_mock = null; | ||
fallback_mock = null; | ||
} | ||
|
||
@Test | ||
public void getStableMinGasPrice_failedCallReturnsZero() { | ||
when(ethModule_mock.call(any(), any())).thenReturn(null); | ||
|
||
Assertions.assertEquals(0, onChainMinGasPriceProvider.getStableMinGasPrice()); | ||
} | ||
|
||
@Test | ||
public void getStableMinGasPrice_returnsCallReturnValue() { | ||
String expectedPrice = "0x21"; | ||
when(ethModule_mock.call(any(), any())).thenReturn(expectedPrice); | ||
|
||
Assertions.assertEquals( | ||
HexUtils.jsonHexToLong(expectedPrice), | ||
onChainMinGasPriceProvider.getStableMinGasPrice() | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullSource | ||
@ValueSource(strings = {"", "0x"}) | ||
public void getStableMinGasPrice_shouldFallback_whenNoData(String data_input) { | ||
when(onChainMinGasPriceSystemConfig_mock.data()).thenReturn(data_input); | ||
|
||
Assertions.assertEquals( | ||
fallback_minGasPrice_fake, | ||
onChainMinGasPriceProvider.getStableMinGasPrice(), | ||
"For " + data_input + ": " | ||
); | ||
} | ||
|
||
} |