clean code
delete unused class and code
This commit is contained in:
parent
270fa6d692
commit
74821e5056
|
@ -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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -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(){
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(){
|
||||
|
|
|
@ -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(){
|
||||
|
|
|
@ -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);
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue