Merge branch 'features1.4/wallet' into develop-1.4
This commit is contained in:
commit
78686fb060
|
@ -54,8 +54,8 @@ public class TransactionTest {
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||||
tpr.setChaincodeID(cid);
|
tpr.setChaincodeID(cid);
|
||||||
tpr.setFcn("invoke");
|
tpr.setFcn("transaction");
|
||||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh","qerh654d5f5h46q4fdh6h65fh2","2"}); //1 foutre to bitman
|
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","qerh654d5f5h46q4fdh6h65fh01","200"}); //1 foutre to bitman
|
||||||
tpr.setProposalWaitTime(120000);
|
tpr.setProposalWaitTime(120000);
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
||||||
|
|
|
@ -3,7 +3,6 @@ package blockchain.query.User;
|
||||||
import blockchain.client.ChannelClientWrapper;
|
import blockchain.client.ChannelClientWrapper;
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.client.FabricClientWrapper;
|
||||||
import blockchain.configuration.Config;
|
import blockchain.configuration.Config;
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
import blockchain.user.UserContext;
|
||||||
import blockchain.utility.Util;
|
import blockchain.utility.Util;
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
@ -14,18 +13,19 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class RegisterUserTestNewVersion {
|
public class DeleteUserTest {
|
||||||
|
private static Logger logger = Logger.getLogger(DeleteUserTest.class);
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestRegisterUser() {
|
public void TestDeleteUser() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||||
|
|
||||||
try {
|
try{
|
||||||
|
String chaincode = Config.CHAINCODE_NAME;
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
Collection<ProposalResponse> successful = new LinkedList<>();
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
Collection<ProposalResponse> failed = new LinkedList<>();
|
||||||
|
|
||||||
|
@ -42,11 +42,19 @@ public class RegisterUserTestNewVersion {
|
||||||
|
|
||||||
channel.initialize();
|
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();
|
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||||
tpr.setChaincodeID(cid);
|
tpr.setChaincodeID(cid);
|
||||||
tpr.setFcn("registerUser");
|
tpr.setFcn("deleteUser");
|
||||||
tpr.setArgs(new String[]{"UserA","Thomas","MEUNIER","0000000000","gonette"});
|
tpr.setArgs(new String[]{"UserA"});
|
||||||
tpr.setProposalWaitTime(120000);
|
tpr.setProposalWaitTime(120000);
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
||||||
|
@ -65,11 +73,8 @@ public class RegisterUserTestNewVersion {
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -36,7 +36,8 @@ public class ReadUserTest {
|
||||||
|
|
||||||
//String[] args1 = {"chef"}
|
//String[] args1 = {"chef"}
|
||||||
//String[] args1 = {"bitman"};
|
//String[] args1 = {"bitman"};
|
||||||
String[] args1 = {"UserA"};
|
//String[] args1 = {"foutre"};
|
||||||
|
String[] args1 = {"usera"};
|
||||||
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readUser",args1);
|
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readUser",args1);
|
||||||
logger.info("RESPONSE : "+responseQuery);
|
logger.info("RESPONSE : "+responseQuery);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package blockchain.query.User;
|
||||||
import blockchain.client.ChannelClientWrapper;
|
import blockchain.client.ChannelClientWrapper;
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.client.FabricClientWrapper;
|
||||||
import blockchain.configuration.Config;
|
import blockchain.configuration.Config;
|
||||||
|
import blockchain.query.QueryTest;
|
||||||
import blockchain.user.UserContext;
|
import blockchain.user.UserContext;
|
||||||
import blockchain.utility.Util;
|
import blockchain.utility.Util;
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
@ -12,56 +13,63 @@ import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.LinkedList;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
|
||||||
//Test to get balance of a User
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class RegisterUserTest {
|
public class RegisterUserTest {
|
||||||
private static Logger logger = Logger.getLogger(RegisterUserTest.class);
|
|
||||||
|
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestARegisterUser() {
|
public void TestRegisterUser() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
|
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||||
|
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
try {
|
||||||
try{
|
Collection<ProposalResponse> successful = new LinkedList<>();
|
||||||
|
Collection<ProposalResponse> failed = new LinkedList<>();
|
||||||
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
logger.info("userContext : "+user.getName());
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
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:7051");
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||||
channel.addPeer(peer);
|
|
||||||
channel.addEventHub(eventHub);
|
|
||||||
channel.addOrderer(orderer);
|
channel.addOrderer(orderer);
|
||||||
|
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||||
|
channel.addPeer(peer);
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
channel.initialize();
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||||
tpr.setChaincodeID(cid);
|
tpr.setChaincodeID(cid);
|
||||||
tpr.setFcn("register");
|
tpr.setFcn("registerUser");
|
||||||
tpr.setArgs(new String[]{"user_test","100"}); //register user_test with 100
|
tpr.setArgs(new String[]{"usera","Thomas","MEUNIER","0000000000","gonette"});
|
||||||
|
tpr.setProposalWaitTime(120000);
|
||||||
|
|
||||||
Collection<ProposalResponse> responses = channel.sendTransactionProposal(tpr);
|
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
||||||
List<ProposalResponse> invalid = responses.stream().filter(r -> r.isInvalid()).collect(Collectors.toList());
|
for(ProposalResponse response : invokePropResp){
|
||||||
|
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
||||||
if (!invalid.isEmpty()) {
|
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
||||||
invalid.forEach(response -> {
|
successful.add(response);
|
||||||
logger.error(response.getMessage());
|
} else {
|
||||||
});
|
failed.add(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("SEND REQUEST");
|
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
|
|
||||||
logger.info("Event id : "+event.getTransactionID()); //print transaction id
|
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
||||||
|
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
82
src/test/java/blockchain/query/User/UserPermissionTest.java
Normal file
82
src/test/java/blockchain/query/User/UserPermissionTest.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
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;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public class UserPermissionTest {
|
||||||
|
private static Logger logger = Logger.getLogger(UserPermissionTest.class);
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ package blockchain.query.Wallet;
|
||||||
import blockchain.client.ChannelClientWrapper;
|
import blockchain.client.ChannelClientWrapper;
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.client.FabricClientWrapper;
|
||||||
import blockchain.configuration.Config;
|
import blockchain.configuration.Config;
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
import blockchain.user.UserContext;
|
||||||
import blockchain.utility.Util;
|
import blockchain.utility.Util;
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
@ -16,17 +15,18 @@ import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class TransactionTestNewVersion {
|
public class DeleteWalletTest {
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
private static Logger logger = Logger.getLogger(DeleteWalletTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestQueryWallet() {
|
public void TestDeleteWallet() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
String chaincode = Config.CHAINCODE_NAME;
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
Collection<ProposalResponse> successful = new LinkedList<>();
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
Collection<ProposalResponse> failed = new LinkedList<>();
|
||||||
|
@ -55,8 +55,8 @@ public class TransactionTestNewVersion {
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||||
tpr.setChaincodeID(cid);
|
tpr.setChaincodeID(cid);
|
||||||
tpr.setFcn("queryWalletsByOwner");
|
tpr.setFcn("deleteWallet");
|
||||||
tpr.setArgs(new String[]{"bitman"});
|
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00"});
|
||||||
tpr.setProposalWaitTime(120000);
|
tpr.setProposalWaitTime(120000);
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
||||||
|
@ -71,12 +71,15 @@ public class TransactionTestNewVersion {
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
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){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
84
src/test/java/blockchain/query/Wallet/InitWalletTest.java
Normal file
84
src/test/java/blockchain/query/Wallet/InitWalletTest.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
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 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 InitWalletTest {
|
||||||
|
private static Logger logger = Logger.getLogger(InitWalletTest.class);
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,7 +17,7 @@ import java.util.Collection;
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class QueryWalletByOwnerTest {
|
public class QueryWalletByOwnerTest {
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
private static Logger logger = Logger.getLogger(QueryWalletByOwnerTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestQueryWallet() {
|
public void TestQueryWallet() {
|
||||||
|
@ -31,6 +31,7 @@ public class QueryWalletByOwnerTest {
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||||
|
|
||||||
String[] args1 = {"bitman"};
|
String[] args1 = {"bitman"};
|
||||||
|
//String[] args1 = {"usera"};
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"queryWalletsByOwner",args1);
|
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"queryWalletsByOwner",args1);
|
||||||
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
for(ProposalResponse pres : responseQuery){
|
||||||
|
|
|
@ -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 QueryWalletByTypeTest {
|
||||||
|
private static Logger logger = Logger.getLogger(QueryWalletByTypeTest.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 = {"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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,7 +31,8 @@ public class QueryWalletHistory {
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||||
|
|
||||||
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh2"};
|
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh2"};
|
||||||
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh"};
|
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh"};
|
||||||
|
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh00"};
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"getHistoryForWallet",args1);
|
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"getHistoryForWallet",args1);
|
||||||
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
for(ProposalResponse pres : responseQuery){
|
||||||
|
|
|
@ -30,7 +30,9 @@ public class ReadWalletTest {
|
||||||
|
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||||
|
|
||||||
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh2"};
|
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh2"};
|
||||||
|
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh00"};
|
||||||
|
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh01"};
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readWallet",args1);
|
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readWallet",args1);
|
||||||
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
for(ProposalResponse pres : responseQuery){
|
||||||
|
|
82
src/test/java/blockchain/query/Wallet/SetWalletSoldTest.java
Normal file
82
src/test/java/blockchain/query/Wallet/SetWalletSoldTest.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
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 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 {
|
||||||
|
private static Logger logger = Logger.getLogger(SetWalletSoldTest.class);
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
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 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);
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue