Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public String getName() {
return service.getName();
}

public Service getService() {
return service;
}

/**
* Converts a transaction messages into an executable transaction of this service.
*
Expand Down
1 change: 1 addition & 0 deletions exonum-java-binding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<module>service-archetype</module>
<module>time-oracle</module>
<module>packaging</module>
<module>testkit</module>
</modules>

<scm>
Expand Down
66 changes: 66 additions & 0 deletions exonum-java-binding/testkit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.exonum.binding</groupId>
<artifactId>exonum-java-binding-parent</artifactId>
<version>0.6.0-SNAPSHOT</version>
</parent>

<artifactId>exonum-testkit</artifactId>
<version>0.6.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Exonum TestKit</name>
<url>https://exonum.com/doc/version/latest/get-started/test-service/</url>

<properties>
<ejb-core.nativeLibPath>${project.parent.basedir}/core/rust/target/debug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since #818 it must be slightly different, @vitvakatu can advise

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay, as we don't have tests with release mode at the moment

</ejb-core.nativeLibPath>
</properties>

<dependencies>
<dependency>
<groupId>com.exonum.binding</groupId>
<artifactId>exonum-java-binding-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
${jacoco.args}
-Djava.library.path=${ejb-core.nativeLibPath}
${java.vm.assertionFlag}
</argLine>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2019 The Exonum Team
*
* 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 com.exonum.binding.testkit;

import com.exonum.binding.common.crypto.KeyPair;
import java.util.OptionalInt;

/**
* Context of the TestKit emulated node.
*/
public class EmulatedNode {

private final OptionalInt validatorId;
private final KeyPair serviceKeyPair;
private final KeyPair consensusKeyPair;

public EmulatedNode(int validatorId, KeyPair serviceKeyPair, KeyPair consensusKeyPair) {
this.validatorId = validatorId >= 0
? OptionalInt.of(validatorId)
: OptionalInt.empty();
this.serviceKeyPair = serviceKeyPair;
this.consensusKeyPair = consensusKeyPair;
}

/**
* Returns a node type - either {@link EmulatedNodeType.VALIDATOR} or {@link EmulatedNodeType.AUDITOR}.
*/
public EmulatedNodeType getNodeType() {
return validatorId.isPresent() ? EmulatedNodeType.VALIDATOR : EmulatedNodeType.AUDITOR;
}

/**
* Returns a validator id if this node is a validator or {@link OptionalInt.EMPTY} is this is a validator node.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if an auditor node.

*/
public OptionalInt getValidatorId() {
return validatorId;
}

/**
* Returns a service key pair of this node.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a good place to link in this case (Node#getPublicKey — but it only returns the public key;
Node#submitTransaction — it signs a transaction with the service public key; or ValidatorKey#consensusKey — but its
documentation is not particularly detailed).

At least, I'd add here in which operations this key pair is used, e.g., "This key pair is used to sign transactions {@linkplain Node#submitTransaction produced} by the service itself".

*/
public KeyPair getServiceKeyPair() {
return serviceKeyPair;
}

/**
* Returns a consensus key pair of this node.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add that this key pair is used to sign consensus message of this node.

*/
public KeyPair getConsensusKeyPair() {
return consensusKeyPair;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2019 The Exonum Team
*
* 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 com.exonum.binding.testkit;

/**
* Type of the TestKit emulated node.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** 
* Type of the Exonum node emulated by TestKit.
*
* @see <a href="https://exonum.com/doc/version/0.10/glossary/#auditor">Auditor Node</a>
*      <a href="https://exonum.com/doc/version/0.10/glossary/#validator">Validator Node</a>
**/

*/
public enum EmulatedNodeType {
VALIDATOR,
AUDITOR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2019 The Exonum Team
*
* 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 com.exonum.binding.testkit;

import java.time.ZonedDateTime;

public class FakeTimeProvider implements TimeProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc is missing. Please describe the purpose of this class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is it decided that it is better to add this just as a placeholder and implement in a separate PR, as originally planned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry for half-introducing classes from other tasks - I wanted native methods signatures to be ready for native tasks, so created these classes as placeholders

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep them as placeholders to avoid redundant work then.


public FakeTimeProvider create(ZonedDateTime time) {
throw new UnsupportedOperationException();
}

public void setTime(ZonedDateTime time) {
throw new UnsupportedOperationException();
}

public void addTime(ZonedDateTime time) {
throw new UnsupportedOperationException();
}

@Override
public ZonedDateTime getTime() {
throw new UnsupportedOperationException();
}
}
Loading