Skip to content

Commit

Permalink
fix: allow data with size lower than 4 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk authored and jurajpiar committed May 17, 2024
1 parent 19d2201 commit 3eeeb97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,16 @@ public ProgramResult callConstant(CallArguments args, Block executionBlock) {
*/
public static Pair<String, byte[]> decodeProgramRevert(ProgramResult programResult) {
byte[] bytes = programResult.getHReturn();
if (bytes == null || bytes.length < 4) {
if (bytes == null) {

return Pair.of(null, null);
}

if (bytes.length < 4) {

return Pair.of(null, bytes);
}

final byte[] signature = copyOfRange(bytes, 0, 4);
if (!Arrays.equals(signature, ERROR_ABI_FUNCTION_SIGNATURE)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected RskJsonRpcRequestException(Integer code, @Nullable byte[] revertData,
}

protected RskJsonRpcRequestException(Integer code, String message, Exception e) {
this(code, new byte[]{}, message, e);
this(code, null, message, e);
}

public RskJsonRpcRequestException(Integer code, @Nullable byte[] revertData, String message) {
Expand All @@ -26,7 +26,7 @@ public RskJsonRpcRequestException(Integer code, @Nullable byte[] revertData, Str
}

public RskJsonRpcRequestException(Integer code, String message) {
this(code, new byte[]{}, message);
this(code, null, message);
}

public Integer getCode() {
Expand All @@ -50,9 +50,7 @@ public static RskJsonRpcRequestException transactionRevertedExecutionError(
@Nonnull byte[] revertData
) {
return executionError(
revertReason.isEmpty()
? "transaction reverted, no reason specified"
: "revert " + revertReason,
"revert " + revertReason,
revertData
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void test_resolveError_givenRskJsonRpcRequestExceptionWithoutData_returnsJsonErr
// Given
Integer code = 1;
String message = "message";
String expectedData = "0x";
String expectedData = null;
RskJsonRpcRequestException exception = new RskJsonRpcRequestException(code, message);

Method methodMock = this.getClass().getMethod("mockMethod");
Expand Down

0 comments on commit 3eeeb97

Please sign in to comment.