Skip to content

Commit

Permalink
Merge branch 'master' into fmacleal/addition_transient_storage_opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
fmacleal committed Nov 23, 2024
2 parents f3f99fa + fb418b5 commit f7d3822
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 30 deletions.
20 changes: 4 additions & 16 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,23 @@ jobs:
GH_PR_HEAD_REF: ${{ github.head_ref }}
GH_REF: ${{ github.ref }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
run: |
if [ "$GH_EVENT" = "pull_request" ]; then
if [ "$IS_FORK" != "true" ]; then
./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonarqube --no-daemon -x build -x test \
if [ "$SONAR_TOKEN" != "" ]; then
./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonar --no-daemon -x build -x test \
-Dsonar.pullrequest.base="$GH_PR_BASE_REF" \
-Dsonar.pullrequest.branch="$GH_PR_HEAD_REF" \
-Dsonar.pullrequest.key="$GH_PR_NUMBER" \
-Dsonar.organization=rsksmart \
-Dsonar.projectKey=rskj \
-Dsonar.host.url="https://sonarcloud.io" \
-Dsonar.junit.reportPaths=rskj-core/build/test-results/ \
-Dsonar.coverage.jacoco.xmlReportPaths=rskj-core/build/reports/jacoco/test/jacocoTestReport.xml \
-Dsonar.token="$SONAR_TOKEN"
else
echo "Skipping SonarQube analysis for pull request from a forked repo."
echo "Skipping SonarQube analysis."
fi
else
./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonarqube --no-daemon -x build -x test \
./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonar --no-daemon -x build -x test \
-Dsonar.branch.name="$GH_REF" \
-Dsonar.organization=rsksmart \
-Dsonar.projectKey=rskj \
-Dsonar.host.url="https://sonarcloud.io" \
-Dsonar.junit.reportPaths=rskj-core/build/test-results/ \
-Dsonar.coverage.jacoco.xmlReportPaths=rskj-core/build/reports/jacoco/test/jacocoTestReport.xml \
-Dsonar.token="$SONAR_TOKEN"
fi
mining-tests:
needs: build
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ plugins {
id "org.sonarqube" version "5.1.0.4882"
}

sonar {
properties {
property "sonar.projectKey", "rskj"
property "sonar.organization", "rsksmart"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.junit.reportPaths", "rskj-core/build/test-results/"
property "sonar.coverage.jacoco.xmlReportPaths", "rskj-core/build/reports/jacoco/test/jacocoTestReport.xml"
}
}

subprojects {
def config = new ConfigSlurper().parse(file("$projectDir/src/main/resources/version.properties").toURI().toURL())
group = 'co.rsk'
Expand Down
36 changes: 22 additions & 14 deletions rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,7 @@ public String call(CallArgumentsParam argsParam, BlockIdentifierParam bnOrId) {
} else {
res = callConstant(args, block);
}
if (res.isRevert()) {
Pair<String, byte[]> programRevert = decodeProgramRevert(res);
String revertReason = programRevert.getLeft();
byte[] revertData = programRevert.getRight();
if (revertData == null) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError();
}

if (revertReason == null) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertData);
}

throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertReason, revertData);
}
handleTransactionRevertIfHappens(res);
hReturn = HexUtils.toUnformattedJsonHex(res.getHReturn());

return hReturn;
Expand Down Expand Up @@ -193,6 +180,9 @@ public String estimateGas(CallArgumentsParam args, @Nonnull BlockIdentifierParam
snapshot
);

ProgramResult res = executor.getResult();
handleTransactionRevertIfHappens(res);

estimation = internalEstimateGas(executor.getResult());

return estimation;
Expand Down Expand Up @@ -357,4 +347,22 @@ private ProgramResult callConstantWithState(CallArguments args, Block executionB
hexArgs.getFromAddress()
);
}

private void handleTransactionRevertIfHappens(ProgramResult res) {
if (res.isRevert()) {
Pair<String, byte[]> programRevert = decodeProgramRevert(res);
String revertReason = programRevert.getLeft();
byte[] revertData = programRevert.getRight();

if (revertData == null) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError();
}

if (revertReason == null) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertData);
}

throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertReason, revertData);
}
}
}
43 changes: 43 additions & 0 deletions rskj-core/src/test/java/co/rsk/rpc/modules/eth/EthModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,49 @@ void whenExecuteEstimateGasWithDataParameter_callExecutorWithData() {
assertArrayEquals(HexUtils.strHexOrStrNumberToByteArray(args.getData()), dataCaptor.getValue());
}

@Test
void testwhenExecuteEstimateGasWithDataParameter_callExecutorWithData() {
CallArguments args = new CallArguments();
Block block = mock(Block.class);
ExecutionBlockRetriever.Result blockResult = mock(ExecutionBlockRetriever.Result.class);
when(blockResult.getBlock()).thenReturn(block);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
when(retriever.retrieveExecutionBlock("latest")).thenReturn(blockResult);
Blockchain blockchain = mock(Blockchain.class);

ProgramResult executorResult = mock(ProgramResult.class);
when(executorResult.isRevert()).thenReturn(true);
TransactionExecutor transactionExecutor = mock(TransactionExecutor.class);
when(transactionExecutor.getResult())
.thenReturn(executorResult);

ReversibleTransactionExecutor reversibleTransactionExecutor = mock(ReversibleTransactionExecutor.class);
when(reversibleTransactionExecutor.estimateGas(eq(block), any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(transactionExecutor);

EthModule eth = new EthModule(
null,
Constants.REGTEST_CHAIN_ID,
blockchain,
null,
reversibleTransactionExecutor,
retriever,
mock(RepositoryLocator.class),
null,
null,
new BridgeSupportFactory(
null, null, null, signatureCache),
config.getGasEstimationCap(),
config.getCallGasCap());

CallArgumentsParam callArgumentsParam = TransactionFactoryHelper.toCallArgumentsParam(args);

RskJsonRpcRequestException exception = assertThrows(RskJsonRpcRequestException.class, () -> {
eth.estimateGas(callArgumentsParam, new BlockIdentifierParam("latest"));
});
assertThat(exception.getMessage(), Matchers.containsString("transaction reverted"));
}

@Test
void whenExecuteEstimateGasWithInputParameter_callExecutorWithInput() {
CallArguments args = new CallArguments();
Expand Down

0 comments on commit f7d3822

Please sign in to comment.