Skip to content

Commit

Permalink
api_reference_version_equals_constant test, readme fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cassandrus committed Mar 18, 2024
1 parent ec870a7 commit 9c6555c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# EVER-SDK for Java

[![JDK version](https://img.shields.io/badge/Java-20-green.svg)](https://shields.io/)
[![SDK version](https://img.shields.io/badge/EVER%20SDK-v1.44.3-orange)](https://github.com/tonlabs/ever-sdk)
[![JDK version](https://img.shields.io/badge/Java-21-green.svg)](https://shields.io/)
[![SDK version](https://img.shields.io/badge/EVER%20SDK-v1.45.0-orange)](https://github.com/tonlabs/ever-sdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-brown.svg)](https://shields.io/)

* Discuss in
Expand All @@ -15,7 +15,7 @@ compatible with
[Everscale](https://everscale.network/), Venom, GOSH & TON blockchain
networks.
Binding calls [JSON-RPC](https://github.com/tonlabs/ever-sdk/blob/master/docs/for-binding-developers/json_interface.md) interface of EVER-SDK.
Native calls are based on modern [Foreign Function & Memory API](https://openjdk.org/jeps/434).
Native calls are based on modern [Foreign Function & Memory API](https://openjdk.org/jeps/454).

This artifact provides full binding functionality, but doesn't include
higher level helpers for development, tests or fast prototyping. Try our larger [Java4Ever](https://github.com/deplant/java4ever-framework) framework
Expand All @@ -31,15 +31,15 @@ that is based on this binding for easier work with TVM blockchains.

#### Prerequisites

* Install **JDK 20** ([link](https://adoptium.net/temurin/releases?version=20))
* Install **JDK 21** ([link](https://adoptium.net/temurin/releases?version=20))

#### Add java4ever to your Maven of Gradle setup:

* Gradle

```groovy
dependencies {
implementation 'tech.deplant.java4ever:java4ever-binding:2.5.0'
implementation 'tech.deplant.java4ever:java4ever-binding:3.0.0'
}
```

Expand All @@ -50,7 +50,7 @@ dependencies {
<dependency>
<groupId>tech.deplant.java4ever</groupId>
<artifactId>java4ever-binding</artifactId>
<version>2.5.0</version>
<version>3.0.0</version>
</dependency>
```

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/tech/deplant/java4ever/binding/EverSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public static EverSdkContext getContext(int contextId) {
return contexts.get(contextId);
}

public static long getDefaultWorkchainId(int contextId) {
return switch (getContext(contextId).config().abi()) {
case null -> 0L;
case Client.AbiConfig abiConfig -> Optional.ofNullable(abiConfig.workchain()).orElse(0L);
};
}

public static void load() {
load(DefaultLoaderContext.SINGLETON(ClassLoader.getSystemClassLoader()));
}
Expand Down
42 changes: 32 additions & 10 deletions src/main/java/tech/deplant/java4ever/binding/JsonContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public static ObjectMapper SDK_JSON_MAPPER() {
return lazySdkMapper;
}

public static ObjectMapper ABI_JSON_MAPPER() {
if (lazyAbiMapper == null) {
lazyAbiMapper = JsonMapper.builder()
.addModule(new ParameterNamesModule())
.addModule(new Jdk8Module())
.addModule(new JavaTimeModule())
.build()
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
return lazyAbiMapper;
}

public static JsonNode EMPTY_NODE() {
if (emptyNode == null) {
emptyNode = SDK_JSON_MAPPER().valueToTree(Map.of());
Expand All @@ -54,16 +66,26 @@ public static Map<String, Object> readAsMap(ObjectMapper mapper, JsonNode json)
return Objs.notNullElseLazy(mapper.readValue(json.traverse(), MAP_STRING_OBJECT_TYPE), Map::of);
}

public static ObjectMapper ABI_JSON_MAPPER() {
if (lazyAbiMapper == null) {
lazyAbiMapper = JsonMapper.builder()
.addModule(new ParameterNamesModule())
.addModule(new Jdk8Module())
.addModule(new JavaTimeModule())
.build()
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
return lazyAbiMapper;
public static <T> T convertAbiMap(Map<String, Object> inputMap, Class<T> outputClass) {
return ABI_JSON_MAPPER().convertValue(inputMap, outputClass);
}

public static <T> T convertAbiMap(Map<String, Object> inputMap, TypeReference<T> outputType) {
return ABI_JSON_MAPPER().convertValue(inputMap, outputType);
}

public static JsonNode readAbiStruct(Object struct) throws JsonProcessingException {
return ABI_JSON_MAPPER().readTree(serialize(struct));
}

public static <T> T deserialize(String inputString, Class<T> outputClass) throws JsonProcessingException {
return ABI_JSON_MAPPER().readValue(inputString, outputClass);
}

public static String serialize(Object inputObject) throws JsonProcessingException {
return ABI_JSON_MAPPER().writeValueAsString(inputObject);
}



}
9 changes: 8 additions & 1 deletion src/test/java/tech/deplant/java4ever/unit/ClientTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ public static void loadSdk() {

@Test
@OnlineMeans(url = TestEnv.NODESE_URL, connectTimeout = 500, readTimeout = 1500)
public void check_ever_sdk_version() throws EverSdkException {
public void sdk_version_equals_constant() throws EverSdkException {
int ctxId = TestEnv.newContext();
assertEquals(DefaultLoader.EVER_SDK_VERSION, Client.version(ctxId).version());
}

@Test
@OnlineMeans(url = TestEnv.NODESE_URL, connectTimeout = 500, readTimeout = 1500)
public void api_reference_version_equals_constant() throws EverSdkException {
int ctxId = TestEnv.newContext();
assertEquals(DefaultLoader.EVER_SDK_VERSION, Client.getApiReference(ctxId).api().get("version").asText());
}

}
2 changes: 1 addition & 1 deletion src/test/java/tech/deplant/java4ever/unit/ConfigTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void config_from_builder_equals_config_from_json() throws IOException {
int ctxId2 = EverSdk.createWithEndpoint(TestEnv.NODESE_ENDPOINT).orElseThrow();
var config1 = EverSdk.getContext(ctxId).config();
var config2 = EverSdk.getContext(ctxId2).config();
//assertEquals(config1,config2);
assertEquals(config1.toString(),config2.toString());
}

@Test
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/tech/deplant/java4ever/unit/TestEnv.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tech.deplant.java4ever.unit;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.jupiter.api.Test;
import tech.deplant.java4ever.binding.EverSdk;

public class TestEnv {
Expand All @@ -14,4 +15,14 @@ static int newContext() {
throw new RuntimeException(e);
}
}


@Test
public void test_method()
{
byte num = (byte)127;
num++;
System.out.println(num);
}

}

0 comments on commit 9c6555c

Please sign in to comment.