Skip to content

Commit 9496eb8

Browse files
committed
<fix>(CI): add compatibility node test.
1 parent 3326452 commit 9496eb8

File tree

6 files changed

+166
-42
lines changed

6 files changed

+166
-42
lines changed

.ci/ci_check.sh

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ check_basic()
1313
bash gradlew build --info
1414
}
1515

16+
download_tassl()
17+
{
18+
local OPENSSL_CMD=${HOME}/.fisco/tassl-1.1.1b
19+
if [ -f "${OPENSSL_CMD}" ];then
20+
return
21+
fi
22+
local package_name="tassl-1.1.1b-linux-x86_64"
23+
if [ "$(uname)" == "Darwin" ];then
24+
package_name="tassl-1.1.1b-macOS-x86_64"
25+
fi
26+
curl -LO "https://github.com/FISCO-BCOS/LargeFiles/raw/master/tools/${package_name}.tar.gz" && tar -zxvf "${package_name}.tar.gz" && mv "${package_name}" tassl-1.1.1b && mkdir -p ~/.fisco && mv tassl-1.1.1b ~/.fisco/
27+
}
28+
1629
download_build_chain()
1730
{
1831
local tag="${1}"
@@ -23,6 +36,17 @@ download_build_chain()
2336
curl -LO "https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/${tag}/build_chain.sh" && chmod u+x build_chain.sh
2437
}
2538

39+
download_binary()
40+
{
41+
local tag="${1}"
42+
LOG_INFO "--- current tag: $tag"
43+
local package_name="fisco-bcos-linux-x86_64.tar.gz"
44+
if [ "$(uname)" == "Darwin" ];then
45+
package_name="fisco-bcos-macOS-x86_64.tar.gz"
46+
fi
47+
curl -LO "https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/${tag}/${package_name}" && tar -zxvf "${package_name}"
48+
}
49+
2650
get_sed_cmd()
2751
{
2852
local sed_cmd="sed -i"
@@ -47,16 +71,15 @@ prepare_environment()
4771
cp -r src/test/resources/ecdsa/abi src/integration-test/resources/abi
4872
cp -r src/test/resources/ecdsa/bin src/integration-test/resources/bin
4973

50-
sed_cmd=$(get_sed_cmd)
51-
52-
local node_type="${1}"
53-
if [ "${node_type}" == "sm" ];then
54-
rm -rf src/integration-test/resources/abi
55-
rm -rf src/integration-test/resources/bin
56-
cp -r src/test/resources/gm/abi src/integration-test/resources/abi
57-
cp -r src/test/resources/gm/bin src/integration-test/resources/bin
58-
${sed_cmd} 's/useSMCrypto = "false"/useSMCrypto = "true"/g' src/integration-test/resources/config.toml
59-
fi
74+
# sed_cmd=$(get_sed_cmd)
75+
# local node_type="${1}"
76+
# if [ "${node_type}" == "sm" ];then
77+
# rm -rf src/integration-test/resources/abi
78+
# rm -rf src/integration-test/resources/bin
79+
# cp -r src/test/resources/gm/abi src/integration-test/resources/abi
80+
# cp -r src/test/resources/gm/bin src/integration-test/resources/bin
81+
# ${sed_cmd} 's/useSMCrypto = "false"/useSMCrypto = "true"/g' src/integration-test/resources/config.toml
82+
# fi
6083
}
6184

6285
prepare_wasm_environment()
@@ -76,9 +99,9 @@ build_node()
7699
local node_type="${1}"
77100
local sed_cmd=$(get_sed_cmd)
78101
if [ "${node_type}" == "wasm" ];then
79-
bash build_chain.sh -l 127.0.0.1:4 -w
102+
bash build_chain.sh -l 127.0.0.1:4 -e ./fisco-bcos -w "${2}"
80103
else
81-
bash build_chain.sh -l 127.0.0.1:4
104+
bash build_chain.sh -l 127.0.0.1:4 -e ./fisco-bcos "${2}"
82105
fi
83106
./nodes/127.0.0.1/fisco-bcos -v
84107
cat nodes/127.0.0.1/node0/config.genesis
@@ -89,41 +112,57 @@ clean_node()
89112
{
90113
bash nodes/127.0.0.1/stop_all.sh
91114
rm -rf nodes
115+
if [ "${1}" == "true" ]; then
116+
rm -rf ./fisco-bcos*
117+
fi
92118
}
93119

