Skip to content

Commit

Permalink
add additional unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Usman Saleem <[email protected]>
  • Loading branch information
usmansaleem committed Jul 15, 2024
1 parent e237bde commit 37517e1
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.Test;

public class JsonCallParameterTest {
Expand All @@ -38,6 +41,64 @@ public void acceptsAndCapMaxValueForGas() throws JsonProcessingException {
assertThat(callParameter.getGasLimit()).isEqualTo(Long.MAX_VALUE);
}

@Test
public void dataAsPayLoad() throws JsonProcessingException {
final String json =
"""
{
"data": "0x1234"
}
""";

final JsonCallParameter callParameter = objectMapper.readValue(json, JsonCallParameter.class);

assertThat(callParameter.getPayload()).isEqualTo(Bytes.fromHexString("0x1234"));
}

@Test
public void inputAsPayLoad() throws JsonProcessingException {
final String json =
"""
{
"input": "0x1234"
}
""";

final JsonCallParameter callParameter = objectMapper.readValue(json, JsonCallParameter.class);

assertThat(callParameter.getPayload()).isEqualTo(Bytes.fromHexString("0x1234"));
}

@Test
public void inputAndDataWithSameValueAsPayLoad() throws JsonProcessingException {
final String json =
"""
{
"input": "0x1234",
"data": "0x1234"
}
""";

final JsonCallParameter callParameter = objectMapper.readValue(json, JsonCallParameter.class);

assertThat(callParameter.getPayload()).isEqualTo(Bytes.fromHexString("0x1234"));
}

@Test
public void inputAndDataWithDifferentValueAsPayLoadCauseException() {
final String json =
"""
{
"input": "0x1234",
"data": "0x1235"
}
""";

assertThatExceptionOfType(JsonMappingException.class)
.isThrownBy(() -> objectMapper.readValue(json, JsonCallParameter.class))
.withMessageContaining("problem: Only one of 'input' or 'data' should be provided");
}

@Test
public void extraParametersAreIgnoredIgnored() throws JsonProcessingException {
final String json =
Expand Down

0 comments on commit 37517e1

Please sign in to comment.