update test
This commit is contained in:
parent
d877c3b39f
commit
843c6a034e
|
@ -1,4 +1,4 @@
|
|||
package blockchain.query.Wallet;
|
||||
package blockchain.query.Transaction;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
|
@ -13,57 +13,69 @@ import org.junit.Ignore;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
@Ignore
|
||||
public class QueryWalletByOwnerTrTest {
|
||||
public class TransactionTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryWallet() {
|
||||
public void TestQueryWalletHistory() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
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();
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://93.30.148.59:87051");
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
channel.addPeer(peer);
|
||||
channel.addEventHub(eventHub);
|
||||
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.setFcn("invoke");
|
||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh","qerh654d5f5h46q4fdh6h65fh2","2"}); //1 foutre to bitman
|
||||
tpr.setProposalWaitTime(120000);
|
||||
|
||||
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());
|
||||
});
|
||||
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());
|
||||
|
||||
logger.info("SEND TRANSACTION");
|
||||
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
|
||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
||||
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -34,8 +34,9 @@ public class ReadUserTest {
|
|||
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
|
||||
//String[] args1 = {"chef"};
|
||||
String[] args1 = {"bitman"};
|
||||
//String[] args1 = {"chef"}
|
||||
//String[] args1 = {"bitman"};
|
||||
String[] args1 = {"UserA"};
|
||||
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readUser",args1);
|
||||
logger.info("RESPONSE : "+responseQuery);
|
||||
|
|
|
@ -46,9 +46,25 @@ public class RegisterUserTestNewVersion {
|
|||
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.setArgs(new String[]{"UserA","Thomas","MEUNIER","0000000000","gonette"});
|
||||
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());
|
||||
|
||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
||||
|
||||
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
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.ChaincodeResponse;
|
||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Ignore
|
||||
public class QueryWalletHistory {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryWalletHistory() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
try{
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
|
||||
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh2"};
|
||||
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh"};
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"getHistoryForWallet",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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
50
src/test/java/blockchain/query/Wallet/ReadWalletTest.java
Normal file
50
src/test/java/blockchain/query/Wallet/ReadWalletTest.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
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.ChaincodeResponse;
|
||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Ignore
|
||||
public class ReadWalletTest {
|
||||
private static Logger logger = Logger.getLogger(ReadWalletTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryWallet() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
try{
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
|
||||
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh2"};
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readWallet",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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue