58 lines
2.2 KiB
Java
58 lines
2.2 KiB
Java
package monnethic.mobile.test.blockchain;
|
|
|
|
import android.content.Context;
|
|
import android.support.test.InstrumentationRegistry;
|
|
|
|
import org.hyperledger.fabric.sdk.ProposalResponse;
|
|
import org.junit.Test;
|
|
|
|
import java.util.Collection;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
import monnethic.mobile.blockchain.client.CAClientWrapper;
|
|
import monnethic.mobile.blockchain.client.ChannelClientWrapper;
|
|
import monnethic.mobile.blockchain.client.FabriClientWrapper;
|
|
import monnethic.mobile.blockchain.network.Config;
|
|
import monnethic.mobile.blockchain.participant.UserContext;
|
|
import monnethic.mobile.test.blockchain.Utility.UtilTest;
|
|
|
|
|
|
public class TestQuery {
|
|
@Test
|
|
public void TestAQueryChainCode() throws Exception {
|
|
// Test query for user a on blockchain
|
|
try{
|
|
String query = "query";
|
|
String[] args1 = {"a"};
|
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
|
|
|
String caUrl = Config.CA_ORG1_URL;
|
|
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null,null,null);
|
|
|
|
UserContext adminContext = new UserContext();
|
|
adminContext.setName(Config.ADMIN);
|
|
adminContext.setAffiliation(Config.ORG1);
|
|
adminContext.setMspId(Config.ORG1_MSP);
|
|
|
|
caClientWrapper.setAdminContext(adminContext);
|
|
adminContext = caClientWrapper.enrollAdmin(appContext,Config.ADMIN,Config.ADMIN_PASSWORD,Config.ORG1);
|
|
|
|
FabriClientWrapper fabriClientWrapper = new FabriClientWrapper(adminContext);
|
|
ChannelClientWrapper channelClientWrapper = fabriClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
|
|
Logger.getLogger(TestQuery.class.getName()).log(Level.INFO, "Querying for USER A ...");
|
|
|
|
Collection<ProposalResponse> responsesQuery = channelClientWrapper.queryByChainCode(Config.CHAINCODE_NAME,query,args1);
|
|
|
|
for(ProposalResponse pres : responsesQuery){
|
|
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
Logger.getLogger(TestQuery.class.getName()).log(Level.INFO, stringResponse);
|
|
}
|
|
|
|
} catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|