New Transaction Method Test
This commit is contained in:
parent
f7dfc4eea2
commit
b07b6a530f
Binary file not shown.
|
@ -2,6 +2,7 @@ package blockchain.utility;
|
||||||
|
|
||||||
|
|
||||||
import blockchain.user.UserContext;
|
import blockchain.user.UserContext;
|
||||||
|
import database.user.User;
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
@ -57,34 +58,30 @@ public class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserContext readUserContext(String affiliation, String username) {
|
public static UserContext readUserContext(String affiliation, String username) {
|
||||||
|
ObjectInputStream ois = null;
|
||||||
UserContext userContext = null;
|
UserContext userContext = null;
|
||||||
FileInputStream fileStream = null;
|
try{
|
||||||
ObjectInputStream in = null;
|
|
||||||
try {
|
|
||||||
String filePath = "msp/" + affiliation + "/" + username + ".context";
|
String filePath = "msp/" + affiliation + "/" + username + ".context";
|
||||||
File file = new File(filePath);
|
final FileInputStream fis = new FileInputStream(filePath);
|
||||||
if (file.exists()) {
|
ois = new ObjectInputStream(fis);
|
||||||
fileStream = new FileInputStream(filePath);
|
userContext = (UserContext) ois.readObject();
|
||||||
in = new ObjectInputStream(fileStream);
|
|
||||||
userContext = (UserContext) in.readObject();
|
logger.info("userContext : "+userContext.getName());
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
}catch (IOException e){
|
||||||
e.printStackTrace();
|
logger.warn("error : "+e);
|
||||||
|
}catch (ClassNotFoundException e){
|
||||||
|
logger.warn("error : "+e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try{
|
||||||
if (in != null)
|
if(ois!=null){
|
||||||
in.close();
|
ois.close();
|
||||||
} catch (IOException e) {
|
}
|
||||||
e.printStackTrace();
|
}catch (IOException e){
|
||||||
|
logger.warn("error : "+e);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
if (fileStream != null)
|
|
||||||
fileStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return userContext;
|
return userContext;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package blockchain.query.User;
|
||||||
|
|
||||||
|
import blockchain.client.ChannelClientWrapper;
|
||||||
|
import blockchain.client.FabricClientWrapper;
|
||||||
|
import blockchain.configuration.Config;
|
||||||
|
import blockchain.query.QueryTest;
|
||||||
|
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.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public class RegisterUserTestNewVersion {
|
||||||
|
|
||||||
|
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void TestRegisterUser() {
|
||||||
|
BasicConfigurator.configure();
|
||||||
|
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Collection<ProposalResponse> successful = new LinkedList<>();
|
||||||
|
Collection<ProposalResponse> failed = new LinkedList<>();
|
||||||
|
|
||||||
|
logger.info("userContext : "+user.getName());
|
||||||
|
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||||
|
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||||
|
|
||||||
|
Channel channel = channelClientWrapper.getChannel();
|
||||||
|
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||||
|
channel.addOrderer(orderer);
|
||||||
|
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||||
|
channel.addPeer(peer);
|
||||||
|
|
||||||
|
|
||||||
|
channel.initialize();
|
||||||
|
|
||||||
|
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||||
|
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||||
|
tpr.setChaincodeID(cid);
|
||||||
|
tpr.setFcn("registerUser");
|
||||||
|
tpr.setArgs(new String[]{"UserA","UserAIdentifier","Thomas","MEUNIER",""}); //TODO
|
||||||
|
tpr.setProposalWaitTime(120000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
|
import blockchain.client.ChannelClientWrapper;
|
||||||
|
import blockchain.client.FabricClientWrapper;
|
||||||
|
import blockchain.configuration.Config;
|
||||||
|
import blockchain.query.QueryTest;
|
||||||
|
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.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public class TransactionTestNewVersion {
|
||||||
|
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void TestQueryWallet() {
|
||||||
|
BasicConfigurator.configure();
|
||||||
|
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||||
|
|
||||||
|
try{
|
||||||
|
String chaincode = Config.CHAINCODE_NAME;
|
||||||
|
Collection<ProposalResponse> successful = new LinkedList<>();
|
||||||
|
Collection<ProposalResponse> failed = new LinkedList<>();
|
||||||
|
|
||||||
|
logger.info("userContext : "+user.getName());
|
||||||
|
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||||
|
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||||
|
|
||||||
|
Channel channel = channelClientWrapper.getChannel();
|
||||||
|
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||||
|
channel.addOrderer(orderer);
|
||||||
|
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||||
|
channel.addPeer(peer);
|
||||||
|
|
||||||
|
|
||||||
|
channel.initialize();
|
||||||
|
|
||||||
|
//CONTROL
|
||||||
|
logger.info("channel INIT : "+channel.isInitialized());
|
||||||
|
for(Peer p : channel.getPeers()){
|
||||||
|
Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
|
||||||
|
logger.info("channels "+channels);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
|
||||||
|
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||||
|
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||||
|
tpr.setChaincodeID(cid);
|
||||||
|
tpr.setFcn("queryWalletsByOwner");
|
||||||
|
tpr.setArgs(new String[]{"chef"});
|
||||||
|
tpr.setProposalWaitTime(120000);
|
||||||
|
|
||||||
|
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
||||||
|
for(ProposalResponse response : invokePropResp){
|
||||||
|
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
||||||
|
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
||||||
|
successful.add(response);
|
||||||
|
} else {
|
||||||
|
failed.add(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue