From 3578868c8d69f7d6a1c9bab8dba57176f4f169a8 Mon Sep 17 00:00:00 2001 From: Fausto Spoto Date: Sun, 21 Jan 2024 11:49:47 +0100 Subject: [PATCH] Added JSON encoding for transaction requests --- io-hotmoka-beans/pom.xml | 23 +- .../beans/BeanMarshallingContexts.java | 3 +- .../beans/BeanUnmarshallingContexts.java | 3 +- .../io/hotmoka/beans/TransactionRequests.java | 20 +- .../gson/TransactionRequestDecoder.java | 31 ++ .../gson/TransactionRequestEncoder.java | 31 ++ .../internal/gson/TransactionRequestJson.java | 266 ++++++++++++++++++ .../marshalling}/BeanMarshallingContext.java | 2 +- .../BeanUnmarshallingContext.java | 2 +- .../FieldSignatureMarshaller.java | 2 +- .../FieldSignatureUnmarshaller.java | 2 +- .../StorageReferenceMarshaller.java | 2 +- .../StorageReferenceUnmarshaller.java | 2 +- .../TransactionReferenceMarshaller.java | 2 +- .../TransactionReferenceUnmarshaller.java | 2 +- .../references/TransactionReferenceImpl.java | 2 +- .../CodeExecutionTransactionRequestImpl.java | 2 +- .../JarStoreTransactionRequestImpl.java | 2 +- .../MethodCallTransactionRequestImpl.java | 2 +- .../requests/TransactionRequestImpl.java | 2 +- .../responses/TransactionResponseImpl.java | 2 +- .../signatures/AbstractCodeSignature.java | 2 +- .../signatures/FieldSignatureImpl.java | 2 +- .../internal/updates/AbstractUpdate.java | 2 +- .../internal/values/AbstractStorageValue.java | 2 +- .../internal/values/StorageReferenceImpl.java | 2 +- .../src/main/java/module-info.java | 1 + .../beans/tests/TransactionRequestTests.java | 155 ++++++++++ .../java/io/hotmoka/tests/Marshallable.java | 2 +- 29 files changed, 532 insertions(+), 41 deletions(-) create mode 100644 io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestDecoder.java create mode 100644 io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestEncoder.java create mode 100644 io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestJson.java rename io-hotmoka-beans/src/main/java/io/hotmoka/beans/{marshalling/internal => internal/marshalling}/BeanMarshallingContext.java (96%) rename io-hotmoka-beans/src/main/java/io/hotmoka/beans/{marshalling/internal => internal/marshalling}/BeanUnmarshallingContext.java (96%) rename io-hotmoka-beans/src/main/java/io/hotmoka/beans/{marshalling/internal => internal/marshalling}/FieldSignatureMarshaller.java (97%) rename io-hotmoka-beans/src/main/java/io/hotmoka/beans/{marshalling/internal => internal/marshalling}/FieldSignatureUnmarshaller.java (97%) rename io-hotmoka-beans/src/main/java/io/hotmoka/beans/{marshalling/internal => internal/marshalling}/StorageReferenceMarshaller.java (97%) rename io-hotmoka-beans/src/main/java/io/hotmoka/beans/{marshalling/internal => internal/marshalling}/StorageReferenceUnmarshaller.java (97%) rename io-hotmoka-beans/src/main/java/io/hotmoka/beans/{marshalling/internal => internal/marshalling}/TransactionReferenceMarshaller.java (97%) rename io-hotmoka-beans/src/main/java/io/hotmoka/beans/{marshalling/internal => internal/marshalling}/TransactionReferenceUnmarshaller.java (97%) create mode 100644 io-hotmoka-beans/src/test/java/io/hotmoka/beans/tests/TransactionRequestTests.java diff --git a/io-hotmoka-beans/pom.xml b/io-hotmoka-beans/pom.xml index 30c37118a..edf413ae8 100644 --- a/io-hotmoka-beans/pom.xml +++ b/io-hotmoka-beans/pom.xml @@ -24,21 +24,26 @@ io.hotmoka io-hotmoka-constants ${hotmoka.version} + + + io.hotmoka + io-hotmoka-exceptions + ${hotmoka.version} - io.hotmoka - io-hotmoka-crypto - ${hotmoka.version} + io.hotmoka + io-hotmoka-crypto + ${hotmoka.version} - io.hotmoka - io-hotmoka-annotations - ${hotmoka.version} + io.hotmoka + io-hotmoka-annotations + ${hotmoka.version} - io.hotmoka - io-hotmoka-marshalling - ${hotmoka.version} + io.hotmoka + io-hotmoka-marshalling + ${hotmoka.version} io.hotmoka.websockets diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/BeanMarshallingContexts.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/BeanMarshallingContexts.java index fb889e851..4d6666379 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/BeanMarshallingContexts.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/BeanMarshallingContexts.java @@ -19,7 +19,7 @@ import java.io.IOException; import java.io.OutputStream; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.api.MarshallingContext; /** @@ -35,6 +35,7 @@ private BeanMarshallingContexts() {} * * @param oos the stream where bytes are marshalled. * @throws IOException if the context cannot be created + * @return the context */ public static MarshallingContext of(OutputStream oos) throws IOException { return new BeanMarshallingContext(oos); diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/BeanUnmarshallingContexts.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/BeanUnmarshallingContexts.java index d6ed117d9..5754bb817 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/BeanUnmarshallingContexts.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/BeanUnmarshallingContexts.java @@ -20,7 +20,7 @@ import java.io.InputStream; import java.io.OutputStream; -import io.hotmoka.beans.marshalling.internal.BeanUnmarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanUnmarshallingContext; import io.hotmoka.marshalling.api.UnmarshallingContext; /** @@ -37,6 +37,7 @@ private BeanUnmarshallingContexts() {} * * @param is the stream from which bytes get unmarshalled * @throws IOException if the context cannot be created + * @return the context */ public static UnmarshallingContext of(InputStream is) throws IOException { return new BeanUnmarshallingContext(is); diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/TransactionRequests.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/TransactionRequests.java index 2b63d2130..b689e8107 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/TransactionRequests.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/TransactionRequests.java @@ -35,9 +35,9 @@ import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.values.StorageReference; import io.hotmoka.beans.api.values.StorageValue; -import io.hotmoka.beans.internal.gson.TransactionReferenceDecoder; -import io.hotmoka.beans.internal.gson.TransactionReferenceEncoder; -import io.hotmoka.beans.internal.gson.TransactionReferenceJson; +import io.hotmoka.beans.internal.gson.TransactionRequestDecoder; +import io.hotmoka.beans.internal.gson.TransactionRequestEncoder; +import io.hotmoka.beans.internal.gson.TransactionRequestJson; import io.hotmoka.beans.internal.requests.ConstructorCallTransactionRequestImpl; import io.hotmoka.beans.internal.requests.GameteCreationTransactionRequestImpl; import io.hotmoka.beans.internal.requests.InitializationTransactionRequestImpl; @@ -314,7 +314,7 @@ public static TransactionRequest from(UnmarshallingContext context) throws IO /** * Gson encoder. */ - public static class Encoder extends TransactionReferenceEncoder { + public static class Encoder extends TransactionRequestEncoder { /** * Creates a new encoder. @@ -325,7 +325,7 @@ public Encoder() {} /** * Gson decoder. */ - public static class Decoder extends TransactionReferenceDecoder { + public static class Decoder extends TransactionRequestDecoder { /** * Creates a new decoder. @@ -336,15 +336,15 @@ public Decoder() {} /** * Json representation. */ - public static class Json extends TransactionReferenceJson { + public static class Json extends TransactionRequestJson { /** - * Creates the Json representation for the given transaction reference. + * Creates the Json representation for the given transaction request. * - * @param reference the transaction reference + * @param request the transaction request */ - public Json(TransactionReference reference) { - super(reference); + public Json(TransactionRequest request) { + super(request); } } } \ No newline at end of file diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestDecoder.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestDecoder.java new file mode 100644 index 000000000..8f62faa3e --- /dev/null +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestDecoder.java @@ -0,0 +1,31 @@ +/* +Copyright 2024 Fausto Spoto + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.hotmoka.beans.internal.gson; + +import io.hotmoka.beans.TransactionRequests; +import io.hotmoka.beans.api.requests.TransactionRequest; +import io.hotmoka.websockets.beans.MappedDecoder; + +/** + * A decoder for {@link TransactionRequest}. + */ +public class TransactionRequestDecoder extends MappedDecoder, TransactionRequests.Json> { + + public TransactionRequestDecoder() { + super(TransactionRequests.Json.class); + } +} \ No newline at end of file diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestEncoder.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestEncoder.java new file mode 100644 index 000000000..84c68f1e4 --- /dev/null +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestEncoder.java @@ -0,0 +1,31 @@ +/* +Copyright 2024 Fausto Spoto + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.hotmoka.beans.internal.gson; + +import io.hotmoka.beans.TransactionRequests; +import io.hotmoka.beans.api.requests.TransactionRequest; +import io.hotmoka.websockets.beans.MappedEncoder; + +/** + * An encoder for {@link TransactionRequest}. + */ +public class TransactionRequestEncoder extends MappedEncoder, TransactionRequests.Json> { + + public TransactionRequestEncoder() { + super((TransactionRequest request) -> new TransactionRequests.Json(request)); + } +} \ No newline at end of file diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestJson.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestJson.java new file mode 100644 index 000000000..3c554da7c --- /dev/null +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/gson/TransactionRequestJson.java @@ -0,0 +1,266 @@ +/* +Copyright 2024 Fausto Spoto + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.hotmoka.beans.internal.gson; + +import java.math.BigInteger; +import java.util.stream.Stream; + +import io.hotmoka.beans.ConstructorSignatures; +import io.hotmoka.beans.MethodSignatures; +import io.hotmoka.beans.StorageValues; +import io.hotmoka.beans.TransactionReferences; +import io.hotmoka.beans.TransactionRequests; +import io.hotmoka.beans.api.requests.ConstructorCallTransactionRequest; +import io.hotmoka.beans.api.requests.GameteCreationTransactionRequest; +import io.hotmoka.beans.api.requests.InitializationTransactionRequest; +import io.hotmoka.beans.api.requests.InstanceMethodCallTransactionRequest; +import io.hotmoka.beans.api.requests.InstanceSystemMethodCallTransactionRequest; +import io.hotmoka.beans.api.requests.JarStoreInitialTransactionRequest; +import io.hotmoka.beans.api.requests.JarStoreTransactionRequest; +import io.hotmoka.beans.api.requests.StaticMethodCallTransactionRequest; +import io.hotmoka.beans.api.requests.TransactionRequest; +import io.hotmoka.beans.api.transactions.TransactionReference; +import io.hotmoka.beans.api.values.StorageReference; +import io.hotmoka.beans.api.values.StorageValue; +import io.hotmoka.crypto.Hex; +import io.hotmoka.crypto.HexConversionException; +import io.hotmoka.exceptions.CheckSupplier; +import io.hotmoka.exceptions.UncheckFunction; +import io.hotmoka.websockets.beans.api.JsonRepresentation; + +/** + * The JSON representation of a {@link TransactionRequest}. + */ +public abstract class TransactionRequestJson implements JsonRepresentation> { + private final String type; + private final TransactionReferences.Json classpath; + private final BigInteger initialAmount; + private final BigInteger redInitialAmount; + private final String publicKey; + private final StorageValues.Json manifest; + private final String jar; // hex bytes + private final TransactionReferences.Json[] dependencies; + private final StorageValues.Json caller; + private final BigInteger gasLimit; + private final BigInteger gasPrice; + private final BigInteger nonce; + private final String chainId; + private final String signature; // hex bytes + private final StorageValues.Json[] actuals; + private final ConstructorSignatures.Json constructor; + private final MethodSignatures.Json method; + private final StorageValues.Json receiver; + + protected TransactionRequestJson(TransactionRequest request) { + if (request instanceof GameteCreationTransactionRequest gctr) { + this.type = GameteCreationTransactionRequest.class.getSimpleName(); + this.classpath = new TransactionReferences.Json(gctr.getClasspath()); + this.initialAmount = gctr.getInitialAmount(); + this.redInitialAmount = gctr.getRedInitialAmount(); + this.publicKey = gctr.getPublicKey(); + this.manifest = null; + this.jar = null; + this.dependencies = null; + this.caller = null; + this.gasLimit = null; + this.gasPrice = null; + this.nonce = null; + this.chainId = null; + this.signature = null; + this.actuals = null; + this.constructor = null; + this.method = null; + this.receiver = null; + } + else if (request instanceof InitializationTransactionRequest itr) { + this.type = InitializationTransactionRequest.class.getSimpleName(); + this.classpath = new TransactionReferences.Json(itr.getClasspath()); + this.initialAmount = null; + this.redInitialAmount = null; + this.publicKey = null; + this.manifest = new StorageValues.Json(itr.getManifest()); + this.jar = null; + this.dependencies = null; + this.caller = null; + this.gasLimit = null; + this.gasPrice = null; + this.nonce = null; + this.chainId = null; + this.signature = null; + this.actuals = null; + this.constructor = null; + this.method = null; + this.receiver = null; + } + else if (request instanceof JarStoreInitialTransactionRequest jitr) { + this.type = JarStoreInitialTransactionRequest.class.getSimpleName(); + this.classpath = null; + this.initialAmount = null; + this.redInitialAmount = null; + this.publicKey = null; + this.manifest = null; + this.jar = Hex.toHexString(jitr.getJar()); + this.dependencies = jitr.getDependencies().map(TransactionReferences.Json::new).toArray(TransactionReferences.Json[]::new); + this.caller = null; + this.gasLimit = null; + this.gasPrice = null; + this.nonce = null; + this.chainId = null; + this.signature = null; + this.actuals = null; + this.constructor = null; + this.method = null; + this.receiver = null; + } + else if (request instanceof JarStoreTransactionRequest jtr) { + this.type = JarStoreTransactionRequest.class.getSimpleName(); + this.classpath = new TransactionReferences.Json(jtr.getClasspath()); + this.initialAmount = null; + this.redInitialAmount = null; + this.publicKey = null; + this.manifest = null; + this.jar = Hex.toHexString(jtr.getJar()); + this.dependencies = jtr.getDependencies().map(TransactionReferences.Json::new).toArray(TransactionReferences.Json[]::new); + this.caller = new StorageValues.Json(jtr.getCaller()); + this.gasLimit = jtr.getGasLimit(); + this.gasPrice = jtr.getGasPrice(); + this.nonce = jtr.getNonce(); + this.chainId = jtr.getChainId(); + this.signature = Hex.toHexString(jtr.getSignature()); + this.actuals = null; + this.constructor = null; + this.method = null; + this.receiver = null; + } + else if (request instanceof ConstructorCallTransactionRequest cctr) { + this.type = ConstructorCallTransactionRequest.class.getSimpleName(); + this.classpath = new TransactionReferences.Json(cctr.getClasspath()); + this.initialAmount = null; + this.redInitialAmount = null; + this.publicKey = null; + this.manifest = null; + this.jar = null; + this.dependencies = null; + this.caller = new StorageValues.Json(cctr.getCaller()); + this.gasLimit = cctr.getGasLimit(); + this.gasPrice = cctr.getGasPrice(); + this.nonce = cctr.getNonce(); + this.chainId = cctr.getChainId(); + this.signature = Hex.toHexString(cctr.getSignature()); + this.actuals = cctr.actuals().map(StorageValues.Json::new).toArray(StorageValues.Json[]::new); + this.constructor = new ConstructorSignatures.Json(cctr.getStaticTarget()); + this.method = null; + this.receiver = null; + } + else if (request instanceof StaticMethodCallTransactionRequest smctr) { + this.type = StaticMethodCallTransactionRequest.class.getSimpleName(); + this.classpath = new TransactionReferences.Json(smctr.getClasspath()); + this.initialAmount = null; + this.redInitialAmount = null; + this.publicKey = null; + this.manifest = null; + this.jar = null; + this.dependencies = null; + this.caller = new StorageValues.Json(smctr.getCaller()); + this.gasLimit = smctr.getGasLimit(); + this.gasPrice = smctr.getGasPrice(); + this.nonce = smctr.getNonce(); + this.chainId = smctr.getChainId(); + this.signature = Hex.toHexString(smctr.getSignature()); + this.actuals = smctr.actuals().map(StorageValues.Json::new).toArray(StorageValues.Json[]::new); + this.constructor = null; + this.method = new MethodSignatures.Json(smctr.getStaticTarget()); + this.receiver = null; + } + else if (request instanceof InstanceMethodCallTransactionRequest imctr) { + this.type = InstanceMethodCallTransactionRequest.class.getSimpleName(); + this.classpath = new TransactionReferences.Json(imctr.getClasspath()); + this.initialAmount = null; + this.redInitialAmount = null; + this.publicKey = null; + this.manifest = null; + this.jar = null; + this.dependencies = null; + this.caller = new StorageValues.Json(imctr.getCaller()); + this.gasLimit = imctr.getGasLimit(); + this.gasPrice = imctr.getGasPrice(); + this.nonce = imctr.getNonce(); + this.chainId = imctr.getChainId(); + this.signature = Hex.toHexString(imctr.getSignature()); + this.actuals = imctr.actuals().map(StorageValues.Json::new).toArray(StorageValues.Json[]::new); + this.constructor = null; + this.method = new MethodSignatures.Json(imctr.getStaticTarget()); + this.receiver = new StorageValues.Json(imctr.getReceiver()); + } + else if (request instanceof InstanceSystemMethodCallTransactionRequest ismctr) { + this.type = InstanceSystemMethodCallTransactionRequest.class.getSimpleName(); + this.classpath = new TransactionReferences.Json(ismctr.getClasspath()); + this.initialAmount = null; + this.redInitialAmount = null; + this.publicKey = null; + this.manifest = null; + this.jar = null; + this.dependencies = null; + this.caller = new StorageValues.Json(ismctr.getCaller()); + this.gasLimit = ismctr.getGasLimit(); + this.gasPrice = null; + this.nonce = ismctr.getNonce(); + this.chainId = null; + this.signature = null; + this.actuals = ismctr.actuals().map(StorageValues.Json::new).toArray(StorageValues.Json[]::new); + this.constructor = null; + this.method = new MethodSignatures.Json(ismctr.getStaticTarget()); + this.receiver = new StorageValues.Json(ismctr.getReceiver()); + } + else + throw new IllegalArgumentException("Unexpected request of type " + request.getClass().getName()); + } + + @Override + public TransactionRequest unmap() throws IllegalArgumentException, HexConversionException { + if (GameteCreationTransactionRequest.class.getSimpleName().equals(type)) + return TransactionRequests.gameteCreation(classpath.unmap(), initialAmount, redInitialAmount, publicKey); + else if (InitializationTransactionRequest.class.getSimpleName().equals(type)) + return TransactionRequests.initialization(classpath.unmap(), (StorageReference) manifest.unmap()); + else if (JarStoreInitialTransactionRequest.class.getSimpleName().equals(type)) + return TransactionRequests.jarStoreInitial(Hex.fromHexString(jar), convertedDependencies()); + else if (JarStoreTransactionRequest.class.getSimpleName().equals(type)) + return TransactionRequests.jarStore(Hex.fromHexString(signature), (StorageReference) caller.unmap(), nonce, chainId, gasLimit, gasPrice, classpath.unmap(), Hex.fromHexString(jar), convertedDependencies()); + else if (ConstructorCallTransactionRequest.class.getSimpleName().equals(type)) + return TransactionRequests.constructorCall(Hex.fromHexString(signature), (StorageReference) caller.unmap(), nonce, chainId, gasLimit, gasPrice, classpath.unmap(), constructor.unmap(), convertedActuals()); + else if (StaticMethodCallTransactionRequest.class.getSimpleName().equals(type)) + return TransactionRequests.staticMethodCall(Hex.fromHexString(signature), (StorageReference) caller.unmap(), nonce, chainId, gasLimit, gasPrice, classpath.unmap(), method.unmap(), convertedActuals()); + else if (InstanceMethodCallTransactionRequest.class.getSimpleName().equals(type)) + return TransactionRequests.instanceMethodCall(Hex.fromHexString(signature), (StorageReference) caller.unmap(), nonce, chainId, gasLimit, gasPrice, classpath.unmap(), method.unmap(), (StorageReference) receiver.unmap(), convertedActuals()); + else if (InstanceSystemMethodCallTransactionRequest.class.getSimpleName().equals(type)) + return TransactionRequests.instanceSystemMethodCall((StorageReference) caller.unmap(), nonce, gasLimit, classpath.unmap(), method.unmap(), (StorageReference) receiver.unmap(), convertedActuals()); + else + throw new IllegalArgumentException("Unexpected request type " + type); + } + + private TransactionReference[] convertedDependencies() throws HexConversionException { + return CheckSupplier.check(HexConversionException.class, + () -> Stream.of(dependencies).map(UncheckFunction.uncheck(TransactionReferences.Json::unmap)).toArray(TransactionReference[]::new) + ); + } + + private StorageValue[] convertedActuals() throws HexConversionException { + return CheckSupplier.check(HexConversionException.class, + () -> Stream.of(actuals).map(UncheckFunction.uncheck(StorageValues.Json::unmap)).toArray(StorageValue[]::new) + ); + } +} \ No newline at end of file diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/BeanMarshallingContext.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/BeanMarshallingContext.java similarity index 96% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/BeanMarshallingContext.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/BeanMarshallingContext.java index 328b40f77..29195afa9 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/BeanMarshallingContext.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/BeanMarshallingContext.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.marshalling.internal; +package io.hotmoka.beans.internal.marshalling; import java.io.IOException; import java.io.OutputStream; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/BeanUnmarshallingContext.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/BeanUnmarshallingContext.java similarity index 96% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/BeanUnmarshallingContext.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/BeanUnmarshallingContext.java index 9caaf6f81..fbb363036 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/BeanUnmarshallingContext.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/BeanUnmarshallingContext.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.marshalling.internal; +package io.hotmoka.beans.internal.marshalling; import java.io.IOException; import java.io.InputStream; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/FieldSignatureMarshaller.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/FieldSignatureMarshaller.java similarity index 97% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/FieldSignatureMarshaller.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/FieldSignatureMarshaller.java index 0a7bd95c2..610c40d0d 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/FieldSignatureMarshaller.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/FieldSignatureMarshaller.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.marshalling.internal; +package io.hotmoka.beans.internal.marshalling; import java.io.IOException; import java.util.HashMap; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/FieldSignatureUnmarshaller.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/FieldSignatureUnmarshaller.java similarity index 97% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/FieldSignatureUnmarshaller.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/FieldSignatureUnmarshaller.java index 03372e9f8..a6ab88c4f 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/FieldSignatureUnmarshaller.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/FieldSignatureUnmarshaller.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.marshalling.internal; +package io.hotmoka.beans.internal.marshalling; import java.io.IOException; import java.util.HashMap; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/StorageReferenceMarshaller.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/StorageReferenceMarshaller.java similarity index 97% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/StorageReferenceMarshaller.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/StorageReferenceMarshaller.java index 5d902483a..f241b2751 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/StorageReferenceMarshaller.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/StorageReferenceMarshaller.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.marshalling.internal; +package io.hotmoka.beans.internal.marshalling; import java.io.IOException; import java.util.HashMap; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/StorageReferenceUnmarshaller.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/StorageReferenceUnmarshaller.java similarity index 97% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/StorageReferenceUnmarshaller.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/StorageReferenceUnmarshaller.java index 52fbf8832..55cce7dff 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/StorageReferenceUnmarshaller.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/StorageReferenceUnmarshaller.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.marshalling.internal; +package io.hotmoka.beans.internal.marshalling; import java.io.IOException; import java.util.HashMap; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/TransactionReferenceMarshaller.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/TransactionReferenceMarshaller.java similarity index 97% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/TransactionReferenceMarshaller.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/TransactionReferenceMarshaller.java index 73d53f6d0..b9eb999b3 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/TransactionReferenceMarshaller.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/TransactionReferenceMarshaller.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.marshalling.internal; +package io.hotmoka.beans.internal.marshalling; import java.io.IOException; import java.util.HashMap; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/TransactionReferenceUnmarshaller.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/TransactionReferenceUnmarshaller.java similarity index 97% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/TransactionReferenceUnmarshaller.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/TransactionReferenceUnmarshaller.java index 797135a97..742a50499 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/marshalling/internal/TransactionReferenceUnmarshaller.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/marshalling/TransactionReferenceUnmarshaller.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.marshalling.internal; +package io.hotmoka.beans.internal.marshalling; import java.io.IOException; import java.util.HashMap; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/references/TransactionReferenceImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/references/TransactionReferenceImpl.java index 0b4041713..80c87e3ff 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/references/TransactionReferenceImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/references/TransactionReferenceImpl.java @@ -21,7 +21,7 @@ import java.util.Arrays; import io.hotmoka.beans.api.transactions.TransactionReference; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.crypto.Hex; import io.hotmoka.crypto.HexConversionException; import io.hotmoka.marshalling.AbstractMarshallable; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/CodeExecutionTransactionRequestImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/CodeExecutionTransactionRequestImpl.java index 49bc368a7..772d9ac88 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/CodeExecutionTransactionRequestImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/CodeExecutionTransactionRequestImpl.java @@ -29,7 +29,7 @@ import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.values.StorageReference; import io.hotmoka.beans.api.values.StorageValue; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.api.MarshallingContext; /** diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/JarStoreTransactionRequestImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/JarStoreTransactionRequestImpl.java index 7ba8e404e..05b645171 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/JarStoreTransactionRequestImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/JarStoreTransactionRequestImpl.java @@ -32,7 +32,7 @@ import io.hotmoka.beans.api.responses.JarStoreTransactionResponse; import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.values.StorageReference; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.crypto.Hex; import io.hotmoka.crypto.api.Signer; import io.hotmoka.marshalling.api.MarshallingContext; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/MethodCallTransactionRequestImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/MethodCallTransactionRequestImpl.java index 38d594961..26cc6e66b 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/MethodCallTransactionRequestImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/MethodCallTransactionRequestImpl.java @@ -63,7 +63,7 @@ protected MethodCallTransactionRequestImpl(StorageReference caller, BigInteger n this.method = Objects.requireNonNull(method, "method cannot be null"); if (method.getFormals().count() != actuals.length) - throw new IllegalArgumentException("Argument count mismatch between formals and actuals"); + throw new IllegalArgumentException("Argument count mismatch: " + method.getFormals().count() + " formals and " + actuals.length + " actuals"); } @Override diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/TransactionRequestImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/TransactionRequestImpl.java index 505d9cfd2..b787afdc4 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/TransactionRequestImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/requests/TransactionRequestImpl.java @@ -22,7 +22,7 @@ import io.hotmoka.annotations.Immutable; import io.hotmoka.beans.api.requests.TransactionRequest; import io.hotmoka.beans.api.responses.TransactionResponse; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.AbstractMarshallable; import io.hotmoka.marshalling.api.MarshallingContext; import io.hotmoka.marshalling.api.UnmarshallingContext; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/TransactionResponseImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/TransactionResponseImpl.java index 0c15c1c2f..209c1078b 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/TransactionResponseImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/TransactionResponseImpl.java @@ -20,7 +20,7 @@ import java.io.OutputStream; import io.hotmoka.beans.api.responses.TransactionResponse; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.AbstractMarshallable; import io.hotmoka.marshalling.api.MarshallingContext; import io.hotmoka.marshalling.api.UnmarshallingContext; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/signatures/AbstractCodeSignature.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/signatures/AbstractCodeSignature.java index 7c9d21fbc..67d2ff7b0 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/signatures/AbstractCodeSignature.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/signatures/AbstractCodeSignature.java @@ -27,7 +27,7 @@ import io.hotmoka.beans.api.signatures.CodeSignature; import io.hotmoka.beans.api.types.ClassType; import io.hotmoka.beans.api.types.StorageType; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.AbstractMarshallable; import io.hotmoka.marshalling.api.MarshallingContext; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/signatures/FieldSignatureImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/signatures/FieldSignatureImpl.java index ac6b3db81..0339df736 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/signatures/FieldSignatureImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/signatures/FieldSignatureImpl.java @@ -26,7 +26,7 @@ import io.hotmoka.beans.api.signatures.FieldSignature; import io.hotmoka.beans.api.types.ClassType; import io.hotmoka.beans.api.types.StorageType; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.constants.Constants; import io.hotmoka.marshalling.AbstractMarshallable; import io.hotmoka.marshalling.api.MarshallingContext; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/updates/AbstractUpdate.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/updates/AbstractUpdate.java index fd4b07bab..59a976882 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/updates/AbstractUpdate.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/updates/AbstractUpdate.java @@ -30,7 +30,7 @@ import io.hotmoka.beans.api.types.ClassType; import io.hotmoka.beans.api.updates.Update; import io.hotmoka.beans.api.values.StorageReference; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.AbstractMarshallable; import io.hotmoka.marshalling.api.MarshallingContext; import io.hotmoka.marshalling.api.UnmarshallingContext; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/values/AbstractStorageValue.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/values/AbstractStorageValue.java index a2b102313..392c1d98e 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/values/AbstractStorageValue.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/values/AbstractStorageValue.java @@ -25,7 +25,7 @@ import io.hotmoka.beans.api.types.ClassType; import io.hotmoka.beans.api.types.StorageType; import io.hotmoka.beans.api.values.StorageValue; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.AbstractMarshallable; import io.hotmoka.marshalling.api.MarshallingContext; import io.hotmoka.marshalling.api.UnmarshallingContext; diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/values/StorageReferenceImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/values/StorageReferenceImpl.java index f303b6ec3..37abbe32c 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/values/StorageReferenceImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/values/StorageReferenceImpl.java @@ -27,7 +27,7 @@ import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.values.StorageReference; import io.hotmoka.beans.api.values.StorageValue; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.api.MarshallingContext; import io.hotmoka.marshalling.api.UnmarshallingContext; diff --git a/io-hotmoka-beans/src/main/java/module-info.java b/io-hotmoka-beans/src/main/java/module-info.java index 9a94131bc..3eed8f96e 100644 --- a/io-hotmoka-beans/src/main/java/module-info.java +++ b/io-hotmoka-beans/src/main/java/module-info.java @@ -28,6 +28,7 @@ requires io.hotmoka.constants; requires io.hotmoka.crypto; requires io.hotmoka.annotations; + requires io.hotmoka.exceptions; requires io.hotmoka.websockets.beans; requires com.google.gson; } \ No newline at end of file diff --git a/io-hotmoka-beans/src/test/java/io/hotmoka/beans/tests/TransactionRequestTests.java b/io-hotmoka-beans/src/test/java/io/hotmoka/beans/tests/TransactionRequestTests.java new file mode 100644 index 000000000..022083a8c --- /dev/null +++ b/io-hotmoka-beans/src/test/java/io/hotmoka/beans/tests/TransactionRequestTests.java @@ -0,0 +1,155 @@ +/* +Copyright 2024 Fausto Spoto + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.hotmoka.beans.tests; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SignatureException; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import io.hotmoka.beans.ConstructorSignatures; +import io.hotmoka.beans.MethodSignatures; +import io.hotmoka.beans.StorageTypes; +import io.hotmoka.beans.StorageValues; +import io.hotmoka.beans.TransactionReferences; +import io.hotmoka.beans.TransactionRequests; +import io.hotmoka.beans.api.requests.SignedTransactionRequest; +import io.hotmoka.beans.api.transactions.TransactionReference; +import io.hotmoka.beans.api.values.StorageReference; +import io.hotmoka.crypto.Base64; +import io.hotmoka.crypto.SignatureAlgorithms; +import io.hotmoka.crypto.api.Signer; +import io.hotmoka.testing.AbstractLoggedTests; +import jakarta.websocket.DecodeException; +import jakarta.websocket.EncodeException; + +public class TransactionRequestTests extends AbstractLoggedTests { + + private final static TransactionReference classpath = TransactionReferences.of("cafebabe01234567cafebabe01234567cafebabe01234567cafebabe01234567"); + private final static TransactionReference reference = TransactionReferences.of("01234567cafebabe01234567cafebabe01234567cafebabe01234567cafebabe"); + private final static TransactionReference reference2 = TransactionReferences.of("a1234567cafebabe01234567cafebabe01234567cafebabe01234567cafebabe"); + private final static TransactionReference reference3 = TransactionReferences.of("b1234567cafebabe01234567cafebabe01234567cafebabe01234567cafebabe"); + private final static StorageReference caller = StorageValues.reference(reference, BigInteger.TWO); + private final static byte[] jar = "Imagine this to be a very beautiful jar file".getBytes(); + private final static Signer> signer; + private final static BigInteger nonce = BigInteger.valueOf(1317); + private final static BigInteger gasLimit = BigInteger.valueOf(1987); + private final static BigInteger gasPrice = BigInteger.valueOf(200); + private final static String chainId = "marabunta"; + + static { + try { + signer = SignatureAlgorithms.ed25519().getSigner(SignatureAlgorithms.ed25519().getKeyPair().getPrivate(), SignedTransactionRequest::toByteArrayWithoutSignature); + } + catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + + @Test + @DisplayName("gamete creation transaction requests are correctly encoded into Json and decoded from Json") + public void encodeDecodeWorksForGameteCreationTransactionRequest() throws EncodeException, DecodeException, NoSuchAlgorithmException { + String publicKey = Base64.toBase64String(SignatureAlgorithms.ed25519().getKeyPair().getPublic().getEncoded()); + var request1 = TransactionRequests.gameteCreation(classpath, BigInteger.TWO, BigInteger.TEN, publicKey); + String encoded = new TransactionRequests.Encoder().encode(request1); + var request2 = new TransactionRequests.Decoder().decode(encoded); + assertEquals(request1, request2); + } + + @Test + @DisplayName("initialization transaction requests are correctly encoded into Json and decoded from Json") + public void encodeDecodeWorksForInitializationTransactionRequest() throws EncodeException, DecodeException { + var manifest = StorageValues.reference(reference, BigInteger.ONE); + var request1 = TransactionRequests.initialization(classpath, manifest); + String encoded = new TransactionRequests.Encoder().encode(request1); + var request2 = new TransactionRequests.Decoder().decode(encoded); + assertEquals(request1, request2); + } + + @Test + @DisplayName("jar store initial transaction requests are correctly encoded into Json and decoded from Json") + public void encodeDecodeWorksForJarStoreInitialTransactionRequest() throws EncodeException, DecodeException { + var request1 = TransactionRequests.jarStoreInitial(jar, reference, reference2, reference3); + String encoded = new TransactionRequests.Encoder().encode(request1); + var request2 = new TransactionRequests.Decoder().decode(encoded); + assertEquals(request1, request2); + } + + @Test + @DisplayName("jar store transaction requests are correctly encoded into Json and decoded from Json") + public void encodeDecodeWorksForJarStoreTransactionRequest() throws EncodeException, DecodeException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + var request1 = TransactionRequests.jarStore(signer, caller, nonce, chainId, gasLimit, gasPrice, classpath, jar, reference, reference2, reference3); + String encoded = new TransactionRequests.Encoder().encode(request1); + var request2 = new TransactionRequests.Decoder().decode(encoded); + assertEquals(request1, request2); + } + + @Test + @DisplayName("constructor call transaction requests are correctly encoded into Json and decoded from Json") + public void encodeDecodeWorksForConstructorCallTransactionRequest() throws EncodeException, DecodeException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + var constructor = ConstructorSignatures.of("io.hotmoka.MyClass", StorageTypes.INT, StorageTypes.named("io.hotmoka.OtherClass")); + var value1 = StorageValues.intOf(13); + var value2 = StorageValues.reference(reference2, BigInteger.ZERO); + var request1 = TransactionRequests.constructorCall(signer, caller, nonce, chainId, gasLimit, gasPrice, classpath, constructor, value1, value2); + String encoded = new TransactionRequests.Encoder().encode(request1); + var request2 = new TransactionRequests.Decoder().decode(encoded); + assertEquals(request1, request2); + } + + @Test + @DisplayName("static method call transaction requests are correctly encoded into Json and decoded from Json") + public void encodeDecodeWorksForStaticMethodCallTransactionRequest() throws EncodeException, DecodeException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + var method = MethodSignatures.of("io.hotmoka.MyClass", "moo", StorageTypes.BOOLEAN, StorageTypes.INT, StorageTypes.named("io.hotmoka.OtherClass")); + var value1 = StorageValues.intOf(13); + var value2 = StorageValues.reference(reference2, BigInteger.ZERO); + var request1 = TransactionRequests.staticMethodCall(signer, caller, nonce, chainId, gasLimit, gasPrice, classpath, method, value1, value2); + String encoded = new TransactionRequests.Encoder().encode(request1); + var request2 = new TransactionRequests.Decoder().decode(encoded); + assertEquals(request1, request2); + } + + @Test + @DisplayName("instance method call transaction requests are correctly encoded into Json and decoded from Json") + public void encodeDecodeWorksForInstanceMethodCallTransactionRequest() throws EncodeException, DecodeException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + var method = MethodSignatures.of("io.hotmoka.MyClass", "moo", StorageTypes.BOOLEAN, StorageTypes.INT, StorageTypes.named("io.hotmoka.OtherClass")); + var value1 = StorageValues.intOf(13); + var value2 = StorageValues.reference(reference2, BigInteger.ZERO); + var receiver = StorageValues.reference(reference2, BigInteger.valueOf(17)); + var request1 = TransactionRequests.instanceMethodCall(signer, caller, nonce, chainId, gasLimit, gasPrice, classpath, method, receiver, value1, value2); + String encoded = new TransactionRequests.Encoder().encode(request1); + var request2 = new TransactionRequests.Decoder().decode(encoded); + assertEquals(request1, request2); + } + + @Test + @DisplayName("instance system method call transaction requests are correctly encoded into Json and decoded from Json") + public void encodeDecodeWorksForInstanceSystemMethodCallTransactionRequest() throws EncodeException, DecodeException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + var method = MethodSignatures.of("io.hotmoka.MyClass", "moo", StorageTypes.BOOLEAN, StorageTypes.INT, StorageTypes.named("io.hotmoka.OtherClass")); + var value1 = StorageValues.intOf(13); + var value2 = StorageValues.reference(reference2, BigInteger.ZERO); + var receiver = StorageValues.reference(reference2, BigInteger.valueOf(17)); + var request1 = TransactionRequests.instanceSystemMethodCall(caller, nonce, gasLimit, classpath, method, receiver, value1, value2); + String encoded = new TransactionRequests.Encoder().encode(request1); + var request2 = new TransactionRequests.Decoder().decode(encoded); + assertEquals(request1, request2); + } +} \ No newline at end of file diff --git a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/Marshallable.java b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/Marshallable.java index 122949f1d..562c3246c 100644 --- a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/Marshallable.java +++ b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/Marshallable.java @@ -23,7 +23,7 @@ import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.values.StorageReference; import io.hotmoka.beans.api.values.StorageValue; -import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext; +import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext; import io.hotmoka.marshalling.MarshallingContexts; public class Marshallable {