Skip to content

Commit

Permalink
- Moved null assertion to its own test.
Browse files Browse the repository at this point in the history
- Renamed EIGHT_BYTES_WORK_V1 constant to BELOW_MAX_WORK_V1
  • Loading branch information
nathanieliov committed Dec 4, 2024
1 parent b5dbef4 commit 5227777
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/test/java/co/rsk/federate/adapter/ThinConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.constants.BridgeConstants;
import co.rsk.peg.constants.BridgeMainNetConstants;
import co.rsk.peg.constants.BridgeRegTestConstants;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.stream.Stream;
Expand All @@ -21,7 +20,7 @@
class ThinConverterTest {

private static final BigInteger NEGATIVE_CHAIN_WORK = BigInteger.valueOf(-1);
private static final BigInteger EIGHT_BYTES_WORK_V1 = new BigInteger("ffffffffffffffff", 16); // 8 bytes
private static final BigInteger BELOW_MAX_WORK_V1 = new BigInteger("ffffffffffffffff", 16); // 8 bytes
private static final BigInteger MAX_WORK_V1 = new BigInteger(/* 12 bytes */ "ffffffffffffffffffffffff", 16);
private static final BigInteger MAX_WORK_V2 = new BigInteger(/* 32 bytes */
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16);
Expand All @@ -42,7 +41,7 @@ public static Stream<Arguments> validChainWorkArgsProvider() {
return Stream.of(
Arguments.of(BigInteger.ZERO),
Arguments.of(BigInteger.ONE),
Arguments.of(EIGHT_BYTES_WORK_V1),
Arguments.of(BELOW_MAX_WORK_V1),
Arguments.of(MAX_WORK_V1),
Arguments.of(TOO_LARGE_WORK_V1),
Arguments.of(MAX_WORK_V2)
Expand Down Expand Up @@ -82,7 +81,6 @@ void toThinInstanceStoredBlock(BigInteger chainWork) {
assertEquals(chainWork, thinStoredBlock.getChainWork());
assertEquals(height, thinStoredBlock.getHeight());
assertArrayEquals(originalBlock.bitcoinSerialize(), thinStoredBlock.getHeader().bitcoinSerialize());
assertNull(ThinConverter.toThinInstance(null, bridgeConstants));
}

@ParameterizedTest
Expand All @@ -96,6 +94,11 @@ void toThinInstanceStored_whenInvalidChainWork_shouldFail(BigInteger chainWork)
Assertions.assertThrows(IllegalArgumentException.class, () -> ThinConverter.toThinInstance(originalStoredBlock, bridgeConstants));
}

@Test
void toThinInstanceStoredBlock_whenPassingNull_shouldReturnNull() {
assertNull(ThinConverter.toThinInstance(null, bridgeConstants));
}

@ParameterizedTest
@MethodSource("validChainWorkArgsProvider")
void toOriginalInstanceStoredBlock(BigInteger chainWork) {
Expand All @@ -110,7 +113,6 @@ void toOriginalInstanceStoredBlock(BigInteger chainWork) {
assertEquals(chainWork, originalStoredBlock.getChainWork());
assertEquals(height, originalStoredBlock.getHeight());
assertArrayEquals(thinBlock.bitcoinSerialize(), originalStoredBlock.getHeader().bitcoinSerialize());
assertNull(ThinConverter.toOriginalInstance(null, bridgeConstants));
}

@ParameterizedTest
Expand All @@ -124,6 +126,11 @@ void toOriginalInstanceStoredBlock_whenInvalidChainWork_shouldFail(BigInteger ch
Assertions.assertThrows(IllegalArgumentException.class, () -> ThinConverter.toOriginalInstance(thinStoredBlock, bridgeConstants));
}

@Test
void toOriginalInstance_whenPassingNull_shouldReturnNull() {
assertNull(ThinConverter.toOriginalInstance(null, bridgeConstants));
}

@Test
void toOriginalInstanceNetworkParameters() {
org.bitcoinj.core.NetworkParameters originalParams = ThinConverter.toOriginalInstance(
Expand Down

0 comments on commit 5227777

Please sign in to comment.