Skip to content

Commit b83503c

Browse files
Fixed test and release first version of library
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent f4bc412 commit b83503c

File tree

7 files changed

+37
-67
lines changed

7 files changed

+37
-67
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Publish package to the Maven Central Repository
22
on:
33
release:
44
types: [created]
5-
push:
6-
branches:
7-
- main
5+
#push:
6+
# branches:
7+
# - main
88
jobs:
99
build:
1010
runs-on: ubuntu-latest

gradle.properties

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
GROUP_ID=io.github.clightning4j
22
ARTIFACT_ID=lite-bitcoin-rpc
3-
VERSION=0.0.1-rc1-SNAPSHOT
4-
MODULE_NAME=io.clightning4j.litebitcoinrpc
5-
6-
#Information abaut the maven repository
7-
signing.keyId=
8-
signing.password=
9-
signing.secretKeyRingFile=
10-
ossrhUsername=
11-
ossrhPassword=
3+
VERSION=0.0.1-rc1
4+
MODULE_NAME=io.clightning4j.litebitcoinrpc

lib/src/main/java/io/github/clightning4j/litebtc/LiteBitcoinRPC.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public <T> T makeBitcoinRequest(Parameters parameters, Class<T> clazz)
6363
T result = HttpFactory.getInstance().makeRequest(parameters);
6464
String resultStr = converter.serialization(result);
6565
return (T) converter.deserialization(resultStr, clazz);
66-
} catch (BitcoinCoreException bitcoinCoreException) {
67-
throw bitcoinCoreException;
6866
} catch (UtilsExceptions utilsExceptions) {
6967
throw new LiteBitcoinRPCException(utilsExceptions.getCause());
7068
}

lib/src/main/java/io/github/clightning4j/litebtc/utils/okhttp/HttpFactory.java

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public <T> T makeRequest(Parameters parameters) throws UtilsExceptions, BitcoinC
8484
ResponseWrapper<T> wrapper =
8585
(ResponseWrapper<T>) converter.deserialization(message, type);
8686
if (wrapper.getError() != null) {
87+
LOGGER.debug("Bitcoin core error with message: " + wrapper.getError().getMessage());
8788
throw new BitcoinCoreException(
8889
wrapper.getError().getCode(), wrapper.getError().getMessage());
8990
}
@@ -106,52 +107,4 @@ public <T> T makeRequest(Parameters parameters) throws UtilsExceptions, BitcoinC
106107
throw new UtilsExceptions(e.getCause());
107108
}
108109
}
109-
110-
public <T> T makeRequestTest(Parameters parameters) throws UtilsExceptions {
111-
if (parameters == null) {
112-
LOGGER.error("Parameters object null");
113-
throw new UtilsExceptions("Parameters object null");
114-
}
115-
Authenticator.setDefault(
116-
new Authenticator() {
117-
@Override
118-
protected PasswordAuthentication getPasswordAuthentication() {
119-
return new PasswordAuthentication(
120-
configuration.getUser(), configuration.getPass().toCharArray());
121-
}
122-
});
123-
124-
try {
125-
HttpURLConnection httpcon =
126-
(HttpURLConnection) new URL(configuration.getUrl()).openConnection();
127-
httpcon.setDoOutput(true);
128-
httpcon.setRequestProperty("Content-Type", "application/json");
129-
httpcon.setRequestProperty("Accept", "application/json");
130-
httpcon.setRequestMethod("POST");
131-
httpcon.connect();
132-
133-
OutputStream stream = httpcon.getOutputStream();
134-
String jsonBody = converter.serialization(parameters);
135-
LOGGER.debug("JSON body:\n" + jsonBody);
136-
stream.write(jsonBody.getBytes());
137-
int code = httpcon.getResponseCode();
138-
boolean isError = code >= 400 && code <= 500;
139-
String text = "";
140-
if (isError) {
141-
LOGGER.error("Eroror with code: " + code);
142-
throw new UtilsExceptions("error");
143-
} else {
144-
InputStream inputStream = httpcon.getInputStream();
145-
if (inputStream != null) {
146-
text = new String(inputStream.readAllBytes());
147-
}
148-
}
149-
LOGGER.error("Response from bitcoind\n" + text);
150-
Type type = new TypeToken<T>() {}.getType();
151-
return (T) converter.deserialization(text, type.getClass());
152-
} catch (IOException e) {
153-
LOGGER.error("Exception in makeRequest" + e.getLocalizedMessage());
154-
throw new UtilsExceptions(e.getCause());
155-
}
156-
}
157110
}

lib/src/main/resources/logback.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
</encoder>
1212
</appender>
1313

14+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
15+
<!-- encoders are assigned the type
16+
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
17+
<encoder>
18+
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
19+
</encoder>
20+
</appender>
21+
1422
<root level="INFO">
1523
<appender-ref ref="FILE" />
24+
<appender-ref ref="STDOUT" />
1625
</root>
1726

1827
<logger name="io.github.clightning4j.litebtc" level="INFO">
1928
<appender-ref ref="FILE" />
29+
<appender-ref ref="STDOUT" />
2030
</logger>
2131
</configuration>

lib/src/test/java/io/github/clightning4j/litebtc/LiteBitcoinRPCTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,19 @@ public void estimateFeeRateWithError() {
6060
}
6161
}
6262

63-
@Test(expected = BitcoinCoreException.class)
64-
public void getUTXOWithError() throws BitcoinCoreException, LiteBitcoinRPCException {
63+
@Test
64+
public void getUTXOWithError() {
6565
Parameters parameters = new Parameters("gettxout");
6666
parameters.addParameter("txid", "txid");
6767
parameters.addParameter("n", 0);
68-
bitcoinRPC.makeBitcoinRequest(parameters, BitcoinUTXO.class);
69-
TestCase.fail("Expected BitcoinCoreException but we not receive it");
68+
try {
69+
bitcoinRPC.makeBitcoinRequest(parameters, BitcoinUTXO.class);
70+
TestCase.fail("Expected BitcoinCoreException but we not receive it");
71+
} catch (LiteBitcoinRPCException e) {
72+
TestCase.fail("Wrong exception received (LiteBitcoinRPCException)");
73+
} catch (BitcoinCoreException bitcoinCoreException) {
74+
TestCase.assertNotNull(bitcoinCoreException);
75+
}
7076
}
7177

7278
@Test
@@ -76,11 +82,11 @@ public void getUTXOWithErrorWithMessage() throws LiteBitcoinRPCException {
7682
parameters.addParameter("n", 0);
7783
try {
7884
bitcoinRPC.makeBitcoinRequest(parameters, BitcoinUTXO.class);
85+
TestCase.fail("Expected BitcoinCoreException but we not receive it");
7986
} catch (BitcoinCoreException bitcoinCoreException) {
8087
TestCase.assertEquals(-8, bitcoinCoreException.getCode());
8188
TestCase.assertEquals(
8289
"txid must be of length 64 (not 4, for 'txid')", bitcoinCoreException.getMessage());
8390
}
84-
TestCase.fail("Expected BitcoinCoreException but we not receive it");
8591
}
8692
}

lib/src/test/resources/logback.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
</encoder>
1212
</appender>
1313

14+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
15+
<!-- encoders are assigned the type
16+
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
17+
<encoder>
18+
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
19+
</encoder>
20+
</appender>
21+
1422
<root level="INFO">
1523
<appender-ref ref="FILE" />
24+
<appender-ref ref="STDOUT" />
1625
</root>
1726

1827
<logger name="io.github.clightning4j.litebtc" level="DEBUG">
1928
<appender-ref ref="FILE" />
29+
<appender-ref ref="STDOUT" />
2030
</logger>
2131
</configuration>

0 commit comments

Comments
 (0)