|
28 | 28 |
|
29 | 29 | public class PeerClientTest {
|
30 | 30 |
|
31 |
| -// static Channel testChain = null; |
32 |
| -// static ChaincodeResponse deployResponse = null; |
33 |
| -// static ChaincodeResponse javaDeployResponse = null; |
| 31 | +// static Channel testChain = null; |
| 32 | +// static ChaincodeResponse deployResponse = null; |
| 33 | +// static ChaincodeResponse javaDeployResponse = null; |
34 | 34 | //
|
35 |
| -// @BeforeClass |
36 |
| -// public static void setupChain() { |
37 |
| -// testChain = new Channel("chain1"); |
38 |
| -// try { |
39 |
| -// testChain.setMemberServicesUrl("grpc://localhost:7054", null); |
40 |
| -// testChain.setKeyValStore(new SampleStore(System.getProperty("user.home")+"/test.properties")); |
41 |
| -// testChain.addPeer("grpc://localhost:7051", null); |
42 |
| -// //testChain.setDevMode(true); |
43 |
| -// SampleUser registrar = testChain.getUser("admin"); |
44 |
| -// if (!registrar.isEnrolled()) { |
45 |
| -// registrar = testChain.enroll("admin", "Xurw3yU9zI0l"); |
46 |
| -// } |
47 |
| -// testChain.setRegistrar(registrar); |
48 |
| -// deployResponse = deploy(); |
49 |
| -// javaDeployResponse = deployJava(); |
50 |
| -// TimeUnit.SECONDS.sleep(10);// deployment takes time, so wait for it to complete before making a query or invoke call |
51 |
| -// } catch(CertificateException | RegistrationException | EnrollmentException | InterruptedException cex) { |
52 |
| -// cex.printStackTrace();// TODO: Handle the exception properly |
53 |
| -// } |
54 |
| -// } |
| 35 | +// @BeforeClass |
| 36 | +// public static void setupChain() { |
| 37 | +// testChain = new Channel("chain1"); |
| 38 | +// try { |
| 39 | +// testChain.setMemberServicesUrl("grpc://localhost:7054", null); |
| 40 | +// testChain.setKeyValStore(new SampleStore(System.getProperty("user.home")+"/test.properties")); |
| 41 | +// testChain.addPeer("grpc://localhost:7051", null); |
| 42 | +// //testChain.setDevMode(true); |
| 43 | +// SampleUser registrar = testChain.getUser("admin"); |
| 44 | +// if (!registrar.isEnrolled()) { |
| 45 | +// registrar = testChain.enroll("admin", "Xurw3yU9zI0l"); |
| 46 | +// } |
| 47 | +// testChain.setRegistrar(registrar); |
| 48 | +// deployResponse = deploy(); |
| 49 | +// javaDeployResponse = deployJava(); |
| 50 | +// TimeUnit.SECONDS.sleep(10);// deployment takes time, so wait for it to complete before making a query or invoke call |
| 51 | +// } catch(CertificateException | RegistrationException | EnrollmentException | InterruptedException cex) { |
| 52 | +// cex.printStackTrace();// TODO: Handle the exception properly |
| 53 | +// } |
| 54 | +// } |
55 | 55 | //
|
56 | 56 | //
|
57 |
| -// public static ChaincodeResponse deploy() throws RegistrationException, EnrollmentException, ProposalException { |
58 |
| -// InstallProposalRequest request = new InstallProposalRequest(); |
59 |
| -// request.setChaincodePath("github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"); |
60 |
| -// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000"))); |
61 |
| -// SampleUser user = getUser("User1", "bank_a"); |
62 |
| -// request.setChaincodeName("mycc"); |
63 |
| -// request.setChaincodeLanguage(ChaincodeLanguage.GO_LANG); |
64 |
| -// return user.deploy(request); |
65 |
| -// } |
| 57 | +// public static ChaincodeResponse deploy() throws RegistrationException, EnrollmentException, ProposalException { |
| 58 | +// InstallProposalRequest request = new InstallProposalRequest(); |
| 59 | +// request.setChaincodePath("github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"); |
| 60 | +// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000"))); |
| 61 | +// SampleUser user = getUser("User1", "bank_a"); |
| 62 | +// request.setChaincodeName("mycc"); |
| 63 | +// request.setChaincodeLanguage(ChaincodeLanguage.GO_LANG); |
| 64 | +// return user.deploy(request); |
| 65 | +// } |
66 | 66 | //
|
67 |
| -// public static ChaincodeResponse deployJava() throws RegistrationException, EnrollmentException { |
68 |
| -// InstallProposalRequest request = new InstallProposalRequest(); |
69 |
| -// request.setChaincodePath(System.getenv("GOPATH")+"/src/github.com/hyperledger/fabric/examples/chaincode/java/Example"); |
70 |
| -// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000"))); |
71 |
| -// SampleUser user = getUser("User1", "bank_a"); |
72 |
| -// request.setChaincodeName("myccj"); |
73 |
| -// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); |
74 |
| -// return user.deploy(request); |
| 67 | +// public static ChaincodeResponse deployJava() throws RegistrationException, EnrollmentException { |
| 68 | +// InstallProposalRequest request = new InstallProposalRequest(); |
| 69 | +// request.setChaincodePath(System.getenv("GOPATH")+"/src/github.com/hyperledger/fabric/examples/chaincode/java/Example"); |
| 70 | +// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000"))); |
| 71 | +// SampleUser user = getUser("User1", "bank_a"); |
| 72 | +// request.setChaincodeName("myccj"); |
| 73 | +// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); |
| 74 | +// return user.deploy(request); |
75 | 75 | //
|
76 |
| -// } |
| 76 | +// } |
77 | 77 | //
|
78 |
| -// @Test |
79 |
| -// public void testQuery() throws RegistrationException, EnrollmentException, ChaincodeException { |
80 |
| -// testInvoke(); // the amount is stored |
81 |
| -// QueryRequest request = new QueryRequest(); |
82 |
| -// request.setArgs(new ArrayList<>(Arrays.asList("query", "a"))); |
83 |
| -// request.setChaincodeID(deployResponse.getChaincodeID()); |
84 |
| -// request.setChaincodeName(deployResponse.getChaincodeID()); |
85 |
| -// SampleUser user = getUser("User1", "bank_a"); |
86 |
| -// user.query(request); |
87 |
| -// } |
| 78 | +// @Test |
| 79 | +// public void testQuery() throws RegistrationException, EnrollmentException, ChaincodeException { |
| 80 | +// testInvoke(); // the amount is stored |
| 81 | +// QueryRequest request = new QueryRequest(); |
| 82 | +// request.setArgs(new ArrayList<>(Arrays.asList("query", "a"))); |
| 83 | +// request.setChaincodeID(deployResponse.getChaincodeID()); |
| 84 | +// request.setChaincodeName(deployResponse.getChaincodeID()); |
| 85 | +// SampleUser user = getUser("User1", "bank_a"); |
| 86 | +// user.query(request); |
| 87 | +// } |
88 | 88 | //
|
89 |
| -// @Test |
90 |
| -// public void testInvoke() throws RegistrationException, EnrollmentException, ChaincodeException { |
91 |
| -// InvokeRequest request = new InvokeRequest(); |
92 |
| -// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200"))); |
93 |
| -// request.setChaincodeID(deployResponse.getChaincodeID()); |
94 |
| -// request.setChaincodeName(deployResponse.getChaincodeID()); |
95 |
| -// SampleUser user = getUser("User1", "bank_a"); |
96 |
| -// user.invoke(request); |
97 |
| -// } |
| 89 | +// @Test |
| 90 | +// public void testInvoke() throws RegistrationException, EnrollmentException, ChaincodeException { |
| 91 | +// InvokeRequest request = new InvokeRequest(); |
| 92 | +// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200"))); |
| 93 | +// request.setChaincodeID(deployResponse.getChaincodeID()); |
| 94 | +// request.setChaincodeName(deployResponse.getChaincodeID()); |
| 95 | +// SampleUser user = getUser("User1", "bank_a"); |
| 96 | +// user.invoke(request); |
| 97 | +// } |
98 | 98 | //
|
99 |
| -// @Test |
100 |
| -// public void testQueryJava() throws RegistrationException, EnrollmentException, ChaincodeException { |
101 |
| -// testInvokeJava(); |
102 |
| -// QueryRequest request = new QueryRequest(); |
103 |
| -// request.setArgs(new ArrayList<>(Arrays.asList("query", "a"))); |
104 |
| -// request.setChaincodeID(javaDeployResponse.getChaincodeID()); |
105 |
| -// request.setChaincodeName(javaDeployResponse.getChaincodeID()); |
106 |
| -// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); |
107 |
| -// SampleUser user = getUser("User1", "bank_a"); |
108 |
| -// user.query(request); |
109 |
| -// } |
| 99 | +// @Test |
| 100 | +// public void testQueryJava() throws RegistrationException, EnrollmentException, ChaincodeException { |
| 101 | +// testInvokeJava(); |
| 102 | +// QueryRequest request = new QueryRequest(); |
| 103 | +// request.setArgs(new ArrayList<>(Arrays.asList("query", "a"))); |
| 104 | +// request.setChaincodeID(javaDeployResponse.getChaincodeID()); |
| 105 | +// request.setChaincodeName(javaDeployResponse.getChaincodeID()); |
| 106 | +// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); |
| 107 | +// SampleUser user = getUser("User1", "bank_a"); |
| 108 | +// user.query(request); |
| 109 | +// } |
110 | 110 | //
|
111 |
| -// @Test |
112 |
| -// public void testInvokeJava() throws RegistrationException, EnrollmentException, ChaincodeException { |
113 |
| -// InvokeRequest request = new InvokeRequest(); |
114 |
| -// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200"))); |
115 |
| -// request.setChaincodeID(javaDeployResponse.getChaincodeID()); |
116 |
| -// request.setChaincodeName(javaDeployResponse.getChaincodeID()); |
117 |
| -// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); |
118 |
| -// SampleUser user = getUser("User1", "bank_a"); |
119 |
| -// user.invoke(request); |
120 |
| -// } |
| 111 | +// @Test |
| 112 | +// public void testInvokeJava() throws RegistrationException, EnrollmentException, ChaincodeException { |
| 113 | +// InvokeRequest request = new InvokeRequest(); |
| 114 | +// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200"))); |
| 115 | +// request.setChaincodeID(javaDeployResponse.getChaincodeID()); |
| 116 | +// request.setChaincodeName(javaDeployResponse.getChaincodeID()); |
| 117 | +// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); |
| 118 | +// SampleUser user = getUser("User1", "bank_a"); |
| 119 | +// user.invoke(request); |
| 120 | +// } |
121 | 121 | //
|
122 |
| -// private static SampleUser getUser(String enrollmentId, String affiliation) throws RegistrationException, EnrollmentException { |
123 |
| -// SampleUser user = testChain.getUser(enrollmentId); |
124 |
| -// if (!user.isRegistered()) { |
125 |
| -// RegistrationRequest registrationRequest = new RegistrationRequest(); |
126 |
| -// registrationRequest.setEnrollmentID(enrollmentId); |
127 |
| -// registrationRequest.setAffiliation(affiliation); |
128 |
| -// //registrationRequest.setAccount(); TODO setAccount missing from registrationRequest? |
129 |
| -// user = testChain.registerAndEnroll(registrationRequest); |
130 |
| -// } else if (!user.isEnrolled()) { |
131 |
| -// user = testChain.enroll(enrollmentId, user.getEnrollmentSecret()); |
132 |
| -// } |
133 |
| -// return user; |
134 |
| -// } |
| 122 | +// private static SampleUser getUser(String enrollmentId, String affiliation) throws RegistrationException, EnrollmentException { |
| 123 | +// SampleUser user = testChain.getUser(enrollmentId); |
| 124 | +// if (!user.isRegistered()) { |
| 125 | +// RegistrationRequest registrationRequest = new RegistrationRequest(); |
| 126 | +// registrationRequest.setEnrollmentID(enrollmentId); |
| 127 | +// registrationRequest.setAffiliation(affiliation); |
| 128 | +// //registrationRequest.setAccount(); TODO setAccount missing from registrationRequest? |
| 129 | +// user = testChain.registerAndEnroll(registrationRequest); |
| 130 | +// } else if (!user.isEnrolled()) { |
| 131 | +// user = testChain.enroll(enrollmentId, user.getEnrollmentSecret()); |
| 132 | +// } |
| 133 | +// return user; |
| 134 | +// } |
135 | 135 | }
|
0 commit comments