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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis/run_travis_job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ else
# Set CI Maven arguments. They enable parallel builds, and parallel tests (Linux only).
# TODO: Remove this when macos builds use newer JDK that does not hang up when
# parallel tests are enabled.
PARALLEL_TESTS_ENABLED="true"
# TODO: Reenable when the broken testkit tests are fixed: ECR-3797
PARALLEL_TESTS_ENABLED="false"
if [[ ${TRAVIS_OS_NAME} == "osx" ]]; then
PARALLEL_TESTS_ENABLED="false"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ServiceRuntimeBootstrapIntegrationTest {

@Test
void createServiceRuntimeAdapter() {
ServiceRuntimeAdapter serviceRuntimeAdapter = ServiceRuntimeBootstrap.createServiceRuntime("/tmp/", PORT);
ServiceRuntimeAdapter serviceRuntimeAdapter = ServiceRuntimeBootstrap
.createServiceRuntime("/tmp/", PORT);

// Check the runtime is created
assertNotNull(serviceRuntimeAdapter);
Expand Down
6 changes: 3 additions & 3 deletions exonum-java-binding/core/rust/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ mod key_set_index;
mod list_index;
mod map_index;
mod pair_iter;
//mod proof_list_index;
mod proof_list_index;
mod proof_map_index;
mod temporarydb;
mod value_set_index;

//pub use self::core_schema::*;
pub use self::core_schema::*;
pub use self::db::Java_com_exonum_binding_core_storage_database_Views_nativeFree;
pub(crate) use self::db::View;
pub use self::entry::*;
pub use self::key_set_index::*;
pub use self::list_index::*;
pub use self::map_index::*;
pub use self::pair_iter::PairIter;
//pub use self::proof_list_index::*;
pub use self::proof_list_index::*;
pub use self::proof_map_index::*;
pub use self::temporarydb::*;
pub use self::value_set_index::*;
116 changes: 8 additions & 108 deletions exonum-java-binding/core/rust/src/storage/proof_list_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use exonum::crypto::Hash;
use exonum_merkledb::{
proof_list_index::{ListProof, ProofListIndexIter, ProofOfAbsence},
Fork, ObjectHash, ProofListIndex, Snapshot,
proof_list_index::ProofListIndexIter, Fork, ObjectHash, ProofListIndex, Snapshot,
};
use jni::{
errors::Result,
objects::{JClass, JObject, JString},
sys::{jboolean, jbyteArray, jint, jlong, jobject},
JNIEnv,
Expand Down Expand Up @@ -206,41 +203,30 @@ pub extern "system" fn Java_com_exonum_binding_core_storage_indices_ProofListInd

/// Returns Java representation of the proof that an element exists at the specified index.
#[no_mangle]
// fixme: ECR-3614
#[allow(unused_variables)]
pub extern "system" fn Java_com_exonum_binding_core_storage_indices_ProofListIndexProxy_nativeGetProof(
env: JNIEnv,
_: JObject,
list_handle: Handle,
index: jlong,
) -> jobject {
let res = panic::catch_unwind(|| {
let proof = match *handle::cast_handle::<IndexType>(list_handle) {
IndexType::SnapshotIndex(ref list) => list.get_proof(index as u64),
IndexType::ForkIndex(ref list) => list.get_proof(index as u64),
};
let length = get_list_length(list_handle);
make_java_proof_root(&env, &proof, length).map(|x| x.into_inner())
});
utils::unwrap_exc_or(&env, res, ptr::null_mut())
ptr::null_mut()
}

/// Returns Java representation of the proof that some elements exists in the specified range.
#[no_mangle]
// fixme: ECR-3614
#[allow(unused_variables)]
pub extern "system" fn Java_com_exonum_binding_core_storage_indices_ProofListIndexProxy_nativeGetRangeProof(
env: JNIEnv,
_: JObject,
list_handle: Handle,
from: jlong,
to: jlong,
) -> jobject {
let res = panic::catch_unwind(|| {
let proof = match *handle::cast_handle::<IndexType>(list_handle) {
IndexType::SnapshotIndex(ref list) => list.get_range_proof(from as u64..to as u64),
IndexType::ForkIndex(ref list) => list.get_range_proof(from as u64..to as u64),
};
let length = get_list_length(list_handle);
make_java_proof_root(&env, &proof, length).map(|x| x.into_inner())
});
utils::unwrap_exc_or(&env, res, ptr::null_mut())
// fixme: ECR-3614
ptr::null_mut()
}

/// Returns pointer to the iterator over list.
Expand Down Expand Up @@ -368,89 +354,3 @@ pub extern "system" fn Java_com_exonum_binding_core_storage_indices_ProofListInd
) {
handle::drop_handle::<ProofListIndexIter<Value>>(&env, iter_handle);
}

fn make_java_proof_root<'a>(
env: &JNIEnv<'a>,
proof: &ListProof<Value>,
length: u64,
) -> Result<JObject<'a>> {
let root = make_java_proof(env, proof)?;
env.new_object(
"com/exonum/binding/common/proofs/list/UncheckedListProofAdapter",
"(Lcom/exonum/binding/common/proofs/list/ListProofNode;J)V",
&[root.into(), (length as jlong).into()],
)
}

fn make_java_proof<'a>(env: &JNIEnv<'a>, proof: &ListProof<Value>) -> Result<JObject<'a>> {
match *proof {
ListProof::Full(ref left, ref right) => {
let left = make_java_proof(env, left.as_ref())?;
let right = make_java_proof(env, right.as_ref())?;
make_java_proof_branch(env, left, right)
}
ListProof::Left(ref left, ref hash) => {
let left = make_java_proof(env, left.as_ref())?;
let right = hash.map_or(Ok((ptr::null_mut() as jobject).into()), |hash| {
make_java_hash_node(env, &hash)
})?;
make_java_proof_branch(env, left, right)
}
ListProof::Right(ref hash, ref right) => {
let left = make_java_hash_node(env, hash)?;
let right = make_java_proof(env, right.as_ref())?;
make_java_proof_branch(env, left, right)
}
ListProof::Leaf(ref value) => make_java_proof_element(env, value),
ListProof::Absent(ref proof_of_absence) => {
make_java_proof_of_absence(env, proof_of_absence)
}
}
}

// TODO: Remove attribute (https://github.com/rust-lang-nursery/rust-clippy/issues/1981).
#[allow(clippy::ptr_arg)]
fn make_java_proof_element<'a>(env: &JNIEnv<'a>, value: &Value) -> Result<JObject<'a>> {
let value = env.auto_local(env.byte_array_from_slice(value)?.into());
env.new_object(
"com/exonum/binding/common/proofs/list/ListProofElement",
"([B)V",
&[value.as_obj().into()],
)
}

fn make_java_proof_branch<'a>(
env: &JNIEnv<'a>,
left: JObject,
right: JObject,
) -> Result<JObject<'a>> {
let left = env.auto_local(left);
let right = env.auto_local(right);
env.new_object(
"com/exonum/binding/common/proofs/list/ListProofBranch",
"(Lcom/exonum/binding/common/proofs/list/ListProofNode;\
Lcom/exonum/binding/common/proofs/list/ListProofNode;)V",
&[left.as_obj().into(), right.as_obj().into()],
)
}

fn make_java_hash_node<'a>(env: &JNIEnv<'a>, hash: &Hash) -> Result<JObject<'a>> {
let hash = env.auto_local(utils::convert_hash(env, hash)?.into());
env.new_object(
"com/exonum/binding/common/proofs/list/ListProofHashNode",
"([B)V",
&[hash.as_obj().into()],
)
}

fn make_java_proof_of_absence<'a>(
env: &JNIEnv<'a>,
proof_of_absence: &ProofOfAbsence,
) -> Result<JObject<'a>> {
let hash = env.auto_local(utils::convert_hash(env, &proof_of_absence.merkle_root())?.into());
env.new_object(
"com/exonum/binding/common/proofs/list/ListProofOfAbsence",
"([B)V",
&[hash.as_obj().into()],
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.exonum.binding.core.service;

import static com.google.common.base.Preconditions.checkNotNull;

import com.exonum.binding.common.hash.HashCode;
import com.exonum.binding.core.runtime.ServiceInstanceSpec;
import com.exonum.binding.core.storage.database.Snapshot;
import com.exonum.binding.core.storage.database.View;
import java.util.List;
Expand All @@ -26,6 +29,35 @@
*/
public abstract class AbstractService implements Service {

private final ServiceInstanceSpec instanceSpec;

protected AbstractService(ServiceInstanceSpec instanceSpec) {
this.instanceSpec = checkNotNull(instanceSpec);
}

/**
* Returns the name of the service instance.
* @see ServiceInstanceSpec#getName()
*/
protected final String getName() {
return instanceSpec.getName();
}

/**
* Returns the numeric id of the service instance.
* @see ServiceInstanceSpec#getId()
*/
protected final int getId() {
return instanceSpec.getId();
}

/**
* Returns this service instance specification.
*/
protected final ServiceInstanceSpec getInstanceSpec() {
return instanceSpec;
}

@Override
public List<HashCode> getStateHashes(Snapshot snapshot) {
return createDataSchema(snapshot).getStateHashes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.exonum.binding.common.hash.HashCode;
import com.exonum.binding.common.message.TransactionMessage;
import com.exonum.binding.core.blockchain.Blockchain;
import com.exonum.binding.core.runtime.ServiceInstanceSpec;
import com.exonum.binding.core.service.TransactionConverter;
import com.exonum.binding.core.storage.database.Fork;

Expand Down Expand Up @@ -54,13 +55,15 @@ public interface TransactionContext {

/**
* Returns the name of the service instance.
*
* @see ServiceInstanceSpec#getName()
*/
String getServiceName();

/**
* Returns the numeric id of the service instance.
*
* @see TransactionMessage#getServiceId()
* @see ServiceInstanceSpec#getId()
*/
int getServiceId();

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

package com.exonum.binding.core.runtime;

import com.exonum.binding.core.service.AbstractService;
import com.exonum.binding.common.hash.HashCode;
import com.exonum.binding.core.service.Node;
import com.exonum.binding.core.service.Schema;
import com.exonum.binding.core.storage.database.View;
import com.exonum.binding.core.service.Service;
import com.exonum.binding.core.storage.database.Snapshot;
import io.vertx.ext.web.Router;
import java.util.Collections;
import java.util.List;

class TestService extends AbstractService {
class TestService implements Service {

@Override
protected Schema createDataSchema(View view) {
return Collections::emptyList;
public List<HashCode> getStateHashes(Snapshot snapshot) {
return Collections.emptyList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,49 @@

package com.exonum.binding.core.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

import com.exonum.binding.core.runtime.ServiceArtifactId;
import com.exonum.binding.core.runtime.ServiceInstanceSpec;
import com.exonum.binding.core.storage.database.Snapshot;
import com.exonum.binding.core.storage.database.View;
import io.vertx.ext.web.Router;
import org.junit.jupiter.api.Test;

class AbstractServiceTest {

private static final String NAME = "test";
private static final int ID = 1;
private static final ServiceInstanceSpec INSTANCE_SPEC = ServiceInstanceSpec.newInstance(NAME, ID,
ServiceArtifactId.newJavaId("g:a:1"));

@Test
void getName() {
AbstractService service = new ServiceUnderTest(INSTANCE_SPEC);
assertThat(service.getName()).isEqualTo(NAME);
}

@Test
void getId() {
AbstractService service = new ServiceUnderTest(INSTANCE_SPEC);
assertThat(service.getId()).isEqualTo(ID);
}

// todo: Remove this test or re-write?
@Test
void getStateHashes_EmptySchema() {
Service service = new ServiceUnderTest();
Service service = new ServiceUnderTest(INSTANCE_SPEC);
assertTrue(service.getStateHashes(mock(Snapshot.class)).isEmpty());
}

static class ServiceUnderTest extends AbstractService {

ServiceUnderTest(ServiceInstanceSpec instanceSpec) {
super(instanceSpec);
}

@Override
protected Schema createDataSchema(View view) {
return mock(Schema.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import com.exonum.binding.common.serialization.StandardSerializers;
import com.exonum.binding.core.storage.database.View;
import org.junit.jupiter.api.Disabled;

@Disabled("ECR-3608")
class ProofListIndexProxyGroupIntegrationTest
extends BaseListIndexProxyGroupTestable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import com.exonum.binding.common.hash.HashCode;
import com.exonum.binding.common.message.TransactionMessage;
import com.exonum.binding.core.blockchain.Blockchain;
import com.exonum.binding.core.runtime.ServiceInstanceSpec;
import com.exonum.binding.core.service.AbstractService;
import com.exonum.binding.core.service.Node;
import com.exonum.binding.core.service.Schema;
import com.exonum.binding.core.storage.database.View;
import com.exonum.binding.core.storage.indices.ListIndex;
import com.exonum.binding.core.storage.indices.MapIndex;
import com.exonum.binding.cryptocurrency.transactions.TxMessageProtos;
import com.google.inject.Inject;
import com.google.protobuf.InvalidProtocolBufferException;
import io.vertx.ext.web.Router;
import java.util.List;
Expand All @@ -42,6 +44,11 @@ public final class CryptocurrencyServiceImpl extends AbstractService

@Nullable private Node node;

@Inject
public CryptocurrencyServiceImpl(ServiceInstanceSpec instanceSpec) {
super(instanceSpec);
}

@Override
protected Schema createDataSchema(View view) {
return new CryptocurrencySchema(view);
Expand Down
Loading