diff --git a/src/main/java/com/casper/sdk/jackson/deserializer/TransactionTargetDeserializer.java b/src/main/java/com/casper/sdk/jackson/deserializer/TransactionTargetDeserializer.java index 1803767a..dfca79dd 100644 --- a/src/main/java/com/casper/sdk/jackson/deserializer/TransactionTargetDeserializer.java +++ b/src/main/java/com/casper/sdk/jackson/deserializer/TransactionTargetDeserializer.java @@ -1,16 +1,19 @@ package com.casper.sdk.jackson.deserializer; +import com.casper.sdk.exception.DeserializationException; import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.transaction.target.*; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.syntifi.crypto.key.encdec.Hex; import java.io.IOException; -import java.util.Iterator; + +import static com.casper.sdk.model.transaction.target.TargetConstants.*; /** * Deserializer for {@link TransactionTarget} types. @@ -19,27 +22,52 @@ */ public class TransactionTargetDeserializer extends JsonDeserializer { + private static final String NATIVE_JSON = "\"Native\""; + @Override - public TransactionTarget deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + public TransactionTarget deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { if (p.getCurrentToken() == JsonToken.START_OBJECT) { final ObjectNode treeNode = p.readValueAsTree(); - final Iterator stringIterator = treeNode.fieldNames(); - final String next = stringIterator.next(); - if (next != null && next.equals(Session.class.getSimpleName())) { - try { - return new Session(Hex.decode(treeNode.get(next).get("module_bytes").asText()), - TransactionRuntime.getJsonRuntime(treeNode.get(next).get("runtime").asText())); - } catch (NoSuchTypeException e) { - throw new RuntimeException(e); - } + final String fieldName = treeNode.fieldNames().next(); + if (SESSION.equals(fieldName)) { + return createSession(treeNode.get(fieldName)); + } else if (STORED.equals(fieldName)) { + return createStored(treeNode.get(fieldName), ctxt); } else { - throw new IllegalArgumentException("Unknown transaction target type: " + next); + throw new IllegalArgumentException("Unknown transaction target type: " + fieldName); } - } else if (p.getCurrentToken() == JsonToken.VALUE_STRING) { + } else if (p.getCurrentToken() == JsonToken.VALUE_STRING && NATIVE_JSON.equals(p.readValueAsTree().toString())) { return new Native(); } else { - throw new IllegalArgumentException("Unknown transaction target type: " + p); + throw new IllegalArgumentException("Unknown transaction target type: " + p.readValueAsTree()); + } + } + + private Stored createStored(final JsonNode node, final DeserializationContext ctx) throws IOException { + try { + return new Stored( + createInvocationTarget(node, ctx), + TransactionRuntime.fromJson(node.get(RUNTIME).asText())); + } catch (NoSuchTypeException e) { + throw new DeserializationException("Unable to find 'runtime'", e); } } + private TransactionInvocationTarget createInvocationTarget(final JsonNode node, final DeserializationContext ctx) throws IOException { + try (final JsonParser parser = node.get(ID).traverse()) { + parser.setCodec(ctx.getParser().getCodec()); + return parser.readValueAs(TransactionInvocationTarget.class); + } + } + + private Session createSession(final JsonNode node) throws DeserializationException { + try { + return new Session( + Hex.decode(node.get(MODULE_BYTES).asText()), + TransactionRuntime.fromJson(node.get(RUNTIME).asText()) + ); + } catch (NoSuchTypeException e) { + throw new DeserializationException("Unable to find required fields", e); + } + } } diff --git a/src/main/java/com/casper/sdk/jackson/serializer/TransactionTargetSerializer.java b/src/main/java/com/casper/sdk/jackson/serializer/TransactionTargetSerializer.java index ee0f1370..23843d0b 100644 --- a/src/main/java/com/casper/sdk/jackson/serializer/TransactionTargetSerializer.java +++ b/src/main/java/com/casper/sdk/jackson/serializer/TransactionTargetSerializer.java @@ -8,6 +8,8 @@ import java.io.IOException; +import static com.casper.sdk.model.transaction.target.TargetConstants.*; + /** * Serializes {@link TransactionTarget} objects. * @@ -19,21 +21,37 @@ public class TransactionTargetSerializer extends JsonSerializer getVersion() { + return Optional.ofNullable(version); + } + + @Override + public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { + ser.writeU8(getByteTag()); + ser.writeByteArray(addr.getDigest()); + if (getVersion().isPresent()) { + ser.writeBool(true); + ser.writeU32(version); + } else { + ser.writeBool(false); + } + } + + @JsonIgnore + @Override + public byte getByteTag() { + return 2; + } +} diff --git a/src/main/java/com/casper/sdk/model/transaction/target/ByPackageName.java b/src/main/java/com/casper/sdk/model/transaction/target/ByPackageName.java new file mode 100644 index 00000000..3c02e2be --- /dev/null +++ b/src/main/java/com/casper/sdk/model/transaction/target/ByPackageName.java @@ -0,0 +1,52 @@ +package com.casper.sdk.model.transaction.target; + +import com.casper.sdk.exception.NoSuchTypeException; +import com.casper.sdk.model.clvalue.serde.Target; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import dev.oak3.sbs4j.SerializerBuffer; +import dev.oak3.sbs4j.exception.ValueSerializationException; +import lombok.*; + +import java.util.Optional; + +/** + * The address and optional version identifying the package. + * + * @author ian@meywood.com + */ +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Getter +public class ByPackageName implements TransactionInvocationTarget { + /** the package name */ + private String name; + /** If `None`, the latest enabled version is implied. */ + @Getter(AccessLevel.NONE) + @JsonProperty("version") + private Long version; + + @JsonIgnore + public Optional getVersion() { + return Optional.ofNullable(version); + } + + @Override + public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { + ser.writeU8(getByteTag()); + ser.writeString(name); + if (getVersion().isPresent()) { + ser.writeBool(true); + ser.writeU32(version); + } else { + ser.writeBool(false); + } + } + + @JsonIgnore + @Override + public byte getByteTag() { + return 3; + } +} diff --git a/src/main/java/com/casper/sdk/model/transaction/target/HashAddress.java b/src/main/java/com/casper/sdk/model/transaction/target/HashAddress.java deleted file mode 100644 index 9ea54330..00000000 --- a/src/main/java/com/casper/sdk/model/transaction/target/HashAddress.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.casper.sdk.model.transaction.target; - -import com.fasterxml.jackson.annotation.JsonValue; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -/** - * An alias for Keys hash variant. - * - * @author ian@meywood.com - */ -@NoArgsConstructor -@AllArgsConstructor -@Getter -public class HashAddress { - @JsonValue - private boolean[] hashAddress; -} diff --git a/src/main/java/com/casper/sdk/model/transaction/target/Session.java b/src/main/java/com/casper/sdk/model/transaction/target/Session.java index 94cf9da5..e1738cc7 100644 --- a/src/main/java/com/casper/sdk/model/transaction/target/Session.java +++ b/src/main/java/com/casper/sdk/model/transaction/target/Session.java @@ -2,10 +2,14 @@ import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.serde.Target; -import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; import dev.oak3.sbs4j.SerializerBuffer; import dev.oak3.sbs4j.exception.ValueSerializationException; -import lombok.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; /** * The execution target is the included module bytes, i.e. compiled Wasm. diff --git a/src/main/java/com/casper/sdk/model/transaction/target/Stored.java b/src/main/java/com/casper/sdk/model/transaction/target/Stored.java index 7955b41d..b16734de 100644 --- a/src/main/java/com/casper/sdk/model/transaction/target/Stored.java +++ b/src/main/java/com/casper/sdk/model/transaction/target/Stored.java @@ -21,6 +21,8 @@ @Builder @JsonTypeName("Stored") public class Stored implements TransactionTarget { + /** The identifier of the stored execution target. */ + private TransactionInvocationTarget id; /** The execution runtime to use. */ @JsonProperty("runtime") @@ -29,6 +31,7 @@ public class Stored implements TransactionTarget { @Override public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { ser.writeU8(getByteTag()); + id.serialize(ser, target); ser.writeU8(runtime.getByteTag()); } diff --git a/src/main/java/com/casper/sdk/model/transaction/target/TargetConstants.java b/src/main/java/com/casper/sdk/model/transaction/target/TargetConstants.java new file mode 100644 index 00000000..b147c397 --- /dev/null +++ b/src/main/java/com/casper/sdk/model/transaction/target/TargetConstants.java @@ -0,0 +1,16 @@ +package com.casper.sdk.model.transaction.target; + +/** + * Constants for transaction targets. + * + * @author ian@meywood.com + */ +public abstract class TargetConstants { + + public static final String ID = "id"; + public static final String MODULE_BYTES = "module_bytes"; + public static final String NATIVE = "Native"; + public static final String RUNTIME = "runtime"; + public static final String SESSION = Session.class.getSimpleName(); + public static final String STORED = Stored.class.getSimpleName(); +} diff --git a/src/main/java/com/casper/sdk/model/transaction/target/TransactionInvocationTarget.java b/src/main/java/com/casper/sdk/model/transaction/target/TransactionInvocationTarget.java index 5f7f093a..dfb5b5ea 100644 --- a/src/main/java/com/casper/sdk/model/transaction/target/TransactionInvocationTarget.java +++ b/src/main/java/com/casper/sdk/model/transaction/target/TransactionInvocationTarget.java @@ -1,9 +1,21 @@ package com.casper.sdk.model.transaction.target; +import com.casper.sdk.model.clvalue.serde.CasperSerializableObject; +import com.casper.sdk.model.key.Tag; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + /** * The identifier of a `TransactionTarget::Stored` * * @author ian@meywood.com */ -public interface TransactionInvocationTarget { +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ByHash.class, name = "ByHash"), + @JsonSubTypes.Type(value = ByName.class, name = "ByName"), + @JsonSubTypes.Type(value = ByPackageName.class, name = "ByPackageName"), + @JsonSubTypes.Type(value = ByPackageHash.class, name = "ByPackageHash") +}) +public interface TransactionInvocationTarget extends CasperSerializableObject, Tag { } diff --git a/src/main/java/com/casper/sdk/model/transaction/target/TransactionInvocationTargetByHash.java b/src/main/java/com/casper/sdk/model/transaction/target/TransactionInvocationTargetByHash.java deleted file mode 100644 index 832b5a36..00000000 --- a/src/main/java/com/casper/sdk/model/transaction/target/TransactionInvocationTargetByHash.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.casper.sdk.model.transaction.target; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -/** - * The address identifying the invocable entity. - * - * @author ian@meywood.com - */ -@NoArgsConstructor -@AllArgsConstructor -@Setter -@Getter -public class TransactionInvocationTargetByHash implements TransactionInvocationTarget { - - private HashAddress hashAddress; -} diff --git a/src/main/java/com/casper/sdk/model/transaction/target/TransactionRuntime.java b/src/main/java/com/casper/sdk/model/transaction/target/TransactionRuntime.java index 0a0dd048..1ba1d19b 100644 --- a/src/main/java/com/casper/sdk/model/transaction/target/TransactionRuntime.java +++ b/src/main/java/com/casper/sdk/model/transaction/target/TransactionRuntime.java @@ -4,16 +4,18 @@ import com.casper.sdk.model.clvalue.serde.CasperSerializableObject; import com.casper.sdk.model.clvalue.serde.Target; import com.casper.sdk.model.key.Tag; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import dev.oak3.sbs4j.SerializerBuffer; import dev.oak3.sbs4j.exception.ValueSerializationException; +import lombok.Getter; /** * The runtime used to execute a `Transaction`. * * @author ian@meywood.com */ - +@Getter public enum TransactionRuntime implements CasperSerializableObject, Tag { /** The Casper Version 1 Virtual Machine. */ @JsonProperty("VmCasperV1") @@ -30,18 +32,19 @@ public enum TransactionRuntime implements CasperSerializableObject, Tag { this.jsonName = jsonName; } + @JsonIgnore @Override public byte getByteTag() { return tag; } - public static String getJsonName(final TransactionRuntime runtime) { - return runtime.jsonName; + public static String toJson(final TransactionRuntime runtime) { + return runtime != null ? runtime.jsonName : null; } - public static TransactionRuntime getJsonRuntime(final String name) throws NoSuchTypeException { - for (TransactionRuntime t: values()){ - if (t.jsonName.equals(name)){ + public static TransactionRuntime fromJson(final String name) throws NoSuchTypeException { + for (TransactionRuntime t : values()) { + if (t.jsonName.equals(name)) { return t; } } diff --git a/src/test/java/com/HowTo.java b/src/test/java/com/HowTo.java index 58b06a28..8211ed1c 100644 --- a/src/test/java/com/HowTo.java +++ b/src/test/java/com/HowTo.java @@ -38,12 +38,12 @@ import com.casper.sdk.model.transfer.TransferData; import com.casper.sdk.model.uref.URef; import com.casper.sdk.service.CasperService; -import com.casper.sdk.service.TransactionTests; import com.syntifi.crypto.key.AbstractPublicKey; import com.syntifi.crypto.key.Ed25519PrivateKey; import dev.oak3.sbs4j.exception.ValueSerializationException; import org.apache.cxf.helpers.IOUtils; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -66,6 +66,7 @@ /** * @author carl@stormeye.co.uk */ +@Disabled public class HowTo { private CasperService casperService; @@ -231,8 +232,9 @@ void queryBalanceDetails() { } @Test - /* TODO - When put transaction is working in the SDK */ - void queryGlobalState() {} + /* TODO - When put transaction is working in the SDK */ + void queryGlobalState() { + } @Test @@ -253,7 +255,7 @@ void getAccountInfo() { } @Test - /* TODO: Make it work */ + /* TODO: Make it work */ void getDictionaryItem() throws IOException { final StatusData status = casperService.getStatus(); @@ -433,7 +435,7 @@ private GetTransactionResult waitForTransaction(final TransactionHash hash) thro GetTransactionResult result = null; - while (result == null || result.getExecutionInfo() == null){ + while (result == null || result.getExecutionInfo() == null) { result = casperService.getTransaction(hash); @@ -453,9 +455,4 @@ private GetTransactionResult waitForTransaction(final TransactionHash hash) thro return result; } - - - - - } diff --git a/src/test/java/com/casper/sdk/model/transaction/target/TransactionTargetTest.java b/src/test/java/com/casper/sdk/model/transaction/target/TransactionTargetTest.java new file mode 100644 index 00000000..f1e26e18 --- /dev/null +++ b/src/test/java/com/casper/sdk/model/transaction/target/TransactionTargetTest.java @@ -0,0 +1,126 @@ +package com.casper.sdk.model.transaction.target; + +import com.casper.sdk.exception.NoSuchTypeException; +import com.casper.sdk.model.clvalue.serde.Target; +import com.casper.sdk.model.common.Digest; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.syntifi.crypto.key.encdec.Hex; +import dev.oak3.sbs4j.SerializerBuffer; +import dev.oak3.sbs4j.exception.ValueSerializationException; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.core.Is.is; + +/** + * Unit tests for the {@link TransactionTarget} classes + * + * @author carl@stormeye.co.uk + */ +public class TransactionTargetTest { + + @Test + void transactionNative() throws Exception { + + final String json = "\"Native\""; + final Native nativeTransactionTarget = readJson(json, Native.class); + + assertThat(nativeTransactionTarget.getTarget(), is("Native")); + assertJson(nativeTransactionTarget, json); + assertBytes(nativeTransactionTarget, "00"); + } + + @Test + void transactionSession() throws Exception { + + final String json = "{\"Session\":{\"module_bytes\":\"aab0da01340446cee477f28410f8af5d6e0f3a88fb26c0cafb8d1625f5cc9c10\",\"runtime\":\"VmCasperV2\"}}"; + final Session session = readJson(json, Session.class); + + assertThat(session.getRuntime().name(), is(TransactionRuntime.VM_CASPER_V2.name())); + assertThat(session.getModuleBytes(), is(Hex.decode("aab0da01340446cee477f28410f8af5d6e0f3a88fb26c0cafb8d1625f5cc9c10"))); + assertJson(session, json); + assertBytes(session, "0220000000aab0da01340446cee477f28410f8af5d6e0f3a88fb26c0cafb8d1625f5cc9c1001"); + } + + @Test + void transactionStoredByHash() throws Exception { + + final String json = "{\"Stored\":{\"id\":{\"ByHash\":\"37c80db9d769cb23ab482f44c2e8d8a73d9e24a1801e81d423953b8ba04b275d\"},\"runtime\":\"VmCasperV1\"}}"; + final Stored stored = readJson(json, Stored.class); + + assertThat(stored.getRuntime().name(), is(TransactionRuntime.VM_CASPER_V1.name())); + assertThat(stored.getId(), is(instanceOf(ByHash.class))); + assertThat(((ByHash) stored.getId()).getHashAddress(), is(new Digest("37c80db9d769cb23ab482f44c2e8d8a73d9e24a1801e81d423953b8ba04b275d"))); + assertJson(stored, json); + assertBytes(stored, "010037c80db9d769cb23ab482f44c2e8d8a73d9e24a1801e81d423953b8ba04b275d00"); + + } + + @Test + void transactionStoredByName() throws Exception { + + final String json = "{\"Stored\":{\"id\":{\"ByName\":\"mint\"},\"runtime\":\"VmCasperV2\"}}"; + final Stored stored = readJson(json, Stored.class); + + assertThat(stored.getRuntime().name(), is(TransactionRuntime.VM_CASPER_V2.name())); + assertThat(stored.getId(), is(instanceOf(ByName.class))); + assertThat(((ByName) stored.getId()).getName(), is("mint")); + assertJson(stored, json); + assertBytes(stored, "0101040000006d696e7401"); + } + + + @Test + void transactionStoredByPackageHash() throws Exception { + + final String json = "{\"Stored\":{\"id\":{\"ByPackageHash\":{\"addr\":\"4b83ad1c5d842e5af75f5e77c56f11372217d8a5473a380fa9dfa96b8cd4c5e2\",\"version\":10}},\"runtime\":\"VmCasperV2\"}}"; + final Stored stored = readJson(json, Stored.class); + + assertThat(stored.getRuntime().name(), is(TransactionRuntime.VM_CASPER_V2.name())); + assertThat(stored.getId(), is(instanceOf(ByPackageHash.class))); + assertThat( + ((ByPackageHash) stored.getId()).getAddr(), + is(new Digest("4b83ad1c5d842e5af75f5e77c56f11372217d8a5473a380fa9dfa96b8cd4c5e2")) + ); + assertThat(((ByPackageHash) stored.getId()).getVersion().isPresent(), is(true)); + assertThat(((ByPackageHash) stored.getId()).getVersion().get(), is(10L)); + + assertJson(stored, json); + + assertBytes(stored, "01024b83ad1c5d842e5af75f5e77c56f11372217d8a5473a380fa9dfa96b8cd4c5e2010a00000001"); + } + + @Test + void transactionStoredByPackageName() throws Exception { + + final String json = "{\"Stored\":{\"id\":{\"ByPackageName\":{\"name\":\"My Package\",\"version\":61523598}},\"runtime\":\"VmCasperV1\"}}"; + final Stored stored = readJson(json, Stored.class); + + assertThat(stored.getRuntime().name(), is(TransactionRuntime.VM_CASPER_V1.name())); + assertThat(stored.getId(), is(instanceOf(ByPackageName.class))); + assertThat(((ByPackageName) stored.getId()).getName(), is("My Package")); + assertThat(((ByPackageName) stored.getId()).getVersion().isPresent(), is(true)); + assertThat(((ByPackageName) stored.getId()).getVersion().get(), is(61523598L)); + assertJson(stored, json); + assertBytes(stored, "01030a0000004d79205061636b616765018ec6aa0300"); + } + + private static T readJson(final String json, final Class expectedClass) throws JsonProcessingException { + TransactionTarget target = new ObjectMapper().readValue(json, TransactionTarget.class); + assertThat(target, is(instanceOf(expectedClass))); + //noinspection unchecked + return (T) target; + } + + private static void assertJson(final TransactionTarget stored, final String expectedJson) throws JsonProcessingException { + assertThat(new ObjectMapper().writeValueAsString(stored), is(expectedJson)); + } + + void assertBytes(final TransactionTarget transactionTarget, final String expectedHexBytes) throws NoSuchTypeException, ValueSerializationException { + final SerializerBuffer serializerBuffer = new SerializerBuffer(); + transactionTarget.serialize(serializerBuffer, Target.BYTE); + assertThat(Hex.encode(serializerBuffer.toByteArray()), is(expectedHexBytes)); + } +} diff --git a/src/test/java/com/casper/sdk/model/transaction/transactiontarget/TransactionTargetTest.java b/src/test/java/com/casper/sdk/model/transaction/transactiontarget/TransactionTargetTest.java deleted file mode 100644 index 9cb446ab..00000000 --- a/src/test/java/com/casper/sdk/model/transaction/transactiontarget/TransactionTargetTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.casper.sdk.model.transaction.transactiontarget; - -import com.casper.sdk.model.transaction.target.Native; -import com.casper.sdk.model.transaction.target.Session; -import com.casper.sdk.model.transaction.target.TransactionRuntime; -import com.casper.sdk.model.transaction.target.TransactionTarget; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.syntifi.crypto.key.encdec.Hex; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -/** - * @author carl@stormeye.co.uk - */ -public class TransactionTargetTest { - - @Test - void transactionNative() throws JsonProcessingException { - - final String json = "\"Native\""; - - final TransactionTarget nativeTransactionTarget = new ObjectMapper().readValue(json, TransactionTarget.class); - - assertThat(nativeTransactionTarget, is(instanceOf(Native.class))); - - final Native nativeType = (Native) nativeTransactionTarget; - - assertThat(nativeType.getTarget(), is("Native")); - - assertThat(new ObjectMapper().writeValueAsString(nativeTransactionTarget), is(json)); - } - - @Test - void transactionSession() throws JsonProcessingException { - - final String json = "{\"Session\":{\"module_bytes\":\"aab0da01340446cee477f28410f8af5d6e0f3a88fb26c0cafb8d1625f5cc9c10\",\"runtime\":\"VmCasperV2\"}}"; - - final TransactionTarget sessionTransactionTarget = new ObjectMapper().readValue(json, TransactionTarget.class); - - assertThat(sessionTransactionTarget, is(instanceOf(Session.class))); - final Session session = (Session) sessionTransactionTarget; - - assertThat(session.getRuntime().name(), is(TransactionRuntime.VM_CASPER_V2.name())); - assertThat(session.getModuleBytes(), is(Hex.decode("aab0da01340446cee477f28410f8af5d6e0f3a88fb26c0cafb8d1625f5cc9c10"))); - - assertThat(new ObjectMapper().writeValueAsString(session), is(json)); - - } - - @Test - void transactionStored() {} - -} diff --git a/src/test/java/com/casper/sdk/service/TransactionTests.java b/src/test/java/com/casper/sdk/service/TransactionTests.java index 87cedbe3..4a745ab8 100644 --- a/src/test/java/com/casper/sdk/service/TransactionTests.java +++ b/src/test/java/com/casper/sdk/service/TransactionTests.java @@ -22,6 +22,7 @@ import com.syntifi.crypto.key.Ed25519PrivateKey; import dev.oak3.sbs4j.exception.ValueSerializationException; import org.apache.cxf.helpers.IOUtils; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -44,7 +45,7 @@ * * @author ian@meywood.com */ -//@Disabled +@Disabled public class TransactionTests { @Test