94120
# check integration-test for non-gm node
95121
check_standard_node()
96122
{
97-
build_node
123+
build_node "normal" "${2}"
98124
prepare_environment
99125
## run integration test
100126
bash gradlew clean integrationTest --info
101127
## clean
102-
clean_node
128+
clean_node "${1}"
103129
}
104130

105131
check_wasm_node()
106132
{
107-
build_node "wasm"
133+
build_node "wasm" "${2}"
108134
prepare_wasm_environment
109135
## run integration test
110136
bash gradlew clean integrationWasmTest --info
111137
## clean
112-
clean_node
138+
clean_node "${1}"
113139
}
114140

115141
pwd
116142
ls -la
117143
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
118-
LOG_INFO "------ download_build_chain---------"
144+
download_tassl
145+
LOG_INFO "------ download_build_chain: v3.2.0---------"
119146
download_build_chain "v3.2.0"
147+
download_binary "v3.2.0"
120148
LOG_INFO "------ check_standard_node---------"
121-
check_standard_node
149+
check_standard_node "false"
122150
LOG_INFO "------ check_wasm_node---------"
123-
check_wasm_node
151+
check_wasm_node "true"
124152
LOG_INFO "------ check_basic---------"
125153
check_basic
126-
LOG_INFO "------ check_log---------"
127154
rm -rf ./bin
128-
cat log/* |grep -i error
129-
cat log/* |grep -i warn
155+
156+
LOG_INFO "------ download_binary: v3.1.0---------"
157+
download_build_chain "v3.1.0"
158+
download_binary "v3.1.0"
159+
LOG_INFO "------ check_standard_node---------"
160+
check_standard_node
161+
rm -rf ./bin
162+
163+
LOG_INFO "------ download_binary: v3.0.0---------"
164+
download_build_chain "v3.0.0"
165+
download_binary "v3.0.0"
166+
LOG_INFO "------ check_standard_node---------"
167+
check_standard_node
168+
rm -rf ./bin

src/integration-test/java/org/fisco/bcos/sdk/v3/test/BcosSDKTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.fisco.bcos.sdk.v3.codec.datatypes.Type;
3636
import org.fisco.bcos.sdk.v3.codec.datatypes.TypeReference;
3737
import org.fisco.bcos.sdk.v3.codec.datatypes.Utf8String;
38+
import org.fisco.bcos.sdk.v3.model.EnumNodeVersion;
3839
import org.fisco.bcos.sdk.v3.model.callback.RespCallback;
3940
import org.fisco.bcos.sdk.v3.client.protocol.response.Abi;
4041
import org.fisco.bcos.sdk.v3.client.protocol.response.BcosBlock;
@@ -334,10 +335,11 @@ public void onError(Response errorResponse) {
334335

335336
String txHash = receipt.getTransactionHash();
336337
BcosTransaction transaction1 = client.getTransaction(txHash, false);
337-
Assert.assertEquals(extraData, transaction1.getResult().getExtraData());
338-
339338
BcosTransactionReceipt transactionReceipt = client.getTransactionReceipt(txHash, false);
340-
Assert.assertEquals(extraData, transactionReceipt.getResult().getExtraData());
339+
if (client.getChainVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) >= 0) {
340+
Assert.assertEquals(extraData, transaction1.getResult().getExtraData());
341+
Assert.assertEquals(extraData, transactionReceipt.getResult().getExtraData());
342+
}
341343

342344
// get 2nd block
343345
block1 =

src/integration-test/java/org/fisco/bcos/sdk/v3/test/precompiled/PrecompiledTest.java

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.concurrent.ExecutorService;
2626
import java.util.concurrent.Executors;
2727
import java.util.concurrent.atomic.AtomicLong;
28+
2829
import org.fisco.bcos.sdk.jni.common.JniException;
2930
import org.fisco.bcos.sdk.v3.client.Client;
3031
import org.fisco.bcos.sdk.v3.client.protocol.response.SealerList;
@@ -45,6 +46,7 @@
4546
import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigService;
4647
import org.fisco.bcos.sdk.v3.crypto.keypair.CryptoKeyPair;
4748
import org.fisco.bcos.sdk.v3.model.ConstantConfig;
49+
import org.fisco.bcos.sdk.v3.model.EnumNodeVersion;
4850
import org.fisco.bcos.sdk.v3.model.PrecompiledConstant;
4951
import org.fisco.bcos.sdk.v3.model.PrecompiledRetCode;
5052
import org.fisco.bcos.sdk.v3.model.RetCode;
@@ -172,28 +174,35 @@ private void testSystemConfigService(
172174
BigInteger queriedValue =
173175
new BigInteger(client.getSystemConfigByKey(key).getSystemConfig().getValue());
174176
System.out.println("queriedValue: " + queriedValue);
175-
Assert.assertTrue(queriedValue.equals(updatedValue));
176-
Assert.assertTrue(queriedValue.equals(value.add(BigInteger.valueOf(100))));
177+
Assert.assertEquals(queriedValue, updatedValue);
178+
Assert.assertEquals(queriedValue, value.add(BigInteger.valueOf(100)));
177179
}
178180

179181
@Test
180-
public void test5CRUDService() throws ConfigException, ContractException, JniException {
182+
public void test5CRUDService() throws ConfigException, ContractException {
181183
ConfigOption configOption = Config.load(configFile);
182184
Client client = Client.build(GROUP, configOption);
183185

184186
CryptoKeyPair cryptoKeyPair = client.getCryptoSuite().getCryptoKeyPair();
185187
TableCRUDService tableCRUDService = new TableCRUDService(client, cryptoKeyPair);
186188
// create a user table
187-
String tableName = "test" + new Random().nextInt(10000);
189+
String tableName = "test" + System.currentTimeMillis();
188190
String key = "key";
189191
List<String> valueFields = new ArrayList<>(5);
190192
for (int i = 0; i < 5; i++) {
191193
valueFields.add(i, "field" + i);
192194
}
193-
RetCode code = tableCRUDService.createTable(tableName, Common.TableKeyOrder.valueOf(0), key, valueFields);
195+
RetCode code;
196+
Map<String, List<String>> desc;
197+
if (client.getChainVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) >= 0) {
198+
code = tableCRUDService.createTable(tableName, Common.TableKeyOrder.valueOf(0), key, valueFields);
199+
desc = tableCRUDService.descWithKeyOrder(tableName);
200+
} else {
201+
code = tableCRUDService.createTable(tableName, key, valueFields);
202+
desc = tableCRUDService.desc(tableName);
203+
}
194204
Assert.assertEquals(0, code.getCode());
195205
// desc
196-
Map<String, List<String>> desc = tableCRUDService.descWithKeyOrder(tableName);
197206
Assert.assertEquals(desc.get(PrecompiledConstant.VALUE_FIELD_NAME), valueFields);
198207

199208
// insert
@@ -207,10 +216,19 @@ public void test5CRUDService() throws ConfigException, ContractException, JniExc
207216
// select key
208217
Map<String, String> result = tableCRUDService.select(tableName, "key1");
209218

210-
ConditionV320 condition = new ConditionV320();
211-
condition.EQ(key,"990");
212-
condition.setLimit(0, 10);
213-
List<Map<String, String>> select = tableCRUDService.select(tableName, condition);
219+
if (client.getChainVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) >= 0) {
220+
ConditionV320 condition = new ConditionV320();
221+
condition.EQ(key, "key1");
222+
condition.setLimit(0, 10);
223+
List<Map<String, String>> select = tableCRUDService.select(tableName, condition);
224+
Assert.assertEquals(select.size(), 1);
225+
} else {
226+
Condition condition = new Condition();
227+
condition.EQ("key1");
228+
condition.setLimit(0, 10);
229+
List<Map<String, String>> select = tableCRUDService.select(tableName, condition);
230+
Assert.assertEquals(select.size(), 1);
231+
}
214232
// field value result + key result
215233
Assert.assertEquals(result.size(), valueFields.size() + 1);
216234
System.out.println("tableCRUDService select result: " + result);
@@ -244,7 +262,12 @@ public void test51SyncCRUDService() throws ConfigException, ContractException, J
244262
String tableName = "test_sync" + System.currentTimeMillis();
245263
List<String> valueFiled = new ArrayList<>();
246264
valueFiled.add("field");
247-
RetCode retCode = crudService.createTable(tableName, Common.TableKeyOrder.valueOf(0), "key", valueFiled);
265+
RetCode retCode;
266+
if (client.getChainVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) >= 0) {
267+
retCode = crudService.createTable(tableName, Common.TableKeyOrder.valueOf(0), "key", valueFiled);
268+
} else {
269+
retCode = crudService.createTable(tableName, "key", valueFiled);
270+
}
248271
System.out.println("tableName" + tableName);
249272
System.out.println(
250273
"createResult: " + retCode.getCode() + ", message: " + retCode.getMessage());
@@ -317,7 +340,11 @@ public void test52AsyncCRUDService()
317340
List<String> valueFiled = new ArrayList<>();
318341
valueFiled.add("field");
319342
String key = "key";
320-
crudService.createTable(tableName, Common.TableKeyOrder.valueOf(0), key, valueFiled);
343+
if (client.getChainVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) >= 0) {
344+
crudService.createTable(tableName, Common.TableKeyOrder.valueOf(0), key, valueFiled);
345+
} else {
346+
crudService.createTable(tableName, key, valueFiled);
347+
}
321348
// create a thread pool to parallel insert and select
322349
ExecutorService threadPool = Executors.newFixedThreadPool(50);
323350
BigInteger orgTxCount =
@@ -369,19 +396,24 @@ public void test52AsyncCRUDService()
369396
}
370397

371398
@Test
372-
public void test6KVService() throws ConfigException, ContractException, JniException {
399+
public void test6KVService() throws ConfigException, ContractException {
373400
ConfigOption configOption = Config.load(configFile);
374401
Client client = Client.build(GROUP, configOption);
375402

376403
CryptoKeyPair cryptoKeyPair = client.getCryptoSuite().getCryptoKeyPair();
377404
KVTableService kvTableService = new KVTableService(client, cryptoKeyPair);
378405
// create a user table
379-
String tableName = "test" + (int) (Math.random() * 1000);
406+
String tableName = "test" + System.currentTimeMillis();
380407
String key = "key";
381408
RetCode code = kvTableService.createTable(tableName, key, "field");
382409
Assert.assertEquals(0, code.getCode());
383410
// desc
384-
Map<String, String> desc = kvTableService.descWithKeyOrder(tableName);
411+
Map<String, String> desc;
412+
if (client.getChainVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) >= 0) {
413+
desc = kvTableService.descWithKeyOrder(tableName);
414+
} else {
415+
desc = kvTableService.desc(tableName);
416+
}
385417
Assert.assertEquals(desc.get(PrecompiledConstant.VALUE_FIELD_NAME), "field");
386418

387419
// set
@@ -395,7 +427,7 @@ public void test6KVService() throws ConfigException, ContractException, JniExcep
395427
}
396428

397429
@Test
398-
public void test7BFSPrecompiled() throws ConfigException, ContractException, JniException {
430+
public void test7BFSPrecompiled() throws ConfigException, ContractException {
399431

400432
ConfigOption configOption = Config.load(configFile);
401433
Client client = Client.build(GROUP, configOption);

src/main/java/org/fisco/bcos/sdk/v3/client/Client.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.fisco.bcos.sdk.v3.client.protocol.response.TotalTransactionCount;
4343
import org.fisco.bcos.sdk.v3.config.ConfigOption;
4444
import org.fisco.bcos.sdk.v3.crypto.CryptoSuite;
45+
import org.fisco.bcos.sdk.v3.model.EnumNodeVersion;
4546
import org.fisco.bcos.sdk.v3.model.callback.RespCallback;
4647
import org.fisco.bcos.sdk.v3.model.callback.TransactionCallback;
4748
import org.slf4j.Logger;
@@ -868,6 +869,20 @@ void getTransactionReceiptAsync(
868869

869870
// ------------------------- rpc interface end ------------------------------------------
870871

872+
/**
873+
* get the chain compatibility version
874+
*
875+
* @return the chain compatibility version
876+
*/
877+
EnumNodeVersion.Version getChainVersion();
878+
879+
/**
880+
* async get the chain compatibility version
881+
*
882+
* @param versionRespCallback the callback instance
883+
*/
884+
void getChainVersionAsync(RespCallback<EnumNodeVersion.Version> versionRespCallback);
885+
871886
void start();
872887

