Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

allprojects {
group = 'com.strategyobject.substrateclient'
version = '0.0.3-SNAPSHOT'
version = '0.0.4-SNAPSHOT'

repositories {
mavenLocal()
Expand Down
2 changes: 1 addition & 1 deletion crypto/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
implementation 'com.github.multiformats:java-multibase:1.1.0'
implementation 'org.bouncycastle:bcprov-jdk15on:1.69'
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
implementation project(":common")
implementation project(":types")
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/rpc-codegen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {

implementation 'com.squareup:javapoet:1.13.0'
testImplementation 'com.google.testing.compile:compile-testing:0.19'
testImplementation 'com.google.code.gson:gson:2.8.9'
testImplementation 'com.google.code.gson:gson:2.9.0'

testCompileOnly project(':rpc:rpc-codegen')
testAnnotationProcessor project(':rpc:rpc-codegen')
Expand Down
2 changes: 1 addition & 1 deletion rpc/rpc-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ dependencies {
implementation project(':scale')
implementation project(':transport')

testImplementation 'com.google.code.gson:gson:2.8.9'
testImplementation 'com.google.code.gson:gson:2.9.0'
}
6 changes: 3 additions & 3 deletions rpc/rpc-sections/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {

testImplementation 'org.testcontainers:testcontainers:1.16.3'
testImplementation 'org.testcontainers:junit-jupiter:1.16.3'
testImplementation 'ch.qos.logback:logback-classic:1.2.10'
testImplementation 'org.awaitility:awaitility:4.1.1'
testImplementation 'org.bouncycastle:bcprov-jdk15on:1.69'
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
testImplementation 'org.awaitility:awaitility:4.2.0'
testImplementation 'org.bouncycastle:bcprov-jdk15on:1.70'
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

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

@Testcontainers
public class StateTests {
Expand Down Expand Up @@ -100,11 +99,29 @@ void getStorage() throws ExecutionException, InterruptedException, TimeoutExcept
val key = "0xc2261276cc9d1f8598ea4b6a74b15c2f308ce9615de0775a82f8a94dc3d285a1"; // TODO implement and use `xxhash`
val storageData = rpcSection.getStorage(StorageKey.valueOf(HexConverter.toBytes(key))).get(WAIT_TIMEOUT, TimeUnit.SECONDS);

assertTrue(storageData != null);
assertNotNull(storageData);
assertTrue(storageData.getData().length > 0);
}
}

@Test
void getStorageHandlesNullResponse() throws ExecutionException, InterruptedException, TimeoutException, RpcInterfaceInitializationException {
try (WsProvider wsProvider = WsProvider.builder()
.setEndpoint(substrate.getWsAddress())
.disableAutoConnect()
.build()) {
wsProvider.connect().get(WAIT_TIMEOUT, TimeUnit.SECONDS);

val sectionFactory = new RpcGeneratedSectionFactory();
State rpcSection = sectionFactory.create(State.class, wsProvider);

val emptyKey = new byte[32];
val storageData = rpcSection.getStorage(StorageKey.valueOf(emptyKey)).get(WAIT_TIMEOUT, TimeUnit.SECONDS);

assertNull(storageData);
}
}

@Test
void getStorageAt() throws ExecutionException, InterruptedException, TimeoutException, RpcInterfaceInitializationException {
try (WsProvider wsProvider = WsProvider.builder()
Expand All @@ -123,7 +140,7 @@ void getStorageAt() throws ExecutionException, InterruptedException, TimeoutExce

assertTrue(changes.size() > 0);
assertTrue(changes.get(0).getChanges().size() > 0);
assertTrue(changes.get(0).getChanges().get(0).getValue0().getData() != null);
assertNotNull(changes.get(0).getChanges().get(0).getValue0().getData());
assertTrue(changes.get(0).getChanges().get(0).getValue0().getData().length > 0);
}
}
Expand Down
6 changes: 3 additions & 3 deletions transport/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ dependencies {
implementation project(':common')

implementation 'org.java-websocket:Java-WebSocket:1.5.2'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.google.code.gson:gson:2.9.0'

testImplementation project(':tests')
testImplementation 'ch.qos.logback:logback-classic:1.2.10'
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
testImplementation 'org.testcontainers:testcontainers:1.16.3'
testImplementation 'org.testcontainers:junit-jupiter:1.16.3'
testImplementation "org.testcontainers:toxiproxy:1.16.3"
testImplementation 'org.awaitility:awaitility:4.1.1'
testImplementation 'org.awaitility:awaitility:4.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class RpcCoder {
private static final Gson GSON = new GsonBuilder()
.registerTypeAdapter(RpcObject.class, new RpcObjectDeserializer())
.registerTypeAdapter(RpcObject.class, new RpcObjectTypeAdapter())
.create();

private final AtomicInteger id = new AtomicInteger(0);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.strategyobject.substrateclient.transport.coder;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.strategyobject.substrateclient.transport.*;
import lombok.val;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class RpcObjectTypeAdapter extends TypeAdapter<RpcObject> {
@Override
public void write(JsonWriter out, RpcObject value) throws IOException {
throw new UnsupportedOperationException();
}

@Override
public RpcObject read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return new RpcNull();
case BOOLEAN:
return new RpcBoolean(in.nextBoolean());
case NUMBER:
return new RpcNumber(in.nextDouble());
case STRING:
return new RpcString(in.nextString());
case BEGIN_ARRAY:
in.beginArray();
val list = new ArrayList<RpcObject>();
while (in.hasNext()) {
list.add(this.read(in));
}

in.endArray();
return new RpcList(list);
default:
in.beginObject();
val map = new HashMap<String, RpcObject>();
while (in.hasNext()) {
map.put(in.nextName(), this.read(in));
}

in.endObject();
return new RpcMap(map);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@

class RpcCoderTest {

@Test
void decodeNullResult() {
val json = "{\n" +
" \"result\": null,\n" +
" \"id\": 0,\n" +
" \"jsonrpc\": \"3.0\"\n" +
"}";
val actual = RpcCoder.decodeJson(json);

val expected = new JsonRpcResponse();
expected.jsonrpc = "3.0";
expected.id = 0;
expected.result = RpcObject.ofNull();
assertThat(actual)
.usingRecursiveComparison()
.isEqualTo(expected);
}

@Test
void decodeJson() {
val json = "{\n" +
Expand Down