@@ -84,12 +84,13 @@ public void testClient() {
84
84
BcosSDK sdk = BcosSDK .build (configFile );
85
85
86
86
Client client = sdk .getClient (GROUP );
87
- Assert .assertThrows (BcosSDKException .class ,
88
- () -> sdk .getClient ("errorClient" ));
87
+ Assert .assertThrows (BcosSDKException .class , () -> sdk .getClient ("errorClient" ));
89
88
90
- sdk .registerBlockNotifier (GROUP ,
89
+ sdk .registerBlockNotifier (
90
+ GROUP ,
91
91
(groupId , blockNumber ) ->
92
- System .out .println ("New block, group: " + groupId + ", blockNumber: " + blockNumber ));
92
+ System .out .println (
93
+ "New block, group: " + groupId + ", blockNumber: " + blockNumber ));
93
94
94
95
// test getBlockNumber
95
96
BlockNumber blockNumber = client .getBlockNumber ();
@@ -100,7 +101,8 @@ public void testClient() {
100
101
101
102
// test getBlockByNumber only header
102
103
BcosBlock onlyHeader = client .getBlockByNumber (blockNumber .getBlockNumber (), true , false );
103
- Assert .assertEquals (onlyHeader .getBlock ().getHash (), blockHashByNumber .getBlockHashByNumber ());
104
+ Assert .assertEquals (
105
+ onlyHeader .getBlock ().getHash (), blockHashByNumber .getBlockHashByNumber ());
104
106
105
107
// test getBlockByNumber
106
108
BcosBlock block = client .getBlockByNumber (blockNumber .getBlockNumber (), false , false );
@@ -132,7 +134,12 @@ public void testClient() {
132
134
133
135
// get getTotalTransactionCount
134
136
TotalTransactionCount totalTransactionCount = client .getTotalTransactionCount ();
135
- Assert .assertTrue (Integer .parseInt (totalTransactionCount .getTotalTransactionCount ().getTransactionCount ()) >= 0 );
137
+ Assert .assertTrue (
138
+ Integer .parseInt (
139
+ totalTransactionCount
140
+ .getTotalTransactionCount ()
141
+ .getTransactionCount ())
142
+ >= 0 );
136
143
137
144
// get getPeers
138
145
Peers peers = client .getPeers ();
@@ -145,11 +152,12 @@ public void testClient() {
145
152
// get getSyncStatus
146
153
SyncStatus syncStatus = client .getSyncStatus ();
147
154
System .out .println (syncStatus .getSyncStatus ().toString ());
155
+ client .stop ();
156
+ client .destroy ();
148
157
}
149
158
150
159
@ Test
151
- public void testClientAsync ()
152
- throws ConfigException , ExecutionException , InterruptedException {
160
+ public void testClientAsync () throws ConfigException , ExecutionException , InterruptedException {
153
161
154
162
ConfigOption configOption = Config .load (configFile );
155
163
Client client = Client .build (GROUP , configOption );
@@ -172,8 +180,7 @@ public void onResponse(BcosBlock bcosBlock) {
172
180
@ Override
173
181
public void onError (Response errorResponse ) {
174
182
System .out .println (
175
- "getBlockByNumberAsync failed: " +
176
- errorResponse .getErrorMessage ());
183
+ "getBlockByNumberAsync failed: " + errorResponse .getErrorMessage ());
177
184
}
178
185
});
179
186
genesisHash [0 ] = hashFuture .get ();
@@ -187,22 +194,27 @@ public void onError(Response errorResponse) {
187
194
@ Override
188
195
public void onResponse (BcosBlock bcosBlock ) {
189
196
System .out .println ("getBlockByNumberAsync=" + bcosBlock .getBlock ());
190
- client .getBlockHashByNumberAsync (BigInteger .valueOf (bcosBlock .getBlock ().getNumber ()), new RespCallback <BlockHash >() {
191
- @ Override
192
- public void onResponse (BlockHash blockHash ) {
193
- System .out .println ("getBlockHashByNumberAsync=" + blockHash .getBlockHashByNumber ());
194
- }
195
-
196
- @ Override
197
- public void onError (Response errorResponse ) {
198
- System .out .println (errorResponse );
199
- }
200
- });
197
+ client .getBlockHashByNumberAsync (
198
+ BigInteger .valueOf (bcosBlock .getBlock ().getNumber ()),
199
+ new RespCallback <BlockHash >() {
200
+ @ Override
201
+ public void onResponse (BlockHash blockHash ) {
202
+ System .out .println (
203
+ "getBlockHashByNumberAsync="
204
+ + blockHash .getBlockHashByNumber ());
205
+ }
206
+
207
+ @ Override
208
+ public void onError (Response errorResponse ) {
209
+ System .out .println (errorResponse );
210
+ }
211
+ });
201
212
}
202
213
203
214
@ Override
204
215
public void onError (Response errorResponse ) {
205
- System .out .println ("getBlockByNumberAsync failed: " + errorResponse .getErrorMessage ());
216
+ System .out .println (
217
+ "getBlockByNumberAsync failed: " + errorResponse .getErrorMessage ());
206
218
}
207
219
});
208
220
@@ -246,7 +258,12 @@ public void onError(Response errorResponse) {
246
258
247
259
// get getTotalTransactionCount
248
260
TotalTransactionCount totalTransactionCount = client .getTotalTransactionCount ();
249
- Assert .assertTrue (Integer .parseInt (totalTransactionCount .getTotalTransactionCount ().getTransactionCount ()) >= 0 );
261
+ Assert .assertTrue (
262
+ Integer .parseInt (
263
+ totalTransactionCount
264
+ .getTotalTransactionCount ()
265
+ .getTransactionCount ())
266
+ >= 0 );
250
267
251
268
// get getPeers
252
269
Peers peers = client .getPeers ();
@@ -256,17 +273,23 @@ public void onError(Response errorResponse) {
256
273
SyncStatus syncStatus = client .getSyncStatus ();
257
274
System .out .println (syncStatus .getSyncStatus ());
258
275
259
- client .getTotalTransactionCountAsync (new RespCallback <TotalTransactionCount >() {
260
- @ Override
261
- public void onResponse (TotalTransactionCount totalTransactionCount ) {
262
- Assert .assertTrue (Integer .parseInt (totalTransactionCount .getTotalTransactionCount ().getTransactionCount ()) >= 0 );
263
- }
276
+ client .getTotalTransactionCountAsync (
277
+ new RespCallback <TotalTransactionCount >() {
278
+ @ Override
279
+ public void onResponse (TotalTransactionCount totalTransactionCount ) {
280
+ Assert .assertTrue (
281
+ Integer .parseInt (
282
+ totalTransactionCount
283
+ .getTotalTransactionCount ()
284
+ .getTransactionCount ())
285
+ >= 0 );
286
+ }
264
287
265
- @ Override
266
- public void onError (Response errorResponse ) {
267
- System .out .println (errorResponse );
268
- }
269
- });
288
+ @ Override
289
+ public void onError (Response errorResponse ) {
290
+ System .out .println (errorResponse );
291
+ }
292
+ });
270
293
271
294
// test getBlockNumber
272
295
client .getBlockNumberAsync (
@@ -282,10 +305,13 @@ public void onError(Response errorResponse) {
282
305
"getBlockNumberAsync failed: " + errorResponse .getErrorMessage ());
283
306
}
284
307
});
308
+
309
+ client .stop ();
310
+ client .destroy ();
285
311
}
286
312
287
313
@ Test
288
- public void testHelloWorldInSolidity () throws ConfigException , JniException , ContractException {
314
+ public void testHelloWorldInSolidity () throws ConfigException , ContractException {
289
315
290
316
ConfigOption configOption = Config .load (configFile );
291
317
Client client = Client .build (GROUP , configOption );
@@ -309,17 +335,19 @@ public void testHelloWorldInSolidity() throws ConfigException, JniException, Con
309
335
helloWorld = HelloWorld .deploy (client , cryptoKeyPair );
310
336
System .out .println ("helloworld address :" + helloWorld .getContractAddress ());
311
337
312
- client .getABIAsync (helloWorld .getContractAddress (), new RespCallback <Abi >() {
313
- @ Override
314
- public void onResponse (Abi abi ) {
315
- Assert .assertEquals (HelloWorld .getABI (), abi .getABI ());
316
- }
338
+ client .getABIAsync (
339
+ helloWorld .getContractAddress (),
340
+ new RespCallback <Abi >() {
341
+ @ Override
342
+ public void onResponse (Abi abi ) {
343
+ Assert .assertEquals (HelloWorld .getABI (), abi .getABI ());
344
+ }
317
345
318
- @ Override
319
- public void onError (Response errorResponse ) {
320
- System .out .println (errorResponse );
321
- }
322
- });
346
+ @ Override
347
+ public void onError (Response errorResponse ) {
348
+ System .out .println (errorResponse );
349
+ }
350
+ });
323
351
324
352
BlockNumber blockNumber = client .getBlockNumber ();
325
353
BcosBlock block1 = client .getBlockByNumber (blockNumber .getBlockNumber (), false , false );
@@ -334,7 +362,9 @@ public void onError(Response errorResponse) {
334
362
String txHash = receipt .getTransactionHash ();
335
363
BcosTransaction transaction1 = client .getTransaction (txHash , false );
336
364
BcosTransactionReceipt transactionReceipt = client .getTransactionReceipt (txHash , false );
337
- if (client .getChainCompatibilityVersion ().compareTo (EnumNodeVersion .BCOS_3_2_0 .toVersionObj ()) >= 0 ) {
365
+ if (client .getChainCompatibilityVersion ()
366
+ .compareTo (EnumNodeVersion .BCOS_3_2_0 .toVersionObj ())
367
+ >= 0 ) {
338
368
Assert .assertEquals (extraData , receipt .getExtraData ());
339
369
Assert .assertEquals (extraData , transaction1 .getResult ().getExtraData ());
340
370
Assert .assertEquals (extraData , transactionReceipt .getResult ().getExtraData ());
@@ -368,6 +398,9 @@ public void onError(Response errorResponse) {
368
398
369
399
blockLimit = client .getBlockLimit ();
370
400
System .out .println ("blockLimit:" + blockLimit );
401
+
402
+ client .stop ();
403
+ client .destroy ();
371
404
}
372
405
373
406
@ Test
@@ -385,7 +418,8 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
385
418
"set" ,
386
419
Arrays .<Type >asList (new Utf8String ("fisco hello" )),
387
420
Collections .<TypeReference <?>>emptyList ());
388
- FunctionEncoderInterface functionEncoderInterface = new FunctionEncoder (client .getCryptoSuite ());
421
+ FunctionEncoderInterface functionEncoderInterface =
422
+ new FunctionEncoder (client .getCryptoSuite ());
389
423
byte [] encode = functionEncoderInterface .encode (function );
390
424
String input = Hex .toHexString (encode );
391
425
@@ -410,7 +444,11 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
410
444
String extraData = "extraData" ;
411
445
String signedMessage =
412
446
TransactionBuilderJniObj .createSignedTransaction (
413
- transactionData , transactionDataHashSignedData2 , transactionDataHash , 0 , extraData );
447
+ transactionData ,
448
+ transactionDataHashSignedData2 ,
449
+ transactionDataHash ,
450
+ 0 ,
451
+ extraData );
414
452
415
453
TransactionPusherService txPusher = new TransactionPusherService (client );
416
454
TransactionReceipt receipt2 = txPusher .push (signedMessage );
@@ -421,10 +459,12 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
421
459
receipt2 .setMessage (receiptMsg );
422
460
423
461
System .out .println (receipt2 );
462
+ client .stop ();
463
+ client .destroy ();
424
464
}
425
465
426
466
@ Test
427
- public void testGetGroupList () throws ConfigException , JniException {
467
+ public void testGetGroupList () throws ConfigException {
428
468
ConfigOption configOption = Config .load (configFile );
429
469
430
470
System .out .println ("configOption: " + configOption );
@@ -434,11 +474,13 @@ public void testGetGroupList() throws ConfigException, JniException {
434
474
List <String > groupList = clientWithoutGroupId .getGroupList ().getResult ().getGroupList ();
435
475
System .out .println ("getGroupList: " + groupList );
436
476
437
- BcosSDK bcosSDK = new BcosSDK (configOption );
438
477
for (String groupId : groupList ) {
478
+ BcosSDK bcosSDK = new BcosSDK (configOption );
439
479
Client client = bcosSDK .getClient (groupId );
440
480
System .out .println ("build client, groupId: " + groupId );
441
481
System .out .println ("getBlockNumber, blk: " + client .getBlockNumber ().getBlockNumber ());
482
+ client .stop ();
483
+ client .destroy ();
442
484
}
443
485
}
444
486
}
0 commit comments