From 97bed825d894c1c1b121417eafcfb83a7001a430 Mon Sep 17 00:00:00 2001 From: maximo santoro <maximo.santoro@iovlabs.org> Date: Thu, 15 Feb 2024 15:18:18 -0300 Subject: [PATCH 01/12] remove unused imports --- rskj-core/src/main/java/co/rsk/net/NodeMessageHandler.java | 1 - .../main/java/co/rsk/net/messages/SnapStatusRequestMessage.java | 2 -- .../main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java | 1 - rskj-core/src/main/java/co/rsk/net/sync/SnapSyncState.java | 1 - .../src/main/java/co/rsk/rpc/modules/rsk/RskModuleImpl.java | 2 -- .../main/java/org/ethereum/net/server/ChannelManagerImpl.java | 1 - 6 files changed, 8 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/net/NodeMessageHandler.java b/rskj-core/src/main/java/co/rsk/net/NodeMessageHandler.java index ce6654cbfe6..59a229f4dc8 100644 --- a/rskj-core/src/main/java/co/rsk/net/NodeMessageHandler.java +++ b/rskj-core/src/main/java/co/rsk/net/NodeMessageHandler.java @@ -30,7 +30,6 @@ import co.rsk.util.MaxSizeHashMap; import co.rsk.util.TraceUtils; import com.google.common.annotations.VisibleForTesting; -import org.ethereum.core.BlockIdentifier; import org.ethereum.crypto.HashUtil; import org.ethereum.net.server.ChannelManager; import org.slf4j.Logger; diff --git a/rskj-core/src/main/java/co/rsk/net/messages/SnapStatusRequestMessage.java b/rskj-core/src/main/java/co/rsk/net/messages/SnapStatusRequestMessage.java index 90499a8b67a..6ee06c4df0c 100644 --- a/rskj-core/src/main/java/co/rsk/net/messages/SnapStatusRequestMessage.java +++ b/rskj-core/src/main/java/co/rsk/net/messages/SnapStatusRequestMessage.java @@ -2,8 +2,6 @@ import org.ethereum.util.RLP; -import java.math.BigInteger; - public class SnapStatusRequestMessage extends Message { public SnapStatusRequestMessage() { diff --git a/rskj-core/src/main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java b/rskj-core/src/main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java index 81132ec9029..d9bc6596ee9 100644 --- a/rskj-core/src/main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java +++ b/rskj-core/src/main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java @@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory; import java.time.Duration; -import java.util.Collections; import java.util.List; import java.util.Optional; diff --git a/rskj-core/src/main/java/co/rsk/net/sync/SnapSyncState.java b/rskj-core/src/main/java/co/rsk/net/sync/SnapSyncState.java index 1457f10db68..2b845288b44 100644 --- a/rskj-core/src/main/java/co/rsk/net/sync/SnapSyncState.java +++ b/rskj-core/src/main/java/co/rsk/net/sync/SnapSyncState.java @@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory; import java.time.Duration; -import java.util.List; public class SnapSyncState extends BaseSyncState { diff --git a/rskj-core/src/main/java/co/rsk/rpc/modules/rsk/RskModuleImpl.java b/rskj-core/src/main/java/co/rsk/rpc/modules/rsk/RskModuleImpl.java index f1fa7e050db..99abf0fba78 100644 --- a/rskj-core/src/main/java/co/rsk/rpc/modules/rsk/RskModuleImpl.java +++ b/rskj-core/src/main/java/co/rsk/rpc/modules/rsk/RskModuleImpl.java @@ -15,7 +15,6 @@ import org.ethereum.db.BlockStore; import org.ethereum.db.ReceiptStore; import org.ethereum.db.TransactionInfo; -import org.ethereum.util.ByteUtil; import org.ethereum.util.RLP; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +33,6 @@ public class RskModuleImpl implements RskModule { private final ReceiptStore receiptStore; private final Web3InformationRetriever web3InformationRetriever; private final Flusher flusher; - private final NodeStopper nodeStopper; private final RskSystemProperties rskSystemProperties; diff --git a/rskj-core/src/main/java/org/ethereum/net/server/ChannelManagerImpl.java b/rskj-core/src/main/java/org/ethereum/net/server/ChannelManagerImpl.java index 606628989a7..26f68a61244 100644 --- a/rskj-core/src/main/java/org/ethereum/net/server/ChannelManagerImpl.java +++ b/rskj-core/src/main/java/org/ethereum/net/server/ChannelManagerImpl.java @@ -31,7 +31,6 @@ import org.ethereum.core.Block; import org.ethereum.core.BlockIdentifier; import org.ethereum.core.Transaction; -import org.ethereum.crypto.HashUtil; import org.ethereum.net.message.ReasonCode; import org.ethereum.sync.SyncPool; import org.slf4j.Logger; From 643fc50ee8cba5321adeae2f4fe195c21327d330 Mon Sep 17 00:00:00 2001 From: maximo santoro <maximo.santoro@iovlabs.org> Date: Thu, 15 Feb 2024 15:19:49 -0300 Subject: [PATCH 02/12] remove unnecessary log --- rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java b/rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java index 02a0efd5380..da5df5721bb 100644 --- a/rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java +++ b/rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java @@ -388,7 +388,6 @@ private void generateChunkRequestTasks() { chunkTasks.add(task); from += chunkSize * 1024L; } - logger.debug("Generated: {} chunk request tasks.", chunkTasks.size()); } private void startRequestingChunks() { From c2d465793488af4d11759d88e4f839bbbe7fe33b Mon Sep 17 00:00:00 2001 From: maximo santoro <maximo.santoro@iovlabs.org> Date: Thu, 15 Feb 2024 15:20:22 -0300 Subject: [PATCH 03/12] change return to default due to sonarcloud complain --- rskj-core/src/main/java/org/ethereum/net/server/Stats.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rskj-core/src/main/java/org/ethereum/net/server/Stats.java b/rskj-core/src/main/java/org/ethereum/net/server/Stats.java index 5265df56c9e..26e50910aa0 100644 --- a/rskj-core/src/main/java/org/ethereum/net/server/Stats.java +++ b/rskj-core/src/main/java/org/ethereum/net/server/Stats.java @@ -117,7 +117,6 @@ public double score(MessageType type) { } private double priority(MessageType type) { - switch (type) { case TRANSACTIONS: return 2; @@ -152,8 +151,9 @@ private double priority(MessageType type) { case BLOCK_HEADERS_RESPONSE_MESSAGE: return 5; // TODO (pato) add priority for Snap sync messages. + default: + return 0.0; } - return 0.0; } public synchronized void imported(boolean best) { if (best) { From 6343952a05542a4e28804975a1211ddfcc959e83 Mon Sep 17 00:00:00 2001 From: maximo santoro <maximo.santoro@iovlabs.org> Date: Thu, 15 Feb 2024 15:20:51 -0300 Subject: [PATCH 04/12] refactor conditionals --- .../src/main/java/co/rsk/trie/TrieDTO.java | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/trie/TrieDTO.java b/rskj-core/src/main/java/co/rsk/trie/TrieDTO.java index 85b9b8f648e..64bfa97ba60 100644 --- a/rskj-core/src/main/java/co/rsk/trie/TrieDTO.java +++ b/rskj-core/src/main/java/co/rsk/trie/TrieDTO.java @@ -25,7 +25,6 @@ import co.rsk.util.HexUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.tuple.Pair; -import org.bouncycastle.util.encoders.Hex; import org.ethereum.crypto.Keccak256Helper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -300,9 +299,18 @@ public byte[] getValue() { } public boolean isTerminal() { - return (!this.leftNodePresent && !this.rightNodePresent) || - !((this.leftNodePresent && !this.leftNodeEmbedded) || - (this.rightNodePresent && !this.rightNodeEmbedded)); + // old impl: +// return (!this.leftNodePresent && !this.rightNodePresent) || +// !((this.leftNodePresent && !this.leftNodeEmbedded) || +// (this.rightNodePresent && !this.rightNodeEmbedded)); + if (!this.leftNodePresent && !this.rightNodePresent) { + return true; + } + + boolean isLeftTerminal = !this.leftNodePresent || this.leftNodeEmbedded; + boolean isRightTerminal = !this.rightNodePresent || this.rightNodeEmbedded; + + return isLeftTerminal && isRightTerminal; } public byte[] getLeft() { @@ -401,14 +409,25 @@ public String toDescription() { * Based on {@link Trie:toMessage()} */ public byte[] toMessage() { - ByteBuffer buffer = ByteBuffer.allocate( - 1 + // flags - (this.sharedPrefixPresent ? SharedPathSerializer.calculateVarIntSize(this.pathLength) + this.path.length : 0) + - serializedLength(leftNodePresent, leftNodeEmbedded, left) + - serializedLength(rightNodePresent, rightNodeEmbedded, right) + - ((leftNodePresent || rightNodePresent) ? childrenSize.getSizeInBytes() : 0) + - (hasLongVal ? Keccak256Helper.DEFAULT_SIZE_BYTES + Uint24.BYTES : value.length) - ); +// ByteBuffer buffer = ByteBuffer.allocate( +// 1 + // flags +// (this.sharedPrefixPresent ? SharedPathSerializer.calculateVarIntSize(this.pathLength) + this.path.length : 0) + +// serializedLength(leftNodePresent, leftNodeEmbedded, left) + +// serializedLength(rightNodePresent, rightNodeEmbedded, right) + +// ((leftNodePresent || rightNodePresent) ? childrenSize.getSizeInBytes() : 0) + +// (hasLongVal ? Keccak256Helper.DEFAULT_SIZE_BYTES + Uint24.BYTES : value.length) +// ); + + int sharedPrefixSize = this.sharedPrefixPresent ? SharedPathSerializer.calculateVarIntSize(this.pathLength) + this.path.length : 0; + int leftNodeSize = serializedLength(leftNodePresent, leftNodeEmbedded, left); + int rightNodeSize = serializedLength(rightNodePresent, rightNodeEmbedded, right); + int childrenSizeBytes = (leftNodePresent || rightNodePresent) ? childrenSize.getSizeInBytes() : 0; + int valueSize = hasLongVal ? Keccak256Helper.DEFAULT_SIZE_BYTES + Uint24.BYTES : value.length; + + int totalSize = 1 + sharedPrefixSize + leftNodeSize + rightNodeSize + childrenSizeBytes + valueSize; + + ByteBuffer buffer = ByteBuffer.allocate(totalSize); + buffer.put(flags); if (this.sharedPrefixPresent) { SharedPathSerializer.serializeBytes(buffer, this.pathLength, this.path); From 10ca7541909943ade570d9e872e08f0503108d39 Mon Sep 17 00:00:00 2001 From: maximo santoro <maximo.santoro@iovlabs.org> Date: Thu, 15 Feb 2024 15:21:14 -0300 Subject: [PATCH 05/12] check for null porinters --- .../co/rsk/trie/TrieDTOInOrderIterator.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/trie/TrieDTOInOrderIterator.java b/rskj-core/src/main/java/co/rsk/trie/TrieDTOInOrderIterator.java index 57f6696bf4d..98529880016 100644 --- a/rskj-core/src/main/java/co/rsk/trie/TrieDTOInOrderIterator.java +++ b/rskj-core/src/main/java/co/rsk/trie/TrieDTOInOrderIterator.java @@ -55,7 +55,13 @@ private TrieDTO findByChildrenSize(long offset, TrieDTO nodeDTO, Deque<TrieDTO> if (nodeDTO.isLeftNodePresent() && !nodeDTO.isLeftNodeEmbedded()) { TrieDTO left = getNode(nodeDTO.getLeftHash()); + + if (left == null) { + throw new NullPointerException("Left node is null"); + } + long maxLeftSize = left.getTotalSize(); + if (offset <= maxLeftSize) { visiting.push(nodeDTO); return findByChildrenSize(offset, left, visiting); @@ -64,25 +70,26 @@ private TrieDTO findByChildrenSize(long offset, TrieDTO nodeDTO, Deque<TrieDTO> if (offset <= maxLeftSize) { return pushAndReturn(nodeDTO, visiting, (offset - left.getTotalSize())); } - } else if (nodeDTO.isLeftNodePresent() && nodeDTO.isLeftNodeEmbedded()) { - if (offset <= nodeDTO.getLeftSize()) { + } else if (nodeDTO.isLeftNodePresent() && nodeDTO.isLeftNodeEmbedded() && (offset <= nodeDTO.getLeftSize())) { return pushAndReturn(nodeDTO, visiting, offset); - } } if (nodeDTO.isRightNodePresent() && !nodeDTO.isRightNodeEmbedded()) { TrieDTO right = getNode(nodeDTO.getRightHash()); + if (right == null) { + throw new NullPointerException("Right node is null."); + } + long maxParentSize = nodeDTO.getTotalSize() - right.getTotalSize(); long maxRightSize = nodeDTO.getTotalSize(); + if (maxParentSize < offset && offset <= maxRightSize) { preRootNodes.add(nodeDTO); return findByChildrenSize(offset - maxParentSize, right, visiting); } - } else if (nodeDTO.isRightNodeEmbedded()) { - if (offset <= nodeDTO.getTotalSize()) { + } else if (nodeDTO.isRightNodeEmbedded() && (offset <= nodeDTO.getTotalSize())) { long leftAndParentSize = nodeDTO.getTotalSize() - nodeDTO.getRightSize(); return pushAndReturn(nodeDTO, visiting, offset - leftAndParentSize); - } } } if (nodeDTO.getTotalSize() >= offset) { From 5ad489c3ed533342027d0b22d725ee07377e0961 Mon Sep 17 00:00:00 2001 From: maximo santoro <maximo.santoro@iovlabs.org> Date: Thu, 15 Feb 2024 15:21:42 -0300 Subject: [PATCH 06/12] throw unsupported exception --- .../src/main/java/co/rsk/trie/TrieDTOInOrderRecoverer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rskj-core/src/main/java/co/rsk/trie/TrieDTOInOrderRecoverer.java b/rskj-core/src/main/java/co/rsk/trie/TrieDTOInOrderRecoverer.java index 5ca71a6f0da..7f5da29ddfa 100644 --- a/rskj-core/src/main/java/co/rsk/trie/TrieDTOInOrderRecoverer.java +++ b/rskj-core/src/main/java/co/rsk/trie/TrieDTOInOrderRecoverer.java @@ -30,6 +30,9 @@ public class TrieDTOInOrderRecoverer { private static final Logger logger = LoggerFactory.getLogger(TrieDTOInOrderRecoverer.class); + private TrieDTOInOrderRecoverer() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } public static Optional<TrieDTO> recoverTrie(TrieDTO[] trieCollection, Consumer<? super TrieDTO> processTrieDTO) { Optional<TrieDTO> result = recoverSubtree(trieCollection, 0, trieCollection.length - 1, processTrieDTO); From a3d4b668f14033b3d25ea9526ce048b0a755f45c Mon Sep 17 00:00:00 2001 From: fmacleal <frederico.macielleal@iovlabs.org> Date: Fri, 1 Mar 2024 14:30:06 +0100 Subject: [PATCH 07/12] Adding unit tests for the snapsynch classes - Also added the assertJ test library --- gradle/verification-metadata.xml | 21 +++++ rskj-core/build.gradle | 3 + .../SnapBlocksRequestMessageTest.java | 66 +++++++++++++ .../SnapBlocksResponseMessageTest.java | 93 +++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java create mode 100644 rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 68389a3f4b8..78d2cf1e75f 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -697,6 +697,14 @@ <sha256 value="d6f158ba70a080da562f8561a824e94b176c4c8cf4494daf695899c911395889" origin="Generated by Gradle"/> </artifact> </component> + <component group="net.bytebuddy" name="byte-buddy" version="1.14.11"> + <artifact name="byte-buddy-1.14.11.jar"> + <sha256 value="62ae28187ed2b062813da6a9d567bfee733c341582699b62dd980230729a0313" origin="Generated by Gradle"/> + </artifact> + <artifact name="byte-buddy-1.14.11.pom"> + <sha256 value="358449d6c73538584508dd8ae6cfde56baf4a34b767b71d9cc4644f0f1f4211a" origin="Generated by Gradle"/> + </artifact> + </component> <component group="net.bytebuddy" name="byte-buddy-agent" version="1.12.10"> <artifact name="byte-buddy-agent-1.12.10.jar"> <sha256 value="5e8606d14a844c1ec70d2eb8f50c4009fb16138905dee8ca50a328116c041257" origin="Generated by Gradle"/> @@ -710,6 +718,11 @@ <sha256 value="e2870e4340a748e717c8e764060504b90c28b9f7598e7779838d38caeea0b9d1" origin="Generated by Gradle"/> </artifact> </component> + <component group="net.bytebuddy" name="byte-buddy-parent" version="1.14.11"> + <artifact name="byte-buddy-parent-1.14.11.pom"> + <sha256 value="46c0f13fc9778dc2ebb69748823aa2c4cbf07eab7d18c6aa191c529d1650892b" origin="Generated by Gradle"/> + </artifact> + </component> <component group="net.iharder" name="base64" version="2.3.9"> <artifact name="base64-2.3.9.jar"> <sha256 value="f1a0e359eee29a5939c35e5fdedc574dd7e8ca065b056fc14b2b29e3ed3cd54d" origin="Generated by Gradle"/> @@ -814,6 +827,14 @@ <sha256 value="e08028131375b357d1d28734e9a4fb4216da84b240641cb3ef7e7c7d628223fc" origin="Generated by Gradle"/> </artifact> </component> + <component group="org.assertj" name="assertj-core" version="3.25.3"> + <artifact name="assertj-core-3.25.3.jar"> + <sha256 value="7fbdffa1996d43cc08e2576e01008b07e57bbad2b4741aa6c3ab73ce8511130e" origin="Generated by Gradle"/> + </artifact> + <artifact name="assertj-core-3.25.3.pom"> + <sha256 value="3917230eaa33bcf13ea33dd337acafa9d326c739660bf4b6fc56c88d78feb9f2" origin="Generated by Gradle"/> + </artifact> + </component> <component group="org.awaitility" name="awaitility" version="4.2.0"> <artifact name="awaitility-4.2.0.jar"> <sha256 value="2d23b79211fdd19036f6940cc783543779320aaf86f38d6e385a2ff26da41272" origin="Generated by Gradle"/> diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index 1559514a43f..33cdc9965b2 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -158,6 +158,7 @@ ext { commonsCodecVer: '1.15', jacksonVer : '2.13.3', okhttpWsVer : '2.7.5', + assertJVer : '3.25.3', rskLllVer : '0.0.2', ] @@ -178,6 +179,7 @@ ext { commonsCodecLib : "commons-codec:commons-codec:${testLibVersions.commonsCodecVer}", jacksonLib : "com.fasterxml.jackson.core:jackson-databind:${testLibVersions.jacksonVer}", okhttpWsLib : "com.squareup.okhttp:okhttp-ws:${testLibVersions.okhttpWsVer}", + assertJLib : "org.assertj:assertj-core:${testLibVersions.assertJVer}", rskLllLib : "co.rsk:lll-compiler:${testLibVersions.rskLllVer}", ] @@ -231,6 +233,7 @@ dependencies { testImplementation "${testLibs.commonsIoLib}" testImplementation "${testLibs.commonsCodecLib}" testImplementation "${testLibs.okhttpWsLib}" + testImplementation "${testLibs.assertJLib}" testImplementation "${testLibs.rskLllLib}" integrationTestImplementation "${testLibs.junitLib}" diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java new file mode 100644 index 00000000000..4ad4f4bab8c --- /dev/null +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java @@ -0,0 +1,66 @@ +package co.rsk.net.messages; + +import co.rsk.blockchain.utils.BlockGenerator; +import org.ethereum.core.Block; +import org.ethereum.util.RLP; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; + +class SnapBlocksRequestMessageTest { + + private Block block4Test = new BlockGenerator().getBlock(1); + private SnapBlocksRequestMessage underTest = new SnapBlocksRequestMessage(block4Test.getNumber()); + + + @Test + void getMessageType_returnCorrectMessageType() { + //given-when + MessageType messageType = underTest.getMessageType(); + + //then + assertEquals(MessageType.SNAP_BLOCKS_REQUEST_MESSAGE, messageType); + } + + @Test + void getEncodedMessage_returnExpectedByteArray() { + //given default block 4 test + + //when + byte[] encodedMessage = underTest.getEncodedMessage(); + + //then + assertThat(encodedMessage) + .isEqualTo(RLP.encodeList(RLP.encodeBigInteger(BigInteger.ONE))); + } + + @Test + void getBlockNumber_returnTheExpectedValue() { + //given default block 4 test + + //when + long blockNumber = underTest.getBlockNumber(); + + //then + assertThat(blockNumber) + .isEqualTo(block4Test.getNumber()); + } + + @Test + void givenAcceptIsCalled_messageVisitorIsAppliedFormessage() { + //given + Block block = new BlockGenerator().getBlock(1); + SnapBlocksRequestMessage message = new SnapBlocksRequestMessage(block.getNumber()); + MessageVisitor visitor = mock(MessageVisitor.class); + + //when + message.accept(visitor); + + //then + verify(visitor, times(1)).apply(message); + } +} \ No newline at end of file diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java new file mode 100644 index 00000000000..5f33fffe7e5 --- /dev/null +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java @@ -0,0 +1,93 @@ +package co.rsk.net.messages; + +import co.rsk.blockchain.utils.BlockGenerator; +import co.rsk.config.TestSystemProperties; +import co.rsk.core.BlockDifficulty; +import co.rsk.db.HashMapBlocksIndex; +import org.ethereum.core.Block; +import org.ethereum.core.BlockFactory; +import org.ethereum.datasource.HashMapDB; +import org.ethereum.db.BlockStore; +import org.ethereum.db.IndexedBlockStore; +import org.ethereum.util.RLP; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; + +class SnapBlocksResponseMessageTest { + + private final TestSystemProperties config = new TestSystemProperties(); + private final BlockFactory blockFactory = new BlockFactory(config.getActivationConfig()); + private final BlockStore indexedBlockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex()); + + private final Block block4Test = new BlockGenerator().getBlock(1); + private List<Block> blockList = Arrays.asList(new BlockGenerator().getBlock(1)); + private List<BlockDifficulty> blockDifficulties = Arrays.asList(indexedBlockStore.getTotalDifficultyForHash(block4Test.getHash().getBytes())); + + private SnapBlocksResponseMessage underTest = new SnapBlocksResponseMessage(blockList, blockDifficulties); + + + @Test + void getMessageType_returnCorrectMessageType() { + //given-when + MessageType messageType = underTest.getMessageType(); + + //then + assertEquals(MessageType.SNAP_BLOCKS_RESPONSE_MESSAGE, messageType); + } + + @Test + void getEncodedMessage_returnExpectedByteArray() { + //given default block 4 test + byte[] expectedEncodedMessage = RLP.encodeList( + RLP.encodeList(RLP.encode(block4Test.getEncoded())), + RLP.encodeList(RLP.encode(blockDifficulties.get(0).getBytes()))); + //when + byte[] encodedMessage = underTest.getEncodedMessage(); + + //then + assertThat(encodedMessage) + .isEqualTo(encodedMessage); + } + + @Test + void getDifficulties_returnTheExpectedValue() { + //given default block 4 test + + //when + List<BlockDifficulty> difficultiesReturned = underTest.getDifficulties(); + //then + assertThat(difficultiesReturned) + .isEqualTo(blockDifficulties); + } + + @Test + void getBlocks_returnTheExpectedValue() { + //given default block 4 test + + //when + List<Block> blocksReturned = underTest.getBlocks(); + //then + assertThat(blocksReturned) + .isEqualTo(blockList); + } + + @Test + void givenAcceptIsCalled_messageVisitorIsAppliedFormessage() { + //given + Block block = new BlockGenerator().getBlock(1); + SnapBlocksRequestMessage message = new SnapBlocksRequestMessage(block.getNumber()); + MessageVisitor visitor = mock(MessageVisitor.class); + + //when + message.accept(visitor); + + //then + verify(visitor, times(1)).apply(message); + } +} \ No newline at end of file From bca0b7f072493b2210de6a9c38245b3248522915 Mon Sep 17 00:00:00 2001 From: fmacleal <frederico.macielleal@iovlabs.org> Date: Fri, 1 Mar 2024 20:31:08 +0100 Subject: [PATCH 08/12] Addition of more tests for the messages --- .../SnapBlocksResponseMessageTest.java | 5 +- .../SnapStateChunkRequestMessageTest.java | 89 +++++++++++++++++-- 2 files changed, 83 insertions(+), 11 deletions(-) diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java index 5f33fffe7e5..8e0fd958d86 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java @@ -28,7 +28,6 @@ class SnapBlocksResponseMessageTest { private final Block block4Test = new BlockGenerator().getBlock(1); private List<Block> blockList = Arrays.asList(new BlockGenerator().getBlock(1)); private List<BlockDifficulty> blockDifficulties = Arrays.asList(indexedBlockStore.getTotalDifficultyForHash(block4Test.getHash().getBytes())); - private SnapBlocksResponseMessage underTest = new SnapBlocksResponseMessage(blockList, blockDifficulties); @@ -52,7 +51,7 @@ void getEncodedMessage_returnExpectedByteArray() { //then assertThat(encodedMessage) - .isEqualTo(encodedMessage); + .isEqualTo(expectedEncodedMessage); } @Test @@ -78,7 +77,7 @@ void getBlocks_returnTheExpectedValue() { } @Test - void givenAcceptIsCalled_messageVisitorIsAppliedFormessage() { + void givenAcceptIsCalled_messageVisitorIsAppliedForMessage() { //given Block block = new BlockGenerator().getBlock(1); SnapBlocksRequestMessage message = new SnapBlocksRequestMessage(block.getNumber()); diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java index de004cbad02..2bc8806ca44 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java @@ -1,32 +1,105 @@ package co.rsk.net.messages; +import co.rsk.blockchain.utils.BlockGenerator; import org.ethereum.TestUtils; +import org.ethereum.core.Block; +import org.ethereum.util.RLP; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.math.BigInteger; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; public class SnapStateChunkRequestMessageTest { + @Test - void createMessage() { - long someId = 42; - SnapStateChunkRequestMessage message = new SnapStateChunkRequestMessage(someId, 0L, 0L, 0L); + void getMessageType_returnCorrectMessageType() { + //given + Block block = new BlockGenerator().getBlock(1); + long id4Test = 42L; + SnapStateChunkRequestMessage message = new SnapStateChunkRequestMessage(id4Test, block.getNumber(), 0L, 0L); + + //when + MessageType messageType = message.getMessageType(); + + //then + assertThat(messageType).isEqualTo(MessageType.STATE_CHUNK_REQUEST_MESSAGE); + } + @Test + void givenParameters4Test_assureExpectedValues() { + //given + Block block = new BlockGenerator().getBlock(1); + long id4Test = 42L; + long from = 5L; + long chunkSize = 10L; + + //when + SnapStateChunkRequestMessage message = new SnapStateChunkRequestMessage(id4Test, block.getNumber(), from, chunkSize); + + //then + assertThat(message).extracting(SnapStateChunkRequestMessage::getId, + SnapStateChunkRequestMessage::getBlockNumber, SnapStateChunkRequestMessage::getFrom, SnapStateChunkRequestMessage::getChunkSize) + .containsExactly(id4Test, block.getNumber(), from, chunkSize); + } + - Assertions.assertEquals(someId, message.getId()); - Assertions.assertEquals(MessageType.STATE_CHUNK_REQUEST_MESSAGE, message.getMessageType()); + @Test + void getEncodedMessageWithoutId_returnExpectedByteArray() { + //given + long blockNumber = 1L; + long id4Test = 42L; + long from = 1L; + long chunkSize = 20L; + byte[] expectedEncodedMessage = RLP.encodeList( + RLP.encodeBigInteger(BigInteger.valueOf(blockNumber)), + RLP.encodeBigInteger(BigInteger.valueOf(from)), + RLP.encodeBigInteger(BigInteger.valueOf(chunkSize))); + + SnapStateChunkRequestMessage message = new SnapStateChunkRequestMessage(id4Test, blockNumber, from, chunkSize); + + //when + byte[] encodedMessage = message.getEncodedMessageWithoutId(); + + //then + assertThat(encodedMessage) + .isEqualTo(expectedEncodedMessage); + } + + @Test + void getEncodedMessageWithId_returnExpectedByteArray() { + //given + long blockNumber = 1L; + long id4Test = 42L; + long from = 1L; + long chunkSize = 20L; + + SnapStateChunkRequestMessage message = new SnapStateChunkRequestMessage(id4Test, blockNumber, from, chunkSize); + byte[] expectedEncodedMessage = RLP.encodeList( + RLP.encodeBigInteger(BigInteger.valueOf(id4Test)), message.getEncodedMessageWithoutId()); + + //when + byte[] encodedMessage = message.getEncodedMessage(); + + //then + assertThat(encodedMessage) + .isEqualTo(expectedEncodedMessage); } @Test - void accept() { + void givenAcceptIsCalled_messageVisitorIsAppliedForMessage() { + //given long someId = 42; byte[] someHash = TestUtils.generateBytes("msg",32); - SnapStateChunkRequestMessage message = new SnapStateChunkRequestMessage(someId, 0L, 0L, 0L); - MessageVisitor visitor = mock(MessageVisitor.class); + //when message.accept(visitor); + //then verify(visitor, times(1)).apply(message); } } From 0119b858ea7c0274692e817e4510486cb43c4464 Mon Sep 17 00:00:00 2001 From: fmacleal <frederico.macielleal@iovlabs.org> Date: Tue, 5 Mar 2024 17:35:10 +0100 Subject: [PATCH 09/12] Addition of more tests for the messages --- .../SnapBlocksResponseMessageTest.java | 13 +- .../SnapStateChunkRequestMessageTest.java | 4 - .../SnapStateChunkResponseMessageTest.java | 121 ++++++++++++++++++ .../SnapStatusRequestMessageTest.java | 47 +++++++ .../SnapStatusResponseMessageTest.java | 104 +++++++++++++++ .../src/test/java/org/ethereum/TestUtils.java | 11 +- 6 files changed, 279 insertions(+), 21 deletions(-) create mode 100644 rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java create mode 100644 rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java create mode 100644 rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java index 8e0fd958d86..e979c0c6138 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java @@ -12,7 +12,7 @@ import org.ethereum.util.RLP; import org.junit.jupiter.api.Test; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -24,11 +24,10 @@ class SnapBlocksResponseMessageTest { private final TestSystemProperties config = new TestSystemProperties(); private final BlockFactory blockFactory = new BlockFactory(config.getActivationConfig()); private final BlockStore indexedBlockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex()); - private final Block block4Test = new BlockGenerator().getBlock(1); - private List<Block> blockList = Arrays.asList(new BlockGenerator().getBlock(1)); - private List<BlockDifficulty> blockDifficulties = Arrays.asList(indexedBlockStore.getTotalDifficultyForHash(block4Test.getHash().getBytes())); - private SnapBlocksResponseMessage underTest = new SnapBlocksResponseMessage(blockList, blockDifficulties); + private final List<Block> blockList = Collections.singletonList(new BlockGenerator().getBlock(1)); + private final List<BlockDifficulty> blockDifficulties = Collections.singletonList(indexedBlockStore.getTotalDifficultyForHash(block4Test.getHash().getBytes())); + private final SnapBlocksResponseMessage underTest = new SnapBlocksResponseMessage(blockList, blockDifficulties); @Test @@ -79,8 +78,7 @@ void getBlocks_returnTheExpectedValue() { @Test void givenAcceptIsCalled_messageVisitorIsAppliedForMessage() { //given - Block block = new BlockGenerator().getBlock(1); - SnapBlocksRequestMessage message = new SnapBlocksRequestMessage(block.getNumber()); + SnapBlocksResponseMessage message = new SnapBlocksResponseMessage(blockList, blockDifficulties); MessageVisitor visitor = mock(MessageVisitor.class); //when @@ -89,4 +87,5 @@ void givenAcceptIsCalled_messageVisitorIsAppliedForMessage() { //then verify(visitor, times(1)).apply(message); } + } \ No newline at end of file diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java index 2bc8806ca44..5fd944b850d 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java @@ -1,16 +1,13 @@ package co.rsk.net.messages; import co.rsk.blockchain.utils.BlockGenerator; -import org.ethereum.TestUtils; import org.ethereum.core.Block; import org.ethereum.util.RLP; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.math.BigInteger; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; public class SnapStateChunkRequestMessageTest { @@ -92,7 +89,6 @@ void getEncodedMessageWithId_returnExpectedByteArray() { void givenAcceptIsCalled_messageVisitorIsAppliedForMessage() { //given long someId = 42; - byte[] someHash = TestUtils.generateBytes("msg",32); SnapStateChunkRequestMessage message = new SnapStateChunkRequestMessage(someId, 0L, 0L, 0L); MessageVisitor visitor = mock(MessageVisitor.class); diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java new file mode 100644 index 00000000000..fa9fe02706b --- /dev/null +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java @@ -0,0 +1,121 @@ +package co.rsk.net.messages; + +import co.rsk.blockchain.utils.BlockGenerator; +import org.ethereum.core.Block; +import org.ethereum.util.RLP; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +public class SnapStateChunkResponseMessageTest { + + @Test + void getMessageType_returnCorrectMessageType() { + //given + Block block = new BlockGenerator().getBlock(1); + long id4Test = 42L; + String trieValue = "any random data"; + SnapStateChunkResponseMessage message = new SnapStateChunkResponseMessage(id4Test, trieValue.getBytes(), block.getNumber(), 0L, 0L, true); + + //when + MessageType messageType = message.getMessageType(); + + //then + assertThat(messageType).isEqualTo(MessageType.STATE_CHUNK_RESPONSE_MESSAGE); + } + + @Test + void givenParameters4Test_assureExpectedValues() { + //given + Block block = new BlockGenerator().getBlock(1); + long id4Test = 42L; + byte[] trieValueBytes = "any random data".getBytes(); + long from = 5L; + long to = 20L; + boolean complete = true; + + //when + SnapStateChunkResponseMessage message = new SnapStateChunkResponseMessage(id4Test, trieValueBytes, block.getNumber(), from, to, complete); + + //then + assertThat(message).extracting(SnapStateChunkResponseMessage::getId, + SnapStateChunkResponseMessage::getChunkOfTrieKeyValue, + SnapStateChunkResponseMessage::getBlockNumber, + SnapStateChunkResponseMessage::getFrom, + SnapStateChunkResponseMessage::getTo, + SnapStateChunkResponseMessage::isComplete) + .containsExactly(id4Test, trieValueBytes, block.getNumber(), from, to, complete); + } + + + @Test + void getEncodedMessageWithoutId_returnExpectedByteArray() { + //given + long blockNumber = 1L; + long id4Test = 42L; + byte[] trieValueBytes = "any random data".getBytes(); + long from = 5L; + long to = 20L; + boolean complete = true; + + byte[] expectedEncodedMessage = RLP.encodeList( + trieValueBytes, + RLP.encodeBigInteger(BigInteger.valueOf(blockNumber)), + RLP.encodeBigInteger(BigInteger.valueOf(from)), + RLP.encodeBigInteger(BigInteger.valueOf(to)), + new byte[]{(byte) 1}); + + SnapStateChunkResponseMessage message = new SnapStateChunkResponseMessage(id4Test, trieValueBytes, blockNumber, from, to, complete); + + //when + byte[] encodedMessage = message.getEncodedMessageWithoutId(); + + //then + assertThat(encodedMessage) + .isEqualTo(expectedEncodedMessage); + } + + @Test + void getEncodedMessageWithId_returnExpectedByteArray() { + //given + long blockNumber = 1L; + long id4Test = 42L; + byte[] trieValueBytes = "any random data".getBytes(); + long from = 5L; + long to = 20L; + boolean complete = true; + + SnapStateChunkResponseMessage message = new SnapStateChunkResponseMessage(id4Test, trieValueBytes, blockNumber, from, to, complete); + byte[] expectedEncodedMessage = RLP.encodeList( + RLP.encodeBigInteger(BigInteger.valueOf(id4Test)), message.getEncodedMessageWithoutId()); + + //when + byte[] encodedMessage = message.getEncodedMessage(); + + //then + assertThat(encodedMessage) + .isEqualTo(expectedEncodedMessage); + } + + @Test + void givenAcceptIsCalled_messageVisitorIsAppliedForMessage() { + //given + long blockNumber = 1L; + long id4Test = 42L; + byte[] trieValueBytes = "any random data".getBytes(); + long from = 5L; + long to = 20L; + boolean complete = true; + SnapStateChunkResponseMessage message = new SnapStateChunkResponseMessage(id4Test, trieValueBytes, blockNumber, from, to, complete); + MessageVisitor visitor = mock(MessageVisitor.class); + + //when + message.accept(visitor); + + //then + verify(visitor, times(1)).apply(message); + } +} diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java new file mode 100644 index 00000000000..70681cdacb6 --- /dev/null +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java @@ -0,0 +1,47 @@ +package co.rsk.net.messages; + +import org.ethereum.util.RLP; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +class SnapStatusRequestMessageTest { + @Test + void getMessageType_returnCorrectMessageType() { + //given + SnapStatusRequestMessage message = new SnapStatusRequestMessage(); + + //when + MessageType messageType = message.getMessageType(); + + //then + assertThat(messageType).isEqualTo(MessageType.SNAP_STATUS_REQUEST_MESSAGE); + } + + @Test + void getEncodedMessage_returnExpectedByteArray() { + //given + SnapStatusRequestMessage message = new SnapStatusRequestMessage(); + byte[] expectedEncodedMessage = RLP.encodedEmptyList(); + //when + byte[] encodedMessage = message.getEncodedMessage(); + + //then + assertThat(encodedMessage) + .isEqualTo(expectedEncodedMessage); + } + + @Test + void givenAcceptIsCalled_messageVisitorIsAppliedForMessage() { + //given + SnapStatusRequestMessage message = new SnapStatusRequestMessage(); + MessageVisitor visitor = mock(MessageVisitor.class); + + //when + message.accept(visitor); + + //then + verify(visitor, times(1)).apply(message); + } +} \ No newline at end of file diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java new file mode 100644 index 00000000000..24cedb1af2c --- /dev/null +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java @@ -0,0 +1,104 @@ +package co.rsk.net.messages; + +import co.rsk.blockchain.utils.BlockGenerator; +import co.rsk.config.TestSystemProperties; +import co.rsk.core.BlockDifficulty; +import co.rsk.db.HashMapBlocksIndex; +import org.ethereum.core.Block; +import org.ethereum.core.BlockFactory; +import org.ethereum.datasource.HashMapDB; +import org.ethereum.db.BlockStore; +import org.ethereum.db.IndexedBlockStore; +import org.ethereum.util.RLP; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.Collections; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +class SnapStatusResponseMessageTest { + + private final TestSystemProperties config = new TestSystemProperties(); + private final BlockFactory blockFactory = new BlockFactory(config.getActivationConfig()); + private final BlockStore indexedBlockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex()); + private final Block block4Test = new BlockGenerator().getBlock(1); + private final List<Block> blockList = Collections.singletonList(new BlockGenerator().getBlock(1)); + private final List<BlockDifficulty> blockDifficulties = Collections.singletonList(indexedBlockStore.getTotalDifficultyForHash(block4Test.getHash().getBytes())); + private final long trieSize = 1L; + private final SnapStatusResponseMessage underTest = new SnapStatusResponseMessage(blockList, blockDifficulties, trieSize); + + + @Test + void getMessageType_returnCorrectMessageType() { + //given-when + MessageType messageType = underTest.getMessageType(); + + //then + assertEquals(MessageType.SNAP_STATUS_RESPONSE_MESSAGE, messageType); + } + + @Test + void getEncodedMessage_returnExpectedByteArray() { + //given default block 4 test + byte[] expectedEncodedMessage = RLP.encodeList( + RLP.encodeList(RLP.encode(block4Test.getEncoded())), + RLP.encodeList(RLP.encode(blockDifficulties.get(0).getBytes())), + RLP.encodeBigInteger(BigInteger.valueOf(this.trieSize))); + //when + byte[] encodedMessage = underTest.getEncodedMessage(); + + //then + assertThat(encodedMessage) + .isEqualTo(expectedEncodedMessage); + } + + @Test + void getDifficulties_returnTheExpectedValue() { + //given default block 4 test + + //when + List<BlockDifficulty> difficultiesReturned = underTest.getDifficulties(); + //then + assertThat(difficultiesReturned) + .isEqualTo(blockDifficulties); + } + + @Test + void getBlocks_returnTheExpectedValue() { + //given default block 4 test + + //when + List<Block> blocksReturned = underTest.getBlocks(); + //then + assertThat(blocksReturned) + .isEqualTo(blockList); + } + + @Test + void getTrieSize_returnTheExpectedValue() { + //given default block 4 test + + //when + long trieSizeReturned = underTest.getTrieSize(); + //then + assertThat(trieSizeReturned) + .isEqualTo(trieSize); + } + + @Test + void givenAcceptIsCalled_messageVisitorIsAppliedForMessage() { + //given + SnapStatusResponseMessage message = new SnapStatusResponseMessage(blockList, blockDifficulties, trieSize); + MessageVisitor visitor = mock(MessageVisitor.class); + + //when + message.accept(visitor); + + //then + verify(visitor, times(1)).apply(message); + } +} \ No newline at end of file diff --git a/rskj-core/src/test/java/org/ethereum/TestUtils.java b/rskj-core/src/test/java/org/ethereum/TestUtils.java index 96b6b60b372..66e35d4440a 100644 --- a/rskj-core/src/test/java/org/ethereum/TestUtils.java +++ b/rskj-core/src/test/java/org/ethereum/TestUtils.java @@ -84,13 +84,10 @@ public static DB createMapDB(String testDBDir) { File dbFile = new File(blocksIndexFile); if (!dbFile.getParentFile().exists()) dbFile.getParentFile().mkdirs(); - DB db = DBMaker.fileDB(dbFile) + return DBMaker.fileDB(dbFile) .transactionDisable() .closeOnJvmShutdown() .make(); - - - return db; } public static List<Block> getRandomChain(BlockFactory blockFactory, byte[] startParentHash, long startNumber, long length) { @@ -151,12 +148,6 @@ public static InetAddress generateIpAddressV6(@Nonnull String discriminator) thr return InetAddress.getByAddress(bytes); } - public static byte[] concat(byte[] first, byte[] second) { - byte[] result = Arrays.copyOf(first, first.length + second.length); - System.arraycopy(second, 0, result, first.length, second.length); - return result; - } - public static <T extends Exception> T assertThrows(Class<T> c, Runnable f) { Exception thrownException = null; try { From bab3cecb3268f07e2778b5172514fcb03193002c Mon Sep 17 00:00:00 2001 From: fmacleal <frederico.macielleal@iovlabs.org> Date: Tue, 5 Mar 2024 18:21:31 +0100 Subject: [PATCH 10/12] Removing assertJ for now before present it to the team --- gradle/verification-metadata.xml | 21 ---------------- rskj-core/build.gradle | 3 --- .../SnapBlocksRequestMessageTest.java | 13 +++++----- .../SnapBlocksResponseMessageTest.java | 12 ++++----- .../SnapStateChunkRequestMessageTest.java | 19 +++++++------- .../SnapStateChunkResponseMessageTest.java | 25 +++++++++---------- .../SnapStatusRequestMessageTest.java | 8 +++--- .../SnapStatusResponseMessageTest.java | 15 +++++------ 8 files changed, 43 insertions(+), 73 deletions(-) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 78d2cf1e75f..68389a3f4b8 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -697,14 +697,6 @@ <sha256 value="d6f158ba70a080da562f8561a824e94b176c4c8cf4494daf695899c911395889" origin="Generated by Gradle"/> </artifact> </component> - <component group="net.bytebuddy" name="byte-buddy" version="1.14.11"> - <artifact name="byte-buddy-1.14.11.jar"> - <sha256 value="62ae28187ed2b062813da6a9d567bfee733c341582699b62dd980230729a0313" origin="Generated by Gradle"/> - </artifact> - <artifact name="byte-buddy-1.14.11.pom"> - <sha256 value="358449d6c73538584508dd8ae6cfde56baf4a34b767b71d9cc4644f0f1f4211a" origin="Generated by Gradle"/> - </artifact> - </component> <component group="net.bytebuddy" name="byte-buddy-agent" version="1.12.10"> <artifact name="byte-buddy-agent-1.12.10.jar"> <sha256 value="5e8606d14a844c1ec70d2eb8f50c4009fb16138905dee8ca50a328116c041257" origin="Generated by Gradle"/> @@ -718,11 +710,6 @@ <sha256 value="e2870e4340a748e717c8e764060504b90c28b9f7598e7779838d38caeea0b9d1" origin="Generated by Gradle"/> </artifact> </component> - <component group="net.bytebuddy" name="byte-buddy-parent" version="1.14.11"> - <artifact name="byte-buddy-parent-1.14.11.pom"> - <sha256 value="46c0f13fc9778dc2ebb69748823aa2c4cbf07eab7d18c6aa191c529d1650892b" origin="Generated by Gradle"/> - </artifact> - </component> <component group="net.iharder" name="base64" version="2.3.9"> <artifact name="base64-2.3.9.jar"> <sha256 value="f1a0e359eee29a5939c35e5fdedc574dd7e8ca065b056fc14b2b29e3ed3cd54d" origin="Generated by Gradle"/> @@ -827,14 +814,6 @@ <sha256 value="e08028131375b357d1d28734e9a4fb4216da84b240641cb3ef7e7c7d628223fc" origin="Generated by Gradle"/> </artifact> </component> - <component group="org.assertj" name="assertj-core" version="3.25.3"> - <artifact name="assertj-core-3.25.3.jar"> - <sha256 value="7fbdffa1996d43cc08e2576e01008b07e57bbad2b4741aa6c3ab73ce8511130e" origin="Generated by Gradle"/> - </artifact> - <artifact name="assertj-core-3.25.3.pom"> - <sha256 value="3917230eaa33bcf13ea33dd337acafa9d326c739660bf4b6fc56c88d78feb9f2" origin="Generated by Gradle"/> - </artifact> - </component> <component group="org.awaitility" name="awaitility" version="4.2.0"> <artifact name="awaitility-4.2.0.jar"> <sha256 value="2d23b79211fdd19036f6940cc783543779320aaf86f38d6e385a2ff26da41272" origin="Generated by Gradle"/> diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index 33cdc9965b2..1559514a43f 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -158,7 +158,6 @@ ext { commonsCodecVer: '1.15', jacksonVer : '2.13.3', okhttpWsVer : '2.7.5', - assertJVer : '3.25.3', rskLllVer : '0.0.2', ] @@ -179,7 +178,6 @@ ext { commonsCodecLib : "commons-codec:commons-codec:${testLibVersions.commonsCodecVer}", jacksonLib : "com.fasterxml.jackson.core:jackson-databind:${testLibVersions.jacksonVer}", okhttpWsLib : "com.squareup.okhttp:okhttp-ws:${testLibVersions.okhttpWsVer}", - assertJLib : "org.assertj:assertj-core:${testLibVersions.assertJVer}", rskLllLib : "co.rsk:lll-compiler:${testLibVersions.rskLllVer}", ] @@ -233,7 +231,6 @@ dependencies { testImplementation "${testLibs.commonsIoLib}" testImplementation "${testLibs.commonsCodecLib}" testImplementation "${testLibs.okhttpWsLib}" - testImplementation "${testLibs.assertJLib}" testImplementation "${testLibs.rskLllLib}" integrationTestImplementation "${testLibs.junitLib}" diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java index 4ad4f4bab8c..53ba49a315a 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java @@ -7,14 +7,15 @@ import java.math.BigInteger; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; class SnapBlocksRequestMessageTest { - private Block block4Test = new BlockGenerator().getBlock(1); - private SnapBlocksRequestMessage underTest = new SnapBlocksRequestMessage(block4Test.getNumber()); + private final Block block4Test = new BlockGenerator().getBlock(1); + private final SnapBlocksRequestMessage underTest = new SnapBlocksRequestMessage(block4Test.getNumber()); @Test @@ -34,8 +35,7 @@ void getEncodedMessage_returnExpectedByteArray() { byte[] encodedMessage = underTest.getEncodedMessage(); //then - assertThat(encodedMessage) - .isEqualTo(RLP.encodeList(RLP.encodeBigInteger(BigInteger.ONE))); + assertThat(encodedMessage, equalTo(RLP.encodeList(RLP.encodeBigInteger(BigInteger.ONE)))); } @Test @@ -46,8 +46,7 @@ void getBlockNumber_returnTheExpectedValue() { long blockNumber = underTest.getBlockNumber(); //then - assertThat(blockNumber) - .isEqualTo(block4Test.getNumber()); + assertThat(blockNumber, equalTo(block4Test.getNumber())); } @Test diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java index e979c0c6138..6e749e3e4a2 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java @@ -15,7 +15,8 @@ import java.util.Collections; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -49,8 +50,7 @@ void getEncodedMessage_returnExpectedByteArray() { byte[] encodedMessage = underTest.getEncodedMessage(); //then - assertThat(encodedMessage) - .isEqualTo(expectedEncodedMessage); + assertThat(encodedMessage, equalTo(expectedEncodedMessage)); } @Test @@ -60,8 +60,7 @@ void getDifficulties_returnTheExpectedValue() { //when List<BlockDifficulty> difficultiesReturned = underTest.getDifficulties(); //then - assertThat(difficultiesReturned) - .isEqualTo(blockDifficulties); + assertThat(difficultiesReturned, equalTo(blockDifficulties)); } @Test @@ -71,8 +70,7 @@ void getBlocks_returnTheExpectedValue() { //when List<Block> blocksReturned = underTest.getBlocks(); //then - assertThat(blocksReturned) - .isEqualTo(blockList); + assertThat(blocksReturned, equalTo(blockList)); } @Test diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java index 5fd944b850d..9a4fe215ee3 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java @@ -7,7 +7,9 @@ import java.math.BigInteger; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; public class SnapStateChunkRequestMessageTest { @@ -23,7 +25,7 @@ void getMessageType_returnCorrectMessageType() { MessageType messageType = message.getMessageType(); //then - assertThat(messageType).isEqualTo(MessageType.STATE_CHUNK_REQUEST_MESSAGE); + assertThat(messageType, equalTo(MessageType.STATE_CHUNK_REQUEST_MESSAGE)); } @Test void givenParameters4Test_assureExpectedValues() { @@ -37,9 +39,10 @@ void givenParameters4Test_assureExpectedValues() { SnapStateChunkRequestMessage message = new SnapStateChunkRequestMessage(id4Test, block.getNumber(), from, chunkSize); //then - assertThat(message).extracting(SnapStateChunkRequestMessage::getId, - SnapStateChunkRequestMessage::getBlockNumber, SnapStateChunkRequestMessage::getFrom, SnapStateChunkRequestMessage::getChunkSize) - .containsExactly(id4Test, block.getNumber(), from, chunkSize); + assertEquals(id4Test, message.getId()); + assertEquals(block.getNumber(), message.getBlockNumber()); + assertEquals(from, message.getFrom()); + assertEquals(chunkSize, message.getChunkSize()); } @@ -61,8 +64,7 @@ void getEncodedMessageWithoutId_returnExpectedByteArray() { byte[] encodedMessage = message.getEncodedMessageWithoutId(); //then - assertThat(encodedMessage) - .isEqualTo(expectedEncodedMessage); + assertThat(encodedMessage, equalTo(expectedEncodedMessage)); } @Test @@ -81,8 +83,7 @@ void getEncodedMessageWithId_returnExpectedByteArray() { byte[] encodedMessage = message.getEncodedMessage(); //then - assertThat(encodedMessage) - .isEqualTo(expectedEncodedMessage); + assertThat(encodedMessage, equalTo(expectedEncodedMessage)); } @Test diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java index fa9fe02706b..f10227c56f7 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java @@ -7,7 +7,9 @@ import java.math.BigInteger; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; public class SnapStateChunkResponseMessageTest { @@ -24,7 +26,7 @@ void getMessageType_returnCorrectMessageType() { MessageType messageType = message.getMessageType(); //then - assertThat(messageType).isEqualTo(MessageType.STATE_CHUNK_RESPONSE_MESSAGE); + assertThat(messageType, equalTo(MessageType.STATE_CHUNK_RESPONSE_MESSAGE)); } @Test @@ -41,13 +43,12 @@ void givenParameters4Test_assureExpectedValues() { SnapStateChunkResponseMessage message = new SnapStateChunkResponseMessage(id4Test, trieValueBytes, block.getNumber(), from, to, complete); //then - assertThat(message).extracting(SnapStateChunkResponseMessage::getId, - SnapStateChunkResponseMessage::getChunkOfTrieKeyValue, - SnapStateChunkResponseMessage::getBlockNumber, - SnapStateChunkResponseMessage::getFrom, - SnapStateChunkResponseMessage::getTo, - SnapStateChunkResponseMessage::isComplete) - .containsExactly(id4Test, trieValueBytes, block.getNumber(), from, to, complete); + assertEquals(id4Test, message.getId()); + assertEquals(trieValueBytes, message.getChunkOfTrieKeyValue()); + assertEquals(block.getNumber(),message.getBlockNumber()); + assertEquals(from,message.getFrom()); + assertEquals(to,message.getTo()); + assertEquals(complete,message.isComplete()); } @@ -74,8 +75,7 @@ void getEncodedMessageWithoutId_returnExpectedByteArray() { byte[] encodedMessage = message.getEncodedMessageWithoutId(); //then - assertThat(encodedMessage) - .isEqualTo(expectedEncodedMessage); + assertThat(encodedMessage, equalTo(expectedEncodedMessage)); } @Test @@ -96,8 +96,7 @@ void getEncodedMessageWithId_returnExpectedByteArray() { byte[] encodedMessage = message.getEncodedMessage(); //then - assertThat(encodedMessage) - .isEqualTo(expectedEncodedMessage); + assertThat(encodedMessage, equalTo(expectedEncodedMessage)); } @Test diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java index 70681cdacb6..cad0aa0aa40 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java @@ -3,7 +3,8 @@ import org.ethereum.util.RLP; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.*; class SnapStatusRequestMessageTest { @@ -16,7 +17,7 @@ void getMessageType_returnCorrectMessageType() { MessageType messageType = message.getMessageType(); //then - assertThat(messageType).isEqualTo(MessageType.SNAP_STATUS_REQUEST_MESSAGE); + assertThat(messageType, equalTo(MessageType.SNAP_STATUS_REQUEST_MESSAGE)); } @Test @@ -28,8 +29,7 @@ void getEncodedMessage_returnExpectedByteArray() { byte[] encodedMessage = message.getEncodedMessage(); //then - assertThat(encodedMessage) - .isEqualTo(expectedEncodedMessage); + assertThat(encodedMessage, equalTo(expectedEncodedMessage)); } @Test diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java index 24cedb1af2c..75d49891147 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java @@ -16,7 +16,8 @@ import java.util.Collections; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @@ -52,8 +53,7 @@ void getEncodedMessage_returnExpectedByteArray() { byte[] encodedMessage = underTest.getEncodedMessage(); //then - assertThat(encodedMessage) - .isEqualTo(expectedEncodedMessage); + assertThat(encodedMessage, equalTo(expectedEncodedMessage)); } @Test @@ -63,8 +63,7 @@ void getDifficulties_returnTheExpectedValue() { //when List<BlockDifficulty> difficultiesReturned = underTest.getDifficulties(); //then - assertThat(difficultiesReturned) - .isEqualTo(blockDifficulties); + assertThat(difficultiesReturned, equalTo(blockDifficulties)); } @Test @@ -74,8 +73,7 @@ void getBlocks_returnTheExpectedValue() { //when List<Block> blocksReturned = underTest.getBlocks(); //then - assertThat(blocksReturned) - .isEqualTo(blockList); + assertThat(blocksReturned, equalTo(blockList)); } @Test @@ -85,8 +83,7 @@ void getTrieSize_returnTheExpectedValue() { //when long trieSizeReturned = underTest.getTrieSize(); //then - assertThat(trieSizeReturned) - .isEqualTo(trieSize); + assertThat(trieSizeReturned, equalTo(trieSize)); } @Test From 35af0b880bc73d338d319a31159b43ea2274b7ff Mon Sep 17 00:00:00 2001 From: fmacleal <frederico.macielleal@iovlabs.org> Date: Thu, 7 Mar 2024 13:12:01 +0100 Subject: [PATCH 11/12] Adding SnapSyncStateTest --- .../co/rsk/net/sync/SnapSyncStateTest.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 rskj-core/src/test/java/co/rsk/net/sync/SnapSyncStateTest.java diff --git a/rskj-core/src/test/java/co/rsk/net/sync/SnapSyncStateTest.java b/rskj-core/src/test/java/co/rsk/net/sync/SnapSyncStateTest.java new file mode 100644 index 00000000000..6da1139d636 --- /dev/null +++ b/rskj-core/src/test/java/co/rsk/net/sync/SnapSyncStateTest.java @@ -0,0 +1,95 @@ +package co.rsk.net.sync; + +import co.rsk.net.NodeID; +import co.rsk.net.Peer; +import co.rsk.net.SnapshotProcessor; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.time.Duration; +import java.util.Optional; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.mockito.Mockito.*; + +class SnapSyncStateTest { + + private final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING; + private final SyncEventsHandler syncEventsHandler = mock(SyncEventsHandler.class); + private final PeersInformation peersInformation = mock(PeersInformation.class); + private final SnapshotProcessor snapshotProcessor = mock(SnapshotProcessor.class); + + private final SnapSyncState underTest = new SnapSyncState(syncEventsHandler, + snapshotProcessor, + syncConfiguration, + peersInformation); + + @BeforeEach + void setUp(){ + reset(syncEventsHandler,peersInformation, snapshotProcessor); + } + + @Test + void givenOnEnterWasCalled_thenSyncingStartWithTestObjectAsParameter(){ + //given-when + underTest.onEnter(); + //then + verify(snapshotProcessor).startSyncing(peersInformation, underTest); + } + + @Test + void givenNewChunk_thenTimerIsReset(){ + //given + underTest.timeElapsed = Duration.ofMinutes(1); + assertThat(underTest.timeElapsed, greaterThan(Duration.ZERO)); + + // when + underTest.newChunk(); + //then + assertThat(underTest.timeElapsed, equalTo(Duration.ZERO)); + } + + @Test + void givenTickIsCalledBeforeTimeout_thenTimerIsUpdated_andNoTimeoutHappens(){ + //given + Duration elapsedTime = Duration.ofMillis(10); + underTest.timeElapsed = Duration.ZERO; + // when + underTest.tick(elapsedTime); + //then + assertThat(underTest.timeElapsed, equalTo(elapsedTime)); + verify(syncEventsHandler, never()).stopSyncing(); + verify(syncEventsHandler, never()).onErrorSyncing(any(),any(),any(),any()); + } + + @Test + void givenTickIsCalledAfterTimeout_thenTimerIsUpdated_andTimeoutHappens() throws UnknownHostException { + //given + Duration elapsedTime = Duration.ofMinutes(1); + underTest.timeElapsed = Duration.ZERO; + Peer mockedPeer = mock(Peer.class); + NodeID nodeID = mock(NodeID.class); + when(mockedPeer.getPeerNodeID()).thenReturn(nodeID); + when(mockedPeer.getAddress()).thenReturn(InetAddress.getByName("127.0.0.1")); + when(peersInformation.getBestPeer()).thenReturn(Optional.of(mockedPeer)); + // when + underTest.tick(elapsedTime); + //then + assertThat(underTest.timeElapsed, equalTo(elapsedTime)); + verify(syncEventsHandler, times(1)).stopSyncing(); + verify(syncEventsHandler, times(1)).onErrorSyncing(any(),any(),any(),any()); + } + + @Test + void givenFinishedIsCalled_thenSyncEventHandlerStopsSync(){ + //given-when + underTest.finished(); + //then + verify(syncEventsHandler, times(1)).snapSyncFinished(); + verify(syncEventsHandler, times(1)).stopSyncing(); + } +} \ No newline at end of file From fb4f2615546e160e9e6c9af8e8b245828b262bcb Mon Sep 17 00:00:00 2001 From: fmacleal <frederico.macielleal@iovlabs.org> Date: Thu, 7 Mar 2024 16:41:05 +0100 Subject: [PATCH 12/12] Adding CC headers to the files --- .../messages/SnapBlocksRequestMessageTest.java | 18 ++++++++++++++++++ .../SnapBlocksResponseMessageTest.java | 18 ++++++++++++++++++ .../SnapStateChunkRequestMessageTest.java | 18 ++++++++++++++++++ .../SnapStateChunkResponseMessageTest.java | 18 ++++++++++++++++++ .../messages/SnapStatusRequestMessageTest.java | 18 ++++++++++++++++++ .../SnapStatusResponseMessageTest.java | 18 ++++++++++++++++++ .../co/rsk/net/sync/SnapSyncStateTest.java | 18 ++++++++++++++++++ 7 files changed, 126 insertions(+) diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java index 53ba49a315a..e5443746b85 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksRequestMessageTest.java @@ -1,3 +1,21 @@ +/* + * This file is part of RskJ + * Copyright (C) 2024 RSK Labs Ltd. + * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package co.rsk.net.messages; import co.rsk.blockchain.utils.BlockGenerator; diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java index 6e749e3e4a2..ca2268576d2 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapBlocksResponseMessageTest.java @@ -1,3 +1,21 @@ +/* + * This file is part of RskJ + * Copyright (C) 2024 RSK Labs Ltd. + * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package co.rsk.net.messages; import co.rsk.blockchain.utils.BlockGenerator; diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java index 9a4fe215ee3..a6c7516fb9a 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkRequestMessageTest.java @@ -1,3 +1,21 @@ +/* + * This file is part of RskJ + * Copyright (C) 2024 RSK Labs Ltd. + * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package co.rsk.net.messages; import co.rsk.blockchain.utils.BlockGenerator; diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java index f10227c56f7..b6646a9a422 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStateChunkResponseMessageTest.java @@ -1,3 +1,21 @@ +/* + * This file is part of RskJ + * Copyright (C) 2024 RSK Labs Ltd. + * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package co.rsk.net.messages; import co.rsk.blockchain.utils.BlockGenerator; diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java index cad0aa0aa40..ff34d0a463c 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusRequestMessageTest.java @@ -1,3 +1,21 @@ +/* + * This file is part of RskJ + * Copyright (C) 2024 RSK Labs Ltd. + * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package co.rsk.net.messages; import org.ethereum.util.RLP; diff --git a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java index 75d49891147..623d0c42325 100644 --- a/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java +++ b/rskj-core/src/test/java/co/rsk/net/messages/SnapStatusResponseMessageTest.java @@ -1,3 +1,21 @@ +/* + * This file is part of RskJ + * Copyright (C) 2024 RSK Labs Ltd. + * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package co.rsk.net.messages; import co.rsk.blockchain.utils.BlockGenerator; diff --git a/rskj-core/src/test/java/co/rsk/net/sync/SnapSyncStateTest.java b/rskj-core/src/test/java/co/rsk/net/sync/SnapSyncStateTest.java index 6da1139d636..998bafc51ae 100644 --- a/rskj-core/src/test/java/co/rsk/net/sync/SnapSyncStateTest.java +++ b/rskj-core/src/test/java/co/rsk/net/sync/SnapSyncStateTest.java @@ -1,3 +1,21 @@ +/* + * This file is part of RskJ + * Copyright (C) 2024 RSK Labs Ltd. + * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package co.rsk.net.sync; import co.rsk.net.NodeID;