Skip to content

Commit 94af3d7

Browse files
Merge remote-tracking branch 'main/master' into check-native-library-version-ECR-3148
2 parents 77b4ef8 + 201f5fc commit 94af3d7

File tree

13 files changed

+151
-8
lines changed

13 files changed

+151
-8
lines changed

exonum-java-binding/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1818
### Added
1919
- Verification of native library compatibility when it is first loaded, to detect
2020
possible mismatch between an installed exonum-java application and the version
21-
used in a service project. (#882)
21+
used in a service project. (#882)
22+
- `Block#isEmpty()`
2223

2324
## [0.6.0]- 2019-05-08
2425

exonum-java-binding/core/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717

1818
<!-- Allow `aBlock` name -->
1919
<suppress files="BlockchainIntegrationTest\.java" checks="MethodName"/>
20+
<suppress files="BlockTest\.java" checks="MethodName"/>
2021
</suppressions>

exonum-java-binding/core/rust/exonum-java/TUTORIAL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ There are also optional parameters useful for debugging purposes, logging config
100100

101101
```$sh
102102
$ exonum-java run -d testnet/db -c testnet/node.toml \
103-
--ejb-port 6000 \
103+
--ejb-port 7000 \
104104
--ejb-log-config-path "log4j.xml" \
105105
--consensus-key-pass pass \
106106
--service-key-pass pass \
@@ -116,7 +116,7 @@ from a debugger:
116116
```sh
117117
$ exonum-java run -d testnet/db -c testnet/node.toml --public-api-address 127.0.0.1:3000 \
118118
--ejb-log-config-path "log4j-fallback.xml" \
119-
--ejb-port 6000 \
119+
--ejb-port 7000 \
120120
--jvm-debug localhost:8000
121121
```
122122

exonum-java-binding/core/rust/exonum-java/start_cryptocurrency_node.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ cargo +$RUST_COMPILER_VERSION run -- run -d testnet/db -c testnet/node.toml \
7373
--service-key-pass pass \
7474
--public-api-address 127.0.0.1:3000 \
7575
--ejb-log-config-path $EJB_LOG_CONFIG_PATH \
76-
--ejb-port 6000
76+
--ejb-port 7000

exonum-java-binding/core/rust/exonum-java/start_qa_node.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ for i in $(seq 0 $((node_count - 1)))
9595
do
9696
port=$((3000 + i))
9797
private_port=$((port + 100))
98-
ejb_port=$((6000 + i))
98+
ejb_port=$((7000 + i))
9999
cargo +$RUST_COMPILER_VERSION run -- run \
100100
-c testnet/node_$i.toml \
101101
-d testnet/db/$i \

exonum-java-binding/core/src/main/java/com/exonum/binding/blockchain/Block.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public abstract class Block {
5858
*/
5959
public abstract long getHeight();
6060

61+
/**
62+
* Returns true if this block is empty:
63+
* contains no {@linkplain #getNumTransactions() transactions}.
64+
*/
65+
public final boolean isEmpty() {
66+
return getNumTransactions() == 0;
67+
}
68+
6169
/**
6270
* Number of transactions in this block.
6371
*/

exonum-java-binding/core/src/test/java/com/exonum/binding/blockchain/BlockTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,41 @@
1616

1717
package com.exonum.binding.blockchain;
1818

19+
import static java.nio.charset.StandardCharsets.UTF_8;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
23+
import com.exonum.binding.blockchain.Block.Builder;
1924
import com.exonum.binding.common.hash.HashCode;
25+
import com.exonum.binding.common.hash.HashFunction;
26+
import com.exonum.binding.common.hash.Hashing;
2027
import nl.jqno.equalsverifier.EqualsVerifier;
2128
import nl.jqno.equalsverifier.Warning;
2229
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.params.ParameterizedTest;
31+
import org.junit.jupiter.params.provider.ValueSource;
2332

2433
class BlockTest {
2534

35+
@Test
36+
void isEmpty() {
37+
Block emptyBlock = aBlock()
38+
.numTransactions(0)
39+
.build();
40+
41+
assertTrue(emptyBlock.isEmpty());
42+
}
43+
44+
@ParameterizedTest
45+
@ValueSource(ints = {1, 2, Integer.MAX_VALUE})
46+
void nonEmptyBlock(int numTransactions) {
47+
Block nonEmptyBlock = aBlock()
48+
.numTransactions(numTransactions)
49+
.build();
50+
51+
assertFalse(nonEmptyBlock.isEmpty());
52+
}
53+
2654
@Test
2755
void verifyEquals() {
2856
EqualsVerifier.forClass(AutoValue_Block.class)
@@ -33,4 +61,17 @@ void verifyEquals() {
3361
.withPrefabValues(HashCode.class, HashCode.fromInt(1), HashCode.fromInt(2))
3462
.verify();
3563
}
64+
65+
private static Builder aBlock() {
66+
HashFunction hashFunction = Hashing.sha256();
67+
long blockHeight = 1;
68+
return Block.builder()
69+
.proposerId(0)
70+
.height(blockHeight)
71+
.numTransactions(0)
72+
.blockHash(hashFunction.hashLong(blockHeight))
73+
.previousBlockHash(hashFunction.hashLong(blockHeight - 1))
74+
.txRootHash(hashFunction.hashString("transactions at" + blockHeight, UTF_8))
75+
.stateHash(hashFunction.hashString("state hash at " + blockHeight, UTF_8));
76+
}
3677
}

exonum-java-binding/cryptocurrency-demo/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ $ npm run build
5959
Run the frontend application:
6060

6161
```sh
62-
$ npm start -- --port=6040 --api-root=http://127.0.0.1:6000 --explorer-root=http://127.0.0.1:3000
62+
$ npm start -- --port=6040 --api-root=http://127.0.0.1:7000 --explorer-root=http://127.0.0.1:3000
6363
```
6464

6565
`--port` is a port for Node.JS app.

exonum-java-binding/cryptocurrency-demo/start-cryptocurrency-demo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ ${EXONUM_JAVA_APP} run -d testnet/db -c testnet/node.toml \
6767
--consensus-key-pass pass \
6868
--service-key-pass pass \
6969
--public-api-address 127.0.0.1:3000 \
70-
--ejb-port 6000
70+
--ejb-port 7000
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
3+
<!--
4+
~ Copyright 2019 The Exonum Team
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<!DOCTYPE suppressions PUBLIC
20+
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
21+
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
22+
23+
<suppressions>
24+
<!-- Allow `aBlock` name -->
25+
<suppress files="BlockTest\.java" checks="MethodName"/>
26+
</suppressions>

0 commit comments

Comments
 (0)