Update Wrappers and Test class
Update of QueryWrapper and TransactionWrapper and dependant test class
This commit is contained in:
parent
ee686187e7
commit
a8bf518845
|
@ -35,6 +35,11 @@ public class ChannelClientWrapper {
|
|||
this.fabricClientWrapper=fabricClientWrapper;
|
||||
}
|
||||
|
||||
public Collection<ProposalResponse> queryByChainCode(QueryByChaincodeRequest queryByChaincodeRequest) throws InvalidArgumentException, ProposalException {
|
||||
return channel.queryByChaincode(queryByChaincodeRequest);
|
||||
}
|
||||
|
||||
|
||||
public Collection<ProposalResponse> queryByChainCode(String chaincodeName,String fuctionName, String[] args) throws InvalidArgumentException, ProposalException {
|
||||
QueryByChaincodeRequest request = fabricClientWrapper.getClient().newQueryProposalRequest();
|
||||
ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(chaincodeName).build();
|
||||
|
|
|
@ -39,5 +39,4 @@ public class FabricClientWrapper {
|
|||
Peer peer = client.newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
return client.queryChannels(peer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,49 +5,54 @@ 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.ChaincodeID;
|
||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.hyperledger.fabric.sdk.QueryByChaincodeRequest;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class QueryWrapper {
|
||||
private static Logger logger = Logger.getLogger(QueryWrapper.class);
|
||||
|
||||
public String getUserBalance(String userHashId){
|
||||
public String sendQuery(String functionName,String[] args) {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1, "admin");
|
||||
String response = null;
|
||||
try{
|
||||
UserContext userContext = Util.readUserContext(Config.ORG1,"User-org1");
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
||||
|
||||
try {
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
|
||||
String[] args = {userHashId};
|
||||
ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||
QueryByChaincodeRequest queryByChaincodeRequest = fabricClientWrapper.getClient().newQueryProposalRequest();
|
||||
queryByChaincodeRequest.setArgs(args);
|
||||
queryByChaincodeRequest.setFcn(functionName);
|
||||
queryByChaincodeRequest.setChaincodeID(chaincodeID);
|
||||
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"query",args);
|
||||
for(ProposalResponse pres : responseQuery){
|
||||
ChaincodeResponse.Status status = pres.getStatus();
|
||||
if(status.getStatus()!=200){
|
||||
throw new Exception(pres.getMessage());
|
||||
Collection<ProposalResponse> queryProposals;
|
||||
|
||||
try {
|
||||
queryProposals = channelClientWrapper.queryByChainCode(queryByChaincodeRequest);
|
||||
} catch (Exception e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
|
||||
response = new String(pres.getChaincodeActionResponsePayload());
|
||||
for (ProposalResponse proposalResponse : queryProposals) {
|
||||
if (!proposalResponse.isVerified() || proposalResponse.getStatus() != ChaincodeResponse.Status.SUCCESS) {
|
||||
logger.error("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status : " + proposalResponse.getStatus() +
|
||||
". Message : " + proposalResponse.getMessage() + ". Was verified : " + proposalResponse.isVerified());
|
||||
} else {
|
||||
response = new String(proposalResponse.getChaincodeActionResponsePayload());
|
||||
logger.info("Query payload : " + response + " from peer : " + proposalResponse.getPeer().getName());
|
||||
}
|
||||
}catch (Exception e){
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
if(response==null) response = "Error";
|
||||
return response;
|
||||
}
|
||||
|
||||
public String getUser(String userHashId){
|
||||
return "";
|
||||
}
|
||||
|
||||
public List<String> getUserLastTransactions(String userHashId){
|
||||
List<String> transactions = new ArrayList<>();
|
||||
return transactions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,36 +5,65 @@ import blockchain.client.FabricClientWrapper;
|
|||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.hyperledger.fabric.sdk.BlockEvent;
|
||||
import org.hyperledger.fabric.sdk.ChaincodeID;
|
||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||
import org.hyperledger.fabric.sdk.TransactionProposalRequest;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class TransactionWrapper {
|
||||
private static Logger logger = Logger.getLogger(TransactionWrapper.class);
|
||||
|
||||
public BlockEvent.TransactionEvent sendTransaction(String functionName, String[] args){
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
public String sendTransaction(String from, String to, String amount){
|
||||
try{
|
||||
UserContext userContext = Util.readUserContext(Config.ORG1,"User-org1");
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
||||
FabricClientWrapper fabricClientWrapper;
|
||||
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
if(user != null){
|
||||
fabricClientWrapper = new FabricClientWrapper(user);
|
||||
} else {
|
||||
throw new Exception("No UserContext");
|
||||
}
|
||||
|
||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||
|
||||
//INIT CHANNEL FOR QUERY
|
||||
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();
|
||||
//
|
||||
|
||||
//Prepare transaction
|
||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||
tpr.setChaincodeID(cid);
|
||||
tpr.setFcn("invoke");
|
||||
tpr.setArgs(new String[]{from,to,amount});
|
||||
tpr.setFcn(functionName);
|
||||
tpr.setArgs(args);
|
||||
tpr.setProposalWaitTime(120000);
|
||||
|
||||
Collection<ProposalResponse> responses = channelClientWrapper.sendTransactionProposal(tpr);
|
||||
System.out.println("VERIFY HERE, TRY TO SEND TRANSACTION");
|
||||
BlockEvent.TransactionEvent event = channelClientWrapper.sendTransaction(responses);
|
||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr); //Send proposal transaction
|
||||
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("Failed transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
||||
}
|
||||
}
|
||||
|
||||
return event.getTransactionID();
|
||||
|
||||
}catch (Exception e){
|
||||
return channelClientWrapper.sendTransaction(successful); //Send successful transaction to orderer
|
||||
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -4,10 +4,12 @@ import blockchain.query.QueryWrapper;
|
|||
|
||||
public class BlockchainQueryImplementation {
|
||||
|
||||
/*
|
||||
public Double getUserBalance(String userHash){
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String result = queryWrapper.getUserBalance(userHash);
|
||||
Double balance = Double.parseDouble(result);
|
||||
return balance;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import restImplementation.BlockchainQueryImplementation;
|
|||
@RequestMapping(value = "/api/rest/query")
|
||||
public class BlockchainQueryResource {
|
||||
|
||||
/*
|
||||
@RequestMapping(value = "/balance", method = RequestMethod.GET ,params = {"userHash"},produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<StringResponse> getUserBalance(@RequestParam(value = "userHash") String userHash){
|
||||
|
@ -23,6 +24,7 @@ public class BlockchainQueryResource {
|
|||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,78 +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.Ignore;
|
||||
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
|
||||
@Ignore
|
||||
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[]{"b","a","25"}); //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());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
logger.info("SEND TRANSACTION");
|
||||
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
|
||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,64 +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.Ignore;
|
||||
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"
|
||||
@Ignore
|
||||
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,36 +1,32 @@
|
|||
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.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
//Test to show channels on a node
|
||||
@Ignore
|
||||
public class QueryChannelTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
private static Logger logger = Logger.getLogger(QueryChannelTest.class);
|
||||
|
||||
@Test
|
||||
public void testQ(){
|
||||
public void TestQueryForChannels(){
|
||||
BasicConfigurator.configure();
|
||||
UserContext userContext = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
try{
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
||||
Set<String> channels = fabricClientWrapper.queryForChannels();
|
||||
|
||||
logger.info("CHANNELS : "+channels);
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,53 +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.Ignore;
|
||||
import org.junit.Test;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
//Test to get balance of a User
|
||||
@Ignore
|
||||
public class QueryTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void TestAQuery() {
|
||||
BasicConfigurator.configure();
|
||||
|
||||
//UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||
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 = {"a"};
|
||||
String[] args1 = {"chef"};
|
||||
//String[] args1 = {"bitman"};
|
||||
//String[] args1 = {"user_test"};
|
||||
|
||||
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,79 +1,27 @@
|
|||
package blockchain.query.Transaction;
|
||||
|
||||
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 blockchain.query.TransactionWrapper;
|
||||
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 TransactionTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
private static Logger logger = Logger.getLogger(TransactionTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryWalletHistory() {
|
||||
public void TestTransaction() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"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("transaction");
|
||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","qerh654d5f5h46q4fdh6h65fh01","200"}); //1 foutre to bitman
|
||||
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
|
||||
|
||||
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "transaction";
|
||||
String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00","qerh654d5f5hdsf1515","200"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
package blockchain.query.User;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
|
||||
import blockchain.query.TransactionWrapper;
|
||||
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 DeleteUserTest {
|
||||
|
@ -22,57 +16,12 @@ public class DeleteUserTest {
|
|||
@Test
|
||||
public void TestDeleteUser() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"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("deleteUser");
|
||||
tpr.setArgs(new String[]{"UserA"});
|
||||
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
|
||||
|
||||
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "deleteUser";
|
||||
String[] args = new String[]{"usera"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,70 +1,39 @@
|
|||
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 blockchain.query.QueryWrapper;
|
||||
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 javax.json.Json;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
@Ignore
|
||||
public class ReadUserTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
private static Logger logger = Logger.getLogger(ReadUserTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryReadUser() {
|
||||
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 = {"chef"}
|
||||
//String[] args1 = {"bitman"};
|
||||
//String[] args1 = {"foutre"};
|
||||
String[] args1 = {"usera"};
|
||||
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readUser",args1);
|
||||
logger.info("RESPONSE : "+responseQuery);
|
||||
logger.info("RESPONSE : "+responseQuery.size());
|
||||
|
||||
String response = null;
|
||||
|
||||
for(ProposalResponse pres : responseQuery){
|
||||
ChaincodeResponse.Status status = pres.getStatus();
|
||||
|
||||
if(status.getStatus()!=200){
|
||||
throw new Exception(pres.getMessage());
|
||||
}
|
||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
||||
response = stringResponse;
|
||||
logger.info("RESPONSE : "+stringResponse);
|
||||
}
|
||||
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String functionName = "readUser";
|
||||
String[] args = new String[]{"usera"};
|
||||
String response = queryWrapper.sendQuery(functionName,args);
|
||||
if(response != null){
|
||||
JsonReader reader = Json.createReader(new StringReader(response));
|
||||
JsonObject userInfo = reader.readObject();
|
||||
logger.info("userAssociation : "+userInfo.getString("userAssociation"));
|
||||
logger.info("userFirstName : "+userInfo.getString("userFirstName"));
|
||||
|
||||
|
||||
} else {
|
||||
throw new Exception("Response is null");
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,75 +1,28 @@
|
|||
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 blockchain.query.TransactionWrapper;
|
||||
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 RegisterUserTest {
|
||||
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
private static Logger logger = Logger.getLogger(RegisterUserTest.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","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
|
||||
|
||||
|
||||
|
||||
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "registerUser";
|
||||
String[] args = new String[]{"usera","Thomas","MEUNIER","0000000000","gonette"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,13 @@
|
|||
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 blockchain.query.TransactionWrapper;
|
||||
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 UserPermissionTest {
|
||||
|
@ -23,60 +16,14 @@ public class UserPermissionTest {
|
|||
@Test
|
||||
public void TestUserPermission() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"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("setUserPermission");
|
||||
tpr.setArgs(new String[]{"UserA"});
|
||||
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
|
||||
|
||||
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "setUserPermission";
|
||||
String[] args = new String[]{"usera"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
package blockchain.query.Wallet;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
|
||||
import blockchain.query.TransactionWrapper;
|
||||
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 DeleteWalletTest {
|
||||
|
@ -22,64 +16,14 @@ public class DeleteWalletTest {
|
|||
@Test
|
||||
public void TestDeleteWallet() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"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("deleteWallet");
|
||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00"});
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "deleteWallet";
|
||||
String[] args = new String[]{"qerh654d5f5hdsf1515"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,13 @@
|
|||
package blockchain.query.Wallet;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.query.User.UserPermissionTest;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
|
||||
import blockchain.query.TransactionWrapper;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.*;
|
||||
import org.hyperledger.fabric.sdk.BlockEvent;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
@Ignore
|
||||
public class InitWalletTest {
|
||||
|
@ -23,60 +16,12 @@ public class InitWalletTest {
|
|||
@Test
|
||||
public void TestInitWallet() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"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("initWallet");
|
||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","client","bitman"});
|
||||
//tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh01","client","foutre"});
|
||||
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("failed "+response.getChaincodeActionResponsePayload());
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "initWallet";
|
||||
String[] args = new String[]{"qerh654d5f5hdsf1515","client","usera"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,51 +1,29 @@
|
|||
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 blockchain.query.QueryWrapper;
|
||||
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 QueryWalletByOwnerTest {
|
||||
private static Logger logger = Logger.getLogger(QueryWalletByOwnerTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryWallet() {
|
||||
public void TestQueryWalletByOwnerTest() {
|
||||
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 = {"bitman"};
|
||||
//String[] args1 = {"usera"};
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"queryWalletsByOwner",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);
|
||||
}
|
||||
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String functionName = "queryWalletsByOwner";
|
||||
String[] args = new String[]{"usera"};
|
||||
//String[] args = new String[]{"bitman"};
|
||||
String response = queryWrapper.sendQuery(functionName,args);
|
||||
logger.info("response : "+response);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,47 +1,26 @@
|
|||
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 blockchain.query.QueryWrapper;
|
||||
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 QueryWalletByTypeTest {
|
||||
private static Logger logger = Logger.getLogger(QueryWalletByTypeTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryWallet() {
|
||||
public void TestQueryWalletByTypeTest() {
|
||||
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 = {"client"};
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"queryWalletsByType",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);
|
||||
}
|
||||
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String functionName = "queryWalletsByType";
|
||||
String[] args = new String[]{"client"};
|
||||
String response = queryWrapper.sendQuery(functionName,args);
|
||||
logger.info("response : "+response);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,53 +1,28 @@
|
|||
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 blockchain.query.QueryWrapper;
|
||||
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);
|
||||
private static Logger logger = Logger.getLogger(QueryWalletHistory.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"};
|
||||
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh00"};
|
||||
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);
|
||||
}
|
||||
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String functionName = "getHistoryForWallet";
|
||||
String[] args = new String[]{"qerh654d5f5hdsf1515"};
|
||||
String response = queryWrapper.sendQuery(functionName,args);
|
||||
logger.info("response : "+response);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,52 +1,28 @@
|
|||
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 blockchain.query.QueryWrapper;
|
||||
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() {
|
||||
public void TestReadWalletTest() {
|
||||
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 = {"qerh654d5f5h46q4fdh6h65fh00"};
|
||||
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh01"};
|
||||
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);
|
||||
}
|
||||
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String functionName = "readWallet";
|
||||
String[] args = new String[]{"qerh654d5f5hdsf1515"};
|
||||
String response = queryWrapper.sendQuery(functionName,args);
|
||||
logger.info("response : "+response);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
package blockchain.query.Wallet;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
|
||||
import blockchain.query.TransactionWrapper;
|
||||
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 SetWalletSoldTest {
|
||||
|
@ -22,59 +16,12 @@ public class SetWalletSoldTest {
|
|||
@Test
|
||||
public void TestSetWalletSold() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"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();
|
||||
|
||||
//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("setSoldOnWallet");
|
||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","3000"});
|
||||
//tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh01","100"});
|
||||
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("failed "+response.getChaincodeActionResponsePayload());
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "setSoldOnWallet";
|
||||
String[] args = new String[]{"qerh654d5f5hdsf1515","500"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,83 +1,30 @@
|
|||
package blockchain.query.Wallet;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
|
||||
import blockchain.query.TransactionWrapper;
|
||||
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 TransferWalletTest {
|
||||
private static Logger logger = Logger.getLogger(DeleteWalletTest.class);
|
||||
private static Logger logger = Logger.getLogger(TransferWalletTest.class);
|
||||
|
||||
@Test
|
||||
public void TestTransfertWallet() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"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("transferWallet");
|
||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","bitman"});
|
||||
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
|
||||
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "transferWallet";
|
||||
String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00","bitman"};
|
||||
//String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00","usera"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package blockchain.queryWrapper;
|
||||
|
||||
import blockchain.query.QueryWrapper;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore
|
||||
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,28 +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.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore
|
||||
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("b","a","150"); //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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue