Skip to content

Commit

Permalink
WIP: testing java_vm_test
Browse files Browse the repository at this point in the history
  • Loading branch information
motxx committed Jan 26, 2017
1 parent 804475a commit 605b6f8
Show file tree
Hide file tree
Showing 34 changed files with 377 additions and 558 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PROJECT(iroha CXX)
ENABLE_LANGUAGE(C)
find_package(Threads)

SET(CMAKE_CXX_FLAGS "-g -Wall -std=c++1y")
SET(CMAKE_CXX_FLAGS "-g -m64 -std=c++1y -Wall -fPIC")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
SET(CMAKE_CXX_FLAGS_DEBUG "-Wextra -O0")
SET(CMAKE_SHARED_LINKER_FLAGS "-lpthread -lssl")
Expand All @@ -13,6 +13,7 @@ add_subdirectory(core)
add_subdirectory(peer)

add_subdirectory(tools)
add_subdirectory(smart_contract)

# at some point we want to include pool as following: #include <worker.hpp>
# which resides in that folder
Expand Down
1 change: 1 addition & 0 deletions core/infra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ add_subdirectory(server)
add_subdirectory(connection)
add_subdirectory(service)
add_subdirectory(protobuf)
#add_subdirectory(config)
2 changes: 1 addition & 1 deletion core/infra/crypto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ KECCAK_PATH = ../../vendor/KeccakCodePackage

DEFINE = -DKeccakP200_excluded -DKeccakP400_excluded -DKeccakP800_excluded

CFLAGS := $(CFLAGS) -std=c++0x
CFLAGS := $(CFLAGS) -g -m64 -std=c++1y -Wall -fPIC
CFLAGS := $(CFLAGS) $(DEFINE)
CFLAGS := $(CFLAGS) -I$(KECCAK_PATH)/bin/generic64/libkeccak.a.headers

Expand Down
5 changes: 3 additions & 2 deletions core/infra/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
SET(CMAKE_CXX_FLAGS "-std=c++14 -L/usr/local/lib `pkg-config --libs grpc++ grpc` -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -lprotobuf -lpthread -ldl")
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

SET(CMAKE_CXX_FLAGS "-g -m64 -std=c++1y -Wall -fPIC -L/usr/local/lib `pkg-config --libs grpc++ grpc` -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -lprotobuf -lpthread -ldl")

link_directories(
/usr/local/lib
Expand All @@ -9,7 +11,6 @@ ADD_LIBRARY(event_with_grpc STATIC
../protobuf/event.grpc.pb.cc
../protobuf/event.pb.cc
)

target_link_libraries(event_with_grpc
grpc++
grpc++_reflection
Expand Down
2 changes: 1 addition & 1 deletion peer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)


SET(CMAKE_CXX_FLAGS "-g -Wall -std=c++1y")
SET(CMAKE_CXX_FLAGS "-g -m64 -std=c++1y -Wall -fPIC")

SET(AERON_PATH "${PROJECT_SOURCE_DIR}/core/vendor/Aeron")
SET(LEVELDB_PATH "${PROJECT_SOURCE_DIR}/core/vendor/leveldb")
Expand Down
39 changes: 39 additions & 0 deletions smart_contract/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

SET(SMART_CONTRACT_PATH ${PROJECT_SOURCE_DIR}/smart_contract)

include_directories(
${SMART_CONTRACT_PATH}
/usr/lib/jvm/java-1.8.0-openjdk-amd64/include
/usr/lib/jvm/java-1.8.0-openjdk-amd64/include/linux
${JAVA_HOME}/include
${JAVA_HOME}/include/linux
)

link_directories(
${LIBRARY_OUTPUT_PATH}
/usr/lib/
)

ADD_LIBRARY(AccountRepository SHARED repository/account_repository_jni.cpp)
target_link_libraries(AccountRepository
domain_repository
convertor
)

ADD_LIBRARY(AssetRepository SHARED repository/asset_repository_jni.cpp)
target_link_libraries(AssetRepository
domain_repository
convertor
)

# compile .java files
#add_custom_command(OUTPUT SampleCurrency.class
# POST_BUILD
# COMMAND javac -encoding UTF-8 $IROHA_HOME/smart_contract/SampleCurrency/SampleCurrency.java
#)

#add_custom_command(OUTPUT JavaExecuteTest.class
# POST_BUILD
# COMMAND javac -encoding UTF-8 $IROHA_HOME/smart_contract/JavaExecuteTest/JavaExecuteTest.java
#)
81 changes: 81 additions & 0 deletions smart_contract/JavaExecuteTest/JavaExecuteTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved.
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.
*/

import java.util.HashMap;
import repository.AccountRepository;
import repository.AssetRepository;

package test;

// no package declasration
public class JavaExecuteTest {

static {
System.loadLibrary("AccountRepository");
System.loadLibrary("AssetRepository");
}

// Test invoke function
public static void test1() {
System.out.println("Hello in JAVA! test1()");
}

// Test invoke function(HashMap<String,String>)
public static void test2(HashMap<String,String> params){
System.out.println("Hello in JAVA! test2()");
assert params.get("key1").equals("Mizuki");
assert params.get("key2").equals("Sonoko");
}

// Test invoke function(HashMap<String,String>) (UTF-8)
public static void test3(HashMap<String,String> params){
System.out.println("Hello in JAVA! test3()");
assert params.get("key1").equals("水樹");
assert params.get("key2").equals("素子");
}

public static void test4(HashMap<String,String> params){
System.out.println("Hello in JAVA! test4() ");
AccountRepository accountRepo = new AccountRepository();
accountRepo.add(params.get("key"), "MizukiSonoko");
}

public static void test5(HashMap<String,String> params){
System.out.println("Hello in JAVA! test5() ");
AssetRepository assetRepo = new AssetRepository();
assetRepo.add(params.get("key"), "MizukiSonoko", "1234567");
}

public static void main(String[] argv) {

System.out.println("Hello in JAVA! This function is expected to be invoked manually");
System.out.println("If you want to invoke test functions automatically, you should run test/smart_contract/java_execute_test (gTset)");

JavaExecuteTest exe = new JavaExecuteTest();
exe.test1();

HashMap<String, String> mp = new HashMap<String, String>();

mp.put("key1", "Mizuki");
mp.put("key2", "Sonoko");
exe.test2(mp);

mp.put("key1", "水樹");
mp.put("key2", "素子");
exe.test3(mp);

mp.put("key", "this is public key");
exe.test4(mp);
exe.test5(mp);
}
}
1 change: 1 addition & 0 deletions smart_contract/JavaExecuteTest/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
javac -encoding UTF-8 $IROHA_HOME/smart_contract/repository/*.java $IROHA_HOME/smart_contract/JavaExecuteTest/JavaExecuteTest.java
3 changes: 3 additions & 0 deletions smart_contract/JavaExecuteTest/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
java -Djava.class.path=$IROHA_HOME/smart_contract/JavaExecuteTest \
-Djava.library.path=$IROHA_HOME/build/lib \
JavaExecuteTest
13 changes: 0 additions & 13 deletions smart_contract/SampleCurrency/SampleCurrency.h

This file was deleted.

37 changes: 4 additions & 33 deletions smart_contract/SampleCurrency/SampleCurrency.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,17 +12,9 @@
*/

import java.util.HashMap;
import repository.DomainRepository;
import repository.AssetRepository;

// no package declaration
public class SampleCurrency {

public static void put( String param ) {
System.out.println("Hello in JAVA! in add");
System.out.println("vvvvvvvv param vvvvvvvv");
System.out.println( param );
}

public static void put( String param ) {
System.out.println("Hello in JAVA! in add");
Expand All @@ -38,28 +29,8 @@ public static void remit(HashMap<String,String> params){
System.out.println( key + " : " + params.get( key ) );
}
}

public static void main(String[] argv) {
// This is DB access test.

System.out.println("Hello in JAVA! check repositories");

System.out.println("DomainRepository");
DomainRepository domain = new DomainRepository();
domain.add("domain", 12345);
// find, remove, ...

System.out.println("AssetRepository");
AssetRepository asset = new AssetRepository();
// asset.add("MPTt3ULszCLGQqAqRgHj2gQHVnxn/DuNlRXR/iLMAn4=", "MyAsset", "some value");
// find, remove, ...

/*
System.out.println("AccountRepository");
AccountRepository account = new AccountRepository();
account.add("account", 12345);
// find, remove, ...
*/

public static void main(String[] argv){
System.out.println("Hello in JAVA! in contract main");
}

}
}
92 changes: 0 additions & 92 deletions smart_contract/SampleCurrency/account_repository_jni.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions smart_contract/SampleCurrency/callcpp.sh

This file was deleted.

1 change: 1 addition & 0 deletions smart_contract/SampleCurrency/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
javac -encoding UTF-8 $IROHA_HOME/smart_contract/SampleCurrency/SampleCurrency.java
Loading

0 comments on commit 605b6f8

Please sign in to comment.