Skip to content

Commit

Permalink
Add tests for FederationSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-iov committed Nov 22, 2024
1 parent f70a3f6 commit d7979b4
Showing 1 changed file with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@
import java.util.stream.Stream;
import co.rsk.peg.storage.StorageAccessor;
import co.rsk.test.builders.FederationSupportBuilder;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;
import org.ethereum.config.blockchain.upgrades.*;
import org.ethereum.core.*;
import org.ethereum.crypto.ECKey;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.*;

class FederationSupportImplTest {

private static final FederationConstants federationMainnetConstants = FederationMainNetConstants.getInstance();
private final Federation genesisFederation = FederationTestUtils.getGenesisFederation(federationMainnetConstants);
private final FederationSupportBuilder federationSupportBuilder = FederationSupportBuilder.builder();
private ErpFederation newFederation;
private Federation newFederation;
private StorageAccessor storageAccessor;
private FederationStorageProvider storageProvider;
private FederationSupport federationSupport;
Expand Down Expand Up @@ -221,6 +217,27 @@ void getActiveFederationUTXOs_returnsGenesisFederationUTXOs() {
List<UTXO> activeFederationUTXOs = federationSupport.getActiveFederationBtcUTXOs();
assertThat(activeFederationUTXOs, is(genesisFederationUTXOs));
}

@Test
void getLiveFederations_returnsGenesisFederation() {
List<Federation> liveFederations = federationSupport.getLiveFederations();

assertEquals(1, liveFederations.size());
assertEquals(genesisFederation, liveFederations.get(0));
}

@Test
void getFederationContext() {
FederationContext federationContext = federationSupport.getFederationContext();
List<Federation> liveFederations = federationContext.getLiveFederations();

assertEquals(genesisFederation, federationContext.getActiveFederation());
assertTrue(federationContext.getRetiringFederation().isEmpty());
assertTrue(federationContext.getLastRetiredFederationP2SHScript().isEmpty());

assertEquals(1, liveFederations.size());
assertEquals(genesisFederation, liveFederations.get(0));
}
}

@Nested
Expand Down Expand Up @@ -420,6 +437,27 @@ void getActiveFederationUTXOs_returnsNewFederationUTXOs() {
List<UTXO> activeFederationUTXOs = federationSupport.getActiveFederationBtcUTXOs();
assertThat(activeFederationUTXOs, is(newFederationUTXOs));
}

@Test
void getLiveFederations_returnsActiveFederation() {
List<Federation> liveFederations = federationSupport.getLiveFederations();

assertEquals(1, liveFederations.size());
assertEquals(newFederation, liveFederations.get(0));
}

@Test
void getFederationContext() {
FederationContext federationContext = federationSupport.getFederationContext();
List<Federation> liveFederations = federationContext.getLiveFederations();

assertEquals(newFederation, federationContext.getActiveFederation());
assertTrue(federationContext.getRetiringFederation().isEmpty());
assertTrue(federationContext.getLastRetiredFederationP2SHScript().isEmpty());

assertEquals(1, liveFederations.size());
assertEquals(newFederation, liveFederations.get(0));
}
}

@Nested
Expand Down Expand Up @@ -584,8 +622,8 @@ private Stream<Arguments> expectedAddressArgs() {
void getActiveFederationSize_returnsExpectedSizeAccordingToActivationAgeAndActivations(
long currentBlock,
ActivationConfig.ForBlock activations,
int expectedSize) {

int expectedSize
) {
Block executionBlock = mock(Block.class);
when(executionBlock.getNumber()).thenReturn(currentBlock);

Expand Down Expand Up @@ -844,6 +882,30 @@ private Stream<Arguments> expectedUTXOsArgs() {
Arguments.of(blockNumberFederationActivationFingerroot, hopActivations, newFederationUTXOs)
);
}

@Test
void getLiveFederations_returnsActiveAndRetiringFederations() {
List<Federation> liveFederations = federationSupport.getLiveFederations();

assertEquals(2, liveFederations.size());
assertEquals(newFederation, liveFederations.get(0));
assertEquals(oldFederation, liveFederations.get(1));
}

@Test
void getFederationContext() {
FederationContext federationContext = federationSupport.getFederationContext();
List<Federation> liveFederations = federationContext.getLiveFederations();

assertEquals(newFederation, federationContext.getActiveFederation());
assertTrue(federationContext.getRetiringFederation().isPresent());
assertEquals(oldFederation, federationContext.getRetiringFederation().get());
assertTrue(federationContext.getLastRetiredFederationP2SHScript().isEmpty());

assertEquals(2, liveFederations.size());
assertEquals(newFederation, liveFederations.get(0));
assertEquals(oldFederation, liveFederations.get(1));
}
}

@Nested
Expand Down

0 comments on commit d7979b4

Please sign in to comment.