Merge branch 'features/clean' into develop

This commit is contained in:
GME 2018-11-17 11:21:54 +01:00
commit 2ee79b3552
27 changed files with 45 additions and 234 deletions

Binary file not shown.

View file

@ -1,14 +0,0 @@
-----BEGIN CERTIFICATE-----
MIICGjCCAcCgAwIBAgIRAI78GIwc1BJbESAVBAu12zgwCgYIKoZIzj0EAwIwczEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh
Lm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwMjExMTQxODI4WhcNMjgwMjA5MTQxODI4
WjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN
U2FuIEZyYW5jaXNjbzEfMB0GA1UEAwwWQWRtaW5Ab3JnMS5leGFtcGxlLmNvbTBZ
MBMGByqGSM49AgEGCCqGSM49AwEHA0IABHc7mBPjvRt41DHUQOwBmPdosuyBiR5q
9ODr4IRm0nSPy8qNMOwNzjq+FBlD/h5q36rHwGVmyK31BlIX3SN6u8KjTTBLMA4G
A1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIMsE632KJqem
rpj0tWcvTaIXe5aa0DPs8dxIkaPosSv8MAoGCCqGSM49BAMCA0gAMEUCIQDxrPnJ
H6UDSPyTAkIZ156RRuAXm3S3quTrXYAVEP1bNgIgNmaykOaIbTBTw7LSv8zPZopP
5XHsa6MEFFL0KM6whQk=
-----END CERTIFICATE-----

View file

@ -1,5 +0,0 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg2KnGkVeiwErPZq2n
WX0AjHkS+XOx2sqON1n4kiTw5QuhRANCAAR3O5gT470beNQx1EDsAZj3aLLsgYke
avTg6+CEZtJ0j8vKjTDsDc46vhQZQ/4eat+qx8BlZsit9QZSF90jervC
-----END PRIVATE KEY-----

View file

@ -1,23 +1,13 @@
package blockchain.utility;
import blockchain.user.CAEnrollement;
import blockchain.user.UserContext;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.bouncycastle.crypto.CryptoException;
import javax.xml.bind.DatatypeConverter;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Security;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
//Class to Read and Write user / admin to msp directory
public class Util {
private static Logger logger = Logger.getLogger(Util.class);
@ -97,40 +87,4 @@ public class Util {
}
}
/*
public static CAEnrollement getEnrollement(String keyFolderPath, String keyFileName, String certFolderPath, String certFileName) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, CryptoException {
PrivateKey key = null;
String certificate = null;
InputStream isKey = null;
BufferedReader brKey = null;
try{
Security.addProvider(new BouncyCastleProvider());
String keyPath = keyFolderPath+"/"+keyFileName;
isKey = new FileInputStream(keyPath);
brKey = new BufferedReader(new InputStreamReader(isKey));
StringBuilder keyBuilder = new StringBuilder();
for(String line = brKey.readLine(); line != null; line = brKey.readLine()){
if(line.indexOf("PRIVATE") == -1){
keyBuilder.append(line);
}
}
certificate = new String(Files.readAllBytes(Paths.get(certFolderPath,certFileName)));
byte[] encoded = DatatypeConverter.parseBase64Binary(keyBuilder.toString());
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
KeyFactory kf = KeyFactory.getInstance("ECDSA");
key = kf.generatePrivate(keySpec);
}finally {
isKey.close();
brKey.close();
}
CAEnrollement enrollment = new CAEnrollement(key,certificate);
return enrollment;
}
*/
}

View file

