|
|
@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
import static org.mockito.ArgumentMatchers.anyLong; |
|
|
|
import static org.mockito.ArgumentMatchers.anyLong; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.lenient; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.times; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
import static org.mockito.Mockito.verifyNoMoreInteractions; |
|
|
|
import static org.mockito.Mockito.verifyNoMoreInteractions; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
@ -61,7 +63,6 @@ import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.internal.verification.VerificationModeFactory; |
|
|
|
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
@ -106,8 +107,8 @@ public class EthGasPriceTest { |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
|
|
|
|
|
|
|
|
verify(blockchain).getChainHeadBlockNumber(); |
|
|
|
verify(blockchain).getChainHeadBlock(); |
|
|
|
verify(blockchain, VerificationModeFactory.times(100)).getBlockByNumber(anyLong()); |
|
|
|
verify(blockchain, times(99)).getBlockByNumber(anyLong()); |
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -127,8 +128,7 @@ public class EthGasPriceTest { |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
|
|
|
|
|
|
|
|
verify(blockchain).getChainHeadBlockNumber(); |
|
|
|
verify(blockchain).getChainHeadBlock(); |
|
|
|
verify(blockchain, VerificationModeFactory.times(1)).getBlockByNumber(anyLong()); |
|
|
|
|
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -146,8 +146,8 @@ public class EthGasPriceTest { |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
|
|
|
|
|
|
|
|
verify(blockchain).getChainHeadBlockNumber(); |
|
|
|
verify(blockchain).getChainHeadBlock(); |
|
|
|
verify(blockchain, VerificationModeFactory.times(100)).getBlockByNumber(anyLong()); |
|
|
|
verify(blockchain, times(99)).getBlockByNumber(anyLong()); |
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -165,8 +165,8 @@ public class EthGasPriceTest { |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
|
|
|
|
|
|
|
|
verify(blockchain).getChainHeadBlockNumber(); |
|
|
|
verify(blockchain).getChainHeadBlock(); |
|
|
|
verify(blockchain, VerificationModeFactory.times(81)).getBlockByNumber(anyLong()); |
|
|
|
verify(blockchain, times(80)).getBlockByNumber(anyLong()); |
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -252,8 +252,7 @@ public class EthGasPriceTest { |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
final JsonRpcResponse actualResponse = method.response(request); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); |
|
|
|
|
|
|
|
|
|
|
|
verify(blockchain).getChainHeadBlockNumber(); |
|
|
|
verify(blockchain).getChainHeadBlock(); |
|
|
|
verify(blockchain, VerificationModeFactory.times(1)).getBlockByNumber(anyLong()); |
|
|
|
|
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
verifyNoMoreInteractions(blockchain); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -328,12 +327,14 @@ public class EthGasPriceTest { |
|
|
|
blocksByNumber.put(i, createFakeBlock(i, txsNum, baseFee)); |
|
|
|
blocksByNumber.put(i, createFakeBlock(i, txsNum, baseFee)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
when(blockchain.getChainHeadBlockNumber()).thenReturn(chainHeadBlockNumber); |
|
|
|
when(blockchain.getChainHeadBlock()).thenReturn(blocksByNumber.get(chainHeadBlockNumber)); |
|
|
|
when(blockchain.getBlockByNumber(anyLong())) |
|
|
|
if (chainHeadBlockNumber > 1) { |
|
|
|
.thenAnswer( |
|
|
|
when(blockchain.getBlockByNumber(anyLong())) |
|
|
|
invocation -> Optional.of(blocksByNumber.get(invocation.getArgument(0, Long.class)))); |
|
|
|
.thenAnswer( |
|
|
|
|
|
|
|
invocation -> Optional.of(blocksByNumber.get(invocation.getArgument(0, Long.class)))); |
|
|
|
when(blockchain.getChainHeadHeader()) |
|
|
|
} |
|
|
|
|
|
|
|
lenient() |
|
|
|
|
|
|
|
.when(blockchain.getChainHeadHeader()) |
|
|
|
.thenReturn(blocksByNumber.get(chainHeadBlockNumber).getHeader()); |
|
|
|
.thenReturn(blocksByNumber.get(chainHeadBlockNumber).getHeader()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|