Skip to content

Commit

Permalink
Added module io-hotmoka-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed Sep 15, 2023
1 parent 7a3b5e1 commit 8fbb246
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 146 deletions.
7 changes: 6 additions & 1 deletion io-hotmoka-crypto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-testing</artifactId>
<version>${hotmoka.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@

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

import java.io.IOException;
import java.net.URL;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.logging.LogManager;

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

import io.hotmoka.crypto.SignatureAlgorithms;
import io.hotmoka.crypto.api.SignatureAlgorithm;
import io.hotmoka.testing.AbstractLoggedTests;

public class QTESLA1 {
public class QTESLA1 extends AbstractLoggedTests {
private final String data = "HELLO QTESLA SCHEME";

@Test
Expand Down Expand Up @@ -69,19 +67,4 @@ void testEncodedPublicKey() throws Exception {
assertTrue(isCorruptedDataWithEncodedKey, "corrupted data is verified with the encoded key");
assertTrue(keyPair.getPublic().equals(publicKey), "the public keys do not match");
}

static {
String current = System.getProperty("java.util.logging.config.file");
if (current == null) {
// if the property is not set, we provide a default (if it exists)
URL resource = QTESLA1.class.getClassLoader().getResource("logging.properties");
if (resource != null)
try (var is = resource.openStream()) {
LogManager.getLogManager().readConfiguration(is);
}
catch (SecurityException | IOException e) {
throw new RuntimeException("Cannot load logging.properties file", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@

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

import java.io.IOException;
import java.net.URL;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.logging.LogManager;

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

import io.hotmoka.crypto.SignatureAlgorithms;
import io.hotmoka.crypto.api.SignatureAlgorithm;
import io.hotmoka.testing.AbstractLoggedTests;

public class QTESLA3 {
public class QTESLA3 extends AbstractLoggedTests {
private final String data = "HELLO QTESLA SCHEME";

@Test
Expand Down Expand Up @@ -69,19 +67,4 @@ void testEncodedPublicKey() throws Exception {
assertTrue(isCorruptedDataWithEncodedKey, "corrupted data is verified with the encoded key");
assertTrue(keyPair.getPublic().equals(publicKey), "the public keys do not match");
}

static {
String current = System.getProperty("java.util.logging.config.file");
if (current == null) {
// if the property is not set, we provide a default (if it exists)
URL resource = QTESLA3.class.getClassLoader().getResource("logging.properties");
if (resource != null)
try (var is = resource.openStream()) {
LogManager.getLogManager().readConfiguration(is);
}
catch (SecurityException | IOException e) {
throw new RuntimeException("Cannot load logging.properties file", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@

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

import java.io.IOException;
import java.net.URL;
import java.util.function.Function;
import java.util.logging.LogManager;

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

import io.hotmoka.crypto.HashingAlgorithms;
import io.hotmoka.testing.AbstractLoggedTests;

public class SHABAL256vsSHA256 {
public class SHABAL256vsSHA256 extends AbstractLoggedTests {

@Test
@DisplayName("10,000,000 iterated sha256")
Expand Down Expand Up @@ -59,19 +57,4 @@ void iteratedSHABAL256() throws Exception {

assertArrayEquals(new byte[] { -110, -11, 92, -50, 122, 2, 38, -72, 74, 124, 82, -29, -9, 122, 63, 3, -27, -127, 35, -30, 8, -11, -39, 87, -90, -97, -118, 14, 29, 45, 62, 91 }, data);
}

static {
String current = System.getProperty("java.util.logging.config.file");
if (current == null) {
// if the property is not set, we provide a default (if it exists)
URL resource = SHABAL256vsSHA256.class.getClassLoader().getResource("logging.properties");
if (resource != null)
try (var is = resource.openStream()) {
LogManager.getLogManager().readConfiguration(is);
}
catch (SecurityException | IOException e) {
throw new RuntimeException("Cannot load logging.properties file", e);
}
}
}
}
8 changes: 0 additions & 8 deletions io-hotmoka-crypto/src/test/resources/logging.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static InitializedNode of(Node parent, ValidatorsConsensusConfig consensu
/**
* An algorithm that yields an object in the store of a node, given
* the node and the reference to the basic classes in its store.
*
* @param <C> the type of the consensus parameters of the node
*/
public interface ProducerOfStorageObject<C extends ConsensusConfig> {

Expand Down
8 changes: 7 additions & 1 deletion io-hotmoka-instrumentation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@
<artifactId>io-takamaka-code</artifactId>
<version>${takamaka.version}</version>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-testing</artifactId>
<version>${hotmoka.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
package io.hotmoka.instrumentation.tests;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.logging.LogManager;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;

import io.hotmoka.constants.Constants;
import io.hotmoka.instrumentation.GasCostModels;
import io.hotmoka.instrumentation.InstrumentedJars;
import io.hotmoka.testing.AbstractLoggedTests;
import io.hotmoka.verification.TakamakaClassLoaders;
import io.hotmoka.verification.UnsupportedVerificationVersionException;
import io.hotmoka.verification.VerificationException;
Expand All @@ -38,7 +37,7 @@
* that translation does not modify static information of the verified jar,
* hence it can be applied twice without exceptions.
*/
class DoubleInstrumentation {
class DoubleInstrumentation extends AbstractLoggedTests {

@Test
void translateTwice() throws IOException, ClassNotFoundException, UnsupportedVerificationVersionException, VerificationException {
Expand All @@ -52,19 +51,4 @@ void translateTwice() throws IOException, ClassNotFoundException, UnsupportedVer
InstrumentedJars.of(verifiedJar, costModel);
InstrumentedJars.of(verifiedJar, costModel);
}

static {
String current = System.getProperty("java.util.logging.config.file");
if (current == null) {
// if the property is not set, we provide a default (if it exists)
URL resource = DoubleInstrumentation.class.getClassLoader().getResource("logging.properties");
if (resource != null)
try (var is = resource.openStream()) {
LogManager.getLogManager().readConfiguration(is);
}
catch (SecurityException | IOException e) {
throw new RuntimeException("Cannot load logging.properties file", e);
}
}
}
}

This file was deleted.

6 changes: 6 additions & 0 deletions io-hotmoka-node/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-crypto</artifactId>
<version>${hotmoka.version}</version>
</dependency>
<dependency>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-testing</artifactId>
<version>${hotmoka.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@

import java.io.IOException;
import java.math.BigInteger;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.NoSuchAlgorithmException;
import java.util.logging.LogManager;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import io.hotmoka.node.ConsensusConfigBuilders;
import io.hotmoka.node.ValidatorsConsensusConfigBuilders;
import io.hotmoka.testing.AbstractLoggedTests;

public class ConsensusConfigTests {
public class ConsensusConfigTests extends AbstractLoggedTests {

@Test
@DisplayName("configs are correctly dumped into TOML and reloaded from TOML")
Expand Down Expand Up @@ -67,19 +66,4 @@ public void validatorsConfigDumpLoadTOMLWorks(@TempDir Path dir) throws IOExcept
var config2 = ValidatorsConsensusConfigBuilders.load(path).build();
assertEquals(config1, config2);
}

static {
String current = System.getProperty("java.util.logging.config.file");
if (current == null) {
// if the property is not set, we provide a default (if it exists)
URL resource = ConsensusConfigTests.class.getClassLoader().getResource("logging.properties");
if (resource != null)
try (var is = resource.openStream()) {
LogManager.getLogManager().readConfiguration(is);
}
catch (SecurityException | IOException e) {
throw new RuntimeException("Cannot load logging.properties file", e);
}
}
}
}
8 changes: 0 additions & 8 deletions io-hotmoka-node/src/test/resources/logging.properties

This file was deleted.

41 changes: 41 additions & 0 deletions io-hotmoka-testing/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>io-hotmoka-testing</artifactId>
<packaging>jar</packaging>
<name>io-hotmoka-testing</name>
<version>${hotmoka.version}</version>
<description>This module implements testing utilities.</description>

<parent>
<groupId>io.hotmoka</groupId>
<artifactId>hotmoka</artifactId>
<version>parent</version>
</parent>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
</dependency>
</dependencies>

<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<configuration>
<skipNexusStagingDeployMojo>false</skipNexusStagingDeployMojo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2023 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.testing;

import io.hotmoka.testing.internal.LoggedTestsImpl;

/**
* Shared code of test classes. It configures the logging system in such a way
* to log each test class in its own log file and to report a header before the logs of each test.
* Test classes just need to subclass this class in order to use these features.
*/
public abstract class AbstractLoggedTests extends LoggedTestsImpl {
}
Loading

0 comments on commit 8fbb246

Please sign in to comment.