Skip to content

Commit

Permalink
Add Protection against Epoch Transition null values received from Koi…
Browse files Browse the repository at this point in the history
…os Instances.

Bump version to 1.16.3
  • Loading branch information
edridudi committed Feb 2, 2023
1 parent aed55ce commit e4313f4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Resource and maintenance requirements for Cardano blockchain components (e.g. ca

| Koios Instance | Koios Java Client |
|:--------------:|:-----------------:|
| 1.0.9 | 1.16.2 |
| 1.0.9 | 1.16.3 |
| 1.0.8 | 1.15.2 |
| 1.0.7 | 1.14.1 |
| 1.0.6 | 1.13 |
Expand All @@ -281,13 +281,13 @@ Resource and maintenance requirements for Cardano blockchain components (e.g. ca
<dependency>
<groupId>io.github.cardano-community</groupId>
<artifactId>koios-java-client</artifactId>
<version>1.16.2</version>
<version>1.16.3</version>
</dependency>
```

- For Gradle, add the following dependency to build.gradle
```
compile group: 'io.github.cardano-community', name: 'koios-java-client', version: '1.16.2'
compile group: 'io.github.cardano-community', name: 'koios-java-client', version: '1.16.3'
```

### Get Koios Backend Service
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.cardano-community</groupId>
<artifactId>koios-java-client</artifactId>
<version>1.16.2</version>
<version>1.16.3</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Koios Java Client is a Java REST Client library which allows interacting with Koios Server Instances using Java Objects</description>
<url>https://github.com/cardano-community/koios-java-client</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,7 @@ public EpochServiceImpl(BaseService baseService) {

@Override
public Result<EpochInfo> getLatestEpochInfo() throws ApiException {
Integer epochNo;
Call<List<Tip>> tipCall = networkApi.getChainTip();
try {
Response<List<Tip>> tipResponse = (Response) execute(tipCall);
Result<Tip> tipResult = processResponseGetOne(tipResponse);
if (tipResult.isSuccessful() && tipResult.getValue() != null && tipResult.getValue().getEpochNo() != null) {
epochNo = tipResult.getValue().getEpochNo();
} else {
throw new ApiException("Missing EpochNo Value from Tip Response: "+tipResult);
}
} catch (IOException e) {
throw new ApiException(e.getMessage(), e);
}
return getEpochInformationByEpoch(epochNo);
return getEpochInformationByEpoch(getEpochNoFromTip());
}

@Override
Expand Down Expand Up @@ -80,14 +67,7 @@ public Result<List<EpochInfo>> getEpochInformation(Options options) throws ApiEx

@Override
public Result<EpochParams> getLatestEpochParameters() throws ApiException {
Options options = Options.builder().option(Limit.of(1)).build();
Call<List<EpochParams>> call = epochApi.getEpochParameters(optionsToParamMap(options));
try {
Response<List<EpochParams>> response = (Response) execute(call);
return processResponseGetOne(response);
} catch (IOException e) {
throw new ApiException(e.getMessage(), e);
}
return getEpochParametersByEpoch(getEpochNoFromTip());
}

@Override
Expand Down Expand Up @@ -135,4 +115,21 @@ public Result<List<EpochBlockProtocols>> getEpochBlockProtocols(Options options)
throw new ApiException(e.getMessage(), e);
}
}

private Integer getEpochNoFromTip() throws ApiException {
Integer epochNo;
Call<List<Tip>> tipCall = networkApi.getChainTip();
try {
Response<List<Tip>> tipResponse = (Response) execute(tipCall);
Result<Tip> tipResult = processResponseGetOne(tipResponse);
if (tipResult.isSuccessful() && tipResult.getValue() != null && tipResult.getValue().getEpochNo() != null) {
epochNo = tipResult.getValue().getEpochNo();
} else {
throw new ApiException("Missing EpochNo Value from Tip Response: "+tipResult);
}
} catch (IOException e) {
throw new ApiException(e.getMessage(), e);
}
return epochNo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void validateHexFormatTest() {
Assertions.assertDoesNotThrow(() -> baseService.validateHexFormat(""));
Assertions.assertDoesNotThrow(() -> baseService.validateHexFormat("0123456789abcdef"));
Assertions.assertThrows(ApiException.class, () -> baseService.validateHexFormat("asdf"));
Assertions.assertThrows(NullPointerException.class, () -> baseService.validateHexFormat(null));
}

@Test
Expand Down
26 changes: 21 additions & 5 deletions src/test/java/rest/koios/client/utils/Bech32UtilTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package rest.koios.client.utils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

import static org.junit.jupiter.api.Assertions.*;

class Bech32UtilTest {

@Test
void invalidCharsTest() {
Assertions.assertFalse(Bech32Util.hasValidChars(null));
assertFalse(Bech32Util.hasValidChars(null));

Assertions.assertFalse(Bech32Util.hasValidChars(""));
assertFalse(Bech32Util.hasValidChars(""));

Assertions.assertFalse(Bech32Util.hasValidChars("IQoJb3JpZ2luX2VjEJP//////////wEaCXVzLWVhc3QtMSJGMEQCIFEdcXP1FbfLBZSp1OCWP6eB6pofyWx/plHVZe4BSuUEAiAKVZYe5340wvB5uDvg/K1SbBJzvEBEyZLPDMZvlb+hjCr4AQjr//////////8BEAAaDDA1NjYxMjc1NDY1OCIMxtO9x0MsdST4bqy0KswBXPQZkMVN6+NRKkhvhkBsKnkrFn43TBFbwNJPRD0y4j2Ov1dikgpzzWGK+gff4pDec6e/vhcK0rZtQ3X7J7Id6NyoKrrt+XAzXdg8s7DWzMw6FkN0yaGIhvtqQATIkt+X5rKm0M9wwS+eNjurTQlqJdYjm94MuVCGWiQ1/xD/ZM2ECKfAV8FcnKLI+scT/kfP+weCQy1+iv8v8caS+uE8LclFINf4UOcBl4fF80vlU8qmXPVQjxXV/j9GqIwJ1+F08gEe2XbiYfHe/+g+MOXC8pAGOpkBeHgMzPDkljTJ244SO/vk1BGNNBrJeBZKLLTPsH/bynI2QSQlZcq8zreLh4GoalS+0QSRcsvPhCainLeZkxOqsK1+kfUBJpe3TW6lGLaqc8DIqUBMkhCwCbSDKWMe/o2RmlzLKZSSeJ/gABoNulUXxPpkfIBemCYi377DD5szO6dWAcLdny1FK2cZqVtRNDwh7XLpunvhMsiA"));
assertFalse(Bech32Util.hasValidChars("IQoJb3JpZ2luX2VjEJP//////////wEaCXVzLWVhc3QtMSJGMEQCIFEdcXP1FbfLBZSp1OCWP6eB6pofyWx/plHVZe4BSuUEAiAKVZYe5340wvB5uDvg/K1SbBJzvEBEyZLPDMZvlb+hjCr4AQjr//////////8BEAAaDDA1NjYxMjc1NDY1OCIMxtO9x0MsdST4bqy0KswBXPQZkMVN6+NRKkhvhkBsKnkrFn43TBFbwNJPRD0y4j2Ov1dikgpzzWGK+gff4pDec6e/vhcK0rZtQ3X7J7Id6NyoKrrt+XAzXdg8s7DWzMw6FkN0yaGIhvtqQATIkt+X5rKm0M9wwS+eNjurTQlqJdYjm94MuVCGWiQ1/xD/ZM2ECKfAV8FcnKLI+scT/kfP+weCQy1+iv8v8caS+uE8LclFINf4UOcBl4fF80vlU8qmXPVQjxXV/j9GqIwJ1+F08gEe2XbiYfHe/+g+MOXC8pAGOpkBeHgMzPDkljTJ244SO/vk1BGNNBrJeBZKLLTPsH/bynI2QSQlZcq8zreLh4GoalS+0QSRcsvPhCainLeZkxOqsK1+kfUBJpe3TW6lGLaqc8DIqUBMkhCwCbSDKWMe/o2RmlzLKZSSeJ/gABoNulUXxPpkfIBemCYi377DD5szO6dWAcLdny1FK2cZqVtRNDwh7XLpunvhMsiA"));

Assertions.assertFalse(Bech32Util.hasValidChars("pooL1rcsezjrma577f06yp40lsz76uvwh7gne35afx3zrq2ktx50f8t8"));
assertFalse(Bech32Util.hasValidChars("pooL1rcsezjrma577f06yp40lsz76uvwh7gne35afx3zrq2ktx50f8t8"));
}

@Test
void testConstructorIsPrivate() throws NoSuchMethodException {
Constructor<Bech32Util> constructor = Bech32Util.class.getDeclaredConstructor();
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
constructor.setAccessible(true);
InvocationTargetException exception = assertThrows(InvocationTargetException.class, constructor::newInstance);
assertInstanceOf(InvocationTargetException.class, exception);
assertInstanceOf(IllegalStateException.class, exception.getCause());
assertEquals("Utility Class", exception.getCause().getMessage());
}
}

0 comments on commit e4313f4

Please sign in to comment.