@ -7,6 +7,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
//Test to enroll Admin
public class TestEnrollAdmin {
@Test
public void TestAEnrollAdmin(){

View file

@ -6,6 +6,7 @@ import blockchain.utility.Util;
import org.apache.log4j.Logger;
import org.junit.Test;
//Test to register and enroll user
public class TestRegisterEnrollUser {
private static Logger logger = Logger.getLogger(TestRegisterEnrollUser.class);
//Success

View file

@ -17,6 +17,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
//Test for transaction
public class ChaincodeTransactionTest {
private static Logger logger = Logger.getLogger(ChaincodeTransactionTest.class);
@Test
@ -33,49 +34,26 @@ public class ChaincodeTransactionTest {
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
Channel channel = channelClientWrapper.getChannel();
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
//OLD PEER
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
//Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
channel.addPeer(peer);
channel.addEventHub(eventHub);
channel.addOrderer(orderer);
channel.initialize();
/*
List<String> args = new ArrayList<>();
args.add("b");
args.add("a");
args.add("5");
String accountFromKey = args.get(0);
String accountToKey = args.get(1);
int amount = Integer.parseInt(args.get(2));
System.out.println("args0 = "+accountFromKey+" -- args1 = "+accountToKey+" -- args2 = "+amount);
*/
/*
String[] args = {"b","a","5"};
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"invoke",args);
for(ProposalResponse presp : responseQuery){
ChaincodeResponse.Status status = presp.getStatus();
if(status.getStatus()!=200){
throw new Exception(presp.getMessage());
}
String stringResponse = new String(presp.getChaincodeActionResponsePayload());
logger.info("RESPONSE : "+stringResponse);
}
*/
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
tpr.setChaincodeID(cid);
tpr.setFcn("invoke");
tpr.setArgs(new String[]{"b","a","20"});
tpr.setArgs(new String[]{"a","b","20"}); //send 20 from a to b
Collection<ProposalResponse> responses = channel.sendTransactionProposal(tpr);
List<ProposalResponse> invalid = responses.stream().filter(r -> r.isInvalid()).collect(Collectors.toList());
@ -87,31 +65,8 @@ public class ChaincodeTransactionTest {
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
event.getTransactionID();
/*
BlockEvent.TransactionEvent event = sendTransaction(fabricClientWrapper.getClient(), channel).get(60, TimeUnit.SECONDS);
if (event.isValid()) {
logger.info("Transacion tx: " + event.getTransactionID() + " is completed.");
} else {
logger.error("Transaction tx: " + event.getTransactionID() + " is invalid.");
}
*/
//String[] args = {"a","b","5"};
//logger.info("LENGHT : "+args.length);
//Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"invoke",args);
//for(ProposalResponse presp : responseQuery){
//ChaincodeResponse.Status status = presp.getStatus();
//if(status.getStatus()!=200){
// throw new Exception(presp.getMessage());
//}
//String stringResponse = new String(presp.getChaincodeActionResponsePayload());
//logger.info("RESPONSE : "+stringResponse);
//}
}catch (Exception e){
e.printStackTrace();
}

View file

@ -6,16 +6,18 @@ import blockchain.configuration.Config;
import blockchain.user.UserContext;
import blockchain.utility.Util;
import org.apache.log4j.BasicConfigurator;
import org.hyperledger.fabric.sdk.Channel;
import org.hyperledger.fabric.sdk.EventHub;
import org.hyperledger.fabric.sdk.Orderer;
import org.hyperledger.fabric.sdk.Peer;
import org.apache.log4j.Logger;
import org.hyperledger.fabric.sdk.*;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
//Test to create user on chaincode -> don't work, can't use function "Init"
public class CreateChaincodeUserTest {
private static Logger logger = Logger.getLogger(QueryTest.class);
@Test
public void TestCreateUser(){
BasicConfigurator.configure();
@ -27,19 +29,31 @@ public class CreateChaincodeUserTest {
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
Channel channel = channelClientWrapper.getChannel();
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
//OLD
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
//Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
channel.addPeer(peer);
channel.addEventHub(eventHub);
channel.addOrderer(orderer);
channel.initialize();
List<String> args = new ArrayList<>();
args.add("user1");
args.add("200");
args.add("user2");
args.add("150");
String[] args = {"user1","200","user2","180"};
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"init",args);
for(ProposalResponse pres : responseQuery){
ChaincodeResponse.Status status = pres.getStatus();
if(status.getStatus()!=200){
throw new Exception(pres.getMessage());
}
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
logger.info("RESPONSE : "+stringResponse);
}
}catch (Exception e){
e.printStackTrace();

View file

@ -11,6 +11,7 @@ import org.junit.Test;
import java.util.Set;
//Test to show channels on a node
public class QueryChannelTest {
private static Logger logger = Logger.getLogger(QueryTest.class);

View file

@ -1,45 +0,0 @@
package blockchain.query;
import blockchain.client.FabricClientWrapper;
import blockchain.configuration.Config;
import blockchain.user.UserContext;
import blockchain.utility.Util;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.hyperledger.fabric.sdk.Enrollment;
import org.hyperledger.fabric.sdk.Peer;
import org.junit.Test;
import java.io.File;
import java.util.Set;
public class QueryForChannelsTest {
private static Logger logger = Logger.getLogger(QueryForChannelsTest.class);
@Test
public void TestAQueryPeerChannels(){
BasicConfigurator.configure();
try{
//TEST
UserContext admin = new UserContext();
File pkFolder = new File(Config.ADMIN_KEY_PATH);
File[] pkFile = pkFolder.listFiles();
File certFolder = new File(Config.ADMIN_CERT_PATH);
File[] certFile = certFolder.listFiles();
admin.setName(Config.ADMIN);
admin.setMspId(Config.ORG1_MSP);
admin.setAffiliation(Config.ORG1);
//Enrollment enrollAdmin = Util.getEnrollement(Config.ADMIN_KEY_PATH, pkFile[0].getName(), Config.ADMIN_CERT_PATH, certFile[0].getName());
//admin.setEnrollment(enrollAdmin);
//END TEST
//FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(admin);
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
//Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
//logger.info(channels);
}catch(Exception e){
e.printStackTrace();
}
}
}

View file

@ -9,11 +9,10 @@ import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.hyperledger.fabric.sdk.*;
import org.junit.Test;
import java.io.File;
import java.util.Collection;
import java.util.Set;
//Test to get balance of a User
public class QueryTest {
private static Logger logger = Logger.getLogger(QueryTest.class);
@ -25,29 +24,13 @@ public class QueryTest {
UserContext user = Util.readUserContext(Config.ORG1,"User-org1");
try{
//TEST FAILED
//UserContext admin = new UserContext();
//File pkFolder = new File(Config.ADMIN_KEY_PATH);
//File[] pkFile = pkFolder.listFiles();
//File certFolder = new File(Config.ADMIN_CERT_PATH);
//File[] certFile = certFolder.listFiles();
//admin.setName(Config.ADMIN);
//admin.setMspId(Config.ORG1_MSP);
//admin.setAffiliation(Config.ORG1);
//Enrollment enrollAdmin = Util.getEnrollement(Config.ADMIN_KEY_PATH, pkFile[0].getName(), Config.ADMIN_CERT_PATH, certFile[0].getName());
//admin.setEnrollment(enrollAdmin);
//END TEST
String chaincode = Config.CHAINCODE_NAME;
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
Channel channel = channelClientWrapper.getChannel();
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
channel.addPeer(peer);
channel.addEventHub(eventHub);

View file

@ -4,6 +4,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
//Test to create a User
public class UserContextTest {
@Test
public void TestACreateUser(){

View file

@ -4,6 +4,7 @@ import blockchain.configuration.Config;
import blockchain.user.UserContext;
import org.junit.Test;
//Test to Read User
public class ReadUserTest {
@Test
public void testReadUserOrg1(){

View file

@ -1,37 +0,0 @@
package blockchain.utility;
import blockchain.configuration.Config;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.hyperledger.fabric.sdk.Enrollment;
import org.junit.Test;
import java.io.File;
public class UtilEnrollTest {
private static Logger logger = Logger.getLogger(UtilTest.class);
@Test
public void TestAGetEnrollement(){
BasicConfigurator.configure();
try{
logger.info("----- START TEST ----");
File pkFolder = new File(Config.ADMIN_KEY_PATH);
File[] pkFile = pkFolder.listFiles();
File certFolder = new File(Config.ADMIN_CERT_PATH);
File[] certFile = certFolder.listFiles();
logger.info("----- GET ENROLLEMENT ----");
//Enrollment enrollAdmin = Util.getEnrollement(Config.ADMIN_KEY_PATH, pkFile[0].getName(), Config.ADMIN_CERT_PATH, certFile[0].getName());
//logger.info("KEY : "+enrollAdmin.getKey());
//logger.info("CERT : "+enrollAdmin.getCert());
}catch (Exception e){
e.printStackTrace();
}
}
}

View file

@ -7,6 +7,7 @@ import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
//Test to Read and Write user from files
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class UtilTest {
private static Logger logger = Logger.getLogger(UtilTest.class);