Skip to content

Commit aef619c

Browse files
committed
<fix>(build): update dependencies version, add UT with AI.
1 parent 9837e92 commit aef619c

File tree

20 files changed

+1876
-6
lines changed

20 files changed

+1876
-6
lines changed

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ ext {
1616
if (!project.hasProperty("ossrhPassword")) {
1717
ossrhPassword = "xxx"
1818
}
19-
jacksonVersion = '2.14.3'
20-
commonsIOVersion = '2.11.0'
21-
commonsLang3Version = '3.12.0'
19+
jacksonVersion = '2.20.1'
20+
commonsIOVersion = '2.20.0'
21+
commonsLang3Version = '3.19.0'
2222
toml4jVersion = "0.7.2"
2323
bcprovJDK18onVersion = '1.78'
2424
webankJavaCryptoVersion = "1.0.3"
@@ -135,6 +135,7 @@ dependencies {
135135
api("com.google.code.gson:gson:${gsonVersion}")
136136
api("org.apache.commons:commons-lang3:${commonsLang3Version}")
137137
api("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}")
138+
api("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${jacksonVersion}")
138139
api("commons-io:commons-io:${commonsIOVersion}")
139140
api("com.webank:webank-blockchain-java-crypto:${webankJavaCryptoVersion}")
140141
api("com.moandjiezana.toml:toml4j:${toml4jVersion}") {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,8 @@ public <T extends JsonRpcResponse<?>> T callRemoteMethod(
16641664

16651665
future.complete(response);
16661666
});
1667-
Response response = future.get();
1667+
Response response =
1668+
future.get(configOption.getNetworkConfig().getTimeout(), TimeUnit.MILLISECONDS);
16681669
return ClientImpl.parseResponseIntoJsonRpcResponse(
16691670
request.getMethod(), response, responseType);
16701671
} catch (ClientException e) {
@@ -1675,7 +1676,10 @@ public <T extends JsonRpcResponse<?>> T callRemoteMethod(
16751676
"callRemoteMethod failed for decode the message exception, error message:"
16761677
+ e.getMessage(),
16771678
e);
1678-
} catch (JsonProcessingException | InterruptedException | ExecutionException e) {
1679+
} catch (JsonProcessingException
1680+
| InterruptedException
1681+
| ExecutionException
1682+
| TimeoutException e) {
16791683
logger.error("callRemoteMethod exception, raw request:{} ", request, e);
16801684
throw new ClientException(
16811685
"callRemoteMethod failed for decode the message exception, error message:"

src/main/java/org/fisco/bcos/sdk/v3/crypto/keypair/ECDSAKeyPair.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ public CryptoKeyPair createKeyPair(KeyPair javaKeyPair) {
9191
return new ECDSAKeyPair(javaKeyPair);
9292
}
9393

94+
public static CryptoKeyPair cryptoKeyPair(KeyPair javaKeyPair) {
95+
if (javaKeyPair == null) {
96+
return new ECDSAKeyPair();
97+
}
98+
return new ECDSAKeyPair(javaKeyPair);
99+
}
100+
94101
public static String getAddressByPublicKey(String publicKey) {
95102
return getAddress(publicKey, ECDSAKeyPair.DefaultHashAlgorithm);
96103
}

src/main/java/org/fisco/bcos/sdk/v3/utils/ObjectMapperFactory.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@
1515

1616
import com.fasterxml.jackson.core.JsonParser;
1717
import com.fasterxml.jackson.databind.DeserializationFeature;
18+
import com.fasterxml.jackson.databind.MapperFeature;
1819
import com.fasterxml.jackson.databind.ObjectMapper;
1920
import com.fasterxml.jackson.databind.ObjectReader;
21+
import com.fasterxml.jackson.databind.json.JsonMapper;
2022

2123
/** Factory for managing our ObjectMapper instances. */
2224
public class ObjectMapperFactory {
2325

24-
private static final ObjectMapper DEFAULT_OBJECT_MAPPER = new ObjectMapper();
26+
private static final ObjectMapper DEFAULT_OBJECT_MAPPER =
27+
JsonMapper.builder()
28+
.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
29+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
30+
.configure(MapperFeature.REQUIRE_HANDLERS_FOR_JAVA8_OPTIONALS, false)
31+
.build();
2532

2633
static {
2734
configureObjectMapper();
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.fisco.bcos.sdk.v3.test.client.protocol.request;
2+
3+
import org.fisco.bcos.sdk.v3.client.protocol.request.DefaultBlockParameterName;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class DefaultBlockParameterNameTest {
8+
9+
@Test
10+
public void testGetValue() {
11+
Assert.assertEquals("earliest", DefaultBlockParameterName.EARLIEST.getValue());
12+
Assert.assertEquals("latest", DefaultBlockParameterName.LATEST.getValue());
13+
}
14+
15+
@Test
16+
public void testIsLatest() {
17+
Assert.assertTrue(DefaultBlockParameterName.LATEST.isLatest());
18+
Assert.assertFalse(DefaultBlockParameterName.EARLIEST.isLatest());
19+
}
20+
21+
@Test
22+
public void testIsEarliest() {
23+
Assert.assertTrue(DefaultBlockParameterName.EARLIEST.isEarliest());
24+
Assert.assertFalse(DefaultBlockParameterName.LATEST.isEarliest());
25+
}
26+
27+
@Test
28+
public void testFromString() {
29+
Assert.assertEquals(DefaultBlockParameterName.EARLIEST,
30+
DefaultBlockParameterName.fromString("earliest"));
31+
Assert.assertEquals(DefaultBlockParameterName.LATEST,
32+
DefaultBlockParameterName.fromString("latest"));
33+
34+
// Test case insensitive
35+
Assert.assertEquals(DefaultBlockParameterName.EARLIEST,
36+
DefaultBlockParameterName.fromString("EARLIEST"));
37+
Assert.assertEquals(DefaultBlockParameterName.LATEST,
38+
DefaultBlockParameterName.fromString("LATEST"));
39+
Assert.assertEquals(DefaultBlockParameterName.EARLIEST,
40+
DefaultBlockParameterName.fromString("EaRlIeSt"));
41+
}
42+
43+
@Test(expected = IllegalArgumentException.class)
44+
public void testFromStringInvalid() {
45+
DefaultBlockParameterName.fromString("invalid");
46+
}
47+
48+
@Test
49+
public void testEnumValues() {
50+
DefaultBlockParameterName[] values = DefaultBlockParameterName.values();
51+
Assert.assertEquals(2, values.length);
52+
Assert.assertEquals(DefaultBlockParameterName.EARLIEST, values[0]);
53+
Assert.assertEquals(DefaultBlockParameterName.LATEST, values[1]);
54+
}
55+
56+
@Test
57+
public void testValueOf() {
58+
Assert.assertEquals(DefaultBlockParameterName.EARLIEST,
59+
DefaultBlockParameterName.valueOf("EARLIEST"));
60+
Assert.assertEquals(DefaultBlockParameterName.LATEST,
61+
DefaultBlockParameterName.valueOf("LATEST"));
62+
}
63+
}
64+
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package org.fisco.bcos.sdk.v3.test.codec.datatypes;
2+
3+
import org.fisco.bcos.sdk.v3.codec.datatypes.Address;
4+
import org.fisco.bcos.sdk.v3.codec.datatypes.generated.Uint160;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
import java.math.BigInteger;
9+
10+
public class AddressTest {
11+
12+
@Test
13+
public void testAddressFromBigInteger() {
14+
BigInteger value = new BigInteger("1234567890");
15+
Address address = new Address(value);
16+
17+
Assert.assertNotNull(address);
18+
Assert.assertEquals("address", address.getTypeAsString());
19+
}
20+
21+
@Test
22+
public void testAddressFromHexString() {
23+
String hexValue = "0x1234567890abcdef1234567890abcdef12345678";
24+
Address address = new Address(hexValue);
25+
26+
Assert.assertNotNull(address);
27+
Assert.assertNotNull(address.getValue());
28+
}
29+
30+
@Test
31+
public void testAddressFromUint160() {
32+
Uint160 uint160 = new Uint160(BigInteger.valueOf(100));
33+
Address address = new Address(uint160);
34+
35+
Assert.assertNotNull(address);
36+
Assert.assertEquals(uint160, address.toUint160());
37+
}
38+
39+
@Test
40+
public void testGetTypeAsString() {
41+
Address address = new Address(BigInteger.ZERO);
42+
Assert.assertEquals("address", address.getTypeAsString());
43+
}
44+
45+
@Test
46+
public void testToString() {
47+
Address address = new Address(BigInteger.valueOf(255));
48+
String result = address.toString();
49+
50+
Assert.assertNotNull(result);
51+
Assert.assertTrue(result.startsWith("0x"));
52+
Assert.assertEquals(42, result.length()); // 0x + 40 hex chars
53+
}
54+
55+
@Test
56+
public void testGetValue() {
57+
Address address = new Address(BigInteger.valueOf(100));
58+
String value = address.getValue();
59+
60+
Assert.assertNotNull(value);
61+
Assert.assertTrue(value.startsWith("0x"));
62+
}
63+
64+
@Test
65+
public void testEquals() {
66+
Address address1 = new Address(BigInteger.valueOf(100));
67+
Address address2 = new Address(BigInteger.valueOf(100));
68+
Address address3 = new Address(BigInteger.valueOf(200));
69+
70+
Assert.assertEquals(address1, address2);
71+
Assert.assertNotEquals(address1, address3);
72+
Assert.assertEquals(address1, address1);
73+
Assert.assertNotEquals(address1, null);
74+
Assert.assertNotEquals(address1, "String");
75+
}
76+
77+
@Test
78+
public void testHashCode() {
79+
Address address1 = new Address(BigInteger.valueOf(100));
80+
Address address2 = new Address(BigInteger.valueOf(100));
81+
82+
Assert.assertEquals(address1.hashCode(), address2.hashCode());
83+
}
84+
85+
@Test
86+
public void testDefaultAddress() {
87+
Assert.assertNotNull(Address.DEFAULT);
88+
Assert.assertEquals(BigInteger.ZERO, Address.DEFAULT.toUint160().getValue());
89+
}
90+
91+
@Test
92+
public void testAddressConstants() {
93+
Assert.assertEquals("address", Address.TYPE_NAME);
94+
Assert.assertEquals(160, Address.LENGTH);
95+
Assert.assertEquals(40, Address.LENGTH_IN_HEX);
96+
}
97+
98+
@Test
99+
public void testToUint160() {
100+
BigInteger value = BigInteger.valueOf(12345);
101+
Address address = new Address(value);
102+
Uint160 uint160 = address.toUint160();
103+
104+
Assert.assertNotNull(uint160);
105+
Assert.assertEquals(value, uint160.getValue());
106+
}
107+
}
108+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.fisco.bcos.sdk.v3.test.codec.datatypes;
2+
3+
import org.fisco.bcos.sdk.v3.codec.datatypes.Bool;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class BoolTest {
8+
9+
@Test
10+
public void testBoolWithPrimitiveTrue() {
11+
Bool bool = new Bool(true);
12+
Assert.assertTrue(bool.getValue());
13+
}
14+
15+
@Test
16+
public void testBoolWithPrimitiveFalse() {
17+
Bool bool = new Bool(false);
18+
Assert.assertFalse(bool.getValue());
19+
}
20+
21+
@Test
22+
public void testBoolWithBooleanTrue() {
23+
Bool bool = new Bool(Boolean.TRUE);
24+
Assert.assertTrue(bool.getValue());
25+
}
26+
27+
@Test
28+
public void testBoolWithBooleanFalse() {
29+
Bool bool = new Bool(Boolean.FALSE);
30+
Assert.assertFalse(bool.getValue());
31+
}
32+
33+
@Test
34+
public void testGetTypeAsString() {
35+
Bool bool = new Bool(true);
36+
Assert.assertEquals("bool", bool.getTypeAsString());
37+
}
38+
39+
@Test
40+
public void testEquals() {
41+
Bool bool1 = new Bool(true);
42+
Bool bool2 = new Bool(true);
43+
Bool bool3 = new Bool(false);
44+
45+
Assert.assertEquals(bool1, bool2);
46+
Assert.assertNotEquals(bool1, bool3);
47+
Assert.assertEquals(bool1, bool1);
48+
Assert.assertNotEquals(bool1, null);
49+
Assert.assertNotEquals(bool1, "String");
50+
}
51+
52+
@Test
53+
public void testHashCode() {
54+
Bool boolTrue1 = new Bool(true);
55+
Bool boolTrue2 = new Bool(true);
56+
Bool boolFalse = new Bool(false);
57+
58+
Assert.assertEquals(boolTrue1.hashCode(), boolTrue2.hashCode());
59+
Assert.assertNotEquals(boolTrue1.hashCode(), boolFalse.hashCode());
60+
Assert.assertEquals(1, boolTrue1.hashCode());
61+
Assert.assertEquals(0, boolFalse.hashCode());
62+
}
63+
64+
@Test
65+
public void testDefaultBool() {
66+
Assert.assertNotNull(Bool.DEFAULT);
67+
Assert.assertFalse(Bool.DEFAULT.getValue());
68+
}
69+
70+
@Test
71+
public void testTypeName() {
72+
Assert.assertEquals("bool", Bool.TYPE_NAME);
73+
}
74+
}
75+

0 commit comments

Comments
 (0)