873888
void stop();

src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,42 @@ public void getGroupNodeInfoAsync(String node, RespCallback<BcosGroupNodeInfo> c
10951095
callback);
10961096
}
10971097

1098+
@Override
1099+
public EnumNodeVersion.Version getChainVersion() {
1100+
List<BcosGroupNodeInfo.GroupNodeInfo> nodeList = getGroupInfo().getResult().getNodeList();
1101+
if (nodeList == null || nodeList.isEmpty()) {
1102+
throw new IllegalStateException("Empty node list in group info.");
1103+
}
1104+
long compatibilityVersion = nodeList.get(0).getProtocol().getCompatibilityVersion();
1105+
return EnumNodeVersion.convertToVersion((int) compatibilityVersion);
1106+
}
1107+
1108+
@Override
1109+
public void getChainVersionAsync(RespCallback<EnumNodeVersion.Version> versionRespCallback) {
1110+
getGroupInfoAsync(
1111+
new RespCallback<BcosGroupInfo>() {
1112+
@Override
1113+
public void onResponse(BcosGroupInfo bcosGroupInfo) {
1114+
List<BcosGroupNodeInfo.GroupNodeInfo> nodeList =
1115+
bcosGroupInfo.getResult().getNodeList();
1116+
if (nodeList == null || nodeList.isEmpty()) {
1117+
versionRespCallback.onError(
1118+
new Response(-1, "Empty node list in group info."));
1119+
return;
1120+
}
1121+
long compatibilityVersion =
1122+
nodeList.get(0).getProtocol().getCompatibilityVersion();
1123+
versionRespCallback.onResponse(
1124+
EnumNodeVersion.convertToVersion((int) compatibilityVersion));
1125+
}
1126+
1127+
@Override
1128+
public void onError(Response errorResponse) {
1129+
versionRespCallback.onError(errorResponse);
1130+
}
1131+
});
1132+
}
1133+
10981134
@Override
10991135
public void start() {
11001136
if (rpcJniObj != null) {

src/test/resources/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ disableSsl = "false" # Communication with nodes without S
1919
[network]
2020
messageTimeout = "10000"
2121
defaultGroup = "group0"
22-
peers=["127.0.0.1:20200", "127.0.0.1:20201"] # The peer list to connect
22+
peers=["127.0.0.1:20201"] # The peer list to connect
2323

2424

2525
[account]

0 commit comments

Comments
 (0)