clean
This commit is contained in:
parent
d127499a32
commit
a687ade3f5
|
@ -7,6 +7,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
public class WelcomeController {
|
public class WelcomeController {
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
public String index(){return "Welcome from Monnethic !";}
|
public String index(){return "Welcome to monnethic ! ";}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,42 +0,0 @@
|
||||||
package blockchain.client;
|
|
||||||
|
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import org.hyperledger.fabric.sdk.Enrollment;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
//Test to enroll Admin
|
|
||||||
public class TestEnrollAdmin {
|
|
||||||
@Test
|
|
||||||
public void TestAEnrollAdmin(){
|
|
||||||
String caUrl = Config.CA_ORG1_URL;
|
|
||||||
try {
|
|
||||||
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null);
|
|
||||||
|
|
||||||
UserContext adminContext = new UserContext();
|
|
||||||
adminContext.setName(Config.ADMIN);
|
|
||||||
adminContext.setAffiliation(Config.ORG1);
|
|
||||||
adminContext.setMspId(Config.ORG1_MSP);
|
|
||||||
|
|
||||||
caClientWrapper.setAdminContext(adminContext);
|
|
||||||
|
|
||||||
UserContext verifyUser = caClientWrapper.getAdminContext();
|
|
||||||
assertEquals(Config.ADMIN, verifyUser.getName());
|
|
||||||
assertEquals(Config.ORG1, verifyUser.getAffiliation());
|
|
||||||
assertEquals(Config.ORG1_MSP, verifyUser.getMspId());
|
|
||||||
|
|
||||||
//ENROLL AND WRITE ADMIN
|
|
||||||
adminContext = caClientWrapper.enrollAdmin(adminContext.getName(),Config.ADMIN_PASSWORD,adminContext.getAffiliation());
|
|
||||||
|
|
||||||
//Check Admin Enrollement
|
|
||||||
Enrollment enrollment = adminContext.getEnrollment();
|
|
||||||
System.out.println("admin cert : "+enrollment.getCert());
|
|
||||||
System.out.println("admin keys : "+enrollment.getKey());
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package blockchain.client;
|
|
||||||
|
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
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
|
|
||||||
@Test
|
|
||||||
public void RegisterEnrollUser(){
|
|
||||||
String caUrl = Config.CA_ORG1_URL;
|
|
||||||
try{
|
|
||||||
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null);
|
|
||||||
UserContext admin = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
||||||
caClientWrapper.setAdminContext(admin);
|
|
||||||
UserContext userContext = new UserContext();
|
|
||||||
|
|
||||||
userContext.setName("User-org1");
|
|
||||||
userContext.setAffiliation(Config.ORG1);
|
|
||||||
userContext.setMspId(Config.ORG1_MSP);
|
|
||||||
String userSecret = caClientWrapper.registerUser(userContext.getName(),userContext.getAffiliation());
|
|
||||||
logger.info("uSecret : "+userSecret);
|
|
||||||
userContext = caClientWrapper.enrollUser(userContext,userSecret);
|
|
||||||
logger.info("userContext enrollement : "+userContext.getEnrollment());
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
package blockchain.query;
|
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
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.*;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
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
|
|
||||||
public void TestATransaction(){
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
|
|
||||||
//UserContext user = Util.readUserContext(Config.ORG1,"User-org1");
|
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
||||||
|
|
||||||
try{
|
|
||||||
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
//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();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("invoke");
|
|
||||||
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());
|
|
||||||
|
|
||||||
if (!invalid.isEmpty()) {
|
|
||||||
invalid.forEach(response -> {
|
|
||||||
logger.error(response.getMessage());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package blockchain.query;
|
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
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.*;
|
|
||||||
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();
|
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
||||||
|
|
||||||
try{
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
//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();
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +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.Peer;
|
|
||||||
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);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testQ(){
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
UserContext userContext = Util.readUserContext(Config.ORG1,"User-org1");
|
|
||||||
|
|
||||||
try{
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
|
||||||
Set<String> channels = fabricClientWrapper.queryForChannels();
|
|
||||||
|
|
||||||
logger.info("CHANNELS : "+channels);
|
|
||||||
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
package blockchain.query;
|
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
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.*;
|
|
||||||
import org.junit.Test;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
|
|
||||||
//Test to get balance of a User
|
|
||||||
public class QueryTest {
|
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestAQueryChannels() {
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
|
|
||||||
//UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"User-org1");
|
|
||||||
|
|
||||||
try{
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
|
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
|
||||||
|
|
||||||
String[] args1 = {"a"};
|
|
||||||
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"query",args1);
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package blockchain.queryWrapper;
|
|
||||||
|
|
||||||
import blockchain.query.QueryWrapper;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class QueryWrapperTest {
|
|
||||||
private static Logger logger = Logger.getLogger(QueryWrapperTest.class);
|
|
||||||
@Test
|
|
||||||
public void TestGerUserBalance() {
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
|
||||||
String response = queryWrapper.getUserBalance("a");
|
|
||||||
logger.info(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package blockchain.queryWrapper;
|
|
||||||
|
|
||||||
import blockchain.query.QueryWrapper;
|
|
||||||
import blockchain.query.TransactionWrapper;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class TransactionWrapperTest {
|
|
||||||
private static Logger logger = Logger.getLogger(TransactionWrapperTest.class);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestTransaction() {
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
|
||||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
|
||||||
String responseTransaction = transactionWrapper.sendTransaction("a","b","15"); //do transaction
|
|
||||||
logger.info("TRANSACTION ID : "+responseTransaction);
|
|
||||||
|
|
||||||
String responseUserB = queryWrapper.getUserBalance("b"); //check new balance of user b
|
|
||||||
logger.info("BALANCE USER B : "+responseUserB);
|
|
||||||
|
|
||||||
String responseUserA = queryWrapper.getUserBalance("a"); //check new balance of user a
|
|
||||||
logger.info("BALANCE USER A :"+responseUserA);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package blockchain.user;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
//Test to create a User
|
|
||||||
public class UserContextTest {
|
|
||||||
@Test
|
|
||||||
public void TestACreateUser(){
|
|
||||||
UserContext userContext = new UserContext();
|
|
||||||
userContext.setName("admin");
|
|
||||||
userContext.setAffiliation("org1");
|
|
||||||
userContext.setMspId("MspidOrg1");
|
|
||||||
userContext.setEnrollment(null);
|
|
||||||
|
|
||||||
assertEquals("org1",userContext.getAffiliation());
|
|
||||||
assertEquals("admin",userContext.getName());
|
|
||||||
assertEquals(null,userContext.getEnrollment());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package blockchain.utility;
|
|
||||||
|
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
//Test to Read User
|
|
||||||
public class ReadUserTest {
|
|
||||||
@Test
|
|
||||||
public void testReadUserOrg1(){
|
|
||||||
try{
|
|
||||||
UserContext userContext = Util.readUserContext(Config.ORG1, "User-org1");
|
|
||||||
System.out.println(userContext.getAffiliation());
|
|
||||||
System.out.println(userContext.getMspId());
|
|
||||||
System.out.println(userContext.getEnrollment().getCert());
|
|
||||||
System.out.println(userContext.getEnrollment().getKey());
|
|
||||||
System.out.println(userContext.getName());
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package blockchain.utility;
|
|
||||||
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
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);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestAReadNullUser(){
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
|
|
||||||
logger.info("----- START TEST READ NULL USER ----");
|
|
||||||
UserContext uc = Util.readUserContext("tata","abdel");
|
|
||||||
if(uc!=null){
|
|
||||||
logger.info("UserContext is : "+uc.toString());
|
|
||||||
}else{
|
|
||||||
logger.info("UserContext doesn't exist");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestBWriteUser(){
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
logger.info("----- START TEST WRITE NULL USER ----");
|
|
||||||
UserContext user = new UserContext();
|
|
||||||
user.setName("abdel");
|
|
||||||
user.setAffiliation("toto");
|
|
||||||
user.setEnrollment(null);
|
|
||||||
user.setMspId("test");
|
|
||||||
|
|
||||||
Util.writeUserContext(user);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestCReadCreatedUser(){
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
logger.info("----- START TEST READ CREATED USER ----");
|
|
||||||
UserContext uc = Util.readUserContext("toto","abdel");
|
|
||||||
if(uc!=null){
|
|
||||||
logger.info("UserContext is : "+uc.toString());
|
|
||||||
}else{
|
|
||||||
logger.info("UserContext doesn't exist");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue