Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .ci/ci_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ check_standard_node()
prepare_environment "${2}"
## run integration test
bash gradlew clean integrationTest --info
# if $? is not 0, then exit
if [ ${?} -ne 0 ]; then
cat log/*.log
fi
## clean
clean_node "${1}"
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ext {
webankJavaCryptoVersion = "1.0.3"
junitVersion = '4.13.2'
commonsCollections4Version = "4.4"
bcosSdkJniVersion = "3.6.0-DEV-SNAPSHOT"
bcosSdkJniVersion = "3.6.0-SNAPSHOT"
slf4jApiVerison = '1.7.36'
mockitoVersion = '4.8.0'
gsonVersion = '2.10.1'
Expand Down
140 changes: 91 additions & 49 deletions src/integration-test/java/org/fisco/bcos/sdk/v3/test/BcosSDKTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ public void testClient() {
BcosSDK sdk = BcosSDK.build(configFile);

Client client = sdk.getClient(GROUP);
Assert.assertThrows(BcosSDKException.class,
() -> sdk.getClient("errorClient"));
Assert.assertThrows(BcosSDKException.class, () -> sdk.getClient("errorClient"));

sdk.registerBlockNotifier(GROUP,
sdk.registerBlockNotifier(
GROUP,
(groupId, blockNumber) ->
System.out.println("New block, group: " + groupId + ", blockNumber: " + blockNumber));
System.out.println(
"New block, group: " + groupId + ", blockNumber: " + blockNumber));

// test getBlockNumber
BlockNumber blockNumber = client.getBlockNumber();
Expand All @@ -100,7 +101,8 @@ public void testClient() {

// test getBlockByNumber only header
BcosBlock onlyHeader = client.getBlockByNumber(blockNumber.getBlockNumber(), true, false);
Assert.assertEquals(onlyHeader.getBlock().getHash(), blockHashByNumber.getBlockHashByNumber());
Assert.assertEquals(
onlyHeader.getBlock().getHash(), blockHashByNumber.getBlockHashByNumber());

// test getBlockByNumber
BcosBlock block = client.getBlockByNumber(blockNumber.getBlockNumber(), false, false);
Expand Down Expand Up @@ -132,7 +134,12 @@ public void testClient() {

// get getTotalTransactionCount
TotalTransactionCount totalTransactionCount = client.getTotalTransactionCount();
Assert.assertTrue(Integer.parseInt(totalTransactionCount.getTotalTransactionCount().getTransactionCount()) >= 0);
Assert.assertTrue(
Integer.parseInt(
totalTransactionCount
.getTotalTransactionCount()
.getTransactionCount())
>= 0);

// get getPeers
Peers peers = client.getPeers();
Expand All @@ -145,11 +152,12 @@ public void testClient() {
// get getSyncStatus
SyncStatus syncStatus = client.getSyncStatus();
System.out.println(syncStatus.getSyncStatus().toString());
client.stop();
client.destroy();
}

@Test
public void testClientAsync()
throws ConfigException, ExecutionException, InterruptedException {
public void testClientAsync() throws ConfigException, ExecutionException, InterruptedException {

ConfigOption configOption = Config.load(configFile);
Client client = Client.build(GROUP, configOption);
Expand All @@ -172,8 +180,7 @@ public void onResponse(BcosBlock bcosBlock) {
@Override
public void onError(Response errorResponse) {
System.out.println(
"getBlockByNumberAsync failed: " +
errorResponse.getErrorMessage());
"getBlockByNumberAsync failed: " + errorResponse.getErrorMessage());
}
});
genesisHash[0] = hashFuture.get();
Expand All @@ -187,22 +194,27 @@ public void onError(Response errorResponse) {
@Override
public void onResponse(BcosBlock bcosBlock) {
System.out.println("getBlockByNumberAsync=" + bcosBlock.getBlock());
client.getBlockHashByNumberAsync(BigInteger.valueOf(bcosBlock.getBlock().getNumber()), new RespCallback<BlockHash>() {
@Override
public void onResponse(BlockHash blockHash) {
System.out.println("getBlockHashByNumberAsync=" + blockHash.getBlockHashByNumber());
}

@Override
public void onError(Response errorResponse) {
System.out.println(errorResponse);
}
});
client.getBlockHashByNumberAsync(
BigInteger.valueOf(bcosBlock.getBlock().getNumber()),
new RespCallback<BlockHash>() {
@Override
public void onResponse(BlockHash blockHash) {
System.out.println(
"getBlockHashByNumberAsync="
+ blockHash.getBlockHashByNumber());
}

@Override
public void onError(Response errorResponse) {
System.out.println(errorResponse);
}
});
}

@Override
public void onError(Response errorResponse) {
System.out.println("getBlockByNumberAsync failed: " + errorResponse.getErrorMessage());
System.out.println(
"getBlockByNumberAsync failed: " + errorResponse.getErrorMessage());
}
});

Expand Down Expand Up @@ -246,7 +258,12 @@ public void onError(Response errorResponse) {

// get getTotalTransactionCount
TotalTransactionCount totalTransactionCount = client.getTotalTransactionCount();
Assert.assertTrue(Integer.parseInt(totalTransactionCount.getTotalTransactionCount().getTransactionCount()) >= 0);
Assert.assertTrue(
Integer.parseInt(
totalTransactionCount
.getTotalTransactionCount()
.getTransactionCount())
>= 0);

// get getPeers
Peers peers = client.getPeers();
Expand All @@ -256,17 +273,23 @@ public void onError(Response errorResponse) {
SyncStatus syncStatus = client.getSyncStatus();
System.out.println(syncStatus.getSyncStatus());

client.getTotalTransactionCountAsync(new RespCallback<TotalTransactionCount>() {
@Override
public void onResponse(TotalTransactionCount totalTransactionCount) {
Assert.assertTrue(Integer.parseInt(totalTransactionCount.getTotalTransactionCount().getTransactionCount()) >= 0);
}
client.getTotalTransactionCountAsync(
new RespCallback<TotalTransactionCount>() {
@Override
public void onResponse(TotalTransactionCount totalTransactionCount) {
Assert.assertTrue(
Integer.parseInt(
totalTransactionCount
.getTotalTransactionCount()
.getTransactionCount())
>= 0);
}

@Override
public void onError(Response errorResponse) {
System.out.println(errorResponse);
}
});
@Override
public void onError(Response errorResponse) {
System.out.println(errorResponse);
}
});

// test getBlockNumber
client.getBlockNumberAsync(
Expand All @@ -282,10 +305,13 @@ public void onError(Response errorResponse) {
"getBlockNumberAsync failed: " + errorResponse.getErrorMessage());
}
});

client.stop();
client.destroy();
}

@Test
public void testHelloWorldInSolidity() throws ConfigException, JniException, ContractException {
public void testHelloWorldInSolidity() throws ConfigException, ContractException {

ConfigOption configOption = Config.load(configFile);
Client client = Client.build(GROUP, configOption);
Expand All @@ -309,17 +335,19 @@ public void testHelloWorldInSolidity() throws ConfigException, JniException, Con
helloWorld = HelloWorld.deploy(client, cryptoKeyPair);
System.out.println("helloworld address :" + helloWorld.getContractAddress());

client.getABIAsync(helloWorld.getContractAddress(), new RespCallback<Abi>() {
@Override
public void onResponse(Abi abi) {
Assert.assertEquals(HelloWorld.getABI(), abi.getABI());
}
client.getABIAsync(
helloWorld.getContractAddress(),
new RespCallback<Abi>() {
@Override
public void onResponse(Abi abi) {
Assert.assertEquals(HelloWorld.getABI(), abi.getABI());
}

@Override
public void onError(Response errorResponse) {
System.out.println(errorResponse);
}
});
@Override
public void onError(Response errorResponse) {
System.out.println(errorResponse);
}
});

BlockNumber blockNumber = client.getBlockNumber();
BcosBlock block1 = client.getBlockByNumber(blockNumber.getBlockNumber(), false, false);
Expand All @@ -334,7 +362,9 @@ public void onError(Response errorResponse) {
String txHash = receipt.getTransactionHash();
BcosTransaction transaction1 = client.getTransaction(txHash, false);
BcosTransactionReceipt transactionReceipt = client.getTransactionReceipt(txHash, false);
if (client.getChainCompatibilityVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) >= 0) {
if (client.getChainCompatibilityVersion()
.compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj())
>= 0) {
Assert.assertEquals(extraData, receipt.getExtraData());
Assert.assertEquals(extraData, transaction1.getResult().getExtraData());
Assert.assertEquals(extraData, transactionReceipt.getResult().getExtraData());
Expand Down Expand Up @@ -368,6 +398,9 @@ public void onError(Response errorResponse) {

blockLimit = client.getBlockLimit();
System.out.println("blockLimit:" + blockLimit);

client.stop();
client.destroy();
}

@Test
Expand All @@ -385,7 +418,8 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
"set",
Arrays.<Type>asList(new Utf8String("fisco hello")),
Collections.<TypeReference<?>>emptyList());
FunctionEncoderInterface functionEncoderInterface = new FunctionEncoder(client.getCryptoSuite());
FunctionEncoderInterface functionEncoderInterface =
new FunctionEncoder(client.getCryptoSuite());
byte[] encode = functionEncoderInterface.encode(function);
String input = Hex.toHexString(encode);

Expand All @@ -410,7 +444,11 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
String extraData = "extraData";
String signedMessage =
TransactionBuilderJniObj.createSignedTransaction(
transactionData, transactionDataHashSignedData2, transactionDataHash, 0, extraData);
transactionData,
transactionDataHashSignedData2,
transactionDataHash,
0,
extraData);

TransactionPusherService txPusher = new TransactionPusherService(client);
TransactionReceipt receipt2 = txPusher.push(signedMessage);
Expand All @@ -421,10 +459,12 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
receipt2.setMessage(receiptMsg);

System.out.println(receipt2);
client.stop();
client.destroy();
}

@Test
public void testGetGroupList() throws ConfigException, JniException {
public void testGetGroupList() throws ConfigException {
ConfigOption configOption = Config.load(configFile);

System.out.println("configOption: " + configOption);
Expand All @@ -434,11 +474,13 @@ public void testGetGroupList() throws ConfigException, JniException {
List<String> groupList = clientWithoutGroupId.getGroupList().getResult().getGroupList();
System.out.println("getGroupList: " + groupList);

BcosSDK bcosSDK = new BcosSDK(configOption);
for (String groupId : groupList) {
BcosSDK bcosSDK = new BcosSDK(configOption);
Client client = bcosSDK.getClient(groupId);
System.out.println("build client, groupId: " + groupId);
System.out.println("getBlockNumber, blk: " + client.getBlockNumber().getBlockNumber());
client.stop();
client.destroy();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public void test1ConsensusService() throws ConfigException, ContractException, J
List<String> observerList4 = client.getObserverList().getResult();
System.out.println("observerList4: " + observerList4);
Assert.assertFalse(observerList4.contains(selectedNode.getNodeID()));

client.stop();
client.destroy();
}

@Test
Expand All @@ -175,6 +178,8 @@ public void test3SystemConfigService() throws ConfigException, ContractException

this.testSystemConfigService(client, systemConfigService, "tx_count_limit");
this.testSystemConfigService(client, systemConfigService, "tx_gas_limit");
client.stop();
client.destroy();
}

private void testSystemConfigService(
Expand Down Expand Up @@ -264,10 +269,12 @@ public void test5CRUDService() throws ConfigException, ContractException {
result = tableCRUDService.select(tableName, "key1");
Assert.assertTrue(result.isEmpty());
System.out.println("testCRUDPrecompiled tableCRUDService.remove size : " + result.size());
client.stop();
client.destroy();
}

@Test
public void test51SyncCRUDService() throws ConfigException, ContractException, JniException {
public void test51SyncCRUDService() throws ConfigException, ContractException {

ConfigOption configOption = Config.load(configFile);
Client client = Client.build(GROUP, configOption);
Expand Down Expand Up @@ -328,6 +335,8 @@ public void test51SyncCRUDService() throws ConfigException, ContractException, J
.getTransactionCount());
System.out.println("orgTxCount: " + orgTxCount + ", currentTxCount:" + currentTxCount);
Assert.assertTrue(currentTxCount.compareTo(orgTxCount.add(BigInteger.valueOf(300))) >= 0);
client.stop();
client.destroy();
}

class FakeTransactionCallback implements PrecompiledCallback {
Expand Down Expand Up @@ -408,6 +417,8 @@ public void test52AsyncCRUDService()
.getTransactionCount());
System.out.println("orgTxCount: " + orgTxCount + ", currentTxCount:" + currentTxCount);
Assert.assertTrue(currentTxCount.compareTo(orgTxCount.add(BigInteger.valueOf(300))) >= 0);
client.stop();
client.destroy();
}

@Test
Expand Down Expand Up @@ -439,6 +450,8 @@ public void test6KVService() throws ConfigException, ContractException {
// field value result + key result
Assert.assertEquals(key1, "value1");
System.out.println("kvTableService select result: " + key1);
client.stop();
client.destroy();
}

@Test
Expand Down Expand Up @@ -483,5 +496,7 @@ public void test7BFSPrecompiled() throws ConfigException, ContractException {
}
}
Assert.assertTrue(flag);
client.stop();
client.destroy();
}
}
Loading